#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Accept file drops across the whole workbench (#8379)
EthanHealy01e89c44e09ca2
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex 9823ce48cb..04e9b9395f 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -4590,15 +4590,12 @@ closeFile = "Close file"[fileEditor]closedFile = "Closed {{name}}"couldNotSave = "Could not save {{name}}"-filesAdded_one = "Added {{count}} file"-filesAdded_other = "Added {{count}} files"filesReordered_one = "File reordered"filesReordered_other = "{{count}} files reordered"loadedFromStorage_one = "Loaded {{count}} file from storage"loadedFromStorage_other = "Loaded {{count}} files from storage"loadFromStorageFailed = "Failed to load some files from storage"pinnedFile = "Pinned {{name}}"-processFilesFailed = "Failed to process files"savedAndClosed = "Saved and closed {{name}}"saveFailed = "Save failed"unpinnedFile = "Unpinned {{name}}"@@ -4724,7 +4721,6 @@ dataLostBody = "This browser lost this file's contents. Upload it again to keepdataLostTitle = "File data is unavailable"downloadFailed = "Download failed"dropHint = "Open files to get started"-dropToAdd = "Drop files to add"duplicateFailed = "Could not duplicate file"expand = "Expand sidebar"googleDrive = "Google Drive"@@ -13901,6 +13897,11 @@ title = "Watermark Text"image = "Image"text = "Text"+[workbench]+dropFailedSingle = "Your file couldn't be added"+dropFailedSome = "{{failed}} of your files couldn't be added"+dropOverlay = "Drop files to add them to the workbench"+[workbench.sessionRestore]none = "Your previous files are no longer stored on this device."partial = "Restored {{restored}} of {{total}} files. The rest are no longer stored on this device."diff --git a/frontend/editor/src/core/components/fileEditor/AddFileCard.module.css b/frontend/editor/src/core/components/fileEditor/AddFileCard.module.cssindex 8372dfc80d..51b7c47ca6 100644--- a/frontend/editor/src/core/components/fileEditor/AddFileCard.module.css+++ b/frontend/editor/src/core/components/fileEditor/AddFileCard.module.css@@ -38,8 +38,7 @@--c-btn-secondary: var(--c-surface);}-/* The surrounding Dropzone sets data-accept while files are dragged over it. */-:global([data-accept]) .card {+.card[data-drag-over] {border-color: var(--c-primary);background: var(--c-primary-subtle);}diff --git a/frontend/editor/src/core/components/fileEditor/AddFileCard.tsx b/frontend/editor/src/core/components/fileEditor/AddFileCard.tsxindex b647077f4f..152a19028e 100644--- a/frontend/editor/src/core/components/fileEditor/AddFileCard.tsx+++ b/frontend/editor/src/core/components/fileEditor/AddFileCard.tsx@@ -7,6 +7,7 @@ import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";import { useIsPhone } from "@app/hooks/useIsMobile";import { useProcessingFolderCreation } from "@app/hooks/useProcessingFolderCreation";import { usePoliciesEnabled } from "@app/components/policies/usePoliciesEnabled";+import { useIsWorkbenchFileDragOver } from "@app/components/layout/useWorkbenchFileDrop";import MobileUploadModal from "@app/components/shared/MobileUploadModal";import { openFilesFromDisk } from "@app/services/openFilesFromDisk";import { ActionIcon } from "@app/ui/ActionIcon";@@ -23,8 +24,8 @@ interface AddFileCardProps {/*** The workbench's standing "add files" slot in the thumbnail grid. Add Files* opens the file library; the overflow menu holds the direct computer and- * mobile uploads. Drops are handled by the surrounding workbench Dropzone,- * whose drag state this card reflects.+ * mobile uploads. Drops are handled by the workbench, whose drag state this+ * card reflects.*/const AddFileCard = ({ onFilesSelected }: AddFileCardProps) => {const { t } = useTranslation();@@ -34,6 +35,7 @@ const AddFileCard = ({ onFilesSelected }: AddFileCardProps) => {const isPhone = useIsPhone();const folderCreation = useProcessingFolderCreation();const signedIn = usePoliciesEnabled();+ const isFileDragOver = useIsWorkbenchFileDragOver();const fileInputRef = useRef<HTMLInputElement | null>(null);const [mobileUploadOpen, setMobileUploadOpen] = useState(false);const moreOptionsLabel = t(@@ -57,7 +59,11 @@ const AddFileCard = ({ onFilesSelected }: AddFileCardProps) => {return (<div className={styles.cell}>- <div className={styles.card} data-testid="add-file-card">+ <div+ className={styles.card}+ data-testid="add-file-card"+ data-drag-over={isFileDragOver || undefined}+ ><div className={styles.more}><Menu position="bottom-end" withinPortal>{/* Tooltip outside the target: inside it, Mantine forwards thediff --git a/frontend/editor/src/core/components/fileEditor/FileEditor.tsx b/frontend/editor/src/core/components/fileEditor/FileEditor.tsxindex a7bd00607f..420f5a81e0 100644--- a/frontend/editor/src/core/components/fileEditor/FileEditor.tsx+++ b/frontend/editor/src/core/components/fileEditor/FileEditor.tsx@@ -1,7 +1,6 @@import { useState, useCallback, useMemo, useEffect, useRef } from "react";import { flushSync } from "react-dom";import { Center, Box, LoadingOverlay } from "@mantine/core";-import { Dropzone } from "@mantine/dropzone";import { useTranslation } from "react-i18next";import {useFileSelection,@@ -21,7 +20,6 @@ import { alert } from "@app/components/toast";import { downloadFileWithPolicy as downloadFile } from "@app/services/exportWithPolicy";import { useToolWorkflow } from "@app/contexts/ToolWorkflowContext";import { usePolicyFileBadges } from "@app/hooks/usePolicyFileBadges";-import { useDropzoneFiles } from "@app/hooks/useDropzoneFiles";import type { FileItemPolicyRef } from "@app/components/shared/PolicyBadges";const EMPTY_POLICIES: FileItemPolicyRef[] = [];@@ -69,7 +67,6 @@ const FileEditor = ({const { setActiveFileIndex, setActiveFileId } = useViewer();const [_status, _setStatus] = useState<string | null>(null);- const [_error, _setError] = useState<string | null>(null);const showStatus = useCallback((@@ -104,33 +101,28 @@ const FileEditor = ({return !toolMode || rawMax == null || rawMax < 0 ? Infinity : rawMax;}, [selectedTool?.maxFiles, toolMode]);- const getDropzoneFiles = useDropzoneFiles();const [showFilePickerModal, setShowFilePickerModal] = useState(false);const handleFileUpload = useCallback(async (uploadedFiles: File[]) => {- _setError(null);-try {- if (uploadedFiles.length > 0) {- await addFiles(uploadedFiles, { selectFiles: true });- if (Number.isFinite(maxAllowed)) {- const nowSelectedIds = selectors- .getSelectedStirlingFileStubs()- .map((r) => r.id);- if (nowSelectedIds.length > maxAllowed) {- setSelectedFiles(nowSelectedIds.slice(-maxAllowed));- }+ await addFiles(uploadedFiles, { selectFiles: true });+ if (Number.isFinite(maxAllowed)) {+ const nowSelectedIds = selectors+ .getSelectedStirlingFileStubs()+ .map((r) => r.id);+ if (nowSelectedIds.length > maxAllowed) {+ setSelectedFiles(nowSelectedIds.slice(-maxAllowed));}- showStatus(- t("fileEditor.filesAdded", {- count: uploadedFiles.length,- defaultValue_one: "Added {{count}} file",- defaultValue_other: "Added {{count}} files",- }),- "success",- );}+ showStatus(+ t("fileEditor.filesAdded", {+ count: uploadedFiles.length,+ defaultValue_one: "Added {{count}} file",+ defaultValue_other: "Added {{count}} files",+ }),+ "success",+ );} catch (err) {const errorMessage =err instanceof Error@@ -370,77 +362,62 @@ const FileEditor = ({);return (- <Dropzone- onDrop={handleFileUpload}- useFsAccessApi={false}- getFilesFromEvent={getDropzoneFiles}- multiple={true}- maxSize={2 * 1024 * 1024 * 1024}- style={{- border: "none",- borderRadius: 0,- backgroundColor: "transparent",- }}- activateOnClick={false}- activateOnDrag={true}- >- <Box pos="relative" style={{ overflow: "auto" }}>- <LoadingOverlay visible={state.ui.isProcessing} />-- <Box p="md">- {activeStirlingFileStubs.length === 0 ? (- <Center h="60vh">+ <Box pos="relative" style={{ overflow: "auto" }}>+ <LoadingOverlay visible={state.ui.isProcessing} />++ <Box p="md">+ {activeStirlingFileStubs.length === 0 ? (+ <Center h="60vh">+ <AddFileCard+ onFilesSelected={(files) => void handleFileUpload(files)}+ />+ </Center>+ ) : (+ <div+ style={{+ display: "grid",+ gridTemplateColumns: "repeat(auto-fill, minmax(276px, 1fr))",+ rowGap: "1.5rem",+ padding: "1rem",+ pointerEvents: "auto",+ }}+ >+ {activeStirlingFileStubs.length > 0 && (<AddFileCard+ key="add-file-card"onFilesSelected={(files) => void handleFileUpload(files)}/>- </Center>- ) : (- <div- style={{- display: "grid",- gridTemplateColumns: "repeat(auto-fill, minmax(276px, 1fr))",- rowGap: "1.5rem",- padding: "1rem",- pointerEvents: "auto",- }}- >- {activeStirlingFileStubs.length > 0 && (- <AddFileCard- key="add-file-card"- onFilesSelected={(files) => void handleFileUpload(files)}+ )}++ {activeStirlingFileStubs.map((record, index) => {+ return (+ <FileEditorThumbnail+ key={record.id}+ file={record}+ index={index}+ totalFiles={activeStirlingFileStubs.length}+ onCloseFile={handleCloseFile}+ onViewFile={handleViewFile}+ onReorderFiles={handleReorderFiles}+ onDownloadFile={handleDownloadFile}+ onUnzipFile={handleUnzipFile}+ toolMode={toolMode}+ isSupported={isFileSupported(record.name)}+ policies={policyFileBadges.get(record.id) ?? EMPTY_POLICIES}/>- )}-- {activeStirlingFileStubs.map((record, index) => {- return (- <FileEditorThumbnail- key={record.id}- file={record}- index={index}- totalFiles={activeStirlingFileStubs.length}- onCloseFile={handleCloseFile}- onViewFile={handleViewFile}- onReorderFiles={handleReorderFiles}- onDownloadFile={handleDownloadFile}- onUnzipFile={handleUnzipFile}- toolMode={toolMode}- isSupported={isFileSupported(record.name)}- policies={policyFileBadges.get(record.id) ?? EMPTY_POLICIES}- />- );- })}- </div>- )}- </Box>-- <FilePickerModal- opened={showFilePickerModal}- onClose={() => setShowFilePickerModal(false)}- storedFiles={[]} // FileEditor doesn't have access to stored files, needs to be passed from parent- onSelectFiles={handleLoadFromStorage}- />+ );+ })}+ </div>+ )}</Box>- </Dropzone>++ <FilePickerModal+ opened={showFilePickerModal}+ onClose={() => setShowFilePickerModal(false)}+ storedFiles={[]} // FileEditor doesn't have access to stored files, needs to be passed from parent+ onSelectFiles={handleLoadFromStorage}+ />+ </Box>);};diff --git a/frontend/editor/src/core/components/filesPage/FileManagerView.tsx b/frontend/editor/src/core/components/filesPage/FileManagerView.tsxindex 1425be4954..ae34e5ad6b 100644--- a/frontend/editor/src/core/components/filesPage/FileManagerView.tsx+++ b/frontend/editor/src/core/components/filesPage/FileManagerView.tsx@@ -734,8 +734,15 @@ export default function FileManagerView() {const node = dropZoneRef.current;if (!node) return;let counter = 0;- const isExternalFileDrag = (e: DragEvent) =>- Array.from(e.dataTransfer?.types ?? []).includes("Files");+ // Stops each event so the workbench's own drop target, which wraps this+ // view, doesn't add the same files again outside the current folder.+ const isExternalFileDrag = (e: DragEvent) => {+ const external = Array.from(e.dataTransfer?.types ?? []).includes(+ "Files",+ );+ if (external) e.stopPropagation();+ return external;+ };const onEnter = (e: DragEvent) => {if (!isExternalFileDrag(e)) return;@@ -747,7 +754,8 @@ export default function FileManagerView() {if (!isExternalFileDrag(e)) return;e.preventDefault();};- const onLeave = () => {+ const onLeave = (e: DragEvent) => {+ if (!isExternalFileDrag(e)) return;counter -= 1;if (counter <= 0) {counter = 0;diff --git a/frontend/editor/src/core/components/layout/Workbench.module.css b/frontend/editor/src/core/components/layout/Workbench.module.cssindex 22d6fdc43c..a9e2f196d9 100644--- a/frontend/editor/src/core/components/layout/Workbench.module.css+++ b/frontend/editor/src/core/components/layout/Workbench.module.css@@ -74,3 +74,35 @@.workbenchScrollable::-webkit-scrollbar-thumb:hover {background-color: var(--mantine-color-gray-5);}++/* pointer-events: none so the drop lands on the workbench beneath, which owns it. */+.fileDropOverlay {+ position: absolute;+ inset: 0.75rem;+ z-index: 60;+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ gap: 1rem;+ border: 2px dashed var(--c-border-strong);+ border-radius: 1rem;+ /* Translucent so the workbench stays visible. */+ background: color-mix(in srgb, var(--c-surface) 85%, transparent);+ backdrop-filter: blur(2px);+ color: var(--c-text);+ font-size: 1.1rem;+ font-weight: 600;+ pointer-events: none;+}++.fileDropOverlayIcon {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ width: 4.5rem;+ height: 4.5rem;+ border-radius: 50%;+ background: var(--c-hover);+ color: var(--c-text-muted);+}diff --git a/frontend/editor/src/core/components/layout/Workbench.tsx b/frontend/editor/src/core/components/layout/Workbench.tsxindex 66ede9761d..33fff48876 100644--- a/frontend/editor/src/core/components/layout/Workbench.tsx+++ b/frontend/editor/src/core/components/layout/Workbench.tsx@@ -17,6 +17,10 @@ import styles from "@app/components/layout/Workbench.module.css";import WorkbenchBar from "@app/components/shared/WorkbenchBar";import { useWorkbenchTakeover } from "@app/components/layout/WorkbenchTakeover";+import {+ useIsWorkbenchFileDragOver,+ useWorkbenchFileDrop,+} from "@app/components/layout/useWorkbenchFileDrop";import { useTitleBarStrip } from "@app/contexts/TitleBarStripContext";import WorkbenchFloatingSearch from "@app/components/shared/WorkbenchFloatingSearch";import LandingPage from "@app/components/shared/LandingPage";@@ -66,6 +70,14 @@ export default function Workbench() {const hasFiles = activeFiles.length > 0;const { t } = useTranslation();+ // Every view takes file drops on the whole canvas, not just the content it+ // happens to render. Views that do something of their own with a dropped file+ // (the file library, the PDF text editor) stop the events reaching here.+ // The file sidebar shares this drop target and its overlay.+ const acceptsFileDrops = !takeover;+ const dropHandlers = useWorkbenchFileDrop(acceptsFileDrops);+ const isFileDragOver = useIsWorkbenchFileDragOver() && acceptsFileDrops;+// The viewer's tool row can be retracted to give the document more height.// State lives here (not in WorkbenchBar) so the reopen tab can hang below the// bar, outside the bar's overflow-clipped wrapper. Scoped to the viewer.@@ -205,7 +217,19 @@ export default function Workbench() {className="flex-1 h-full min-w-0 relative flex flex-col"data-tour="workbench"style={{ backgroundColor: "var(--c-bg)", minWidth: 0, minHeight: 0 }}+ {...dropHandlers}>+ {isFileDragOver && (+ <div className={styles.fileDropOverlay} aria-live="polite">+ <span className={styles.fileDropOverlayIcon}>+ <Icon name="file-up" size="2.5rem" />+ </span>+ {t(+ "workbench.dropOverlay",+ "Drop files to add them to the workbench",+ )}+ </div>+ )}{/* Phone only: above that the rail carries the bell, and here no bar does. */}{isPhone && !showWorkbenchBar && topControlsAvailable && (<div style={{ position: "absolute", top: 12, right: 12, zIndex: 20 }}>diff --git a/frontend/editor/src/core/components/layout/useWorkbenchFileDrop.ts b/frontend/editor/src/core/components/layout/useWorkbenchFileDrop.tsnew file mode 100644index 0000000000..9d168f6932--- /dev/null+++ b/frontend/editor/src/core/components/layout/useWorkbenchFileDrop.ts@@ -0,0 +1,108 @@+import { useSyncExternalStore, type DragEvent } from "react";+import { useTranslation } from "react-i18next";+import { useFileSelectors } from "@app/contexts/FileContext";+import { useFileHandler } from "@app/hooks/useFileHandler";+import { useDropzoneFiles } from "@app/hooks/useDropzoneFiles";+import { alert } from "@app/components/toast";++// One drag state shared by every surface given these handlers (the workbench+// and the file sidebar), so the overlay the workbench draws stays up while the+// pointer moves from one to the other. Every child the pointer crosses fires its+// own enter/leave pair, so a depth count, not the last event, says whether the+// drag is still over any of them.+let dragDepth = 0;+let dragOver = false;+const listeners = new Set<() => void>();++function setDragDepth(depth: number) {+ dragDepth = Math.max(0, depth);+ const next = dragDepth > 0;+ if (next === dragOver) return;+ dragOver = next;+ listeners.forEach((listener) => listener());+}++function subscribe(listener: () => void) {+ listeners.add(listener);+ return () => listeners.delete(listener);+}++/** Whether files from outside the app are being dragged over any drop surface. */+export function useIsWorkbenchFileDragOver(): boolean {+ return useSyncExternalStore(subscribe, () => dragOver);+}++/**+ * Turns the element given `dropHandlers` into a target for files dragged in+ * from outside the app, adding them to the workbench. In-app drags (page and+ * file reorders) carry no "Files" type and pass straight through. While+ * `enabled` is false every handler is a no-op.+ */+export function useWorkbenchFileDrop(enabled: boolean) {+ const { t } = useTranslation();+ const { addFiles } = useFileHandler();+ const getDropzoneFiles = useDropzoneFiles();+ const fileSelectors = useFileSelectors();++ // React bubbles events out of portals, so a drop on a modal's own dropzone+ // would otherwise reach here too; only the element's real subtree counts.+ const isExternalFileDrag = (e: DragEvent<HTMLElement>) =>+ enabled &&+ e.currentTarget.contains(e.target as Node) &&+ e.dataTransfer.types.includes("Files");++ const reportFailure = (cause: unknown, dropped: number, added: number) => {+ // ZIP extraction can add more files than were dropped, hence the floor.+ const failed = Math.max(1, dropped - added);+ alert({+ alertType: "error",+ title:+ dropped === 1+ ? t("workbench.dropFailedSingle", "Your file couldn't be added")+ : t(+ "workbench.dropFailedSome",+ "{{failed}} of your files couldn't be added",+ { failed },+ ),+ body: cause instanceof Error ? cause.message : undefined,+ expandable: false,+ durationMs: 5000,+ });+ };++ // WebKit (the macOS desktop webview) only keeps an element as the drop+ // target if dragenter is cancelled too; Chromium settles for dragover.+ const onDragEnter = (e: DragEvent<HTMLElement>) => {+ if (!isExternalFileDrag(e)) return;+ e.preventDefault();+ setDragDepth(dragDepth + 1);+ };+ const onDragLeave = (e: DragEvent<HTMLElement>) => {+ if (!isExternalFileDrag(e)) return;+ setDragDepth(dragDepth - 1);+ };+ const onDragOver = (e: DragEvent<HTMLElement>) => {+ if (!isExternalFileDrag(e)) return;+ e.preventDefault();+ e.dataTransfer.dropEffect = "copy";+ };+ const onDrop = async (e: DragEvent<HTMLElement>) => {+ if (!isExternalFileDrag(e)) return;+ e.preventDefault();+ setDragDepth(0);+ const dropped = await getDropzoneFiles(e);+ const files = dropped.filter((item) => item instanceof File);+ if (files.length === 0) return;+ const openBefore = fileSelectors.getStirlingFileStubs().length;+ try {+ await addFiles(files);+ } catch (cause) {+ // addFiles dispatches in chunks, so a mid-batch failure leaves the+ // earlier files open.+ const added = fileSelectors.getStirlingFileStubs().length - openBefore;+ reportFailure(cause, files.length, added);+ }+ };++ return { onDragEnter, onDragLeave, onDragOver, onDrop };+}diff --git a/frontend/editor/src/core/components/shared/FileSidebar.css b/frontend/editor/src/core/components/shared/FileSidebar.cssindex 85cd2a599c..2fa20b3970 100644--- a/frontend/editor/src/core/components/shared/FileSidebar.css+++ b/frontend/editor/src/core/components/shared/FileSidebar.css@@ -116,42 +116,6 @@/* The footer is the shared <NavFooter>: it brings its own boxes and padding,so this class only positions it in the column. */-/* ---- Native file drag-and-drop ---- */-.file-sidebar[data-file-drag-over] {- outline: 2px dashed var(--mantine-color-blue-6, var(--c-primary));- outline-offset: -4px;-}--.file-sidebar-drop-overlay {- position: absolute;- inset: 0;- z-index: 20;- display: flex;- flex-direction: column;- align-items: center;- justify-content: center;- gap: 8px;- padding: 12px;- text-align: center;- pointer-events: none;- background-color: color-mix(- in srgb,- var(--mantine-color-blue-6, var(--c-primary)) 12%,- var(--c-bg-raised)- );-}--.file-sidebar-drop-overlay-icon {- color: var(--c-accent-text) !important;- font-size: 28px !important;-}--.file-sidebar-drop-overlay-text {- font-size: 13px;- font-weight: 600;- color: var(--c-accent-text);-}-/* ---- Scrollable content ---- *//* This is a flex column - action rows are fixed, only the file list scrolls */.file-sidebar-scroll {diff --git a/frontend/editor/src/core/components/shared/FileSidebar.tsx b/frontend/editor/src/core/components/shared/FileSidebar.tsxindex 058ade1fc2..2874cbcfa4 100644--- a/frontend/editor/src/core/components/shared/FileSidebar.tsx+++ b/frontend/editor/src/core/components/shared/FileSidebar.tsx@@ -67,6 +67,7 @@ import { FolderTreeSidebar } from "@app/components/filesPage/FolderTreeSidebar";import { useFilesPage } from "@app/contexts/FilesPageContext";import type { FolderId, FolderRecord } from "@app/types/folder";import { useToolEligibleFileIds } from "@app/contexts/ToolFileEligibilityContext";+import { useWorkbenchFileDrop } from "@app/components/layout/useWorkbenchFileDrop";import "@app/components/shared/FileSidebar.css";// Shared with the processor sidebar via tokens, so the two cannot drift.@@ -196,19 +197,6 @@ function SidebarActionRow({ action }: { action: SidebarAction }) {);}-function FileDropOverlay({ show }: { show: boolean }) {- const { t } = useTranslation();- if (!show) return null;- return (- <div className="file-sidebar-drop-overlay" aria-hidden="true">- <Icon name="file-up" className="file-sidebar-drop-overlay-icon" />- <span className="file-sidebar-drop-overlay-text">- {t("fileSidebar.dropToAdd", "Drop files to add")}- </span>- </div>- );-}-interface LibraryHeaderProps {stubs: StirlingFileStub[];scrolled: boolean;@@ -1048,48 +1036,9 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(return () => onRegisterOpenFromComputer(null);}, [onRegisterOpenFromComputer, openNativeFilePicker]);- // Internal folder drags have their own payloads and must bypass file ingestion.- const [isFileDragOver, setIsFileDragOver] = useState(false);- const dragDepth = useRef(0);-- const isNativeFileDrag = (e: React.DragEvent) =>- Array.from(e.dataTransfer.types).includes("Files");-- const handleDragEnter = useCallback((e: React.DragEvent) => {- if (!isNativeFileDrag(e)) return;- e.preventDefault();- dragDepth.current += 1;- setIsFileDragOver(true);- }, []);-- const handleDragOver = useCallback((e: React.DragEvent) => {- if (!isNativeFileDrag(e)) return;- // Required so the browser fires `drop` rather than opening the file.- e.preventDefault();- e.dataTransfer.dropEffect = "copy";- }, []);-- const handleDragLeave = useCallback((e: React.DragEvent) => {- if (!isNativeFileDrag(e)) return;- // dragenter/leave fire per child element; the counter keeps the overlay- // stable until the cursor genuinely leaves the sidebar.- dragDepth.current -= 1;- if (dragDepth.current <= 0) {- dragDepth.current = 0;- setIsFileDragOver(false);- }- }, []);-- const handleDrop = useCallback(- async (e: React.DragEvent) => {- if (!isNativeFileDrag(e)) return;- e.preventDefault();- dragDepth.current = 0;- setIsFileDragOver(false);- await ingestFiles(Array.from(e.dataTransfer.files ?? []));- },- [ingestFiles],- );+ // Drops here go through the workbench's target, whose overlay covers the+ // workbench rather than this sidebar.+ const dropHandlers = useWorkbenchFileDrop(true);const eligibleFileIds = useToolEligibleFileIds();@@ -1194,13 +1143,8 @@ const FileSidebar = forwardRef<HTMLDivElement, FileSidebarProps>(}}data-sidebar="file-sidebar"data-tour="quick-access-bar"- data-file-drag-over={isFileDragOver || undefined}- onDragEnter={handleDragEnter}- onDragOver={handleDragOver}- onDragLeave={handleDragLeave}- onDrop={handleDrop}+ {...dropHandlers}>- <FileDropOverlay show={isFileDragOver} /><div className="file-sidebar-inner"><SidebarHeader />diff --git a/frontend/editor/src/core/components/shared/LandingPage.css b/frontend/editor/src/core/components/shared/LandingPage.cssindex ab1b6234ec..d6b4c49170 100644--- a/frontend/editor/src/core/components/shared/LandingPage.css+++ b/frontend/editor/src/core/components/shared/LandingPage.css@@ -134,15 +134,3 @@.landing-bar--strong {background-color: var(--c-illustration-line-strong);}--/* Dropzone accept/reject outlines. Mantine 8 no longer supports nested- * `&[data-accept]` selectors inside the `styles` prop object, so these are- * plain CSS attribute selectors on a class applied to the Dropzone root. */-.landing-dropzone[data-accept] {- outline: 2px dashed var(--c-primary);- outline-offset: 4px;-}-.landing-dropzone[data-reject] {- outline: 2px dashed var(--mantine-color-red-6);- outline-offset: 4px;-}diff --git a/frontend/editor/src/core/components/shared/LandingPage.tsx b/frontend/editor/src/core/components/shared/LandingPage.tsxindex 5515201f21..49bf6c07ac 100644--- a/frontend/editor/src/core/components/shared/LandingPage.tsx+++ b/frontend/editor/src/core/components/shared/LandingPage.tsx@@ -1,26 +1,17 @@import React, { useState } from "react";import { Container } from "@mantine/core";-import { Dropzone } from "@mantine/dropzone";import { useFileHandler } from "@app/hooks/useFileHandler";-import { useFileActionTerminology } from "@app/hooks/useFileActionTerminology";import MobileUploadModal from "@app/components/shared/MobileUploadModal";import { openFilesFromDisk } from "@app/services/openFilesFromDisk";import { Logo } from "@app/ui/Logo";import { LandingActions } from "@app/components/shared/LandingActions";-import { useDropzoneFiles } from "@app/hooks/useDropzoneFiles";import "@app/components/shared/LandingPage.css";const LandingPage = () => {const { addFiles } = useFileHandler();- const getDropzoneFiles = useDropzoneFiles();const fileInputRef = React.useRef<HTMLInputElement | null>(null);- const terminology = useFileActionTerminology();const [mobileUploadModalOpen, setMobileUploadModalOpen] = useState(false);- const handleFileDrop = async (files: File[]) => {- await addFiles(files);- };-const handleNativeUploadClick = async () => {const files = await openFilesFromDisk({multiple: true,@@ -55,30 +46,7 @@ const LandingPage = () => {className="flex min-h-0 flex-col"style={{ position: "relative" }}>- <Dropzone- onDrop={handleFileDrop}- multiple- activateOnClick={false}- useFsAccessApi={false}- getFilesFromEvent={getDropzoneFiles}- enablePointerEvents- aria-label={terminology.dropFilesHere}- className="landing-dropzone flex min-h-0 flex-1 cursor-default flex-col items-center justify-center border-none bg-transparent px-4 py-8 shadow-none outline-none"- styles={{- root: {- border: "none !important",- backgroundColor: "transparent",- overflow: "visible",- },- inner: {- overflow: "visible",- display: "flex",- flexDirection: "column",- alignItems: "center",- width: "100%",- },- }}- >+ <div className="flex min-h-0 w-full flex-1 flex-col items-center justify-center overflow-visible px-4 py-8"><Logovariant="iconAndText"orientation="vertical"@@ -97,7 +65,7 @@ const LandingPage = () => {onFileSelect={handleFileSelect}/></div>- </Dropzone>+ </div><MobileUploadModalopened={mobileUploadModalOpen}diff --git a/frontend/editor/src/core/tests/stubbed/merge-tool.spec.ts b/frontend/editor/src/core/tests/stubbed/merge-tool.spec.tsindex 4db02a54cd..f3b802edbb 100644--- a/frontend/editor/src/core/tests/stubbed/merge-tool.spec.ts+++ b/frontend/editor/src/core/tests/stubbed/merge-tool.spec.ts@@ -31,10 +31,9 @@ test.describe("5. Merge Tool", () => {await expect(mergeButton).toBeVisible();await expect(mergeButton).toBeDisabled();- // Step 4: Verify the file upload drop zone is visible- // (input[type="file"] is excluded — it is hidden in the FileSidebar)+ // Step 4: Verify the landing page's upload action is displayedawait expect(- page.locator('[class*="upload"], [class*="dropzone"]').first(),+ page.getByRole("button", { name: /^Add Files$/i }).first(),).toBeVisible();});});diff --git a/frontend/editor/src/core/tests/stubbed/tool-pages-common.spec.ts b/frontend/editor/src/core/tests/stubbed/tool-pages-common.spec.tsindex d50ebd9b74..92d9c16829 100644--- a/frontend/editor/src/core/tests/stubbed/tool-pages-common.spec.ts+++ b/frontend/editor/src/core/tests/stubbed/tool-pages-common.spec.ts@@ -16,10 +16,9 @@ test.describe("4. PDF Tool Pages - Common Patterns", () => {await expect(actionButton).toBeVisible({ timeout: 10000 });await expect(actionButton).toBeDisabled();- // Step 3: Verify the file upload area is displayed- // (input[type="file"] is excluded — it is hidden in the FileSidebar)+ // Step 3: Verify the landing page's upload action is displayedawait expect(- page.locator('[class*="upload"], [class*="dropzone"]').first(),+ page.getByRole("button", { name: /^Add Files$/i }).first(),).toBeVisible();// Step 4: Verify that clicking the disabled action button does nothingdiff --git a/frontend/editor/src/core/tools/pdfTextEditor/components/PageStage.tsx b/frontend/editor/src/core/tools/pdfTextEditor/components/PageStage.tsxindex afc6bdf384..a053aa5a54 100644--- a/frontend/editor/src/core/tools/pdfTextEditor/components/PageStage.tsx+++ b/frontend/editor/src/core/tools/pdfTextEditor/components/PageStage.tsx@@ -210,18 +210,23 @@ export function PageStage() {pos="relative"ref={stageRootRef}style={{ flex: 1, minHeight: 0 }}+ // Each handler stops the event: the workbench wraps this stage and would+ // otherwise also add the dropped file to the workspace.onDragEnter={(e) => {+ e.stopPropagation();if (Array.from(e.dataTransfer?.types ?? []).includes("Files")) {dragCountRef.current += 1;setDraggingFile(true);}}}onDragOver={(e) => {+ e.stopPropagation();if (Array.from(e.dataTransfer?.types ?? []).includes("Files")) {e.preventDefault();}}}- onDragLeave={() => {+ onDragLeave={(e) => {+ e.stopPropagation();dragCountRef.current = Math.max(0, dragCountRef.current - 1);if (dragCountRef.current === 0) setDraggingFile(false);}}@@ -229,6 +234,7 @@ export function PageStage() {// ALWAYS claim the drop: without preventDefault the browser navigates// the tab to the dropped file, discarding the editor.e.preventDefault();+ e.stopPropagation();dragCountRef.current = 0;setDraggingFile(false);const files = e.dataTransfer?.files;