YText.YText(stringopt)

Type that represents text with formatting information.

This type replaces y-richtext as this implementation is able to handle block formats (format information on a paragraph), embeds (complex elements like pictures and videos), and text formats (bold, italic).

new YText(stringopt)

Parameters:
Name Type Attributes Description
string String <optional>

The initial value of the YText.

Extends

Members

nullable _pending :Array.<function(): void>

Array of pending operations on this type

_searchMarker :Array.<ArraySearchMarker>

doc :Doc

length :number

Number of characters of this text type.

Methods

_callObserver(transaction, parentSubs)

Creates YTextEvent 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)

Parameters:
Name Type Description
y Doc
item Item

_write(encoder)

Parameters:
Name Type Description
encoder AbstractUpdateEncoder

applyDelta(delta, optsopt)

Apply a Delta on this shared YText type.

Parameters:
Name Type Attributes Description
delta any

The changes to apply on this element.

opts object <optional>
Properties
Name Type Attributes Description
sanitize boolean <optional>

Sanitize input delta. Removes ending newlines if set to true.

clone() → {YText}

Returns:
YText

delete(index, length)

Deletes text starting from an index.

Parameters:
Name Type Description
index number

Index at which to start deleting.

length number

The number of characters to remove. Defaults to 1.

format(index, length, attributes)

Assigns properties to a range of text.

Parameters:
Name Type Description
index number

The position where to start formatting.

length number

The amount of characters to assign properties to.

attributes TextAttributes

Attribute information to apply on the text.

getAttribute(attributeName) → {any}

Returns an attribute value that belongs to the attribute name.

Parameters:
Name Type Description
attributeName String

The attribute name that identifies the queried value.

Returns:
any -

The queried attribute value.

getAttributes(snapshotopt) → {Object.<string, any>}

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

Parameters:
Name Type Attributes Description
snapshot Snapshot <optional>
Returns:
Object.<string, any> -

A JSON Object that describes the attributes.

insert(index, text, attributesopt)

Insert text at a given index.

Parameters:
Name Type Attributes Description
index number

The index at which to start inserting.

text String

The text to insert at the specified position.

attributes TextAttributes <optional>

Optionally define some formatting information to apply on the inserted Text.

insertEmbed(index, embed, attributes)

Inserts an embed at a index.

Parameters:
Name Type Description
index number

The index to insert the embed at.

embed Object

The Object that represents the embed.

attributes TextAttributes

Attribute information to apply on the embed

removeAttribute(attributeName)

Removes an attribute.

Parameters:
Name Type Description
attributeName String

The attribute name that is to be removed.

setAttribute(attributeName, attributeValue)

Sets or updates an attribute.

Parameters:
Name Type Description
attributeName String

The attribute name that is to be set.

attributeValue any

The attribute value that is to be set.

toDelta(snapshotopt, prevSnapshotopt, computeYChangeopt) → {any}

Returns the Delta representation of this YText type.

Parameters:
Name Type Attributes Description
snapshot Snapshot <optional>
prevSnapshot Snapshot <optional>
computeYChange function <optional>
Returns:
any -

The Delta representation of this type.

toJSON() → {string}

Returns the unformatted string representation of this YText type.

Returns:
string

toString()

Returns the unformatted string representation of this YText type.