Peach: Local-first video metadata scraper and media manager.
fix(web): 共享数据表的主要名称列承接剩余宽度
longmeidaoe89f71759e41
diff --git a/docs/BOARD_UI.md b/docs/BOARD_UI.mdindex 7c1bd76cb..d92dfaafb 100644--- a/docs/BOARD_UI.md+++ b/docs/BOARD_UI.md@@ -230,6 +230,8 @@ Radial Chart Card、Bar List Card、Heatmap 与 Sankey 的 Pro 源码**未取得### 关注列表的表格视图(2026-09-08)+共享数据表的主要名称列默认承接剩余宽度;馆藏、关注来源、JAV 订阅、创作者别名、文件已丢失的记录、链接检查与诊断清单共用这套列宽偏好。手动调整后保存像素宽度,重置列宽恢复自适应,列显示独立保存。名称、路径、地址与结果正文以单元格可用宽度折行或省略;路径与地址随列宽重算中间省略,完整原文保留在提示和无障碍名称中。文件已丢失的记录根据有无替代文件给操作列分配默认宽度;窄屏在表格内横向滚动。+取证来源是 https://www.boardui.com/components/data-table 的实时 DOM 与样式表:`_next/static/chunks/0n0ugaibgw__p.css`(SHA-256 `a856db5e9e1a58b2e32b7bfa6d7f1cab69dd09e4bd7ac22fc455dd10b525cf27`)里的 `.bui-table` 规则,以及公开注册表 `r/table.json`(`fc12a8f2f4012d9e983e0b9bbb10f9fe3288d74046566d2623d60e7056c50d88`)和 `r/data-table.json`(`613299eca0f448460a546f7959feab8dab19fbfd6e18670f7216ff304a1e3574`)。2026-09-16 重取这三份:`r/table.json` 与 `r/pagination.json` 逐字节未变,`r/data-table.json` 已是 `7bb73a6cd099b9b16390e5fe00f8ba2d55b5ef96c1e8f90a056168cd2e3235e6`(24531 字节),上游自己改过。Peach 复制进树的是 `table` 条目,`data-table` 只读不抄(原因见 `frontend/src/react/boardui/ORIGIN.md`),所以这次漂移不影响已复制文件的哈希。diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 631e5ed95..e561c39bb 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -348,6 +348,7 @@ OneJAV、Free JAV Torrent 只给种子链接。这类条目经索引器同源的- 首页新作与实体资料页共用 `/api/entity/shapes` 和 `feedNewSkeletonHtml`;`home.feed` 按新作列表同一套未入库、未忽略与合集条件判定,有内容才留位;同步设置先于最终横条和网格,同形骨架复用节点。- 首页、人物页和 JAV「发现」的新作头像共用 `feedIdentity`、`web_catalog.entity_ref` 与 `avatarInner`,携带实体图片版本和人脸取景,多人最多叠三枚,图片缺失时显示首字。已建档人物的头像通往规范资料页,不新增实体、头像采集或运行依赖。- 作者别名管理复用 `@tanstack/react-table` 9.3.1(MIT)和 BoardUI `Table`、`DataTableFrame`、`DataTableFooter`、`AuthorAvatar` 与既有别名 API。两张表均支持全集排序、分页和跨页选择;待合并表以平台别名为行身份,已保存表以规范创作者键为行身份。批量合并与移除读当前清单的所选行,串行执行并报告部分失败;勾写 `slot={null}`。`frontend/test/react/follow-alias.test.tsx` 验证清单刷新、勾选、合并、保存与移除,不新增依赖。扫描与采集方式收在 BoardUI `Button` 与 React Aria `Popover` 下拉里,行外观复用 `menu-styles.ts`(见 `frontend/src/react/boardui/ORIGIN.md`)。+- 表格自适应列宽复用已固定的 `react-aria-components` 1.22.1(Apache-2.0)`ResizableTableContainer` 与 `Column` 的 `1fr`、像素宽度及调整回调,沿用库内 `TableColumnLayout` 的尺寸分配和键盘调整,不添加布局依赖。Peach 保留各表的最小宽度、操作列默认值、偏好持久化、重置和列显示规则;文件名、路径及地址的中间省略继续复用 `middle-truncate.ts` 的 `ResizeObserver`。- 数据管理的孤儿记录与链接结果复用 `react/components/data-table.tsx`,由同版 TanStack Table 处理全集排序、行选择与最后一步分页,外观复用 BoardUI `Table` 与 `DataTableFrame`。七张表共用 `table-controls.tsx` 的分页底栏;关注列表保留卡片与表格共享的排序状态,其余表的排序控件复用 `DataTableSort`。工具栏共享 `styles.css` 的 `data-responsive-toolbar`、`data-toolbar-heading` 与 `data-toolbar-actions` 分组,使用 CSS Flexbox 按可用宽度整体换行;列设置与排序方向各有独立原子组,不新增布局依赖。默认每页 20 条,批量动作在选中后使用 `SelectionDock`。`use-table-selection.ts` 在同页表格间互斥选择,保持一份批量栏。孤儿记录批量删除复用 `/api/batch`;链接清理的可选 `ids` 必须属于 `check_id` 对应的失效清单,只重验和处理所选链接,未选行保留。组件回归与临时数据库验证跨页选择、清单刷新、确认和删除范围;不新增依赖。- 关注列表分页用 `pagination.ts` 的页码范围与边界裁剪(React 与遗留层共用这份纯函数);默认视图按创作者组,表格按来源。关注列表与 JAV 订阅源表格复用 `@tanstack/react-table` 9.3.1(MIT,https://github.com/TanStack/table ,按 ADR-0031「前端基础库」引入),兼容 React 18+ 与 Node 20+;传递依赖为 `table-core`、`react-store`、`store` 和 `use-sync-external-store`,精确版本由前端锁文件记录。按官方 [React 迁移指南](https://tanstack.com/table/latest/docs/framework/react/guide/migrating) 使用 `useTable`、`tableFeatures` 和带 features 类型的 `createColumnHelper().columns()`,注册分页、行选择、排序与列显隐状态,单元格使用 `getVisibleCells`。Peach 保留共用排序比较器、来源 ID(`getRowId`)、跨视图勾选集合、页码裁剪和批量写入策略;排序作用在全集,分页只切最后一步,频率、日期与数量按原始值排序。`frontend/test/react/follow-manage.test.tsx` 验证排序、取消选择、跨页跨视图勾选、批量写与清单变化。- 馆藏表格列宽复用 React Aria Components 1.22.1(Apache-2.0)的 `ResizableTableContainer` 与 `ColumnResizer`,按官方 [Table 列宽调整](https://react-aria.adobe.com/Table#column-resizing) 组合现有 BoardUI Table;鼠标、触摸与键盘调整由该组件处理。列隐藏复用 TanStack Table 9.3.1 的 `columnVisibilityFeature` 与现有 Popover、Checkbox;隐藏列仍可参与服务端排序。`RatingStars` 共用馆藏表格、馆藏详情和 JAV 来源评分的图形与颜色,支持交互星级与只读小数填充;评分取值共用 `rating-values.ts`,表格写入复用 `/api/feedback`、`useAction`、查询缓存与操作回执。Peach 维护各列默认值和上下限、浏览器偏好保存与重置;右侧弹性空白列承接剩余宽度,不参与偏好保存。使用现有依赖,无新增包;回归覆盖长名称、缺图、宽屏两种布局、列宽与显示偏好、隐藏列排序、评分保存与取消、失败重试及撤销。diff --git a/frontend/e2e/catalog-table-layout.test.ts b/frontend/e2e/catalog-table-layout.test.tsindex fb042b1b4..22c5be843 100644--- a/frontend/e2e/catalog-table-layout.test.ts+++ b/frontend/e2e/catalog-table-layout.test.ts@@ -70,13 +70,16 @@ describe('馆藏表格宽屏与选择操作', () => {const row = node.querySelector('[data-catalog-row]')!.getBoundingClientRect();const header = node.querySelector('thead')!.getBoundingClientRect();const heights = [...node.querySelectorAll('[role="toolbar"] button')].map(button => button.getBoundingClientRect().height);+ const others = [...node.querySelectorAll('thead th:not([data-key="name"])')]+ .reduce((sum, cell) => sum + cell.getBoundingClientRect().width, 0);return { available: scroll.clientWidth, table: table.width, row: row.width, header: header.width,- name: node.querySelector('th[data-key="name"]')!.getBoundingClientRect().width, heights };+ name: node.querySelector('th[data-key="name"]')!.getBoundingClientRect().width, others, heights };});assert.ok(Math.abs(geometry.table - geometry.available) <= 1, JSON.stringify(geometry));assert.ok(Math.abs(geometry.row - geometry.available) <= 1, JSON.stringify(geometry));assert.ok(Math.abs(geometry.header - geometry.available) <= 1, JSON.stringify(geometry));- assert.ok(Math.abs(geometry.name - 400) <= 1, JSON.stringify(geometry));+ assert.ok(geometry.name > 400, JSON.stringify(geometry));+ assert.ok(Math.abs(geometry.name + geometry.others - geometry.available) <= 2, JSON.stringify(geometry));assert.ok(Math.max(...geometry.heights) - Math.min(...geometry.heights) <= 1, JSON.stringify(geometry));const stars = await page.locator('[data-catalog-row]').first().locator('[data-catalog-rating]').evaluate(node => {const icon = node.querySelector('svg')!;diff --git a/frontend/e2e/diagnostics.test.ts b/frontend/e2e/diagnostics.test.tsindex 3d3a36e01..736cc3067 100644--- a/frontend/e2e/diagnostics.test.ts+++ b/frontend/e2e/diagnostics.test.ts@@ -3,6 +3,7 @@ import { describe, it } from 'node:test';import type { Browser } from 'playwright-core';import { installDesignBrowser } from './design-fixture.ts';import { layout, settle, visit, VIEWPORTS } from './harness.ts';+import { verifyColumnContentWidth } from './table-preferences-fixture.ts';describe('配置中的系统诊断', () => {let browser: Browser;@@ -35,6 +36,7 @@ describe('配置中的系统诊断', () => {assert.equal(await table.getByRole('row').count(), 21);assert.ok((await table.innerText()).includes('演示文件 1.mp4'));assert.ok((await table.innerText()).includes('R:\\Media\\演示文件 1.mp4'));+ await verifyColumnContentWidth(table, 'path', '[data-middle-truncate]');const pagination = page.getByRole('navigation', { name: '缺封面分页' });await pagination.getByRole('button', { name: '下一页', exact: true }).click();assert.equal(await table.getByRole('row').count(), 12);diff --git a/frontend/e2e/link-manager.test.ts b/frontend/e2e/link-manager.test.tsindex ae2a9601e..a21aab9fb 100644--- a/frontend/e2e/link-manager.test.ts+++ b/frontend/e2e/link-manager.test.ts@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';import { after, before, describe, it } from 'node:test';import type { Browser } from 'playwright-core';import { launch, visit, settle, VIEWPORTS, layout } from './harness.ts';+import { verifyColumnContentWidth } from './table-preferences-fixture.ts';describe('链接检查身份与断链动效', () => {let browser: Browser;@@ -14,7 +15,7 @@ describe('链接检查身份与断链动效', () => {await page.emulateMedia({ reducedMotion: 'no-preference' });const row = { id: 1, entity: '示例作者', entity_id: 31, entity_kind: 'performer',face: { id: 31, name: '示例作者', has_image: true }, link_kind: 'official', label: '示例事务所',- url: 'https://example.com/profile', note: 'HTTP 404' };+ url: `https://example.com/profile/${'long-address-'.repeat(30)}`, note: 'HTTP 404' };await page.route('**/api/links/check', route => {if (!route.request().postDataJSON()?.status_only) phase = 'running';return route.fulfill({ json: {@@ -38,6 +39,8 @@ describe('链接检查身份与断链动效', () => {assert.equal(await table.locator('[data-link-name] img').count(), 0);assert.ok((await table.innerText()).includes('Peach 资料'));assert.ok((await table.innerText()).includes('链接名称'));+ await verifyColumnContentWidth(table, 'url', '[data-link-address]');+ await verifyColumnContentWidth(table, 'note', '[data-link-result]');}const sections = await page.evaluate(() => {const gone = document.querySelector('[data-link-results="gone"]')!;diff --git a/frontend/e2e/orphan-table.test.ts b/frontend/e2e/orphan-table.test.tsindex d33991082..cd932ca4b 100644--- a/frontend/e2e/orphan-table.test.ts+++ b/frontend/e2e/orphan-table.test.ts@@ -3,7 +3,7 @@ import { mkdir } from 'node:fs/promises';import { after, before, describe, it } from 'node:test';import type { Browser } from 'playwright-core';import { launch, layout, settle, VIEWPORTS, visit } from './harness.ts';-import { verifyTablePreferences } from './table-preferences-fixture.ts';+import { verifyTablePreferences, verifyColumnContentWidth } from './table-preferences-fixture.ts';describe('孤儿记录数据表', () => {let browser: Browser;@@ -32,6 +32,11 @@ describe('孤儿记录数据表', () => {await table.waitFor();await settle(page);await verifyTablePreferences(page, table, '文件已消失的作品', 'item', { id: 'records', label: '个人记录' });+ await verifyColumnContentWidth(table, 'item', 'span[title]');+ const widths = await table.locator('th').evaluateAll(nodes => Object.fromEntries(nodes.map(node =>+ [node.getAttribute('data-key'), node.getBoundingClientRect().width])));+ assert.ok(widths.item! > widths.target! * 2, JSON.stringify(widths));+ assert.ok(widths.target! <= 144, JSON.stringify(widths));const faces = await page.evaluate(() => {const read = (node: Element) => {const style = getComputedStyle(node);diff --git a/frontend/e2e/table-preferences-fixture.ts b/frontend/e2e/table-preferences-fixture.tsindex bccc657cd..f804c1d41 100644--- a/frontend/e2e/table-preferences-fixture.ts+++ b/frontend/e2e/table-preferences-fixture.ts@@ -86,11 +86,44 @@ export async function verifyTablePreferences(page: Page, table: Locator, label:await table.waitFor();assert.ok(Math.abs(await width() - resized) <= 1, label);assert.equal(await table.locator(`th[data-key="${optional.id}"]`).count(), 0);- await controls.getByRole('button', { name: '重置列宽', exact: true }).click();- assert.ok(Math.abs(await width() - initial) <= 1, label);await controls.getByRole('button', { name: '显示列', exact: true }).click();await menu.getByRole('button', { name: '恢复默认显示', exact: true }).click();await page.keyboard.press('Escape');await table.locator(`th[data-key="${optional.id}"]`).waitFor();+ await controls.getByRole('button', { name: '重置列宽', exact: true }).click();+ await page.waitForFunction(({ node, initial }) => node && Math.abs(node.getBoundingClientRect().width - initial) <= 1,+ { node: await header.elementHandle(), initial }, { timeout: 5000 });+ assert.ok(Math.abs(await width() - initial) <= 1, label);+ assert.ok(await table.locator('th[data-table-space]').evaluate(node => node.getBoundingClientRect().width) <= 1,+ `${label} 默认剩余空间由名称列承接`);await scroll.evaluate(node => { node.scrollLeft = 0 });}++/** 内容的可用宽度跟随列变化,文字完整保留在 DOM 中。 */+export async function verifyColumnContentWidth(table: Locator, id: string, selector: string) {+ const header = table.locator(`th[data-key="${id}"]`);+ const index = await header.evaluate(node => [...node.parentElement!.children].indexOf(node));+ const cell = table.locator('tbody tr').first().locator('td').nth(index);+ const content = cell.locator(selector).first();+ const measure = () => content.evaluate(node => ({ width: node.getBoundingClientRect().width,+ cell: node.closest('td')!.getBoundingClientRect().width,+ text: node.getAttribute('title') || node.getAttribute('aria-label') || node.textContent }));+ const initial = await measure();+ // 用户按住列边拖动;键盘调整时表格的方向键导航会抢走焦点,测不出内容宽度。+ const resizer = header.locator('.react-aria-ColumnResizer');+ // 滚到视口中间,避开右下角弹出的提示。+ await resizer.evaluate(node => node.scrollIntoView({ block: 'center', inline: 'nearest' }));+ const box = (await resizer.boundingBox())!;+ const page = content.page(), x = box.x + box.width / 2, y = box.y + box.height / 2;+ await page.mouse.move(x, y); await page.mouse.down(); await page.mouse.move(x + 100, y, { steps: 10 }); await page.mouse.up();+ await page.waitForFunction(({ node, initial }) => node && node.closest('td')!.getBoundingClientRect().width > initial + 70,+ { node: await content.elementHandle(), initial: initial.cell }, { timeout: 5000 }).catch(() => undefined);+ const resized = await measure();+ assert.ok(resized.cell > initial.cell + 70, `${id} 列没有拉宽:${JSON.stringify({ initial, resized })}`);+ assert.ok(Math.abs((resized.width - initial.width) - (resized.cell - initial.cell)) <= 2,+ `${id} 内容没有随列拉宽:${JSON.stringify({ initial, resized })}`);+ assert.equal(resized.text, initial.text);+ const geometry = await content.evaluate(node => ({ content: node.getBoundingClientRect().right,+ cell: node.closest('td')!.getBoundingClientRect().right }));+ assert.ok(geometry.content <= geometry.cell, JSON.stringify(geometry));+}diff --git a/frontend/src/react/catalog-grid/catalog-column-widths.ts b/frontend/src/react/catalog-grid/catalog-column-widths.tsindex 80b01d434..5e8e79dfc 100644--- a/frontend/src/react/catalog-grid/catalog-column-widths.ts+++ b/frontend/src/react/catalog-grid/catalog-column-widths.ts@@ -4,7 +4,7 @@ import { useTablePreferences } from '../components/table-column-preferences';const KEY = 'peach.catalog-column-widths.v1';export const columnSizes: Record<string, { width: number; min: number; max: number }> = {select: { width: 48, min: 48, max: 48 },- name: { width: 400, min: 260, max: 800 },+ name: { width: 400, min: 320, max: 2000 },dur: { width: 96, min: 80, max: 240 },size: { width: 112, min: 96, max: 240 },resolution: { width: 144, min: 128, max: 320 },@@ -22,7 +22,7 @@ export const defaultColumnVisibility: ColumnVisibilityState = { code: false, o:const labels: Record<string, string> = { select: '选择', name: '名称', dur: '时长', size: '体积', resolution: '分辨率',rating: '评分', o: '高潮计数', plays: '观看次数', new: '入库时间', played: '观看时间', release: '发行时间', code: '番号' };const columns = ['select', 'name', 'code', 'dur', 'resolution', 'size', 'rating', 'plays', 'o', 'played', 'new', 'release']- .map(id => ({ id, label: labels[id]!, ...columnSizes[id]!, required: id === 'select' || id === 'name', visible: defaultColumnVisibility[id] !== false }));+ .map(id => ({ id, label: labels[id]!, ...columnSizes[id]!, flex: id === 'name', required: id === 'select' || id === 'name', visible: defaultColumnVisibility[id] !== false }));export function useCatalogTablePreferences() {return useTablePreferences('catalog', columns, { widths: KEY, visibility: VISIBLE_KEY });}diff --git a/frontend/src/react/catalog-grid/catalog-list-page.tsx b/frontend/src/react/catalog-grid/catalog-list-page.tsxindex ee7d9e9ff..25bab2238 100644--- a/frontend/src/react/catalog-grid/catalog-list-page.tsx+++ b/frontend/src/react/catalog-grid/catalog-list-page.tsx@@ -161,7 +161,7 @@ export function CatalogListPage(props: CatalogGridProps) {<TableColumnResizer preferences={preferences} id={header.id} /></>}</TableColumn>)}- <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width="1fr" minWidth={0} />+ <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width={preferences.spaceWidth} minWidth={0} /></TableHeader><TableBody renderEmptyState={() => result.isPending? <div data-skeleton="" data-table-skeleton="" aria-busy="true" role="status" aria-label="正在读取作品列表">diff --git a/frontend/src/react/components/data-table.tsx b/frontend/src/react/components/data-table.tsxindex 640da7c19..bb21a9637 100644--- a/frontend/src/react/components/data-table.tsx+++ b/frontend/src/react/components/data-table.tsx@@ -30,6 +30,7 @@ export interface DataColumn<T> {width?: number;min?: number;max?: number;+ flex?: boolean;}interface DataTableProps<T> {@@ -55,7 +56,8 @@ export function DataTable<T extends RowData>({ label, items, columns, rowId, rowconst [sorting, setSorting] = useState<SortingState>([]);const preferenceColumns = useMemo(() => [{ id: 'select', label: '选择', width: 48, min: 48, max: 48, required: true },- ...columns.map((column, index) => ({ ...column, width: column.width ?? (index === 0 ? 320 : 200), required: index === 0 })),+ ...columns.map((column, index) => ({ ...column, width: column.width ?? (index === 0 ? 320 : 160),+ min: column.min ?? (index === 0 ? 320 : 96), flex: column.flex ?? index === 0, required: index === 0 })),], [columns]);const preferences = useTablePreferences(`data:${label}`, preferenceColumns);const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 20 });@@ -131,7 +133,7 @@ export function DataTable<T extends RowData>({ label, items, columns, rowId, row</span><TableColumnResizer preferences={preferences} id={header.id} /></>}</TableColumn>))}- <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width="1fr" minWidth={0} />+ <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width={preferences.spaceWidth} minWidth={0} /></TableHeader><TableBody renderEmptyState={() => '没有记录'}>{table.getRowModel().rows.map((row) => (diff --git a/frontend/src/react/components/table-column-controls.css b/frontend/src/react/components/table-column-controls.cssindex 7f7349356..bc9fb8815 100644--- a/frontend/src/react/components/table-column-controls.css+++ b/frontend/src/react/components/table-column-controls.css@@ -1,8 +1,10 @@.peach-react [data-board-data-table][data-resizable-table] .bui-table { table-layout: fixed; }.peach-react [data-board-data-table][data-resizable-table] th { position: relative; padding-right: 16px; }.peach-react [data-board-data-table][data-resizable-table] td { overflow: hidden; text-overflow: ellipsis; }-.peach-react [data-board-data-table] [data-table-space] { padding: 0; }+.peach-react [data-board-data-table][data-resizable-table] [data-table-space] { padding: 0; }.peach-react [data-board-data-table] td a { width: fit-content; max-width: 100%; align-self: flex-start; }+/* 中间省略按元素自身宽度重算;链接随文字收缩时拉宽列也不会再展开,所以这类链接铺满单元格。 */+.peach-react [data-board-data-table] td a:has(> [data-middle-truncate]) { width: 100%; }.peach-react [data-board-data-table] .react-aria-ColumnResizer { position: absolute; top: 0; right: 0; bottom: 0; width: 12px; cursor: col-resize; touch-action: none; }.peach-react [data-board-data-table] .react-aria-ColumnResizer::after { content: ''; position: absolute; top: 8px; bottom: 8px; left: 5px; width: 1px; background: var(--border-15); }.peach-react [data-board-data-table] .react-aria-ColumnResizer:is([data-hovered],[data-resizing],[data-focus-visible])::after { background: var(--ink); }diff --git a/frontend/src/react/components/table-column-preferences.ts b/frontend/src/react/components/table-column-preferences.tsindex 1e6ee5e7f..85eb503e4 100644--- a/frontend/src/react/components/table-column-preferences.ts+++ b/frontend/src/react/components/table-column-preferences.ts@@ -2,9 +2,9 @@ import { useMemo, useState } from 'react';import type { ResizableTableContainerProps } from 'react-aria-components';import type { ColumnVisibilityState, OnChangeFn } from '@tanstack/react-table';-export interface ColumnSize { width: number; min: number; max: number }+export interface ColumnSize { width: number; min: number; max: number; flex?: boolean }export interface TableColumnSpec {- id: string; label: string; width?: number; min?: number; max?: number; required?: boolean; visible?: boolean;+ id: string; label: string; width?: number; min?: number; max?: number; required?: boolean; visible?: boolean; flex?: boolean;}function read(key: string): Record<string, unknown> {@@ -18,11 +18,16 @@ function persist(key: string, value: unknown) {}export function useTableColumnWidths(key: string, sizes: Record<string, ColumnSize>) {- const bounded = (value: Record<string, unknown>): Record<string, number> => Object.fromEntries(Object.entries(sizes).map(([id, size]) => {+ const bounded = (value: Record<string, unknown>): Record<string, number | '1fr'> => Object.fromEntries(Object.entries(sizes).map(([id, size]) => {const width = value[id];- return [id, typeof width === 'number' && Number.isFinite(width) ? Math.max(size.min, Math.min(size.max, width)) : size.width];+ return [id, typeof width === 'number' && Number.isFinite(width) ? Math.max(size.min, Math.min(size.max, width)) : size.flex ? '1fr' : size.width];}));- const [widths, setWidths] = useState(() => bounded(read(key)));+ const [widths, setWidths] = useState(() => {+ const saved = read(key);+ // 历史偏好包含整张表的默认像素值;默认身份宽度采用自适应,定制宽度保留。+ for (const [id, size] of Object.entries(sizes)) if (size.flex && saved[id] === size.width) delete saved[id];+ return bounded(saved);+ });const resize: NonNullable<ResizableTableContainerProps['onResize']> = values => {setWidths(current => bounded({ ...current, ...Object.fromEntries(values) }));};@@ -51,14 +56,18 @@ export function useTableColumnVisibility(key: string, ids: string[], required: s/** 每张表使用独立偏好;身份列和勾选列保留,隐藏列仍可排序。 */export function useTablePreferences(id: string, columns: TableColumnSpec[], keys?: { widths: string; visibility: string }) {const sizes = useMemo(() => Object.fromEntries(columns.map(column => [column.id, {- width: column.width ?? 180, min: column.min ?? 96, max: column.max ?? 800,+ width: column.width ?? 180, min: column.min ?? 96, max: column.max ?? (column.flex ? 2000 : 800), flex: column.flex,}])), [columns]);const sizing = useTableColumnWidths(keys?.widths ?? `peach.table.${id}.widths.v1`, sizes);const visible = useTableColumnVisibility(keys?.visibility ?? `peach.table.${id}.visibility.v1`,columns.map(column => column.id), columns.filter(column => column.required).map(column => column.id),Object.fromEntries(columns.filter(column => column.visible === false).map(column => [column.id, false])));- return { ...sizing, ...visible, columns,- columnProps: (column: string) => ({ width: sizing.widths[column], minWidth: sizes[column]!.min, maxWidth: sizes[column]!.max }),+ const flexible = columns.some(column => column.flex && visible.visibility[column.id] !== false && sizing.widths[column.id] === '1fr');+ return { ...sizing, ...visible, columns, spaceWidth: flexible ? 0 : '1fr' as const,+ // 自适应列只承接多出来的空间,窄屏上不缩到默认宽度以下;手动调整后才允许到最小宽度。+ columnProps: (column: string) => sizing.widths[column] === '1fr'+ ? { width: '1fr' as const, minWidth: sizes[column]!.width, maxWidth: undefined }+ : { width: sizing.widths[column], minWidth: sizes[column]!.min, maxWidth: sizes[column]!.max },canResize: (column: string) => sizes[column]!.max > sizes[column]!.min,};}diff --git a/frontend/src/react/data-cleanup/link-manager.tsx b/frontend/src/react/data-cleanup/link-manager.tsxindex 20e1c3c3c..cb5e2d245 100644--- a/frontend/src/react/data-cleanup/link-manager.tsx+++ b/frontend/src/react/data-cleanup/link-manager.tsx@@ -87,7 +87,7 @@ function LinkTable(render: (item) => <span className="flex min-w-24 items-center gap-2" data-link-name=""><span className="min-w-0 wrap-anywhere">{item.label || new URL(item.url).hostname}</span></span> },{ id: 'note', label: '结果', width: 320, min: 192, value: (item) => item.note,- render: (item) => <div className="min-w-40 max-w-80" data-link-result={confirmed ? 'gone' : 'unclear'}>+ render: (item) => <div className="min-w-0 w-full" data-link-result={confirmed ? 'gone' : 'unclear'}>{/^(?:HTTP\s+)?[1-5]\d{2}$/.test(item.note.trim())? <StatusLabel tone={confirmed || /^(?:HTTP\s+)?5\d{2}$/.test(item.note.trim()) ? 'error' : 'warning'} data-link-code="">{item.note.trim()}</StatusLabel>: <div className="flex flex-col items-start gap-1"><StatusLabel tone={confirmed ? 'error' : 'warning'}>{confirmed ? '地址已失效' : '未取得结论'}</StatusLabel>@@ -95,7 +95,7 @@ function LinkTable(</div> },{ id: 'url', label: '地址', width: 360, min: 180, value: (item) => item.url,render: (item) => <a href={item.url} target="_blank" rel="noreferrer" title={item.url} data-link-address=""- className="flex max-w-90 min-w-0 items-center gap-1 text-text-secondary hover:text-text-primary">+ className="flex min-w-0 items-center gap-1 text-text-secondary hover:text-text-primary"><SiteMark linkId={item.id} /><span data-middle-truncate className="min-w-0 truncate">{item.url}</span><RiExternalLinkLine aria-hidden className="size-3.5 shrink-0" />diff --git a/frontend/src/react/data-cleanup/orphan-records-card.tsx b/frontend/src/react/data-cleanup/orphan-records-card.tsxindex 4fc3807a6..0bf5f0f2a 100644--- a/frontend/src/react/data-cleanup/orphan-records-card.tsx+++ b/frontend/src/react/data-cleanup/orphan-records-card.tsx@@ -58,7 +58,7 @@ function OrphanActions({ item, toast }: { item: OrphanRecord; toast(message: str};const busy = attach.isPending || purge.isPending;return (- <span className="flex min-w-48 flex-wrap items-center gap-2">+ <span className="flex min-w-0 flex-wrap items-center gap-2">{item.candidates.length? <Select aria-label={`选择接收 ${item.name} 个人记录的文件`} className="w-52" selectedKey={target}onSelectionChange={(key) => { if (key !== null) setTarget(Number(key)) }}>@@ -91,9 +91,9 @@ function OrphanIdentity({ item }: { item: OrphanRecord }) {className="absolute inset-0 size-full object-contain" />: null}</span>- <span className="flex min-w-0 flex-col gap-0.5">- <span title={item.name} className="max-w-56 truncate text-body-regular text-text-primary">{item.name}</span>- <small className="max-w-56 truncate text-caption-1-regular text-text-secondary">+ <span className="flex min-w-0 flex-1 flex-col gap-0.5">+ <span title={item.name} className="truncate text-body-regular text-text-primary">{item.name}</span>+ <small className="truncate text-caption-1-regular text-text-secondary">{[item.code, LOC[item.location] || item.location].filter(Boolean).join(' · ')}</small></span>@@ -120,10 +120,10 @@ export function OrphanRecordsCard({ toast }: { toast(message: string): void }) {onConfirm: () => purge.mutateAsync(chosen.map((item) => item.id)),});const columns: DataColumn<OrphanRecord>[] = [- { id: 'item', label: '作品', value: (item) => item.name, render: (item) => <OrphanIdentity item={item} /> },- { id: 'records', label: '个人记录', min: 144, value: (item) => recordsText(item.records),- render: (item) => <span className="block min-w-28">{recordsText(item.records) || '无'}</span> },- { id: 'target', label: '操作', width: 360, min: 240, value: (item) => item.candidates.length,+ { id: 'item', label: '作品', width: 480, min: 320, value: (item) => item.name, render: (item) => <OrphanIdentity item={item} /> },+ { id: 'records', label: '个人记录', width: 176, min: 144, value: (item) => recordsText(item.records),+ render: (item) => <span className="block min-w-0 whitespace-normal wrap-anywhere">{recordsText(item.records) || '无'}</span> },+ { id: 'target', label: '操作', width: items.some(item => item.candidates.length) ? 360 : 128, min: 128, value: (item) => item.candidates.length,render: (item) => <OrphanActions item={item} toast={toast} /> },];if (!query.isError && !items.length) return null;diff --git a/frontend/src/react/diagnostics/health-list.tsx b/frontend/src/react/diagnostics/health-list.tsxindex d4210a79e..5fe19a797 100644--- a/frontend/src/react/diagnostics/health-list.tsx+++ b/frontend/src/react/diagnostics/health-list.tsx@@ -25,22 +25,22 @@ export function HealthList({ group, openItem, receipt }: {const copy = (items: LibraryItem[]) => void action.run('copy',() => navigator.clipboard.writeText(listText(items)), () => receipt('已复制清单'));const columns: DataColumn<LibraryItem>[] = [- { id: 'title', label: '作品', value: identity, render: item => <span className="flex min-w-48 max-w-72 flex-col gap-1">+ { id: 'title', label: '作品', value: identity, render: item => <span className="flex min-w-0 flex-col gap-1"><LinkButton variant="primary" className="justify-start whitespace-normal text-left"onClick={() => openItem(item.id)}>{identity(item)}</LinkButton>{item.name && item.name !== identity(item)? <span data-middle-truncate title={item.name} className="block min-w-0 text-caption-1-regular text-text-secondary">{item.name}</span> : null}</span> },- { id: 'code', label: '番号', value: item => item.code || '',+ { id: 'code', label: '番号', width: 144, value: item => item.code || '',render: item => <span className="whitespace-nowrap">{item.code || '未识别'}</span> },- { id: 'location', label: '媒体库', value: item => LOC[item.location] || item.location,+ { id: 'location', label: '媒体库', width: 128, value: item => LOC[item.location] || item.location,render: item => LOC[item.location] || item.location || '未取得' },- { id: 'path', label: '文件路径', value: item => item.path,+ { id: 'path', label: '文件路径', width: 320, min: 180, value: item => item.path,render: item => <span data-middle-truncate title={item.path}- className="block w-64 text-body-2-regular text-text-secondary">{item.path || '未取得'}</span> },- { id: 'duration', label: '时长', value: item => item.duration ?? 0,+ className="block min-w-0 w-full text-body-2-regular text-text-secondary">{item.path || '未取得'}</span> },+ { id: 'duration', label: '时长', width: 112, value: item => item.duration ?? 0,render: item => item.duration && item.duration > 0 ? fmtDur(item.duration) : '未取得' },- { id: 'size', label: '大小', value: item => item.size ?? 0,+ { id: 'size', label: '大小', width: 112, value: item => item.size ?? 0,render: item => item.size !== null ? fmtSize(item.size) : '未取得' },];return <Disclosure summary={`${group.label} · ${group.count === null ? '未取得' : `${group.count.toLocaleString()} 项`}`}>diff --git a/frontend/src/react/follow-manage/alias-manager.tsx b/frontend/src/react/follow-manage/alias-manager.tsxindex 69cdf9892..0a85b000c 100644--- a/frontend/src/react/follow-manage/alias-manager.tsx+++ b/frontend/src/react/follow-manage/alias-manager.tsx@@ -43,7 +43,7 @@ const suggestionFeatures = tableFeatures({ rowSelectionFeature, rowSortingFeatursortedRowModel: createSortedRowModel(), paginatedRowModel: createPaginatedRowModel() });const savedFeatures = suggestionFeatures;const selectColumn = { id: 'select', label: '选择', width: 48, min: 48, max: 48, required: true };-const identityColumn = { id: 'canonical', label: '统一名称', width: 280, min: 180, required: true };+const identityColumn = { id: 'canonical', label: '统一名称', width: 280, min: 240, required: true, flex: true };const suggestionPreferences = [selectColumn, identityColumn, { id: 'alias', label: '平台别名', width: 240 },{ id: 'evidence', label: '依据', width: 320 }, { id: 'actions', label: '操作', width: 112 }];const savedPreferences = [selectColumn, identityColumn, { id: 'aliases', label: '平台别名', width: 400 }, { id: 'actions', label: '操作', width: 184, min: 168 }];@@ -325,7 +325,7 @@ export function AliasManager({ groups, suggestions, sources = [], readOnly, toas</span><TableColumnResizer preferences={suggestionView} id={header.id} /></>}</TableColumn>))}- <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width="1fr" minWidth={0} />+ <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width={suggestionView.spaceWidth} minWidth={0} /></TableHeader><TableBody>{suggestionTable.getRowModel().rows.map((row) => (@@ -381,7 +381,7 @@ export function AliasManager({ groups, suggestions, sources = [], readOnly, toas</span><TableColumnResizer preferences={savedView} id={header.id} /></>}</TableColumn>))}- <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width="1fr" minWidth={0} />+ <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width={savedView.spaceWidth} minWidth={0} /></TableHeader><TableBody>{savedTable.getRowModel().rows.map((row) => (diff --git a/frontend/src/react/follow-manage/feed-sources.tsx b/frontend/src/react/follow-manage/feed-sources.tsxindex 73baae0b5..9af1233af 100644--- a/frontend/src/react/follow-manage/feed-sources.tsx+++ b/frontend/src/react/follow-manage/feed-sources.tsx@@ -78,7 +78,8 @@ const COLUMN_LABELS: Record<string, string> = {const SILENT_COLUMNS = new Set(['actions']);const preferenceColumns = Object.entries(COLUMN_LABELS).map(([id, label]) => ({ id, label,width: id === 'select' ? 48 : id === 'name' ? 300 : id === 'actions' ? 208 : id === 'fetched' ? 200 : 160,- min: id === 'select' ? 48 : id === 'actions' ? 200 : 112, max: id === 'select' ? 48 : 800,+ min: id === 'select' ? 48 : id === 'actions' ? 200 : id === 'name' ? 300 : 112, max: id === 'select' ? 48 : id === 'name' ? 2000 : 800,+ flex: id === 'name',required: id === 'select' || id === 'name',}));@@ -424,7 +425,7 @@ export function FeedSources({ readOnly, toast }: {</TableColumn>);})}- <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width="1fr" minWidth={0} />+ <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width={preferences.spaceWidth} minWidth={0} /></TableHeader><TableBody>{table.getRowModel().rows.map((row) => (diff --git a/frontend/src/react/follow-manage/source-list.tsx b/frontend/src/react/follow-manage/source-list.tsxindex 4578a01fe..f393c1127 100644--- a/frontend/src/react/follow-manage/source-list.tsx+++ b/frontend/src/react/follow-manage/source-list.tsx@@ -103,7 +103,8 @@ const COLUMN_LABELS: Record<string, string> = {};const preferenceColumns = Object.entries(COLUMN_LABELS).map(([id, label]) => ({ id, label,width: id === 'select' ? 48 : id === 'source' ? 320 : id === 'author' ? 240 : id === 'actions' ? 208 : 184,- min: id === 'select' ? 48 : id === 'actions' ? 200 : 112, max: id === 'select' ? 48 : 800,+ min: id === 'select' ? 48 : id === 'actions' ? 200 : id === 'source' ? 320 : 112, max: id === 'select' ? 48 : id === 'source' ? 2000 : 800,+ flex: id === 'source',required: id === 'select' || id === 'source',}));@@ -640,7 +641,7 @@ export function SourceList(props: SourceListProps) {</TableColumn>);})}- <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width="1fr" minWidth={0} />+ <TableColumn id="remaining-space" aria-label="行空白区域" data-table-space="" width={preferences.spaceWidth} minWidth={0} /></TableHeader><TableBody renderEmptyState={() => '这一页没有来源'}>{pageRows.map((row) => (diff --git a/frontend/test/react/catalog-column-widths.test.tsx b/frontend/test/react/catalog-column-widths.test.tsxindex 354c21f46..b7bd3551c 100644--- a/frontend/test/react/catalog-column-widths.test.tsx+++ b/frontend/test/react/catalog-column-widths.test.tsx@@ -10,11 +10,11 @@ function Probe() { sizing = useCatalogTablePreferences(); visibility = sizing; rbeforeEach(() => localStorage.clear());it('损坏或超限偏好不会破坏列宽,选择列保持固定', async () => {- for (const saved of ['broken', 'null', '[]', '{"name":99999,"select":200,"dur":-10,"size":"wide"}']) {+ for (const [saved, name] of [['broken', '1fr'], ['null', '1fr'], ['[]', '1fr'],+ ['{"name":99999,"select":200,"dur":-10,"size":"wide"}', 2000]] as const) {localStorage.setItem(key, saved);const root = await mountRoot(<Probe />);- expect(sizing.widths.name).toBeGreaterThanOrEqual(260);- expect(sizing.widths.name).toBeLessThanOrEqual(800);+ expect(sizing.widths.name).toBe(name);expect(sizing.widths.select).toBe(48);expect(sizing.widths.dur).toBeGreaterThanOrEqual(80);expect(sizing.widths.size).toBe(112);@@ -45,7 +45,7 @@ it('调整结束保存列宽,重置清除偏好,存储被禁用时仍可调await mountRoot(<Probe />);expect(sizing.widths.name).toBe(512);await act(() => sizing.reset());- expect(sizing.widths.name).toBe(400);+ expect(sizing.widths.name).toBe('1fr');expect(localStorage.getItem(key)).toBeNull();const blocked = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => { throw new Error('存储未允许') });try {diff --git a/frontend/test/react/table-preferences.test.tsx b/frontend/test/react/table-preferences.test.tsxindex 6baa8b841..4a7e23489 100644--- a/frontend/test/react/table-preferences.test.tsx+++ b/frontend/test/react/table-preferences.test.tsx@@ -24,3 +24,29 @@ it('各表独立保存列显示和列宽,隐藏列保留宽度,身份列保expect(first.widths.extra).toBe(160);expect(first.visibility.extra).toBe(false);});++it('名称默认使用剩余宽度,手动宽度可恢复,重置后保持自适应', async () => {+ let preferences!: ReturnType<typeof useTablePreferences>;+ function Flexible() {+ preferences = useTablePreferences('flexible', [{ ...columns[0]!, flex: true }, columns[1]!]);+ return null;+ }+ localStorage.setItem('peach.table.flexible.widths.v1', JSON.stringify({ name: 280, extra: 160 }));+ const root = await mountRoot(<Flexible />);+ expect(preferences.columnProps('name').width).toBe('1fr');+ expect(preferences.columnProps('name').maxWidth).toBeUndefined();+ expect(preferences.columnProps('name').minWidth).toBe(280);+ expect(preferences.spaceWidth).toBe(0);+ await act(() => preferences.save(new Map([['name', 720], ['extra', 180]])));+ expect(preferences.columnProps('name').width).toBe(720);+ expect(preferences.columnProps('name').minWidth).toBe(96);+ expect(preferences.spaceWidth).toBe('1fr');+ await root.unmount();+ await mountRoot(<Flexible />);+ expect(preferences.columnProps('name').width).toBe(720);+ await act(() => preferences.reset());+ expect(preferences.columnProps('name').width).toBe('1fr');+ await act(() => preferences.save(new Map<string, number | '1fr'>([['name', '1fr'], ['extra', 200]])));+ expect(preferences.columnProps('name').width).toBe('1fr');+ expect(preferences.columnProps('extra').width).toBe(200);+});