Update dropped node attributes

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 should be called for dropped content as well.

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.

Ah, right, that’s the same as with pasting (copying content from inside the editor will behave the same).

Is the appendTransaction approach to IDs not working for you?

Ah, right, that’s the same as with pasting (copying content from inside the editor will behave the same).

hmm no. transformPasted is called for both pasting content from outside and inside of the editor.

Is the appendTransaction approach to IDs not working for you?

I’m not quite sure how to get to the dropped nodes with their new position within appendTransaction right now. Do you have a hint for me?

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.

On closer look, the fact that transformPasted isn’t called on locally dropped content seems to be a bug. I’ll push a fix.

1 Like

Ah, thanks for that! :+1: