Skip to content
Snippets Groups Projects
Commit ef84bfee authored by chris's avatar chris
Browse files

display on node

parent d33aab9f
No related branches found
No related tags found
1 merge request!396add inputs
......@@ -61,8 +61,6 @@ const ContentArea = styled.div`
overflow-y: auto;
`;
let a = '';
const Ncbi = () => {
const [content, setContent] = useState('');
......
......@@ -19,6 +19,7 @@ export default class CommentsService extends Service {
CommentBubbleComponent,
{},
{
nodeType: '',
markType: '',
followCursor: false,
selection: true,
......
......@@ -11,6 +11,7 @@ class CustomTagInlineService extends Service {
CustomTagInlineOverlayComponent,
{},
{
nodeType: '',
markType: 'customTagInline',
followCursor: false,
selection: true,
......
......@@ -17,6 +17,7 @@ export default class LinkService extends Service {
LinkComponent,
{},
{
nodeType: '',
markType: 'link',
followCursor: false,
selection: false,
......
......@@ -14,7 +14,8 @@ class CreateDropDownService extends Service {
DropDownComponent,
{},
{
markType: 'multiple_drop_down_option',
nodeType: 'multiple_drop_down_option',
markType: '',
followCursor: true,
selection: false,
},
......
......@@ -21,7 +21,7 @@ export default options => {
});
let mark = {};
let node = {};
/* Sets Default position at the end of the annotation. You
can overwrite the default position in your component.
Check: wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js
......@@ -52,6 +52,25 @@ export default options => {
};
};
const displayOnNode = (focusedView, overlayOptions) => {
const { nodeType, followCursor } = overlayOptions;
const PMnode = focusedView.state.schema.nodes[nodeType];
node = DocumentHelpers.findNode(focusedView.state, PMnode);
if (!isObject(node)) return defaultOverlay;
const { from, to } = followCursor ? focusedView.state.selection : node;
const { left, top } = calculatePosition(focusedView, from, to);
return {
left,
top,
from,
to,
};
};
const displayOnMark = (focusedView, overlayOptions) => {
const { markType, followCursor } = overlayOptions;
const PMmark = focusedView.state.schema.marks[markType];
......@@ -92,7 +111,11 @@ export default options => {
const updatePosition = useCallback((followCursor = true) => {
if (Object.keys(activeView).length === 0) return defaultOverlay;
const { markType, selection } = options;
const { markType, selection, nodeType } = options;
if (nodeType) {
return displayOnNode(activeView, options);
}
if (markType && selection)
return displayOnMarkOrSelection(activeView, options);
......
/* eslint-disable no-underscore-dangle */
import React, { useMemo } from 'react';
import { injectable, inject } from 'inversify';
import { isEmpty } from 'lodash';
......
......@@ -27,6 +27,18 @@ const findMark = (state, PMmark, toArr = false) => {
return markFound;
};
const findNode = (state, PMnode) => {
let nodeFound;
if (state.selection.node && state.selection.node.type.name === PMnode.name) {
nodeFound = {
from: state.selection.from,
to: state.selection.to,
node: state.selection.node,
};
}
return nodeFound;
};
const getCommentsTracksCount = main => {
const marks = findInlineNodes(main.state.doc);
const commentsTracksFormat = [];
......@@ -270,6 +282,7 @@ const findParentOfType = (state, nodeType) => {
export default {
findMark,
findNode,
findBlockNodes,
findChildrenByType,
findInlineNodes,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment