Module

table/utils

@ckeditor/ckeditor5-table/src/utils

module

Filtering

Functions

  • getColumnIndexes( tableCells ) → Object

    static

    Returns an object with the first and last column index contained in the given tableCells.

    const selectedTableCells = getSelectedTableCells( editor.model.document.selection );
    
    const { first, last } = getColumnIndexes( selectedTableCells );
    
    console.log( `Selected columns: ${ first } to ${ last }` );

    Parameters

    tableCells : Array.<Element>

    Returns

    Object

    Returns an object with the first and last table 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 = 3

     0   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 : Element

    The table to check.

    overlapColumn : Number

    The index of the column to check.

    Returns

    Array.<TableWalkerValue>
  • getRowIndexes( tableCells ) → Object

    static

    Returns an object with the first and last row index contained in the given tableCells.

    const selectedTableCells = getSelectedTableCells( editor.model.document.selection );
    
    const { first, last } = getRowIndexes( selectedTableCells );
    
    console.log( `Selected rows: ${ first } to ${ last }` );

    Parameters

    tableCells : Array.<Element>

    Returns

    Object

    Returns an object with the first and last table 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 | null

    static

    Returns a table widget editing view element if one is selected.

    Parameters

    selection : Selection | DocumentSelection

    Returns

    Element | null
  • 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 getTableCellsContainingSelection and getSelectedTableCells.

    Parameters

    selection : Selection

    Returns

    Array.<Element>
  • getTableCellsContainingSelection( selection ) → Array.<Element>

    static

    Returns all model table cells that the provided model selection's ranges start inside.

    To obtain the cells selected from the outside, use getSelectedTableCells.

    Parameters

    selection : Selection

    Returns

    Array.<Element>
  • getTableWidgetAncestor( selection ) → Element | null

    static

    Returns a table widget editing view element if one is among the selection's ancestors.

    Parameters

    selection : Selection | DocumentSelection

    Returns

    Element | null
  • 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 : Element

    The table to check.

    overlapRow : Number

    The index of the row to check.

    [ startRow ] : Number

    A 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 ) → Boolean

    static

    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 ) → Boolean

    static

    Checks if a given view element is a table widget.

    Parameters

    viewElement : Element

    Returns

    Boolean
  • splitHorizontally( tableCell, splitRow, writer )

    static

    Splits the table cell horizontally.

    Parameters

    tableCell : Element
    splitRow : Number
    writer : Writer
  • splitVertically( tableCell, columnIndex, splitColumn, writer )

    static

    Splits the table cell vertically.

    Parameters

    tableCell : Element
    columnIndex : Number

    The table cell column index.

    splitColumn : Number

    The index of column to split cell on.

    writer : Writer
  • toTableWidget( viewElement, writer, label ) → Element

    static

    Converts a given Element to a table widget:

    • Adds a custom property allowing to recognize the table widget element.
    • Calls the toWidget function with the proper element's label creator.

    Parameters

    viewElement : Element
    writer : DowncastWriter

    An instance of the view writer.

    label : String

    The element's label. It will be concatenated with the table alt attribute if one is present.

    Returns

    Element