Renderer (engine/view)
@ckeditor/ckeditor5-engine/src/view/renderer
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
module:engine/view/renderer~Renderer#domConverter
readonly
Converter instance.
-
domDocuments : Set.<Document>
module:engine/view/renderer~Renderer#domDocuments
readonly
Set of DOM Documents instances.
-
markedAttributes : Set.<Node>
module:engine/view/renderer~Renderer#markedAttributes
readonly
Set of nodes which attributes changed and may need to be rendered.
-
markedChildren : Set.<Node>
module:engine/view/renderer~Renderer#markedChildren
readonly
Set of elements which child lists changed and may need to be rendered.
-
markedTexts : Set.<Node>
module:engine/view/renderer~Renderer#markedTexts
readonly
Set of text nodes which text data changed and may need to be rendered.
-
selection : DocumentSelection
module:engine/view/renderer~Renderer#selection
readonly
View selection. Renderer updates DOM selection based on the view selection.
-
_fakeSelectionContainer : null | HTMLElement
module:engine/view/renderer~Renderer#_fakeSelectionContainer
private
DOM element containing fake selection.
-
_inlineFiller : Text
module:engine/view/renderer~Renderer#_inlineFiller
private
The text node in which the inline filler was rendered.
Methods
-
constructor( domConverter, selection )
module:engine/view/renderer~Renderer#constructor
Creates a renderer instance.
Parameters
domConverter : DomConverter
Converter instance.
selection : DocumentSelection
View selection.
-
markToSync( type, node )
module:engine/view/renderer~Renderer#markToSync
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()
module:engine/view/renderer~Renderer#render
Renders all buffered changes (
markedAttributes
,markedChildren
andmarkedTexts
) 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>
module:engine/view/renderer~Renderer#_diffNodeLists
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
module:engine/view/renderer~Renderer#_domSelectionNeedsUpdate
private
Checks whether a given DOM selection needs to be updated.
Parameters
domSelection : Selection
The DOM selection to check.
Returns
Boolean
-
_fakeSelectionNeedsUpdate( domRoot ) → Boolean
module:engine/view/renderer~Renderer#_fakeSelectionNeedsUpdate
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>
module:engine/view/renderer~Renderer#_findReplaceActions
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
module:engine/view/renderer~Renderer#_getInlineFillerPosition
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
-
_isSelectionInInlineFiller() → Boolean
module:engine/view/renderer~Renderer#_isSelectionInInlineFiller
private
Returns
true
if the selection has not left the inline filler's text node. If it istrue
, 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 )
module:engine/view/renderer~Renderer#_markDescendantTextToSync
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
module:engine/view/renderer~Renderer#_needsInlineFillerAtSelection
private
Checks if the inline filler should be added.
Returns
Boolean
true
if the inline filler should be added.
-
_removeDomSelection()
module:engine/view/renderer~Renderer#_removeDomSelection
private
Removes the DOM selection.
-
_removeFakeSelection()
module:engine/view/renderer~Renderer#_removeFakeSelection
private
Removes the fake selection.
-
_removeInlineFiller()
module:engine/view/renderer~Renderer#_removeInlineFiller
private
Removes the inline filler.
-
_updateAttrs( viewElement )
module:engine/view/renderer~Renderer#_updateAttrs
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 } )
module:engine/view/renderer~Renderer#_updateChildren
private
Checks if elements child list needs to be updated and possibly updates it.
-
_updateChildrenMappings( viewElement )
module:engine/view/renderer~Renderer#_updateChildrenMappings
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 )
module:engine/view/renderer~Renderer#_updateDomSelection
private
Updates the DOM selection.
Parameters
domRoot : HTMLElement
A valid DOM root where the DOM selection should be rendered.
-
_updateElementMappings( viewElement, domElement )
module:engine/view/renderer~Renderer#_updateElementMappings
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 )
module:engine/view/renderer~Renderer#_updateFakeSelection
private
Updates the fake selection.
Parameters
domRoot : HTMLElement
A valid DOM root where the fake selection container should be added.
-
_updateFocus()
module:engine/view/renderer~Renderer#_updateFocus
private
Checks if focus needs to be updated and possibly updates it.
-
_updateSelection()
module:engine/view/renderer~Renderer#_updateSelection
private
Checks if the selection needs to be updated and possibly updates it.
-
_updateText( viewText, options = { options.inlineFillerPosition } )
module:engine/view/renderer~Renderer#_updateText
private
Checks if text needs to be updated and possibly updates it.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.