Skip to main content

@lexical/y

Classes​

YBinding​

Defined in: packages/lexical-y/src/internal/Binding.ts:252

Experimental

A Yjs 14 binding for one editor and one shared root.

Every container (the root, and every node stored as its own Y.Node) holds one sequence of text, child nodes and line markers; see the package README for the layout.

Warnings (read only states, recoveries, the opt-in self-check) go to the editor's onWarn as LexicalWarnings with @lexical/y/... codes (see UNSUPPORTED_LAYOUT_WARNING and the other *_WARNING constants), once a remote change has been applied in full: never from inside a Yjs observer or transaction. A handler that throws does not affect syncing.

Constructors​

Constructor​

new YBinding(editor, doc, options?): YBinding

Defined in: packages/lexical-y/src/internal/Binding.ts:436

Experimental

Parameters​
editor​

LexicalEditor

doc​

Doc

options?​

YBindingOptions = {}

Returns​

YBinding

Accessors​

doc​
Get Signature​

get doc(): Doc

Defined in: packages/lexical-y/src/internal/Binding.ts:409

Experimental

The shared document.

Returns​

Doc

editor​
Get Signature​

get editor(): LexicalEditor

Defined in: packages/lexical-y/src/internal/Binding.ts:404

Experimental

The bound editor.

Returns​

LexicalEditor

pins​
Get Signature​

get pins(): ReadonlyMap<string, { by?: readonly string[]; kind: StorageKind; }>

Defined in: packages/lexical-y/src/internal/Binding.ts:424

Experimental

Storage kinds the document records per node type (see the README).

Returns​

ReadonlyMap<string, { by?: readonly string[]; kind: StorageKind; }>

root​
Get Signature​

get root(): YNode

Defined in: packages/lexical-y/src/internal/Binding.ts:414

Experimental

The shared root this binding reads and writes.

Returns​

YNode

status​
Get Signature​

get status(): YBindingStatus

Defined in: packages/lexical-y/src/internal/Binding.ts:419

Experimental

See YBindingStatus; onStatus reports changes.

Returns​

YBindingStatus

undoManager​
Get Signature​

get undoManager(): UndoManager | null

Defined in: packages/lexical-y/src/internal/Binding.ts:432

Experimental

The collaborative undo manager; null when undo is disabled.

Returns​

UndoManager | null

Methods​

$resolveCursor()​

$resolveCursor(cursor): { anchor: PointType; focus: PointType; } | null

Defined in: packages/lexical-y/src/internal/Binding.ts:3192

Experimental

Resolve a cursor to Lexical points (call inside a read or update).

Parameters​
cursor​

YCursor

Returns​

{ anchor: PointType; focus: PointType; } | null

dispose()​

dispose(): void

Defined in: packages/lexical-y/src/internal/Binding.ts:654

Experimental

Disconnect from the document and the editor (start returns this).

Returns​

void

getCursor()​

getCursor(): YCursor | null

Defined in: packages/lexical-y/src/internal/Binding.ts:3090

Experimental

The local selection as relative positions (JSON), or null.

Returns​

YCursor | null

initialize()​

initialize(): void

Defined in: packages/lexical-y/src/internal/Binding.ts:688

Experimental

Call after the provider's first sync. An empty root is marked with this layout and gets the editor's current content, unless an older layout's root (root, root-v2) has content: such a document is read only, and must be converted instead (a binding with convert: true writes the layout root next to the old one). Anything else is read.

The initial content (including an update still pending, such as editor.update(seed) right before this call) is not part of the undo history. Into a pristine root (one that has never held an item or an attribute), it is written with a client id derived from the layout version and the content itself, so that two clients initializing the same document with the same content at once write the same items (one copy); anywhere else, with this client's own id.

Returns​

void

redo()​

redo(): boolean

Defined in: packages/lexical-y/src/internal/Binding.ts:2953

Experimental

Redo what undo undid; see undo.

Returns​

boolean

start()​

start(): () => void

Defined in: packages/lexical-y/src/internal/Binding.ts:456

Experimental

Start listening; read the document if it is already initialized.

Returns​

() => void

undo()​

undo(): boolean

Defined in: packages/lexical-y/src/internal/Binding.ts:2948

