Expand description
§canvist_extension_table
TipTap’s tables for the canvist editor, as in TipTap’s
@tiptap/extension-table: Table registers table, tableRow,
tableCell, and tableHeader, with merged cells, header rows and
columns, and Tab between cells.
Cells hold blocks and carry colspan, rowspan, and colwidth
attributes. The insertTable command makes a table of empty cells;
addColumnBefore, addRowAfter, and the like grow it, deleteColumn,
deleteRow, and deleteTable shrink it, mergeCells and splitCell
merge and split cells, the toggleHeader… commands switch cells to
header cells and back, and setCellAttribute sets any cell attribute.
The tableCell query, and TableHandle::cell, say where the
selection head sits. TableHandle offers each command typed.
After every structural change, the tables it touched are kept well
formed, as TipTap’s fixTables keeps them: every cell holds a block, and
every row covers every column. Tab moves to the next cell, adding a row
past the last, and Backspace and Delete never join text across a cell’s
edge.
use std::time::Duration;
use canvist_core::Editor;
use canvist_core::Env;
use canvist_extension_document::Document;
use canvist_extension_paragraph::Paragraph;
use canvist_extension_table::Table;
let mut builder = Editor::builder().extension(Document).extension(Paragraph);
let table = builder.add(Table);
let mut editor = builder.build()?;
let mut env = Env::headless(Duration::ZERO);
editor.run(&table.insert(2, 3, true), &mut env)?;
editor.run(&table.add_column_after(), &mut env)?;
let cell = table.cell(editor.state()).expect("the caret is in the first cell");
assert!(cell.header);
assert_eq!((cell.row, cell.column), (0, 0));
assert_eq!((cell.rows, cell.columns), (2, 4));Structs§
- Table
- TipTap’s
TableKit: atableoftableRows oftableCells andtableHeaders, each cell holding blocks, withcolspan,rowspan, andcolwidthattributes. - Table
Cell - Where the selection head sits in its table, from
TableHandle::cell. - Table
Handle - Typed access to
Table.
Enums§
- Header
Part - Which cells
TableHandle::toggle_headerswitches.