Overview
The Table extension provides comprehensive table support with features like column resizing, cell merging, row and column manipulation, and cell selection. Built on top ofprosemirror-tables, it offers a powerful table editing experience.
Installation
Basic Usage
Table Structure
Tables consist of three node types:- table: The container node
- tableRow: Represents a row in the table
- tableCell: Regular data cell
- tableHeaderCell: Header cell for column/row headers
Commands
Creating Tables
insertTable
Inserts a new table with specified dimensions.rows: Number of rows to createcols: Number of columns to createwithHeaderRow: Whether to include a header row (default:true)
Adding Rows and Columns
addTableRowAbove
Adds a row above the current selection.addTableRowBelow
Adds a row below the current selection.addTableColumnBefore
Adds a column before the current selection.addTableColumnAfter
Adds a column after the current selection.Deleting Elements
deleteTable
Deletes the entire table.deleteTableRow
Deletes the current row.deleteTableColumn
Deletes the current column.deleteCellSelection
Deletes the content of selected cells.Cell Operations
mergeTableCells
Merges selected cells into a single cell.splitTableCell
Splits a merged cell back into individual cells.Selection Commands
selectTable
Selects the entire table.selectTableRow
Selects an entire row.selectTableColumn
Selects an entire column.selectTableCell
Selects a specific cell.Moving Rows and Columns
moveTableRow
Moves the current row up or down.moveTableColumn
Moves the current column left or right.Navigation
exitTable
Moves the cursor out of the table.Cell Attributes
Table cells support the following attributes:Styling
The extension includes default styles that can be imported:CSS Classes
The following CSS classes are applied:Utilities
The extension exports utility functions:findTable
Finds the table node that contains the current selection.isCellSelection
Checks if the current selection is a cell selection.Complete Example
Keyboard Shortcuts
Default keyboard shortcuts for table navigation:- Tab: Move to next cell
- Shift+Tab: Move to previous cell
- Arrow Keys: Navigate between cells
- Enter: Create new row (when in last cell)
- Backspace: Delete cell content or merge with previous
Advanced Features
Column Resizing
Tables support interactive column resizing by dragging column borders.Drop Indicator
The extension includes visual feedback when dragging content over tables:Cell Selection
Supports selecting multiple cells for batch operations like merging or deleting.Related Extensions
- Use with
defineDoc()anddefineParagraph()for complete document structure - Combine with text formatting extensions for rich cell content
- Works with
defineImage()to embed images in table cells