Experimental

Undo this client's last change in the document (collaborative undo). Returns whether there was one; false while the binding is not active.

Returns​

boolean

Interfaces​

YBindingOptions​

Defined in: packages/lexical-y/src/internal/Binding.ts:167

Experimental

Options of YBinding (and YCollabExtension).

Properties​

captureTimeout?​

optional captureTimeout?: number | null

Defined in: packages/lexical-y/src/internal/Binding.ts:171

Experimental

Undo capture timeout in ms (default 500); null disables undo.

clientIDRange?​

optional clientIDRange?: ClientIDRange

Defined in: packages/lexical-y/src/internal/Binding.ts:206

Experimental

The range of the document's client ids: 'uint53' (default, Yjs 14's ids, left as they are) or 'uint32' (kept in 32 bits, for servers on yrs before 0.28; see ClientIDRange).

convert?​

optional convert?: boolean

Defined in: packages/lexical-y/src/internal/Binding.ts:200

Experimental

Initialize even when an older layout's root has content: for a converter writing the layout root of an existing document.

onStatus?​

optional onStatus?: (status) => void

Defined in: packages/lexical-y/src/internal/Binding.ts:177

Experimental

Called when status changes, once the binding's work is done and Yjs is idle (like warnings, never inside a Yjs observer or transaction). Several changes in one such step report the last.

Parameters​
status​

YBindingStatus

Returns​

void

root?​

optional root?: YNode<any>

Defined in: packages/lexical-y/src/internal/Binding.ts:169

Experimental

The shared root to bind; defaults to doc.get('lexical-y').

selfCheck?​

optional selfCheck?: boolean

Defined in: packages/lexical-y/src/internal/Binding.ts:188

Experimental

Read every line a local write touched back from Yjs and compare it with the editor; mismatches are reported to the editor's onWarn as a LexicalWarning (code '@lexical/y/self-check'). Structural changes (and remote changes) also compare a fresh read of the whole container: every time for containers of up to 256 lines and nodes, and with probability 256 / size for bigger ones, so the expected cost of an edit stays bounded. Default: off. A debugging aid: turn it on in tests and development builds to catch binding bugs.

selfCheckSample?​

optional selfCheckSample?: number

Defined in: packages/lexical-y/src/internal/Binding.ts:195

Experimental

The fraction of changes the self-check samples (default 1): of local writes, and of remote changes, where a sampled check that finds the editor differing from the shared content also reads those containers again (see selfCheck).


YCollabConfig​

Defined in: packages/lexical-y/src/internal/YExtension.ts:34

Experimental

The configuration of YCollabExtension.

Properties​

captureTimeout​

captureTimeout: number | null

Defined in: packages/lexical-y/src/internal/YExtension.ts:46

Experimental

Undo capture timeout in ms; null disables collaborative undo.

clientIDRange​

clientIDRange: ClientIDRange

Defined in: packages/lexical-y/src/internal/YExtension.ts:48

Experimental

See YBindingOptions.clientIDRange (default 'uint53').

convert​

convert: boolean

Defined in: packages/lexical-y/src/internal/YExtension.ts:57

Experimental

See YBindingOptions.convert (default false).

doc​

doc: Doc | null

Defined in: packages/lexical-y/src/internal/YExtension.ts:36

Experimental

The shared document. Required.

root​

root: YNode<any> | null

Defined in: packages/lexical-y/src/internal/YExtension.ts:38

Experimental

The shared root; defaults to doc.get('lexical-y').

selfCheck​

selfCheck: boolean | null

Defined in: packages/lexical-y/src/internal/YExtension.ts:53

Experimental

See YBindingOptions.selfCheck; null keeps the default (off). Warnings go to the editor's onWarn.

selfCheckSample​

selfCheckSample: number | null

Defined in: packages/lexical-y/src/internal/YExtension.ts:55

Experimental

See YBindingOptions.selfCheckSample; null keeps the default (1).

synced​

synced: boolean

Defined in: packages/lexical-y/src/internal/YExtension.ts:44

Experimental

Initialize as soon as the extension registers: use it when the document is already synced (a headless writer, a converter, tests). Otherwise call binding.initialize() after the provider's first sync.


