Skip to content
Snippets Groups Projects
Commit 520f7a0c authored by Christos's avatar Christos
Browse files

Merge branch 'fix-paste-ids' into 'master'

transform comment before merging them into document

See merge request !105
parents 365c8546 d59d38cb
No related branches found
No related tags found
1 merge request!105transform comment before merging them into document
export { WaxContext, useInjection } from "./src/ioc-react";
export { WaxContext, useInjection } from "./src/WaxContext";
export { default as Wax } from "./src/Wax";
import React, { useEffect, useState } from "react";
import WaxProvider from "./ioc-react";
import WaxProvider from "./WaxContext";
import Application from "./Application";
import debounce from "lodash/debounce";
......
......@@ -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 { WaxContext } from "./WaxContext";
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);
}
}
);
......
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 notes = DocumentHelpers.findChildrenByType(
content,
view.state.schema.nodes.footnote,
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();
});
notes.forEach(note => {
note.node.attrs.id = uuidv4();
});
return slice;
};
export default transformPasted;
......@@ -10,6 +10,7 @@ import { Commands } from "wax-prosemirror-utilities";
import { NoteEditorContainer } from "wax-prosemirror-components";
import { DocumentHelpers } from "wax-prosemirror-utilities";
import { filter } from "lodash";
import transformPasted from "./helpers/TransformPasted";
export default ({ node, view }) => {
const editorRef = useRef();
......@@ -62,6 +63,9 @@ export default ({ node, view }) => {
// the parent editor is focused.
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