* A helper function to add a cell to the grid and update the position map. * @param row The absolute row index in the grid. * @param nd The `TableNode` cell to add.
(tableGrid: TableGrid, nd: TableNode, row: number)
| 90 | * @param nd The `TableNode` cell to add. |
| 91 | */ |
| 92 | function addCell(tableGrid: TableGrid, nd: TableNode, row: number) { |
| 93 | if (!tableGrid.grid[row]) { |
| 94 | tableGrid.grid[row] = []; |
| 95 | } |
| 96 | const col = tableGrid.grid[row].length; |
| 97 | |
| 98 | addBorder(nd); |
| 99 | const cell = nd.toCell(); |
| 100 | tableGrid.grid[row].push(cell); |
| 101 | |
| 102 | // Add the cell position to the map. |
| 103 | if (!nd.id) { |
| 104 | return; |
| 105 | } |
| 106 | if (!tableGrid.posMap) { |
| 107 | tableGrid.posMap = new Map(); |
| 108 | } |
| 109 | if (!tableGrid.posMap.get(nd.id)) { |
| 110 | tableGrid.posMap.set(nd.id, []); |
| 111 | } |
| 112 | |
| 113 | const posList = tableGrid.posMap.get(nd.id)!; |
| 114 | posList.push({ row, col, type: cell.type }); |
| 115 | } |
| 116 | |
| 117 | function addBorder(nd: TableNode) { |
| 118 | nd.addClass("border-b").addClass("border-r"); |