Newer
Older
/* eslint react/prop-types: 0 */
import React, { useLayoutEffect, useContext } from 'react';
import { WaxContext, Commands, DocumentHelpers } from 'wax-prosemirror-core';
import { AnnotationPluginKey } from '../../../plugins/AnnotationPlugin';
const { activeView, activeViewId } = useContext(WaxContext);
const { state, dispatch } = activeView;
useLayoutEffect(() => {
const WaxSurface = activeView.dom.getBoundingClientRect();
const { selection } = activeView.state;
const { from, to } = selection;
const start = activeView.coordsAtPos(from);
const end = activeView.coordsAtPos(to);
const difference = end.top - start.top;
const top = end.top - WaxSurface.top - difference / 2 - 5;
setPosition({ ...position, left, top });
conversation: [],
group,
viewid: activeViewId,
},
dispatch(state.tr);
// Delete when new comments are done
// Commands.createComment(state, dispatch, group, activeViewId);
// activeView.focus();
const commentMark = activeView.state.schema.marks.comment;
const marks = DocumentHelpers.findMark(state, commentMark, true);
let allowed = true;
state.doc.nodesBetween(
state.selection.$from.pos,
state.selection.$to.pos,
marks.forEach(mark => {
if (mark.attrs.group === 'main') allowed = false;
});
// TO DO this is because of a bug and overlay doesn't rerender. Fix in properly in Notes, and remove
if (activeViewId !== 'main' && marks.length >= 1) allowed = false;