Files
shumai/packages/webui/components/file-viewer.tsx
T
Yiling-J 87e88396d1 feat(webui): add space key quick preview for files and folders (#402)
* feat(webui): add space key quick preview for files and folders

Allow users in file list views to press the Space key to quick preview the most recently selected item.

- Add FilePreviewDialog supporting both folder previews (icon, name, count) and real file previews (reusing FileViewer with viewer area and control bar).
- Constrain dialog to max 1920x1080 or 70vw/70vh.
- Support dismissing via close button, clicking outside, or pressing Space again (intercepted in capture phase).
- Enable across project file lists, share links, and public share views.

* feat(webui): auto play video in quick preview dialog

- Pass autoPlay prop from FilePreviewDialog through FileViewer to VideoViewer
- Configure videojs with autoplay: 'any' and handle policy rejection with muted autoplay fallback
- Add test coverage for autoPlay prop forwarding in FilePreviewDialog

* fix(webui): resolve video quick preview initialization and autoplay pause bugs

* fix(webui): support folder symlinks and password-protected shares in quick preview
2026-09-13 18:51:06 +08:00

43 lines
959 B
TypeScript

import { getViewerForFile } from './viewers/registry'
import type { FileViewerProps, MediaController } from './viewers/types'
import React, { RefObject } from 'react'
interface OuterFileViewerProps extends FileViewerProps {
mediaControllerRef?: RefObject<MediaController | null>
}
export function FileViewer({
file,
mediaControllerRef,
onPlay,
onPause,
onTimeUpdate,
annotations,
startTime,
shareId,
allowDownload,
autoPlay,
children,
}: OuterFileViewerProps) {
const viewerDef = getViewerForFile(file)
const ViewerComponent = viewerDef.viewer
return (
<ViewerComponent
key={viewerDef.id}
ref={mediaControllerRef}
file={file}
onPlay={onPlay}
onPause={onPause}
onTimeUpdate={onTimeUpdate}
annotations={annotations}
startTime={startTime}
shareId={shareId}
allowDownload={allowDownload}
autoPlay={autoPlay}
>
{children}
</ViewerComponent>
)
}