canvist_collab
Real-time collaboration for canvist documents over Yjs, using yrs.
Most apps add it through canvist, the crate to install, as canvist::collab behind the collab feature: cargo add canvist --features collab.
- Binding: mirrors a
canvist_modeldocument into a yrs document and back. Each model step becomes yrs operations and each remote yrs event becomes steps, so nothing is ever diffed. - Plain Yjs: the shared document follows a documented schema of
Y.Mapblocks,Y.Textwith marks as formatting, and nestedY.Arrays, so JavaScript Yjs peers, y-websocket, and Hocuspocus take part without knowing about canvist. - Robust: updates may arrive out of order or twice, blocks that break the schema are hidden rather than deleted, and concurrent moves of one block keep a single copy.
- Shared undo: a yrs
UndoManagerthat only undoes local changes, behind aHistorytrait the editor can swap. - Sync and presence: a transport-agnostic y-sync session for y-websocket and Hocuspocus servers, and awareness carets that stay on their characters while others type.
Mirroring a keystroke into a Yjs update takes about 2 µs, and applying a remote keystroke about 2.5 µs, whether the document has 100 blocks or 10,000. Run cargo bench -p canvist_collab to reproduce.
The compatibility tests run a real JavaScript Yjs peer under Deno, which the devenv shell provides.
Shared block trees are limited to 64 levels, counting root blocks as level 1. An update that exceeds this limit returns CollabError::BlockDepthLimit before changing the model. The CRDT retains the update; once a peer corrects its nesting, the binding rebuilds the model from the bounded shared state.