+ {fileTreeContainer && (
+
+ {isConnected ? null : }
+
+
+
+
+
+
+
+
+
+
+ )}
+
)
})
diff --git a/services/web/frontend/js/features/file-tree/contexts/file-tree-draggable.tsx b/services/web/frontend/js/features/file-tree/contexts/file-tree-draggable.tsx
index 32fd0974ab..df2c72b1c1 100644
--- a/services/web/frontend/js/features/file-tree/contexts/file-tree-draggable.tsx
+++ b/services/web/frontend/js/features/file-tree/contexts/file-tree-draggable.tsx
@@ -1,102 +1,87 @@
-import { useRef, useEffect, useState, FC } from 'react'
+import { useEffect, useState, FC, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import getDroppedFiles from '@uppy/utils/lib/getDroppedFiles'
-import { DndProvider, createDndContext, useDrag, useDrop } from 'react-dnd'
+import { DndProvider, DragSourceMonitor, useDrag, useDrop } from 'react-dnd'
import {
HTML5Backend,
getEmptyImage,
NativeTypes,
} from 'react-dnd-html5-backend'
-
import {
findAllInTreeOrThrow,
findAllFolderIdsInFolders,
} from '../util/find-in-tree'
-
import { useFileTreeActionable } from './file-tree-actionable'
-import { useFileTreeData } from '../../../shared/context/file-tree-data-context'
+import { useFileTreeData } from '@/shared/context/file-tree-data-context'
import { useFileTreeSelectable } from '../contexts/file-tree-selectable'
-import { useEditorContext } from '../../../shared/context/editor-context'
-
-// HACK ALERT
-// DnD binds drag and drop events on window and stop propagation if the dragged
-// item is not a DnD element. This break other drag and drop interfaces; in
-// particular in rich text.
-// This is a hacky workaround to avoid calling the DnD listeners when the
-// draggable or droppable element is not within a `dnd-container` element.
-const ModifiedBackend = (...args: any[]) => {
- function isDndChild(elt: Element): boolean {
- if (elt.getAttribute && elt.getAttribute('dnd-container')) return true
- if (!elt.parentNode) return false
- return isDndChild(elt.parentNode as Element)
- }
- // @ts-ignore
- const instance = new HTML5Backend(...args)
-
- const dragDropListeners = [
- 'handleTopDragStart',
- 'handleTopDragStartCapture',
- 'handleTopDragEndCapture',
- 'handleTopDragEnter',
- 'handleTopDragEnterCapture',
- 'handleTopDragLeaveCapture',
- 'handleTopDragOver',
- 'handleTopDragOverCapture',
- 'handleTopDrop',
- 'handleTopDropCapture',
- ]
-
- dragDropListeners.forEach(dragDropListener => {
- const originalListener = instance[dragDropListener]
- instance[dragDropListener] = (ev: Event, ...extraArgs: any[]) => {
- if (isDndChild(ev.target as Element)) originalListener(ev, ...extraArgs)
- }
- })
-
- return instance
-}
-
-const DndContext = createDndContext(ModifiedBackend)
+import { useEditorContext } from '@/shared/context/editor-context'
const DRAGGABLE_TYPE = 'ENTITY'
-export const FileTreeDraggableProvider: FC = ({ children }) => {
- const DndManager = useRef(DndContext)
+export const FileTreeDraggableProvider: FC<{
+ fileTreeContainer?: HTMLDivElement
+}> = ({ fileTreeContainer, children }) => {
+ const options = useMemo(
+ () => ({ rootElement: fileTreeContainer }),
+ [fileTreeContainer]
+ )
return (
-