@seafile/sdoc-editor 1.0.116 → 1.0.118

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.
@@ -91,7 +91,6 @@ const CommentEditor = _ref => {
91
91
  updateContent && updateContent(value);
92
92
  }, [content, insertContent, updateContent]);
93
93
  const onSubmit = (0, _react.useCallback)(event => {
94
- if (!_slateReact.ReactEditor.isFocused(editor)) return;
95
94
  event && event.stopPropagation();
96
95
  const mdString = (0, _slateToMd.default)(editor.children);
97
96
  updateValue(mdString);
@@ -102,13 +101,17 @@ const CommentEditor = _ref => {
102
101
  _slate.Transforms.select(editor, _slate.Editor.start(editor, []));
103
102
  updateGlobalCommentContent && updateGlobalCommentContent(null);
104
103
  }, [editor, updateValue, addParticipants, userInfo.username, placeholder, updateGlobalCommentContent]);
104
+ const onSubmitByEnterKey = (0, _react.useCallback)(event => {
105
+ if (!_slateReact.ReactEditor.isFocused(editor)) return;
106
+ onSubmit(event);
107
+ }, [editor, onSubmit]);
105
108
  (0, _react.useEffect)(() => {
106
109
  const eventBus = _eventBus.default.getInstance();
107
- const unsubscribePostComment = eventBus.subscribe(_constants2.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmit);
110
+ const unsubscribePostComment = eventBus.subscribe(_constants2.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmitByEnterKey);
108
111
  return () => {
109
112
  unsubscribePostComment();
110
113
  };
111
- }, [onSubmit]);
114
+ }, [onSubmitByEnterKey]);
112
115
  const onCancel = (0, _react.useCallback)(event => {
113
116
  event.stopPropagation();
114
117
  const {
@@ -18,36 +18,48 @@ var _constants = require("../constants");
18
18
  const CommentItemCollapseWrapper = _ref => {
19
19
  let {
20
20
  element,
21
- latestComment,
22
21
  topLevelComment,
22
+ latestReply,
23
23
  editor,
24
- commentCount,
24
+ replyCount,
25
25
  setCurrentCommentGroup,
26
26
  t
27
27
  } = _ref;
28
- const [editorContent, setEditorContent] = (0, _react.useState)('');
28
+ const scrollRef = (0, _react.useRef)(document.querySelector('.sdoc-scroll-container'));
29
29
  const {
30
30
  notificationsInfo
31
31
  } = (0, _notificationHooks.useNotificationContext)();
32
- const scrollRef = (0, _react.useRef)(document.querySelector('.sdoc-scroll-container'));
33
- const isUnseen = notificationsInfo.notifications_map[`sdoc_notification_${latestComment.id}`] ? true : false;
32
+ const [commentContent, setCommentContent] = (0, _react.useState)('');
33
+ const [replyContent, setReplyContent] = (0, _react.useState)('');
34
+ const isUnseen = notificationsInfo.notifications_map[`sdoc_notification_${topLevelComment.id}`] ? true : false;
34
35
  (0, _react.useEffect)(() => {
35
- let mdString = '';
36
- if (latestComment.reply === 'True') {
37
- mdString = t('Mark_as_Resolved');
38
- } else if (latestComment.reply === 'False') {
39
- mdString = t('Resubmitted');
40
- } else if (latestComment.reply) {
41
- mdString = latestComment.reply;
42
- } else {
43
- mdString = latestComment.comment;
44
- }
45
- transferHtml(mdString);
46
- }, [latestComment.comment, latestComment.reply, t]);
47
- const transferHtml = async mdString => {
48
- const htmlString = await _mdToHtml.default.process(mdString);
49
- setEditorContent(String(htmlString));
50
- };
36
+ const initCommentContent = async () => {
37
+ const htmlString = await _mdToHtml.default.process(topLevelComment.comment);
38
+ setCommentContent(String(htmlString));
39
+ };
40
+ initCommentContent();
41
+ }, [topLevelComment.comment]);
42
+ (0, _react.useEffect)(() => {
43
+ const initReplyContent = async () => {
44
+ if (!latestReply) {
45
+ setReplyContent('');
46
+ return;
47
+ }
48
+ let mdString = '';
49
+ if (latestReply.reply === 'True') {
50
+ mdString = t('Mark_as_Resolved');
51
+ } else if (latestReply.reply === 'False') {
52
+ mdString = t('Resubmitted');
53
+ } else if (latestReply.reply) {
54
+ mdString = latestReply.reply;
55
+ } else {
56
+ mdString = '';
57
+ }
58
+ const htmlString = await _mdToHtml.default.process(mdString);
59
+ setReplyContent(String(htmlString));
60
+ };
61
+ initReplyContent();
62
+ }, [latestReply, t]);
51
63
  const handleScrollToArticle = (0, _react.useCallback)(e => {
52
64
  e.stopPropagation();
53
65
  const dom = _slateReact.ReactEditor.toDOMNode(editor, element);
@@ -87,14 +99,14 @@ const CommentItemCollapseWrapper = _ref => {
87
99
  className: "comment-author__avatar"
88
100
  }, /*#__PURE__*/_react.default.createElement("img", {
89
101
  alt: "",
90
- src: latestComment.avatar_url
102
+ src: topLevelComment.avatar_url
91
103
  })), /*#__PURE__*/_react.default.createElement("span", {
92
104
  className: "comment-author__info"
93
105
  }, /*#__PURE__*/_react.default.createElement("span", {
94
106
  className: "name"
95
- }, latestComment.user_name), /*#__PURE__*/_react.default.createElement("span", {
107
+ }, topLevelComment.user_name), /*#__PURE__*/_react.default.createElement("span", {
96
108
  className: "time"
97
- }, (0, _dayjs.default)(latestComment.updated_at).format('MM-DD HH:mm'), isUnseen && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
109
+ }, (0, _dayjs.default)(topLevelComment.updated_at).format('MM-DD HH:mm'), isUnseen && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
98
110
  className: "sdoc-unread-message-tip"
99
111
  }), /*#__PURE__*/_react.default.createElement("span", {
100
112
  className: "sdoc-unread-message-text-tip"
@@ -102,28 +114,28 @@ const CommentItemCollapseWrapper = _ref => {
102
114
  className: "comment-content"
103
115
  }, /*#__PURE__*/_react.default.createElement("div", {
104
116
  dangerouslySetInnerHTML: {
105
- __html: editorContent
117
+ __html: commentContent
106
118
  }
107
- })), /*#__PURE__*/_react.default.createElement("div", {
119
+ })), replyCount !== 0 && /*#__PURE__*/_react.default.createElement("div", {
108
120
  className: "comment-footer"
109
121
  }, /*#__PURE__*/_react.default.createElement("span", {
110
122
  className: "comments-count"
111
123
  }, /*#__PURE__*/_react.default.createElement("i", {
112
124
  className: "sdocfont sdoc-comments"
113
- }), commentCount !== 0 && /*#__PURE__*/_react.default.createElement("span", {
125
+ }), /*#__PURE__*/_react.default.createElement("span", {
114
126
  className: "comments-count-number"
115
- }, commentCount)), /*#__PURE__*/_react.default.createElement("div", {
127
+ }, replyCount)), /*#__PURE__*/_react.default.createElement("div", {
116
128
  className: "comment-author"
117
129
  }, /*#__PURE__*/_react.default.createElement("span", {
118
130
  className: "comment-author__avatar"
119
131
  }, /*#__PURE__*/_react.default.createElement("img", {
120
132
  alt: "",
121
- src: latestComment.avatar_url
133
+ src: latestReply.avatar_url
122
134
  })), /*#__PURE__*/_react.default.createElement("div", {
123
135
  className: "comment-author__latest-reply"
124
136
  }, /*#__PURE__*/_react.default.createElement("div", {
125
137
  dangerouslySetInnerHTML: {
126
- __html: editorContent
138
+ __html: replyContent
127
139
  }
128
140
  })))))));
