Class

Renderer (engine/view)

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

class

Renderer is responsible for updating the DOM structure and the DOM selection based on the information about updated view nodes. In other words, it renders the view to the DOM.

Its main responsibility is to make only the necessary, minimal changes to the DOM. However, unlike in many virtual DOM implementations, the primary reason for doing minimal changes is not the performance but ensuring that native editing features such as text composition, autocompletion, spell checking, selection's x-index are affected as little as possible.

Renderer uses DomConverter to transform view nodes and positions to and from the DOM.

Filtering

Properties

  • domConverter : DomConverter

    readonly

    Converter instance.

  • domDocuments : Set.<Document>

    readonly

    Set of DOM Documents instances.

  • isFocused : Boolean

    Indicates if the view document is focused and selection can be rendered. Selection will not be rendered if this is set to false.

  • markedAttributes : Set.<Node>

    readonly

    Set of nodes which attributes changed and may need to be rendered.

  • markedChildren : Set.<Node>

    readonly

    Set of elements which child lists changed and may need to be rendered.

  • markedTexts : Set.<Node>

    readonly

    Set of text nodes which text data changed and may need to be rendered.

  • selection : DocumentSelection

    readonly

    View selection. Renderer updates DOM selection based on the view selection.

  • _fakeSelectionContainer : null | HTMLElement

    private

    DOM element containing fake selection.

  • _inlineFiller : Text

    private

    The text node in which the inline filler was rendered.

Methods

  • constructor( domConverter, selection )

    Creates a renderer instance.

    Parameters

    domConverter : DomConverter

    Converter instance.

    selection : DocumentSelection

    View selection.

  • markToSync( type, node )

    Marks a view node to be updated in the DOM by render().

    Note that only view nodes whose parents have corresponding DOM elements need to be marked to be synchronized.

    Parameters

    type : ChangeType

    Type of the change.

    node : Node

    Node to be marked.

    Related:

  • render()

    Renders all buffered changes (markedAttributes, markedChildren and markedTexts) and the current view selection (if needed) to the DOM by applying a minimal set of changes to it.

    Renderer tries not to break the text composition (e.g. IME) and x-index of the selection, so it does as little as it is needed to update the DOM.

    Renderer also handles fillers. Especially, it checks if the inline filler is needed at the selection position and adds or removes it. To prevent breaking text composition inline filler will not be removed as long as the selection is in the text node which needed it at first.

  • _diffNodeLists( actualDomChildren, expectedDomChildren ) → Array.<String>

    private

    Shorthand for diffing two arrays or node lists of DOM nodes.

    Parameters

    actualDomChildren : Array.<Node> | NodeList

    Actual DOM children

    expectedDomChildren : Array.<Node> | NodeList

    Expected DOM children.

    Returns

    Array.<String>

    The list of actions based on the diff function.

  • _domSelectionNeedsUpdate( domSelection ) → Boolean

    private

    Checks whether a given DOM selection needs to be updated.

    Parameters

    domSelection : Selection

    The DOM selection to check.

    Returns

    Boolean
  • _fakeSelectionNeedsUpdate( domRoot ) → Boolean

    private

    Checks whether the fake selection needs to be updated.

    Parameters

    domRoot : HTMLElement

    A valid DOM root where a new fake selection container should be added.

    Returns

    Boolean
  • _findReplaceActions( actions, actualDom, expectedDom ) → Array.<String>

    private

    Finds DOM nodes that were replaced with the similar nodes (same tag name) in the view. All nodes are compared within one insert/delete action group, for example:

    Actual DOM:        <p><b>Foo</b>Bar<i>Baz</i><b>Bax</b></p>
    Expected DOM:    <p>Bar<b>123</b><i>Baz</i><b>456</b></p>
    Input actions:    [ insert, insert, delete, delete, equal, insert, delete ]
    Output actions:    [ insert, replace, delete, equal, replace ]

    Parameters

    actions : Array.<String>

    Actions array which is a result of the diff function.

    actualDom : Array.<Node> | NodeList

    Actual DOM children

    expectedDom : Array.<Node>

    Expected DOM children.

    Returns

    Array.<String>

    Actions array modified with the replace actions.

  • _getInlineFillerPosition() → Position

    private

    Gets the position of the inline filler based on the current selection. Here, we assume that we know that the filler is needed and is at the selection position, and, since it is needed, it is somewhere at the selection position.

    Note: The filler position cannot be restored based on the filler's DOM text node, because when this method is called (before rendering), the bindings will often be broken. View-to-DOM bindings are only dependable after rendering.

    Returns

    Position
  • _isSelectionInInlineFiller() → Boolean

    private

    Returns true if the selection has not left the inline filler's text node. If it is true, it means that the filler had been added for a reason and the selection did not leave the filler's text node. For example, the user can be in the middle of a composition so it should not be touched.

    Returns

    Boolean

    true if the inline filler and selection are in the same place.

  • _markDescendantTextToSync( viewNode )

    private

    Marks text nodes to be synchronized.

    If a text node is passed, it will be marked. If an element is passed, all descendant text nodes inside it will be marked.

    Parameters

    viewNode : Node

    View node to sync.

  • _needsInlineFillerAtSelection() → Boolean

    private

    Checks if the inline filler should be added.

    Returns

    Boolean

    true if the inline filler should be added.

  • _removeDomSelection()

    private

    Removes the DOM selection.

  • _removeFakeSelection()

    private

    Removes the fake selection.

  • _removeInlineFiller()

    private

    Removes the inline filler.

  • _updateAttrs( viewElement )

    private

    Checks if attribute list needs to be updated and possibly updates it.

    Parameters

    viewElement : Element

    The view element to update.

  • _updateChildren( viewElement, options = { options.inlineFillerPosition } )

    private

    Checks if elements child list needs to be updated and possibly updates it.

    Parameters

    viewElement : Element

    View element to update.

    options : Object
    Properties
    options.inlineFillerPosition : Position

    The position where the inline filler should be rendered.

  • _updateChildrenMappings( viewElement )

    private

    Updates mappings of view element's children.

    Children that were replaced in the view structure by similar elements (same tag name) are treated as 'replaced'. This means that their mappings can be updated so the new view elements are mapped to the existing DOM elements. Thanks to that these elements do not need to be re-rendered completely.

    Parameters

    viewElement : Node

    The view element whose children mappings will be updated.

  • _updateDomSelection( domRoot )

    private

    Updates the DOM selection.

    Parameters

    domRoot : HTMLElement

    A valid DOM root where the DOM selection should be rendered.

  • _updateElementMappings( viewElement, domElement )

    private

    Updates mappings of a given view element.

    Parameters

    viewElement : Node

    The view element whose mappings will be updated.

    domElement : Node

    The DOM element representing the given view element.

  • _updateFakeSelection( domRoot )

    private

    Updates the fake selection.

    Parameters

    domRoot : HTMLElement

    A valid DOM root where the fake selection container should be added.

  • _updateFocus()

    private

    Checks if focus needs to be updated and possibly updates it.

  • _updateSelection()

    private

    Checks if the selection needs to be updated and possibly updates it.

  • _updateText( viewText, options = { options.inlineFillerPosition } )

    private

    Checks if text needs to be updated and possibly updates it.

    Parameters

    viewText : Text

    View text to update.

    options : Object
    Properties
    options.inlineFillerPosition : Position

    The position where the inline filler should be rendered.