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

set left of WaxSurface for comment

parent 2f6bc103
No related branches found
No related tags found
1 merge request!72Comments
...@@ -4,7 +4,20 @@ import { WaxContext } from "wax-prosemirror-core/src/ioc-react"; ...@@ -4,7 +4,20 @@ import { WaxContext } from "wax-prosemirror-core/src/ioc-react";
import { DocumentHelpers } from "wax-prosemirror-utilities"; import { DocumentHelpers } from "wax-prosemirror-utilities";
const CommentBubbleComponent = ({ setPosition, position }) => { const CommentBubbleComponent = ({ setPosition, position }) => {
return <div>bubble</div>; const { view: { main } } = useContext(WaxContext);
const { state, dispatch } = main;
const ref = useRef(null);
useEffect(
() => {
const WaxSurface = main.dom.offsetParent.firstChild.getBoundingClientRect();
const left = WaxSurface.width;
setPosition({ ...position, left });
},
[position.left]
);
return <div ref={ref}>bubble</div>;
}; };
export default CommentBubbleComponent; export default CommentBubbleComponent;
...@@ -8,8 +8,9 @@ export default class CommentsService extends Service { ...@@ -8,8 +8,9 @@ export default class CommentsService extends Service {
boot() { boot() {
const createOverlay = this.container.get("CreateOverlay"); const createOverlay = this.container.get("CreateOverlay");
createOverlay(CommentBubbleComponent, { createOverlay(CommentBubbleComponent, {
markType: "selection", markType: "",
followCursor: false followCursor: false,
selection: true
}); });
} }
......
...@@ -34,8 +34,6 @@ const LinkComponent = ({ mark, setPosition, position }) => { ...@@ -34,8 +34,6 @@ const LinkComponent = ({ mark, setPosition, position }) => {
const width = ref.current ? ref.current.offsetWidth : 0; const width = ref.current ? ref.current.offsetWidth : 0;
const left = Math.abs(position.left - width / 2); const left = Math.abs(position.left - width / 2);
//TODO Overwrite default position in order to position LinkOverlay
// setPosition({ ...position, left });
setLinkText(); setLinkText();
removeMarkIfEmptyHref(); removeMarkIfEmptyHref();
}, },
......
...@@ -10,7 +10,11 @@ export default class LinkService extends Service { ...@@ -10,7 +10,11 @@ export default class LinkService extends Service {
boot() { boot() {
const createOverlay = this.container.get("CreateOverlay"); const createOverlay = this.container.get("CreateOverlay");
createOverlay(LinkComponent, { markType: "link", followCursor: false }); createOverlay(LinkComponent, {
markType: "link",
followCursor: false,
selection: false
});
} }
register() { register() {
......
...@@ -35,7 +35,7 @@ export default options => { ...@@ -35,7 +35,7 @@ export default options => {
}; };
}; };
const displayOnSelection = main => { const displayOnSelection = (main, options) => {
const { selection } = main.state; const { selection } = main.state;
const { from, to } = selection; const { from, to } = selection;
if (from === to) return defaultOverlay; if (from === to) return defaultOverlay;
...@@ -73,9 +73,9 @@ export default options => { ...@@ -73,9 +73,9 @@ export default options => {
const updatePosition = useCallback((followCursor = true) => { const updatePosition = useCallback((followCursor = true) => {
if (!main) return defaultOverlay; if (!main) return defaultOverlay;
const { markType } = options; const { markType, selection } = options;
if (markType === "selection") return displayOnSelection(main); if (selection) return displayOnSelection(main, options);
return displayOnMark(main, options); return displayOnMark(main, options);
}); });
......
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