Skip to content
Snippets Groups Projects
Commit 72e7883b authored by Christos's avatar Christos
Browse files

Merge branch 'display-comment-conversation' into 'master'

Display comment conversation

See merge request !110
parents fb2c91f4 67780ac0
No related branches found
No related tags found
1 merge request!110Display comment conversation
Showing
with 157 additions and 52 deletions
...@@ -23,6 +23,8 @@ import { ...@@ -23,6 +23,8 @@ import {
CommentsService CommentsService
} from "wax-prosemirror-services"; } from "wax-prosemirror-services";
import { WaxSelectionPlugin } from "wax-prosemirror-plugins";
import invisibles, { import invisibles, {
space, space,
hardBreak, hardBreak,
...@@ -54,7 +56,12 @@ export default { ...@@ -54,7 +56,12 @@ export default {
RulesService: [emDash, ellipsis], RulesService: [emDash, ellipsis],
ShortCutsService: {}, ShortCutsService: {},
PmPlugins: [columnResizing(), tableEditing(), invisibles([hardBreak()])], PmPlugins: [
columnResizing(),
tableEditing(),
invisibles([hardBreak()]),
WaxSelectionPlugin
],
// Always load first CommentsService and LinkService, // Always load first CommentsService and LinkService,
//as it matters on how PM treats nodes and marks //as it matters on how PM treats nodes and marks
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror UI components", "description": "Wax prosemirror UI components",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
import React, {
Fragment,
useState,
useEffect,
useContext,
useRef
} from "react";
import { v4 as uuidv4 } from "uuid";
import styled from "styled-components";
import { WaxContext } from "wax-prosemirror-core";
import { DocumentHelpers } from "wax-prosemirror-utilities";
const SinlgeCommentRow = styled.div`
padding: 4px;
border-bottom: 1px solid #ffab20;
`;
export default ({ comment, activeView, user }) => {
const commentInput = useRef(null);
const [currentUser, setCurrentuser] = useState(user);
const [commentAnnotation, setCommentAnnotation] = useState(comment);
const [commentInputValue, setcommentInputValue] = useState("");
const { state, dispatch } = activeView;
const { attrs: { conversation } } = comment;
const handleKeyDown = event => {
if (event.key === "Enter" || event.which === 13) {
saveComment();
}
};
const saveComment = () => {
const { current: { value } } = commentInput;
const { tr, doc } = state;
const commentMark = state.schema.marks.comment;
const obj = { [user.username]: value };
commentAnnotation.attrs.conversation.push(obj);
const actualComment = DocumentHelpers.findMark(state, commentMark);
dispatch(
tr.addMark(
actualComment.from,
actualComment.to,
commentMark.create({
...((commentAnnotation && commentAnnotation.attrs) || {}),
conversation: commentAnnotation.attrs.conversation
})
)
);
setcommentInputValue("");
};
const updateCommentInputValue = () => {
const { current: { value } } = commentInput;
setcommentInputValue(value);
};
const commentInputReply = () => {
return (
<Fragment>
<input
type="text"
ref={commentInput}
placeholder="add a new comment"
onChange={updateCommentInputValue}
onKeyPress={handleKeyDown}
autoFocus
value={commentInputValue}
/>
<button onClick={saveComment}>Post</button>
<button>Cancel</button>
</Fragment>
);
};
return conversation.length === 0 ? (
<Fragment>{commentInputReply()}</Fragment>
) : (
<Fragment>
{conversation.map((singleComment, index) => {
return (
<SinlgeCommentRow key={uuidv4()}>{`${user.username} : ${
singleComment[user.username]
}`}</SinlgeCommentRow>
);
})}
{commentInputReply()}
</Fragment>
);
};
...@@ -9,6 +9,7 @@ import React, { ...@@ -9,6 +9,7 @@ import React, {
import { Transition } from "react-transition-group"; import { Transition } from "react-transition-group";
import styled from "styled-components"; import styled from "styled-components";
import { WaxContext } from "wax-prosemirror-core"; import { WaxContext } from "wax-prosemirror-core";
import Comment from "./Comment";
const CommentBoxStyled = styled.div` const CommentBoxStyled = styled.div`
display: flex; display: flex;
...@@ -37,11 +38,7 @@ export default ({ comment, view, top, dataBox }) => { ...@@ -37,11 +38,7 @@ export default ({ comment, view, top, dataBox }) => {
const { view: { main: { props: { user } } }, app, activeView } = useContext( const { view: { main: { props: { user } } }, app, activeView } = useContext(
WaxContext WaxContext
), ),
{ state, dispatch } = activeView,
commentInput = useRef(null),
[animate, setAnimate] = useState(false), [animate, setAnimate] = useState(false),
[commentAnnotation, setCommentAnnotation] = useState(comment),
[currentUser, setCurrentuser] = useState(user),
{ attrs: { id } } = comment, { attrs: { id } } = comment,
activeCommentPlugin = app.PmPlugins.get("activeComment"), activeCommentPlugin = app.PmPlugins.get("activeComment"),
activeComment = activeCommentPlugin.getState(activeView.state).comment; activeComment = activeCommentPlugin.getState(activeView.state).comment;
...@@ -52,32 +49,6 @@ export default ({ comment, view, top, dataBox }) => { ...@@ -52,32 +49,6 @@ export default ({ comment, view, top, dataBox }) => {
setAnimate(true); setAnimate(true);
}, []); }, []);
const handleKeyDown = event => {
if (event.key === "Enter" || event.which === 13) {
saveComment();
}
};
const saveComment = () => {
const { current: { value } } = commentInput;
const { tr, doc } = state;
const commentMark = state.schema.marks.comment;
const obj = { [user.username]: value };
commentAnnotation.attrs.conversation.push(obj);
dispatch(
tr.addMark(
commentAnnotation.pos,
commentAnnotation.pos + commentAnnotation.node.nodeSize,
commentMark.create({
...((commentAnnotation && commentAnnotation.attrs) || {}),
conversation: commentAnnotation.attrs.conversation
})
)
);
};
return ( return (
<Fragment> <Fragment>
<Transition in={animate} timeout={1000}> <Transition in={animate} timeout={1000}>
...@@ -88,17 +59,12 @@ export default ({ comment, view, top, dataBox }) => { ...@@ -88,17 +59,12 @@ export default ({ comment, view, top, dataBox }) => {
data-box={dataBox} data-box={dataBox}
active={active} active={active}
> >
<div> <Comment
<input comment={comment}
type="text" active={active}
ref={commentInput} activeView={activeView}
placeholder="add a new comment" user={user}
onKeyPress={handleKeyDown} />
autoFocus
/>
<button onClick={saveComment}>Post</button>
<button>Cancel</button>
</div>
</CommentBoxStyled> </CommentBoxStyled>
)} )}
</Transition> </Transition>
......
...@@ -19,7 +19,6 @@ const Button = styled.button` ...@@ -19,7 +19,6 @@ const Button = styled.button`
`; `;
const LinkComponent = ({ mark, setPosition, position }) => { const LinkComponent = ({ mark, setPosition, position }) => {
console.log(mark);
const href = mark ? mark.attrs.href : null, const href = mark ? mark.attrs.href : null,
linkMark = mark ? mark : null, linkMark = mark ? mark : null,
{ view: { main }, activeView } = useContext(WaxContext), { view: { main }, activeView } = useContext(WaxContext),
......
...@@ -156,7 +156,6 @@ const updateMarks = view => { ...@@ -156,7 +156,6 @@ const updateMarks = view => {
mark.type.name === "format_change" mark.type.name === "format_change"
) { ) {
mark.pos = node.pos; mark.pos = node.pos;
mark.node = node.node;
finalMarks.push(mark); finalMarks.push(mark);
} }
}); });
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror core", "description": "Wax prosemirror core",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror layouts", "description": "Wax prosemirror layouts",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
...@@ -10,6 +10,12 @@ export default css` ...@@ -10,6 +10,12 @@ export default css`
outline: none; outline: none;
} }
} }
.ProseMirror .wax-selection-marker {
background: #0a78ff;
color: white;
}
.ProseMirror footnote { .ProseMirror footnote {
font-size: 0; font-size: 0;
display: inline-block; display: inline-block;
...@@ -28,6 +34,7 @@ export default css` ...@@ -28,6 +34,7 @@ export default css`
font-size: 16px; font-size: 16px;
counter-increment: footnote; counter-increment: footnote;
} }
hr { hr {
padding: 2px 10px; padding: 2px 10px;
border: none; border: none;
......
...@@ -3,3 +3,4 @@ export { ...@@ -3,3 +3,4 @@ export {
} from "./src/trackChanges/TrackChangePlugin"; } from "./src/trackChanges/TrackChangePlugin";
export { default as ActiveComment } from "./src/comments/ActiveComment"; export { default as ActiveComment } from "./src/comments/ActiveComment";
export { default as WaxSelectionPlugin } from "./src/WaxSelectionPlugin";
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror plugins", "description": "Wax prosemirror plugins",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
import { Decoration, DecorationSet } from "prosemirror-view";
import { Plugin } from "prosemirror-state";
const WaxSelectionPlugin = new Plugin({
state: {
init(config, instance) {
return { deco: DecorationSet.empty };
},
apply(transaction, state, prevEditorState, editorState) {
const sel = transaction.curSelection;
if (sel) {
const decos = [
Decoration.inline(sel.$from.pos, sel.$to.pos, {
class: "wax-selection-marker"
})
];
const deco = DecorationSet.create(editorState.doc, decos);
return { deco };
}
return state;
}
},
props: {
decorations(state) {
if (state && this.getState(state)) {
return this.getState(state).deco;
}
return null;
}
}
});
export default WaxSelectionPlugin;
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror schema", "description": "Wax prosemirror schema",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror services", "description": "Wax prosemirror services",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror themes", "description": "Wax prosemirror themes",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"version": "0.0.8", "version": "0.0.8",
"description": "Wax prosemirror utilities", "description": "Wax prosemirror utilities",
"license": "MIT", "license": "MIT",
"main": "index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "BABEL_ENV=production rollup -c" "build": "BABEL_ENV=production rollup -c"
......
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