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

add copy paste comment plugin

parent 824edd28
No related branches found
No related tags found
1 merge request!338Fix feedback
......@@ -43,10 +43,6 @@ const Editoria = () => {
const EditoriaComponent = useMemo(
() => (
<>
<button onClick={() => console.log(editorRef.current.getContent())}>
Click
</button>
<Wax
ref={editorRef}
key={key}
......@@ -60,7 +56,6 @@ const Editoria = () => {
// onChange={debounce(source => {
// console.log(JSON.stringify(source));
// }, 200)}
// onBlur={source => console.log(source)}
user={user}
/>
</>
......
......@@ -24,7 +24,7 @@ const Hhmi = () => {
config={config}
autoFocus
fileUpload={file => renderImage(file)}
value={t}
value=""
// readonly
layout={HhmiLayout}
// onChange={source => console.log(source)}
......
import { injectable } from "inversify";
import { injectable } from 'inversify';
@injectable()
export default class PmPlugins {
_plugins = new Map();
......
/* eslint-disable array-callback-return */
/* eslint-disable no-param-reassign */
import { forEach, each } from 'lodash';
import { each } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { DocumentHelpers } from 'wax-prosemirror-utilities';
const transformPasted = (slice, view) => {
const { content } = slice;
if (view.state.schema.marks.comment) {
const commentNodes = DocumentHelpers.findChildrenByMark(
content,
view.state.schema.marks.comment,
true,
);
const allComments = [];
commentNodes.map(node => {
node.node.marks.map(comment => {
if (comment.type.name === 'comment') {
allComments.push(comment);
}
});
});
const groupedCommentsById = allComments.reduce((obj, mark) => {
obj[mark.attrs.id] = [...(obj[mark.attrs.id] || []), mark];
return obj;
}, {});
forEach(Object.keys(groupedCommentsById), key => {
const id = uuidv4();
forEach(groupedCommentsById[key], comment => {
comment.attrs.id = id;
});
});
}
const schemaNotes = [];
each(view.state.schema.nodes, node => {
......
......@@ -2,6 +2,8 @@ export { default as TrackChangePlugin } from './src/trackChanges/TrackChangePlug
export { default as HideShowPlugin } from './src/trackChanges/HideShowPlugin';
export { default as CommentPlugin } from './src/comments/CommentPlugin';
export { default as CopyPasteCommentPlugin } from './src/comments/CopyPasteCommentPlugin';
export { default as WaxSelectionPlugin } from './src/WaxSelectionPlugin';
export { default as highlightPlugin } from './src/highlightPlugin';
......
/* eslint-disable */
import { forEach } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { Plugin, PluginKey } from 'prosemirror-state';
import { DocumentHelpers } from 'wax-prosemirror-utilities';
const copyPasteCommentPugin = new PluginKey('copyPasteCommentPugin');
export default (props, context) => {
return new Plugin({
key: copyPasteCommentPugin,
props: {
transformPasted: slice => {
const { activeView } = context.app.context;
console.log(activeView);
const { content } = slice;
console.log(slice);
const commentNodes = DocumentHelpers.findChildrenByMark(
content,
activeView.state.schema.marks.comment,
true,
);
const allComments = [];
commentNodes.map(node => {
node.node.marks.map(comment => {
if (comment.type.name === 'comment') {
allComments.push(comment);
}
});
});
const groupedCommentsById = allComments.reduce((obj, mark) => {
obj[mark.attrs.id] = [...(obj[mark.attrs.id] || []), mark];
return obj;
}, {});
forEach(Object.keys(groupedCommentsById), key => {
const id = uuidv4();
forEach(groupedCommentsById[key], comment => {
comment.attrs.id = id;
});
});
return slice;
},
},
});
};
import { commentMark } from 'wax-prosemirror-schema';
import { RightArea, CommentBubbleComponent } from 'wax-prosemirror-components';
import { CommentPlugin } from 'wax-prosemirror-plugins';
import { CommentPlugin, CopyPasteCommentPlugin } from 'wax-prosemirror-plugins';
import Service from '../Service';
const PLUGIN_KEY = 'commentPlugin';
......@@ -8,6 +8,10 @@ const PLUGIN_KEY = 'commentPlugin';
export default class CommentsService extends Service {
boot() {
this.app.PmPlugins.add(PLUGIN_KEY, CommentPlugin(PLUGIN_KEY));
this.app.PmPlugins.add(
'copyPasteCommentPlugin',
CopyPasteCommentPlugin('copyPasteCommentPlugin', this.app.context),
);
const createOverlay = this.container.get('CreateOverlay');
const layout = this.container.get('Layout');
createOverlay(
......
......@@ -11,7 +11,6 @@ import { undo, redo } from 'prosemirror-history';
import { WaxContext } from 'wax-prosemirror-core';
import { NoteEditorContainer } from 'wax-prosemirror-components';
import { DocumentHelpers } from 'wax-prosemirror-utilities';
import transformPasted from './helpers/TransformPasted';
import trackedTransaction from '../TrackChangeService/track-changes/trackedTransaction';
export default ({ node, view }) => {
......@@ -63,9 +62,6 @@ export default ({ node, view }) => {
handleTextInput: (editorView, from, to, text) => {
typing = true;
},
transformPasted: slice => {
return transformPasted(slice, noteView);
},
attributes: {
spellcheck: 'false',
......
import { forEach } from "lodash";
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 => {
node.node.marks.map(comment => {
if (comment.type.name === "comment") {
allComments.push(comment);
}
});
});
let groupedCommentsById = allComments.reduce((obj, mark) => {
obj[mark.attrs.id] = [...(obj[mark.attrs.id] || []), mark];
return obj;
}, {});
forEach(Object.keys(groupedCommentsById), key => {
let id = uuidv4();
forEach(groupedCommentsById[key], comment => {
comment.attrs.id = id;
});
});
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