From d5cc1fe48a867317b54f501581930436d7f10fdf Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 2 Apr 2024 17:47:49 +0300 Subject: [PATCH] add non yjs methods --- .../CommentsService/plugins/CommentState.js | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js b/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js index 5eb16122c..32fb91c29 100644 --- a/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js +++ b/wax-prosemirror-services/src/CommentsService/plugins/CommentState.js @@ -58,11 +58,11 @@ export default class CommentState { const decorations = []; const ystate = ySyncPluginKey.getState(state); - const { doc, type, binding } = ystate; const { map } = this.options; - if (binding) { + if (ystate?.binding) { + const { doc, type, binding } = ystate; map.forEach((annotation, id) => { if (typeof annotation.yjsFrom === 'number') { annotation.yjsFrom = absolutePositionToRelativePosition( @@ -95,6 +95,26 @@ export default class CommentState { return; } + decorations.push( + Decoration.inline( + from, + to, + { + class: 'comment', + 'data-id': annotation.id, + }, + { + id: annotation.id, + data: annotation, + inclusiveEnd: true, + }, + ), + ); + }); + } else { + this.allCommentsList().forEach(annotation => { + const { from, to } = annotation; + decorations.push( Decoration.inline( from, @@ -113,25 +133,6 @@ export default class CommentState { }); } - // 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); } @@ -192,7 +193,16 @@ export default class CommentState { if (ystate?.binding && ystate?.binding.mapping) { this.updateCommentPostions(ystate); return this; + // eslint-disable-next-line no-else-return + } else { + this.options.map.forEach((annotation, _) => { + if ('from' in annotation && 'to' in annotation) { + annotation.from = transaction.mapping.map(annotation.from); + annotation.to = transaction.mapping.map(annotation.to); + } + }); + this.createDecorations(state); + return this; } - return this; } } -- GitLab