Newer
Older
import { Plugin, PluginKey } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import { CommentDecorationPluginKey } from './CommentDecorationPlugin';
const commentsMap = CommentDecorationPluginKey.getState(state).getMap();
const commentsDataMap = CommentDecorationPluginKey.getState(
state,
).getCommentsDataMap();
if (commentsMap.size === 0) return;
let commentData = [];
commentsMap.forEach(comment => {
if (inRange(state.selection.from, comment.data.pmFrom, comment.data.pmTo)) {
commentData.push(comment);
}
});
commentsDataMap.get(last(commentData)?.id)?.data?.conversation
.length === 0) ||
commentsDataMap.get(last(commentData)?.id)?.data?.conversation
.length !== 0)
state: {
init: (_, state) => {
},
apply(tr, prev, _, newState) {
let createDecoration;
if (comment) {
createDecoration = DecorationSet.create(newState.doc, [
Decoration.inline(comment.data.pmFrom, comment.data.pmTo, {
]);
}
return {
comment,
const commentPluginState = state && commentPlugin.getState(state);
return commentPluginState.createDecoration;