YXml.YXmlFragment()

Represents a list of YXmlElement.and YXmlText types. A YxmlFragment is similar to a YXmlElement, but it does not have a nodeName and it does not have attributes. Though it can be bound to a DOM element - in this case the attributes and the nodeName are not shared.

new YXmlFragment()

Extends

Members

_prelimContent :Array.<any>|null

_prelimContent :Array.<any>

_prelimContent :Array.<any>

firstChild :YXmlElement|YXmlText|null

Methods

_callObserver(transaction, parentSubs)

Creates YXmlEvent and calls observers.

Parameters:
Name Type Description
transaction Transaction
parentSubs Set.<(null|string)>

Keys changed on this type. null if list was modified.

_integrate(y, item)

Integrate this type into the Yjs instance.

  • Save this struct in the os
  • This type is sent to other client
  • Observer functions are fired
Parameters:
Name Type Description
y Doc

The Yjs instance

item Item

_write(encoder)

Transform the properties of this type to binary and write it to an BinaryEncoder.

This is called when this Item is sent to a remote peer.

Parameters:
Name Type Description
encoder AbstractUpdateEncoder

The encoder to write data to.

clone() → {YXmlFragment}

Returns:
YXmlFragment

createTreeWalker(filter) → {YXmlTreeWalker}

Create a subtree of childNodes.

Parameters:
Name Type Description
filter function

Function that is called on each child element and returns a Boolean indicating whether the child is to be included in the subtree.

Returns:
YXmlTreeWalker -

A subtree and a position within it.

Example
const walker = elem.createTreeWalker(dom => dom.nodeName === 'div')
for (let node in walker) {
  // `node` is a div node
  nop(node)
}

delete(index, lengthopt)

Deletes elements starting from an index.

Parameters:
Name Type Attributes Default Description
index number

Index at which to start deleting elements

length number <optional>
1

The number of elements to remove. Defaults to 1.

get(index) → {YXmlElement|YXmlText}

Returns the i-th element from a YArray.

Parameters:
Name Type Description
index number

The index of the element to return from the YArray

Returns:
YXmlElement | YXmlText

insert(index, content)

Inserts new content at an index.

Parameters:
Name Type Description
index number

The index to insert content at

content Array.<(YXmlElement|YXmlText)>

The array of content

Example
// Insert character 'a' at position 0
 xml.insert(0, [new Y.XmlText('text')])

insertAfter(ref, content)

Inserts new content at an index.

Parameters:
Name Type Description
ref null | Item | YXmlElement | YXmlText

The index to insert content at

content Array.<(YXmlElement|YXmlText)>

The array of content

Example
// Insert character 'a' at position 0
 xml.insert(0, [new Y.XmlText('text')])

push(content)

Appends content to this YArray.

Parameters:
Name Type Description
content Array.<(YXmlElement|YXmlText)>

Array of content to append.

querySelector(query) → {YXmlElement|YXmlText|YXmlHook|null}

Returns the first YXmlElement that matches the query. Similar to DOM's querySelector.

Query support:

  • tagname TODO:
  • id
  • attribute
Parameters:
Name Type Description
query CSS_Selector

The query on the children.

Returns:
YXmlElement | YXmlText | YXmlHook | null -

The first element that matches the query or null.

querySelectorAll(query) → {Array.<(YXmlElement|YXmlText|YXmlHook|null)>}

Returns all YXmlElements that match the query. Similar to Dom's querySelectorAll.

Parameters:
Name Type Description
query CSS_Selector

The query on the children

Returns:
Array.<(YXmlElement|YXmlText|YXmlHook|null)> -

The elements that match this query.

To Do:
  • Does not yet support all queries. Currently only query by tagName.

slice(startopt, endopt) → {Array.<(YXmlElement|YXmlText)>}

Transforms this YArray to a JavaScript Array.

Parameters:
Name Type Attributes Default Description
start number <optional>
0
end number <optional>
Returns:
Array.<(YXmlElement|YXmlText)>

toArray() → {Array.<(YXmlElement|YXmlText|YXmlHook)>}

Transforms this YArray to a JavaScript Array.

Returns:
Array.<(YXmlElement|YXmlText|YXmlHook)>

toDOM(_documentopt, hooksopt, bindingopt) → {Node}

Creates a Dom Element that mirrors this YXmlElement.

Parameters:
Name Type Attributes Default Description
_document Document <optional>
document

The document object (you must define this when calling this method in nodejs)

hooks Object.<string, any> <optional>
{}

Optional property to customize how hooks are presented in the DOM

binding any <optional>

You should not set this property. This is used if DomBinding wants to create a association to the created DOM type.

Returns:
Node -

The Dom Element

toJSON() → {string}

Returns:
string

toString() → {string}

Get the string representation of all the children of this YXmlFragment.

Returns:
string -

The string representation of all children.

unshift(content)

Preppends content to this YArray.

Parameters:
Name Type Description
content Array.<(YXmlElement|YXmlText)>

Array of content to preppend.