1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Lexical: Further improvements to table selection and captions

- Fixed errors with selection and range handling due to captions
  existing.
- Updated TableNode change handling to update existing DOM instead of
  re-creating, which avoids breaking an attached selection helper.
  - To support, Added function to handle node change detection and apply
    relevant dom updates for common properties.
This commit is contained in:
Dan Brown
2025-05-28 22:47:39 +01:00
parent d9ea52522e
commit b862f12a50
6 changed files with 84 additions and 21 deletions

View File

@ -9,7 +9,7 @@ import {
} from "@lexical/table";
import {$getParentOfType} from "./nodes";
import {$getNodeFromSelection} from "./selection";
import {formatSizeValue} from "./dom";
import {el, formatSizeValue} from "./dom";
import {TableMap} from "./table-map";
function $getTableFromCell(cell: TableCellNode): TableNode|null {
@ -140,6 +140,23 @@ export function $getTableCellColumnWidth(editor: LexicalEditor, cell: TableCellN
return (widths.length > index) ? widths[index] : '';
}
export function buildColgroupFromTableWidths(colWidths: string[]): HTMLElement|null {
if (colWidths.length === 0) {
return null
}
const colgroup = el('colgroup');
for (const width of colWidths) {
const col = el('col');
if (width) {
col.style.width = width;
}
colgroup.append(col);
}
return colgroup;
}
export function $getTableCellsFromSelection(selection: BaseSelection|null): TableCellNode[] {
if ($isTableSelection(selection)) {
const nodes = selection.getNodes();