Type Editor / @type-editor/tables / tablemap/TableMap / TableMap
Class: TableMap
Defined in: tables/src/tablemap/TableMap.ts:15
A table map describes the structure of a given table. To avoid recomputing them all the time, they are cached per table node. To be able to do that, positions saved in the map are relative to the start of the table, rather than the start of the document.
Constructors
Constructor
new TableMap(
width,
height,
map,
problems): TableMap;Defined in: tables/src/tablemap/TableMap.ts:31
Parameters
| Parameter | Type | Description |
|---|---|---|
width | number | The number of columns |
height | number | The number of rows |
map | number[] | A width * height array with the start position of the cell covering that part of the table in each slot. |
problems | Problem[] | An optional array of problems (cell overlap or non-rectangular shape) for the table, used by the table normalizer. |
Returns
TableMap
Accessors
height
Get Signature
get height(): number;Defined in: tables/src/tablemap/TableMap.ts:53
Returns
number
map
Get Signature
get map(): number[];Defined in: tables/src/tablemap/TableMap.ts:57
Returns
number[]
problems
Get Signature
get problems(): Problem[];Defined in: tables/src/tablemap/TableMap.ts:41
Returns
Problem[]
Set Signature
set problems(problems): void;Defined in: tables/src/tablemap/TableMap.ts:45
Parameters
| Parameter | Type |
|---|---|
problems | Problem[] |
Returns
void
width
Get Signature
get width(): number;Defined in: tables/src/tablemap/TableMap.ts:49
Returns
number
Methods
cellsInRect()
cellsInRect(rect): number[];Defined in: tables/src/tablemap/TableMap.ts:188
Return the position of all cells that have the top left corner in the given rectangle.
Parameters
| Parameter | Type | Description |
|---|---|---|
rect | Rect | The rectangular region to search within |
Returns
number[]
Array of table-relative positions of cells with top-left corners in the rect
colCount()
colCount(pos): number;Defined in: tables/src/tablemap/TableMap.ts:117
Find the left side (column index) of the cell at the given position.
Parameters
| Parameter | Type | Description |
|---|---|---|
pos | number | The table-relative position of the cell |
Returns
number
The 0-based column index where the cell starts
Throws
If no cell exists at the given position
findCell()
findCell(pos): Rect;Defined in: tables/src/tablemap/TableMap.ts:80
Find the dimensions of the cell at the given position.
Parameters
| Parameter | Type | Description |
|---|---|---|
pos | number | The table-relative position of the cell |
Returns
A Rect describing the cell's boundaries in the grid
Throws
If no cell exists at the given position
nextCell()
nextCell(
pos,
axis,
dir): number;Defined in: tables/src/tablemap/TableMap.ts:135
Find the next cell in the given direction, starting from the cell at pos, if any.
Parameters
| Parameter | Type | Description |
|---|---|---|
pos | number | The table-relative position of the starting cell |
axis | "horiz" | "vert" | The direction axis: 'horiz' for horizontal, 'vert' for vertical |
dir | number | The direction: negative for left/up, positive for right/down |
Returns
number
The position of the adjacent cell, or null if at table boundary
positionAt()
positionAt(
row,
col,
table): number;Defined in: tables/src/tablemap/TableMap.ts:223
Return the position at which the cell at the given row and column starts, or would start, if a cell started there.
Parameters
| Parameter | Type | Description |
|---|---|---|
row | number | The 0-based row index |
col | number | The 0-based column index |
table | Node_2 | The table node |
Returns
number
The table-relative position where the cell at (row, col) starts
rectBetween()
rectBetween(a, b): Rect;Defined in: tables/src/tablemap/TableMap.ts:158
Get the rectangle spanning the two given cells.
Parameters
| Parameter | Type | Description |
|---|---|---|
a | number | The table-relative position of the first cell |
b | number | The table-relative position of the second cell |
Returns
A Rect that encompasses both cells
get()
static get(table): TableMap;Defined in: tables/src/tablemap/TableMap.ts:69
Find the table map for the given table node. Results are cached, so subsequent calls with the same node are efficient.
Parameters
| Parameter | Type | Description |
|---|---|---|
table | Node_2 | The table node to get the map for |
Returns
TableMap
The TableMap for the given table node
Throws
If the provided node is not a table