]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/utils/tables.ts
Lexical: Linked row properties form up
[bookstack] / resources / js / wysiwyg / utils / tables.ts
index d92f56c8205daee69e884fa7e75cbae0d174cd9e..e808fd595cccd84e9283aba95456041895b0596d 100644 (file)
@@ -6,6 +6,7 @@ import {$getParentOfType} from "./nodes";
 import {$getNodeFromSelection} from "./selection";
 import {formatSizeValue} from "./dom";
 import {TableMap} from "./table-map";
+import {$isCustomTableRowNode, CustomTableRowNode} from "../nodes/custom-table-row";
 
 function $getTableFromCell(cell: CustomTableCellNode): CustomTableNode|null {
     return $getParentOfType(cell, $isCustomTableNode) as CustomTableNode|null;
@@ -192,6 +193,19 @@ export function $mergeTableCellsInSelection(selection: TableSelection): void {
     firstCell.setRowSpan(newHeight);
 }
 
+export function $getTableRowsFromSelection(selection: BaseSelection|null): CustomTableRowNode[] {
+    const cells = $getTableCellsFromSelection(selection);
+    const rowsByKey: Record<string, CustomTableRowNode> = {};
+    for (const cell of cells) {
+        const row = cell.getParent();
+        if ($isCustomTableRowNode(row)) {
+            rowsByKey[row.getKey()] = row;
+        }
+    }
+
+    return Object.values(rowsByKey);
+}
+