@seafile/sdoc-editor 0.1.91 → 0.1.93
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/api/sdoc-server-api.js +58 -0
- package/dist/api/seafile-api.js +14 -1
- package/dist/basic-sdk/comment/comment/comment-editor.js +53 -0
- package/dist/basic-sdk/comment/{comment-item.js → comment/comment-item-content.js} +29 -14
- package/dist/basic-sdk/comment/comment/comment-item-reply.js +112 -0
- package/dist/basic-sdk/comment/comment/comment-item-wrapper.js +208 -0
- package/dist/basic-sdk/comment/{comment-list.js → comment/comment-list.js} +58 -71
- package/dist/basic-sdk/comment/{comment.js → comment/index.js} +4 -4
- package/dist/basic-sdk/comment/{style.css → comment/style.css} +43 -8
- package/dist/basic-sdk/comment/dialogs/delete-comment-dialog.js +11 -4
- package/dist/basic-sdk/comment/hooks/use-comment-mount.js +5 -1
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +82 -0
- package/dist/basic-sdk/editor.js +3 -4
- package/dist/basic-sdk/extension/commons/color-menu/index.js +6 -5
- package/dist/basic-sdk/extension/plugins/table/helpers.js +85 -30
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-bg-color-menu.js +35 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-text-align-menu.js +43 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +31 -171
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/remove-table-menu.js +26 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/table-column-menu.js +35 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/table-row-menu.js +35 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.js +1 -0
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +6 -8
- package/dist/basic-sdk/extension/toolbar/context-toolbar/index.css +1 -1
- package/dist/basic-sdk/extension/toolbar/context-toolbar/index.js +1 -1
- package/dist/basic-sdk/hooks/use-color-context.js +48 -0
- package/dist/components/common-loading/index.css +54 -0
- package/dist/components/common-loading/index.js +8 -0
- package/dist/components/doc-info/index.js +5 -2
- package/dist/components/doc-operations/revision-operations/index.js +2 -1
- package/dist/components/doc-operations/revision-operations/revisions/index.css +16 -0
- package/dist/components/doc-operations/revision-operations/revisions/index.js +49 -0
- package/dist/components/doc-operations/revision-operations/revisions/revisions-dialog/index.css +120 -0
- package/dist/components/doc-operations/revision-operations/revisions/revisions-dialog/index.js +174 -0
- package/dist/components/doc-operations/style.css +13 -0
- package/dist/context.js +27 -0
- package/dist/model/index.js +2 -0
- package/dist/model/revision.js +35 -0
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +11 -1
- package/public/locales/zh-CN/sdoc-editor.json +11 -1
- package/dist/basic-sdk/comment/comment-editor.js +0 -73
- package/dist/basic-sdk/hooks/use-font-color-context.js +0 -28
- package/dist/basic-sdk/hooks/use-highlight-color-context.js +0 -28
|
@@ -110,6 +110,64 @@ var SDocServerApi = /*#__PURE__*/function () {
|
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "updateCommentState",
|
|
115
|
+
value: function updateCommentState(commentId, resolved) {
|
|
116
|
+
var server = this.server,
|
|
117
|
+
docUuid = this.docUuid,
|
|
118
|
+
accessToken = this.accessToken;
|
|
119
|
+
var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/comment/").concat(commentId, "/");
|
|
120
|
+
var newComment = {};
|
|
121
|
+
if (resolved) {
|
|
122
|
+
newComment.resolved = 'true';
|
|
123
|
+
} else {
|
|
124
|
+
newComment.resolved = 'false';
|
|
125
|
+
}
|
|
126
|
+
return axios.put(url, newComment, {
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: "Token ".concat(accessToken)
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "insertReply",
|
|
134
|
+
value: function insertReply(commentId, reply) {
|
|
135
|
+
var server = this.server,
|
|
136
|
+
docUuid = this.docUuid,
|
|
137
|
+
accessToken = this.accessToken;
|
|
138
|
+
var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/comment/").concat(commentId, "/replies/");
|
|
139
|
+
return axios.post(url, reply, {
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: "Token ".concat(accessToken)
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}, {
|
|
146
|
+
key: "deleteReply",
|
|
147
|
+
value: function deleteReply(commentId, replyId) {
|
|
148
|
+
var server = this.server,
|
|
149
|
+
docUuid = this.docUuid,
|
|
150
|
+
accessToken = this.accessToken;
|
|
151
|
+
var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/comment/").concat(commentId, "/replies/").concat(replyId, "/");
|
|
152
|
+
return axios.delete(url, {
|
|
153
|
+
headers: {
|
|
154
|
+
Authorization: "Token ".concat(accessToken)
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}, {
|
|
159
|
+
key: "updateReply",
|
|
160
|
+
value: function updateReply(commentId, replyId, reply) {
|
|
161
|
+
var server = this.server,
|
|
162
|
+
docUuid = this.docUuid,
|
|
163
|
+
accessToken = this.accessToken;
|
|
164
|
+
var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/comment/").concat(commentId, "/replies/").concat(replyId, "/");
|
|
165
|
+
return axios.put(url, reply, {
|
|
166
|
+
headers: {
|
|
167
|
+
Authorization: "Token ".concat(accessToken)
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
113
171
|
}]);
|
|
114
172
|
return SDocServerApi;
|
|
115
173
|
}();
|
package/dist/api/seafile-api.js
CHANGED
|
@@ -55,7 +55,7 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
55
55
|
}, {
|
|
56
56
|
key: "startRevise",
|
|
57
57
|
value: function startRevise(repoID, fileUuid, path) {
|
|
58
|
-
var url = '/api/v2.1/seadoc/
|
|
58
|
+
var url = '/api/v2.1/seadoc/start-revise/';
|
|
59
59
|
var form = new FormData();
|
|
60
60
|
form.append('p', path);
|
|
61
61
|
form.append('repo_id', repoID);
|
|
@@ -68,6 +68,19 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
68
68
|
var url = '/api/v2.1/seadoc/revision/download-links/' + docUuid + '/';
|
|
69
69
|
return this.req.get(url);
|
|
70
70
|
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "getSdocRevisionsCount",
|
|
73
|
+
value: function getSdocRevisionsCount(docUuid) {
|
|
74
|
+
var url = 'api/v2.1/seadoc/revisions-count/' + docUuid + '/';
|
|
75
|
+
return this.req.get(url);
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "getSdocRevisions",
|
|
79
|
+
value: function getSdocRevisions(docUuid, page) {
|
|
80
|
+
var perPage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 25;
|
|
81
|
+
var url = 'api/v2.1/seadoc/revisions/' + docUuid + '/?page=' + page + '&per_page=' + perPage;
|
|
82
|
+
return this.req.get(url);
|
|
83
|
+
}
|
|
71
84
|
}]);
|
|
72
85
|
return SeafileAPI;
|
|
73
86
|
}();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
3
|
+
import { withTranslation } from 'react-i18next';
|
|
4
|
+
var CommentEditor = function CommentEditor(_ref) {
|
|
5
|
+
var content = _ref.content,
|
|
6
|
+
placeholder = _ref.placeholder,
|
|
7
|
+
insertContent = _ref.insertContent,
|
|
8
|
+
updateContent = _ref.updateContent,
|
|
9
|
+
t = _ref.t;
|
|
10
|
+
var inputRef = useRef();
|
|
11
|
+
var _useState = useState(content || ''),
|
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
13
|
+
value = _useState2[0],
|
|
14
|
+
setValue = _useState2[1];
|
|
15
|
+
var onChange = useCallback(function (event) {
|
|
16
|
+
setValue(event.target.value);
|
|
17
|
+
}, []);
|
|
18
|
+
var updateValue = useCallback(function (value) {
|
|
19
|
+
if (!value || value.trim() === '') return;
|
|
20
|
+
if (!content) {
|
|
21
|
+
insertContent(value);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
updateContent(value);
|
|
25
|
+
}, [content, insertContent, updateContent]);
|
|
26
|
+
var onBlur = useCallback(function () {
|
|
27
|
+
updateValue(value);
|
|
28
|
+
setValue('');
|
|
29
|
+
}, [updateValue, value]);
|
|
30
|
+
var onKeyDown = useCallback(function (event) {
|
|
31
|
+
// enter
|
|
32
|
+
if (event.keyCode === 13) {
|
|
33
|
+
inputRef.current.blur();
|
|
34
|
+
}
|
|
35
|
+
if (event.keyCode === 27) {
|
|
36
|
+
setValue('');
|
|
37
|
+
}
|
|
38
|
+
}, []);
|
|
39
|
+
placeholder = t(placeholder);
|
|
40
|
+
return /*#__PURE__*/React.createElement("input", {
|
|
41
|
+
ref: inputRef,
|
|
42
|
+
className: "comment-editor",
|
|
43
|
+
value: value,
|
|
44
|
+
placeholder: placeholder,
|
|
45
|
+
onChange: onChange,
|
|
46
|
+
onKeyDown: onKeyDown,
|
|
47
|
+
onBlur: onBlur
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
CommentEditor.defaultProps = {
|
|
51
|
+
placeholder: 'Enter_a_comment'
|
|
52
|
+
};
|
|
53
|
+
export default withTranslation('sdoc-editor')(CommentEditor);
|
|
@@ -4,9 +4,10 @@ import { withTranslation } from 'react-i18next';
|
|
|
4
4
|
import { PopoverBody, UncontrolledPopover } from 'reactstrap';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import CommentEditor from './comment-editor';
|
|
7
|
-
import DeleteCommentDialog from '
|
|
7
|
+
import DeleteCommentDialog from '../dialogs/delete-comment-dialog';
|
|
8
8
|
var CommentItem = function CommentItem(_ref) {
|
|
9
9
|
var comment = _ref.comment,
|
|
10
|
+
selectionElement = _ref.selectionElement,
|
|
10
11
|
updateComment = _ref.updateComment,
|
|
11
12
|
deleteComment = _ref.deleteComment,
|
|
12
13
|
t = _ref.t;
|
|
@@ -43,12 +44,22 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
43
44
|
deleteComment(comment.id);
|
|
44
45
|
setIsShowDeleteDialog(false);
|
|
45
46
|
}, [comment.id, deleteComment]);
|
|
46
|
-
var
|
|
47
|
-
if (
|
|
48
|
-
|
|
47
|
+
var updateContent = useCallback(function (content) {
|
|
48
|
+
if (comment.comment !== content) {
|
|
49
|
+
var elementId = selectionElement.id;
|
|
50
|
+
var time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
51
|
+
var newComment = {
|
|
52
|
+
comment: content,
|
|
53
|
+
detail: {
|
|
54
|
+
element_id: elementId,
|
|
55
|
+
comment: content
|
|
56
|
+
},
|
|
57
|
+
updated_at: time
|
|
58
|
+
};
|
|
59
|
+
updateComment(elementId, comment.id, newComment);
|
|
49
60
|
}
|
|
50
61
|
setIsEditing(false);
|
|
51
|
-
}, [
|
|
62
|
+
}, [comment, selectionElement.id, updateComment]);
|
|
52
63
|
var menuId = useMemo(function () {
|
|
53
64
|
return "comment_".concat(comment.id);
|
|
54
65
|
}, [comment]);
|
|
@@ -66,8 +77,12 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
66
77
|
alt: "",
|
|
67
78
|
src: comment.avatar_url
|
|
68
79
|
})), /*#__PURE__*/React.createElement("span", {
|
|
69
|
-
className: "comment-
|
|
70
|
-
},
|
|
80
|
+
className: "comment-author__info"
|
|
81
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
82
|
+
className: "name"
|
|
83
|
+
}, comment.user_name), /*#__PURE__*/React.createElement("span", {
|
|
84
|
+
className: "time"
|
|
85
|
+
}, dayjs(comment.updated_at).format('MM-DD HH:mm')))), isActive && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
71
86
|
id: menuId,
|
|
72
87
|
className: "comment-operation"
|
|
73
88
|
}, /*#__PURE__*/React.createElement("i", {
|
|
@@ -77,7 +92,8 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
77
92
|
trigger: "legacy",
|
|
78
93
|
target: menuId,
|
|
79
94
|
placement: "bottom-end",
|
|
80
|
-
hideArrow: true
|
|
95
|
+
hideArrow: true,
|
|
96
|
+
container: 'comment-item-wrapper'
|
|
81
97
|
}, /*#__PURE__*/React.createElement(PopoverBody, {
|
|
82
98
|
className: "sdoc-comment-menu"
|
|
83
99
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -88,15 +104,14 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
88
104
|
}, t('Edit')), /*#__PURE__*/React.createElement("div", {
|
|
89
105
|
className: "sdoc-popover-menu__item",
|
|
90
106
|
onClick: onDeleteToggle
|
|
91
|
-
}, t('Delete')))))),
|
|
92
|
-
className: "comment-time"
|
|
93
|
-
}, dayjs(comment.updated_at).format('MM-DD HH:mm'))), /*#__PURE__*/React.createElement("div", {
|
|
107
|
+
}, t('Delete'))))))), /*#__PURE__*/React.createElement("div", {
|
|
94
108
|
className: "comment-content"
|
|
95
109
|
}, isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
content: comment.comment,
|
|
111
|
+
updateContent: updateContent
|
|
98
112
|
}), !isEditing && /*#__PURE__*/React.createElement(React.Fragment, null, comment.comment))), isShowDeleteDialog && /*#__PURE__*/React.createElement(DeleteCommentDialog, {
|
|
99
|
-
|
|
113
|
+
type: 'comment',
|
|
114
|
+
deleteConfirm: _deleteComment,
|
|
100
115
|
setIsShowDeleteModal: setIsShowDeleteDialog
|
|
101
116
|
}));
|
|
102
117
|
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { withTranslation } from 'react-i18next';
|
|
4
|
+
import { PopoverBody, UncontrolledPopover } from 'reactstrap';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import CommentEditor from './comment-editor';
|
|
7
|
+
import DeleteCommentDialog from '../dialogs/delete-comment-dialog';
|
|
8
|
+
var CommentReplyItem = function CommentReplyItem(_ref) {
|
|
9
|
+
var reply = _ref.reply,
|
|
10
|
+
deleteReply = _ref.deleteReply,
|
|
11
|
+
updateReply = _ref.updateReply,
|
|
12
|
+
t = _ref.t;
|
|
13
|
+
var popoverRef = useRef(null);
|
|
14
|
+
var _useState = useState(false),
|
|
15
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
+
isActive = _useState2[0],
|
|
17
|
+
setActive = _useState2[1];
|
|
18
|
+
var onMouseEnter = useCallback(function () {
|
|
19
|
+
setActive(true);
|
|
20
|
+
}, []);
|
|
21
|
+
var onMouseLeave = useCallback(function () {
|
|
22
|
+
setActive(false);
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
// const [isShowItemMenu, setIsShowItemMenu] = useState(false);
|
|
26
|
+
var _useState3 = useState(false),
|
|
27
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
|
+
isEditing = _useState4[0],
|
|
29
|
+
setIsEditing = _useState4[1];
|
|
30
|
+
var onEditToggle = useCallback(function () {
|
|
31
|
+
setIsEditing(true);
|
|
32
|
+
popoverRef.current.toggle();
|
|
33
|
+
}, []);
|
|
34
|
+
var _useState5 = useState(false),
|
|
35
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
36
|
+
isShowDeleteDialog = _useState6[0],
|
|
37
|
+
setIsShowDeleteDialog = _useState6[1];
|
|
38
|
+
var onDeleteToggle = useCallback(function () {
|
|
39
|
+
setIsShowDeleteDialog(true);
|
|
40
|
+
popoverRef.current.toggle();
|
|
41
|
+
}, []);
|
|
42
|
+
var _deleteReply = useCallback(function () {
|
|
43
|
+
deleteReply(reply.id);
|
|
44
|
+
setIsShowDeleteDialog(false);
|
|
45
|
+
}, [reply.id, deleteReply]);
|
|
46
|
+
var updateContent = useCallback(function (content) {
|
|
47
|
+
if (reply.reply !== content) {
|
|
48
|
+
var time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
49
|
+
var newReply = {
|
|
50
|
+
reply: content,
|
|
51
|
+
updated_at: time
|
|
52
|
+
};
|
|
53
|
+
updateReply(reply.id, newReply);
|
|
54
|
+
}
|
|
55
|
+
setIsEditing(false);
|
|
56
|
+
}, [reply, updateReply]);
|
|
57
|
+
var menuId = useMemo(function () {
|
|
58
|
+
return "reply_".concat(reply.id);
|
|
59
|
+
}, [reply]);
|
|
60
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("li", {
|
|
61
|
+
className: "comment-item",
|
|
62
|
+
onMouseEnter: onMouseEnter,
|
|
63
|
+
onMouseLeave: onMouseLeave
|
|
64
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
className: "comment-header"
|
|
66
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
67
|
+
className: "comment-author"
|
|
68
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
69
|
+
className: "comment-author__avatar"
|
|
70
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
71
|
+
alt: "",
|
|
72
|
+
src: reply.avatar_url
|
|
73
|
+
})), /*#__PURE__*/React.createElement("span", {
|
|
74
|
+
className: "comment-author__info"
|
|
75
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
76
|
+
className: "name"
|
|
77
|
+
}, reply.user_name), /*#__PURE__*/React.createElement("span", {
|
|
78
|
+
className: "time"
|
|
79
|
+
}, dayjs(reply.updated_at).format('MM-DD HH:mm')))), isActive && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
80
|
+
id: menuId,
|
|
81
|
+
className: "comment-operation"
|
|
82
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
83
|
+
className: "sdocfont sdoc-more mr-1"
|
|
84
|
+
})), /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
85
|
+
ref: popoverRef,
|
|
86
|
+
trigger: "legacy",
|
|
87
|
+
target: menuId,
|
|
88
|
+
placement: "bottom-end",
|
|
89
|
+
hideArrow: true,
|
|
90
|
+
container: 'comment-item-wrapper'
|
|
91
|
+
}, /*#__PURE__*/React.createElement(PopoverBody, {
|
|
92
|
+
className: "sdoc-comment-menu"
|
|
93
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
94
|
+
className: "sdoc-popover-menu"
|
|
95
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
className: "sdoc-popover-menu__item",
|
|
97
|
+
onClick: onEditToggle
|
|
98
|
+
}, t('Edit')), /*#__PURE__*/React.createElement("div", {
|
|
99
|
+
className: "sdoc-popover-menu__item",
|
|
100
|
+
onClick: onDeleteToggle
|
|
101
|
+
}, t('Delete'))))))), /*#__PURE__*/React.createElement("div", {
|
|
102
|
+
className: "comment-content"
|
|
103
|
+
}, isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
104
|
+
content: reply.reply,
|
|
105
|
+
updateContent: updateContent
|
|
106
|
+
}), !isEditing && /*#__PURE__*/React.createElement(React.Fragment, null, reply.reply))), isShowDeleteDialog && /*#__PURE__*/React.createElement(DeleteCommentDialog, {
|
|
107
|
+
type: "reply",
|
|
108
|
+
deleteConfirm: _deleteReply,
|
|
109
|
+
setIsShowDeleteModal: setIsShowDeleteDialog
|
|
110
|
+
}));
|
|
111
|
+
};
|
|
112
|
+
export default withTranslation('sdoc-editor')(CommentReplyItem);
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
|
+
import React, { useCallback, useRef } from 'react';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import context from '../../../context';
|
|
7
|
+
import { useCommentContext } from '../hooks/use-comment-context';
|
|
8
|
+
import CommentItemContent from './comment-item-content';
|
|
9
|
+
import CommentItemReply from './comment-item-reply';
|
|
10
|
+
import CommentEditor from './comment-editor';
|
|
11
|
+
export default function CommentItemWrapper(_ref) {
|
|
12
|
+
var isActive = _ref.isActive,
|
|
13
|
+
comment = _ref.comment,
|
|
14
|
+
selectionElement = _ref.selectionElement,
|
|
15
|
+
onCommentClick = _ref.onCommentClick;
|
|
16
|
+
var listRef = useRef(null);
|
|
17
|
+
var _useCommentContext = useCommentContext(),
|
|
18
|
+
dispatch = _useCommentContext.dispatch;
|
|
19
|
+
var deleteComment = useCallback( /*#__PURE__*/function () {
|
|
20
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(commentId) {
|
|
21
|
+
var elementId;
|
|
22
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
23
|
+
while (1) switch (_context.prev = _context.next) {
|
|
24
|
+
case 0:
|
|
25
|
+
elementId = selectionElement.id;
|
|
26
|
+
_context.next = 3;
|
|
27
|
+
return context.deleteComment(commentId);
|
|
28
|
+
case 3:
|
|
29
|
+
dispatch({
|
|
30
|
+
type: 'DELETE_COMMENT',
|
|
31
|
+
payload: {
|
|
32
|
+
element_id: elementId,
|
|
33
|
+
comment_id: commentId
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
case 4:
|
|
37
|
+
case "end":
|
|
38
|
+
return _context.stop();
|
|
39
|
+
}
|
|
40
|
+
}, _callee);
|
|
41
|
+
}));
|
|
42
|
+
return function (_x) {
|
|
43
|
+
return _ref2.apply(this, arguments);
|
|
44
|
+
};
|
|
45
|
+
}(), [dispatch, selectionElement]);
|
|
46
|
+
var updateComment = useCallback( /*#__PURE__*/function () {
|
|
47
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(elementId, commentId, newComment) {
|
|
48
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
49
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
_context2.next = 2;
|
|
52
|
+
return context.updateComment(commentId, newComment);
|
|
53
|
+
case 2:
|
|
54
|
+
dispatch({
|
|
55
|
+
type: 'UPDATE_COMMENT',
|
|
56
|
+
payload: {
|
|
57
|
+
element_id: elementId,
|
|
58
|
+
comment_id: commentId,
|
|
59
|
+
comment: newComment
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
case 3:
|
|
63
|
+
case "end":
|
|
64
|
+
return _context2.stop();
|
|
65
|
+
}
|
|
66
|
+
}, _callee2);
|
|
67
|
+
}));
|
|
68
|
+
return function (_x2, _x3, _x4) {
|
|
69
|
+
return _ref3.apply(this, arguments);
|
|
70
|
+
};
|
|
71
|
+
}(), [dispatch]);
|
|
72
|
+
var insertReply = useCallback( /*#__PURE__*/function () {
|
|
73
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(elementId, commentId, reply) {
|
|
74
|
+
var res, returnReply, newReply;
|
|
75
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
76
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
77
|
+
case 0:
|
|
78
|
+
_context3.next = 2;
|
|
79
|
+
return context.insertReply(commentId, reply);
|
|
80
|
+
case 2:
|
|
81
|
+
res = _context3.sent;
|
|
82
|
+
returnReply = res.data.reply;
|
|
83
|
+
newReply = _objectSpread(_objectSpread({}, reply), {}, {
|
|
84
|
+
id: returnReply.id,
|
|
85
|
+
user_name: returnReply.user_name,
|
|
86
|
+
avatar_url: returnReply.avatar_url
|
|
87
|
+
});
|
|
88
|
+
dispatch({
|
|
89
|
+
type: 'INSERT_REPLY',
|
|
90
|
+
payload: {
|
|
91
|
+
element_id: elementId,
|
|
92
|
+
comment_id: commentId,
|
|
93
|
+
reply: newReply
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
setTimeout(function () {
|
|
97
|
+
listRef.current.scrollTop = 10000;
|
|
98
|
+
}, 0);
|
|
99
|
+
case 7:
|
|
100
|
+
case "end":
|
|
101
|
+
return _context3.stop();
|
|
102
|
+
}
|
|
103
|
+
}, _callee3);
|
|
104
|
+
}));
|
|
105
|
+
return function (_x5, _x6, _x7) {
|
|
106
|
+
return _ref4.apply(this, arguments);
|
|
107
|
+
};
|
|
108
|
+
}(), [dispatch]);
|
|
109
|
+
var insertContent = useCallback(function (content) {
|
|
110
|
+
var user = context.getUserInfo();
|
|
111
|
+
var elementId = selectionElement.id;
|
|
112
|
+
var time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
113
|
+
var reply = {
|
|
114
|
+
type: 'reply',
|
|
115
|
+
reply: content,
|
|
116
|
+
updated_at: time,
|
|
117
|
+
author: user.username
|
|
118
|
+
};
|
|
119
|
+
insertReply(elementId, comment.id, reply);
|
|
120
|
+
}, [comment, insertReply, selectionElement.id]);
|
|
121
|
+
var deleteReply = useCallback( /*#__PURE__*/function () {
|
|
122
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(replyId) {
|
|
123
|
+
var elementId;
|
|
124
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
125
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
126
|
+
case 0:
|
|
127
|
+
elementId = selectionElement.id;
|
|
128
|
+
_context4.next = 3;
|
|
129
|
+
return context.deleteReply(comment.id, replyId);
|
|
130
|
+
case 3:
|
|
131
|
+
dispatch({
|
|
132
|
+
type: 'DELETE_REPLY',
|
|
133
|
+
payload: {
|
|
134
|
+
element_id: elementId,
|
|
135
|
+
comment_id: comment.id,
|
|
136
|
+
reply_id: replyId
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
case 4:
|
|
140
|
+
case "end":
|
|
141
|
+
return _context4.stop();
|
|
142
|
+
}
|
|
143
|
+
}, _callee4);
|
|
144
|
+
}));
|
|
145
|
+
return function (_x8) {
|
|
146
|
+
return _ref5.apply(this, arguments);
|
|
147
|
+
};
|
|
148
|
+
}(), [comment.id, dispatch, selectionElement.id]);
|
|
149
|
+
var updateReply = useCallback( /*#__PURE__*/function () {
|
|
150
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(replyId, newReply) {
|
|
151
|
+
var elementId, commentId;
|
|
152
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
153
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
154
|
+
case 0:
|
|
155
|
+
elementId = selectionElement.id;
|
|
156
|
+
commentId = comment.id;
|
|
157
|
+
_context5.next = 4;
|
|
158
|
+
return context.updateReply(commentId, replyId, newReply);
|
|
159
|
+
case 4:
|
|
160
|
+
dispatch({
|
|
161
|
+
type: 'UPDATE_REPLY',
|
|
162
|
+
payload: {
|
|
163
|
+
element_id: elementId,
|
|
164
|
+
comment_id: commentId,
|
|
165
|
+
reply_id: replyId,
|
|
166
|
+
reply: newReply
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
case 5:
|
|
170
|
+
case "end":
|
|
171
|
+
return _context5.stop();
|
|
172
|
+
}
|
|
173
|
+
}, _callee5);
|
|
174
|
+
}));
|
|
175
|
+
return function (_x9, _x10) {
|
|
176
|
+
return _ref6.apply(this, arguments);
|
|
177
|
+
};
|
|
178
|
+
}(), [comment.id, dispatch, selectionElement.id]);
|
|
179
|
+
var onItemClick = useCallback(function () {
|
|
180
|
+
onCommentClick(comment);
|
|
181
|
+
}, [comment, onCommentClick]);
|
|
182
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
183
|
+
id: "comment-item-wrapper",
|
|
184
|
+
className: "comment-ui-container ".concat(isActive ? 'active' : ''),
|
|
185
|
+
onClick: onItemClick
|
|
186
|
+
}, /*#__PURE__*/React.createElement("ul", {
|
|
187
|
+
ref: listRef,
|
|
188
|
+
className: "comment-item-list"
|
|
189
|
+
}, /*#__PURE__*/React.createElement(CommentItemContent, {
|
|
190
|
+
key: comment.id,
|
|
191
|
+
comment: comment,
|
|
192
|
+
selectionElement: selectionElement,
|
|
193
|
+
deleteComment: deleteComment,
|
|
194
|
+
updateComment: updateComment
|
|
195
|
+
}), comment.replies && comment.replies.length > 0 && comment.replies.map(function (reply) {
|
|
196
|
+
return /*#__PURE__*/React.createElement(CommentItemReply, {
|
|
197
|
+
key: reply.id,
|
|
198
|
+
reply: reply,
|
|
199
|
+
deleteReply: deleteReply,
|
|
200
|
+
updateReply: updateReply
|
|
201
|
+
});
|
|
202
|
+
})), isActive && /*#__PURE__*/React.createElement("div", {
|
|
203
|
+
className: "comment-editor-wrapper mt-4"
|
|
204
|
+
}, /*#__PURE__*/React.createElement(CommentEditor, {
|
|
205
|
+
placeholder: 'Enter_a_reply',
|
|
206
|
+
insertContent: insertContent
|
|
207
|
+
})));
|
|
208
|
+
}
|