Class

NodeList (engine/model)

@ckeditor/ckeditor5-engine/src/model/nodelist

class

Provides an interface to operate on a list of nodes. NodeList is used internally in classes like Element or DocumentFragment.

Filtering

Properties

  • readonly

    length : number

    Number of nodes contained inside this node list.

  • readonly

    maxOffset : number

    Sum of offset sizes of all nodes contained inside this node list.

  • private

    _nodes : Array<Node>

    Nodes contained in this node list.

Methods

  • internal

    constructor( [ nodes ] )

    Creates an empty node list.

    Parameters

    [ nodes ] : Iterable<Node>

    Nodes contained in this node list.

  • Symbol.iterator() → IterableIterator<Node>

    Iterable interface.

    Iterates over all nodes contained inside this node list.

    Returns

    IterableIterator<Node>
  • getNode( index ) → null | Node

    Gets the node at the given index. Returns null if incorrect index was passed.

    Parameters

    index : number

    Returns

    null | Node
  • getNodeIndex( node ) → null | number

    Returns an index of the given node. Returns null if given node is not inside this node list.

    Parameters

    node : Node

    Returns

    null | number
  • getNodeStartOffset( node ) → null | number

    Returns the starting offset of given node. Starting offset is equal to the sum of offset sizes of all nodes that are before this node in this node list.

    Parameters

    node : Node

    Returns

    null | number
  • indexToOffset( index ) → number

    Converts index to offset in node list.

    Returns starting offset of a node that is at given index. Throws CKEditorError model-nodelist-index-out-of-bounds if given index is less than 0 or more than length.

    Parameters

    index : number

    Returns

    number
  • offsetToIndex( offset ) → number

    Converts offset in node list to index.

    Returns index of a node that occupies given offset. Throws CKEditorError model-nodelist-offset-out-of-bounds if given offset is less than 0 or more than maxOffset.

    Parameters

    offset : number

    Returns

    number
  • toJSON() → unknown

    Converts NodeList instance to an array containing nodes that were inserted in the node list. Nodes are also converted to their plain object representation.

    Returns

    unknown

    NodeList instance converted to Array.

  • internal

    _insertNodes( index, nodes ) → void

    Inserts given nodes at given index.

    Parameters

    index : number

    Index at which nodes should be inserted.

    nodes : Iterable<Node>

    Nodes to be inserted.

    Returns

    void
  • internal

    _removeNodes( indexStart, howMany ) → Array<Node>

    Removes one or more nodes starting at the given index.

    Parameters

    indexStart : number

    Index of the first node to remove.

    howMany : number

    Number of nodes to remove.

    Defaults to 1

    Returns

    Array<Node>

    Array containing removed nodes.