DocumentCrdt
The editor's document CRDT: a fractional-ordered set of blocks, each a text RGA + a mark store (or an attribute-only atom). It translates the editor's offset-based {@link Step}s into id-based CRDT ops ({@link translateStep}), integrates ops from any replica ({@link applyOp}), and materializes an {@link EditorDocument} ({@link toDocument}).
Signature
class DocumentCrdtMethods
setIdFactoryWire the replica's id generator (called once by the provider).
setIdFactory(factory: () => OpId): void| Parameter | Type | Description |
|---|---|---|
factory | () => OpId | — |
applyOpApply one op (local or remote). Returns false if a causal dependency is missing.
applyOp(op: EditorOp): boolean| Parameter | Type | Description |
|---|---|---|
op | EditorOp | — |
booleantoDocumenttoDocument(): EditorDocumentEditorDocumentgcCompact the CRDT: drop tombstoned characters and fully-removed blocks that are covered by `stable`. Mark-span endpoints are preserved so formatting survives. Call ONLY at quiescence — every replica fully synced, nothing in flight — or a late op referencing dropped content can no longer integrate.
gc(stable: VersionVector):| Parameter | Type | Description |
|---|---|---|
stable | VersionVector | — |
{ blocks: number; chars: number; }hasBlockWhether a block currently exists and is visible.
hasBlock(blockId: string): boolean| Parameter | Type | Description |
|---|---|---|
blockId | string | — |
booleantoAnchorConvert a model selection into a char-id anchor (for presence broadcast).
toAnchor(selection: Selection): SelectionAnchor| Parameter | Type | Description |
|---|---|---|
selection | Selection | — |
SelectionAnchorresolveAnchorResolve an anchor back into a model selection against the current document.
resolveAnchor(anchor: SelectionAnchor | null): Selection | null| Parameter | Type | Description |
|---|---|---|
anchor | SelectionAnchor | null | — |
Selection | nulltranslateStepGenerate the ops for a local step, reading current state for ids/positions.
translateStep(step: Step): EditorOp[]| Parameter | Type | Description |
|---|---|---|
step | Step | — |
EditorOp[]seedFromDocumentOps to seed the CRDT from an initial document.
seedFromDocument(doc: EditorDocument): EditorOp[]| Parameter | Type | Description |
|---|---|---|
doc | EditorDocument | — |
EditorOp[]