129
141
  };
@@ -148,8 +148,8 @@ const GlobalComment = _ref => {
148
148
  className: "sdoc-comment-list-container"
149
149
  }, !activeCommentGroup && Array.isArray(commentList) && commentList.map(comment => {
150
150
  var _comment$replies, _comment$replies2;
151
- const latestComment = ((_comment$replies = comment.replies) === null || _comment$replies === void 0 ? void 0 : _comment$replies.length) > 0 ? comment.replies[comment.replies.length - 1] : comment;
152
- const commentCount = (_comment$replies2 = comment.replies) === null || _comment$replies2 === void 0 ? void 0 : _comment$replies2.length;
151
+ const replyCount = (_comment$replies = comment.replies) === null || _comment$replies === void 0 ? void 0 : _comment$replies.length;
152
+ const latestReply = ((_comment$replies2 = comment.replies) === null || _comment$replies2 === void 0 ? void 0 : _comment$replies2.length) > 0 ? comment.replies[comment.replies.length - 1] : null;
153
153
  const elementId = comment.detail.element_id;
154
154
  const element = getNodeByElementId(elementId);
155
155
  return /*#__PURE__*/_react.default.createElement(_commentItemCollapseWrapper.default, {
@@ -157,8 +157,8 @@ const GlobalComment = _ref => {
157
157
  editor: editor,
158
158
  element: element,
159
159
  topLevelComment: comment,
160
- latestComment: latestComment,
161
- commentCount: commentCount,
160
+ replyCount: replyCount,
161
+ latestReply: latestReply,
162
162
  setCurrentCommentGroup: setCurrentCommentGroup
163
163
  });
164
164
  }), activeCommentGroup && /*#__PURE__*/_react.default.createElement(_commentItemWrapper.default, {
@@ -59,7 +59,7 @@ const renderCallout = (_ref, editor) => {
59
59
  return _constant.CALLOUT_ICON_MAP[callout_icon];
60
60
  }, [element]);
61
61
  const isShowPlaceholder = (0, _react.useCallback)(() => {
62
- if (isSelected) return false;
62
+ if (readOnly || isSelected) return false;
63
63
  // If element contains more than one element or element is not paragraph, show placeholder
64
64
  const isContainUnitElement = element.children.length !== 1 || element.children.some(childElement => childElement.type !== 'paragraph');
65
65
  if (isContainUnitElement) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.116",
3
+ "version": "1.0.118",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",