Table
Full table editing with merge, styling, and multi-cell selection.
Import
typescript
import { tablePlugin } from 'halka/plugins/table';Usage
- Insert table with row/column count and optional header row
- Add/remove rows and columns when cursor is in a cell
- Merge cells with multi-cell selection; split only works on merged cells
- Read table.active on formatChange to drive table toolbar (split when cell.isMerged)
Commands
| Command | Description |
|---|---|
table.insert | Insert table |
table.addRow / table.addColumn | Add row or column |
table.removeRow / table.removeColumn | Remove row or column |
table.mergeCells / table.splitCell | Merge or split cells |
table.styleCell / table.styleRow / table.styleTable | Apply CSS |
State
Read plugin state with editor.getState(name). Listen to formatChange to refresh UI when the selection moves.
| State | Description |
|---|---|
table.active | Table context at caret, or null |
typescript
const tableActive = editor.getState('table.active') as {
cell: {
tagName: 'TD' | 'TH';
colSpan: number;
rowSpan: number;
isMerged: boolean;
} | null;
} | null;
const inTable = tableActive !== null;
const canSplitCell = tableActive?.cell?.isMerged ?? false;
editor.on('formatChange', () => {
const active = editor.getState('table.active');
});Example
typescript
editor.execCommand('table.insert', {
rows: 3, columns: 4, header: true
});Notes
Split cell only affects merged cells (colSpan or rowSpan > 1). table.active.cell is null when the caret is in a table but not inside a cell.