-
Notifications
You must be signed in to change notification settings - Fork 11
Adding pasteHandler to ensure new UUID on copying a footnote Reference #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Adding pasteHandler to ensure new UUID on copying a footnote Reference #25
Conversation
When a footnote reference is pasted, the uuid gets copied, creating duplicate references. We add a paste handler, to go through the slice, and ensure that pasted footnoteReferences get a new UUID
shailejajain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some quick questions
| transformPasted(slice) { | ||
| const newTopLevelNodes: PMNode[] = []; | ||
| slice.content.forEach(topNode => { | ||
| newTopLevelNodes.push(mapNode(topNode)); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this not use map? feels like its just mapping each node in slice.content
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiptap fragment (which is what slice.content is) does not have a map function. It only has a forEach function to interate through the nodes in the fragment. That's why I used a forEach
| */ | ||
| const mapNode = (node: PMNode): PMNode => { | ||
| // 1. If this is a footnoteReference, create a new one with a new ID. | ||
| if (node.type.name === this.name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does this.name get set to footnoteReference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.name is accessible because we are creating a TipTap Node.
It gets set here
| } | ||
|
|
||
| // 2. If this node has children, we must recurse by mapping over its content. | ||
| if (node.content && node.content.size > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if node.type.name === this.name is set, the node can't have children?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
footnoteReference cannot have child nodes. It can only have text within it, according to the schema defined :
https://github.com/Some1Somewhere/tiptap-footnotes/blob/2984459a4eb67167ad65c17fd2647a018fd6c9be/package/src/footnotes/reference.ts#L25
shailejajain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Fixes : #24
When a footnote reference is pasted, the UUID gets copied, creating duplicate data-id across references.
We add a paste handler plugin to go through the slice and ensure that pasted footnote references get a new UUID
Footnote reference handling improvements
footnotePasteHandler) to theFootnoteReferencenode that recursively traverses pasted content and assigns a new uniquedata-idto everyfootnoteReference, ensuring no duplicate IDs are introduced when pasting.mapNodefunction to rebuild the node tree for pasted content, updating attributes as needed for eachfootnoteReference.Code cleanup
nodeInputRuleimport from@tiptap/coreinpackage/src/footnotes/reference.ts.Node,Fragment, andSlicefrom@tiptap/pm/modelto support the new plugin logic.