ModelDocumentFragment
ModelDocumentFragment 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.
ModelDocumentFragment has own MarkerCollection. Markers from this collection
will be set to the model markers by a
insert function.
Properties
-
childCount : numberreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#childCountNumber of this document fragment's children.
-
document : nullreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#documentArtificial owner of
ModelDocumentFragment. Returnsnull. Added for compatibility reasons. -
isEmpty : booleanreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#isEmptyIs
trueif there are no nodes inside this document fragment,falseotherwise. -
markers : Map<string, ModelRange>readonlymodule:engine/model/documentfragment~ModelDocumentFragment#markersModelDocumentFragment static markers map. This is a list of names and ranges which will be set as Markers to model markers collection when ModelDocumentFragment will be inserted to the document.
-
maxOffset : numberreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#maxOffsetSum of offset sizes of all of this document fragment's children.
-
name : undefinedmodule:engine/model/documentfragment~ModelDocumentFragment#nameArtificial element name. Returns
undefined. Added for compatibility reasons. -
nextSibling : nullreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#nextSiblingArtificial next sibling. Returns
null. Added for compatibility reasons. -
parent : nullreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#parentArtificial parent of
ModelDocumentFragment. Returnsnull. Added for compatibility reasons. -
previousSibling : nullreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#previousSiblingArtificial previous sibling. Returns
null. Added for compatibility reasons. -
root : ModelDocumentFragmentreadonlymodule:engine/model/documentfragment~ModelDocumentFragment#rootArtificial root of
ModelDocumentFragment. Returns itself. Added for compatibility reasons. -
rootName : undefinedmodule:engine/model/documentfragment~ModelDocumentFragment#rootNameArtificial root name. Returns
undefined. Added for compatibility reasons. -
_children : ModelNodeListprivatereadonlymodule:engine/model/documentfragment~ModelDocumentFragment#_childrenList of nodes contained inside the document fragment.
Methods
-
constructor( [ children ] )internalmodule:engine/model/documentfragment~ModelDocumentFragment#constructorCreates an empty
ModelDocumentFragment.Note: Constructor of this class shouldn't be used directly in the code. Use the
createDocumentFragmentmethod instead.Parameters
-
Symbol.iterator() → IterableIterator<ModelNode>module:engine/model/documentfragment~ModelDocumentFragment#Symbol.iteratorReturns an iterator that iterates over all nodes contained inside this document fragment.
Returns
IterableIterator<ModelNode>
-
getAncestors() → Array<never>module:engine/model/documentfragment~ModelDocumentFragment#getAncestorsReturns empty array. Added for compatibility reasons.
Returns
Array<never>
-
module:engine/model/documentfragment~ModelDocumentFragment#getChildGets the child at the given index. Returns
nullif incorrect index was passed.Parameters
index : numberIndex in this document fragment.
Returns
null | ModelNodeChild node.
-
getChildAtOffset( offset ) → null | ModelNodemodule:engine/model/documentfragment~ModelDocumentFragment#getChildAtOffsetGets the child at the given offset. Returns
nullif incorrect index was passed.Parameters
offset : numberOffset in this document fragment.
Returns
null | ModelNodeChild node.
-
getChildIndex( node ) → null | numbermodule:engine/model/documentfragment~ModelDocumentFragment#getChildIndexReturns an index of the given child node. Returns
nullif given node is not a child of this document fragment.Parameters
node : ModelNodeChild node to look for.
Returns
null | numberChild node's index.
-
getChildStartOffset( node ) → null | numbermodule:engine/model/documentfragment~ModelDocumentFragment#getChildStartOffsetReturns 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
nullif given node is not a child of this document fragment.Parameters
node : ModelNodeChild node to look for.
Returns
null | numberChild node's starting offset.
-
getChildren() → IterableIterator<ModelNode>module:engine/model/documentfragment~ModelDocumentFragment#getChildrenReturns an iterator that iterates over all of this document fragment's children.
Returns
IterableIterator<ModelNode>
-
getNodeByPath( relativePath ) → ModelNode | ModelDocumentFragmentmodule:engine/model/documentfragment~ModelDocumentFragment#getNodeByPathReturns a descendant node by its path relative to this element.
// <this>a<b>c</b></this> this.getNodeByPath( [ 0 ] ); // -> "a" this.getNodeByPath( [ 1 ] ); // -> <b> this.getNodeByPath( [ 1, 0 ] ); // -> "c"Copy codeParameters
relativePath : Array<number>Path of the node to find, relative to this element.
Returns
-
getPath() → Array<number>module:engine/model/documentfragment~ModelDocumentFragment#getPathReturns path to a
ModelDocumentFragment, which is an empty array. Added for compatibility reasons.Returns
Array<number>
-
is( type ) → this is ModelElement | ModelRootElementinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:ELEMENTChecks whether the object is of type
ModelElementor its subclass.element.is( 'element' ); // -> true element.is( 'node' ); // -> true element.is( 'model:element' ); // -> true element.is( 'model:node' ); // -> true element.is( 'view:element' ); // -> false element.is( 'documentSelection' ); // -> falseCopy codeAssuming that the object being checked is an element, you can also check its name:
element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element text.is( 'element', 'imageBlock' ); -> falseCopy codeParameters
type : 'element' | 'model:element'
Returns
this is ModelElement | ModelRootElement
-
module:engine/model/documentfragment~ModelDocumentFragment#is:TEXTChecks whether the object is of type
ModelText.text.is( '$text' ); // -> true text.is( 'node' ); // -> true text.is( 'model:$text' ); // -> true text.is( 'model:node' ); // -> true text.is( 'view:$text' ); // -> false text.is( 'documentSelection' ); // -> falseCopy codeNote: Until version 20.0.0 this method wasn't accepting
'$text'type. The legacy'text'type is still accepted for backward compatibility.Parameters
type : '$text' | 'model:$text'
Returns
this is ModelText
-
is( type ) → this is ModelPosition | ModelLivePositioninheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:POSITIONChecks whether the object is of type
ModelPositionor its subclass.position.is( 'position' ); // -> true position.is( 'model:position' ); // -> true position.is( 'view:position' ); // -> false position.is( 'documentSelection' ); // -> falseCopy codeParameters
type : 'position' | 'model:position'
Returns
this is ModelPosition | ModelLivePosition
-
is( type ) → this is ModelRootElementinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:ROOT_ELEMENTChecks whether the object is of type
ModelRootElement.rootElement.is( 'rootElement' ); // -> true rootElement.is( 'element' ); // -> true rootElement.is( 'node' ); // -> true rootElement.is( 'model:rootElement' ); // -> true rootElement.is( 'model:element' ); // -> true rootElement.is( 'model:node' ); // -> true rootElement.is( 'view:element' ); // -> false rootElement.is( 'documentFragment' ); // -> falseCopy codeAssuming that the object being checked is an element, you can also check its name:
rootElement.is( 'rootElement', '$root' ); // -> same as aboveCopy codeParameters
type : 'rootElement' | 'model:rootElement'
Returns
this is ModelRootElement
-
is( type ) → this is ModelLiveRangeinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:LIVE_RANGEChecks whether the object is of type
ModelLiveRange.liveRange.is( 'range' ); // -> true liveRange.is( 'model:range' ); // -> true liveRange.is( 'liveRange' ); // -> true liveRange.is( 'model:liveRange' ); // -> true liveRange.is( 'view:range' ); // -> false liveRange.is( 'documentSelection' ); // -> falseCopy codeParameters
type : 'liveRange' | 'model:liveRange'
Returns
this is ModelLiveRange
-
module:engine/model/documentfragment~ModelDocumentFragment#is:MARKER -
is( type ) → this is ModelTextProxyinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:TEXT_PROXYChecks whether the object is of type
ModelTextProxy.textProxy.is( '$textProxy' ); // -> true textProxy.is( 'model:$textProxy' ); // -> true textProxy.is( 'view:$textProxy' ); // -> false textProxy.is( 'range' ); // -> falseCopy codeNote: Until version 20.0.0 this method wasn't accepting
'$textProxy'type. The legacy'textProxt'type is still accepted for backward compatibility.Parameters
type : '$textProxy' | 'model:$textProxy'
Returns
this is ModelTextProxy
-
is( type ) → this is ModelDocumentSelectioninheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:DOCUMENT_SELECTIONChecks whether the object is of type
ModelDocumentSelection.selection.is( 'selection' ); // -> true selection.is( 'documentSelection' ); // -> true selection.is( 'model:selection' ); // -> true selection.is( 'model:documentSelection' ); // -> true selection.is( 'view:selection' ); // -> false selection.is( 'element' ); // -> false selection.is( 'node' ); // -> falseCopy codeParameters
type : 'documentSelection' | 'model:documentSelection'
Returns
this is ModelDocumentSelection
-
is( type ) → this is ModelSelection | ModelDocumentSelectioninheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:SELECTIONChecks whether the object is of type
ModelSelectionorModelDocumentSelection.selection.is( 'selection' ); // -> true selection.is( 'model:selection' ); // -> true selection.is( 'view:selection' ); // -> false selection.is( 'range' ); // -> falseCopy codeParameters
type : 'selection' | 'model:selection'
Returns
this is ModelSelection | ModelDocumentSelection
-
is( type ) → this is ModelDocumentFragmentinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:DOCUMENT_FRAGMENTChecks whether the object is of type
ModelDocumentFragment.docFrag.is( 'documentFragment' ); // -> true docFrag.is( 'model:documentFragment' ); // -> true docFrag.is( 'view:documentFragment' ); // -> false docFrag.is( 'element' ); // -> false docFrag.is( 'node' ); // -> falseCopy codeParameters
type : 'documentFragment' | 'model:documentFragment'
Returns
this is ModelDocumentFragment
-
is( type ) → this is ModelRange | ModelLiveRangeinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:RANGEChecks whether the object is of type
ModelRangeor its subclass.range.is( 'range' ); // -> true range.is( 'model:range' ); // -> true range.is( 'view:range' ); // -> false range.is( 'documentSelection' ); // -> falseCopy codeParameters
type : 'range' | 'model:range'
Returns
this is ModelRange | ModelLiveRange
-
is( type ) → this is ModelLivePositioninheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:LIVE_POSITIONChecks whether the object is of type
ModelLivePosition.livePosition.is( 'position' ); // -> true livePosition.is( 'model:position' ); // -> true livePosition.is( 'liveposition' ); // -> true livePosition.is( 'model:livePosition' ); // -> true livePosition.is( 'view:position' ); // -> false livePosition.is( 'documentSelection' ); // -> falseCopy codeParameters
type : 'livePosition' | 'model:livePosition'
Returns
this is ModelLivePosition
-
is( type, name ) → booleaninheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:ELEMENT_NAMEChecks whether the object is of type
ModelElementor its subclass and has the specifiedname.element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element text.is( 'element', 'imageBlock' ); -> falseCopy codeType parameters
N : extends string
Parameters
type : 'element' | 'model:element'name : N
Returns
boolean
-
is( type, name ) → booleaninheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:ROOT_ELEMENT_NAMEChecks whether the object is of type
ModelRootElementand has the specifiedname.rootElement.is( 'rootElement', '$root' );Copy codeType parameters
N : extends string
Parameters
type : 'rootElement' | 'model:rootElement'name : N
Returns
boolean
-
is( type ) → this is ModelNode | ModelText | ModelElement | ModelRootElementinheritedmodule:engine/model/documentfragment~ModelDocumentFragment#is:NODEChecks whether the object is of type
ModelNodeor its subclass.This method is useful when processing model objects that are of unknown type. For example, a function may return a
ModelDocumentFragmentor aModelNodethat can be either a text node or an element. This method can be used to check what kind of object is returned.someObject.is( 'element' ); // -> true if this is an element someObject.is( 'node' ); // -> true if this is a node (a text node or an element) someObject.is( 'documentFragment' ); // -> true if this is a document fragmentCopy codeSince this method is also available on a range of view objects, you can prefix the type of the object with
model:orview:to check, for example, if this is the model's or view's element:modelElement.is( 'model:element' ); // -> true modelElement.is( 'view:element' ); // -> falseCopy codeBy using this method it is also possible to check a name of an element:
imageElement.is( 'element', 'imageBlock' ); // -> true imageElement.is( 'element', 'imageBlock' ); // -> same as above imageElement.is( 'model:element', 'imageBlock' ); // -> same as above, but more preciseCopy codeParameters
type : 'node' | 'model:node'
Returns
this is ModelNode | ModelText | ModelElement | ModelRootElement
-
isAttached() → falsemodule:engine/model/documentfragment~ModelDocumentFragment#isAttachedReturns
falseasModelDocumentFragmentby definition is not attached to a document. Added for compatibility reasons.Returns
false
-
offsetToIndex( offset ) → numbermodule:engine/model/documentfragment~ModelDocumentFragment#offsetToIndexConverts 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.const textNode = new Text( 'foo' ); const pElement = new Element( 'p' ); const docFrag = new ModelDocumentFragment( [ textNode, pElement ] ); docFrag.offsetToIndex( -1 ); // Returns 0, because offset is too low. docFrag.offsetToIndex( 0 ); // Returns 0, because offset 0 is taken by `textNode` which is at index 0. docFrag.offsetToIndex( 1 ); // Returns 0, because `textNode` has `offsetSize` equal to 3, so it occupies offset 1 too. docFrag.offsetToIndex( 2 ); // Returns 0. docFrag.offsetToIndex( 3 ); // Returns 1. docFrag.offsetToIndex( 4 ); // Returns 2. There are no nodes at offset 4, so last available index is returned.Copy codeParameters
offset : numberOffset to look for.
Returns
numberIndex of a node that occupies given offset.
-
toJSON() → unknownmodule:engine/model/documentfragment~ModelDocumentFragment#toJSONConverts
ModelDocumentFragmentinstance to plain object and returns it. Takes care of converting all of this document fragment's children.Returns
unknownModelDocumentFragmentinstance converted to plain object.
-
_appendChild( items ) → voidinternalmodule:engine/model/documentfragment~ModelDocumentFragment#_appendChild -
_insertChild( index, items ) → voidinternalmodule:engine/model/documentfragment~ModelDocumentFragment#_insertChild -
_removeChildren( index, howMany ) → Array<ModelNode>internalmodule:engine/model/documentfragment~ModelDocumentFragment#_removeChildren -
_removeChildrenArray( nodes ) → voidinternalmodule:engine/model/documentfragment~ModelDocumentFragment#_removeChildrenArray
Static methods
-
fromJSON( json ) → ModelDocumentFragmentstaticmodule:engine/model/documentfragment~ModelDocumentFragment.fromJSONCreates a
ModelDocumentFragmentinstance from given plain object (i.e. parsed JSON string). ConvertsModelDocumentFragmentchildren to proper nodes.Parameters
json : anyPlain object to be converted to
ModelDocumentFragment.
Returns
ModelDocumentFragmentModelDocumentFragmentinstance created using given plain object.