Skip to main content

@lexical/y

Classes​

YBinding​

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

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.

Constructors​

Constructor​

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

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

Experimental

Parameters​
editor​

LexicalEditor

doc​

Doc

options?​

YBindingOptions = {}

Returns​

YBinding

Properties​

doc​

readonly doc: Doc

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

Experimental

editor​

readonly editor: LexicalEditor

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

Experimental

root​

readonly root: YNode

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

Experimental

status​

status: YBindingStatus = 'pending'

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

Experimental

undoManager​

undoManager: UndoManager | null = null

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

Experimental

Methods​

$resolveCursor()​

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

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

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:276

Experimental

Returns​

void

getCursor()​

getCursor(): YCursor | null

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

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:301

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 other than an upgrade notice: such a document must be converted (writeEditorToYDoc) instead. Anything else is read.

The initial content 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), and is not part of the undo history.

Returns​

void

redo()​

redo(): boolean

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

Experimental

Returns​

boolean

start()​

start(): () => void

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

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:1199

Experimental

Returns​

boolean

Interfaces​

YBindingOptions​

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

Experimental

Options of YBinding (and YCollabExtension).

Properties​

captureTimeout?​

optional captureTimeout?: number | null

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

Experimental

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

clientIDRange?​

optional clientIDRange?: ClientIDRange

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

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:121

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:105

Experimental

Called when status changes.

Parameters​
status​

YBindingStatus

Returns​

void

onWarn?​

optional onWarn?: (message) => void

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

Experimental

Called with warnings (newer layout, foreign content).

Parameters​
message​

string

Returns​

void

root?​

optional root?: YNode<any>

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

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:114

Experimental

Read every line a local write touched back from Yjs and compare it with the editor; mismatches are reported through the editor's onWarn. 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: on in development, off in production.

selfCheckSample?​

optional selfCheckSample?: number

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

Experimental

Fraction of local writes the self-check samples (default 1).


YCollabConfig​

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

Experimental

The configuration of YCollabExtension.

Properties​

captureTimeout​

captureTimeout: number | null

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

Experimental

Undo capture timeout in ms; null disables collaborative undo.

clientIDRange​

clientIDRange: ClientIDRange

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

Experimental

See YBindingOptions.clientIDRange (default 'uint53').

convert​

convert: boolean

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

Experimental

See YBindingOptions.convert (default false).

doc​

doc: Doc | null

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

Experimental

The shared document. Required.

onWarn​

onWarn: ((message) => void) | null

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

Experimental

root​

root: YNode<any> | null

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

Experimental

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

selfCheck​

selfCheck: boolean | null

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

Experimental

See YBindingOptions.selfCheck; null keeps the default (on in development, off in production).

selfCheckSample​

selfCheckSample: number | null

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

Experimental

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

synced​

synced: boolean

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

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:134

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:135

Experimental

focus​

focus: unknown

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

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.

YBindingStatus​

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

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

Experimental

The state of a YBinding.

Variables​

DEFAULT_ROOT_NAME​

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

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

Experimental

The default name of the shared root (not v1's or v2's).


LAYOUT_VERSION​

const LAYOUT_VERSION: 1 = 1

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

Experimental

The layout version this binding reads and writes.


YCollabExtension​

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

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

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​

createYDoc()​

createYDoc(options?): Doc

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

Experimental

Create a Y.Doc for @lexical/y. With compat: 'yrs-0.23' its client ids stay in 32 bits (see ClientIDRange), for servers on yrs before 0.28.

Parameters​

options?​

DocOpts & object = {}

Returns​

Doc


writeEditorToYDoc()​

writeEditorToYDoc(editor, doc, options?): void

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

Experimental

The one-off writer: write an editor's current document into the empty layout root of doc, without a live binding. Use it to seed a new document (on a server, from a template or an import) and in converters, which write it next to an older layout's root in the same document. Throws when the layout root is not empty. For a live, editable document use YCollabExtension (or YBinding).

Parameters​

editor​

LexicalEditor

doc​

Doc

options?​
clientIDRange?​

ClientIDRange

root?​

YNode<any>

Returns​

void