diff --git a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx index 683b938fb4e..9c7e581306a 100644 --- a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx +++ b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx @@ -55,7 +55,7 @@ const tabsReducer = (state: ITabsState, action: ITabsAction) => { return { ...state, currentExt: action.ext, - selectedIndex: action.payload + selectedIndex: action.payload, } case 'SET_FILE_DECORATIONS': return { @@ -155,7 +155,7 @@ export const TabsUI = (props: TabsUIProps) => { } const setFileDecorations = (fileStates: fileDecoration[]) => { - getAI().then(value => setAI_switch(value)).catch(error => console.log(error)) + getAI().then((value) => setAI_switch(value)).catch((error) => console.log(error)) dispatch({ type: 'SET_FILE_DECORATIONS', payload: fileStates }) } @@ -187,8 +187,31 @@ export const TabsUI = (props: TabsUIProps) => { else return '' } + const handleFileDrop = (event: React.DragEvent) => { + event.preventDefault() + if (event.dataTransfer?.files.length > 0) { + const files = event.dataTransfer.files + + for (const file of files) { + const reader = new FileReader() + reader.readAsText(file) + + reader.onload = (e) => { + props.plugin.call('fileManager', 'writeFile', '/tmp/' + file.name, e.target?.result) + } + } + } + } + return ( -
+
{ + e.preventDefault() + }} + >
{ ) : ( )} - - } - > + }> @@ -238,7 +258,8 @@ export const TabsUI = (props: TabsUIProps) => { - }> -
- - {((tabsState.currentExt === 'sol') || (tabsState.currentExt === 'vy') || (tabsState.currentExt === 'circom')) ? ( - - ) : ( - - )} - - } - > + + +
+ {tabsState.currentExt === 'sol' || tabsState.currentExt === 'vy' || tabsState.currentExt === 'circom' ? : }}> - - {tabsState.currentExt === 'sol' ? ( - !ai_switch ? ( - - ) : () - ) : ( - - )} - - } - > + {tabsState.currentExt === 'sol' ? !ai_switch ? : : }}>
-
+
}> props.onZoomOut()}> @@ -339,7 +335,7 @@ export const TabsUI = (props: TabsUIProps) => { dispatch({ type: 'SELECT_INDEX', payload: index, - ext: getExt(props.tabs[currentIndexRef.current].name) + ext: getExt(props.tabs[currentIndexRef.current].name), }) }} > diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index 9853cf3739f..ba777f9662f 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -640,6 +640,7 @@ export const FileExplorer = (props: FileExplorerProps) => { handleClickFolder={handleClickFolder} createNewFile={props.createNewFile} createNewFolder={props.createNewFolder} + plugin={plugin} deletePath={deletePath} editPath={props.editModeOn} fileTarget={feTarget} diff --git a/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx b/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx index 693fc496bd1..32e56f89a87 100644 --- a/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx +++ b/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx @@ -5,7 +5,6 @@ import { extractParentFromKey } from '@remix-ui/helper' import { FileSystemContext } from '../contexts' export const FlatTreeDrop = (props: FlatTreeDropProps) => { - const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props // delay timer const [timer, setTimer] = useState() @@ -29,7 +28,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { setFolderToOpen(null) } if (dragDestination && dragDestination.isDirectory && !expandPath.includes(dragDestination.path) && folderToOpen !== dragDestination.path && props.handleClickFolder) { - setFolderToOpen(dragDestination.path) timer && clearTimeout(timer) setTimer( @@ -41,7 +39,7 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { } } - const onDrop = async (event: SyntheticEvent) => { + const onDrop = async (event: React.DragEvent) => { event.preventDefault() const target = await getEventTarget(event) @@ -51,12 +49,26 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { if (!target || !target.path) { dragDestination = { path: '/', - isDirectory: true + isDirectory: true, } } else { dragDestination = getFlatTreeItem(target.path) } + if (event.dataTransfer?.files.length > 0) { + const files = event.dataTransfer.files + + for (const file of files){ + const reader = new FileReader() + reader.readAsText(file) + + reader.onload = (e) => { + props.plugin.call('fileManager', 'writeFile', `${dragDestination.path}/${file.name}`, e.target?.result) + } + } + return + } + props.selectedItems.forEach((item) => filePaths.push(item.path)) props.setFilesSelected(filePaths) @@ -77,7 +89,8 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { * @returns Promise */ const moveItemsSilently = async (items: DragStructure[], targetPath: string) => { - const promises = items.filter(item => item.path !== targetPath) + const promises = items + .filter((item) => item.path !== targetPath) .map(async (item) => { if (item.type === 'file') { await props.moveFileSilently(targetPath, item.path) @@ -89,8 +102,9 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { props.resetMultiselect() } - return (
{props.children}
) + return ( +
+ {props.children} +
+ ) } diff --git a/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx b/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx index 8632d50a005..84f073b8521 100644 --- a/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx +++ b/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx @@ -48,6 +48,7 @@ interface FlatTreeProps { deletePath?: (path: string | string[]) => void | Promise editPath?: (path: string, type: string, isNew?: boolean) => void warnMovingItems: (srcs: string[], dests: string) => Promise + plugin: any } let mouseTimer: any = { @@ -143,12 +144,13 @@ export const FlatTree = (props: FlatTreeProps) => { } } - const onDragStart = async (event: SyntheticEvent) => { + const onDragStart = async (event: React.DragEvent) => { const target = await getEventTarget(event) setDragSource(flatTree.find((item) => item.path === target.path)) setIsDragging(true) buildMultiSelectedItemProfiles(target) setFilesSelected(selectedItems.map((item) => item.path)) + event.dataTransfer.setData('text/plain', target.path) } useEffect(() => { @@ -252,6 +254,11 @@ export const FlatTree = (props: FlatTreeProps) => { const Row = (index: number) => { const node = Object.keys(flatTree)[index] const file = flatTree[node] + + if (file.path.startsWith("tmp")){ + return
Temp File
+ } + return (
  • { expandPath={expandPath} selectedItems={selectedItems} setSelectedItems={setSelectedItems} + plugin={props.plugin} >
    > warnMovingItems: (srcs: string[], dest: string) => Promise + plugin: any } export type DragStructure = {