Skip to content

Commit

Permalink
Read colgroups when deserializing LexicalTableNode
Browse files Browse the repository at this point in the history
  • Loading branch information
cwstra authored Oct 14, 2024
1 parent 2e64bfc commit 1467755
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/lexical-table/src/LexicalTableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {$isTableCellNode, TableCellNode} from './LexicalTableCellNode';
import {TableDOMCell, TableDOMTable} from './LexicalTableObserver';
import {TableRowNode} from './LexicalTableRowNode';
import {getTable} from './LexicalTableSelectionHelpers';
import {PIXEL_VALUE_REG_EXP} from './constants'

export type SerializedTableNode = Spread<
{
Expand Down Expand Up @@ -358,6 +359,19 @@ export function $convertTableElement(
if (domNode.hasAttribute('data-lexical-row-striping')) {
tableNode.setRowStriping(true);
}
const colGroup = domNode.querySelector(":scope > colgroup");
if (colGroup) {
let columns: number[] | undefined = [];
for (const col of colGroup.querySelectorAll(":scope > col")) {
const width = (col as HTMLElement).style.width;
if (!width || !PIXEL_VALUE_REG_EXP.test(width)) {
columns = undefined;
break;
}
columns.push(parseFloat(width))
}
if (columns) tableNode.setColWidths(columns);
}
return {node: tableNode};
}

Expand Down

0 comments on commit 1467755

Please sign in to comment.