diff --git a/editors/editoria/src/Editoria.js b/editors/editoria/src/Editoria.js index b99067c7eb28fb20f406a525af26156b5b503495..7026299c1cc96686000daff054fdb280edb1d10f 100644 --- a/editors/editoria/src/Editoria.js +++ b/editors/editoria/src/Editoria.js @@ -51,7 +51,7 @@ const Editoria = () => ( '<p class="paragraph">this is <span class="comment" id="1b87a19d-891c-4329-9482-b8ab8523c129" data-viewid="main" data-conversation="[]">some</span> content</p>' } layout={EditoriaLayout} - onChange={source => console.log(source)} + // onChange={source => console.log(source)} user={user} /> </Fragment> diff --git a/wax-prosemirror-components/src/components/comments/CommentBox.js b/wax-prosemirror-components/src/components/comments/CommentBox.js index c2e5fa7b81ebde03a59d3b1857f16ecd4e832e75..5f4b145bc14a733d03681a447d9c8af8dea865fa 100644 --- a/wax-prosemirror-components/src/components/comments/CommentBox.js +++ b/wax-prosemirror-components/src/components/comments/CommentBox.js @@ -8,12 +8,10 @@ const CommentBoxStyled = styled.div` flex-direction: column; margin-top: 10px; background: black; + position: absolute; + top: ${props => (props.top ? `${props.top}px` : 0)}; `; -export default ({ mark, view }) => { - useEffect(() => { - console.log(document.getElementById(mark.attrs.id)); - }, []); - - return <CommentBoxStyled />; +export default ({ mark, view, top }) => { + return <CommentBoxStyled top={top} />; }; diff --git a/wax-prosemirror-components/src/components/comments/CommentsBoxList.js b/wax-prosemirror-components/src/components/comments/CommentsBoxList.js index b30084e9a69631967cfdb558211fa98f36cd7730..37bf58332b81589803232067de6595969221da9c 100644 --- a/wax-prosemirror-components/src/components/comments/CommentsBoxList.js +++ b/wax-prosemirror-components/src/components/comments/CommentsBoxList.js @@ -1,17 +1,56 @@ -import React, { Fragment } from "react"; +import React, { Fragment, useEffect } from "react"; +import { each } from "lodash"; import CommentBox from "./CommentBox"; //TODO find from marks actual comment mark export default ({ comments, view }) => { + let commentEl = null; + let commentElTop = 0; + let top = 0; + + if (comments.length > 0) { + const WaxSurface = view.dom.getBoundingClientRect(); + each(comments, (entry, pos) => { + commentElTop = 0; + commentEl = document.getElementById(entry.node.marks[0].attrs.id); + commentElTop = commentEl.getBoundingClientRect().top - WaxSurface.top; + entry.node.marks[0].top = commentElTop; + }); + } + + const setTops = () => { + if (comments.length > 0) { + each(comments, (entry, pos) => { + const WaxSurface = view.dom.getBoundingClientRect(); + commentElTop = 0; + commentEl = document.getElementById(entry.node.marks[0].attrs.id); + commentElTop = commentEl.getBoundingClientRect().top - WaxSurface.top; + entry.node.marks[0].top = commentElTop; + return commentElTop; + }); + } + }; + + useEffect( + () => { + console.log("change"); + }, + [setTops] + ); return ( <Fragment> - {comments.map(comment => ( - <CommentBox - key={comment.node.marks[0].attrs.id} - mark={comment.node.marks[0]} - view={view} - /> - ))} + {comments.map(comment => { + if (comment) top = comment.node.marks[0].top; + console.log(comment.node.marks[0].attrs.id); + return ( + <CommentBox + key={comment.node.marks[0].top} + mark={comment.node.marks[0]} + view={view} + top={top} + /> + ); + })} </Fragment> ); };