jupyter-server / jupyter_ydoc

Jupyter document structures for collaborative editing using Yjs/pycrdt
https://jupyter-ydoc.readthedocs.io
BSD 3-Clause "New" or "Revised" License
25 stars 16 forks source link

Support document forking #218

Open davidbrochart opened 4 months ago

davidbrochart commented 4 months ago

See https://github.com/jupyterlab/jupyterlab/issues/16008.

This PR adds an ISharedDocument.provider attribute, which is an IDocumentProvider and which represents the current provider for the document. The IDocumentProvider interface is moved from jupyter-collaboration to jupyter_ydoc (see https://github.com/jupyterlab/jupyter-collaboration/pull/239). I think this is fine since jupyter-collaboration depends on jupyter_ydoc. A YDocument can only have one provider at a time (as before), but the provider can change over time. This is typically done when forking a document: the initial provider (set by the YDrive) connects to the root document, and the new provider connects to the forked document. An ISharedDocument has a root room ID rootRoomId which is set when first connecting to the root room, and a current room ID currentRoomId which can be the root room ID or any other fork of the root room. This way we can say if the document is currently on a fork or on the root, and we know to which (root) room to merge when on a fork. An ISharedDocument has an addFork(forkId) method that sets a key fork_{forkId} on the Y document's state when the provider is asked to fork. This is a way to advertise all the forks of this document, so that any client viewing the document can be notified of a new fork and can connect to it.