Skip to content

API > @blocksuite/store > Y > XmlElement

Class: XmlElement<KV> ​

An YXmlElement imitates the behavior of a Element.

  • An YXmlElement has attributes (key value pairs)
  • An YXmlElement has childElements that must inherit from YXmlElement

Extends ​

Constructors ​

constructor ​

new XmlElement<KV>(nodeName?): XmlElement< KV >

Type parameters ​

ParameterDefault
KV extends {}{}

Parameters ​

ParameterType
nodeName?string

Returns ​

XmlElement< KV >

Overrides ​

XmlFragment.constructor

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:18

Properties ​

_dEH ​

_dEH: EventHandler< YEvent< any >[], Transaction >

Deep event handlers

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:46

Inherited from ​

XmlFragment._dEH


_eH ​

_eH: EventHandler< YXmlEvent, Transaction >

Event handlers

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:41

Inherited from ​

XmlFragment._eH


_item ​

_item: null | Item

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:23

Inherited from ​

XmlFragment._item


_length ​

_length: number

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:36

Inherited from ​

XmlFragment._length


_map ​

_map: Map< string, Item >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:27

Inherited from ​

XmlFragment._map


_prelimAttrs ​

_prelimAttrs: null | Map< string, any >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:23


_prelimContent ​

_prelimContent: null | any[]

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:68

Inherited from ​

XmlFragment._prelimContent


_searchMarker ​

_searchMarker: null | ArraySearchMarker[]

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:50

Inherited from ​

XmlFragment._searchMarker


_start ​

_start: null | Item

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:31

Inherited from ​

XmlFragment._start


doc ​

doc: null | Doc

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:35

Inherited from ​

XmlFragment.doc


nodeName ​

nodeName: string

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:19

Accessors ​

_first ​

get _first(): null | Item

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:81

Inherited from ​

XmlFragment._first


firstChild ​

get firstChild(): null | XmlText | XmlElement< {} >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:72

Inherited from ​

XmlFragment.firstChild


length ​

get length(): number

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:91

Inherited from ​

XmlFragment.length


nextSibling ​

get nextSibling(): null | XmlText | XmlElement< {} >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:27


parent ​

get parent(): null | AbstractType< any >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:54

Inherited from ​

XmlFragment.parent


prevSibling ​

get prevSibling(): null | XmlText | XmlElement< {} >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:33

Methods ​

_callObserver ​

_callObserver(transaction, _parentSubs): void

Creates YEvent and calls all type observers. Must be implemented by each type.

Parameters ​

ParameterTypeDescription
transactionTransaction-
_parentSubsSet< null | string >Keys changed on this type. null if list was modified.

Returns ​

void

Inherited from ​

XmlFragment._callObserver

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:89


_copy ​

_copy(): XmlElement< {} >

Creates an Item with the same effect as this Item (without position effect)

Returns ​

XmlElement< {} >

Overrides ​

XmlFragment._copy

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:41


_integrate ​

_integrate(y, item): void

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 ​

ParameterTypeDescription
yDocThe Yjs instance
itemItem-

Returns ​

void

Inherited from ​

XmlFragment._integrate

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:85


_write ​

_write(_encoder): void

Parameters ​

ParameterType
_encoderUpdateEncoderV1 | UpdateEncoderV2

Returns ​

void

Inherited from ​

XmlFragment._write

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:77


clone ​

clone(): XmlElement< KV >

Returns ​

XmlElement< KV >

Overrides ​

XmlFragment.clone

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:45


createTreeWalker ​

createTreeWalker(filter): YXmlTreeWalker

Create a subtree of childNodes.

Parameters ​

ParameterTypeDescription
filterfunctionFunction 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.

Inherited from ​

XmlFragment.createTreeWalker

Example ​

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

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:109


delete ​

delete(index, length?): void

Deletes elements starting from an index.

Parameters ​

ParameterTypeDescription
indexnumberIndex at which to start deleting elements
length?numberThe number of elements to remove. Defaults to 1.

Returns ​

void

Inherited from ​

XmlFragment.delete

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:188


forEach ​

forEach(f): void

Executes a provided function on once on overy child element.

Parameters ​

ParameterTypeDescription
ffunctionA function to execute on every element of this YArray.

Returns ​

void

Inherited from ​

XmlFragment.forEach

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:227


get ​

get(index): XmlText | XmlElement< {} >

Returns the i-th element from a YArray.

Parameters ​

ParameterTypeDescription
indexnumberThe index of the element to return from the YArray

Returns ​

XmlText | XmlElement< {} >

Inherited from ​

XmlFragment.get

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:213


getAttribute ​

getAttribute<KEY_1>(attributeName): undefined | KV[KEY_1]

Returns an attribute value that belongs to the attribute name.

Type parameters ​

Parameter
KEY_1 extends string

Parameters ​

ParameterTypeDescription
attributeNameKEY_1The attribute name that identifies the
queried value.

