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

new comment discussion structure

parent 394bb22c
No related branches found
No related tags found
1 merge request!130new comment discussion structure
This commit is part of merge request !130. Comments created here will be created in the context of that merge request.
...@@ -6,6 +6,6 @@ const { prettier } = require('@coko/lint'); ...@@ -6,6 +6,6 @@ const { prettier } = require('@coko/lint');
* prettier.semi = true * prettier.semi = true
* *
*/ */
prettier.printWidth = 120;
prettier.semi = true; prettier.semi = true;
module.exports = prettier; module.exports = prettier;
...@@ -47,9 +47,9 @@ const Editoria = () => ( ...@@ -47,9 +47,9 @@ const Editoria = () => (
autoFocus autoFocus
placeholder="Type Something..." placeholder="Type Something..."
fileUpload={file => renderImage(file)} fileUpload={file => renderImage(file)}
value={`<p class="paragraph">This is the first paragraph</p><p class="paragraph">This is the <span class="comment" data-id="203df89d-294b-4e35-b48c-408e135ee8fa" data-conversation="[{&quot;demo&quot;:&quot;comment&quot;}]" data-viewid="main" data-group="main">second</span> paragraph</p><p class="author">This is an author</p>`} value={`<p class="paragraph">This is the first paragraph</p><p class="paragraph">This is the second paragraph</p><p class="author">This is an author</p>`}
layout={EditoriaLayout} layout={EditoriaLayout}
TrackChange // TrackChange
// onChange={source => console.log(source)} // onChange={source => console.log(source)}
user={user} user={user}
/> />
......
import { emDash, ellipsis } from "prosemirror-inputrules"; import { emDash, ellipsis } from 'prosemirror-inputrules';
import { columnResizing, tableEditing } from "prosemirror-tables"; import { columnResizing, tableEditing } from 'prosemirror-tables';
import { import {
AnnotationToolGroupService, AnnotationToolGroupService,
ImageService, ImageService,
...@@ -20,37 +20,37 @@ import { ...@@ -20,37 +20,37 @@ import {
NoteService, NoteService,
NoteToolGroupService, NoteToolGroupService,
TrackChangeService, TrackChangeService,
CommentsService CommentsService,
} from "wax-prosemirror-services"; } from 'wax-prosemirror-services';
import { WaxSelectionPlugin } from "wax-prosemirror-plugins"; import { WaxSelectionPlugin } from 'wax-prosemirror-plugins';
import invisibles, { import invisibles, {
space, space,
hardBreak, hardBreak,
paragraph paragraph,
} from "@guardian/prosemirror-invisibles"; } from '@guardian/prosemirror-invisibles';
export default { export default {
MenuService: [ MenuService: [
{ {
templateArea: "topBar", templateArea: 'topBar',
toolGroups: [ toolGroups: [
"Base", 'Base',
{ {
name: "Annotations", name: 'Annotations',
more: ["Superscript", "Subscript", "SmallCaps"] more: ['Superscript', 'Subscript', 'SmallCaps'],
}, },
"Notes", 'Notes',
"Lists", 'Lists',
"Images", 'Images',
"Tables" 'Tables',
] ],
}, },
{ {
templateArea: "leftSideBar", templateArea: 'leftSideBar',
toolGroups: ["Display", "Text"] toolGroups: ['Display', 'Text'],
} },
], ],
RulesService: [emDash, ellipsis], RulesService: [emDash, ellipsis],
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
columnResizing(), columnResizing(),
tableEditing(), tableEditing(),
invisibles([hardBreak()]), invisibles([hardBreak()]),
WaxSelectionPlugin WaxSelectionPlugin,
], ],
// Always load first CommentsService and LinkService, // Always load first CommentsService and LinkService,
...@@ -85,6 +85,6 @@ export default { ...@@ -85,6 +85,6 @@ export default {
new ImageToolGroupService(), new ImageToolGroupService(),
new AnnotationToolGroupService(), new AnnotationToolGroupService(),
new NoteToolGroupService(), new NoteToolGroupService(),
new ListToolGroupService() new ListToolGroupService(),
] ],
}; };
...@@ -14,7 +14,10 @@ export default ({ comment, activeView, user }) => { ...@@ -14,7 +14,10 @@ export default ({ comment, activeView, user }) => {
const [commentAnnotation, setCommentAnnotation] = useState(comment); const [commentAnnotation, setCommentAnnotation] = useState(comment);
const [commentInputValue, setcommentInputValue] = useState(''); const [commentInputValue, setcommentInputValue] = useState('');
const { state, dispatch } = activeView; const { state, dispatch } = activeView;
const allCommentsWithSameId = DocumentHelpers.findAllMarksWithSameId(state, comment); const allCommentsWithSameId = DocumentHelpers.findAllMarksWithSameId(
state,
comment,
);
const { const {
attrs: { conversation }, attrs: { conversation },
} = comment; } = comment;
...@@ -34,7 +37,12 @@ export default ({ comment, activeView, user }) => { ...@@ -34,7 +37,12 @@ export default ({ comment, activeView, user }) => {
} = commentInput; } = commentInput;
const { tr, doc } = state; const { tr, doc } = state;
const obj = { [user.username]: value }; const obj = {
content: value,
displayName: user.username,
timestamp: Math.floor(Date.now() / 300000),
};
commentAnnotation.attrs.conversation.push(obj); commentAnnotation.attrs.conversation.push(obj);
allCommentsWithSameId.forEach(singleComment => { allCommentsWithSameId.forEach(singleComment => {
...@@ -79,12 +87,17 @@ export default ({ comment, activeView, user }) => { ...@@ -79,12 +87,17 @@ export default ({ comment, activeView, user }) => {
let minPos = comment.pos; let minPos = comment.pos;
allCommentsWithSameId.forEach(singleComment => { allCommentsWithSameId.forEach(singleComment => {
const markPosition = DocumentHelpers.findMarkPosition(activeView, singleComment.pos, 'comment'); const markPosition = DocumentHelpers.findMarkPosition(
activeView,
singleComment.pos,
'comment',
);
if (markPosition.from < minPos) minPos = markPosition.from; if (markPosition.from < minPos) minPos = markPosition.from;
if (markPosition.to > maxPos) maxPos = markPosition.to; if (markPosition.to > maxPos) maxPos = markPosition.to;
}); });
if (allCommentsWithSameId.length > 1) maxPos += last(allCommentsWithSameId).node.nodeSize; if (allCommentsWithSameId.length > 1)
maxPos += last(allCommentsWithSameId).node.nodeSize;
dispatch(state.tr.removeMark(minPos, maxPos, commentMark)); dispatch(state.tr.removeMark(minPos, maxPos, commentMark));
activeView.focus(); activeView.focus();
}; };
...@@ -121,7 +134,9 @@ export default ({ comment, activeView, user }) => { ...@@ -121,7 +134,9 @@ export default ({ comment, activeView, user }) => {
<> <>
{conversation.map((singleComment, index) => { {conversation.map((singleComment, index) => {
return ( return (
<SinlgeCommentRow key={uuidv4()}>{`${user.username} : ${singleComment[user.username]}`}</SinlgeCommentRow> <SinlgeCommentRow key={uuidv4()}>
{`${singleComment.displayName} : ${singleComment.content}`}
</SinlgeCommentRow>
); );
})} })}
{commentInputReply()} {commentInputReply()}
......
import { Decoration, DecorationSet } from "prosemirror-view"; import { Decoration, DecorationSet } from 'prosemirror-view';
import { Plugin } from "prosemirror-state"; import { Plugin } from 'prosemirror-state';
const WaxSelectionPlugin = new Plugin({ const WaxSelectionPlugin = new Plugin({
state: { state: {
...@@ -8,18 +8,26 @@ const WaxSelectionPlugin = new Plugin({ ...@@ -8,18 +8,26 @@ const WaxSelectionPlugin = new Plugin({
}, },
apply(transaction, state, prevEditorState, editorState) { apply(transaction, state, prevEditorState, editorState) {
const sel = transaction.curSelection; const sel = transaction.curSelection;
if (sel) {
// TODO fix the selection when a note is present.
let flag = false;
const difference = sel.$to.pos - sel.$from.pos;
editorState.doc.nodesBetween(sel.$from.pos, sel.$to.pos, (node, from) => {
if (node.type.name === 'footnote') flag = true;
});
if (sel && !flag) {
const decos = [ const decos = [
Decoration.inline(sel.$from.pos, sel.$to.pos, { Decoration.inline(sel.$from.pos, sel.$to.pos, {
class: "wax-selection-marker" class: 'wax-selection-marker',
}) }),
]; ];
const deco = DecorationSet.create(editorState.doc, decos); const deco = DecorationSet.create(editorState.doc, decos);
return { deco }; return { deco };
} }
return state; return state;
} },
}, },
props: { props: {
decorations(state) { decorations(state) {
...@@ -27,8 +35,8 @@ const WaxSelectionPlugin = new Plugin({ ...@@ -27,8 +35,8 @@ const WaxSelectionPlugin = new Plugin({
return this.getState(state).deco; return this.getState(state).deco;
} }
return null; return null;
} },
} },
}); });
export default WaxSelectionPlugin; export default WaxSelectionPlugin;
export { default as Service } from './src/Service';
export { default as componentPlugin } from './src/LayoutService/components/componentPlugin'; export { default as componentPlugin } from './src/LayoutService/components/componentPlugin';
export { default as LayoutService } from './src/LayoutService/LayoutService'; export { default as LayoutService } from './src/LayoutService/LayoutService';
export { default as MenuService } from './src/MenuService/MenuService'; export { default as MenuService } from './src/MenuService/MenuService';
......
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