import type { ISlidePlaceholderData } from '@univerjs-pro/slides'; import type { IDocumentData } from '@univerjs/core'; import type { ISlideTableCellStyle, ISlideTableStyleOptions } from '../types'; import type { ISlideTableBuilderInfo } from './f-slide-table-builder'; import { FSlideTable } from './f-slide-table'; import { FSlideTableBuilder } from './f-slide-table-builder'; export interface ISlideTableInsertOptions { tableId?: string; elementId?: string; index?: number; left?: number; top?: number; width?: number; height?: number; rotation?: number; rowHeight?: number; columnWidth?: number; name?: string; description?: string; styleId?: string; custom?: Record | null; options?: ISlideTableStyleOptions; values?: string[][]; textData?: IDocumentData[][]; cellStyles?: Array<{ row: number; column: number; style: ISlideTableCellStyle; }>; placeholder?: ISlidePlaceholderData; } export interface IFSlideTableMixin { /** * Return a builder for a new slide table. * * @param {number} [rows] The initial row count. * @param {number} [columns] The initial column count. * @returns {FSlideTableBuilder} A table builder. * * @example * ```ts * import '@univerjs-pro/slides-table/facade'; * * const fPresentation = univerAPI.getActivePresentation(); * const fSlide = fPresentation?.getActiveSlide(); * const tableInfo = fSlide?.newTable(2, 3) * .setValues([ * ['Name', 'Owner', 'Status'], * ['Facade', 'API', 'Ready'], * ]) * .build(); * if (fSlide && tableInfo) { * fSlide.insertTable(tableInfo); * } * ``` */ newTable(rows?: number, columns?: number): FSlideTableBuilder; /** * Insert a table from builder info. * * @param {ISlideTableBuilderInfo} tableInfo The table builder info. * @param {number} [index] The slide element insert index. * @returns {FSlideTable} The inserted table facade. * * @example * ```ts * const tableInfo = fSlide.newTable(2, 2) * .setTableId('status-table') * .build(); * const table = fSlide.insertTable(tableInfo); * console.log(table.getTableId()); * ``` */ insertTable(tableInfo: ISlideTableBuilderInfo, index?: number): FSlideTable; /** * Insert a table by row and column count. * * @param {number} rows The row count. * @param {number} columns The column count. * @param {ISlideTableInsertOptions} [options] Optional ids, layout, values, and style settings. * @returns {FSlideTable} The inserted table facade. * * @example * ```ts * const table = fSlide.insertTable(2, 3, { * tableId: 'status-table', * values: [ * ['Name', 'Owner', 'Status'], * ['Facade', 'API', 'Ready'], * ], * }); * console.log(table.getCellText(0, 0)); * ``` */ insertTable(rows: number, columns: number, options?: ISlideTableInsertOptions): FSlideTable; /** * Insert a table and fill it with plain text data. * * @param {string[][]} values Two-dimensional plain text values. * @param {ISlideTableInsertOptions} [options] Optional ids, layout, and style settings. * @returns {FSlideTable} The inserted table facade. * * @example * ```ts * const table = fSlide.insertTableFromData([ * ['Name', 'Status'], * ['Facade', 'Ready'], * ], { tableId: 'status-table' }); * console.log(table.getRowCount()); * ``` */ insertTableFromData(values: string[][], options?: ISlideTableInsertOptions): FSlideTable; /** * Return all slide tables on this slide. * * @returns {FSlideTable[]} All table facades in element order. * * @example * ```ts * const tables = fSlide.getTables(); * console.log(tables.map((table) => table.getTableId())); * ``` */ getTables(): FSlideTable[]; /** * Return a slide table by table resource id or element id. * * @param {string} id The table resource id or table element id. * @returns {FSlideTable | null} The table facade, or `null` when it does not exist. * * @example * ```ts * const table = fSlide.getTableById('status-table'); * console.log(table?.getColumnCount()); * ``` */ getTableById(id: string): FSlideTable | null; /** * Return a slide table by its order on the slide. * * @param {number} index The zero-based table index. * @returns {FSlideTable | null} The table facade, or `null` when the index is out of range. * * @example * ```ts * const firstTable = fSlide.getTableAt(0); * console.log(firstTable?.getTableId()); * ``` */ getTableAt(index: number): FSlideTable | null; /** * Remove a slide table by facade, table id, or element id. * * @param {FSlideTable | string} table The table facade, table resource id, or element id. * @returns {boolean} Whether the command succeeded. * * @example * ```ts * const table = fSlide.getTableById('status-table'); * if (table) { * fSlide.removeTable(table); * } * ``` */ removeTable(table: FSlideTable | string): boolean; } declare module '@univerjs-pro/slides/facade' { interface FSlide extends IFSlideTableMixin { } }