维护者在 #817 上批准了「后台自动激活不接管右侧栏」的行为,并要求同批补上 「后台新开了页面」的提示:事件不能丢,但也不能把读者正在看的页面顶走。 行为: - 被门控跳过的那次激活仍然创建任务管理页,只是不再抢焦点 (`OpenTabSeed.reveal: false` → 宿主 `revealIfOpened: false`,即 「放置但不聚焦」;页面类型本来就没有自己的聚焦路径,已经存在的页面 再开一次也只是一次聚焦,正是门控要拒绝的那件事)。 - 该页在原生右栏芯片与插件底部工作台对应页签上显示一个静态小红点 (`aria-label` = 新词条 `tabUnread`,颜色取既有 `--dsw-alias-danger`)。 - 读者切到该页即清除标记:底部工作台走 service.activateTab;原生栏的 点击插件看不见(`ISidebarRight` 只有 `active()` 读取器,没有选中事件流), 所以由宿主自己的芯片按 `tab.visible` 清除——非可见芯片不清除, 否则宿主为每个展开页签都画标题,红点刚亮就会被抹掉。 - 标记存进会话状态的 `unread: TabType[]`(随布局持久化,跨挂载/跨会话/ 刷新都在),两个承载面读同一份,不会各自为政。 文案:20 份词典同批更新两条设置项描述(门控行为变了)+ 新增 `tabUnread` 词条(ja 真日文)。 测试:`tests/sidebar-auto-activation.spec.tsx` 的门控两条改为断言 「页面仍创建 + revealIfOpened:false + 标记出现」,并加红点生命周期与 「已在任务页/正常激活不标红」三条;新增 `tests/native-tab-unread.spec.tsx` 钉住原生芯片这一承载面(画点、按 visible 清除、非可见不清除、别的类型 不串味、不破坏可访问名)。判别性用 6 处镜像还原逐条证伪(见报告)。
168 lines
6.1 KiB
TypeScript
168 lines
6.1 KiB
TypeScript
/**
|
|
* Consumer-facing type surface compile gate (v0.12.0+): this file exercises
|
|
* EVERY public type and descriptor field exactly the way an external plugin
|
|
* would, so `pnpm typecheck` fails the moment the shipped declaration
|
|
* surface (service.ts re-exports / descriptor fields / service methods)
|
|
* drifts from what consumers can name. Type-only — erased at runtime, never
|
|
* executed by vitest (no `*.spec` suffix).
|
|
*
|
|
* Mirrors the "external consumer" fixture: what is importable here from
|
|
* `../src/client/service.ts` must also be importable from
|
|
* `dsh-better-sidebar/client/service` in the built package.
|
|
*/
|
|
import type {} from '../src/client/service.ts'
|
|
import {
|
|
FOLDER_EXT,
|
|
FOLDER_OPEN_EXT,
|
|
SIDEBAR_FEATURES,
|
|
SIDEBAR_SERVICE_VERSION,
|
|
} from '../src/client/service.ts'
|
|
import type {
|
|
BetterSidebarService,
|
|
FileFetchStrategy,
|
|
FileIconDescriptor,
|
|
FileViewerDescriptor,
|
|
FileViewerProps,
|
|
OpenTabSeed,
|
|
SidebarSettingsDeclaration,
|
|
SidebarSettingsRenderProps,
|
|
SidebarSettingToggle,
|
|
SidebarSettingToggleType,
|
|
TabComponentProps,
|
|
TabDescriptor,
|
|
} from '../src/client/service.ts'
|
|
import type {
|
|
SessionScope,
|
|
SidebarDiffRef,
|
|
SidebarPrefs,
|
|
SidebarSnapshot,
|
|
SidebarState,
|
|
SidebarStore,
|
|
SidebarTab,
|
|
TabType,
|
|
} from '../src/client/service.ts'
|
|
|
|
/** A full-featured external tab descriptor using every v0.12.0 field. */
|
|
const tab: TabDescriptor = {
|
|
id: 'my-plugin:db',
|
|
title: () => 'Database',
|
|
icon: (_size: number) => null,
|
|
order: 50,
|
|
hidden: false,
|
|
available: (ctx, scope, state) => scope.sessionId !== '' && state.bottomOpen && ctx !== null,
|
|
single: false,
|
|
dedupeKey: (t: SidebarTab) => t.id,
|
|
createTab: (state: SidebarState) => ({
|
|
tab: { id: `my-plugin:db:${state.nextBrowser}`, type: 'my-plugin:db', title: 'DB', meta: { n: state.nextBrowser } },
|
|
patch: { nextBrowser: state.nextBrowser + 1 },
|
|
}),
|
|
badge: (ctx, scope, state) => (state.expanded.length > 0 ? state.expanded.length : null),
|
|
onOpen: (tab: SidebarTab, scope: SessionScope) => { void tab; void scope },
|
|
onActivate: (tab: SidebarTab, scope: SessionScope) => { void tab; void scope },
|
|
onClose: (tab: SidebarTab, scope: SessionScope) => { void tab; void scope },
|
|
settings: {
|
|
toggles: [{ key: 'autoOpenSubagent', title: 'Auto-open', type: 'switch' }],
|
|
pluginToggles: [{
|
|
key: 'pageSize',
|
|
title: 'Page size',
|
|
type: 'number',
|
|
min: 1,
|
|
max: 100,
|
|
unit: 'rows',
|
|
}],
|
|
render: (props: SidebarSettingsRenderProps) => {
|
|
props.updatePluginSetting('refresh', true)
|
|
props.close()
|
|
return null
|
|
},
|
|
},
|
|
component: (props: TabComponentProps) => {
|
|
const { ctx, store, scope, tab, visible } = props
|
|
void ctx; void store; void scope; void tab; void visible
|
|
return null
|
|
},
|
|
}
|
|
|
|
/** A full-featured external viewer using the v0.12.0 load signal. */
|
|
const viewer: FileViewerDescriptor = {
|
|
id: 'my-plugin:csv',
|
|
title: 'CSV',
|
|
exts: ['csv'],
|
|
priority: 10,
|
|
fetchStrategy: 'custom',
|
|
detect: (_path, head: Uint8Array) => head.length > 0,
|
|
load: async (path: string, scope: SessionScope, signal?: AbortSignal) => {
|
|
void path; void scope; void signal
|
|
return { rows: [] }
|
|
},
|
|
settings: { pluginToggles: [{ key: 'delimiter', title: 'Delimiter', type: 'text', placeholder: ',' }] },
|
|
component: (props: FileViewerProps) => {
|
|
const { customData, content, truncated, mediaUrl, viewerId, path, title } = props
|
|
void customData; void content; void truncated; void mediaUrl; void viewerId; void path; void title
|
|
return null
|
|
},
|
|
}
|
|
|
|
/** The full service surface, exercised exactly as consumers call it. */
|
|
declare const ctx: { betterSidebar: BetterSidebarService }
|
|
const service: BetterSidebarService = ctx.betterSidebar
|
|
service.registerTab(tab)
|
|
service.registerFileViewer(viewer)
|
|
service.getTabs()
|
|
service.getFileViewers()
|
|
service.getTab('my-plugin:db')
|
|
service.isTabEnabled('my-plugin:db')
|
|
service.isViewerEnabled('my-plugin:csv')
|
|
service.matchFileViewer('a.csv', new Uint8Array([1]))
|
|
service.closeTab('tab:1')
|
|
service.subscribe(() => {})
|
|
const seed: OpenTabSeed = { type: 'my-plugin:db', title: 'DB', path: '/p', id: 'x', meta: { a: 1 } }
|
|
service.openTab(seed)
|
|
service.openTab(seed, { sessionId: 's1', cwd: '/p' })
|
|
// `reveal: false` places the tab without focusing it (a background open).
|
|
service.openTab({ ...seed, reveal: false })
|
|
const _version: string = service.version
|
|
service.features.includes('badge')
|
|
const snapshot: SidebarSnapshot | undefined = service.getSnapshot()
|
|
void snapshot
|
|
service.subscribeState(() => {})
|
|
service.updateTab('tab:1', { title: 'T', path: '/p', meta: 1 })
|
|
service.activateTab('tab:1')
|
|
// Retiring the "new page" dot for one session's tab type.
|
|
service.clearUnread('my-plugin:db', 's1')
|
|
service.openFile({ sessionId: 's1', cwd: '/p' }, '/p/a.csv', 'Data')
|
|
|
|
/** File-icon registration surface (feature `fileIcons`). */
|
|
const icon: FileIconDescriptor = {
|
|
id: 'my-plugin:icons',
|
|
exts: ['csv', FOLDER_EXT, FOLDER_OPEN_EXT],
|
|
names: ['package.json'],
|
|
folderNames: ['node_modules'],
|
|
priority: 5,
|
|
icon: (path: string, size: number, open?: boolean) => {
|
|
void path; void size; void open
|
|
return null
|
|
},
|
|
}
|
|
service.registerFileIcon(icon)
|
|
service.getFileIcons()
|
|
service.matchFileIcon('/p/a.csv')
|
|
service.matchFolderIcon(true)
|
|
service.matchFolderIcon(true, 'node_modules')
|
|
service.fileIcon('/p/a.csv', 14)
|
|
service.folderIcon('/p', true, 14)
|
|
|
|
/** Named state vocabulary stays importable (the pre-0.12 gap). */
|
|
const diff: SidebarDiffRef = { kind: 'worktree', path: '/p/a.ts', staged: false }
|
|
const prefs: SidebarPrefs = { ...({} as SidebarPrefs) }
|
|
const store: SidebarStore = null as unknown as SidebarStore
|
|
const toggleType: SidebarSettingToggleType = 'number'
|
|
const toggle: SidebarSettingToggle = { key: 'k', title: 'K', type: toggleType }
|
|
const declaration: SidebarSettingsDeclaration = { toggles: [toggle], pluginToggles: [toggle] }
|
|
const typeName: TabType = 'my-plugin:db'
|
|
const version: string = SIDEBAR_SERVICE_VERSION
|
|
const features: readonly string[] = SIDEBAR_FEATURES
|
|
void version; void features
|
|
const strategy: FileFetchStrategy = 'mediaUrl'
|
|
void diff; void prefs; void store; void declaration; void typeName; void strategy
|