Table

Full table editing with merge, styling, and multi-cell selection.

Try this feature →

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

CommandDescription
table.insertInsert table
table.addRow / table.addColumnAdd row or column
table.removeRow / table.removeColumnRemove row or column
table.mergeCells / table.splitCellMerge or split cells
table.styleCell / table.styleRow / table.styleTableApply CSS

State

Read plugin state with editor.getState(name). Listen to formatChange to refresh UI when the selection moves.

StateDescription
table.activeTable 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.

MIT · Halka Editor