Skip to content

[lexical-table][lexical-playground] Feature: $setTableRowIsHeader and $setTableColumnIsHeader utilities#8815

Merged
etrepum merged 1 commit into
facebook:mainfrom
mayrang:feat/table-row-column-header-util
Jul 9, 2026
Merged

[lexical-table][lexical-playground] Feature: $setTableRowIsHeader and $setTableColumnIsHeader utilities#8815
etrepum merged 1 commit into
facebook:mainfrom
mayrang:feat/table-row-column-header-util

Conversation

@mayrang

@mayrang mayrang commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Adds two public utility functions to @lexical/table for setting row-level and column-level header state: $setTableRowIsHeader(tableNode, rowIndex, isHeader) and $setTableColumnIsHeader(tableNode, colIndex, isHeader).

The playground's table action menu contained ~56 lines of inline header toggle logic — iterating the table map, deduplicating merged cells, and applying header bitmask operations. This PR extracts that logic into reusable library functions. The playground now calls these utilities in ~22 lines, and any consumer can use the same API for header manipulation without reimplementing the map iteration and merged-cell deduplication.

Both functions use $computeTableMapSkipCellCheck to build the rectangular grid map (handling colSpan/rowSpan), iterate the target row or column, deduplicate merged cells via Set<TableCellNode>, and call setHeaderStyles(state, mask) — which preserves the orthogonal header bit (e.g., setting ROW header on a COLUMN-header cell keeps the COLUMN bit intact).

Design notes

Index-based API — The functions take a numeric row/column index rather than a cell node. This matches $moveTableColumn(tableNode, colIndex, ...) and directly serves the two main use cases: toggling from a context menu (index available via $getTableRowIndexFromTableCellNode) and restoring headers after row/column insertion (index known from the insertion point). A cell-based convenience is trivial to add on top if needed.

set over toggle — The isHeader: boolean parameter explicitly sets state rather than toggling. This avoids ambiguity with merged cells spanning header/non-header rows and is safer for post-insertion restoration where the caller knows the desired state. Toggle is a one-liner at the call site: $setTableRowIsHeader(table, row, !cell.hasHeaderState(TableCellHeaderStates.ROW)).

Closes #8812

Test plan

  • 14 new unit tests covering: set/clear header, preserve orthogonal bits, colSpan, rowSpan, middle row/column, out-of-range invariant, BOTH→clear single bit
  • npm run test-unit — 3697 passed (211 test files)
  • E2E gate — 768 passed (chromium)
  • Manual playground (Chrome, Firefox, Safari):
    • Toggle row/column header on/off via context menu
    • Merged cells across header boundaries update correctly
    • Toggling one axis preserves the other axis's header state

… and $setTableColumnIsHeader utilities

Extract the playground's manual header toggle implementation into public utilities that handle merged cells via the table map. Refactor the playground to use the new functions.

Closes facebook#8812
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Jul 8, 2026 2:09pm
lexical-playground Ready Ready Preview Jul 8, 2026 2:09pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 8, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jul 8, 2026
@etrepum etrepum added this pull request to the merge queue Jul 9, 2026
Merged via the queue into facebook:main with commit 9b2e8d2 Jul 9, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Public row-level header utility (e.g. $setTableRowIsHeader)

2 participants