@lexical/y
Classes
YBinding
Defined in: packages/lexical-y/src/internal/Binding.ts:219
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:301
Experimental
Parameters
editor
doc
options?
YBindingOptions = {}
Returns
Accessors
doc
Get Signature
get doc():
Doc
Defined in: packages/lexical-y/src/internal/Binding.ts:277
Experimental
The shared document.
Returns
editor
Get Signature
get editor():
LexicalEditor
Defined in: packages/lexical-y/src/internal/Binding.ts:272
Experimental
The bound editor.
Returns
pins
Get Signature
get pins():
ReadonlyMap<string,Pin>
Defined in: packages/lexical-y/src/internal/Binding.ts:292
Experimental
Storage kinds the document records per node type (see the README).
Returns
ReadonlyMap<string, Pin>
root
Get Signature
get root():
YNode
Defined in: packages/lexical-y/src/internal/Binding.ts:282
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:287
Experimental
See YBindingStatus; onStatus reports changes.
Returns
undoManager
Get Signature
get undoManager():
UndoManager|null
Defined in: packages/lexical-y/src/internal/Binding.ts:297
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:1957
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:399
Experimental
Returns
void
getCursor()
getCursor():
YCursor|null
Defined in: packages/lexical-y/src/internal/Binding.ts:1920
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:424
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 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:1865
Experimental
Returns
boolean
start()
start(): () =>
void
Defined in: packages/lexical-y/src/internal/Binding.ts:322
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:1850
Experimental
Returns
boolean
Interfaces
YBindingOptions
Defined in: packages/lexical-y/src/internal/Binding.ts:165
Experimental
Options of YBinding (and YCollabExtension).
Properties
captureTimeout?
optionalcaptureTimeout?:number|null
Defined in: packages/lexical-y/src/internal/Binding.ts:169
Experimental
Undo capture timeout in ms (default 500); null disables undo.
clientIDRange?
optionalclientIDRange?:ClientIDRange
Defined in: packages/lexical-y/src/internal/Binding.ts:200
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:194
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:177
Experimental
Called when status changes.
Parameters
status
Returns
void
onWarn?
optionalonWarn?: (warning) =>void
Defined in: packages/lexical-y/src/internal/Binding.ts:175
Experimental
Called with the binding's warnings (see YWarningCode); default:
console.warn outside production. Never the editor's onWarn, which
throws in development.
Parameters
warning
Returns
void
root?
optionalroot?:YNode<any>
Defined in: packages/lexical-y/src/internal/Binding.ts:167
Experimental
The shared root to bind; defaults to doc.get('lexical-y').
selfCheck?
optionalselfCheck?:boolean
Defined in: packages/lexical-y/src/internal/Binding.ts:187
Experimental
Read every line a local write touched back from Yjs and compare it with
the editor; mismatches are reported through onWarn (code
'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: on in development, off in production.
selfCheckSample?
optionalselfCheckSample?:number
Defined in: packages/lexical-y/src/internal/Binding.ts:189
Experimental
Fraction of local writes the self-check samples (default 1).
YCollabConfig
Defined in: packages/lexical-y/src/internal/YExtension.ts:32
Experimental
The configuration of YCollabExtension.
Properties
captureTimeout
captureTimeout:
number|null
Defined in: packages/lexical-y/src/internal/YExtension.ts:44
Experimental
Undo capture timeout in ms; null disables collaborative undo.
clientIDRange
clientIDRange:
ClientIDRange
Defined in: packages/lexical-y/src/internal/YExtension.ts:46
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:34
Experimental
The shared document. Required.
onWarn
onWarn: ((
warning) =>void) |null
Defined in: packages/lexical-y/src/internal/YExtension.ts:48
Experimental
See YBindingOptions.onWarn.
root
root:
YNode<any> |null
Defined in: packages/lexical-y/src/internal/YExtension.ts:36
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 (on in development, off in production).
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:42
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:207
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:208
Experimental
focus
focus:
unknown
Defined in: packages/lexical-y/src/internal/Binding.ts:209
Experimental
YWarning
Defined in: packages/lexical-y/src/internal/Binding.ts:159
Experimental
A warning of a YBinding, passed to onWarn.
Properties
code
readonlycode:YWarningCode
Defined in: packages/lexical-y/src/internal/Binding.ts:160
Experimental
message
readonlymessage:string
Defined in: packages/lexical-y/src/internal/Binding.ts:161
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:233
Experimental
How @lexical/y stores an element type; see describeStorage.
YBindingStatus
YBindingStatus =
"pending"|"active"|"readonly"
Defined in: packages/lexical-y/src/internal/Binding.ts:126
Experimental
The state of a YBinding.
YWarningCode
YWarningCode =
"unsupported-layout"|"unknown-node-types"|"storage-mismatch"|"self-check"|"recovered-read"|"recovered-write"
Defined in: packages/lexical-y/src/internal/Binding.ts:138
Experimental
What a YWarning reports. Codes are stable: new ones may be added, existing ones keep their meaning.
Variables
DEFAULT_ROOT_NAME
constDEFAULT_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
constLAYOUT_VERSION:2=2
Defined in: packages/lexical-y/src/internal/constants.ts:19
Experimental
The newest layout version this binding reads and writes. A document starts at version 1; the first move record or lifted block written into it marks it 2 (clients that only know version 1 then go read only instead of misreading them).
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">