How to preserve cell attributes of exiting table when pasting another table? Now if I copy/paste a table, current attributes are being removed even if they are in schema. I use Tiptap but as it is made on top of Prosemirror, I ask here. I have checked the way prosemirror-table handles paste, and as far as I see tr.replace is used to replace content by Slices, and I cannot figure out how to get and put existing attributes to new cells.
Are your parseDOM
and toDOM
correct? You might not handle the attributes. I’d look there first, after that I’d go trough all the code that is called on paste events ( parseHTML
, handlePaste
, transformPastedHTML
etc. )
Attribute has been added using TipTap extension API, like this:
addAttributes() {
return {
...this.parent?.(),
["data-sync-id"]: {
default: null,
renderHTML: (attributes) => {
if (!attributes["data-sync-id"]) {
return null;
}
return {
["data-sync-id"]: attributes["data-sync-id"],
};
},
parseHTML: (element) => {
return element.getAttribute("data-sync-id");
},
},
};
},
I suppose these methods use parseDOM and toDOM methods from prosemirror.
What do you mean to go through all the code that is called on paste events? Should I replace default behaviour with custom one somewhere in these events?
First I’d just log out things, see if they’re what you expect them to be.
Could you please clarify which things? I don’t just have idea where to start?
See what the pasted html element is, see the pasted text, check out how prosemirror handles pastes by default in prosemirror-view, see the created Slice after pasting etc. In short: start logging.
Alright I have made it in another way: I’m collecting attributes in a Map of Maps from oldState and then applying them to newState in appendTransaction
.