Skip to main content

@lexical/yjs

Interfaces

BaseBinding

Defined in: packages/lexical-yjs/src/Bindings.ts:27

Extended by

Properties

clientID

clientID: number

Defined in: packages/lexical-yjs/src/Bindings.ts:28

cursorHighlightSheet

cursorHighlightSheet: CSSStyleSheet | null

Defined in: packages/lexical-yjs/src/Bindings.ts:35

For remote cursors, we lazily create stylesheet that hosts the ::highlight(...) rules. Editors mounted in different frames each adopt the sheet into their own document.

cursors

cursors: Map<number, Cursor>

Defined in: packages/lexical-yjs/src/Bindings.ts:29

cursorsContainer

cursorsContainer: HTMLElement | null

Defined in: packages/lexical-yjs/src/Bindings.ts:30

doc

doc: Doc

Defined in: packages/lexical-yjs/src/Bindings.ts:36

docMap

docMap: Map<string, Doc>

Defined in: packages/lexical-yjs/src/Bindings.ts:37

editor

editor: LexicalEditor

Defined in: packages/lexical-yjs/src/Bindings.ts:38

excludedProperties

excludedProperties: ExcludedProperties

Defined in: packages/lexical-yjs/src/Bindings.ts:41

id

id: string

Defined in: packages/lexical-yjs/src/Bindings.ts:39

nodeProperties

nodeProperties: Map<string, {[property: string]: unknown; }>

Defined in: packages/lexical-yjs/src/Bindings.ts:40


Binding

Defined in: packages/lexical-yjs/src/Bindings.ts:54

Extends

Properties

clientID

clientID: number

Defined in: packages/lexical-yjs/src/Bindings.ts:28

Inherited from

BaseBinding.clientID

collabNodeMap

collabNodeMap: Map<string, CollabElementNode | CollabTextNode | CollabDecoratorNode | CollabLineBreakNode>

Defined in: packages/lexical-yjs/src/Bindings.ts:55

cursorHighlightSheet

cursorHighlightSheet: CSSStyleSheet | null

Defined in: packages/lexical-yjs/src/Bindings.ts:35

For remote cursors, we lazily create stylesheet that hosts the ::highlight(...) rules. Editors mounted in different frames each adopt the sheet into their own document.

Inherited from

BaseBinding.cursorHighlightSheet

cursors

cursors: Map<number, Cursor>

Defined in: packages/lexical-yjs/src/Bindings.ts:29

Inherited from

BaseBinding.cursors

cursorsContainer

cursorsContainer: HTMLElement | null

Defined in: packages/lexical-yjs/src/Bindings.ts:30

Inherited from

BaseBinding.cursorsContainer

doc

doc: Doc

Defined in: packages/lexical-yjs/src/Bindings.ts:36

Inherited from

BaseBinding.doc

docMap

docMap: Map<string, Doc>

Defined in: packages/lexical-yjs/src/Bindings.ts:37

Inherited from

BaseBinding.docMap

editor

editor: LexicalEditor

Defined in: packages/lexical-yjs/src/Bindings.ts:38

Inherited from

BaseBinding.editor

excludedProperties

excludedProperties: ExcludedProperties

Defined in: packages/lexical-yjs/src/Bindings.ts:41

Inherited from

BaseBinding.excludedProperties

id

id: string

Defined in: packages/lexical-yjs/src/Bindings.ts:39

Inherited from

BaseBinding.id

nodeProperties

nodeProperties: Map<string, {[property: string]: unknown; }>

Defined in: packages/lexical-yjs/src/Bindings.ts:40

Inherited from

BaseBinding.nodeProperties

root

root: CollabElementNode

Defined in: packages/lexical-yjs/src/Bindings.ts:62


BindingV2

Defined in: packages/lexical-yjs/src/Bindings.ts:65

Extends

Properties

clientID

clientID: number

Defined in: packages/lexical-yjs/src/Bindings.ts:28

Inherited from

BaseBinding.clientID

cursorHighlightSheet

cursorHighlightSheet: CSSStyleSheet | null

Defined in: packages/lexical-yjs/src/Bindings.ts:35

For remote cursors, we lazily create stylesheet that hosts the ::highlight(...) rules. Editors mounted in different frames each adopt the sheet into their own document.

