diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 439515b5e3744696ce5da416bbba4cf120a96330..05450beb96144e5a40e472f5d33266e2252fa80f 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -3,10 +3,12 @@ import React, { useEffect, useRef, useContext } from "react"; import applyDevTools from "prosemirror-dev-tools"; import { EditorState } from "prosemirror-state"; import { EditorView } from "prosemirror-view"; + import "prosemirror-view/style/prosemirror.css"; import { trackedTransaction } from "wax-prosemirror-services"; import { WaxContext } from "./ioc-react"; +import transformPasted from "./helpers/TransformPasted"; export default props => { const { @@ -36,6 +38,9 @@ export default props => { onBlur(view.state.doc.content); } : null + }, + transformPasted: slice => { + return transformPasted(slice, view); } } ); diff --git a/wax-prosemirror-core/src/helpers/TransformPasted.js b/wax-prosemirror-core/src/helpers/TransformPasted.js new file mode 100644 index 0000000000000000000000000000000000000000..9ff762af758dd6e67cc90627e8f87e574a977ddb --- /dev/null +++ b/wax-prosemirror-core/src/helpers/TransformPasted.js @@ -0,0 +1,23 @@ +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"; + }); + }); + + allComments.forEach(comment => { + comment[0].attrs.id = uuidv4(); + }); + return slice; +}; + +export default transformPasted;