Hey everyone !!
I recently encountered a unique situation, and I’m not sure if Prosemirror has a built-in solution for this. I’ve looked through the Prosemirror code but couldn’t find anything relevant.
Imagine I maintain two JSON documents for the editor: one for the current mode and another for the draft mode. Let’s say someone comments on the current mode (view mode) of the editor where the text is “Hello Prosemirror community!!” However, in draft mode, this text has already been changed to “Hello, how are you, Prosemirror community!?” Additionally, the position of this node has changed in draft mode. How can Promirror handle this?
If I use the set comment feature through the annotation extension with ‘to’ and ‘from’ positions, it won’t help because the position has changed, and I need to apply the comment in draft mode when someone comments in view mode.
I look forward to your insights on this.
If you have the steps that produced the difference between the two documents, you can use position mapping to project positions from one to the other. If you just have two JSON values, there’s not much you can do.
@marijn thanks for the insight
storing steps from one version to another version will be hectic, suppose I have
v1 ,v2,v3…,v11
v1 is a version of a document that we see in view mode and v11 is a version of a document that we see in draft mode since it has gone through lots of changes
if I store all steps of changes from v1 to v11 and add a mark(comment) to any node in v1 and then use those steps to put that mark in v11 that seems to be doable but storing all transactions for every doc change is not looking good to me
Any insight on this like how we can optimise this ??
You can use YJS for storing the doc ( and for handling the collaboration if you need that ). Then you can use YJS RelativePositions
to keep track of items ( beware of copy pasting! ).
There’s also UniqueID extension | Tiptap Editor Docs that can help you ( it’s TipTap but can be converted to pure ProseMirror ).
Another way is to just compare the two documents, and do text-similarity between nodes so you can pair them up. After that you can do diffs on block nodes and map your comments accordingly.
can we not somehow store all steps by merging ProseMirror Reference manual at every change to map the old position to the new position
tr.mapping.map(15)
mapping can give me new from and to after all steps ??
@ViktorVaczi @marijn
Yes, if you store all the steps then you can map positions trough them. I thought you don’t want to store them, hence the alternatives I mentioned.
storing all steps is a bit of a messy and unrealistic task, as it can be a million steps from v1 to v11 but what I prefer is merging all steps through merge merge(other: Step) → Step | null
.
it will be helpful here ??
Thank you for the quick reply @ViktorVaczi !!
You can try that, not every step is mergeable, but most of them are ( continous writing ).
okay thank you @ViktorVaczi and @marijn for help thinking something like this Serializing and storing Mapping objects
to serialize and store mapping object to build new position out of old one