|
|
@ -23,7 +23,6 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
key: '', |
|
|
|
key: '', |
|
|
|
type: 'folder' |
|
|
|
type: 'folder' |
|
|
|
}], |
|
|
|
}], |
|
|
|
focusPath: null, |
|
|
|
|
|
|
|
files: [], |
|
|
|
files: [], |
|
|
|
fileManager: null, |
|
|
|
fileManager: null, |
|
|
|
ctrlKey: false, |
|
|
|
ctrlKey: false, |
|
|
@ -56,6 +55,13 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
path: [], |
|
|
|
path: [], |
|
|
|
extension: [], |
|
|
|
extension: [], |
|
|
|
pattern: [] |
|
|
|
pattern: [] |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
id: 'run', |
|
|
|
|
|
|
|
name: 'Run', |
|
|
|
|
|
|
|
type: [], |
|
|
|
|
|
|
|
path: [], |
|
|
|
|
|
|
|
extension: ['.js'], |
|
|
|
|
|
|
|
pattern: [] |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
id: 'pushChangesToGist', |
|
|
|
id: 'pushChangesToGist', |
|
|
|
name: 'Push changes to gist', |
|
|
|
name: 'Push changes to gist', |
|
|
@ -78,11 +84,11 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
extension: [], |
|
|
|
extension: [], |
|
|
|
pattern: [] |
|
|
|
pattern: [] |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
id: 'run', |
|
|
|
id: 'copy', |
|
|
|
name: 'Run', |
|
|
|
name: 'Copy', |
|
|
|
type: [], |
|
|
|
type: ['folder', 'file'], |
|
|
|
path: [], |
|
|
|
path: [], |
|
|
|
extension: ['.js'], |
|
|
|
extension: [], |
|
|
|
pattern: [] |
|
|
|
pattern: [] |
|
|
|
}], |
|
|
|
}], |
|
|
|
focusContext: { |
|
|
|
focusContext: { |
|
|
@ -112,8 +118,10 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
toasterMsg: '', |
|
|
|
toasterMsg: '', |
|
|
|
mouseOverElement: null, |
|
|
|
mouseOverElement: null, |
|
|
|
showContextMenu: false, |
|
|
|
showContextMenu: false, |
|
|
|
reservedKeywords: [name, 'gist-'] |
|
|
|
reservedKeywords: [name, 'gist-'], |
|
|
|
|
|
|
|
copyElement: [] |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
const [canPaste, setcanPaste] = useState(false) |
|
|
|
const [fileSystem, dispatch] = useReducer(fileSystemReducer, fileSystemInitialState) |
|
|
|
const [fileSystem, dispatch] = useReducer(fileSystemReducer, fileSystemInitialState) |
|
|
|
const editRef = useRef(null) |
|
|
|
const editRef = useRef(null) |
|
|
|
|
|
|
|
|
|
|
@ -176,12 +184,7 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (contextMenuItems) { |
|
|
|
if (contextMenuItems) { |
|
|
|
setState(prevState => { |
|
|
|
addMenuItems(contextMenuItems) |
|
|
|
// filter duplicate items
|
|
|
|
|
|
|
|
const items = contextMenuItems.filter(({ name }) => prevState.actions.findIndex(action => action.name === name) === -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { ...prevState, actions: [...prevState.actions, ...items] } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, [contextMenuItems]) |
|
|
|
}, [contextMenuItems]) |
|
|
|
|
|
|
|
|
|
|
@ -223,6 +226,38 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}, [state.modals]) |
|
|
|
}, [state.modals]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (canPaste) { |
|
|
|
|
|
|
|
addMenuItems([{ |
|
|
|
|
|
|
|
id: 'paste', |
|
|
|
|
|
|
|
name: 'Paste', |
|
|
|
|
|
|
|
type: ['folder', 'file'], |
|
|
|
|
|
|
|
path: [], |
|
|
|
|
|
|
|
extension: [], |
|
|
|
|
|
|
|
pattern: [] |
|
|
|
|
|
|
|
}]) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
removeMenuItems(['paste']) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [canPaste]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const addMenuItems = (items: { id: string, name: string, type: string[], path: string[], extension: string[], pattern: string[] }[]) => { |
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
|
|
|
// filter duplicate items
|
|
|
|
|
|
|
|
const actions = items.filter(({ name }) => prevState.actions.findIndex(action => action.name === name) === -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { ...prevState, actions: [...prevState.actions, ...actions] } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const removeMenuItems = (ids: string[]) => { |
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
|
|
|
const actions = prevState.actions.filter(({ id }) => ids.findIndex(value => value === id) === -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { ...prevState, actions } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const extractNameFromKey = (key: string):string => { |
|
|
|
const extractNameFromKey = (key: string):string => { |
|
|
|
const keyPath = key.split('/') |
|
|
|
const keyPath = key.split('/') |
|
|
|
|
|
|
|
|
|
|
@ -695,6 +730,21 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleCopyClick = (path: string, type: string) => { |
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
|
|
|
return { ...prevState, copyElement: [...prevState.copyElement, { key: path, type }] } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
setcanPaste(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handlePasteClick = (dest: string) => { |
|
|
|
|
|
|
|
console.log('destination: ', dest) |
|
|
|
|
|
|
|
setState(prevState => { |
|
|
|
|
|
|
|
return { ...prevState, copyElement: [] } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
setcanPaste(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const label = (file: File) => { |
|
|
|
const label = (file: File) => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div |
|
|
|
<div |
|
|
@ -868,6 +918,8 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
deletePath={deletePath} |
|
|
|
deletePath={deletePath} |
|
|
|
renamePath={editModeOn} |
|
|
|
renamePath={editModeOn} |
|
|
|
runScript={runScript} |
|
|
|
runScript={runScript} |
|
|
|
|
|
|
|
copy={handleCopyClick} |
|
|
|
|
|
|
|
paste={handlePasteClick} |
|
|
|
emit={emitContextMenuEvent} |
|
|
|
emit={emitContextMenuEvent} |
|
|
|
pageX={state.focusContext.x} |
|
|
|
pageX={state.focusContext.x} |
|
|
|
pageY={state.focusContext.y} |
|
|
|
pageY={state.focusContext.y} |
|
|
|