Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | 1x 1x 1x 9x 9x 7x 10x 10x 10x 10x 6x 10x 10x 19x 19x 19x 19x 19x 4x 15x 19x 10x 10x | import { createTableCell, getSelectedCells, mutateBlock } from 'roosterjs-content-model-dom';
import type {
ContentModelTableRow,
ShallowMutableContentModelTable,
} from 'roosterjs-content-model-types';
const MIN_HEIGHT = 22;
/**
* @internal
*/
export function splitTableCellVertically(table: ShallowMutableContentModelTable) {
const sel = getSelectedCells(table);
if (sel) {
for (let rowIndex = sel.lastRow; rowIndex >= sel.firstRow; rowIndex--) {
const row = table.rows[rowIndex];
const belowRow = table.rows[rowIndex + 1];
row.cells.forEach(mutateBlock);
Iif (
belowRow?.cells.every(
(belowCell, colIndex) =>
colIndex < sel.firstColumn ||
colIndex > sel.lastColumn ||
belowCell.spanAbove
)
) {
belowRow.cells.forEach((belowCell, colIndex) => {
if (colIndex >= sel.firstColumn && colIndex <= sel.lastColumn) {
mutateBlock(belowCell).spanAbove = false;
}
});
} else {
const newHeight = Math.max((row.height /= 2), MIN_HEIGHT);
const newRow: ContentModelTableRow = {
format: { ...row.format },
height: newHeight,
cells: row.cells.map((cell, colIndex) => {
const mutableCell = mutateBlock(cell);
delete mutableCell.format.height;
const newCell = createTableCell(
cell.spanLeft,
cell.spanAbove,
cell.isHeader,
mutableCell.format
);
newCell.dataset = { ...cell.dataset };
if (colIndex < sel.firstColumn || colIndex > sel.lastColumn) {
newCell.spanAbove = true;
} else {
newCell.isSelected = cell.isSelected;
}
return newCell;
}),
};
row.height = newHeight;
table.rows.splice(rowIndex + 1, 0, newRow);
}
}
}
}
|