|
|
|
@ -7,7 +7,6 @@ import { FileExplorerProps, File } from './types' |
|
|
|
|
import * as helper from '../../../../../apps/remix-ide/src/lib/helper' |
|
|
|
|
|
|
|
|
|
import './css/file-explorer.css' |
|
|
|
|
import { connected } from 'process' |
|
|
|
|
|
|
|
|
|
export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
const { filesProvider, name, registry, plugin } = props |
|
|
|
@ -394,103 +393,94 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
// register to event of the file provider
|
|
|
|
|
// files.event.register('fileRemoved', fileRemoved)
|
|
|
|
|
// files.event.register('fileRenamed', fileRenamed)
|
|
|
|
|
props.filesProvider.event.register('fileRenamedError', (error) => { |
|
|
|
|
// modalDialogCustom.alert(error)
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
props.filesProvider.event.register('fileAdded', async (filePath: string) => { |
|
|
|
|
const pathArr = filePath.split('/') |
|
|
|
|
const hasChild = pathArr.length > 2 |
|
|
|
|
|
|
|
|
|
if (hasChild) { |
|
|
|
|
const expandPath = pathArr.map((path, index) => { |
|
|
|
|
return [...pathArr.slice(0, index)].join('/') |
|
|
|
|
}).filter(path => path && (path !== name)) |
|
|
|
|
|
|
|
|
|
if (state.files.findIndex(item => item.path === expandPath[0]) === -1) { |
|
|
|
|
const dir = buildTree(expandPath) |
|
|
|
|
let files = [dir, ...state.files] |
|
|
|
|
|
|
|
|
|
await Promise.all(expandPath.map(async path => { |
|
|
|
|
files = await resolveDirectory(path, files) |
|
|
|
|
})) |
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, files, expandPath: [...state.expandPath, ...expandPath] } |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
console.log('called here again') |
|
|
|
|
console.log('expandPath[expandPath.length - 1]: ', expandPath[expandPath.length - 1]) |
|
|
|
|
if (state.expandPath.findIndex(path => path === expandPath[expandPath.length - 1]) !== -1) return |
|
|
|
|
const dir = state.files.find(item => item.path === expandPath[0]) |
|
|
|
|
let files = [{ |
|
|
|
|
...dir, |
|
|
|
|
child: [...(await fetchDirectoryContent(dir.path))] |
|
|
|
|
}, ...state.files.filter(item => item.path !== expandPath[0])] |
|
|
|
|
console.log('files: ', files) |
|
|
|
|
|
|
|
|
|
await Promise.all(expandPath.map(async path => { |
|
|
|
|
files = await resolveDirectory(path, files) |
|
|
|
|
})) |
|
|
|
|
const updatedPath = [state.expandPath.filter(key => key && (typeof key === 'string') && !key.startsWith(expandPath[0]))] |
|
|
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, files, expandPath: [...updatedPath, ...expandPath] } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
addFile(pathArr[0], filePath) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
props.filesProvider.event.register('folderAdded', async (folderpath: string) => { |
|
|
|
|
const pathArr = folderpath.split('/') |
|
|
|
|
const hasChild = pathArr.length > 2 |
|
|
|
|
|
|
|
|
|
if (hasChild) { |
|
|
|
|
const expandPath = pathArr.map((path, index) => { |
|
|
|
|
return [...pathArr.slice(0, index)].join('/') |
|
|
|
|
}).filter(path => path && (path !== name)) |
|
|
|
|
|
|
|
|
|
if (state.files.findIndex(item => item.path === expandPath[0]) === -1) { |
|
|
|
|
const dir = buildTree(expandPath) |
|
|
|
|
let files = [dir, ...state.files] |
|
|
|
|
|
|
|
|
|
await Promise.all(expandPath.map(async path => { |
|
|
|
|
files = await resolveDirectory(path, files) |
|
|
|
|
})) |
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, files, expandPath: [...state.expandPath, ...expandPath] } |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
if (state.files.findIndex(item => item.path === expandPath[expandPath.length - 1]) !== -1) return |
|
|
|
|
const dir = state.files.find(item => item.path === expandPath[0]) |
|
|
|
|
let files = [{ |
|
|
|
|
...dir, |
|
|
|
|
child: [...(await fetchDirectoryContent(dir.path))] |
|
|
|
|
}, ...state.files.filter(item => item.path !== expandPath[0])] |
|
|
|
|
|
|
|
|
|
await Promise.all(expandPath.map(async path => { |
|
|
|
|
files = await resolveDirectory(path, files) |
|
|
|
|
})) |
|
|
|
|
const updatedPath = [state.expandPath.filter(key => key && (typeof key === 'string') && !key.startsWith(expandPath[0]))] |
|
|
|
|
// props.filesProvider.event.register('fileRenamedError', (error) => {
|
|
|
|
|
// // modalDialogCustom.alert(error)
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, files, expandPath: [...updatedPath, ...expandPath] } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
addFolder(pathArr[0], folderpath) |
|
|
|
|
} |
|
|
|
|
// props.filesProvider.event.register('fileAdded', async (filePath: string) => {
|
|
|
|
|
// const pathArr = filePath.split('/')
|
|
|
|
|
// const hasChild = pathArr.length > 2
|
|
|
|
|
|
|
|
|
|
// if (hasChild) {
|
|
|
|
|
// const expandPath = pathArr.map((path, index) => {
|
|
|
|
|
// return [...pathArr.slice(0, index)].join('/')
|
|
|
|
|
// }).filter(path => path && (path !== name))
|
|
|
|
|
|
|
|
|
|
// if (state.files.findIndex(item => item.path === expandPath[0]) === -1) {
|
|
|
|
|
// const dir = buildTree(expandPath)
|
|
|
|
|
// let files = [dir, ...state.files]
|
|
|
|
|
|
|
|
|
|
// await Promise.all(expandPath.map(async path => {
|
|
|
|
|
// files = await resolveDirectory(path, files)
|
|
|
|
|
// }))
|
|
|
|
|
// setState(prevState => {
|
|
|
|
|
// return { ...prevState, files, expandPath: [...state.expandPath, ...expandPath] }
|
|
|
|
|
// })
|
|
|
|
|
// } else {
|
|
|
|
|
// console.log('called here again')
|
|
|
|
|
// console.log('expandPath[expandPath.length - 1]: ', expandPath[expandPath.length - 1])
|
|
|
|
|
// if (state.expandPath.findIndex(path => path === expandPath[expandPath.length - 1]) !== -1) return
|
|
|
|
|
// const dir = state.files.find(item => item.path === expandPath[0])
|
|
|
|
|
// let files = [{
|
|
|
|
|
// ...dir,
|
|
|
|
|
// child: [...(await fetchDirectoryContent(dir.path))]
|
|
|
|
|
// }, ...state.files.filter(item => item.path !== expandPath[0])]
|
|
|
|
|
// console.log('files: ', files)
|
|
|
|
|
|
|
|
|
|
// await Promise.all(expandPath.map(async path => {
|
|
|
|
|
// files = await resolveDirectory(path, files)
|
|
|
|
|
// }))
|
|
|
|
|
// const updatedPath = [state.expandPath.filter(key => key && (typeof key === 'string') && !key.startsWith(expandPath[0]))]
|
|
|
|
|
|
|
|
|
|
// setState(prevState => {
|
|
|
|
|
// return { ...prevState, files, expandPath: [...updatedPath, ...expandPath] }
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// addFile(pathArr[0], filePath)
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// folderpath = folderpath.split('/').slice(0, -1).join('/')
|
|
|
|
|
// self.files.resolveDirectory(folderpath, (error, fileTree) => {
|
|
|
|
|
// if (error) console.error(error)
|
|
|
|
|
// if (!fileTree) return
|
|
|
|
|
// fileTree = normalize(folderpath, fileTree)
|
|
|
|
|
// self.treeView.updateNodeFromJSON(folderpath, fileTree, true)
|
|
|
|
|
// if (!self.treeView.isExpanded(folderpath)) self.treeView.expand(folderpath)
|
|
|
|
|
// })
|
|
|
|
|
}) |
|
|
|
|
// props.filesProvider.event.register('folderAdded', async (folderpath: string) => {
|
|
|
|
|
// const pathArr = folderpath.split('/')
|
|
|
|
|
// const hasChild = pathArr.length > 2
|
|
|
|
|
|
|
|
|
|
// if (hasChild) {
|
|
|
|
|
// const expandPath = pathArr.map((path, index) => {
|
|
|
|
|
// return [...pathArr.slice(0, index)].join('/')
|
|
|
|
|
// }).filter(path => path && (path !== name))
|
|
|
|
|
|
|
|
|
|
// if (state.files.findIndex(item => item.path === expandPath[0]) === -1) {
|
|
|
|
|
// const dir = buildTree(expandPath)
|
|
|
|
|
// let files = [dir, ...state.files]
|
|
|
|
|
|
|
|
|
|
// await Promise.all(expandPath.map(async path => {
|
|
|
|
|
// files = await resolveDirectory(path, files)
|
|
|
|
|
// }))
|
|
|
|
|
// setState(prevState => {
|
|
|
|
|
// return { ...prevState, files, expandPath: [...state.expandPath, ...expandPath] }
|
|
|
|
|
// })
|
|
|
|
|
// } else {
|
|
|
|
|
// if (state.files.findIndex(item => item.path === expandPath[expandPath.length - 1]) !== -1) return
|
|
|
|
|
// const dir = state.files.find(item => item.path === expandPath[0])
|
|
|
|
|
// let files = [{
|
|
|
|
|
// ...dir,
|
|
|
|
|
// child: [...(await fetchDirectoryContent(dir.path))]
|
|
|
|
|
// }, ...state.files.filter(item => item.path !== expandPath[0])]
|
|
|
|
|
|
|
|
|
|
// await Promise.all(expandPath.map(async path => {
|
|
|
|
|
// files = await resolveDirectory(path, files)
|
|
|
|
|
// }))
|
|
|
|
|
// const updatedPath = [state.expandPath.filter(key => key && (typeof key === 'string') && !key.startsWith(expandPath[0]))]
|
|
|
|
|
|
|
|
|
|
// setState(prevState => {
|
|
|
|
|
// return { ...prevState, files, expandPath: [...updatedPath, ...expandPath] }
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// addFolder(pathArr[0], folderpath)
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
const handleClickFile = (path: string) => { |
|
|
|
|
state.fileManager.open(path) |
|
|
|
@ -648,8 +638,8 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
<div key={index}> |
|
|
|
|
<TreeViewItem |
|
|
|
|
id={`treeViewItem${file.path}`} |
|
|
|
|
iconX='pr-3 far fa-folder' |
|
|
|
|
iconY='pr-3 far fa-folder-open' |
|
|
|
|
iconX='pr-3 fa fa-folder text-info' |
|
|
|
|
iconY='pr-3 fa fa-folder-open text-info' |
|
|
|
|
key={`${file.path + index}`} |
|
|
|
|
label={label(file)} |
|
|
|
|
onClick={(e) => { |
|
|
|
|