-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FileView: added file preview for images/videos/pdf/text files
- Loading branch information
1 parent
01d1031
commit 87980ad
Showing
20 changed files
with
3,474 additions
and
14,994 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-explorer", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Plugin-based file explorer written with React", | ||
"main": "build/main.js", | ||
"build": { | ||
|
@@ -28,6 +28,9 @@ | |
"build/**/*" | ||
] | ||
}, | ||
"overrides": { | ||
"nan": "github:jkleinsc/nan#remove_accessor_signature" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"test:e2e": "npm run server:stop && cd e2e && npm run build && npm run server && npm run cypress:run --config video=false && pm2 stop cy-server", | ||
|
@@ -79,8 +82,8 @@ | |
"clean-webpack-plugin": "^4.0.0", | ||
"copy-webpack-plugin": "^11.0.0", | ||
"css-loader": "^6.7.1", | ||
"electron": "^21.0.1", | ||
"electron-builder": "^23.2.0", | ||
"electron": "^22.3.27", | ||
"electron-builder": "^24.13.3", | ||
"electron-devtools-installer": "^3.1.1", | ||
"eslint": "^8.27.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
|
@@ -135,6 +138,7 @@ | |
"react": "^16.9.0", | ||
"react-dnd": "^14.0.5", | ||
"react-dnd-html5-backend": "^14.1.0", | ||
"react-doc-viewer": "git+https://[email protected]/warpdesign/react-doc-viewer.git#release", | ||
"react-dom": "^16.9.0", | ||
"react-i18next": "^12.0.0", | ||
"react-virtual": "^2.10.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import React, { KeyboardEvent as KE, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react' | ||
import { useStores } from '$src/hooks/useStores' | ||
import { Button, Classes, Colors, Dialog, Icon } from '@blueprintjs/core' | ||
import { observer } from 'mobx-react' | ||
import DocViewer, { DocViewerRenderers } from 'react-doc-viewer' | ||
import { TypeIcons } from '$src/constants/icons' | ||
import { formatBytes } from '$src/utils/formatBytes' | ||
import { FileDescriptor } from '$src/services/Fs' | ||
import { FileState } from '$src/state/fileState' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
const lightTheme = { | ||
tertiary: Colors.WHITE, | ||
disableThemeScrollbar: true, | ||
} | ||
|
||
const darkTheme = { | ||
tertiary: Colors.DARK_GRAY3, | ||
textPrimary: Colors.WHITE, | ||
textSecondary: Colors.LIGHT_GRAY1, | ||
textTertiary: Colors.LIGHT_GRAY5, | ||
disableThemeScrollbar: true, | ||
} | ||
|
||
export const PreviewDialog = observer(() => { | ||
const { appState, settingsState } = useStores('appState', 'settingsState') | ||
const { isPreviewOpen } = appState | ||
const view = appState.activeView | ||
const cache = view.getVisibleCache() | ||
const cursorIndex = cache.getFileIndex(cache.cursor) | ||
const docs = useMemo(() => { | ||
return cache.files.map((file) => ({ uri: cache.join(file.dir, file.fullname).replace(/#/g, '%23') })) | ||
}, [cache.cursor]) | ||
const activeDocument = docs[cursorIndex] | ||
const { isDir, type, length, mDate } = cache.cursor || ({} as FileDescriptor) | ||
const icon = (isDir && TypeIcons['dir']) || (type && TypeIcons[type]) || TypeIcons['any'] | ||
const size = (length && formatBytes(length)) || 0 | ||
const theme = settingsState.isDarkModeActive ? darkTheme : lightTheme | ||
|
||
const Header = ({ cache }: { cache: FileState }) => { | ||
const file = cache.cursor | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
flexShrink: 1, | ||
columnGap: '20px', | ||
}} | ||
> | ||
<p | ||
style={{ | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
margin: 0, | ||
}} | ||
> | ||
{file.fullname} | ||
</p> | ||
{file.isDir === false && ( | ||
<Button onClick={() => cache.openFile(appState, cache.cursor)}>{t('DIALOG.PREVIEW.OPEN')}</Button> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
const NoPreviewRenderer = ({ document, fileName }: any) => { | ||
const { t } = useTranslation() | ||
const fileText = fileName || document?.fileType || '' | ||
const modifiedString = (mDate && t('DIALOG.PREVIEW.LAST_MODIFIED_ON', { date: mDate.toLocaleString() })) || '' | ||
|
||
return ( | ||
<div style={{ display: 'flex', padding: '16px 32px', columnGap: '40px' }}> | ||
<div> | ||
<Icon icon={icon} size={100} color={Colors.GRAY3} /> | ||
</div> | ||
<div> | ||
{fileText && <h3>{fileText}</h3>} | ||
<p | ||
style={{ | ||
color: Colors.GRAY3, | ||
}} | ||
> | ||
{!isDir && <>{size}</>} | ||
<br /> | ||
{modifiedString} | ||
</p> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
cache.cursor && ( | ||
<Dialog | ||
icon={icon} | ||
style={{ width: '66%' }} | ||
title={<Header cache={cache} />} | ||
isOpen={isPreviewOpen} | ||
onClose={() => appState.togglePreviewDialog(false)} | ||
> | ||
<div className={Classes.DIALOG_BODY}> | ||
<DocViewer | ||
style={{ | ||
maxHeight: '80vh', | ||
}} | ||
config={{ | ||
header: { | ||
disableHeader: true, | ||
}, | ||
noRenderer: { | ||
overrideComponent: NoPreviewRenderer, | ||
}, | ||
}} | ||
documents={docs} | ||
initialActiveDocument={activeDocument} | ||
activeDocument={activeDocument} | ||
pluginRenderers={DocViewerRenderers} | ||
theme={theme} | ||
/> | ||
</div> | ||
</Dialog> | ||
) | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
body{ | ||
body { | ||
margin:0; | ||
overflow:hidden; | ||
height:100vh; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.