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` ...@@ -61,8 +61,6 @@ const ContentArea = styled.div`
overflow-y: auto; overflow-y: auto;
`; `;
let a = '';
const Ncbi = () => { const Ncbi = () => {
const [content, setContent] = useState(''); const [content, setContent] = useState('');
......
...@@ -19,6 +19,7 @@ export default class CommentsService extends Service { ...@@ -19,6 +19,7 @@ export default class CommentsService extends Service {
CommentBubbleComponent, CommentBubbleComponent,
{}, {},
{ {
nodeType: '',
markType: '', markType: '',
followCursor: false, followCursor: false,
selection: true, selection: true,
......
...@@ -11,6 +11,7 @@ class CustomTagInlineService extends Service { ...@@ -11,6 +11,7 @@ class CustomTagInlineService extends Service {
CustomTagInlineOverlayComponent, CustomTagInlineOverlayComponent,
{}, {},
{ {
nodeType: '',
markType: 'customTagInline', markType: 'customTagInline',
followCursor: false, followCursor: false,
selection: true, selection: true,
......
...@@ -17,6 +17,7 @@ export default class LinkService extends Service { ...@@ -17,6 +17,7 @@ export default class LinkService extends Service {
LinkComponent, LinkComponent,
{}, {},
{ {
nodeType: '',
markType: 'link', markType: 'link',
followCursor: false, followCursor: false,
selection: false, selection: false,
......
...@@ -14,7 +14,8 @@ class CreateDropDownService extends Service { ...@@ -14,7 +14,8 @@ class CreateDropDownService extends Service {
DropDownComponent, DropDownComponent,
{}, {},
{ {
markType: 'multiple_drop_down_option', nodeType: 'multiple_drop_down_option',
markType: '',
followCursor: true, followCursor: true,
selection: false, selection: false,
}, },
......
...@@ -21,7 +21,7 @@ export default options => { ...@@ -21,7 +21,7 @@ export default options => {
}); });
let mark = {}; let mark = {};
let node = {};
/* Sets Default position at the end of the annotation. You /* Sets Default position at the end of the annotation. You
can overwrite the default position in your component. can overwrite the default position in your component.
Check: wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js Check: wax-prosemirror-components/src/components/comments/CommentBubbleComponent.js
...@@ -52,6 +52,25 @@ export default options => { ...@@ -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 displayOnMark = (focusedView, overlayOptions) => {
const { markType, followCursor } = overlayOptions; const { markType, followCursor } = overlayOptions;
const PMmark = focusedView.state.schema.marks[markType]; const PMmark = focusedView.state.schema.marks[markType];
...@@ -92,7 +111,11 @@ export default options => { ...@@ -92,7 +111,11 @@ export default options => {
const updatePosition = useCallback((followCursor = true) => { const updatePosition = useCallback((followCursor = true) => {
if (Object.keys(activeView).length === 0) return defaultOverlay; 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) if (markType && selection)
return displayOnMarkOrSelection(activeView, options); return displayOnMarkOrSelection(activeView, options);
......
/* eslint-disable no-underscore-dangle */
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { injectable, inject } from 'inversify'; import { injectable, inject } from 'inversify';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
......
...@@ -27,6 +27,18 @@ const findMark = (state, PMmark, toArr = false) => { ...@@ -27,6 +27,18 @@ const findMark = (state, PMmark, toArr = false) => {
return markFound; 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 getCommentsTracksCount = main => {
const marks = findInlineNodes(main.state.doc); const marks = findInlineNodes(main.state.doc);
const commentsTracksFormat = []; const commentsTracksFormat = [];
...@@ -270,6 +282,7 @@ const findParentOfType = (state, nodeType) => { ...@@ -270,6 +282,7 @@ const findParentOfType = (state, nodeType) => {
export default { export default {
findMark, findMark,
findNode,
findBlockNodes, findBlockNodes,
findChildrenByType, findChildrenByType,
findInlineNodes, 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