jupyter_ydoc
jupyter_ydoc copied to clipboard
Y bridge between YDocs
Problem
One document may have different YDoc structures, e.g. a Jupyter notebook can be opened in JupyterLab as a notebook (and it will be shown nicely with cells etc.) or as a plain text document. While the text document has a relatively simple YDoc, with only a YText for the whole content, the notebook has a YArray for cells, a YMap for metadata, etc. This finer-grained structure allows to observe changes to e.g. a cell source only, and react accordingly. While a YDoc can be synced with another YDoc of the same structure, for instance between two browsers showing the same notebook, the same document cannot be synced when opened as two different YDocs (e.g. in text/as a notebook) in the same JupyterLab.
Proposed Solution
We could create a "Y bridge", that would make syncing the two "incompatible" YDocs possible. Something that observes changes to a YDoc and translates them to the other. It will require some interpretation, e.g. when changing the cell source in a text document, we need to do the update in the appropriate cell structure in a notebook.
cc @dmonad @hbcarlos
Additional context
See https://github.com/jupyterlab/jupyterlab/pull/12360#discussion_r869224163.