Newer
Older
import { Plugin, PluginKey } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
const getComment = (state, context) => {
const {
options: { comments },
} = context;
if (!comments?.length) return;
inRange(state.selection.from, comment.from, comment.to),
);
(state.selection.from !== state.selection.to &&
last(commentData).data.conversation.length === 0) ||
(state.selection.from === state.selection.to &&
last(commentData).data.conversation.length !== 0)
state: {
init: (_, state) => {
},
apply(tr, prev, _, newState) {
let createDecoration;
if (comment) {
createDecoration = DecorationSet.create(newState.doc, [
Decoration.inline(comment.from, comment.to, {
]);
}
return {
comment,
const commentPluginState = state && commentPlugin.getState(state);
return commentPluginState.createDecoration;