DocumentFragment (engine/model)
@ckeditor/ckeditor5-engine/src/model/documentfragment
DocumentFragment represents a part of model which does not have a common root but its top-level nodes can be seen as siblings. In other words, it is a detached part of model tree, without a root.
DocumentFragment has own MarkerCollection
. Markers from this collection
will be set to the model markers by a
insert
function.
Filtering
Properties
-
childCount : Number
readonly
Number of this document fragment's children.
-
isEmpty : Boolean
readonly
Is
true
if there are no nodes inside this document fragment,false
otherwise. -
DocumentFragment static markers map. This is a list of names and ranges which will be set as Markers to model markers collection when DocumentFragment will be inserted to the document.
-
maxOffset : Number
readonly
Sum of offset sizes of all of this document fragment's children.
-
parent : null
readonly
Artificial parent of
DocumentFragment
. Returnsnull
. Added for compatibility reasons. -
root : DocumentFragment
readonly
Artificial root of
DocumentFragment
. Returns itself. Added for compatibility reasons. -
List of nodes contained inside the document fragment.
Methods
-
constructor( [ children ] )
protected
Creates an empty
DocumentFragment
.Note: Constructor of this class shouldn't be used directly in the code. Use the
createDocumentFragment
method instead.Parameters
-
Symbol.iterator() → Iterable.<Node>
Returns an iterator that iterates over all nodes contained inside this document fragment.
Returns
Iterable.<Node>
-
Gets the child at the given index. Returns
null
if incorrect index was passed. -
getChildIndex( node ) → Number | null
Returns an index of the given child node. Returns
null
if given node is not a child of this document fragment. -
getChildStartOffset( node ) → Number | null
Returns the starting offset of given child. Starting offset is equal to the sum of offset sizes of all node's siblings that are before it. Returns
null
if given node is not a child of this document fragment. -
getChildren() → Iterable.<Node>
Returns an iterator that iterates over all of this document fragment's children.
Returns
Iterable.<Node>
-
getNodeByPath( relativePath ) → Node | DocumentFragment
Returns a descendant node by its path relative to this element.
Parameters
relativePath : Array.<Number>
Path of the node to find, relative to this element.
Returns
-
getPath() → Array
Returns path to a
DocumentFragment
, which is an empty array. Added for compatibility reasons.Returns
Array
-
is( type ) → Boolean
Checks whether this object is of the given type.
Check the entire list of model objects which implement the
is()
method.Parameters
type : String
Returns
Boolean
-
offsetToIndex( offset ) → Number
Converts offset "position" to index "position".
Returns index of a node that occupies given offset. If given offset is too low, returns
0
. If given offset is too high, returns index after last child}.Parameters
offset : Number
Offset to look for.
Returns
Number
Index of a node that occupies given offset.
-
toJSON() → Object
Converts
DocumentFragment
instance to plain object and returns it. Takes care of converting all of this document fragment's children.Returns
Object
DocumentFragment
instance converted to plain object.
-
_appendChild( items )
protected
Inserts one or more nodes at the end of this document fragment.
-
_insertChild( index, items )
protected
Inserts one or more nodes at the given index and sets parent of these nodes to this document fragment.
-
_removeChildren( index, [ howMany ] ) → Array.<Node>
protected
Static methods
-
fromJSON( json ) → DocumentFragment
static
Creates a
DocumentFragment
instance from given plain object (i.e. parsed JSON string). ConvertsDocumentFragment
children to proper nodes.Parameters
json : Object
Plain object to be converted to
DocumentFragment
.
Returns
DocumentFragment
DocumentFragment
instance created using given plain object.
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.