Feature: Public row-level header utility (e.g. $setTableRowIsHeader)
Description
@lexical/table models header state per-cell (TableCellHeaderStates bitmask on TableCellNode), but there is no public row-level API for it.
I'm working on a Notion-style table UX where the header row must always be the first row, and I'd like a supported way to set / clear the ROW header bit for an entire table row.
Today this requires re-implementing the same non-trivial iteration in userland:
walking the table map (to handle merged cells correctly), de-duplicating spanned cells,
and calling setHeaderStyles(value, TableCellHeaderStates.ROW) with a mask so the COLUMN bits are preserved.
The playground itself does exactly this in app code. That's a strong signal the primitive belongs in the library rather than in every consumer.
Concrete situation that motivated this
$insertTableRowAtNode/$insertTableRowAtSelectionpropagate only theCOLUMNbit to newly created cells (LexicalTableUtils.ts#L333-L336).- That default is correct for inserting below a header row, but it means inserting a row above row 0 of a table with a header row leaves the header row stranded at index 1.
- Restoring the "header row is the first row" invariant after insert/duplicate currently takes ~20 lines of hand-rolled cell iteration per app.
Proposed API :
export function $setTableRowIsHeader(
tableNode: TableNode,
rowIndex: number,
isHeader: boolean,
): void;
- Iterates the row via the table map so merged cells (
colSpan/rowSpan) are handled and each spanned cell is visited once. - Applies
setHeaderStyles(isHeader ? TableCellHeaderStates.ROW : TableCellHeaderStates.NO_STATUS, TableCellHeaderStates.ROW), leavingCOLUMNbits untouched. - Purely additive and opt-in — no change to existing insertion behavior.
The playground's toggleTableRowIsHeader could then be reduced to a call to this utility.
A column-level counterpart would follow the same shape (the playground implements toggleTableColumnIsHeader manually as well):
export function $setTableColumnIsHeader(
tableNode: TableNode,
columnIndex: number,
isHeader: boolean,
): void;
Use cases
- Notion/Docs-style editors that enforce "the header row is always the first row": re-assert the invariant after inserting a row above the header or duplicating the header row.
- "Toggle row header" menu items (what the playground implements manually today).
- Normalizing header state on paste/import of table content.
Impact
Any app that exposes header-row UX on tables — which is most rich-text table UIs — would benefit. The playground itself would be a first consumer, replacing toggleTableRowIsHeader's inline implementation. The change is purely additive (a new exported utility), so there is no migration cost or behavior change for existing users.
Nice proposal — I'll put together a PR for this.