Expand all

ve.dm.TableMatrix

Constructor

new ve.dm.TableMatrix(tableNode) #

A helper class that allows random access to the table cells and introduces place-holders for fields occupied by spanning cells, making it a non-sparse representation of the sparse HTML model. This is essential for the implementation of table manipulations, such as row insertions or deletions.

Example:

<table>
  <tr><td rowspan=2>1</td><td colspan=2>2</td><td rowspan=2 colspan=2>3</td></tr>
  <tr><td>4</td><td>5</td></tr>
</table>

Visually this table would look like:

 -------------------
| 1 | 2     | 3     |
|   |-------|       |
|   | 4 | 5 |       |
 -------------------

The HTML model is sparse which makes it hard to read but also difficult to work with programmatically. The corresponding TableCellMatrix would look like:

| C[1] | C[2] | P[2] | C[3] | P[3] |
| P[1] | C[4] | C[5] | P[3] | P[3] |

Where C[1] represents a Cell instance wrapping cell 1, and P[1] a PlaceHolder instance owned by that cell.

Parameters:

Name Type Description
tableNode ve.dm.TableNode

Reference to a table instance

Mixes in:
Source:

A helper class that allows random access to the table cells and introduces place-holders for fields occupied by spanning cells, making it a non-sparse representation of the sparse HTML model.

Methods

findClosestCell(cell) → {ve.dm.TableMatrixCell|null} #

Finds the closest cell not being a placeholder for a given cell.

Parameters:

Name Type Description
cell ve.dm.TableMatrixCell

Table cell

Source:

Returns:

Closest cell

Type
ve.dm.TableMatrixCell | null
Finds the closest cell not being a placeholder for a given cell.

getCell(row, col) → {ve.dm.TableMatrixCell|undefined} #

Retrieves a single cell.

Parameters:

Name Type Description
row number

Row index

col number

Column index

Source:

Returns:

Cell, or undefined if out of bounds

Type
ve.dm.TableMatrixCell | undefined
Retrieves a single cell.

getColCount(row) → {number} #

Get number of columns in a row

To get the number of columns in a table use #getMaxColCount

Parameters:

Name Type Description
row number

Row to count columns in

Source:

Returns:

Number of columns

Type
number

Get number of columns in a row

To get the number of columns in a table use #getMaxColCount

getColumn(col) → {Array.<ve.dm.TableMatrixCell>} #

Retrieves all cells of a column with given index.

Parameters:

Name Type Description
col number

Column index

Source:

Returns:

The cells of a column

Type
Array.<ve.dm.TableMatrixCell>
Retrieves all cells of a column with given index.

getMatrix() → {Array.<Array.<ve.dm.TableMatrixCell>>} #

Provides a reference to the internal cell matrix.

Note: this is primarily for internal use. Do not change the delivered matrix and do not store as it may be invalidated.

Source:

Returns:

Table matrix

Type
Array.<Array.<ve.dm.TableMatrixCell>>
Provides a reference to the internal cell matrix.

getMaxColCount() → {number} #

Get the maximum number of columns in a table

This is required because in sparse tables the column count is variable.

Source:

Returns:

Number of columns

Type
number

Get the maximum number of columns in a table

This is required because in sparse tables the column count is variable.

getRow(row) → {Array.<ve.dm.TableMatrixCell>} #

Retrieves all cells of a row with given index.

Parameters:

Name Type Description
row number

Row index

Source:

Returns:

The cells of a row

Type
Array.<ve.dm.TableMatrixCell>
Retrieves all cells of a row with given index.

getRowCount() → {number} #

Get number of rows in the table

Source:

Returns:

Number of rows

Type
number
Get number of rows in the table

getRowNode(row) → {ve.dm.TableRowNode|undefined} #

Retrieves the row node of a row with given index.

It is possible for bad tables to be constructed with rowspans that exceed the last actual row node. In these cases, the number of rows in the table matrix will exceed the number of row nodes, so users should expected getRowNode to sometimes return undefined. (T191858)

Parameters:

Name Type Description
row number

Row index

Source:

Returns:

Node at given index, if found

Type
ve.dm.TableRowNode | undefined
Retrieves the row node of a row with given index.

getRowNodes() → {Array.<ve.dm.TableRowNode>} #

Provides a reference to the internal array of row nodes.

Note: this is primarily for internal use. Do not change the delivered array and do not store it as it may be invalidated.

Source:

Returns:

Table row nodes

Type
Array.<ve.dm.TableRowNode>
Provides a reference to the internal array of row nodes.

invalidate() #

Invalidates the matrix structure.

This is called by ve.dm.TableNode on structural changes.

Source:

Fires:

Invalidates the matrix structure.

lookupCell(cellNode) → {ve.dm.TableMatrixCell|null} #

Look up the matrix cell for a given cell node.

Parameters:

Name Type Description
cellNode ve.dm.TableCellNode

Cell node

Source:

Returns:

The cell or null if not found

Type
ve.dm.TableMatrixCell | null
Look up the matrix cell for a given cell node.

update() #

Recreates the matrix structure.

Source:
Recreates the matrix structure.

Events

structureChange() #