watershed Collaborative data structures for Gleam

← watershed · SharedRichText operational transform

Transform edits,
preserve intent.

json_ot transforms a shared JSON document; this is the same protocol turned on rich text. watershed's rich_text_kernel ports the quill-delta algebra (retain/insert/delete spans, attribute patches, embeds) behind the same single-op-in-flight client-transform machinery. Three Quill editors share one document with concurrent typing, formatting, and deletion, and transformed deltas bring every replica to the same text, formatting, and embeds. SharedRichText is OT-backed; the CRDT-backed SharedText handles plain text with grapheme identities and merge-based convergence.

SharedRichText, live

Three watershed documents share one rich-text channel over the rich_text_kernel. It runs the same single-op-in-flight client-transform protocol as the json_ot demo, but over quill-delta's algebra: operations retain, insert, or delete spans of text. Each op can carry an attribute patch (bold, color, …) or wrap an embed (an image) instead of plain text. Positions are counted in UTF-16 code units (the units Quill and JavaScript strings index by), so nothing converts at the editor boundary. Each editor keeps at most one op in flight; anything typed while it's outstanding composes into a single buffered op behind it. This is SharedRichText, watershed's OT-backed rich text. For CRDT-backed plain text, SharedText indexes graphemes by stable identity and converges by merge rather than by transform.

Local edits apply the instant you type, Quill's own optimistic model, no different from typing into any editor. Race two clients at the same spot, format concurrently, or delete under someone else's formatting, then watch the op log and the canonical text below each editor converge. Peer cursors (dashed, colored) track where the other two are looking, transformed through every edit exactly like the local caret is.

Client A

synced

    Client B

    synced

      Client C

      synced

        Sequencer SN 0

          Converged replicas identical · nothing pending

          The scenario buttons submit through each editor's own Quill instance (the same path a browser keystroke takes), so you're watching the genuine client-transform protocol, not a scripted animation. Manual typing and toolbar formatting work in all three editors too; try editing one while a race is still in flight in another.