Newer
Older
/* eslint react/prop-types: 0 */
import React, { useLayoutEffect, useContext } from 'react';
import { WaxContext } from 'wax-prosemirror-core';
import { CommentDecorationPluginKey } from '../../../plugins/CommentDecorationPlugin';
const {
activeView,
activeViewId,
options: { comments },
} = 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 });
const isCommentAllowed = () => {
let allowed = true;
state.doc.nodesBetween(
state.selection.$from.pos,
state.selection.$to.pos,
comments.find(
comm =>
comm.from === state.selection.from && comm.to === state.selection.to,
)
) {