@seafile/comment-editor 0.0.1-alpha.0 → 0.0.1-alpha.2
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/README.md +2 -4
- package/dist/basic-sdk/assets/css/layout.css +2 -2
- package/dist/basic-sdk/assets/css/sdoc-comment-editor-plugin.css +4 -4
- package/dist/basic-sdk/comment/components/comment-all-participants/index.css +8 -8
- package/dist/basic-sdk/comment/components/comment-editor.js +123 -7
- package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +2 -2
- package/dist/basic-sdk/comment/components/comment-item-content.js +11 -13
- package/dist/basic-sdk/comment/components/comment-item-wrapper.js +32 -36
- package/dist/basic-sdk/comment/components/comment-list.css +4 -4
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +2 -2
- package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +5 -4
- package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +11 -4
- package/dist/basic-sdk/comment/components/global-comment/index.css +56 -54
- package/dist/basic-sdk/comment/components/global-comment/index.js +41 -36
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +3 -4
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +2 -6
- package/dist/basic-sdk/comment/index.js +2 -48
- package/dist/basic-sdk/constants/index.js +1 -2
- package/dist/basic-sdk/context.js +8 -8
- package/dist/basic-sdk/extension/plugins/link/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/mention/render-elem/participant-popover.js +3 -6
- package/dist/basic-sdk/extension/render/render-comment-editor-element.js +1 -1
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +3 -3
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/post-comment/index.js +2 -2
- package/dist/basic-sdk/hooks/use-comment.js +218 -0
- package/dist/basic-sdk/index.js +12 -32
- package/dist/basic-sdk/{right-panel → layout/comment-layout}/index.css +2 -2
- package/dist/basic-sdk/{right-panel → layout/comment-layout}/index.js +29 -28
- package/dist/basic-sdk/layout/comment-layout/resize-width/index.css +38 -0
- package/dist/basic-sdk/{right-panel → layout/comment-layout}/resize-width/index.js +3 -3
- package/dist/basic-sdk/layout/index.js +0 -7
- package/dist/index.js +12 -0
- package/dist/pages/seafile-comment-editor.js +19 -52
- package/package.json +2 -1
- package/dist/basic-sdk/comment/components/global-comment/global-comment-editor.js +0 -36
- package/dist/basic-sdk/comment/provider/comment-context-provider.js +0 -37
- package/dist/basic-sdk/comment/provider/index.js +0 -23
- package/dist/basic-sdk/comment/provider/notification-context-provider.js +0 -31
- package/dist/basic-sdk/comment/provider/participants-content-provider.js +0 -96
- package/dist/basic-sdk/editor/comment-article.js +0 -104
- package/dist/basic-sdk/editor/sdoc-comment-editor.js +0 -128
- package/dist/basic-sdk/editor/sdoc-editor.js +0 -50
- package/dist/basic-sdk/hooks/use-collaborators.js +0 -62
- package/dist/basic-sdk/hooks/use-plugins.js +0 -9
- package/dist/basic-sdk/layout/article-container.js +0 -89
- package/dist/basic-sdk/right-panel/resize-width/index.css +0 -38
- package/dist/hooks/index.js +0 -12
- package/dist/hooks/use-document.js +0 -75
package/README.md
CHANGED
|
@@ -17,7 +17,6 @@ comment-editor/
|
|
|
17
17
|
assets // css 文件, 图片文件
|
|
18
18
|
commons // 公共组件
|
|
19
19
|
components // 应用组件
|
|
20
|
-
containers // 容器组件
|
|
21
20
|
pages // 页面组件
|
|
22
21
|
app.js // 应用对象
|
|
23
22
|
index.html // 主页
|
|
@@ -27,11 +26,10 @@ comment-editor/
|
|
|
27
26
|
setting.local.dist // 用户基于 setting.local.dist.js copy 一份的配置文件
|
|
28
27
|
src/(组件库)
|
|
29
28
|
assets // css 文件, 资源文件
|
|
29
|
+
basic-sdk // 编辑器元素包
|
|
30
30
|
components // 封装的视图组件
|
|
31
|
-
editor // 封装的编辑器组件
|
|
32
|
-
lib // 底层接口
|
|
33
31
|
utils // 工具接口
|
|
34
|
-
|
|
32
|
+
pages // 封装的视图组件
|
|
35
33
|
index.js // 组件库导出内容入口文件
|
|
36
34
|
tests // 测试
|
|
37
35
|
webpack // site 打包文件
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
transform: scale(.75);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
.
|
|
145
|
+
.comment-editor-toolbar {
|
|
146
146
|
display: flex;
|
|
147
147
|
justify-content: space-between;
|
|
148
148
|
align-items: center;
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
margin-top: 5px;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
.
|
|
157
|
+
.comment-editor-menu-group {
|
|
158
158
|
border-right: none;
|
|
159
159
|
padding-left: 0 !important;
|
|
160
160
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/* List */
|
|
2
|
-
.sdoc-editor-container .
|
|
2
|
+
.sdoc-editor-container .comment-editor .list-container {
|
|
3
3
|
padding-left: 2em !important;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
.
|
|
6
|
+
.comment-editor .list-container li p {
|
|
7
7
|
margin: 0 !important;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/* Paragraph */
|
|
11
|
-
.
|
|
11
|
+
.comment-editor .comment-editor-paragraph {
|
|
12
12
|
margin: 0.8em 0 !important;
|
|
13
13
|
padding: 0 !important;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/* Image */
|
|
17
|
-
.
|
|
17
|
+
.comment-editor .sdoc-image-wrapper {
|
|
18
18
|
padding: 1px !important;
|
|
19
19
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.
|
|
1
|
+
.comment-drawer .comments-panel-body__header .comments-participants-container {
|
|
2
2
|
width: fit-content;
|
|
3
3
|
max-width: 100%;
|
|
4
4
|
height: 42px;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
position: relative;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
.
|
|
11
|
+
.comment-drawer .comments-panel-body__header .comments-participants-editor-target {
|
|
12
12
|
position: absolute;
|
|
13
13
|
left: -1px;
|
|
14
14
|
top: 0;
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
background-color: transparent;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
.
|
|
21
|
+
.comment-drawer .comments-panel-body__header .comment-participant-avatar {
|
|
22
22
|
border-radius: 50%;
|
|
23
23
|
vertical-align: middle;
|
|
24
24
|
margin-right: -0.5rem;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
.
|
|
27
|
+
.comment-drawer .comments-panel-body__header .comment-participant-avatar img {
|
|
28
28
|
width: 28px;
|
|
29
29
|
height: 28px;
|
|
30
30
|
border: 2px solid #fff;
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
user-select: none;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
.
|
|
44
|
+
.comment-drawer .comments-panel-body__header .add-comments-participants {
|
|
45
45
|
position: relative;
|
|
46
46
|
bottom: -3px;
|
|
47
47
|
cursor: pointer;
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
justify-content: center;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
.
|
|
59
|
+
.comment-drawer .add-comments-participants .sdocfont {
|
|
60
60
|
font-size: 16px;
|
|
61
61
|
color: #ff8000;
|
|
62
62
|
border-radius: 50%;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
.
|
|
65
|
+
.comment-drawer .comment-participants-more {
|
|
66
66
|
position: absolute;
|
|
67
67
|
top: 0;
|
|
68
68
|
left: 0;
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
border: 2px solid #fff;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
.
|
|
80
|
+
.comment-drawer .comment-participants-more .sdocfont {
|
|
81
81
|
color: #fff;
|
|
82
82
|
font-size: 12px;
|
|
83
83
|
}
|
|
@@ -11,17 +11,25 @@ var _reactI18next = require("react-i18next");
|
|
|
11
11
|
var _slate = require("@seafile/slate");
|
|
12
12
|
var _slateReact = require("@seafile/slate-react");
|
|
13
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
|
+
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
15
|
+
var _scrollIntoViewIfNeeded = _interopRequireDefault(require("scroll-into-view-if-needed"));
|
|
14
16
|
var _constants = require("../../constants");
|
|
15
17
|
var _context = _interopRequireDefault(require("../../context"));
|
|
16
|
-
var
|
|
18
|
+
var _useCursors = require("../../cursor/use-cursors");
|
|
19
|
+
var _decorates = require("../../decorates");
|
|
17
20
|
var _extension = require("../../extension");
|
|
18
21
|
var _constants2 = require("../../extension/constants");
|
|
19
22
|
var _core = require("../../extension/core");
|
|
23
|
+
var _renderCommentEditorElement = _interopRequireDefault(require("../../extension/render/render-comment-editor-element"));
|
|
24
|
+
var _commentEditorToolbar = _interopRequireDefault(require("../../extension/toolbar/comment-editor-toolbar"));
|
|
25
|
+
var _useComment = require("../../hooks/use-comment");
|
|
26
|
+
var _useScrollContext = require("../../hooks/use-scroll-context");
|
|
27
|
+
var _layout = require("../../layout");
|
|
20
28
|
var _nodeId = _interopRequireDefault(require("../../node-id"));
|
|
21
29
|
var _mdToSlate = _interopRequireDefault(require("../../slate-convert/md-to-slate"));
|
|
22
30
|
var _slateToMd = _interopRequireDefault(require("../../slate-convert/slate-to-md"));
|
|
23
31
|
var _eventBus = _interopRequireDefault(require("../../utils/event-bus"));
|
|
24
|
-
var
|
|
32
|
+
var _eventHandler = _interopRequireDefault(require("../../utils/event-handler"));
|
|
25
33
|
const getSubmitTip = (type, content) => {
|
|
26
34
|
if (content) return 'Save';
|
|
27
35
|
return type === 'comment' ? 'Comment' : 'Reply';
|
|
@@ -49,7 +57,7 @@ const CommentEditor = _ref => {
|
|
|
49
57
|
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
50
58
|
const {
|
|
51
59
|
addParticipants
|
|
52
|
-
} = (0,
|
|
60
|
+
} = (0, _useComment.useComment)();
|
|
53
61
|
const submitTip = (0, _react.useMemo)(() => getSubmitTip(type, content), [content, type]);
|
|
54
62
|
const userInfo = _context.default.getUserInfo();
|
|
55
63
|
const document = (0, _react.useMemo)(() => {
|
|
@@ -63,6 +71,8 @@ const CommentEditor = _ref => {
|
|
|
63
71
|
cursor
|
|
64
72
|
};
|
|
65
73
|
}, [placeholder]);
|
|
74
|
+
const [slateValue, setSlateValue] = (0, _react.useState)(document.elements);
|
|
75
|
+
const commentEditorContainerRef = (0, _react.useRef)(null);
|
|
66
76
|
const editor = (0, _react.useMemo)(() => {
|
|
67
77
|
const defaultEditor = (0, _extension.createCommentEditor)();
|
|
68
78
|
const newEditor = (0, _nodeId.default)(defaultEditor);
|
|
@@ -74,6 +84,13 @@ const CommentEditor = _ref => {
|
|
|
74
84
|
newEditor.editorType = _constants.COMMENT_EDITOR;
|
|
75
85
|
return newEditor;
|
|
76
86
|
}, [document]);
|
|
87
|
+
const {
|
|
88
|
+
cursors
|
|
89
|
+
} = (0, _useCursors.useCursors)(editor);
|
|
90
|
+
const decorate = (0, _decorates.usePipDecorate)(editor);
|
|
91
|
+
// init eventHandler
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
const eventProxy = (0, _react.useMemo)(() => new _eventHandler.default(editor), []);
|
|
77
94
|
const updateValue = (0, _react.useCallback)(value => {
|
|
78
95
|
if (!value || value.trim() === '') return;
|
|
79
96
|
if (!content) return insertContent(value);
|
|
@@ -139,6 +156,75 @@ const CommentEditor = _ref => {
|
|
|
139
156
|
editor.children = children;
|
|
140
157
|
_slate.Transforms.select(editor, _slate.Editor.end(editor, []));
|
|
141
158
|
}, [editor, content, commentContent]);
|
|
159
|
+
|
|
160
|
+
// useMount: focus editor
|
|
161
|
+
(0, _react.useEffect)(() => {
|
|
162
|
+
const [firstNode] = editor.children;
|
|
163
|
+
if (firstNode) {
|
|
164
|
+
const [firstNodeFirstChild] = firstNode.children;
|
|
165
|
+
if (firstNodeFirstChild) {
|
|
166
|
+
const endOfFirstNode = _slate.Editor.end(editor, [0, 0]);
|
|
167
|
+
const range = {
|
|
168
|
+
anchor: endOfFirstNode,
|
|
169
|
+
focus: endOfFirstNode
|
|
170
|
+
};
|
|
171
|
+
(0, _core.focusEditor)(editor, range);
|
|
172
|
+
}
|
|
173
|
+
// Force refresh to fix comment list
|
|
174
|
+
setSlateValue([...editor.children]);
|
|
175
|
+
}
|
|
176
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
|
+
}, []);
|
|
178
|
+
const handleFocusEditor = e => {
|
|
179
|
+
if (e.target === commentEditorContainerRef.current) {
|
|
180
|
+
const focusPoint = _slate.Editor.end(editor, []);
|
|
181
|
+
(0, _core.focusEditor)(editor, focusPoint);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const handleScrollIntoView = (0, _react.useCallback)((editor, domRange) => {
|
|
185
|
+
try {
|
|
186
|
+
const {
|
|
187
|
+
selection
|
|
188
|
+
} = editor;
|
|
189
|
+
// Do not scroll into view, when focus on image
|
|
190
|
+
const [imageNodeEntry] = _slate.Editor.nodes(editor, {
|
|
191
|
+
match: n => [_constants2.IMAGE, _constants2.IMAGE_BLOCK].includes(n.type),
|
|
192
|
+
at: selection
|
|
193
|
+
});
|
|
194
|
+
if (imageNodeEntry) return;
|
|
195
|
+
const focusedNode = _slate.Node.get(editor, selection.focus.path);
|
|
196
|
+
const domNode = _slateReact.ReactEditor.toDOMNode(editor, focusedNode);
|
|
197
|
+
if (!domNode) return;
|
|
198
|
+
(0, _scrollIntoViewIfNeeded.default)(domNode, {
|
|
199
|
+
'scrollMode': 'if-needed'
|
|
200
|
+
});
|
|
201
|
+
} catch (error) {
|
|
202
|
+
//
|
|
203
|
+
}
|
|
204
|
+
}, []);
|
|
205
|
+
const onMouseDown = (0, _react.useCallback)(event => {
|
|
206
|
+
if (event.button === 0) {
|
|
207
|
+
// Compatible with the editor which unload table plugin
|
|
208
|
+
editor.reSetTableSelectedRange && editor.reSetTableSelectedRange();
|
|
209
|
+
const eventBus = _eventBus.default.getInstance();
|
|
210
|
+
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
211
|
+
}
|
|
212
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
213
|
+
}, []);
|
|
214
|
+
const onKeyDown = (0, _react.useCallback)(event => {
|
|
215
|
+
if ((0, _isHotkey.default)('enter', event)) {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
const eventBus = _eventBus.default.getInstance();
|
|
218
|
+
eventBus.dispatch(_constants.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, event);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if ((0, _isHotkey.default)('shift+enter', event)) {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
_slate.Editor.insertBreak(editor);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
eventProxy.onKeyDown(event);
|
|
227
|
+
}, [eventProxy, editor]);
|
|
142
228
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
143
229
|
className: (0, _classnames.default)('comment-editor-wrapper', className),
|
|
144
230
|
ref: commentWrapperRef
|
|
@@ -153,13 +239,43 @@ const CommentEditor = _ref => {
|
|
|
153
239
|
width: "100%"
|
|
154
240
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
155
241
|
className: "comment-editor-user-name"
|
|
156
|
-
}, userInfo.name)), /*#__PURE__*/_react.default.createElement(
|
|
242
|
+
}, userInfo.name)), /*#__PURE__*/_react.default.createElement(_layout.EditorContainer, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
243
|
+
className: "comment-editor-content"
|
|
244
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
245
|
+
ref: commentEditorContainerRef,
|
|
246
|
+
className: "article comment-editor",
|
|
247
|
+
onClick: handleFocusEditor
|
|
248
|
+
}, /*#__PURE__*/_react.default.createElement(_useScrollContext.ScrollContext.Provider, {
|
|
249
|
+
value: {
|
|
250
|
+
scrollRef: commentEditorContainerRef
|
|
251
|
+
}
|
|
252
|
+
}, /*#__PURE__*/_react.default.createElement(_slateReact.Slate, {
|
|
253
|
+
editor: editor,
|
|
254
|
+
value: slateValue,
|
|
255
|
+
onChange: setSlateValue
|
|
256
|
+
}, /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
|
|
257
|
+
id: "sdoc-editor",
|
|
258
|
+
scrollSelectionIntoView: handleScrollIntoView,
|
|
259
|
+
cursors: cursors,
|
|
260
|
+
renderElement: props => (0, _renderCommentEditorElement.default)({
|
|
261
|
+
...props,
|
|
262
|
+
commentType: type
|
|
263
|
+
}),
|
|
264
|
+
renderLeaf: _extension.renderLeaf,
|
|
265
|
+
onMouseDown: onMouseDown,
|
|
266
|
+
decorate: decorate,
|
|
267
|
+
onCut: eventProxy.onCut,
|
|
268
|
+
onCopy: eventProxy.onCopy,
|
|
269
|
+
onCompositionStart: eventProxy.onCompositionStart,
|
|
270
|
+
onCompositionUpdate: eventProxy.onCompositionUpdate,
|
|
271
|
+
onCompositionEnd: eventProxy.onCompositionEnd,
|
|
272
|
+
onKeyDown: onKeyDown,
|
|
273
|
+
onBeforeInput: eventProxy.onBeforeInput
|
|
274
|
+
})))), /*#__PURE__*/_react.default.createElement(_commentEditorToolbar.default, {
|
|
157
275
|
editor: editor,
|
|
158
|
-
type: type,
|
|
159
|
-
document: document,
|
|
160
276
|
onSubmit: onSubmit,
|
|
161
277
|
submitBtnText: t(submitTip),
|
|
162
278
|
onCancel: onCancel
|
|
163
|
-
}));
|
|
279
|
+
}))));
|
|
164
280
|
};
|
|
165
281
|
var _default = exports.default = CommentEditor;
|
|
@@ -12,10 +12,10 @@ var _slate = require("@seafile/slate");
|
|
|
12
12
|
var _slateReact = require("@seafile/slate-react");
|
|
13
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
14
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
15
|
+
var _useComment = require("../../hooks/use-comment");
|
|
15
16
|
var _mdToHtml = _interopRequireDefault(require("../../slate-convert/md-to-html"));
|
|
16
17
|
var _constants = require("../constants");
|
|
17
18
|
var _helper = require("../helper");
|
|
18
|
-
var _notificationHooks = require("../hooks/notification-hooks");
|
|
19
19
|
const CommentItemCollapseWrapper = _ref => {
|
|
20
20
|
var _topLevelComment$deta;
|
|
21
21
|
let {
|
|
@@ -30,7 +30,7 @@ const CommentItemCollapseWrapper = _ref => {
|
|
|
30
30
|
const scrollRef = (0, _react.useRef)(document.querySelector('.sdoc-scroll-container'));
|
|
31
31
|
const {
|
|
32
32
|
notificationsInfo
|
|
33
|
-
} = (0,
|
|
33
|
+
} = (0, _useComment.useComment)();
|
|
34
34
|
const [commentContent, setCommentContent] = (0, _react.useState)('');
|
|
35
35
|
const [replyContent, setReplyContent] = (0, _react.useState)('');
|
|
36
36
|
const isUnseen = notificationsInfo.notifications_map[`sdoc_notification_${topLevelComment.id}`] ? true : false;
|
|
@@ -12,8 +12,8 @@ var _reactstrap = require("reactstrap");
|
|
|
12
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
13
|
var _tooltip = _interopRequireDefault(require("../../components/tooltip"));
|
|
14
14
|
var _context = _interopRequireDefault(require("../../context"));
|
|
15
|
+
var _useComment = require("../../hooks/use-comment");
|
|
15
16
|
var _mdToHtml = _interopRequireDefault(require("../../slate-convert/md-to-html"));
|
|
16
|
-
var _notificationHooks = require("../hooks/notification-hooks");
|
|
17
17
|
var _commentEditor = _interopRequireDefault(require("./comment-editor"));
|
|
18
18
|
const CommentItemContent = _ref => {
|
|
19
19
|
let {
|
|
@@ -22,7 +22,7 @@ const CommentItemContent = _ref => {
|
|
|
22
22
|
comment,
|
|
23
23
|
updateComment,
|
|
24
24
|
updateCommentState,
|
|
25
|
-
|
|
25
|
+
onShowDeletePopover,
|
|
26
26
|
t,
|
|
27
27
|
targetId
|
|
28
28
|
} = _ref;
|
|
@@ -30,12 +30,8 @@ const CommentItemContent = _ref => {
|
|
|
30
30
|
const [isEditing, setIsEditing] = (0, _react.useState)(false);
|
|
31
31
|
const {
|
|
32
32
|
notificationsInfo
|
|
33
|
-
} = (0,
|
|
33
|
+
} = (0, _useComment.useComment)();
|
|
34
34
|
const [editorContent, setEditorContent] = (0, _react.useState)('');
|
|
35
|
-
const onEditToggle = (0, _react.useCallback)(event => {
|
|
36
|
-
event.stopPropagation();
|
|
37
|
-
setIsEditing(true);
|
|
38
|
-
}, []);
|
|
39
35
|
const isUnseen = notificationsInfo.notifications_map[`sdoc_notification_${comment.id}`] ? true : false;
|
|
40
36
|
(0, _react.useEffect)(() => {
|
|
41
37
|
transferHtml(comment.comment);
|
|
@@ -44,10 +40,6 @@ const CommentItemContent = _ref => {
|
|
|
44
40
|
const htmlString = await _mdToHtml.default.process(mdString);
|
|
45
41
|
setEditorContent(String(htmlString));
|
|
46
42
|
};
|
|
47
|
-
const onDeleteToggle = (0, _react.useCallback)(event => {
|
|
48
|
-
event.stopPropagation();
|
|
49
|
-
onDeleteComment(true);
|
|
50
|
-
}, [onDeleteComment]);
|
|
51
43
|
const updateContent = (0, _react.useCallback)(content => {
|
|
52
44
|
const commentId = comment.id;
|
|
53
45
|
if (comment.comment !== content) {
|
|
@@ -127,11 +119,17 @@ const CommentItemContent = _ref => {
|
|
|
127
119
|
}, /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownItem, {
|
|
128
120
|
className: "sdoc-dropdown-menu-item",
|
|
129
121
|
tag: "div",
|
|
130
|
-
onClick:
|
|
122
|
+
onClick: event => {
|
|
123
|
+
event.stopPropagation();
|
|
124
|
+
setIsEditing(true);
|
|
125
|
+
}
|
|
131
126
|
}, t('Edit')), /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownItem, {
|
|
132
127
|
className: "sdoc-dropdown-menu-item",
|
|
133
128
|
tag: "div",
|
|
134
|
-
onClick:
|
|
129
|
+
onClick: event => {
|
|
130
|
+
event.stopPropagation();
|
|
131
|
+
onShowDeletePopover(true);
|
|
132
|
+
}
|
|
135
133
|
}, t('Delete')), !comment.resolved && /*#__PURE__*/_react.default.createElement(_reactstrap.DropdownItem, {
|
|
136
134
|
className: "sdoc-dropdown-menu-item",
|
|
137
135
|
tag: "div",
|
|
@@ -12,9 +12,9 @@ var _slateReact = require("@seafile/slate-react");
|
|
|
12
12
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
13
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
14
14
|
var _context = _interopRequireDefault(require("../../context"));
|
|
15
|
+
var _useComment = require("../../hooks/use-comment");
|
|
15
16
|
var _constants = require("../constants");
|
|
16
17
|
var _helper = require("../helper");
|
|
17
|
-
var _useCommentContext = require("../hooks/comment-hooks/use-comment-context");
|
|
18
18
|
var _commentDeletePopover = _interopRequireDefault(require("./comment-delete-popover"));
|
|
19
19
|
var _commentItemContent = _interopRequireDefault(require("./comment-item-content"));
|
|
20
20
|
var _commentItemReply = _interopRequireDefault(require("./comment-item-reply"));
|
|
@@ -41,37 +41,17 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
41
41
|
} = _ref;
|
|
42
42
|
const listRef = (0, _react.useRef)(null);
|
|
43
43
|
const {
|
|
44
|
-
dispatch
|
|
45
|
-
|
|
44
|
+
dispatch,
|
|
45
|
+
api
|
|
46
|
+
} = (0, _useComment.useComment)();
|
|
46
47
|
const scrollRef = (0, _react.useRef)(document.querySelector('.sdoc-scroll-container'));
|
|
47
48
|
const [isShowDeletePopover, setIsShowDeletePopover] = (0, _react.useState)(false);
|
|
48
49
|
const commentOpToolsId = `commentOpTools_${comment === null || comment === void 0 ? void 0 : comment.id}`;
|
|
49
50
|
const style = !isGlobalComment && isCollapseCommentEditor ? {
|
|
50
51
|
maxHeight: '341px'
|
|
51
52
|
} : {};
|
|
52
|
-
const deleteComment = (0, _react.useCallback)(async commentId => {
|
|
53
|
-
await _context.default.deleteComment(commentId);
|
|
54
|
-
let {
|
|
55
|
-
element_id: elementId,
|
|
56
|
-
element_id_list
|
|
57
|
-
} = comment.detail;
|
|
58
|
-
if (element_id_list) {
|
|
59
|
-
var _comment$detail;
|
|
60
|
-
elementId = element_id_list[0];
|
|
61
|
-
(0, _helper.updateCommentedElementsAttrs)(element_id_list, editor, (_comment$detail = comment.detail) === null || _comment$detail === void 0 ? void 0 : _comment$detail.text_comment_id, false, true);
|
|
62
|
-
}
|
|
63
|
-
dispatch({
|
|
64
|
-
type: 'DELETE_COMMENT',
|
|
65
|
-
payload: {
|
|
66
|
-
element_id: elementId,
|
|
67
|
-
comment_id: commentId
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
closeComment && closeComment();
|
|
71
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
-
}, [comment.detail, dispatch, editor]);
|
|
73
53
|
const updateComment = (0, _react.useCallback)(async (commentId, newComment) => {
|
|
74
|
-
await
|
|
54
|
+
await api.updateComment(commentId, newComment);
|
|
75
55
|
const elementId = (0, _helper.getPrimaryElementId)(comment.detail);
|
|
76
56
|
dispatch({
|
|
77
57
|
type: 'UPDATE_COMMENT',
|
|
@@ -81,10 +61,11 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
81
61
|
comment: newComment
|
|
82
62
|
}
|
|
83
63
|
});
|
|
84
|
-
}, [comment.detail, dispatch]);
|
|
64
|
+
}, [api, comment.detail, dispatch]);
|
|
85
65
|
const updateCommentState = (0, _react.useCallback)(async (commentId, newComment) => {
|
|
86
66
|
const time = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
87
67
|
const user = _context.default.getUserInfo();
|
|
68
|
+
console.log(user);
|
|
88
69
|
const reply = {
|
|
89
70
|
type: 'comment',
|
|
90
71
|
reply: newComment.resolved,
|
|
@@ -93,7 +74,7 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
93
74
|
};
|
|
94
75
|
|
|
95
76
|
// When updating comment status, add a new reply
|
|
96
|
-
const res = await
|
|
77
|
+
const res = await api.insertReply(commentId, reply);
|
|
97
78
|
const {
|
|
98
79
|
reply: returnReply
|
|
99
80
|
} = res.data;
|
|
@@ -134,7 +115,7 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
134
115
|
});
|
|
135
116
|
|
|
136
117
|
// Modify comment status
|
|
137
|
-
await
|
|
118
|
+
await api.updateComment(commentId, newComment);
|
|
138
119
|
dispatch({
|
|
139
120
|
type: 'UPDATE_COMMENT_STATE',
|
|
140
121
|
payload: {
|
|
@@ -262,11 +243,25 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
262
243
|
if (event.target.className === _constants.COMMENT_URL_CLASSNAME) return;
|
|
263
244
|
onCommentClick && onCommentClick(comment);
|
|
264
245
|
}, [comment, onCommentClick]);
|
|
265
|
-
const onDeleteComment = (0, _react.useCallback)(() => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
246
|
+
const onDeleteComment = (0, _react.useCallback)(async () => {
|
|
247
|
+
await api.deleteComment(comment.id);
|
|
248
|
+
let {
|
|
249
|
+
element_id: elementId,
|
|
250
|
+
element_id_list
|
|
251
|
+
} = comment.detail;
|
|
252
|
+
if (element_id_list) {
|
|
253
|
+
var _comment$detail;
|
|
254
|
+
elementId = element_id_list[0];
|
|
255
|
+
(0, _helper.updateCommentedElementsAttrs)(element_id_list, editor, (_comment$detail = comment.detail) === null || _comment$detail === void 0 ? void 0 : _comment$detail.text_comment_id, false, true);
|
|
256
|
+
}
|
|
257
|
+
dispatch({
|
|
258
|
+
type: 'DELETE_COMMENT',
|
|
259
|
+
payload: {
|
|
260
|
+
element_id: elementId,
|
|
261
|
+
comment_id: comment.id
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
closeComment && closeComment();
|
|
270
265
|
setIsShowDeletePopover(false);
|
|
271
266
|
setCurrentCommentGroup && setCurrentCommentGroup(null);
|
|
272
267
|
if (isClickedContextComment) {
|
|
@@ -278,7 +273,8 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
278
273
|
onSelectElement(newCommentIdArray, true);
|
|
279
274
|
}
|
|
280
275
|
}
|
|
281
|
-
|
|
276
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
277
|
+
}, [comment.id, commentsDetail, isClickedContextComment, onSelectElement, setCurrentCommentGroup, setIsClickedContextComment, setIsCommentPanelVisible]);
|
|
282
278
|
(0, _react.useEffect)(() => {
|
|
283
279
|
if (!isActive) {
|
|
284
280
|
setIsShowDeletePopover(false);
|
|
@@ -334,7 +330,7 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
334
330
|
comment: comment,
|
|
335
331
|
updateComment: updateComment,
|
|
336
332
|
updateCommentState: updateCommentState,
|
|
337
|
-
|
|
333
|
+
onShowDeletePopover: () => setIsShowDeletePopover(true),
|
|
338
334
|
targetId: commentOpToolsId,
|
|
339
335
|
isClickedContextComment: isClickedContextComment
|
|
340
336
|
}), isClickedContextComment && comment.replies && comment.replies.length > 0 && comment.replies.filter(item => item.type === 'reply').map(reply => {
|
|
@@ -360,7 +356,7 @@ const CommentItemWrapper = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
360
356
|
})), isShowDeletePopover && isActive && /*#__PURE__*/_react.default.createElement(_commentDeletePopover.default, {
|
|
361
357
|
type: "comment",
|
|
362
358
|
targetId: commentOpToolsId,
|
|
363
|
-
deleteConfirm:
|
|
359
|
+
deleteConfirm: onDeleteComment,
|
|
364
360
|
setIsShowDeletePopover: setIsShowDeletePopover,
|
|
365
361
|
parentDom: listRef.current
|
|
366
362
|
}));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
right: 0;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
.sdoc-comment-list-container .article.
|
|
6
|
+
.sdoc-comment-list-container .article.comment-editor {
|
|
7
7
|
font-size: 14px;
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -254,14 +254,14 @@
|
|
|
254
254
|
color: #fff;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
.
|
|
257
|
+
.comment-editor-content {
|
|
258
258
|
border: 1px solid #ececec;
|
|
259
259
|
border-top-left-radius: 3px;
|
|
260
260
|
border-top-right-radius: 3px;
|
|
261
261
|
border-radius: 3px;
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
.comment-editor-wrapper .
|
|
264
|
+
.comment-editor-wrapper .comment-editor-content .article.comment-editor {
|
|
265
265
|
width: 100%;
|
|
266
266
|
padding: 8px;
|
|
267
267
|
padding-bottom: 0;
|
|
@@ -282,7 +282,7 @@
|
|
|
282
282
|
width: auto;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
.article.
|
|
285
|
+
.article.comment-editor :first-child {
|
|
286
286
|
margin-top: 0 !important;
|
|
287
287
|
}
|
|
288
288
|
|
|
@@ -9,7 +9,7 @@ exports.default = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _reactI18next = require("react-i18next");
|
|
11
11
|
var _reactstrap = require("reactstrap");
|
|
12
|
-
var
|
|
12
|
+
var _useComment = require("../../../hooks/use-comment");
|
|
13
13
|
var _mouseEvent = require("../../../utils/mouse-event");
|
|
14
14
|
var _utils = require("../../utils");
|
|
15
15
|
var _searchedCollaborators = _interopRequireDefault(require("./searched-collaborators"));
|
|
@@ -23,7 +23,7 @@ const CommentParticipantsEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref
|
|
|
23
23
|
const popoverRef = (0, _react.useRef)();
|
|
24
24
|
const {
|
|
25
25
|
collaborators
|
|
26
|
-
} = (0,
|
|
26
|
+
} = (0, _useComment.useComment)();
|
|
27
27
|
const {
|
|
28
28
|
t
|
|
29
29
|
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _reactI18next = require("react-i18next");
|
|
10
10
|
var _reactstrap = require("reactstrap");
|
|
11
|
+
var _useComment = require("../../../hooks/use-comment");
|
|
11
12
|
var _mouseEvent = require("../../../utils/mouse-event");
|
|
12
13
|
var _constants = require("../../constants");
|
|
13
14
|
const CommentTypeDropdownItem = _ref => {
|
|
@@ -30,12 +31,12 @@ const CommentTypeDropdownItem = _ref => {
|
|
|
30
31
|
onClick: event => handleCommentTypeChanged(event, type)
|
|
31
32
|
}, t(type));
|
|
32
33
|
};
|
|
33
|
-
const GlobalCommentBodyHeader =
|
|
34
|
-
|
|
35
|
-
commentList
|
|
34
|
+
const GlobalCommentBodyHeader = () => {
|
|
35
|
+
const {
|
|
36
|
+
commentList,
|
|
36
37
|
commentType,
|
|
37
38
|
setCommentType
|
|
38
|
-
} =
|
|
39
|
+
} = (0, _useComment.useComment)();
|
|
39
40
|
const {
|
|
40
41
|
t
|
|
41
42
|
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
@@ -10,7 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _reactI18next = require("react-i18next");
|
|
11
11
|
var _tooltip = _interopRequireDefault(require("../../../components/tooltip"));
|
|
12
12
|
var _constants = require("../../../constants");
|
|
13
|
-
var
|
|
13
|
+
var _useComment = require("../../../hooks/use-comment");
|
|
14
14
|
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
|
|
15
15
|
var _mouseEvent = require("../../../utils/mouse-event");
|
|
16
16
|
const GlobalCommentHeader = _ref => {
|
|
@@ -24,6 +24,13 @@ const GlobalCommentHeader = _ref => {
|
|
|
24
24
|
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
25
25
|
const panelHeaderRef = (0, _react.useRef)(null);
|
|
26
26
|
const [isMounted, setIsMounted] = (0, _react.useState)(false);
|
|
27
|
+
const {
|
|
28
|
+
api
|
|
29
|
+
} = (0, _useComment.useComment)();
|
|
30
|
+
const {
|
|
31
|
+
readAllNotifications,
|
|
32
|
+
listUnseenNotifications
|
|
33
|
+
} = api;
|
|
27
34
|
(0, _react.useEffect)(() => {
|
|
28
35
|
if (panelHeaderRef.current) {
|
|
29
36
|
setIsMounted(true);
|
|
@@ -36,8 +43,8 @@ const GlobalCommentHeader = _ref => {
|
|
|
36
43
|
const toggleReadAll = (0, _react.useCallback)(async event => {
|
|
37
44
|
(0, _mouseEvent.eventStopPropagation)(event);
|
|
38
45
|
try {
|
|
39
|
-
await
|
|
40
|
-
const res = await
|
|
46
|
+
await readAllNotifications();
|
|
47
|
+
const res = await listUnseenNotifications();
|
|
41
48
|
const notifications = res.data.notifications;
|
|
42
49
|
const eventBus = _eventBus.default.getInstance();
|
|
43
50
|
eventBus.dispatch(_constants.INTERNAL_EVENT.UNSEEN_NOTIFICATIONS_COUNT, notifications === null || notifications === void 0 ? void 0 : notifications.length);
|
|
@@ -46,7 +53,7 @@ const GlobalCommentHeader = _ref => {
|
|
|
46
53
|
} catch (error) {
|
|
47
54
|
//
|
|
48
55
|
}
|
|
49
|
-
}, []);
|
|
56
|
+
}, [listUnseenNotifications, readAllNotifications]);
|
|
50
57
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
51
58
|
className: "comments-panel-header"
|
|
52
59
|
}, /*#__PURE__*/_react.default.createElement("div", {
|