Skip to content

Type Editor


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

ts
new TableMap(
   width,
   height,
   map,
   problems): TableMap;

Defined in: tables/src/tablemap/TableMap.ts:31

Parameters

ParameterTypeDescription
widthnumberThe number of columns
heightnumberThe number of rows
mapnumber[]A width * height array with the start position of the cell covering that part of the table in each slot.
problemsProblem[]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

ts
get height(): number;

Defined in: tables/src/tablemap/TableMap.ts:53

Returns

number


map

Get Signature

ts
get map(): number[];

Defined in: tables/src/tablemap/TableMap.ts:57

Returns

number[]


problems

Get Signature

ts
get problems(): Problem[];

Defined in: tables/src/tablemap/TableMap.ts:41

Returns

Problem[]

Set Signature

ts
set problems(problems): void;

Defined in: tables/src/tablemap/TableMap.ts:45

Parameters
ParameterType
problemsProblem[]
Returns

void


width

Get Signature

ts
get width(): number;

Defined in: tables/src/tablemap/TableMap.ts:49

Returns

number

Methods

cellsInRect()

ts
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

ParameterTypeDescription
rectRectThe rectangular region to search within

Returns

number[]

Array of table-relative positions of cells with top-left corners in the rect


colCount()

ts
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

ParameterTypeDescription
posnumberThe 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()

ts
findCell(pos): Rect;

Defined in: tables/src/tablemap/TableMap.ts:80

Find the dimensions of the cell at the given position.

Parameters

ParameterTypeDescription
posnumberThe table-relative position of the cell

Returns

Rect

A Rect describing the cell's boundaries in the grid

Throws

If no cell exists at the given position


nextCell()

ts
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

ParameterTypeDescription
posnumberThe table-relative position of the starting cell
axis"horiz" | "vert"The direction axis: 'horiz' for horizontal, 'vert' for vertical
dirnumberThe direction: negative for left/up, positive for right/down

Returns

number

The position of the adjacent cell, or null if at table boundary


positionAt()

ts
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

ParameterTypeDescription
rownumberThe 0-based row index
colnumberThe 0-based column index
tableNode_2The table node

Returns

number

The table-relative position where the cell at (row, col) starts


rectBetween()

ts
rectBetween(a, b): Rect;

Defined in: tables/src/tablemap/TableMap.ts:158

Get the rectangle spanning the two given cells.

Parameters

ParameterTypeDescription
anumberThe table-relative position of the first cell
bnumberThe table-relative position of the second cell

Returns

Rect

A Rect that encompasses both cells


get()

ts
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

ParameterTypeDescription
tableNode_2The 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