Y.XmlFragment
A shared type to manage a collection of Y.Xml* Nodes
API
yxmlFragment.doc: Y.Doc | null
(readonly)
The Yjs document that this type is bound to. Is null
when it is not bound yet.
yxmlFragment.parent: Y.AbstractType | null
The parent that holds this type. Is null
if this yxmlFragment
is a top-level type.
yxmlFragment.firstChild: Y.XmlElement | Y.XmlText | null
The first child that holds this type holds. Is null
if this type doesn't hold any children.
yxmlFragment.length: number
The number of child-elements that this Y.XmlFragment holds.
yxmlFragment.insert(index: number, content: Array<Y.XmlElement | Y.XmlText>)
Insert content at a specified index
. Note that - for performance reasons - content is always an array of elements. I.e. yxmlFragment.insert(0, [new Y.XmlElement()])
inserts a single element at position 0.
yxmlFragment.insertAfter(ref: Y.XmlElement | Y.XmlText | null, content: Array<Y.XmlElement | Y.XmlText>)
Insert content after a reference element. If the reference element ref
is null, then the content is inserted at the beginning.
yxmlFragment.delete(index: number, length: number)
Delete length
elements starting from index
.
yxmlFragment.push(content: Array<Y.XmlElement | Y.XmlText>)
Append content at the end of the Y.XmlElement. Equivalent to yxmlFragment.insert(yxmlFragment.length, content)
.
yxmlFragment.unshift(content: Array<Y.XmlElement | Y.XmlText>)
Prepend content to the beginning of the Y.Array. Same as yxmlFragment.insert(0, content)
.
yxmlFragment.get(index: number): Y.XmlElement | Y.XmlText
Retrieve the n-th element.
yxmlFragment.toJSON(): String
Retrieve the JSON representation of this type. The result is a concatenated string of XML elements.
Example:
If the fragment contains more than one XML element, the output will not be a valid XML; It will need to be placed inside a container element to be valid and parsable. Example:
yxmlFragment.clone(): Y.XmlFragment
Clone all values into a fresh Y.XmlFragment instance. The returned type can be included into the Yjs document.
toDOM():DocumentFragment Transforms this type and all children to new DOM elements.
yxmlFragment.observe(function(Y.XmlEvent, Transaction))
Registers a change observer that will be called synchronously every time this shared type is modified. In the case this type is modified in the observer call, the event listener will be called again after the current event listener returns.
yxmlFragment.unobserve(function)
Unregisters a change observer that has been registered with yxmlFragment.observe
.
yxmlFragment.observeDeep(function(Array<Y.Event>, Transaction))
Registers a change observer that will be called synchronously every time this type or any of its children is modified. In the case this type is modified in the event listener, the event listener will be called again after the current event listener returns. The event listener receives all Events created by itself and any of its children.
yxmlFragment.unobserveDeep(function)
Unregisters a change observer that has been registered with yxmlFragment.observeDeep
.
Observing changes: Y.XmlEvent
Y.XmlEvent API
[todo]
Last updated
Was this helpful?