Returns ​

undefined | KV[KEY_1]

The queried attribute value.

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:76


getAttributes ​

getAttributes(snapshot?): { [Key in string]?: KV[Key] }

Returns all attribute name/value pairs in a JSON Object.

Parameters ​

ParameterType
snapshot?Snapshot

Returns ​

{ [Key in string]?: KV[Key] }

A JSON Object that describes the attributes.

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:94


hasAttribute ​

hasAttribute(attributeName): boolean

Returns whether an attribute exists

Parameters ​

ParameterTypeDescription
attributeNamestringThe attribute name to check for existence.

Returns ​

boolean

whether the attribute exists.

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:85


insert ​

insert(index, content): void

Inserts new content at an index.

Parameters ​

ParameterTypeDescription
indexnumberThe index to insert content at
content(XmlText | XmlElement< {} >)[]The array of content

Returns ​

void

Inherited from ​

XmlFragment.insert

Example ​

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

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:170


insertAfter ​

insertAfter(ref, content): void

Inserts new content at an index.

Parameters ​

ParameterTypeDescription
refnull | Item | XmlText | XmlElement< {} >The index to insert content at
content(XmlText | XmlElement< {} >)[]The array of content

Returns ​

void

Inherited from ​

XmlFragment.insertAfter

Example ​

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

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:181


observe ​

observe(f): void

Observe all events that are created on this type.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

XmlFragment.observe

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:95


observeDeep ​

observeDeep(f): void

Observe all events that are created by this type and its children.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

XmlFragment.observeDeep

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:101


push ​

push(content): void

Appends content to this YArray.

Parameters ​

ParameterTypeDescription
content(XmlText | XmlElement< {} >)[]Array of content to append.

Returns ​

void

Inherited from ​

XmlFragment.push

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:200


querySelector ​

querySelector(query): null | XmlText | XmlHook | XmlElement< {} >

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

Query support:

  • tagname TODO:
  • id
  • attribute

Parameters ​

ParameterTypeDescription
querystringThe query on the children.

Returns ​

null | XmlText | XmlHook | XmlElement< {} >

The first element that matches the query or null.

Inherited from ​

XmlFragment.querySelector

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:125


querySelectorAll ​

querySelectorAll(query): (null | XmlText | XmlHook | XmlElement< {} >)[]

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

Parameters ​

ParameterTypeDescription
querystringThe query on the children

Returns ​

(null | XmlText | XmlHook | XmlElement< {} >)[]

The elements that match this query.

Inherited from ​

XmlFragment.querySelectorAll

Todo ​

Does not yet support all queries. Currently only query by tagName.

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:137


removeAttribute ​

removeAttribute(attributeName): void

Removes an attribute from this YXmlElement.

Parameters ​

ParameterTypeDescription
attributeNamestringThe attribute name that is to be removed.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:53


setAttribute ​

setAttribute<KEY>(attributeName, attributeValue): void

Sets or updates an attribute.

Type parameters ​

Parameter
KEY extends string

Parameters ​

ParameterTypeDescription
attributeNameKEYThe attribute name that is to be set.
attributeValueKV[KEY]The attribute value that is to be set.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlElement.d.ts:64


slice ​

slice(start?, end?): (XmlText | XmlElement< {} >)[]

Transforms this YArray to a JavaScript Array.

Parameters ​

ParameterType
start?number
end?number

Returns ​

(XmlText | XmlElement< {} >)[]

Inherited from ​

XmlFragment.slice

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:221


toArray ​

toArray(): (XmlText | XmlHook | XmlElement< {} >)[]

Transforms this YArray to a JavaScript Array.

Returns ​

(XmlText | XmlHook | XmlElement< {} >)[]

Inherited from ​

XmlFragment.toArray

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:194


toDOM ​

toDOM( _document?, hooks?, binding?): Node

Creates a Dom Element that mirrors this YXmlElement.

Parameters ​

ParameterTypeDescription
_document?DocumentThe document object (you must define
this when calling this method in
nodejs)
hooks?objectOptional property to customize how hooks
are presented in the DOM
binding?anyYou should not set this property. This is
used if DomBinding wants to create a
association to the created DOM type.

Returns ​

Node

The Element

Inherited from ​

XmlFragment.toDOM

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:157


toJSON ​

toJSON(): string

Returns ​

string

Inherited from ​

XmlFragment.toJSON

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:141


unobserve ​

unobserve(f): void

Unregister an observer function.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

XmlFragment.unobserve

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:107


unobserveDeep ​

unobserveDeep(f): void

Unregister an observer function.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

XmlFragment.unobserveDeep

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:113


unshift ​

unshift(content): void

Preppends content to this YArray.

Parameters ​

ParameterTypeDescription
content(XmlText | XmlElement< {} >)[]Array of content to preppend.

Returns ​

void

Inherited from ​

XmlFragment.unshift

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YXmlFragment.d.ts:206