fix: Do not allow copy/pasting comment marks between documents (#5507)
This commit is contained in:
@@ -19,10 +19,31 @@ export default class Comment extends Mark {
|
|||||||
userId: {},
|
userId: {},
|
||||||
},
|
},
|
||||||
inclusive: false,
|
inclusive: false,
|
||||||
parseDOM: [{ tag: "span.comment-marker" }],
|
parseDOM: [
|
||||||
|
{
|
||||||
|
tag: "span.comment-marker",
|
||||||
|
getAttrs: (dom: HTMLSpanElement) => {
|
||||||
|
// Ignore comment markers from other documents
|
||||||
|
const documentId = dom.getAttribute("data-document-id");
|
||||||
|
if (documentId && documentId !== this.editor.props.id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: dom.getAttribute("id")?.replace("comment-", ""),
|
||||||
|
userId: dom.getAttribute("data-user-id"),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
toDOM: (node) => [
|
toDOM: (node) => [
|
||||||
"span",
|
"span",
|
||||||
{ class: "comment-marker", id: `comment-${node.attrs.id}` },
|
{
|
||||||
|
class: "comment-marker",
|
||||||
|
id: `comment-${node.attrs.id}`,
|
||||||
|
"data-user-id": node.attrs.userId,
|
||||||
|
"data-document-id": this.editor.props.id,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -87,7 +108,7 @@ export default class Comment extends Mark {
|
|||||||
new Plugin({
|
new Plugin({
|
||||||
props: {
|
props: {
|
||||||
handleDOMEvents: {
|
handleDOMEvents: {
|
||||||
mouseup: (view, event: MouseEvent) => {
|
mouseup: (_view, event: MouseEvent) => {
|
||||||
if (
|
if (
|
||||||
!(event.target instanceof HTMLSpanElement) ||
|
!(event.target instanceof HTMLSpanElement) ||
|
||||||
!event.target.classList.contains("comment-marker")
|
!event.target.classList.contains("comment-marker")
|
||||||
|
|||||||
Reference in New Issue
Block a user