YCursor​

Defined in: packages/lexical-y/src/internal/Binding.ts:213

Experimental

A selection as Yjs relative positions, from YBinding#getCursor (for an awareness-based cursor UI).

Properties​

anchor​

anchor: unknown

Defined in: packages/lexical-y/src/internal/Binding.ts:214

Experimental

focus​

focus: unknown

Defined in: packages/lexical-y/src/internal/Binding.ts:215

Experimental

Type Aliases​

ClientIDRange​

ClientIDRange = "uint53" | "uint32"

Defined in: packages/lexical-y/src/internal/ClientID.ts:20

Experimental

The range of the client ids a document writes with.

  • 'uint53': Yjs 14's default (random 53-bit ids).
  • 'uint32': ids that fit in 32 bits, for servers that read client ids as 32-bit numbers (yrs before 0.28, e.g. y-crdt relays on 0.23): with a 53-bit id, such a server stores the author's content under a truncated id, and the author receives its own content back as another client's on reconnect, duplicating the document.

StorageKind​

StorageKind = "line" | "format" | "group" | "nested"

Defined in: packages/lexical-y/src/internal/Schema.ts:226

Experimental

How @lexical/y stores an element type; see describeStorage.


YBindingStatus​

YBindingStatus = "pending" | "active" | "readonly"

Defined in: packages/lexical-y/src/internal/Binding.ts:154

Experimental

The state of a YBinding.


YWarningCode​

YWarningCode = typeof UNSUPPORTED_LAYOUT_WARNING | typeof UNKNOWN_NODE_TYPES_WARNING | typeof STORAGE_MISMATCH_WARNING | typeof SELF_CHECK_WARNING | typeof RECOVERED_READ_WARNING | typeof RECOVERED_WRITE_WARNING | typeof NESTED_FALLBACK_WARNING | typeof UNSYNCED_VALUE_WARNING | typeof UNSUPPORTED_SLOTS_WARNING | typeof UNSUPPORTED_CONFIG_WARNING

Defined in: packages/lexical-y/src/internal/Warnings.ts:91

Experimental

The codes of the LexicalWarnings @lexical/y passes to the editor's onWarn (error.code when error instanceof LexicalWarning). Codes are public API: a code is never renamed, and never reused for another condition; new codes may be added in any release, so a switch over error.code needs a default branch.

Variables​

DEFAULT_ROOT_NAME​

const DEFAULT_ROOT_NAME: "lexical-y" = 'lexical-y'

Defined in: packages/lexical-y/src/internal/constants.ts:13

Experimental

The default name of the shared root, which @lexical/yjs clients never write to (they use root and root-v2).


LAYOUT_VERSION​

const LAYOUT_VERSION: 1 = 1

Defined in: packages/lexical-y/src/internal/constants.ts:25

Experimental

The layout version this binding reads and writes.


NESTED_FALLBACK_WARNING​

const NESTED_FALLBACK_WARNING: "@lexical/y/nested-fallback" = '@lexical/y/nested-fallback'

Defined in: packages/lexical-y/src/internal/Warnings.ts:56

Experimental

A node class's declarations make it a line, format or group, but something the class does prevents it (an incomplete schema, an overridden merge method, slots): it is stored as a nested node. Reported once per class and reason. data: {type: string}.


RECOVERED_READ_WARNING​

const RECOVERED_READ_WARNING: "@lexical/y/recovered-read" = '@lexical/y/recovered-read'

Defined in: packages/lexical-y/src/internal/Warnings.ts:43

Experimental

A remote change could not be read: the editor was rebuilt from the document. data: {error: unknown} (what the reader threw).


RECOVERED_WRITE_WARNING​

const RECOVERED_WRITE_WARNING: "@lexical/y/recovered-write" = '@lexical/y/recovered-write'

Defined in: packages/lexical-y/src/internal/Warnings.ts:49

Experimental

A local change could not be written: the document was rewritten from the editor. data: {error: unknown} (what the writer threw).


SELF_CHECK_WARNING​

const SELF_CHECK_WARNING: "@lexical/y/self-check" = '@lexical/y/self-check'

Defined in: packages/lexical-y/src/internal/Warnings.ts:38

Experimental

