I try to add uuids to some nodes. There are already some threads about it but I couldn’t find any approaches about handling paste and drop.
Updating pasted content with transformPasted is super straightforward since I can easily loop over slice.content.
new Plugin({
props: {
transformPasted: slice => {
return new Slice(transformContent(slice.content), slice.openStart, slice.openEnd)
},
},
})
But I’m struggling with updating the dropped content. Since I can drop and duplicate (holding alt key) content, I have to find a way to update its attributes to avoid duplicated uuids. Unfortunately there isn’t something like transformDropped. There was also closed RFC about replacing transactions which could help here.
What would be the easiest way to update dropped content? I’m thinking about undoing the last transaction and reapplying its steps with updated sliced content but I feel like that seems unnecessarily complex.
transformPasted is only called if I drop content from outside of the editor. If I drag content within the editor while holding alt to duplicate the dropped content, it is not called.
The idea is that you wouldn’t write drop-specific code in the append-transaction handler, but react to any steps whose step map covers any node starts by iterating the entire document to ensure IDs are unique.