Inherited from

BaseBinding.cursorHighlightSheet

cursors

cursors: Map<number, Cursor>

Defined in: packages/lexical-yjs/src/Bindings.ts:29

Inherited from

BaseBinding.cursors

cursorsContainer

cursorsContainer: HTMLElement | null

Defined in: packages/lexical-yjs/src/Bindings.ts:30

Inherited from

BaseBinding.cursorsContainer

doc

doc: Doc

Defined in: packages/lexical-yjs/src/Bindings.ts:36

Inherited from

BaseBinding.doc

docMap

docMap: Map<string, Doc>

Defined in: packages/lexical-yjs/src/Bindings.ts:37

Inherited from

BaseBinding.docMap

editor

editor: LexicalEditor

Defined in: packages/lexical-yjs/src/Bindings.ts:38

Inherited from

BaseBinding.editor

excludedProperties

excludedProperties: ExcludedProperties

Defined in: packages/lexical-yjs/src/Bindings.ts:41

Inherited from

BaseBinding.excludedProperties

id

id: string

Defined in: packages/lexical-yjs/src/Bindings.ts:39

Inherited from

BaseBinding.id

mapping

mapping: CollabV2Mapping

Defined in: packages/lexical-yjs/src/Bindings.ts:66

nodeProperties

nodeProperties: Map<string, {[property: string]: unknown; }>

Defined in: packages/lexical-yjs/src/Bindings.ts:40

Inherited from

BaseBinding.nodeProperties

root

root: YXmlElement

Defined in: packages/lexical-yjs/src/Bindings.ts:67


CreateBindingV2Options__EXPERIMENTAL

Defined in: packages/lexical-yjs/src/Bindings.ts:181

Options for createBindingV2__EXPERIMENTAL.

Properties

excludedProperties?

optional excludedProperties?: ExcludedProperties

Defined in: packages/lexical-yjs/src/Bindings.ts:182

getXmlElement?

optional getXmlElement?: (doc) => YXmlElement

Defined in: packages/lexical-yjs/src/Bindings.ts:203

Resolve the root XmlElement from the Doc yourself, for roots that are not a top-level shared type (e.g. an XmlElement held in a Y.Map or Y.Array, as when one Doc stores many independently editable documents). The V2 equivalent of CreateYjsBindingOptions.getXmlText, with the same before-any-sync timing and the same idempotency requirement.

The returned type is checked to be an XmlElement integrated into doc (reachable from a top-level shared type) that was created as new XmlElement() without a nodeName — the root is identified by its default 'UNDEFINED' node name, which is also what doc.get(rootName, XmlElement) produces — and fails with an invariant rather than corrupting the document. As in V1, that it is not in use by another live binding cannot be checked and is the caller's to guarantee. When given, it takes precedence over CreateBindingV2Options__EXPERIMENTAL.rootName.

Parameters
doc

Doc

Returns

YXmlElement

rootName?

optional rootName?: string

Defined in: packages/lexical-yjs/src/Bindings.ts:184

The key used to look up the root XmlElement shared type on the Yjs Doc. Defaults to 'root-v2'.


CreateYjsBindingOptions

Defined in: packages/lexical-yjs/src/Bindings.ts:99

Options for createYjsBinding.

Properties

doc

doc: Doc

Defined in: packages/lexical-yjs/src/Bindings.ts:103

docMap

docMap: Map<string, Doc>

Defined in: packages/lexical-yjs/src/Bindings.ts:104

editor

editor: LexicalEditor

Defined in: packages/lexical-yjs/src/Bindings.ts:100

excludedProperties?

optional excludedProperties?: ExcludedProperties

Defined in: packages/lexical-yjs/src/Bindings.ts:105

getXmlText?

optional getXmlText?: (doc) => YXmlText

Defined in: packages/lexical-yjs/src/Bindings.ts:127

Resolve the root XmlText from the Doc yourself, for roots that are not a top-level shared type (e.g. an XmlText held in a Y.Map or Y.Array, as when one Doc stores many independently editable documents).

