@manuscripts/article-editor 3.4.7 → 3.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/comments/CommentActions.js +11 -7
- package/dist/cjs/components/comments/CommentActions.js.map +1 -1
- package/dist/cjs/components/comments/CommentBody.js +11 -7
- package/dist/cjs/components/comments/CommentBody.js.map +1 -1
- package/dist/cjs/components/comments/CommentCard.js +163 -0
- package/dist/cjs/components/comments/CommentCard.js.map +1 -0
- package/dist/cjs/components/comments/CommentResolveButton.js +1 -1
- package/dist/cjs/components/comments/CommentThread.js +88 -88
- package/dist/cjs/components/comments/CommentThread.js.map +1 -1
- package/dist/cjs/components/comments/CommentsPanel.js +45 -10
- package/dist/cjs/components/comments/CommentsPanel.js.map +1 -1
- package/dist/cjs/components/comments/DeleteCommentConfirmation.js +115 -0
- package/dist/cjs/components/comments/DeleteCommentConfirmation.js.map +1 -0
- package/dist/cjs/components/comments/ReplyBox.js +121 -0
- package/dist/cjs/components/comments/ReplyBox.js.map +1 -0
- package/dist/cjs/lib/comments.js +26 -5
- package/dist/cjs/lib/comments.js.map +1 -1
- package/dist/es/components/comments/CommentActions.js +11 -7
- package/dist/es/components/comments/CommentActions.js.map +1 -1
- package/dist/es/components/comments/CommentBody.js +12 -8
- package/dist/es/components/comments/CommentBody.js.map +1 -1
- package/dist/es/components/comments/CommentCard.js +133 -0
- package/dist/es/components/comments/CommentCard.js.map +1 -0
- package/dist/es/components/comments/CommentResolveButton.js +1 -1
- package/dist/es/components/comments/CommentThread.js +91 -91
- package/dist/es/components/comments/CommentThread.js.map +1 -1
- package/dist/es/components/comments/CommentsPanel.js +47 -12
- package/dist/es/components/comments/CommentsPanel.js.map +1 -1
- package/dist/es/components/comments/DeleteCommentConfirmation.js +85 -0
- package/dist/es/components/comments/DeleteCommentConfirmation.js.map +1 -0
- package/dist/es/components/comments/ReplyBox.js +91 -0
- package/dist/es/components/comments/ReplyBox.js.map +1 -0
- package/dist/es/lib/comments.js +23 -3
- package/dist/es/lib/comments.js.map +1 -1
- package/dist/types/components/comments/CommentBody.d.ts +0 -1
- package/dist/types/components/comments/CommentCard.d.ts +26 -0
- package/dist/types/components/comments/CommentThread.d.ts +3 -2
- package/dist/types/components/comments/DeleteCommentConfirmation.d.ts +19 -0
- package/dist/types/components/comments/ReplyBox.d.ts +18 -0
- package/dist/types/lib/comments.d.ts +4 -3
- package/package.json +1 -1
@@ -1,105 +1,105 @@
|
|
1
|
-
import {
|
2
|
-
import React, { forwardRef, useState } from 'react';
|
1
|
+
import { TextButton, usePermissions } from '@manuscripts/style-guide';
|
2
|
+
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
3
3
|
import styled from 'styled-components';
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import { CommentBody } from './CommentBody';
|
4
|
+
import { commentsByTime } from '../../lib/comments';
|
5
|
+
import { CommentCard } from './CommentCard';
|
6
|
+
import { ReplyBox } from './ReplyBox';
|
8
7
|
const Container = styled.div `
|
9
|
-
padding:
|
10
|
-
background-color: ${(props) => (props.isSelected ? '#
|
11
|
-
border: 1px solid
|
12
|
-
border-left-width: 4px;
|
8
|
+
padding: 8px;
|
9
|
+
background-color: ${(props) => (props.isSelected ? '#fff' : '#fafafa')};
|
10
|
+
border: 1px solid #c9c9c9;
|
11
|
+
${(props) => props.isSelected && 'border-left-width: 4px'};
|
12
|
+
border-radius: 4px;
|
13
13
|
margin-bottom: 16px;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
flex: 1;
|
21
|
-
padding-left: 8px;
|
22
|
-
padding-right: 8px;
|
23
|
-
`;
|
24
|
-
const CommentAuthor = styled.div `
|
25
|
-
display: flex;
|
26
|
-
color: #353535;
|
27
|
-
font-weight: 400;
|
28
|
-
max-width: 200px;
|
29
|
-
white-space: nowrap;
|
30
|
-
overflow: hidden;
|
31
|
-
text-overflow: ellipsis;
|
32
|
-
width: 100%;
|
14
|
+
margin-left: 12px;
|
15
|
+
margin-right: 12px;
|
16
|
+
cursor: pointer;
|
17
|
+
.actions-icon {
|
18
|
+
visibility: ${(props) => (props.isSelected ? 'visible' : 'hidden')};
|
19
|
+
}
|
33
20
|
|
34
|
-
|
35
|
-
|
21
|
+
&:hover {
|
22
|
+
background-color: #fff;
|
23
|
+
|
24
|
+
.actions-icon {
|
25
|
+
visibility: visible;
|
26
|
+
}
|
36
27
|
}
|
37
28
|
`;
|
38
|
-
const
|
39
|
-
|
40
|
-
color: #
|
41
|
-
|
42
|
-
padding: 4px 8px;
|
43
|
-
margin-top: 16px;
|
44
|
-
margin-bottom: 16px;
|
29
|
+
const SeparatorLine = styled.div `
|
30
|
+
margin-bottom: 8px;
|
31
|
+
background-color: #c9c9c9;
|
32
|
+
height: 1px;
|
45
33
|
`;
|
46
|
-
const
|
47
|
-
|
48
|
-
line-height: 16px;
|
49
|
-
font-weight: 400;
|
50
|
-
color: #6e6e6e;
|
34
|
+
const Indented = styled.div `
|
35
|
+
padding-left: 16px;
|
51
36
|
`;
|
52
37
|
export const CommentThread = forwardRef((props, ref) => {
|
53
|
-
const {
|
38
|
+
const { thread, isSelected, onSelect, onSave, onDelete, insertCommentReply, } = props;
|
54
39
|
const can = usePermissions();
|
55
|
-
const
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
const handleSave = (contents) => {
|
74
|
-
onSave({
|
75
|
-
...tree.comment.node.attrs,
|
76
|
-
contents,
|
77
|
-
});
|
78
|
-
setEditing(false);
|
79
|
-
};
|
80
|
-
const handleCancel = () => {
|
81
|
-
setEditing(false);
|
82
|
-
if (tree.isNew) {
|
83
|
-
onDelete(tree.comment.node.attrs.id);
|
40
|
+
const { comment, isNew, replies } = thread;
|
41
|
+
const cardsRef = useRef(null);
|
42
|
+
const [showMore, setShowMore] = useState(false);
|
43
|
+
const [editingCommentId, setEditingCommentId] = useState(isNew ? comment.node.attrs.id : null);
|
44
|
+
useEffect(() => {
|
45
|
+
if (!isSelected) {
|
46
|
+
setEditingCommentId(null);
|
47
|
+
}
|
48
|
+
}, [isSelected]);
|
49
|
+
useEffect(() => {
|
50
|
+
if (cardsRef.current) {
|
51
|
+
const contentHeight = cardsRef.current.scrollHeight;
|
52
|
+
setShowMore(contentHeight > 280);
|
53
|
+
}
|
54
|
+
}, [comment, replies]);
|
55
|
+
const handleSelect = () => {
|
56
|
+
if (!isSelected) {
|
57
|
+
onSelect();
|
84
58
|
}
|
85
59
|
};
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
React.createElement(CommentActions, { comment: tree.comment, isResolveEnabled: isResolveEnabled, isActionsEnabled: isActionsEnabled, onDelete: () => onDelete(tree.comment.node.attrs.id), onEdit: handleEdit, toggleResolve: handleToggleResolve })),
|
102
|
-
tree.comment.node.attrs.originalText && (React.createElement(CommentTarget, null, tree.comment.node.attrs.originalText)),
|
103
|
-
React.createElement(CommentBody, { comment: tree.comment, isEditing: tree.isNew || isEditing, onSave: handleSave, onCancel: handleCancel, onSelect: onSelect })));
|
60
|
+
return (React.createElement(Container, { "data-cy": "comment", isSelected: isSelected, ref: ref, onClick: handleSelect },
|
61
|
+
React.createElement(CardsWrapper, { ref: cardsRef, isSelected: isSelected, showMore: showMore },
|
62
|
+
React.createElement(CommentCard, { comment: comment, isReply: false, numOfReplies: replies.length, isNew: isNew, isEndOfThread: !replies.length, editingCommentId: editingCommentId, setEditingCommentId: setEditingCommentId, onDelete: onDelete, onSave: onSave }),
|
63
|
+
replies.sort(commentsByTime).map((reply, index) => {
|
64
|
+
return (React.createElement("div", { key: reply.node.attrs.id },
|
65
|
+
index === 0 && React.createElement(SeparatorLine, null),
|
66
|
+
React.createElement(Indented, null,
|
67
|
+
index !== 0 && React.createElement(SeparatorLine, null),
|
68
|
+
React.createElement(CommentCard, { comment: reply, isReply: true, numOfReplies: 0, isNew: false, isEndOfThread: index === replies.length - 1, editingCommentId: editingCommentId, setEditingCommentId: setEditingCommentId, onDelete: onDelete, onSave: onSave }))));
|
69
|
+
})),
|
70
|
+
showMore && !isSelected && (React.createElement(React.Fragment, null,
|
71
|
+
React.createElement(SeparatorLine, null),
|
72
|
+
React.createElement(ButtonContainer, null,
|
73
|
+
React.createElement(ShowMore, { onClick: onSelect }, "Show more")))),
|
74
|
+
can.createComment && isSelected && editingCommentId === null && (React.createElement(ReplyBox, { insertCommentReply: insertCommentReply, commentID: comment.node.attrs.id }))));
|
104
75
|
});
|
76
|
+
const ButtonContainer = styled.div `
|
77
|
+
display: flex;
|
78
|
+
justify-content: center;
|
79
|
+
align-items: center;
|
80
|
+
`;
|
81
|
+
const ShowMore = styled(TextButton) `
|
82
|
+
cursor: pointer;
|
83
|
+
text-align: center;
|
84
|
+
margin-top: 6px;
|
85
|
+
color: #353535;
|
86
|
+
`;
|
87
|
+
const CardsWrapper = styled.div `
|
88
|
+
max-height: ${({ isSelected }) => (isSelected ? 'none' : '280px')};
|
89
|
+
position: relative;
|
90
|
+
${({ showMore, isSelected }) => showMore &&
|
91
|
+
!isSelected &&
|
92
|
+
`
|
93
|
+
overflow: hidden;
|
94
|
+
&:after {
|
95
|
+
content: '';
|
96
|
+
position: absolute;
|
97
|
+
bottom: 0;
|
98
|
+
left: 0;
|
99
|
+
right: 0;
|
100
|
+
height: 40px;
|
101
|
+
background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
|
102
|
+
}
|
103
|
+
`}
|
104
|
+
`;
|
105
105
|
//# sourceMappingURL=CommentThread.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CommentThread.js","sourceRoot":"","sources":["../../../../src/components/comments/CommentThread.tsx"],"names":[],"mappings":"AAYA,OAAO,
|
1
|
+
{"version":3,"file":"CommentThread.js","sourceRoot":"","sources":["../../../../src/components/comments/CommentThread.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACtE,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,cAAc,EAAU,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAA0B;;sBAEhC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;;IAEpE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,IAAI,wBAAwB;;;;;;;kBAOzC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;;;;;;;;;;CAUrE,CAAA;AACD,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAA;;;;CAI/B,CAAA;AACD,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAA;;CAE1B,CAAA;AAWD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CACrC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACb,MAAM,EACJ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,kBAAkB,GACnB,GAAG,KAAK,CAAA;IAET,MAAM,GAAG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C,CAAA;AAED,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;;;;;CAKlC,CAAA;AAED,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAG7B;gBACc,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;;IAE/D,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,CAC7B,QAAQ;IACR,CAAC,UAAU;IACX;;;;;;;;;;;GAWD;CACF,CAAA"}
|
@@ -9,13 +9,16 @@
|
|
9
9
|
*
|
10
10
|
* All portions of the code written by Atypon Systems LLC are Copyright (c) 2019 Atypon Systems LLC. All Rights Reserved.
|
11
11
|
*/
|
12
|
-
import {
|
12
|
+
import { commentsKey, isNodeComment, setCommentSelection, } from '@manuscripts/body-editor';
|
13
|
+
import { buildContribution } from '@manuscripts/json-schema';
|
13
14
|
import { CheckboxField, CheckboxLabel } from '@manuscripts/style-guide';
|
14
15
|
import { skipTracking } from '@manuscripts/track-changes-plugin';
|
16
|
+
import { generateNodeID, schema } from '@manuscripts/transform';
|
15
17
|
import { NodeSelection, TextSelection } from 'prosemirror-state';
|
18
|
+
import { findChildrenByType } from 'prosemirror-utils';
|
16
19
|
import React, { useCallback, useMemo, useState } from 'react';
|
17
20
|
import styled from 'styled-components';
|
18
|
-
import {
|
21
|
+
import { buildThreads } from '../../lib/comments';
|
19
22
|
import { useStore } from '../../store';
|
20
23
|
import { CommentsPlaceholder } from './CommentsPlaceholder';
|
21
24
|
import { CommentThread } from './CommentThread';
|
@@ -34,14 +37,17 @@ const scrollIntoView = (element) => {
|
|
34
37
|
}
|
35
38
|
};
|
36
39
|
export const CommentsPanel = () => {
|
37
|
-
const [{ view, newCommentID, selectedCommentKey }] = useStore((state) => ({
|
40
|
+
const [{ view, newCommentID, selectedCommentKey, user, doc }] = useStore((state) => ({
|
38
41
|
view: state.view,
|
42
|
+
doc: state.doc,
|
39
43
|
newCommentID: state.newCommentID,
|
40
44
|
selectedCommentKey: state.selectedCommentKey,
|
45
|
+
user: state.user,
|
41
46
|
}));
|
42
47
|
const [showResolved, setShowResolved] = useState(true);
|
43
|
-
const comments = useMemo(() => view?.state ? commentsKey.getState(view.state)?.comments : undefined, [view?.state]
|
44
|
-
|
48
|
+
const comments = useMemo(() => view?.state ? commentsKey.getState(view.state)?.comments : undefined, [view?.state, doc] // eslint-disable-line react-hooks/exhaustive-deps
|
49
|
+
);
|
50
|
+
const threads = useMemo(() => (comments ? buildThreads([...comments.values()], newCommentID) : []), [comments, newCommentID]);
|
45
51
|
const selectedRef = useCallback((e) => {
|
46
52
|
if (e) {
|
47
53
|
scrollIntoView(e);
|
@@ -66,6 +72,25 @@ export const CommentsPanel = () => {
|
|
66
72
|
view.focus();
|
67
73
|
view.dispatch(tr);
|
68
74
|
};
|
75
|
+
const insertCommentReply = (target, contents) => {
|
76
|
+
if (!view) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
const attrs = {
|
80
|
+
id: generateNodeID(schema.nodes.comment),
|
81
|
+
contents,
|
82
|
+
target,
|
83
|
+
contributions: [buildContribution(user._id)],
|
84
|
+
resolved: false,
|
85
|
+
};
|
86
|
+
const comment = view.state.schema.nodes.comment.create(attrs);
|
87
|
+
const comments = findChildrenByType(view.state.doc, view.state.schema.nodes.comments)[0];
|
88
|
+
if (comments) {
|
89
|
+
const pos = comments.pos + 1;
|
90
|
+
const tr = view.state.tr.insert(pos, comment);
|
91
|
+
view.dispatch(skipTracking(tr));
|
92
|
+
}
|
93
|
+
};
|
69
94
|
const handleSave = (attrs) => {
|
70
95
|
const comment = comments?.get(attrs.id);
|
71
96
|
if (!comment || !view) {
|
@@ -73,9 +98,19 @@ export const CommentsPanel = () => {
|
|
73
98
|
}
|
74
99
|
const tr = view.state.tr;
|
75
100
|
tr.setNodeMarkup(comment.pos, undefined, attrs);
|
76
|
-
clearCommentSelection(tr);
|
77
101
|
view.dispatch(skipTracking(tr));
|
78
102
|
};
|
103
|
+
const deleteHighlightMarkers = (id, tr) => {
|
104
|
+
const nodes = findChildrenByType(doc, schema.nodes.highlight_marker);
|
105
|
+
// Sort nodes in reverse order by position to ensure deletions do not affect the positions of subsequent nodes
|
106
|
+
nodes.sort((a, b) => b.pos - a.pos);
|
107
|
+
nodes.forEach(({ node, pos }) => {
|
108
|
+
const attrs = node.attrs;
|
109
|
+
if (attrs.id === id) {
|
110
|
+
tr.delete(pos, pos + node.nodeSize);
|
111
|
+
}
|
112
|
+
});
|
113
|
+
};
|
79
114
|
const handleDelete = (id) => {
|
80
115
|
const comment = comments?.get(id);
|
81
116
|
if (!comment || !view) {
|
@@ -83,16 +118,16 @@ export const CommentsPanel = () => {
|
|
83
118
|
}
|
84
119
|
const tr = view.state.tr;
|
85
120
|
tr.delete(comment.pos, comment.pos + comment.node.nodeSize);
|
86
|
-
|
121
|
+
deleteHighlightMarkers(id, tr);
|
87
122
|
view.dispatch(skipTracking(tr));
|
88
123
|
};
|
89
|
-
const isSelected = (
|
90
|
-
return
|
124
|
+
const isSelected = (thread) => {
|
125
|
+
return thread && selectedCommentKey === thread.comment.key;
|
91
126
|
};
|
92
127
|
if (!view) {
|
93
128
|
return null;
|
94
129
|
}
|
95
|
-
if (!
|
130
|
+
if (!threads.length) {
|
96
131
|
return React.createElement(CommentsPlaceholder, null);
|
97
132
|
}
|
98
133
|
return (React.createElement(React.Fragment, null,
|
@@ -100,8 +135,8 @@ export const CommentsPanel = () => {
|
|
100
135
|
React.createElement(CheckboxLabel, null,
|
101
136
|
React.createElement(CheckboxField, { name: 'show-resolved', checked: showResolved, onChange: (e) => setShowResolved(e.target.checked) }),
|
102
137
|
React.createElement(CheckboxLabelText, null, "See resolved"))),
|
103
|
-
|
138
|
+
threads
|
104
139
|
.filter((c) => showResolved || !c.comment.node.attrs.resolved)
|
105
|
-
.map((c, i, a) => (React.createElement(CommentThread, { key: c.comment.node.attrs.id, ref: isSelected(c) && !isSelected(a[i - 1]) ? selectedRef : null,
|
140
|
+
.map((c, i, a) => (React.createElement(CommentThread, { key: c.comment.node.attrs.id, ref: isSelected(c) && !isSelected(a[i - 1]) ? selectedRef : null, thread: c, isSelected: isSelected(c), onSelect: () => setSelectedComment(c.comment), onSave: handleSave, onDelete: handleDelete, insertCommentReply: insertCommentReply })))));
|
106
141
|
};
|
107
142
|
//# sourceMappingURL=CommentsPanel.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CommentsPanel.js","sourceRoot":"","sources":["../../../../src/components/comments/CommentsPanel.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,
|
1
|
+
{"version":3,"file":"CommentsPanel.js","sourceRoot":"","sources":["../../../../src/components/comments/CommentsPanel.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAGL,WAAW,EAGX,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAe,MAAM,mBAAmB,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7D,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,OAAO,EAAE,YAAY,EAAU,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;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U,EAClB,QAAQ,EAAE,YAAY,EACtB,kBAAkB,EAAE,kBAAkB,GACtC,CACH,CAAC,CACH,CACJ,CAAA;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/*!
|
2
|
+
* The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://mpapp-public.gitlab.io/manuscripts-frontend/LICENSE. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
|
3
|
+
*
|
4
|
+
* Software distributed under the License is distributed on an “AS IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
|
5
|
+
*
|
6
|
+
* The Original Code is manuscripts-frontend.
|
7
|
+
*
|
8
|
+
* The Original Developer is the Initial Developer. The Initial Developer of the Original Code is Atypon Systems LLC.
|
9
|
+
*
|
10
|
+
* All portions of the code written by Atypon Systems LLC are Copyright (c) 2024 Atypon Systems LLC. All Rights Reserved.
|
11
|
+
*/
|
12
|
+
import { AttentionOrangeIcon, ButtonGroup, PrimaryButton, SecondaryButton, } from '@manuscripts/style-guide';
|
13
|
+
import React, { useEffect, useRef } from 'react';
|
14
|
+
import styled from 'styled-components';
|
15
|
+
const MessageContainer = styled.div `
|
16
|
+
display: flex;
|
17
|
+
align-items: center;
|
18
|
+
flex-grow: 1;
|
19
|
+
|
20
|
+
svg {
|
21
|
+
padding-left: 14px;
|
22
|
+
}
|
23
|
+
`;
|
24
|
+
const CancelButton = styled(SecondaryButton) `
|
25
|
+
padding: 4px ${(props) => props.theme.grid.unit * 3}px;
|
26
|
+
font-size: 14px;
|
27
|
+
`;
|
28
|
+
const DeleteButton = styled(PrimaryButton) `
|
29
|
+
padding: 4px ${(props) => props.theme.grid.unit * 3}px;
|
30
|
+
margin-right: 16px;
|
31
|
+
font-size: 14px;
|
32
|
+
`;
|
33
|
+
const Message = styled.div `
|
34
|
+
font-weight: 700;
|
35
|
+
color: #000;
|
36
|
+
font-size: 14px;
|
37
|
+
line-height: 16px;
|
38
|
+
margin: 0 8px;
|
39
|
+
`;
|
40
|
+
const DeleteConfirmation = styled.div `
|
41
|
+
border-top: 1px solid #e2e2e2;
|
42
|
+
border-bottom: 1px solid #e2e2e2;
|
43
|
+
box-shadow: 0px 4px 9px 0px rgba(0, 0, 0, 0.3);
|
44
|
+
position: absolute;
|
45
|
+
top: -9px;
|
46
|
+
left: ${(props) => (props.isReply ? '-24px' : '-8px')};
|
47
|
+
right: -8px;
|
48
|
+
bottom: -9px;
|
49
|
+
opacity: 0.95;
|
50
|
+
display: flex;
|
51
|
+
align-items: center;
|
52
|
+
justify-content: center;
|
53
|
+
background: #fafafa;
|
54
|
+
z-index: 10;
|
55
|
+
`;
|
56
|
+
const Buttons = styled(ButtonGroup) `
|
57
|
+
& button:not(:last-of-type) {
|
58
|
+
margin-right: 4px;
|
59
|
+
}
|
60
|
+
`;
|
61
|
+
export const DeleteCommentConfirmation = ({ isReply, onCancel, onConfirm }) => {
|
62
|
+
const deleteConfirmationRef = useRef(null);
|
63
|
+
useEffect(() => {
|
64
|
+
const handleClickOutside = (e) => {
|
65
|
+
if (e.target &&
|
66
|
+
deleteConfirmationRef.current &&
|
67
|
+
!deleteConfirmationRef.current.contains(e.target) &&
|
68
|
+
!e.target.closest('.delete-button')) {
|
69
|
+
onCancel();
|
70
|
+
}
|
71
|
+
};
|
72
|
+
document.addEventListener('click', handleClickOutside);
|
73
|
+
return () => {
|
74
|
+
document.removeEventListener('click', handleClickOutside);
|
75
|
+
};
|
76
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
77
|
+
return (React.createElement(DeleteConfirmation, { isReply: isReply, ref: deleteConfirmationRef },
|
78
|
+
React.createElement(MessageContainer, null,
|
79
|
+
React.createElement(AttentionOrangeIcon, null),
|
80
|
+
React.createElement(Message, null, "Delete this comment?")),
|
81
|
+
React.createElement(Buttons, null,
|
82
|
+
React.createElement(CancelButton, { onClick: onCancel }, "Cancel"),
|
83
|
+
React.createElement(DeleteButton, { onClick: onConfirm }, "Delete"))));
|
84
|
+
};
|
85
|
+
//# sourceMappingURL=DeleteCommentConfirmation.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"DeleteCommentConfirmation.js","sourceRoot":"","sources":["../../../../src/components/comments/DeleteCommentConfirmation.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,MAAM,MAAM,mBAAmB,CAAA;AAEtC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;CAQlC,CAAA;AAED,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;iBAC3B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;;CAEpD,CAAA;AACD,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;iBACzB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;;;CAGpD,CAAA;AACD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;CAMzB,CAAA;AAED,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAuB;;;;;;UAMlD,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;;;;;;;;;CAStD,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;;;;CAIlC,CAAA;AAQD,MAAM,CAAC,MAAM,yBAAyB,GAElC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IACvC,MAAM,qBAAqB,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;IAE1D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,kBAAkB,GAAG,CAAC,CAAa,EAAE,EAAE;YAC3C,IACE,CAAC,CAAC,MAAM;gBACR,qBAAqB,CAAC,OAAO;gBAC7B,CAAC,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAqB,CAAC;gBAChE,CAAE,CAAC,CAAC,MAAsB,CAAC,OAAO,CAAC,gBAAgB,CAAC,EACpD;gBACA,QAAQ,EAAE,CAAA;aACX;QACH,CAAC,CAAA;QACD,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;QACtD,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;QAC3D,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC,kDAAkD;IAEzD,OAAO,CACL,oBAAC,kBAAkB,IAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,qBAAqB;QAC9D,oBAAC,gBAAgB;YACf,oBAAC,mBAAmB,OAAG;YACvB,oBAAC,OAAO,+BAA+B,CACtB;QACnB,oBAAC,OAAO;YACN,oBAAC,YAAY,IAAC,OAAO,EAAE,QAAQ,aAAuB;YACtD,oBAAC,YAAY,IAAC,OAAO,EAAE,SAAS,aAAuB,CAC/C,CACS,CACtB,CAAA;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/*!
|
2
|
+
* The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://mpapp-public.gitlab.io/manuscripts-frontend/LICENSE. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
|
3
|
+
*
|
4
|
+
* Software distributed under the License is distributed on an “AS IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
|
5
|
+
*
|
6
|
+
* The Original Code is manuscripts-frontend.
|
7
|
+
*
|
8
|
+
* The Original Developer is the Initial Developer. The Initial Developer of the Original Code is Atypon Systems LLC.
|
9
|
+
*
|
10
|
+
* All portions of the code written by Atypon Systems LLC are Copyright (c) 2024 Atypon Systems LLC. All Rights Reserved.
|
11
|
+
*/
|
12
|
+
import { ButtonGroup, PrimaryButton, TertiaryButton, } from '@manuscripts/style-guide';
|
13
|
+
import React, { useMemo, useRef, useState } from 'react';
|
14
|
+
import styled from 'styled-components';
|
15
|
+
export const ReplyBox = ({ insertCommentReply, commentID, }) => {
|
16
|
+
const [isTextBoxFocused, setIsTextBoxFocused] = useState(false);
|
17
|
+
const [value, setValue] = useState('');
|
18
|
+
const replyRef = useRef(null);
|
19
|
+
const handleFocus = () => setIsTextBoxFocused(true);
|
20
|
+
const reply = () => {
|
21
|
+
if (replyRef.current) {
|
22
|
+
insertCommentReply(commentID, replyRef.current.value);
|
23
|
+
setValue('');
|
24
|
+
replyRef.current.value = '';
|
25
|
+
replyRef.current.style.height = '30px'; // Reset the height
|
26
|
+
}
|
27
|
+
};
|
28
|
+
const handleCancel = () => {
|
29
|
+
setIsTextBoxFocused(false);
|
30
|
+
setValue('');
|
31
|
+
if (replyRef.current) {
|
32
|
+
replyRef.current.value = '';
|
33
|
+
replyRef.current.style.height = '30px'; // Reset the height
|
34
|
+
}
|
35
|
+
};
|
36
|
+
const disableSaveButton = useMemo(() => !value.length, [value]);
|
37
|
+
const onTextChange = (e) => {
|
38
|
+
setValue(e.target.value);
|
39
|
+
if (replyRef.current) {
|
40
|
+
replyRef.current.style.height = '30px'; // Reset the height
|
41
|
+
replyRef.current.style.height = `${Math.min(replyRef.current.scrollHeight, 55)}px`; // Set the height based on content
|
42
|
+
}
|
43
|
+
};
|
44
|
+
return (React.createElement(React.Fragment, null,
|
45
|
+
React.createElement(TextBox, { "data-cy": "reply", placeholder: "Reply...", ref: replyRef, onChange: onTextChange, onFocus: handleFocus }),
|
46
|
+
isTextBoxFocused && (React.createElement(Actions, { "data-cy": "reply-actions" },
|
47
|
+
React.createElement(TertiaryButton, { onClick: handleCancel }, "Cancel"),
|
48
|
+
React.createElement(PrimaryButton, { onClick: reply, disabled: disableSaveButton }, "Reply")))));
|
49
|
+
};
|
50
|
+
const TextBox = styled.textarea `
|
51
|
+
cursor: text;
|
52
|
+
font-family: ${(props) => props.theme.font.family.sans};
|
53
|
+
color: ${(props) => props.theme.colors.text.primary};
|
54
|
+
margin: ${(props) => props.theme.grid.unit * 2}px 0;
|
55
|
+
resize: none;
|
56
|
+
|
57
|
+
width: 100%;
|
58
|
+
|
59
|
+
height: 30px;
|
60
|
+
max-height: 55px;
|
61
|
+
|
62
|
+
outline: 0;
|
63
|
+
border: 1px solid #e2e2e2;
|
64
|
+
border-radius: 6px;
|
65
|
+
|
66
|
+
&:focus {
|
67
|
+
background: #f2fbfc;
|
68
|
+
border: 1px solid #bce7f6;
|
69
|
+
border-radius: 6px;
|
70
|
+
}
|
71
|
+
|
72
|
+
box-sizing: border-box;
|
73
|
+
padding: 3px 16px 3px 16px;
|
74
|
+
font-style: normal;
|
75
|
+
font-weight: 400;
|
76
|
+
font-size: 14px;
|
77
|
+
line-height: 24px;
|
78
|
+
overflow: hidden;
|
79
|
+
`;
|
80
|
+
const Actions = styled(ButtonGroup) `
|
81
|
+
& button:not(:last-of-type) {
|
82
|
+
margin-right: 4px;
|
83
|
+
}
|
84
|
+
& ${TertiaryButton} {
|
85
|
+
&:hover {
|
86
|
+
background-color: inherit !important;
|
87
|
+
border-color: transparent !important;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
`;
|
91
|
+
//# sourceMappingURL=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,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO;YACzC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;CAyB/C,CAAA;AAED,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;;;;MAI7B,cAAc;;;;;;CAMnB,CAAA"}
|
package/dist/es/lib/comments.js
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
/*!
|
2
|
+
* The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://mpapp-public.gitlab.io/manuscripts-frontend/LICENSE. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
|
3
|
+
*
|
4
|
+
* Software distributed under the License is distributed on an “AS IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
|
5
|
+
*
|
6
|
+
* The Original Code is manuscripts-frontend.
|
7
|
+
*
|
8
|
+
* The Original Developer is the Initial Developer. The Initial Developer of the Original Code is Atypon Systems LLC.
|
9
|
+
*
|
10
|
+
* All portions of the code written by Atypon Systems LLC are Copyright (c) 2024 Atypon Systems LLC. All Rights Reserved.
|
11
|
+
*/
|
12
|
+
import { isReply } from '@manuscripts/body-editor';
|
1
13
|
export const getAuthorID = (comment) => {
|
2
14
|
const contributions = comment.node.attrs.contributions;
|
3
15
|
if (!contributions?.length) {
|
@@ -5,11 +17,14 @@ export const getAuthorID = (comment) => {
|
|
5
17
|
}
|
6
18
|
return contributions[0].profileID;
|
7
19
|
};
|
8
|
-
export const
|
9
|
-
return comments
|
20
|
+
export const buildThreads = (comments, newCommentID) => {
|
21
|
+
return comments
|
22
|
+
.filter((c) => !isReply(c)) // Filter out replies
|
23
|
+
.map((c) => ({
|
10
24
|
comment: c,
|
11
25
|
isNew: newCommentID === c.node.attrs.id,
|
12
|
-
|
26
|
+
replies: comments.filter((reply) => reply.node.attrs.target === c.node.attrs.id // Find replies for each comment
|
27
|
+
),
|
13
28
|
}));
|
14
29
|
};
|
15
30
|
export const buildAuthorName = (user) => {
|
@@ -20,4 +35,9 @@ export const buildAuthorName = (user) => {
|
|
20
35
|
.filter(Boolean)
|
21
36
|
.join(' ');
|
22
37
|
};
|
38
|
+
export const commentsByTime = (a, b) => {
|
39
|
+
const aTimestamp = a.node.attrs.contributions?.[0].timestamp || 0;
|
40
|
+
const bTimestamp = b.node.attrs.contributions?.[0].timestamp || 0;
|
41
|
+
return aTimestamp - bTimestamp;
|
42
|
+
};
|
23
43
|
//# sourceMappingURL=comments.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../../../src/lib/comments.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../../../src/lib/comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAW,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAS3D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC9C,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAA;IACtD,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE;QAC1B,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACnC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,QAAmB,EACnB,YAAqB,EACX,EAAE;IACZ,OAAO,QAAQ;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,qBAAqB;SAChD,GAAG,CAAC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