diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js index 5bd37509506da0181ca5f925a63c31f503c8a0ce..4293bf1a13cb9cb8ab75698003fed441428a1def 100644 --- a/editors/demo/src/Editoria/Editoria.js +++ b/editors/demo/src/Editoria/Editoria.js @@ -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} /> </> diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js index bbd32b6ea531849610d820521da41394e34d5470..ef7845bf449bc04a350a75e62dbed03718d0b6f2 100644 --- a/editors/demo/src/HHMI/HHMI.js +++ b/editors/demo/src/HHMI/HHMI.js @@ -24,7 +24,7 @@ const Hhmi = () => { config={config} autoFocus fileUpload={file => renderImage(file)} - value={t} + value="" // readonly layout={HhmiLayout} // onChange={source => console.log(source)} diff --git a/wax-prosemirror-core/src/PmPlugins.js b/wax-prosemirror-core/src/PmPlugins.js index ac5b5bf562166fbbaca25ff0f027732a8385761a..98ccb800cea1583e0b1d9224acec04d70b8a9389 100644 --- a/wax-prosemirror-core/src/PmPlugins.js +++ b/wax-prosemirror-core/src/PmPlugins.js @@ -1,4 +1,4 @@ -import { injectable } from "inversify"; +import { injectable } from 'inversify'; @injectable() export default class PmPlugins { _plugins = new Map(); diff --git a/wax-prosemirror-core/src/helpers/TransformPasted.js b/wax-prosemirror-core/src/helpers/TransformPasted.js index 9a4ce541f0ae0911fedf9761b523e70031fa4dee..4bdfdd9b9a7c20b9e03f8f7fc155aa81721c7ed6 100644 --- a/wax-prosemirror-core/src/helpers/TransformPasted.js +++ b/wax-prosemirror-core/src/helpers/TransformPasted.js @@ -1,40 +1,11 @@ /* 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 => { diff --git a/wax-prosemirror-plugins/index.js b/wax-prosemirror-plugins/index.js index d0a198c76de0f10be29733fa77a2c6d8f9dbafa5..431000b44c6b2e7eae3a322bb6a4feb280e178bc 100644 --- a/wax-prosemirror-plugins/index.js +++ b/wax-prosemirror-plugins/index.js @@ -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'; diff --git a/wax-prosemirror-plugins/src/comments/CopyPasteCommentPlugin.js b/wax-prosemirror-plugins/src/comments/CopyPasteCommentPlugin.js new file mode 100644 index 0000000000000000000000000000000000000000..00c5d6379b68ed65472add7467e18d73de2ececf --- /dev/null +++ b/wax-prosemirror-plugins/src/comments/CopyPasteCommentPlugin.js @@ -0,0 +1,50 @@ +/* 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; + }, + }, + }); +}; diff --git a/wax-prosemirror-services/src/CommentsService/CommentsService.js b/wax-prosemirror-services/src/CommentsService/CommentsService.js index 6a2b16d5fb00baf2375f96333b61ad76a8ebef10..11e5ca070e2d2c7fdb2eabea02fb7a6ce26ef3ed 100644 --- a/wax-prosemirror-services/src/CommentsService/CommentsService.js +++ b/wax-prosemirror-services/src/CommentsService/CommentsService.js @@ -1,6 +1,6 @@ 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( diff --git a/wax-prosemirror-services/src/NoteService/Editor.js b/wax-prosemirror-services/src/NoteService/Editor.js index 5fffc0b55429113ffec7eccaa53bc2b66047c905..30d736d6ea2c535bb715318b0539c37ee65379fd 100644 --- a/wax-prosemirror-services/src/NoteService/Editor.js +++ b/wax-prosemirror-services/src/NoteService/Editor.js @@ -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', diff --git a/wax-prosemirror-services/src/NoteService/helpers/TransformPasted.js b/wax-prosemirror-services/src/NoteService/helpers/TransformPasted.js deleted file mode 100644 index 353c11a4bae400864330f4abc9726fbc81dc5a85..0000000000000000000000000000000000000000 --- a/wax-prosemirror-services/src/NoteService/helpers/TransformPasted.js +++ /dev/null @@ -1,38 +0,0 @@ -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;