C

DocumentCrdt

The writekit's document CRDT: a fractional-ordered set of blocks, each a text RGA + a mark store (or an attribute-only atom). It translates the writekit's offset-based Steps into id-based CRDT ops (translateStep), integrates ops from any replica (applyOp), and materializes an WritekitDocument (toDocument).

Signature

ts
class DocumentCrdt

Methods

setIdFactory

Wire the replica's id generator (called once by the provider).

ts
setIdFactory(factory: () => OpId): void
ParameterTypeDescription
factory() => OpId
applyOp

Apply one op (local or remote). Returns false if a causal dependency is missing.

ts
applyOp(op: WritekitOp): boolean
ParameterTypeDescription
opWritekitOp
Returnsboolean
toDocument
ts
toDocument(): WritekitDocument
ReturnsWritekitDocument
gc

Compact 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.

ts
gc(stable: VersionVector):
ParameterTypeDescription
stableVersionVector
Returns{ blocks: number; chars: number }
hasBlock

Whether a block currently exists and is visible.

ts
hasBlock(blockId: string): boolean
ParameterTypeDescription
blockIdstring
Returnsboolean
toAnchor

Convert a model selection into a char-id anchor (for presence broadcast).

ts
toAnchor(selection: Selection): SelectionAnchor
ParameterTypeDescription
selectionSelection
ReturnsSelectionAnchor
resolveAnchor

Resolve an anchor back into a model selection against the current document.

ts
resolveAnchor(anchor: SelectionAnchor | null): Selection | null
ParameterTypeDescription
anchorSelectionAnchor | null
ReturnsSelection | null
translateStep

Generate the ops for a local step, reading current state for ids/positions.

ts
translateStep(step: Step): WritekitOp[]
ParameterTypeDescription
stepStep
ReturnsWritekitOp[]
seedFromDocument

Ops to seed the CRDT from an initial document.

ts
seedFromDocument(doc: WritekitDocument): WritekitOp[]
ParameterTypeDescription
docWritekitDocument
ReturnsWritekitOp[]