- 新 src/client/builtins/ 目录:tabs.tsx(6 个 tab descriptor + TERMINAL_LIMIT/uiTerminalCount,terminal 配额知识离开 state.ts)、 viewers.tsx(8 个 viewer descriptor)、index.ts(registerBuiltins 聚合 注册 + 幂等 disposer);删除旧 builtins.tsx - icons.tsx:删除零调用者的 tabTypeIcon 及多余 import(图标已归 descriptor.icon,映射随 tab 类型一起注册化) - OrphanedTab:内联 style → sidebar.module.css 新增 .orphanedType 类 - 新增 tests/builtins.spec.ts(6 tab + 8 viewer 注册断言、code catch-all、 binary-download NUL detect、office 优先级、disposer 幂等) - 新增 tests/orphaned-tab.spec.tsx(sanitize 保留未注册类型 tab、 OrphanedTab 占位渲染);tests/browser-globals.ts 供拉入 xterm/ CodeMirror 的 spec 首个 import(模块求值期需要 self/document/navigator) - service.spec 补 openDiffTab 与 diff dedupeKey 一致性用例
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
/**
|
|
* The 8 built-in file viewer descriptors: every preview surface is a
|
|
* registered viewer (image / pdf / docx / xlsx / pptx / markdown / code /
|
|
* binary-download), exactly like external plugins register theirs. The
|
|
* `binary-download` viewer sniffs NUL bytes via `detect` for unknown
|
|
* binaries and serves doc/xls/ppt by extension; `code` is the catch-all
|
|
* (`exts: []`, lowest priority) that claims any file no other viewer did.
|
|
*/
|
|
import { DocxView, XlsxView } from '../office-view.tsx'
|
|
import { PdfView } from '../PdfView.tsx'
|
|
import { PptxView } from '../PptxView.tsx'
|
|
import { TextEditor } from '../TextEditor.tsx'
|
|
import { BinaryDownload } from '../binary-download.tsx'
|
|
import type { FileViewerDescriptor } from '../service.ts'
|
|
import css from '../sidebar.module.css'
|
|
|
|
/** The 8 built-in file viewer descriptors. */
|
|
export function builtinViewers(): readonly FileViewerDescriptor[] {
|
|
return [
|
|
{
|
|
id: 'image',
|
|
exts: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'ico', 'avif'],
|
|
fetchStrategy: 'mediaUrl',
|
|
component: ({ mediaUrl: url, title }) => (
|
|
<div className={css.editorImageWrap}>
|
|
<img className={css.editorImage} src={url} alt={title} />
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
id: 'pdf',
|
|
exts: ['pdf'],
|
|
fetchStrategy: 'mediaUrl',
|
|
component: ({ scope, path, title }) => (
|
|
<PdfView scope={scope} path={path} title={title} />
|
|
),
|
|
},
|
|
{
|
|
id: 'docx',
|
|
exts: ['docx'],
|
|
fetchStrategy: 'mediaUrl',
|
|
component: ({ scope, path, title }) => (
|
|
<DocxView scope={scope} path={path} title={title} />
|
|
),
|
|
},
|
|
{
|
|
id: 'xlsx',
|
|
exts: ['xlsx'],
|
|
fetchStrategy: 'mediaUrl',
|
|
component: ({ scope, path, title }) => (
|
|
<XlsxView scope={scope} path={path} title={title} />
|
|
),
|
|
},
|
|
{
|
|
id: 'pptx',
|
|
exts: ['pptx'],
|
|
fetchStrategy: 'mediaUrl',
|
|
component: ({ scope, path, title }) => (
|
|
<PptxView scope={scope} path={path} title={title} />
|
|
),
|
|
},
|
|
{
|
|
id: 'markdown',
|
|
exts: ['md', 'markdown'],
|
|
fetchStrategy: 'fsRead',
|
|
component: (props) => <TextEditor {...props} />,
|
|
},
|
|
{
|
|
id: 'code',
|
|
exts: [],
|
|
priority: -100,
|
|
fetchStrategy: 'fsRead',
|
|
component: (props) => <TextEditor {...props} />,
|
|
},
|
|
{
|
|
id: 'binary-download',
|
|
exts: ['doc', 'xls', 'ppt'],
|
|
priority: -50,
|
|
fetchStrategy: 'binary-download',
|
|
// NUL probe: a file whose head bytes contain a NUL is binary — claimed
|
|
// before the catch-all code viewer on the head re-match.
|
|
detect: (_path, head) => head.includes(0),
|
|
component: ({ scope, path }) => <BinaryDownload scope={scope} path={path} />,
|
|
},
|
|
]
|
|
}
|