Files
superwork/vscode/webview-ui/src/codeReader/subRows.ts
T

27 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Inline, PropertyItem, PropertyRow } from './types'
/**
* 一行下面展开的子行怎么排:翻译插件给了列名的(输入参数)排成带表头和边框的表格,没给的(导入项、字典 / 对象的各项)排成列表;
* 没有子行就什么都不展开。
*/
export function subRowsLayout(row: PropertyRow): 'table' | 'list' | undefined {
if (!row.items?.length)
return undefined
return row.columns ? 'table' : 'list'
}
/**
* 表格的列宽(整张表格一个网格,各行借用它的列):按整列的内容定,不认是哪种表格。
* 前几列(参数名、类型,字段、约束)宽裕时放到整列不换行;最后一列(默认值、说明)分剩下的宽度,至少留 min(20%, 8em):
* 放不下时先让最后一列换行,前几列(约束这种结构化的词)尽量一行写完。编辑区再窄,前几列平分剩下的宽度、在格子里换行(长名字从中间断开),
* 不把表格撑出卡片、不藏掉哪一列。
*/
export function tableTemplate(count: number): string {
return [...Array.from({ length: count - 1 }, () => 'minmax(0, max-content)'), 'minmax(min(20%, 8em), 1fr)'].join(' ')
}
/** 表格里一个子行的格子:按列名的列数取,子行少给的格子留空、多给的不显示。 */
export function tableCells(item: PropertyItem, columns: string[]): Inline[][] {
return columns.map((_, i) => item.cells[i] ?? [])
}