Home Reference Source
import YText from 'yjs/src/Types/YText/YText.js'
public class | source

YText

Extends:

ItemTypeYArray → YText

Direct Subclass:

YXmlText

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).

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

applyDelta(delta: Delta)

Apply a Delta on this shared YText type.

public

delete(index: Integer, length: Integer)

Deletes text starting from an index.

public

format(index: Integer, length: Integer, attributes: TextAttributes)

Assigns properties to a range of text.

public

insert(index: Integer, text: String, attributes: TextAttributes)

Insert text at a given index.

public

insertEmbed(index: Integer, embed: Object, attributes: TextAttributes)

Inserts an embed at a index.

public

Returns the Delta representation of this YText type.

public

toString(): *

Returns the unformatted string representation of this YText type.

Inherited Summary

From class Type
public

getPathTo(type: YType): Array<string>

Compute the path from this type to the specified target.

public

Observe all events that are created on this type.

public

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

public

Unregister an observer function.

public

Unregister an observer function.

From class YArray
public get

length: *

Computes the length of this YArray.

public

[Symbol.iterator](): {"next": *, "_item": *, "_itemElement": *, "_count": *}

public

delete(index: Integer, length: Integer)

Deletes elements starting from an index.

public

Executes a provided function on once on overy element of this YArray.

public

get(index: Integer): *

Returns the i-th element from a YArray.

public

insert(index: Integer, content: Array)

Inserts new content at an index.

public

Returns an Array with the result of calling a provided function on every element of this YArray.

public

push(content: Array)

Appends content to this YArray.

public

Transforms this YArray to a JavaScript Array.

public

Transforms this Shared Type to a JSON object.

Public Constructors

public constructor() source

Override:

Type#constructor

Public Methods

public applyDelta(delta: Delta) source

Apply a Delta on this shared YText type.

Params:

NameTypeAttributeDescription
delta Delta

The changes to apply on this element.

public delete(index: Integer, length: Integer) source

Deletes text starting from an index.

Override:

YArray#delete

Params:

NameTypeAttributeDescription
index Integer

Index at which to start deleting.

length Integer

The number of characters to remove. Defaults to 1.

public format(index: Integer, length: Integer, attributes: TextAttributes) source

Assigns properties to a range of text.

Params:

NameTypeAttributeDescription
index Integer

The position where to start formatting.

length Integer

The amount of characters to assign properties to.

attributes TextAttributes

Attribute information to apply on the text.

public insert(index: Integer, text: String, attributes: TextAttributes) source

Insert text at a given index.

Override:

YArray#insert

Params:

NameTypeAttributeDescription
index Integer

The index at which to start inserting.

text String

The text to insert at the specified position.

attributes TextAttributes

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

public insertEmbed(index: Integer, embed: Object, attributes: TextAttributes) source

Inserts an embed at a index.

Params:

NameTypeAttributeDescription
index Integer

The index to insert the embed at.

embed Object

The Object that represents the embed.

attributes TextAttributes

Attribute information to apply on the embed

public toDelta(): Delta source

Returns the Delta representation of this YText type.

Return:

Delta

The Delta representation of this type.

public toString(): * source

Returns the unformatted string representation of this YText type.

Return:

*