@lexical/y
Classes
YBinding
Defined in: packages/lexical-y/src/internal/Binding.ts:260
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:426
Experimental
Parameters
editor
doc
options?
YBindingOptions = {}
Returns
Accessors
doc
Get Signature
get doc():
Doc
Defined in: packages/lexical-y/src/internal/Binding.ts:399
Experimental
The shared document.
Returns
editor
Get Signature
get editor():
LexicalEditor
Defined in: packages/lexical-y/src/internal/Binding.ts:394
Experimental
The bound editor.
Returns
pins
Get Signature
get pins():
ReadonlyMap<string, {by?: readonlystring[];kind:StorageKind; }>
Defined in: packages/lexical-y/src/internal/Binding.ts:414
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:404
Experimental
The shared root this binding reads and writes.
Returns
status
Get Signature
get status():
YBindingStatus
Defined in: packages/lexical-y/src/internal/Binding.ts:409
Experimental
See YBindingStatus; onStatus reports changes.
Returns
undoManager
Get Signature
get undoManager():
UndoManager|null
Defined in: packages/lexical-y/src/internal/Binding.ts:422
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:3114
Experimental
Resolve a cursor to Lexical points (call inside a read or update).
Parameters
cursor
Returns
{ anchor: PointType; focus: PointType; } | null
dispose()
dispose():
void
Defined in: packages/lexical-y/src/internal/Binding.ts:644
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:3052
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:677
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:2915
Experimental
Redo what undo undid; see undo.
Returns
boolean
start()
start(): () =>
void
Defined in: packages/lexical-y/src/internal/Binding.ts:448
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:2910
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:175
Experimental
Options of YBinding (and YCollabExtension).
Properties
captureTimeout?
optionalcaptureTimeout?:number|null
Defined in: packages/lexical-y/src/internal/Binding.ts:179
Experimental
Undo capture timeout in ms (default 500); null disables undo.
clientIDRange?
optionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/internal/Binding.ts:214
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?
optionalconvert?:boolean
Defined in: packages/lexical-y/src/internal/Binding.ts:208
Experimental
Initialize even when an older layout's root has content: for a converter writing the layout root of an existing document.
onStatus?
optionalonStatus?: (status) =>void
Defined in: packages/lexical-y/src/internal/Binding.ts:185
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
Returns
void
root?
optionalroot?:YNode<any>
Defined in: packages/lexical-y/src/internal/Binding.ts:177
Experimental
The shared root to bind; defaults to doc.get('lexical-y').
selfCheck?
optionalselfCheck?:boolean
Defined in: packages/lexical-y/src/internal/Binding.ts:196
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?
optionalselfCheckSample?:number
Defined in: packages/lexical-y/src/internal/Binding.ts:203
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:221
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:222
Experimental
focus
focus:
unknown
Defined in: packages/lexical-y/src/internal/Binding.ts:223
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:254
Experimental
How @lexical/y stores an element type; see describeStorage.
YBindingStatus
YBindingStatus =
"pending"|"active"|"readonly"
Defined in: packages/lexical-y/src/internal/Binding.ts:162
Experimental
The state of a YBinding.
YWarningCode
YWarningCode = typeof
UNSUPPORTED_LAYOUT_WARNING| typeofUNKNOWN_NODE_TYPES_WARNING| typeofSTORAGE_MISMATCH_WARNING| typeofSELF_CHECK_WARNING| typeofRECOVERED_READ_WARNING| typeofRECOVERED_WRITE_WARNING| typeofNESTED_FALLBACK_WARNING| typeofUNSYNCED_VALUE_WARNING| typeofUNSUPPORTED_SLOTS_WARNING| typeofUNSUPPORTED_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
constDEFAULT_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
constLAYOUT_VERSION:2=2
Defined in: packages/lexical-y/src/internal/constants.ts:30
Experimental
The newest layout version this binding reads and writes. A document records version 1; the first move record or lifted block written into it also records 2 (clients that only know version 1 then go read only instead of misreading them).
NESTED_FALLBACK_WARNING
constNESTED_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
constRECOVERED_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
constRECOVERED_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
constSELF_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
constSTORAGE_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
constUNKNOWN_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
constUNSUPPORTED_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
constUNSUPPORTED_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
constUNSUPPORTED_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
constUNSYNCED_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
constYCollabExtension: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
binding?
pins
ReadonlyMap<string, { kind: StorageKind; }>
Returns
Record<string, StorageKind | "text">