|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import React, { SyntheticEvent, useContext, useEffect, useRef, useState } from 'react' |
|
|
|
|
import { DragStructure, FileType, FlatTreeDropProps } from '../types' |
|
|
|
|
import { getEventTarget } from '../utils/getEventTarget' |
|
|
|
|
import { buildMultiSelectedItemProfiles, getEventTarget } from '../utils/getEventTarget' |
|
|
|
|
import { extractParentFromKey } from '@remix-ui/helper' |
|
|
|
|
import { FileSystemContext } from '../contexts' |
|
|
|
|
|
|
|
|
@ -14,20 +14,14 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
|
// folder to open
|
|
|
|
|
const [folderToOpen, setFolderToOpen] = useState<string>() |
|
|
|
|
const globalFEContext = useContext(FileSystemContext) |
|
|
|
|
const [selectedItems, setSelectedItems] = useState<DragStructure[]>([]) |
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
======= |
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
|
|
}, [globalFEContext.fs.focusElement.length]) |
|
|
|
|
const [selectedItems, setSelectedItems] = useState<DragStructure[]>([]) |
|
|
|
|
|
|
|
|
|
>>>>>>> consume function to move files silently |
|
|
|
|
const onDragOver = async (e: SyntheticEvent) => { |
|
|
|
|
e.preventDefault() |
|
|
|
|
|
|
|
|
|
const target = await getEventTarget(e) |
|
|
|
|
buildMultiSelectedItemProfiles(target) |
|
|
|
|
|
|
|
|
|
if (!target || !target.path) { |
|
|
|
|
clearTimeout(timer) |
|
|
|
|
setFolderToOpen(null) |
|
|
|
@ -56,7 +50,7 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
|
event.preventDefault() |
|
|
|
|
|
|
|
|
|
const target = await getEventTarget(event) |
|
|
|
|
const items = buildMultiSelectedItemProfiles(target) |
|
|
|
|
// const items = buildMultiSelectedItemProfiles(target)
|
|
|
|
|
const filePaths = [] |
|
|
|
|
|
|
|
|
|
let dragDestination: any |
|
|
|
@ -69,62 +63,32 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
|
dragDestination = getFlatTreeItem(target.path) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
items.forEach((item) => filePaths.push(item.path)) |
|
|
|
|
props.selectedItems.forEach((item) => filePaths.push(item.path)) |
|
|
|
|
props.setFilesSelected(filePaths) |
|
|
|
|
|
|
|
|
|
if (dragDestination.isDirectory) { |
|
|
|
|
if (dragSource.isDirectory) { |
|
|
|
|
moveFolder(dragDestination.path, [dragSource.path]) |
|
|
|
|
await moveFoldersSilently(items, dragDestination.path) |
|
|
|
|
moveFolder(dragDestination.path, dragSource.path) |
|
|
|
|
await moveFoldersSilently(props.selectedItems, dragDestination.path) |
|
|
|
|
} else { |
|
|
|
|
moveFile(dragDestination.path, [dragSource.path]) |
|
|
|
|
await moveFilesSilently(items, dragDestination.path) |
|
|
|
|
moveFile(dragDestination.path, dragSource.path) |
|
|
|
|
await moveFilesSilently(props.selectedItems, dragDestination.path) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
const path = extractParentFromKey(dragDestination.path) || '/' |
|
|
|
|
|
|
|
|
|
if (dragSource.isDirectory) { |
|
|
|
|
moveFolder(path, [dragSource.path]) |
|
|
|
|
await moveFoldersSilently(items, dragDestination.path) |
|
|
|
|
moveFolder(path, dragSource.path) |
|
|
|
|
await moveFoldersSilently(props.selectedItems, dragDestination.path) |
|
|
|
|
} else { |
|
|
|
|
moveFile(path, [dragSource.path]) |
|
|
|
|
await moveFilesSilently(items, dragDestination.path) |
|
|
|
|
moveFile(path, dragSource.path) |
|
|
|
|
await moveFilesSilently(props.selectedItems, dragDestination.path) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
document.querySelectorAll('li.remix_selected').forEach(item => { |
|
|
|
|
item.classList.remove('remix_selected') |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* When multiple files are selected in FileExplorer, |
|
|
|
|
* and these files are dragged to a target folder, |
|
|
|
|
* this function will build the profile of each selected item |
|
|
|
|
* in FileExplorer so they can be moved when dropped |
|
|
|
|
* @param target - Initial target item in FileExplorer |
|
|
|
|
* @returns - {DragStructure} Array of selected items |
|
|
|
|
*/ |
|
|
|
|
const buildMultiSelectedItemProfiles = (target: { |
|
|
|
|
path: string |
|
|
|
|
type: string |
|
|
|
|
content: string |
|
|
|
|
position: { |
|
|
|
|
top: number |
|
|
|
|
left: number |
|
|
|
|
} |
|
|
|
|
}) => { |
|
|
|
|
const selectItems = [] |
|
|
|
|
document.querySelectorAll('li.remix_selected').forEach(item => { |
|
|
|
|
|
|
|
|
|
const dragTarget = { |
|
|
|
|
position: { top: target?.position.top || 0, left: target?.position.left || 0 }, |
|
|
|
|
path: item.getAttribute('data-path') || item.getAttribute('data-label-path') || '', |
|
|
|
|
type: item.getAttribute('data-type') || item.getAttribute('data-label-type') || '', |
|
|
|
|
content: item.textContent || '' |
|
|
|
|
} |
|
|
|
|
selectItems.push(dragTarget) |
|
|
|
|
document.querySelectorAll('li.remixui_selected').forEach(item => { |
|
|
|
|
item.classList.remove('remixui_selected') |
|
|
|
|
item.classList.remove('bg-secondary') |
|
|
|
|
}) |
|
|
|
|
return selectItems |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -138,7 +102,7 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
|
const promises = items.filter(item => item.path !== targetPath) |
|
|
|
|
.map(async (item) => { |
|
|
|
|
if (item.type === 'file') { |
|
|
|
|
await props.moveFileSilently(targetPath, [item.path]) |
|
|
|
|
await props.moveFileSilently(targetPath, item.path) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
await Promise.all(promises) |
|
|
|
@ -155,7 +119,7 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { |
|
|
|
|
const promises = items.filter(item => item.path !== targetPath) |
|
|
|
|
.map(async (item) => { |
|
|
|
|
if (item.type === 'folder') { |
|
|
|
|
await props.moveFolderSilently(targetPath, [item.path]) |
|
|
|
|
await props.moveFolderSilently(targetPath, item.path) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
await Promise.all(promises) |
|
|
|
|