composablesys / collabs

Collabs library monorepo
https://collabs.readthedocs.io/
Apache License 2.0
254 stars 11 forks source link

CPositionSource sharing #264

Closed mweidner037 closed 1 year ago

mweidner037 commented 1 year ago

Allow multiple list CRDTs to share a CPositionSource, possibly across linked documents (https://github.com/composablesys/collabs/issues/262).

E.g.:

(Can we make this work for multiple CRichTexts as well, including formatting spans?)

LocalList gets partway there but not all the way.

Some specific changes needed:

This feature is not critical, but it would be nice to implement it sooner because it will break backwards compatibility for saved states.

mweidner037 commented 1 year ago

[ ] Ensure CPositionSource doesn’t have any mutable state besides the abstract tree structure that might confuse sharers. E.g., the current delete counts would break CValueList merging if a separate list modified them.

My current plan for this:

mweidner037 commented 1 year ago

I'm skipping CPositionSource.compare for now because it was more complicated than I expected and had a performance cost (from storing depth). There is an untested draft here: https://github.com/composablesys/collabs/blob/9b20307e05d32f69049e62cb60319c83174e80e6/crdts/src/list/c_position_source.ts#L532

mweidner037 commented 1 year ago

[ ] Individual list CRDTs allow specifying a CPositionSource

I'm omitting this for now because I can't think of a good use case, and we can add it backwards-compatibly later.

E.g. for suggestions on a doc, storing the actual text and suggestions in separate CValueLists does not allow proper "accepting": you want to transfer (position, value) pairs from the suggestion to the actual text, but CValueList doesn't let you set a position directly. Instead, you should:

  1. Store suggestions in a "forked" doc that you merge to accept.
  2. Or, manually manage a CPositionSource plus 2 LocalLists. (We can make this easier to moving CValueList's merge logic to a static LocalList function.)

Even without this feature, the CPositionSource refactoring still makes (2) more reasonable. It might also enable using CPositionSource in a centralized app, to manage a CRDT total order whose actual position-value maps are handled by a server.