| 11 | * @returns A `tableGrid` object representing the virtual table. |
| 12 | */ |
| 13 | export function buildTableGrid(tree: Tree) { |
| 14 | const tableGrid = newTableGrid(); |
| 15 | |
| 16 | if (!tree.valid()) { |
| 17 | return tableGrid; |
| 18 | } |
| 19 | |
| 20 | /* The table represented by root needs to meet the following requirements: |
| 21 | * 1. Cells in the same column should maintain the same width. |
| 22 | * 2. Cells in the same row should maintain the same span. |
| 23 | */ |
| 24 | const root = createNode({ row: 0, level: 0 }, tree, tree.root()); |
| 25 | |
| 26 | for (let i = 0; i < root.span; i++) { |
| 27 | fillGrid(tableGrid, root, i); |
| 28 | } |
| 29 | |
| 30 | tableGrid.width = root.width; |
| 31 | tableGrid.height = root.span * globalStyle.rowHeight; |
| 32 | return tableGrid; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Fills the `grid` and `posMap` of a `tableGrid` by traversing a given `TableNode` row. |