[lexical-table][lexical-playground] Feature: $setTableRowIsHeader and $setTableColumnIsHeader utilities#8815
Merged
Conversation
… 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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds two public utility functions to
@lexical/tablefor 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
$computeTableMapSkipCellCheckto build the rectangular grid map (handling colSpan/rowSpan), iterate the target row or column, deduplicate merged cells viaSet<TableCellNode>, and callsetHeaderStyles(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.setovertoggle— TheisHeader: booleanparameter 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
npm run test-unit— 3697 passed (211 test files)