Skip to content
Snippets Groups Projects
Commit 7a0509d6 authored by chris's avatar chris
Browse files

alter id's for comments/notes in all pm views before pasting

parent 675fc8c3
No related branches found
No related tags found
1 merge request!105transform comment before merging them into document
...@@ -8,15 +8,28 @@ const transformPasted = (slice, view) => { ...@@ -8,15 +8,28 @@ const transformPasted = (slice, view) => {
view.state.schema.marks.comment, view.state.schema.marks.comment,
true true
); );
const notes = DocumentHelpers.findChildrenByType(
content,
view.state.schema.nodes.footnote,
true
);
const allComments = commentNodes.map(node => { const allComments = commentNodes.map(node => {
return node.node.marks.filter(comment => { return node.node.marks.filter(comment => {
return comment.type.name === "comment"; return comment.type.name === "comment";
}); });
}); });
//TODO check to alter attr with transform
allComments.forEach(comment => { allComments.forEach(comment => {
comment[0].attrs.id = uuidv4(); comment[0].attrs.id = uuidv4();
}); });
notes.forEach(note => {
note.node.attrs.id = uuidv4();
});
return slice; return slice;
}; };
......
...@@ -10,6 +10,7 @@ import { Commands } from "wax-prosemirror-utilities"; ...@@ -10,6 +10,7 @@ import { Commands } from "wax-prosemirror-utilities";
import { NoteEditorContainer } from "wax-prosemirror-components"; import { NoteEditorContainer } from "wax-prosemirror-components";
import { DocumentHelpers } from "wax-prosemirror-utilities"; import { DocumentHelpers } from "wax-prosemirror-utilities";
import { filter } from "lodash"; import { filter } from "lodash";
import transformPasted from "./helpers/TransformPasted";
export default ({ node, view }) => { export default ({ node, view }) => {
const editorRef = useRef(); const editorRef = useRef();
...@@ -62,6 +63,9 @@ export default ({ node, view }) => { ...@@ -62,6 +63,9 @@ export default ({ node, view }) => {
// the parent editor is focused. // the parent editor is focused.
if (noteView.hasFocus()) noteView.focus(); if (noteView.hasFocus()) noteView.focus();
} }
},
transformPasted: slice => {
return transformPasted(slice, noteView);
} }
} }
); );
......
import { v4 as uuidv4 } from "uuid";
import { DocumentHelpers } from "wax-prosemirror-utilities";
const transformPasted = (slice, view) => {
const { content } = slice;
const commentNodes = DocumentHelpers.findChildrenByMark(
content,
view.state.schema.marks.comment,
true
);
const allComments = commentNodes.map(node => {
return node.node.marks.filter(comment => {
return comment.type.name === "comment";
});
});
//TODO check to alter attr with transform
allComments.forEach(comment => {
comment[0].attrs.id = uuidv4();
});
return slice;
};
export default transformPasted;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment