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 toDoc1
so we use ProseMirroreditable: false
UserA
’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
UserA
doesn’t have write access these changes aren’t propagated to other clients or stored, its inUserA
’s client side memory only. - Create a
Y.RelativePosition
onDoc1
where theNestedDocView
is inserted, then store an encoded version of it as a property onDoc2
. - A new
Y.Doc
(orY.xmlFragment
)Doc2
is created and and is bound to the new NestedDocView via the syncPlugin,UserA
has write access. - When
UserA
loadsDoc1
later, we can rehydrate the previous state by resolving an absolute position from the encodedY.RelativePosition
from step 4 then inserting aNestedDocView
in that position. Any remote updates toDoc1
won’t mess with consistent positioning ofDoc2
withinDoc1
- Similarly
UserB
may have access toDoc2
andDoc1
will be able to seeDoc2
embedded in the correct spot withinDoc1
because of that storedY.RelativePosition
.
Assumptions:
- Remote changes to
Doc1
can be applied toUserA
’s modified version, and the NestedDocView will keep its relative position. - After changes to
Doc1
between sessions, the encodedY.RelativePosition
inDoc2
will always give a valid absolute position index
Questions
- What happens if the characters referenced by the encoded
Y.RelativePosition
reference 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 toDoc1
but not propagate that specific change to other clients / server. - I think undo/redo for
Admin
would be fine, just don’t record theNestedDocView
insertion on hydration? - Any other obvious edge cases that will need some workaround?