Overview
The Table plugin provides a rich table editor with support for header rows/columns, cell merging, column resizing, cell styling, and more.
Installation
npm install @yoopta/table
Basic Usage
import { useMemo } from 'react' ;
import YooptaEditor , { createYooptaEditor } from '@yoopta/editor' ;
import Table from '@yoopta/table' ;
const plugins = [ Table ];
export default function Editor () {
const editor = useMemo (() => createYooptaEditor ({ plugins , marks: [] }), []);
return < YooptaEditor editor = { editor } onChange = { () => {} } /> ;
}
Features
Rich Editing : Full table editing with rows and columns
Headers : Toggle header rows and columns
Cell Operations : Merge cells, set background/text colors, align content
Column Resizing : Adjustable column widths
Row/Column Management : Insert, delete, and move rows/columns
Keyboard Navigation : Navigate cells with Tab, Arrow keys
Shortcuts : Type table, ||, or 3x3 to insert
Structure
The Table block consists of nested elements:
table (props: headerRow, headerColumn, columnWidths)
└── table-row (multiple)
└── table-data-cell (multiple, props: asHeader, align, colSpan, rowSpan, etc.)
Configuration
import Table from '@yoopta/table' ;
const plugins = [ Table ];
Options
Display title in UI menus
description
string
default: "Add simple table"
Description shown in menus
shortcuts
string[]
default: "['table', '||', '3x3']"
Keyboard shortcuts to trigger the plugin in slash menu
Element Props
Table Element
Whether the first row is a header row
Whether the first column is a header column
Array of column widths in pixels
Enable horizontal scrolling for wide tables
Table Cell Element
Render cell as header (th instead of td)
align
'left' | 'center' | 'right' | 'justify'
default: "left"
Horizontal text alignment
verticalAlign
'top' | 'middle' | 'bottom'
default: "top"
Vertical text alignment
Number of columns the cell spans
Number of rows the cell spans
Minimum cell width in pixels
Maximum cell width in pixels
Commands
Table commands are available via TableCommands.
insertTable
Insert a new Table block.
import Table , { TableCommands } from '@yoopta/table' ;
TableCommands . insertTable ( editor , {
rows: 4 ,
columns: 3 ,
columnWidth: 200 ,
headerRow: true ,
headerColumn: false ,
at: 0 ,
});
Number of columns to create
Default column width in pixels
Make first row a header row
Make first column a header column
Index where to insert the block
Row Operations
import { TableCommands } from '@yoopta/table' ;
// Insert row
TableCommands . insertTableRow ( editor , blockId , {
insertMode: 'after' , // or 'before'
select: true ,
});
// Delete row
TableCommands . deleteTableRow ( editor , blockId );
// Move row
TableCommands . moveTableRow ( editor , blockId , {
from: [ 0 , 1 ],
to: [ 0 , 2 ],
});
Column Operations
import { TableCommands } from '@yoopta/table' ;
// Insert column
TableCommands . insertTableColumn ( editor , blockId , {
insertMode: 'after' , // or 'before'
select: true ,
});
// Delete column
TableCommands . deleteTableColumn ( editor , blockId );
// Move column
TableCommands . moveTableColumn ( editor , blockId , {
from: [ 0 , 0 , 1 ],
to: [ 0 , 0 , 2 ],
});
// Set column width
TableCommands . setColumnWidth ( editor , blockId , columnIndex , 300 );
import { TableCommands } from '@yoopta/table' ;
// Toggle header row
TableCommands . toggleHeaderRow ( editor , blockId );
// Toggle header column
TableCommands . toggleHeaderColumn ( editor , blockId );
Cell Operations
import { TableCommands } from '@yoopta/table' ;
// Merge cells
TableCommands . mergeCells ( editor , blockId , {
cells: selectedCells , // Array of [cell, path] tuples
});
// Clear cell contents
TableCommands . clearContents ( editor , blockId , {
cells: selectedCells ,
});
// Set cell background color
TableCommands . setCellBackgroundColor ( editor , blockId , {
cells: selectedCells ,
color: '#f0f0f0' ,
});
// Set cell text color
TableCommands . setCellTextColor ( editor , blockId , {
cells: selectedCells ,
color: '#333333' ,
});
// Set horizontal alignment
TableCommands . setCellHorizontalAlign ( editor , blockId , {
cells: selectedCells ,
align: 'center' , // 'left' | 'center' | 'right' | 'justify'
});
// Set vertical alignment
TableCommands . setCellVerticalAlign ( editor , blockId , {
cells: selectedCells ,
align: 'middle' , // 'top' | 'middle' | 'bottom'
});
deleteTable
Delete a table block.
import { TableCommands } from '@yoopta/table' ;
TableCommands . deleteTable ( editor , blockId );
buildTableElements
Build table element structure (used internally).
import { TableCommands } from '@yoopta/table' ;
const tableElement = TableCommands . buildTableElements ( editor , {
rows: 3 ,
columns: 3 ,
});
Keyboard Behavior
Tab : Move to next cell (creates new row at end of table)
Shift+Tab : Move to previous cell
Arrow Keys : Navigate between cells
Enter : Insert new row (when in last row)
Backspace : Delete empty row or cell content
Parsers
HTML
Deserialize : <table> with <tr>, <th>, <td> elements
Serialize : Table block → <table> with proper structure and cell attributes
Markdown
Serialize : Table → Markdown table syntax with pipes and alignment
Email
Serialize : Table-based layout with inline styles for email client compatibility
Utilities
Selection Management
import { TABLE_CELLS_IN_SELECTION , TABLE_SLATE_TO_SELECTION_SET } from '@yoopta/table' ;
// WeakMaps for tracking cell selection state
// Used internally for multi-cell selection