โ
import * as Y from 'yjs'โconst ydoc = new Y.Doc()โ// You can define a Y.Text as a top-level type or a nested typeโ// Method 1: Define a top-level typeconst yxmlText = ydoc.get('my text type', Y.XmlText)// Method 2: Define Y.XmlText that can be included into the Yjs documentconst yxmltextNested = new Y.XmlText()โ// Nested types can be included as content into any other shared typeyxmlText.set('my nested text', ytextNested)โ// Common methods (also available in Y.Text)yxmlText.insert(0, 'abc') // insert three elementsyxmlText.format(1, 2, { bold: true }) // delete second elementyxmlText.toString() // => 'abc'yxmlText.toDelta() // => [{ insert: 'a' }, { insert: 'bc', attributes: { bold: true }}]โ// methods only available in Y.TextyxmlText.toString() // => "a<bold>bc</bold>"yxmlText.nextSibling
Inherits from Y.Text.
const yxmlText = Y.XmlText()
yxmlText.prevSibling: Y.XmlElement | Y.XmlText | null
The previous sibling of this type. Is null if this is the first child of its parent.
yxmlText.nextSibling: Y.XmlElement | Y.XmlText | null
The next sibling of this type. Is null if this is the last child of its parent.
yxmlText.toString(): string
Returns the XML-String representation of this element. Formatting attributes are transformed to XML-tags. If the formatting attribute contains an object, the key-value pairs will be used as attributes. E.g.
ymxlText.insert(0, "my link", { a: { href: 'https://..' } })ymxlText.toString() // => <a href="https://..">my link</a>
โ
โ