Called while the binding is constructed — before any provider has synced — so it must resolve (or create) the root from whatever the Doc holds locally at that moment, and it must be idempotent: a caller may build more than one binding over the same root (React StrictMode's double-invoked render, a remount), and creating a shared type twice would replace what the first call created.

The returned type is checked to be an XmlText integrated into doc (reachable from a top-level shared type). It must also not be in use by another live binding, which cannot be checked — a second binding over one root replaces the collab nodes cached on its shared types. A binding cannot be repointed at a different root afterwards. When given, this takes precedence over CreateYjsBindingOptions.rootName.

Parameters
doc

Doc

Returns

YXmlText

id

id: string

Defined in: packages/lexical-yjs/src/Bindings.ts:102

Identifier for this binding, used as the key in docMap.

rootName?

optional rootName?: string

Defined in: packages/lexical-yjs/src/Bindings.ts:107

The key used to look up the root XmlText shared type on the Yjs Doc. Defaults to 'root'.


Provider

Defined in: packages/lexical-yjs/src/index.ts:57

Properties

awareness

awareness: ProviderAwareness

Defined in: packages/lexical-yjs/src/index.ts:58

Methods

connect()

connect(): void | Promise<void>

Defined in: packages/lexical-yjs/src/index.ts:59

Returns

void | Promise<void>

disconnect()

disconnect(): void

Defined in: packages/lexical-yjs/src/index.ts:60

Returns

void

off()
Call Signature

off(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:61

Parameters
type

"sync"

cb

(isSynced) => void

Returns

void

Call Signature

off(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:62

Parameters
type

"update"

cb

(arg0) => void

Returns

void

Call Signature

off(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:63

Parameters
type

"status"

cb

(arg0) => void

Returns

void

Call Signature

off(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:64

Parameters
type

"reload"

cb

(doc) => void

Returns

void

on()
Call Signature

on(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:65

Parameters
type

"sync"

cb

(isSynced) => void

Returns

void

Call Signature

on(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:66

Parameters
type

"status"

cb

(arg0) => void

Returns

void

Call Signature

on(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:67

Parameters
type

"update"

cb

(arg0) => void

Returns

void

Call Signature

on(type, cb): void

Defined in: packages/lexical-yjs/src/index.ts:68

Parameters
type

"reload"

cb

(doc) => void

Returns

void

Type Aliases

ClientID

ClientID = number

Defined in: packages/lexical-yjs/src/Bindings.ts:26


Delta

Delta = Operation[]

Defined in: packages/lexical-yjs/src/index.ts:76


ExcludedProperties

ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>

Defined in: packages/lexical-yjs/src/Bindings.ts:72


Operation

Operation = object

Defined in: packages/lexical-yjs/src/index.ts:70

Properties

attributes

attributes: object

Defined in: packages/lexical-yjs/src/index.ts:71

__type

__type: string

insert

insert: string | Record<string, unknown>

Defined in: packages/lexical-yjs/src/index.ts:74


ProviderAwareness

ProviderAwareness = object

Defined in: packages/lexical-yjs/src/index.ts:49

Properties

getLocalState

getLocalState: () => UserState | null

Defined in: packages/lexical-yjs/src/index.ts:50

Returns

UserState | null

getStates

getStates: () => Map<number, UserState>

Defined in: packages/lexical-yjs/src/index.ts:51

Returns

Map<number, UserState>

off

off: (type, cb) => void

Defined in: packages/lexical-yjs/src/index.ts:52

Parameters
type

"update"

cb

() => void

Returns

void

on

on: (type, cb) => void

Defined in: packages/lexical-yjs/src/index.ts:53

Parameters
type

"update"

cb

() => void

Returns

void

setLocalState

setLocalState: (arg0) => void

Defined in: packages/lexical-yjs/src/index.ts:54

Parameters
arg0

UserState | null

Returns

void

setLocalStateField

setLocalStateField: (field, value) => void

Defined in: packages/lexical-yjs/src/index.ts:55

Parameters
field

string

value

unknown

Returns

void


SyncCursorPositionsFn

SyncCursorPositionsFn = (binding, provider, options?) => void

Defined in: packages/lexical-yjs/src/SyncCursors.ts:913

Parameters

binding

AnyBinding

provider

Provider

options?

SyncCursorPositionsOptions

Returns

void


UserState

UserState = object

Defined in: packages/lexical-yjs/src/index.ts:24

Indexable

[key: string]: unknown

Properties

anchorPos

anchorPos: null | RelativePosition

Defined in: packages/lexical-yjs/src/index.ts:25

awarenessData

awarenessData: object

Defined in: packages/lexical-yjs/src/index.ts:30

color

color: string

Defined in: packages/lexical-yjs/src/index.ts:26

focusing

focusing: boolean

Defined in: packages/lexical-yjs/src/index.ts:27

focusPos

focusPos: null | RelativePosition

Defined in: packages/lexical-yjs/src/index.ts:28

name

name: string

Defined in: packages/lexical-yjs/src/index.ts:29


YjsEvent

YjsEvent = Record<string, unknown>

Defined in: packages/lexical-yjs/src/index.ts:78


YjsNode

YjsNode = Record<string, unknown>

Defined in: packages/lexical-yjs/src/index.ts:77

Variables

CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL

const CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL: LexicalCommand<void>

Defined in: packages/lexical-yjs/src/index.ts:45


CONNECTED_COMMAND

const CONNECTED_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical-yjs/src/index.ts:33


DIFF_VERSIONS_COMMAND__EXPERIMENTAL

const DIFF_VERSIONS_COMMAND__EXPERIMENTAL: LexicalCommand<{ prevSnapshot?: Snapshot; snapshot?: Snapshot; }>

Defined in: packages/lexical-yjs/src/index.ts:39


TOGGLE_CONNECT_COMMAND

const TOGGLE_CONNECT_COMMAND: LexicalCommand<boolean>

Defined in: packages/lexical-yjs/src/index.ts:35

Functions

$getAnchorAndFocusForUserState()

$getAnchorAndFocusForUserState(binding, userState): object

Defined in: packages/lexical-yjs/src/SyncCursors.ts:674

Parameters

binding

AnyBinding

userState

UserState

Returns

object

anchorKey

anchorKey: string | null

anchorOffset

anchorOffset: number

focusKey

focusKey: string | null

focusOffset

focusOffset: number


$getYChangeState()

$getYChangeState<UserT>(node): YChange<UserT> | null

Defined in: packages/lexical-yjs/src/RenderSnapshot.ts:37

Type Parameters

UserT

UserT = unknown

Parameters

node

LexicalNode

Returns

YChange<UserT> | null


createBinding()

createBinding(editor, provider, id, doc, docMap, excludedProperties?): Binding

Defined in: packages/lexical-yjs/src/Bindings.ts:165

Parameters

editor

LexicalEditor

provider

Provider

id

string

doc

Doc | null | undefined

docMap

Map<string, Doc>

excludedProperties?

ExcludedProperties

Returns

Binding


createBindingV2__EXPERIMENTAL()

createBindingV2__EXPERIMENTAL(editor, id, doc, docMap, options?): BindingV2

Defined in: packages/lexical-yjs/src/Bindings.ts:206

Parameters

editor

LexicalEditor

id

string

doc

Doc | null | undefined

docMap

Map<string, Doc>

options?

CreateBindingV2Options__EXPERIMENTAL = {}

Returns

BindingV2


createUndoManager()

createUndoManager(binding, root): UndoManager

Defined in: packages/lexical-yjs/src/index.ts:95

Parameters

binding

BaseBinding

root

YXmlText | YXmlElement<{[key: string]: string; }>

Returns

UndoManager


createYjsBinding()

createYjsBinding(__namedParameters): Binding

Defined in: packages/lexical-yjs/src/Bindings.ts:136

Create a V1 Yjs Binding that connects a LexicalEditor to a Yjs Doc for real-time collaboration.

For the legacy positional-argument API, see createBinding.

Parameters

__namedParameters

CreateYjsBindingOptions

Returns

Binding


getAnchorAndFocusCollabNodesForUserState()

getAnchorAndFocusCollabNodesForUserState(binding, userState): object

Defined in: packages/lexical-yjs/src/SyncCursors.ts:638

Parameters

binding

Binding

userState

UserState

Returns

object

anchorCollabNode

anchorCollabNode: AnyCollabNode | null

anchorOffset

anchorOffset: number

focusCollabNode

focusCollabNode: AnyCollabNode | null

focusOffset

focusOffset: number

Deprecated

Use $getAnchorAndFocusForUserState instead.


initLocalState()

initLocalState(provider, name, color, focusing, awarenessData): void

Defined in: packages/lexical-yjs/src/index.ts:108

Parameters

provider

Provider

name

string

color

string

focusing

boolean

awarenessData

object

Returns

void


removeCursorHighlightRule()

removeCursorHighlightRule(binding, highlightName): void

Defined in: packages/lexical-yjs/src/SyncCursors.ts:149

Parameters

binding

BaseBinding

highlightName

string

Returns

void


renderSnapshot__EXPERIMENTAL()

renderSnapshot__EXPERIMENTAL(binding, snapshot?, prevSnapshot?): void

Defined in: packages/lexical-yjs/src/RenderSnapshot.ts:53

Replaces the editor content with a view that compares the state between two given snapshots. Any added or removed nodes between the two snapshots will have YChange attached to them.

Parameters

binding

BindingV2

Yjs binding

snapshot?

Snapshot = ...

Ending snapshot state (default: current state of the Yjs document)

prevSnapshot?

Snapshot = emptySnapshot

Starting snapshot state (default: empty snapshot)

Returns

void


setLocalStateFocus()

setLocalStateFocus(provider, name, color, focusing, awarenessData): void

Defined in: packages/lexical-yjs/src/index.ts:125

Parameters

provider

Provider

name

string

color

string

focusing

boolean

awarenessData

object

Returns

void


syncCursorPositions()

syncCursorPositions(binding, provider, options?): void

Defined in: packages/lexical-yjs/src/SyncCursors.ts:936

Parameters

binding

AnyBinding

provider

Provider

options?

SyncCursorPositionsOptions

Returns

void


syncLexicalUpdateToYjs()

syncLexicalUpdateToYjs(binding, provider, prevEditorState, currEditorState, dirtyElements, dirtyLeaves, normalizedNodes, tags): void

Defined in: packages/lexical-yjs/src/SyncEditorStates.ts:359

Parameters

binding

Binding

provider

Provider

prevEditorState

EditorState

currEditorState

EditorState

dirtyElements

Map<string, boolean>

dirtyLeaves

Set<string>

normalizedNodes

Set<string>

tags

Set<string>

Returns

void


syncLexicalUpdateToYjsV2__EXPERIMENTAL()

syncLexicalUpdateToYjsV2__EXPERIMENTAL(binding, provider, prevEditorState, currEditorState, dirtyElements, dirtyLeaves, normalizedNodes, tags): void

Defined in: packages/lexical-yjs/src/SyncEditorStates.ts:568

Parameters

binding

BindingV2

provider

Provider

prevEditorState

EditorState

currEditorState

EditorState

dirtyElements

Map<string, boolean>

dirtyLeaves

Set<string>

normalizedNodes

Set<string>

tags

Set<string>

Returns

void


syncYjsChangesToLexical()

syncYjsChangesToLexical(binding, provider, events, isFromUndoManger, syncCursorPositionsFn?): void

Defined in: packages/lexical-yjs/src/SyncEditorStates.ts:195

Parameters

binding

Binding

provider

Provider

events

YEvent<YText>[]

isFromUndoManger

boolean

syncCursorPositionsFn?

SyncCursorPositionsFn = syncCursorPositions

Returns

void


syncYjsChangesToLexicalV2__EXPERIMENTAL()

syncYjsChangesToLexicalV2__EXPERIMENTAL(binding, provider, events, transaction, isFromUndoManger): void

Defined in: packages/lexical-yjs/src/SyncEditorStates.ts:481

Parameters

binding

BindingV2

provider

Provider

events

YEvent<YXmlText | YXmlElement<{[key: string]: string; }>>[]

transaction

Transaction

isFromUndoManger

boolean

Returns

void


syncYjsStateToLexicalV2__EXPERIMENTAL()

syncYjsStateToLexicalV2__EXPERIMENTAL(binding, provider): void

Defined in: packages/lexical-yjs/src/SyncEditorStates.ts:540

Parameters

binding

BindingV2

provider

Provider

Returns

void