- 新 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 一致性用例
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/**
|
|
* Built-in registration: the plugin registers its own tab pages and file
|
|
* previewers through the same {@link BetterSidebarService} external plugins
|
|
* use — eating its own dogfood. The descriptors live next to their feature
|
|
* modules (tabs.tsx / viewers.tsx); this module only aggregates them and
|
|
* owns the disposer lifecycle (cordis auto-invokes it on fiber disposal,
|
|
* HMR-safe).
|
|
*/
|
|
import type { Context } from '../../context-types.ts'
|
|
import type { BetterSidebarService } from '../service.ts'
|
|
import { builtinTabs } from './tabs.tsx'
|
|
import { builtinViewers } from './viewers.tsx'
|
|
|
|
/**
|
|
* Register all built-in tabs and viewers with the service. Returns a
|
|
* disposer that unregisters everything (cordis auto-invokes it on fiber
|
|
* disposal). The `ctx` is threaded into tab descriptors that need it
|
|
* (EditorHost reads `ctx.betterSidebar` for file-viewer matching).
|
|
*/
|
|
export function registerBuiltins(ctx: Context, service: BetterSidebarService): () => void {
|
|
const disposers: (() => void)[] = []
|
|
for (const tab of builtinTabs(ctx)) {
|
|
disposers.push(service.registerTab(tab))
|
|
}
|
|
for (const viewer of builtinViewers()) {
|
|
disposers.push(service.registerFileViewer(viewer))
|
|
}
|
|
return () => {
|
|
for (const d of disposers) {
|
|
try { d() } catch { /* already disposed */ }
|
|
}
|
|
}
|
|
}
|