Report an issue
Class

Node (engine/view)

@ckeditor/ckeditor5-engine/src/view/node

class

Abstract tree view node class.

This is an abstract class. Its constructor should not be used directly. Use the Element class to create view elements or Text class to create view text nodes.

Filtering

Properties

Methods

  • constructor()

    Creates a tree view node.

  • getAncestors( options = { [options.includeSelf], [options.parentFirst] } ) → Array

    Returns ancestors array of this node.

    Parameters

    options : Object

    Options object.

    Properties
    [ options.includeSelf ] : Boolean

    When set to true this node will be also included in parent's array.

    Defaults to false

    [ options.parentFirst ] : Boolean

    When set to true, array will be sorted from node's parent to root element, otherwise root element will be the first item in the array.

    Defaults to false

    Returns

    Array

    Array with ancestors.

  • getCommonAncestor( node, options = { [options.includeSelf] } ) → Element | DocumentFragment | null

    Returns a Element or DocumentFragment which is a common ancestor of both nodes.

    Parameters

    node : Node

    The second node.

    options : Object

    Options object.

    Properties
    [ options.includeSelf ] : Boolean

    When set to true both nodes will be considered "ancestors" too. Which means that if e.g. node A is inside B, then their common ancestor will be B.

    Defaults to false

    Returns

    Element | DocumentFragment | null
  • getPath() → Array.<Number>

    Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node, beginning from root, down to this node's index.

    const abc = downcastWriter.createText( 'abc' );
    const foo = downcastWriter.createText( 'foo' );
    const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
    const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
    const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
    foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
    h1.getPath(); // Returns [ 0 ].
    div.getPath(); // Returns [].

    Returns

    Array.<Number>

    The path.

  • is( type ) → Boolean

    Checks whether given view tree object is of given type.

    This method is useful when processing view tree objects that are of unknown type. For example, a function may return DocumentFragment or Node that can be either text node or element. This method can be used to check what kind of object is returned.

    obj.is( 'node' ); // true for any node, false for document fragment and text fragment
    obj.is( 'documentFragment' ); // true for document fragment, false for any node
    obj.is( 'element' ); // true for any element, false for text node or document fragment
    obj.is( 'element', 'p' ); // true only for element which name is 'p'
    obj.is( 'p' ); // shortcut for obj.is( 'element', 'p' )
    obj.is( 'text' ); // true for text node, false for element and document fragment

    Parameters

    type : 'element' | 'containerElement' | 'attributeElement' | 'emptyElement' | 'uiElement' | 'rootElement' | 'documentFragment' | 'text' | 'textProxy'

    Returns

    Boolean
  • isAfter( node ) → Boolean

    Returns whether this node is after given node. false is returned if nodes are in different trees (for example, in different DocumentFragments).

    Parameters

    node : Node

    Node to compare with.

    Returns

    Boolean
  • isBefore( node ) → Boolean

    Returns whether this node is before given node. false is returned if nodes are in different trees (for example, in different DocumentFragments).

    Parameters

    node : Node

    Node to compare with.

    Returns

    Boolean
  • isSimilar() → Boolean

    Checks if provided node is similar to this node.

    Returns

    Boolean

    True if nodes are similar.

  • toJSON() → Object

    Custom toJSON method to solve child-parent circular dependencies.

    Returns

    Object

    Clone of this object with the parent property removed.

  • _clone() → Node

    protected

    Clones this node.

    Returns

    Node

    Clone of this node.

  • _fireChange( type, node )

    protected

    Parameters

    type : ChangeType

    Type of the change.

    node : Node

    Changed node.

    Fires

  • _remove()

    protected

    Removes node from parent.

Events

  • change( eventInfo )

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

  • change:attributes( eventInfo, changedNode )

    Fired when list of elements attributes changes.

    Change event is bubbled – it is fired on all ancestors.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    changedNode : Node
  • change:children( eventInfo, changedNode )

    Fired when list of elements children changes.

    Change event is bubbled – it is fired on all ancestors.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    changedNode : Node
  • change:text( eventInfo, changedNode )

    Fired when text nodes data changes.

    Change event is bubbled – it is fired on all ancestors.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    changedNode : Node