The self-check (selfCheck, off by default) found the editor and the document disagree. data: {problems: string[], remote: boolean} (remote: found reading a peer's change, which the binding then reads again in full).


STORAGE_MISMATCH_WARNING​

const STORAGE_MISMATCH_WARNING: "@lexical/y/storage-mismatch" = '@lexical/y/storage-mismatch'

Defined in: packages/lexical-y/src/internal/Warnings.ts:31

Experimental

The document stores node types in a way this editor's classes cannot (another storage kind or group identity): the binding is read only. data: {types: string[]}.


UNKNOWN_NODE_TYPES_WARNING​

const UNKNOWN_NODE_TYPES_WARNING: "@lexical/y/unknown-node-types" = '@lexical/y/unknown-node-types'

Defined in: packages/lexical-y/src/internal/Warnings.ts:25

Experimental

The document has node types the editor does not register: the binding is read only. data: {types: string[]}.


UNSUPPORTED_CONFIG_WARNING​

const UNSUPPORTED_CONFIG_WARNING: "@lexical/y/unsupported-config" = '@lexical/y/unsupported-config'

Defined in: packages/lexical-y/src/internal/Warnings.ts:82

Experimental

The editor is configured in a way the binding cannot write safely: BlockIdExtension with repairTransforms: true (YCollabExtension sets false; an app overrode it, or a YBinding used directly runs with the extension's default). Nothing is written and the binding is read only. data: {options: string[]} ('<extension>.<option>').


UNSUPPORTED_LAYOUT_WARNING​

const UNSUPPORTED_LAYOUT_WARNING: "@lexical/y/unsupported-layout" = '@lexical/y/unsupported-layout'

Defined in: packages/lexical-y/src/internal/Warnings.ts:20

Experimental

The document's layout record is missing (its root has content, or the record was removed), newer than this version supports or malformed, or an older layout's root has content: the binding is read only. data: {layout: number | undefined, legacyRoots: string[]} (the layout version the record names when it is newer, otherwise undefined, and the older layouts' roots that hold content).


UNSUPPORTED_SLOTS_WARNING​

const UNSUPPORTED_SLOTS_WARNING: "@lexical/y/unsupported-slots" = '@lexical/y/unsupported-slots'

Defined in: packages/lexical-y/src/internal/Warnings.ts:73

Experimental

A node holds named slots where the document cannot store them: on a node stored as a line, a format or a group (a slot set on a paragraph, a link or a list), or on the root. The change is not written and the binding is read only. data: {types: string[]} (the types of those nodes).


UNSYNCED_VALUE_WARNING​

const UNSYNCED_VALUE_WARNING: "@lexical/y/unsynced-value" = '@lexical/y/unsynced-value'

Defined in: packages/lexical-y/src/internal/Warnings.ts:64

Experimental

A node property or NodeState value is not plain JSON (for example a nested editor instance), so it is not synchronized. Reported once per property. data: {property: string} ('<type>.<field>' or 'NodeState <key>').


YCollabExtension​

const YCollabExtension: LexicalExtension<YCollabConfig, "@lexical/y/Collab", { binding: YBinding; status: ReadonlySignal<YBindingStatus>; }, unknown>

Defined in: packages/lexical-y/src/internal/YExtension.ts:67

Experimental

Binds the editor to a Yjs 14 document with the block-marker layout, and provides collaborative undo (UNDO_COMMAND / REDO_COMMAND, CAN_UNDO_COMMAND / CAN_REDO_COMMAND). Its output has the binding and a status signal ('pending' until the layout record is read, then 'active' or 'readonly'). It conflicts with the history extensions.

Functions​

describeStorage()​

describeStorage(editor, binding?): Record<string, StorageKind | "text">

Defined in: packages/lexical-y/src/internal/Describe.ts:28

Experimental

How @lexical/y stores each node type: 'line', 'format', 'group' or 'nested' for elements (derived from the classes' $config() declarations, or the kind a document recorded when binding is given), 'text' for text and line breaks, 'nested' for decorators. The root is left out.

Parameters​

editor​

LexicalEditor

binding?​
pins​

ReadonlyMap<string, { kind: StorageKind; }>

Returns​

Record<string, StorageKind | "text">