I’d like to build an app where users are able to add notes to documents they don’t have edit access to. Essentially they are taking their own collaborative notes on someone else’s (potentially live edited) notes.
It seems prosemirror supports nested instances of the editor via custom view nodes. How plausible is the following strategy:
UserA’s client has read access, but not write access toDoc1so we use ProseMirroreditable: falseUserA’s client can, however, specify a position to insert a new block node toDoc1. This node has a custom node view that embeds a prosemirror instance (we’ll call this nodeNestedDocView).- Since
UserAdoesn’t have write access these changes aren’t propagated to other clients or stored, its inUserA’s client side memory only. - Create a
Y.RelativePositiononDoc1where theNestedDocViewis inserted, then store an encoded version of it as a property onDoc2. - A new
Y.Doc(orY.xmlFragment)Doc2is created and and is bound to the new NestedDocView via the syncPlugin,UserAhas write access. - When
UserAloadsDoc1later, we can rehydrate the previous state by resolving an absolute position from the encodedY.RelativePositionfrom step 4 then inserting aNestedDocViewin that position. Any remote updates toDoc1won’t mess with consistent positioning ofDoc2withinDoc1 - Similarly
UserBmay have access toDoc2andDoc1will be able to seeDoc2embedded in the correct spot withinDoc1because of that storedY.RelativePosition.
Assumptions:
- Remote changes to
Doc1can be applied toUserA’s modified version, and the NestedDocView will keep its relative position. - After changes to
Doc1between sessions, the encodedY.RelativePositioninDoc2will always give a valid absolute position index
Questions
- What happens if the characters referenced by the encoded
Y.RelativePositionreference are deleted? whats a sensible strategy to resolve this? just append to end ofDoc1, or can we do something smarter? - If the owner of
Doc1(Admin) can also viewDoc2, can I add the NestedDocView node toDoc1but not propagate that specific change to other clients / server. - I think undo/redo for
Adminwould be fine, just don’t record theNestedDocViewinsertion on hydration? - Any other obvious edge cases that will need some workaround?