Skip to content

API > @blocksuite/store > Y > Text

Class: Text ​

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

Extends ​

Constructors ​

constructor ​

new Text(string?): Text

Parameters ​

ParameterTypeDescription
string?stringThe initial value of the YText.

Returns ​

Text

Overrides ​

AbstractType.constructor

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:97

Properties ​

_dEH ​

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

Deep event handlers

Defined In ​

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

Inherited from ​

AbstractType._dEH


_eH ​

_eH: EventHandler< YTextEvent, Transaction >

Event handlers

Defined In ​

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

Inherited from ​

AbstractType._eH


_hasFormatting ​

_hasFormatting: boolean

Whether this YText contains formatting attributes. This flag is updated when a formatting item is integrated (see ContentFormat.integrate)

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:107


_item ​

_item: null | Item

Defined In ​

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

Inherited from ​

AbstractType._item


_length ​

_length: number

Defined In ​

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

Inherited from ​

AbstractType._length


_map ​

_map: Map< string, Item >

Defined In ​

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

Inherited from ​

AbstractType._map


_pending ​

_pending: null | () => void[]

Array of pending operations on this type

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:102


_searchMarker ​

_searchMarker: null | ArraySearchMarker[]

Defined In ​

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

Inherited from ​

AbstractType._searchMarker


_start ​

_start: null | Item

Defined In ​

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

Inherited from ​

AbstractType._start


doc ​

doc: null | Doc

Defined In ​

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

Inherited from ​

AbstractType.doc

Accessors ​

_first ​

get _first(): null | Item

Defined In ​

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

Inherited from ​

AbstractType._first


length ​

get length(): number

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:113


parent ​

get parent(): null | AbstractType< any >

Defined In ​

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

Inherited from ​

AbstractType.parent

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 ​

AbstractType._callObserver

Defined In ​

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


_copy ​

_copy(): Text

Returns ​

Text

Overrides ​

AbstractType._copy

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:119


_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

Overrides ​

AbstractType._integrate

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:118


_write ​

_write(_encoder): void

Parameters ​

ParameterType
_encoderUpdateEncoderV1 | UpdateEncoderV2

Returns ​

void

Inherited from ​

AbstractType._write

Defined In ​

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


applyDelta ​

applyDelta(delta, opts?): void

Apply a Delta on this shared YText type.

Parameters ​

ParameterTypeDescription
deltaanyThe changes to apply on this element.
opts?object-
opts.sanitize?booleanSanitize input delta. Removes ending newlines if set to true.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:141


clone ​

clone(): Text

Returns ​

Text

Overrides ​

AbstractType.clone

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:123


delete ​

delete(index, length): void

Deletes text starting from an index.

Parameters ​

ParameterTypeDescription
indexnumberIndex at which to start deleting.
lengthnumberThe number of characters to remove. Defaults to 1.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:185


format ​

format( index, length, attributes): void

Assigns properties to a range of text.

Parameters ​

ParameterTypeDescription
indexnumberThe position where to start formatting.
lengthnumberThe amount of characters to assign properties to.
attributesObjectAttribute information to apply on the
text.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:196


getAttribute ​

getAttribute(attributeName): any

Returns an attribute value that belongs to the attribute name.

Parameters ​

ParameterTypeDescription
attributeNamestringThe attribute name that identifies the
queried value.

Returns ​

any

The queried attribute value.

Note ​

Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:229


getAttributes ​

getAttributes(): object

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

Returns ​

object

A JSON Object that describes the attributes.

Note ​

Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:239


insert ​

insert( index, text, attributes?): void

Insert text at a given index.

Parameters ​

ParameterTypeDescription
indexnumberThe index at which to start inserting.
textstringThe text to insert at the specified position.
attributes?ObjectOptionally define some formatting
information to apply on the inserted
Text.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:165


insertEmbed ​

insertEmbed( index, embed, attributes?): void

Inserts an embed at a index.

Parameters ​

ParameterTypeDescription
indexnumberThe index to insert the embed at.
embedObject | AbstractType< any >The Object that represents the embed.
attributes?ObjectAttribute information to apply on the
embed

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:176


observe ​

observe(f): void

Observe all events that are created on this type.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

AbstractType.observe

Defined In ​

node_modules/.pnpm/yjs@13.6.8/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 ​

AbstractType.observeDeep

Defined In ​

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


removeAttribute ​

removeAttribute(attributeName): void

Removes an attribute.

Parameters ​

ParameterTypeDescription
attributeNamestringThe attribute name that is to be removed.

Returns ​

void

Note ​

Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:206


setAttribute ​

setAttribute(attributeName, attributeValue): void

Sets or updates an attribute.

Parameters ​

ParameterTypeDescription
attributeNamestringThe attribute name that is to be set.
attributeValueanyThe attribute value that is to be set.

Returns ​

void

Note ​

Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:217


toDelta ​

toDelta( snapshot?, prevSnapshot?, computeYChange?): any

Returns the Delta representation of this YText type.

Parameters ​

ParameterType
snapshot?Snapshot
prevSnapshot?Snapshot
computeYChange?function

Returns ​

any

The Delta representation of this type.

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:154


toJSON ​

toJSON(): string

Returns the unformatted string representation of this YText type.

Returns ​

string

Overrides ​

AbstractType.toJSON

Defined In ​

node_modules/.pnpm/yjs@13.6.8/node_modules/yjs/dist/src/types/YText.d.ts:130


unobserve ​

unobserve(f): void

Unregister an observer function.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

AbstractType.unobserve

Defined In ​

node_modules/.pnpm/yjs@13.6.8/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 ​

AbstractType.unobserveDeep

Defined In ​

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