Skip to content

[lexical-table] Feature: Add $moveTableRow function & Add missing export for $unmergeCellNode - #8833

Merged
etrepum merged 4 commits into
meta:mainfrom
hamo-o:feat/move-table-row
Jul 15, 2026
Merged

etrepum merged 4 commits into
meta:mainfrom
hamo-o:feat/move-table-row

Conversation

@hamo-o

@hamo-o hamo-o commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

1. Adds $moveTableRow(tableNode, originRow, targetRow) to @lexical/table, the row counterpart of $moveTableColumn (added in #8063).

  • Moves a row from one index to another within a simple (non-merged) table.
  • Exported from the package entry point, declared in flow/LexicalTable.js.flow, and documented with JSDoc.

2. Fixes a missing export while touching the entry point: $unmergeCellNode (added in #7408) was never re-exported from src/index.ts

same issue as $insertTableRowAtNode / $insertTableColumnAtNode, which were fixed in #8791.
Without it, unmerging a specific cell requires moving the selection into the cell first (cellNode.selectEnd() + $unmergeCell()). This PR adds the export, the Flow declaration, and JSDoc.

Test plan

Added unit tests for $moveTableRow (12 cases in LexicalTableUtils.test.ts):

  • Moves a row forward / backward / to the first and last position, swaps adjacent rows
  • No-op cases: originRow === targetRow, out-of-bounds or negative indices, tables with merged cells
  • Header cells move along with the row, and table structure is preserved after the move

Before

import {$moveTableRow} from '@lexical/table';
// => Module '"@lexical/table"' has no exported member '$moveTableRow'.

import {$unmergeCellNode} from '@lexical/table';
// => Module '"@lexical/table"' has no exported member '$unmergeCellNode'.

// Unmerging a specific cell requires selection manipulation:
cellNode.selectEnd();
$unmergeCell();

Rows can only be reordered by removing and re-inserting them manually.

After

import {$moveTableRow, $unmergeCellNode} from '@lexical/table';

$moveTableRow(tableNode, 0, 2); // moves the first row to index 2
$unmergeCellNode(cellNode); // no selection manipulation needed

npm run test-unit -- LexicalTableUtils.test — 38 tests pass (12 new, 26 existing).

@vercel

vercel Bot commented Jul 14, 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 15, 2026 11:03am
lexical-playground Ready Ready Preview Jul 15, 2026 11:03am

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 14, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jul 14, 2026
Comment on lines +520 to +530
beforeEach(() => {
editor = createEditor({
namespace: 'test',
nodes: [TableNode, TableCellNode, TableRowNode],
onError: (error: Error) => {
throw error;
},
theme: {},
});
editor._headless = true;
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to use the newer style of tests using buildEditorFromExtensions for this to ensure that all of the expected transforms and other code are also running. It also has better defaults, like an onError that throws.

@hamo-o hamo-o Jul 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8f0fa11 — since all four describe blocks needed the exact same setup, I hoisted the shared beforeEach/afterEach to the top of the file.

Comment on lines +543 to +546
const table = $getRoot().getFirstChild();
if (!$isTableNode(table)) {
throw new Error('Expected table node');
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const table = $getRoot().getFirstChild();
if (!$isTableNode(table)) {
throw new Error('Expected table node');
}
const table = $assertNodeType($getRoot().getFirstChild(), $isTableNode);

these can all be a little shorter with the $assertNodeType helper

@hamo-o hamo-o Jul 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bf41069 — I also modified the rest of the same pattern.

@etrepum
etrepum added this pull request to the merge queue Jul 15, 2026
Merged via the queue into meta:main with commit 782b6e9 Jul 15, 2026
52 checks passed

This branch was successfully deployed

2 active deployments
Preview – lexical — bf41069d Deployed Jul 15, 2026 by vercel[bot]
Preview – lexical-playground — bf41069d Deployed Jul 15, 2026 by vercel[bot]
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.

2 participants