import { TrBaseToken } from './trBase'; import { SyntaxToken } from '../syntax'; import type { Config, LintError, AST } from '../../base'; import type { AttributesToken, TdToken, TrToken, Token } from '../../internal'; import type { TableCoords } from './trBase'; import type { TdAttrs, TdSubtypes } from './td'; export interface TableRenderedCoords { readonly row?: undefined; readonly column?: undefined; readonly x: number; readonly y: number; } export type TableTokens = TableToken | TrToken | TdToken; /** @extends {Array} */ export declare class Layout extends Array { abstract static from(arr: TableCoords[][]): Layout; /** * Print the table layout * * 打印表格布局 */ print(): void; } /** * table * * 表格 * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken[], ...TrToken[], ?SyntaxToken]}` */ export declare abstract class TableToken extends TrBaseToken { readonly childNodes: readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]]; abstract get lastChild(): AttributesToken | TdToken | TrToken | SyntaxToken; abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]]; abstract get lastElementChild(): AttributesToken | TdToken | TrToken | SyntaxToken; get type(): 'table'; /** whether the table is closed / 表格是否闭合 */ get closed(): boolean; set closed(closed: boolean); /** * @param syntax 表格语法 * @param attr 表格属性 */ constructor(syntax?: string, attr?: string, config?: Config, accum?: Token[]); /** * Close the table syntax * * 闭合表格语法 * @param syntax syntax of the table end / 表格结尾语法 */ close(syntax?: string, halfParsed?: boolean): void; /** * Get the table layout * * 获取表格布局 * @param stop stop condition / 中止条件 * @param stop.row stop at the row / 中止行 * @param stop.column stop at the column / 中止列 * @param stop.x stop at the row / 中止行 * @param stop.y stop at the column / 中止列 */ getLayout(stop?: { row?: number; column?: number; x?: number; y?: number; }): Layout; /** * Get all rows * * 获取所有行 */ getAllRows(): (TrToken | this)[]; /** * Get the `n`-th row * * 获取第n行 * @param n row number / 行号 * @param force whether to regard the table itself as the first row / 是否将表格自身视为第一行 * @param insert whether to be used to insert a new row / 是否用于判断插入新行的位置 * @throws `RangeError` 不存在该行 */ getNthRow(n: number, force: boolean, insert: true): TrToken | this | SyntaxToken | undefined; getNthRow(n: number, force?: boolean, insert?: false): TrToken | this | undefined; /** * @override * @param token node to be inserted / 待插入的子节点 * @param i position to be inserted at / 插入位置 * @throws `SyntaxError` 表格的闭合部分非法 */ insertAt(token: T, i?: number): T; /** * Get the next row * * 获取下一行 */ getNextRow(): TrToken | undefined; /** * Get the cell with the specified coordinates * * 获取指定坐标的单元格 * @param coords table coordinates / 表格坐标 */ getNthCell(coords: TableCoords | TableRenderedCoords): TdToken | undefined; /** * Print the table layout * * 打印表格布局 */ printLayout(): void; /** * Convert to table coordinates after rendering * * 转换为渲染后的表格坐标 * @param {TableCoords} coord table coordinates in wikitext / wikitext中的表格坐标 */ toRenderedCoords(coord: TableCoords): TableRenderedCoords | undefined; /** * Convert to table coordinates in wikitext * * 转换为wikitext中的表格坐标 * @param {TableRenderedCoords} coord table coordinates after rendering / 渲染后的表格坐标 */ toRawCoords(coord: TableRenderedCoords): TableCoords | undefined; /** * Get the full row * * 获取完整行 * @param y row number / 行号 */ getFullRow(y: number): Map; /** * Get the full column * * 获取完整列 * @param x column number / 列号 */ getFullCol(x: number): Map; /** * Format the row * * 设置行格式 * @param y row number / 行号 * @param attr table attribute / 表格属性 * @param multiRow whether to format multi-row cells / 是否对所有单元格设置,或是仅对行首单元格设置 */ formatTableRow(y: number, attr?: TdAttrs | TdSubtypes, multiRow?: boolean): void; /** * Format the column * * 设置列格式 * @param x column number / 列号 * @param attr table attribute / 表格属性 * @param multiCol whether to format multi-column cells / 是否对所有单元格设置,或是仅对行首单元格设置 */ formatTableCol(x: number, attr?: TdAttrs | TdSubtypes, multiCol?: boolean): void; /** * Fill the table row * * 填补表格行 * @param y row number / 行号 * @param inner content to fill / 填充内容 * @param subtype type of the cell / 单元格类型 * @param attr table attribute / 表格属性 */ fillTableRow(y: number, inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void; /** * Fill the table * * 填补表格 * @param inner content to fill / 填充内容 * @param subtype type of the cell / 单元格类型 * @param attr table attribute / 表格属性 */ fillTable(inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void; insertTableCell(inner: string | Token, coords: TableCoords | TableRenderedCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken; /** * Insert a table row * * 插入表格行 * @param y row number / 行号 * @param attr table row attribute / 表格行属性 * @param inner inner wikitext / 内部wikitext * @param subtype type of the cell / 单元格类型 * @param innerAttr cell attribute / 单元格属性 */ insertTableRow(y: number, attr?: Record, inner?: string | Token, subtype?: TdSubtypes, innerAttr?: TdAttrs): TrToken; /** * Insert a table column * * 插入表格列 * @param x column number / 列号 * @param inner inner wikitext / 内部wikitext * @param subtype type of the cell / 单元格类型 * @param attr cell attribute / 单元格属性 */ insertTableCol(x: number, inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs): void; /** * Remove a table row * * 移除表格行 * @param y row number / 行号 */ removeTableRow(y: number): TrToken; /** * Remove a table column * * 移除表格列 * @param x column number / 列号 */ removeTableCol(x: number): void; /** * Marge cells * * 合并单元格 * @param xlim column range / 列范围 * @param ylim row range / 行范围 */ mergeCells(xlim: readonly [number, number], ylim: readonly [number, number]): TdToken; /** * Split a cell into rows * * 分裂成多行 * @param coords coordinates of the cell / 单元格坐标 */ splitIntoRows(coords: TableCoords | TableRenderedCoords): void; /** * Split a cell into columns * * 分裂成多列 * @param coords coordinates of the cell / 单元格坐标 */ splitIntoCols(coords: TableCoords | TableRenderedCoords): void; /** * Split a cell into cells * * 分裂成单元格 * @param coords coordinates of the cell / 单元格坐标 */ splitIntoCells(coords: TableCoords | TableRenderedCoords): void; /** * Replicate a row and insert the result before the row * * 复制一行并插入该行之前 * @param row row number / 行号 */ replicateTableRow(row: number): TrToken; /** * Replicate a column and insert the result before the column * * 复制一列并插入该列之前 * @param x column number / 列号 */ replicateTableCol(x: number): TdToken[]; /** * Move a table row * * 移动表格行 * @param y row number / 行号 * @param before new position / 新位置 */ moveTableRowBefore(y: number, before: number): TrToken; /** * Move a table row * * 移动表格行 * @param y row number / 行号 * @param after new position / 新位置 */ moveTableRowAfter(y: number, after: number): TrToken; /** * Move a table column * * 移动表格列 * @param x column number / 列号 * @param before new position / 新位置 */ moveTableColBefore(x: number, before: number): void; /** * Move a table column * * 移动表格列 * @param x column number / 列号 * @param after new position / 新位置 */ moveTableColAfter(x: number, after: number): void; }