diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js index 8837b278e3d8c3e0e7c6f5a3ea237f63a71cfb22..3e85568eaea88403be4213b9ad9291685b3f3d73 100644 --- a/editors/demo/src/Editoria/Editoria.js +++ b/editors/demo/src/Editoria/Editoria.js @@ -55,7 +55,7 @@ const Editoria = () => { autoFocus placeholder="Type Something..." fileUpload={file => renderImage(file)} - value={demo} + // value={demo} // readonly layout={layout} // onChange={debounce(source => { diff --git a/editors/demo/src/Editoria/config/config.js b/editors/demo/src/Editoria/config/config.js index 35325a79dfa790596301d94b0d9259ef607a5776..bbcf6e2a6c271d44f92408bf39005d45a1eb5d70 100644 --- a/editors/demo/src/Editoria/config/config.js +++ b/editors/demo/src/Editoria/config/config.js @@ -26,7 +26,7 @@ import { disallowPasteImagesPlugin, BlockDropDownToolGroupService, AskAiContentService, - // YjsService, + YjsService, CommentDecoration, } from 'wax-prosemirror-services'; @@ -149,7 +149,7 @@ export default { 'HighlightToolGroup', 'TransformToolGroup', 'CustomTagInline', - 'Notes', + // 'Notes', 'Lists', 'Images', 'SpecialCharacters', @@ -227,11 +227,11 @@ export default { ], updateTags: saveTags, }, - // YjsService: { - // // eslint-disable-next-line no-restricted-globals - // connectionUrl: 'ws://localhost:4000', - // docIdentifier: 'prosemirror-demo', - // }, + YjsService: { + // eslint-disable-next-line no-restricted-globals + connectionUrl: 'ws://localhost:4000', + docIdentifier: 'prosemirror-demo', + }, AskAiContentService: { AskAiContentTransformation: DummyPromise, @@ -239,7 +239,7 @@ export default { }, services: [ - // new YjsService(), + new YjsService(), new BlockDropDownToolGroupService(), new AskAiContentService(), new CustomTagService(), @@ -253,7 +253,7 @@ export default { new ImageService(), new TablesService(), new BaseService(), - new NoteService(), + // new NoteService(), new CodeBlockService(), new EditingSuggestingService(), new DisplayTextToolGroupService(), diff --git a/wax-prosemirror-services/src/CommentsService/CommentsService.js b/wax-prosemirror-services/src/CommentsService/CommentsService.js index 1a732f086b3f88cc2cb3fb3372d8ec5b95c633a6..84295de4ca5faceeff067e03bcf8a68bcc5233cd 100644 --- a/wax-prosemirror-services/src/CommentsService/CommentsService.js +++ b/wax-prosemirror-services/src/CommentsService/CommentsService.js @@ -1,4 +1,5 @@ import { Service } from 'wax-prosemirror-core'; +import * as Y from 'yjs'; import CommentBubbleComponent from './components/ui/comments/CommentBubbleComponent'; import RightArea from './components/RightArea'; import commentMark from './schema/commentMark'; diff --git a/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js b/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js index f7e55fc20b2fcd6da782dbcf0af6d246e87c2e72..560bf634e705f13517a0ed9307956dfaf1885cf3 100644 --- a/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js +++ b/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js @@ -1,6 +1,11 @@ /* eslint-disable no-param-reassign */ import { v4 as uuidv4 } from 'uuid'; import { Decoration, DecorationSet } from 'prosemirror-view'; +import { + ySyncPluginKey, + relativePositionToAbsolutePosition, + absolutePositionToRelativePosition, +} from 'y-prosemirror'; import CommentDecoration from './CommentDecoration'; import { CommentDecorationPluginKey } from './CommentDecorationPlugin'; @@ -51,26 +56,70 @@ export default class CommentState { createDecorations(state) { const decorations = []; + const ystate = ySyncPluginKey.getState(state); + const { doc, type, binding } = ystate; - this.allCommentsList().forEach(annotation => { - const { from, to } = annotation; - - decorations.push( - Decoration.inline( - from, - to, - { - class: 'comment', - 'data-id': annotation.id, - }, - { - id: annotation.id, - data: annotation, - inclusiveEnd: true, - }, - ), - ); - }); + const { map } = this.options; + console.log(binding); + if (binding) { + console.log(doc, type, binding); + map.forEach((annotation, id) => { + console.log(annotation); + const from = relativePositionToAbsolutePosition( + doc, + type, + annotation.from, + binding.mapping, + ); + console.log(from); + const to = relativePositionToAbsolutePosition( + doc, + type, + annotation.to, + binding.mapping, + ); + + if (!from || !to) { + return; + } + + decorations.push( + Decoration.inline( + from, + to, + { + class: 'comment', + 'data-id': annotation.id, + }, + { + id: annotation.id, + data: annotation, + inclusiveEnd: true, + }, + ), + ); + }); + } + + // this.allCommentsList().forEach(annotation => { + // const { from, to } = annotation; + + // decorations.push( + // Decoration.inline( + // from, + // to, + // { + // class: 'comment', + // 'data-id': annotation.id, + // }, + // { + // id: annotation.id, + // data: annotation, + // inclusiveEnd: true, + // }, + // ), + // ); + // }); this.decorations = DecorationSet.create(state.doc, decorations); }