table/utils
@ckeditor/ckeditor5-table/src/utils
Filtering
Functions
-
getColumnIndexes( tableCells ) → Objectstatic
Returns an object with the
firstandlastcolumn index contained in the giventableCells.const selectedTableCells = getSelectedTableCells( editor.model.document.selection ); const { first, last } = getColumnIndexes( selectedTableCells ); console.log( `Selected columns: ${ first } to ${ last }` );Parameters
tableCells : Array.<Element>
Returns
ObjectReturns an object with the
firstandlasttable column indexes.
-
getHorizontallyOverlappingCells( table, overlapColumn ) → Array.<TableWalkerValue>static
Returns slot info of cells that starts before and overlaps a given column.
In a table below, passing
overlapColumn = 30 1 2 3 4┌───────┬───────┬───┐ │ a │ b │ c │ │───┬───┴───────┼───┤ │ d │ e │ f │ ├───┼───┬───────┴───┤ │ g │ h │ i │ ├───┼───┼───┬───────┤ │ j │ k │ l │ m │ ├───┼───┴───┼───┬───┤ │ n │ o │ p │ q │ └───┴───────┴───┴───┘ ^ Overlap column to check
will return slot info for cells: "b", "e", "i".
Parameters
table : ElementThe table to check.
overlapColumn : NumberThe index of the column to check.
Returns
Array.<TableWalkerValue>
-
getRowIndexes( tableCells ) → Objectstatic
Returns an object with the
firstandlastrow index contained in the giventableCells.const selectedTableCells = getSelectedTableCells( editor.model.document.selection ); const { first, last } = getRowIndexes( selectedTableCells ); console.log( `Selected rows: ${ first } to ${ last }` );Parameters
tableCells : Array.<Element>
Returns
ObjectReturns an object with the
firstandlasttable row indexes.
-
getSelectedTableCells( selection ) → Array.<Element>static
Returns all model table cells that are fully selected (from the outside) within the provided model selection's ranges.
To obtain the cells selected from the inside, use
getTableCellsContainingSelection.Parameters
selection : Selection
Returns
Array.<Element>
-
getSelectedTableWidget( selection ) → Element | nullstatic
Returns a table widget editing view element if one is selected.
-
getSelectionAffectedTableCells( selection ) → Array.<Element>static
Returns all model table cells that are either completely selected by selection ranges or host selection range start positions inside them.
Combines
getTableCellsContainingSelectionandgetSelectedTableCells.Parameters
selection : Selection
Returns
Array.<Element>
-
getTableCellsContainingSelection( selection ) → Array.<Element>static
Returns all model table cells that the provided model selection's ranges
startinside.To obtain the cells selected from the outside, use
getSelectedTableCells.Parameters
selection : Selection
Returns
Array.<Element>
-
getTableWidgetAncestor( selection ) → Element | nullstatic
Returns a table widget editing view element if one is among the selection's ancestors.
-
getVerticallyOverlappingCells( table, overlapRow, [ startRow ] ) → Array.<TableWalkerValue>static
Returns slot info of cells that starts above and overlaps a given row.
In a table below, passing
overlapRow = 3┌───┬───┬───┬───┬───┐0 │ a │ b │ c │ d │ e │ │ ├───┼───┼───┼───┤ 1 │ │ f │ g │ h │ i │ ├───┤ ├───┼───┤ │ 2 │ j │ │ k │ l │ │ │ │ │ ├───┼───┤ 3 │ │ │ │ m │ n │ <- overlap row to check ├───┼───┤ │ ├───│ 4 │ o │ p │ │ │ q │ └───┴───┴───┴───┴───┘
will return slot info for cells: "j", "f", "k".
Parameters
table : ElementThe table to check.
overlapRow : NumberThe index of the row to check.
[ startRow ] : NumberA row to start analysis. Use it when it is known that the cells above that row will not overlap.
Defaults to
0
Returns
Array.<TableWalkerValue>
-
isSelectionRectangular( selectedTableCells, tableUtils ) → Booleanstatic
Checks if the selection contains cells that do not exceed rectangular selection.
In a table below:
┌───┬───┬───┬───┐ │ a │ b │ c │ d │ ├───┴───┼───┤ │ │ e │ f │ │ │ ├───┼───┤ │ │ g │ h │ └───────┴───┴───┘
Valid selections are these which create a solid rectangle (without gaps), such as:
- a, b (two horizontal cells)
- c, f (two vertical cells)
- a, b, e (cell "e" spans over four cells)
- c, d, f (cell d spans over a cell in the row below)
While an invalid selection would be:
- a, c (the unselected cell "b" creates a gap)
- f, g, h (cell "d" spans over a cell from the row of "f" cell - thus creates a gap)
Parameters
selectedTableCells : Array.<Element>tableUtils : TableUtils
Returns
Boolean
-
isTableWidget( viewElement ) → Booleanstatic
Checks if a given view element is a table widget.
-
splitHorizontally( tableCell, splitRow, writer )static
Splits the table cell horizontally.
-
splitVertically( tableCell, columnIndex, splitColumn, writer )static
Splits the table cell vertically.
-
toTableWidget( viewElement, writer, label ) → Elementstatic
Converts a given
Elementto a table widget:- Adds a custom property allowing to recognize the table widget element.
- Calls the
toWidgetfunction with the proper element's label creator.
Parameters
viewElement : Elementwriter : DowncastWriterAn instance of the view writer.
label : StringThe element's label. It will be concatenated with the table
altattribute if one is present.
Returns