@seafile/sdoc-editor 0.1.98 → 0.1.100
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/assets/css/simple-editor.css +3 -1
- package/dist/basic-sdk/comment/comment/comment-item-content.js +28 -15
- package/dist/basic-sdk/comment/comment/comment-item-reply.js +7 -4
- package/dist/basic-sdk/comment/comment/comment-item-resolved-reply.js +28 -0
- package/dist/basic-sdk/comment/comment/comment-item-wrapper.js +135 -53
- package/dist/basic-sdk/comment/comment/comment-list.css +165 -0
- package/dist/basic-sdk/comment/comment/comment-list.js +9 -7
- package/dist/basic-sdk/comment/comment/editor-comment.js +66 -0
- package/dist/basic-sdk/comment/comment/global-comment-header.js +66 -0
- package/dist/basic-sdk/comment/comment/global-comment.js +94 -0
- package/dist/basic-sdk/comment/comment/index.js +3 -66
- package/dist/basic-sdk/comment/comment/style.css +66 -125
- package/dist/basic-sdk/comment/comment-decorate.js +5 -2
- package/dist/basic-sdk/comment/hooks/use-comment-list.js +39 -0
- package/dist/basic-sdk/comment/index.js +2 -2
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +143 -35
- package/dist/components/doc-operations/comments-operation/index.js +14 -0
- package/dist/components/doc-operations/index.js +3 -2
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +8 -0
- package/public/locales/zh-CN/sdoc-editor.json +8 -0
|
@@ -31,12 +31,14 @@
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/* reset common css */
|
|
34
|
-
.sdoc-editor-page-wrapper
|
|
34
|
+
.sdoc-editor-page-wrapper .dropdown-item,
|
|
35
|
+
.sdoc-comment-list-menu .dropdown-item,
|
|
35
36
|
.sdoc-context-menu .dropdown-item {
|
|
36
37
|
color: #212529;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
.sdoc-editor-page-wrapper .dropdown-item:hover,
|
|
41
|
+
.sdoc-comment-list-menu .dropdown-item:hover,
|
|
40
42
|
.sdoc-context-menu .dropdown-item:hover {
|
|
41
43
|
color: #fff;
|
|
42
44
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
4
|
import { withTranslation } from 'react-i18next';
|
|
@@ -7,8 +8,8 @@ import CommentEditor from './comment-editor';
|
|
|
7
8
|
import DeleteCommentDialog from '../dialogs/delete-comment-dialog';
|
|
8
9
|
var CommentItem = function CommentItem(_ref) {
|
|
9
10
|
var isActive = _ref.isActive,
|
|
11
|
+
container = _ref.container,
|
|
10
12
|
comment = _ref.comment,
|
|
11
|
-
selectionElement = _ref.selectionElement,
|
|
12
13
|
updateComment = _ref.updateComment,
|
|
13
14
|
updateCommentState = _ref.updateCommentState,
|
|
14
15
|
deleteComment = _ref.deleteComment,
|
|
@@ -49,28 +50,34 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
49
50
|
setIsShowDeleteDialog(false);
|
|
50
51
|
}, [comment.id, deleteComment]);
|
|
51
52
|
var updateContent = useCallback(function (content) {
|
|
53
|
+
var commentId = comment.id;
|
|
52
54
|
if (comment.comment !== content) {
|
|
53
|
-
var elementId = selectionElement.id;
|
|
54
55
|
var time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
55
56
|
var newComment = {
|
|
56
57
|
comment: content,
|
|
57
|
-
detail: {
|
|
58
|
-
element_id: elementId,
|
|
58
|
+
detail: _objectSpread(_objectSpread({}, comment.detail), {}, {
|
|
59
59
|
comment: content
|
|
60
|
-
},
|
|
60
|
+
}),
|
|
61
61
|
updated_at: time
|
|
62
62
|
};
|
|
63
|
-
updateComment(
|
|
63
|
+
updateComment(commentId, newComment);
|
|
64
64
|
}
|
|
65
65
|
setIsEditing(false);
|
|
66
|
-
}, [comment,
|
|
67
|
-
var updateCommentResolved = useCallback(function () {
|
|
68
|
-
var
|
|
66
|
+
}, [comment, updateComment]);
|
|
67
|
+
var updateCommentResolved = useCallback(function (state) {
|
|
68
|
+
var commentId = comment.id;
|
|
69
69
|
var newComment = {
|
|
70
|
-
resolved:
|
|
70
|
+
resolved: state
|
|
71
71
|
};
|
|
72
|
-
updateCommentState(
|
|
73
|
-
}, [comment.id,
|
|
72
|
+
updateCommentState(commentId, newComment);
|
|
73
|
+
}, [comment.id, updateCommentState]);
|
|
74
|
+
var markAsResolved = useCallback(function () {
|
|
75
|
+
updateCommentResolved(true);
|
|
76
|
+
}, [updateCommentResolved]);
|
|
77
|
+
var resubmit = useCallback(function () {
|
|
78
|
+
updateCommentResolved(false);
|
|
79
|
+
popoverRef.current.toggle();
|
|
80
|
+
}, [updateCommentResolved]);
|
|
74
81
|
var menuId = useMemo(function () {
|
|
75
82
|
return "comment_".concat(comment.id);
|
|
76
83
|
}, [comment]);
|
|
@@ -97,7 +104,7 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
97
104
|
className: "d-flex"
|
|
98
105
|
}, !comment.resolved && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
99
106
|
className: "comment-operation mr-2",
|
|
100
|
-
onClick:
|
|
107
|
+
onClick: markAsResolved
|
|
101
108
|
}, /*#__PURE__*/React.createElement("i", {
|
|
102
109
|
id: "tooltip_".concat(menuId),
|
|
103
110
|
className: "sdocfont sdoc-confirm"
|
|
@@ -120,7 +127,7 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
120
127
|
target: menuId,
|
|
121
128
|
placement: "bottom-end",
|
|
122
129
|
hideArrow: true,
|
|
123
|
-
container:
|
|
130
|
+
container: container
|
|
124
131
|
}, /*#__PURE__*/React.createElement(PopoverBody, {
|
|
125
132
|
className: "sdoc-comment-menu"
|
|
126
133
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -131,7 +138,13 @@ var CommentItem = function CommentItem(_ref) {
|
|
|
131
138
|
}, t('Edit')), /*#__PURE__*/React.createElement("div", {
|
|
132
139
|
className: "sdoc-popover-menu__item",
|
|
133
140
|
onClick: onDeleteToggle
|
|
134
|
-
}, t('Delete'))
|
|
141
|
+
}, t('Delete')), !comment.resolved && /*#__PURE__*/React.createElement("div", {
|
|
142
|
+
className: "sdoc-popover-menu__item",
|
|
143
|
+
onClick: markAsResolved
|
|
144
|
+
}, t('Mark_as_Resolved')), comment.resolved && /*#__PURE__*/React.createElement("div", {
|
|
145
|
+
className: "sdoc-popover-menu__item",
|
|
146
|
+
onClick: resubmit
|
|
147
|
+
}, t('Resubmit'))))))), /*#__PURE__*/React.createElement("div", {
|
|
135
148
|
className: "comment-content"
|
|
136
149
|
}, isEditing && /*#__PURE__*/React.createElement(CommentEditor, {
|
|
137
150
|
content: comment.comment,
|
|
@@ -3,10 +3,12 @@ import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
|
|
|
3
3
|
import { withTranslation } from 'react-i18next';
|
|
4
4
|
import { PopoverBody, UncontrolledPopover } from 'reactstrap';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
|
+
import context from '../../../context';
|
|
6
7
|
import CommentEditor from './comment-editor';
|
|
7
8
|
import DeleteCommentDialog from '../dialogs/delete-comment-dialog';
|
|
8
|
-
var
|
|
9
|
+
var CommentItemReply = function CommentItemReply(_ref) {
|
|
9
10
|
var isActive = _ref.isActive,
|
|
11
|
+
container = _ref.container,
|
|
10
12
|
reply = _ref.reply,
|
|
11
13
|
deleteReply = _ref.deleteReply,
|
|
12
14
|
updateReply = _ref.updateReply,
|
|
@@ -60,6 +62,7 @@ var CommentReplyItem = function CommentReplyItem(_ref) {
|
|
|
60
62
|
var menuId = useMemo(function () {
|
|
61
63
|
return "reply_".concat(reply.id);
|
|
62
64
|
}, [reply]);
|
|
65
|
+
var user = context.getUserInfo();
|
|
63
66
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("li", {
|
|
64
67
|
className: "comment-item",
|
|
65
68
|
onMouseEnter: onMouseEnter,
|
|
@@ -79,7 +82,7 @@ var CommentReplyItem = function CommentReplyItem(_ref) {
|
|
|
79
82
|
className: "name"
|
|
80
83
|
}, reply.user_name), /*#__PURE__*/React.createElement("span", {
|
|
81
84
|
className: "time"
|
|
82
|
-
}, dayjs(reply.updated_at).format('MM-DD HH:mm')))), isMouseOver && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
}, dayjs(reply.updated_at).format('MM-DD HH:mm')))), isMouseOver && user.username === reply.author && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
83
86
|
id: menuId,
|
|
84
87
|
className: "comment-operation"
|
|
85
88
|
}, /*#__PURE__*/React.createElement("i", {
|
|
@@ -90,7 +93,7 @@ var CommentReplyItem = function CommentReplyItem(_ref) {
|
|
|
90
93
|
target: menuId,
|
|
91
94
|
placement: "bottom-end",
|
|
92
95
|
hideArrow: true,
|
|
93
|
-
container:
|
|
96
|
+
container: container
|
|
94
97
|
}, /*#__PURE__*/React.createElement(PopoverBody, {
|
|
95
98
|
className: "sdoc-comment-menu"
|
|
96
99
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -113,4 +116,4 @@ var CommentReplyItem = function CommentReplyItem(_ref) {
|
|
|
113
116
|
setIsShowDeleteModal: setIsShowDeleteDialog
|
|
114
117
|
}));
|
|
115
118
|
};
|
|
116
|
-
export default withTranslation('sdoc-editor')(
|
|
119
|
+
export default withTranslation('sdoc-editor')(CommentItemReply);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
|
+
import { withTranslation } from 'react-i18next';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
var CommentItemResolvedReply = function CommentItemResolvedReply(_ref) {
|
|
5
|
+
var reply = _ref.reply,
|
|
6
|
+
t = _ref.t;
|
|
7
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("li", {
|
|
8
|
+
className: "comment-item"
|
|
9
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
10
|
+
className: "comment-header"
|
|
11
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
12
|
+
className: "comment-author"
|
|
13
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
14
|
+
className: "comment-author__avatar"
|
|
15
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
16
|
+
alt: "",
|
|
17
|
+
src: reply.avatar_url
|
|
18
|
+
})), /*#__PURE__*/React.createElement("span", {
|
|
19
|
+
className: "comment-author__info"
|
|
20
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
21
|
+
className: "name"
|
|
22
|
+
}, reply.user_name), /*#__PURE__*/React.createElement("span", {
|
|
23
|
+
className: "time"
|
|
24
|
+
}, dayjs(reply.updated_at).format('MM-DD HH:mm'))))), /*#__PURE__*/React.createElement("div", {
|
|
25
|
+
className: "comment-content"
|
|
26
|
+
}, reply.reply === 'True' && /*#__PURE__*/React.createElement("div", null, t('Mark_as_Resolved')), reply.reply === 'False' && /*#__PURE__*/React.createElement("div", null, t('Resubmitted')))));
|
|
27
|
+
};
|
|
28
|
+
export default withTranslation('sdoc-editor')(CommentItemResolvedReply);
|
|
@@ -3,16 +3,19 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
3
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
4
|
import React, { useCallback, useRef } from 'react';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
|
+
import classNames from 'classnames';
|
|
6
7
|
import context from '../../../context';
|
|
7
8
|
import { useCommentContext } from '../hooks/use-comment-context';
|
|
8
9
|
import CommentItemContent from './comment-item-content';
|
|
9
10
|
import CommentItemReply from './comment-item-reply';
|
|
10
11
|
import CommentEditor from './comment-editor';
|
|
12
|
+
import CommentItemResolvedReply from './comment-item-resolved-reply';
|
|
11
13
|
export default function CommentItemWrapper(_ref) {
|
|
12
|
-
var
|
|
14
|
+
var container = _ref.container,
|
|
15
|
+
isActive = _ref.isActive,
|
|
13
16
|
comment = _ref.comment,
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
onCommentClick = _ref.onCommentClick,
|
|
18
|
+
updateScrollPosition = _ref.updateScrollPosition;
|
|
16
19
|
var listRef = useRef(null);
|
|
17
20
|
var _useCommentContext = useCommentContext(),
|
|
18
21
|
dispatch = _useCommentContext.dispatch;
|
|
@@ -22,10 +25,10 @@ export default function CommentItemWrapper(_ref) {
|
|
|
22
25
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
23
26
|
while (1) switch (_context.prev = _context.next) {
|
|
24
27
|
case 0:
|
|
25
|
-
|
|
26
|
-
_context.next = 3;
|
|
28
|
+
_context.next = 2;
|
|
27
29
|
return context.deleteComment(commentId);
|
|
28
|
-
case
|
|
30
|
+
case 2:
|
|
31
|
+
elementId = comment.detail.element_id;
|
|
29
32
|
dispatch({
|
|
30
33
|
type: 'DELETE_COMMENT',
|
|
31
34
|
payload: {
|
|
@@ -42,15 +45,17 @@ export default function CommentItemWrapper(_ref) {
|
|
|
42
45
|
return function (_x) {
|
|
43
46
|
return _ref2.apply(this, arguments);
|
|
44
47
|
};
|
|
45
|
-
}(), [
|
|
48
|
+
}(), [comment.detail, dispatch]);
|
|
46
49
|
var updateComment = useCallback( /*#__PURE__*/function () {
|
|
47
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(
|
|
50
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(commentId, newComment) {
|
|
51
|
+
var elementId;
|
|
48
52
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
49
53
|
while (1) switch (_context2.prev = _context2.next) {
|
|
50
54
|
case 0:
|
|
51
55
|
_context2.next = 2;
|
|
52
56
|
return context.updateComment(commentId, newComment);
|
|
53
57
|
case 2:
|
|
58
|
+
elementId = comment.detail.element_id;
|
|
54
59
|
dispatch({
|
|
55
60
|
type: 'UPDATE_COMMENT',
|
|
56
61
|
payload: {
|
|
@@ -59,19 +64,19 @@ export default function CommentItemWrapper(_ref) {
|
|
|
59
64
|
comment: newComment
|
|
60
65
|
}
|
|
61
66
|
});
|
|
62
|
-
case
|
|
67
|
+
case 4:
|
|
63
68
|
case "end":
|
|
64
69
|
return _context2.stop();
|
|
65
70
|
}
|
|
66
71
|
}, _callee2);
|
|
67
72
|
}));
|
|
68
|
-
return function (_x2, _x3
|
|
73
|
+
return function (_x2, _x3) {
|
|
69
74
|
return _ref3.apply(this, arguments);
|
|
70
75
|
};
|
|
71
|
-
}(), [dispatch]);
|
|
76
|
+
}(), [comment.detail, dispatch]);
|
|
72
77
|
var updateCommentState = useCallback( /*#__PURE__*/function () {
|
|
73
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(
|
|
74
|
-
var time, user, reply, res, returnReply, newReply;
|
|
78
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(commentId, newComment) {
|
|
79
|
+
var time, user, reply, res, returnReply, newReply, elementId;
|
|
75
80
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
76
81
|
while (1) switch (_context3.prev = _context3.next) {
|
|
77
82
|
case 0:
|
|
@@ -82,7 +87,7 @@ export default function CommentItemWrapper(_ref) {
|
|
|
82
87
|
reply: newComment.resolved,
|
|
83
88
|
updated_at: time,
|
|
84
89
|
author: user.username
|
|
85
|
-
};
|
|
90
|
+
}; // When updating comment status, add a new reply
|
|
86
91
|
_context3.next = 5;
|
|
87
92
|
return context.insertReply(commentId, reply);
|
|
88
93
|
case 5:
|
|
@@ -90,20 +95,24 @@ export default function CommentItemWrapper(_ref) {
|
|
|
90
95
|
returnReply = res.data.reply;
|
|
91
96
|
newReply = _objectSpread(_objectSpread({}, reply), {}, {
|
|
92
97
|
id: returnReply.id,
|
|
98
|
+
reply: returnReply.reply,
|
|
93
99
|
user_name: returnReply.user_name,
|
|
94
100
|
avatar_url: returnReply.avatar_url
|
|
95
101
|
});
|
|
102
|
+
elementId = comment.detail.element_id;
|
|
96
103
|
dispatch({
|
|
97
|
-
type: '
|
|
104
|
+
type: 'INSERT_REPLY',
|
|
98
105
|
payload: {
|
|
99
106
|
element_id: elementId,
|
|
100
107
|
comment_id: commentId,
|
|
101
108
|
reply: newReply
|
|
102
109
|
}
|
|
103
110
|
});
|
|
104
|
-
|
|
111
|
+
|
|
112
|
+
// Modify comment status
|
|
113
|
+
_context3.next = 12;
|
|
105
114
|
return context.updateComment(commentId, newComment);
|
|
106
|
-
case
|
|
115
|
+
case 12:
|
|
107
116
|
dispatch({
|
|
108
117
|
type: 'UPDATE_COMMENT_STATE',
|
|
109
118
|
payload: {
|
|
@@ -112,29 +121,45 @@ export default function CommentItemWrapper(_ref) {
|
|
|
112
121
|
comment: newComment
|
|
113
122
|
}
|
|
114
123
|
});
|
|
115
|
-
|
|
124
|
+
|
|
125
|
+
// If the status of the comment is set to resolved, the page jumps to the position of the comment
|
|
126
|
+
if (newComment.resolved === true) {
|
|
127
|
+
setTimeout(function () {
|
|
128
|
+
updateScrollPosition && updateScrollPosition();
|
|
129
|
+
}, 100);
|
|
130
|
+
}
|
|
131
|
+
case 14:
|
|
116
132
|
case "end":
|
|
117
133
|
return _context3.stop();
|
|
118
134
|
}
|
|
119
135
|
}, _callee3);
|
|
120
136
|
}));
|
|
121
|
-
return function (
|
|
137
|
+
return function (_x4, _x5) {
|
|
122
138
|
return _ref4.apply(this, arguments);
|
|
123
139
|
};
|
|
124
|
-
}(), [dispatch]);
|
|
140
|
+
}(), [comment.detail, dispatch, updateScrollPosition]);
|
|
125
141
|
var insertReply = useCallback( /*#__PURE__*/function () {
|
|
126
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(
|
|
127
|
-
var res, returnReply, newReply;
|
|
142
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(commentId, replies) {
|
|
143
|
+
var elementId, i, reply, res, returnReply, newReply, newComment;
|
|
128
144
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
129
145
|
while (1) switch (_context4.prev = _context4.next) {
|
|
130
146
|
case 0:
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
elementId = comment.detail.element_id;
|
|
148
|
+
i = 0;
|
|
133
149
|
case 2:
|
|
150
|
+
if (!(i < replies.length)) {
|
|
151
|
+
_context4.next = 13;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
reply = replies[i];
|
|
155
|
+
_context4.next = 6;
|
|
156
|
+
return context.insertReply(commentId, reply);
|
|
157
|
+
case 6:
|
|
134
158
|
res = _context4.sent;
|
|
135
159
|
returnReply = res.data.reply;
|
|
136
160
|
newReply = _objectSpread(_objectSpread({}, reply), {}, {
|
|
137
161
|
id: returnReply.id,
|
|
162
|
+
reply: returnReply.reply,
|
|
138
163
|
user_name: returnReply.user_name,
|
|
139
164
|
avatar_url: returnReply.avatar_url
|
|
140
165
|
});
|
|
@@ -146,22 +171,59 @@ export default function CommentItemWrapper(_ref) {
|
|
|
146
171
|
reply: newReply
|
|
147
172
|
}
|
|
148
173
|
});
|
|
174
|
+
case 10:
|
|
175
|
+
i++;
|
|
176
|
+
_context4.next = 2;
|
|
177
|
+
break;
|
|
178
|
+
case 13:
|
|
179
|
+
if (!(replies.length > 1)) {
|
|
180
|
+
_context4.next = 18;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
newComment = {
|
|
184
|
+
resolved: false
|
|
185
|
+
};
|
|
186
|
+
_context4.next = 17;
|
|
187
|
+
return context.updateComment(commentId, newComment);
|
|
188
|
+
case 17:
|
|
189
|
+
dispatch({
|
|
190
|
+
type: 'UPDATE_COMMENT_STATE',
|
|
191
|
+
payload: {
|
|
192
|
+
element_id: elementId,
|
|
193
|
+
comment_id: commentId,
|
|
194
|
+
comment: newComment
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
case 18:
|
|
149
198
|
setTimeout(function () {
|
|
150
199
|
listRef.current.scrollTop = 10000;
|
|
151
200
|
}, 0);
|
|
152
|
-
case
|
|
201
|
+
case 19:
|
|
153
202
|
case "end":
|
|
154
203
|
return _context4.stop();
|
|
155
204
|
}
|
|
156
205
|
}, _callee4);
|
|
157
206
|
}));
|
|
158
|
-
return function (
|
|
207
|
+
return function (_x6, _x7) {
|
|
159
208
|
return _ref5.apply(this, arguments);
|
|
160
209
|
};
|
|
161
|
-
}(), [dispatch]);
|
|
210
|
+
}(), [comment.detail, dispatch]);
|
|
162
211
|
var insertContent = useCallback(function (content) {
|
|
163
212
|
var user = context.getUserInfo();
|
|
164
|
-
var
|
|
213
|
+
var replies = [];
|
|
214
|
+
// The comment has already been resolved, when adding a new reply, resubmit the comment
|
|
215
|
+
if (comment.resolved) {
|
|
216
|
+
var _time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
217
|
+
var stateChangeReply = {
|
|
218
|
+
type: 'comment',
|
|
219
|
+
reply: false,
|
|
220
|
+
updated_at: _time,
|
|
221
|
+
author: user.username
|
|
222
|
+
};
|
|
223
|
+
replies.push(stateChangeReply);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// User added reply
|
|
165
227
|
var time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
166
228
|
var reply = {
|
|
167
229
|
type: 'reply',
|
|
@@ -169,44 +231,46 @@ export default function CommentItemWrapper(_ref) {
|
|
|
169
231
|
updated_at: time,
|
|
170
232
|
author: user.username
|
|
171
233
|
};
|
|
172
|
-
|
|
173
|
-
|
|
234
|
+
replies.push(reply);
|
|
235
|
+
insertReply(comment.id, replies);
|
|
236
|
+
}, [comment.id, comment.resolved, insertReply]);
|
|
174
237
|
var deleteReply = useCallback( /*#__PURE__*/function () {
|
|
175
238
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(replyId) {
|
|
176
|
-
var elementId;
|
|
239
|
+
var commentId, elementId;
|
|
177
240
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
178
241
|
while (1) switch (_context5.prev = _context5.next) {
|
|
179
242
|
case 0:
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
243
|
+
commentId = comment.id;
|
|
244
|
+
elementId = comment.detail.element_id;
|
|
245
|
+
_context5.next = 4;
|
|
246
|
+
return context.deleteReply(commentId, replyId);
|
|
247
|
+
case 4:
|
|
184
248
|
dispatch({
|
|
185
249
|
type: 'DELETE_REPLY',
|
|
186
250
|
payload: {
|
|
187
251
|
element_id: elementId,
|
|
188
|
-
comment_id:
|
|
252
|
+
comment_id: commentId,
|
|
189
253
|
reply_id: replyId
|
|
190
254
|
}
|
|
191
255
|
});
|
|
192
|
-
case
|
|
256
|
+
case 5:
|
|
193
257
|
case "end":
|
|
194
258
|
return _context5.stop();
|
|
195
259
|
}
|
|
196
260
|
}, _callee5);
|
|
197
261
|
}));
|
|
198
|
-
return function (
|
|
262
|
+
return function (_x8) {
|
|
199
263
|
return _ref6.apply(this, arguments);
|
|
200
264
|
};
|
|
201
|
-
}(), [comment.id, dispatch
|
|
265
|
+
}(), [comment.detail, comment.id, dispatch]);
|
|
202
266
|
var updateReply = useCallback( /*#__PURE__*/function () {
|
|
203
267
|
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(replyId, newReply) {
|
|
204
|
-
var
|
|
268
|
+
var commentId, elementId;
|
|
205
269
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
206
270
|
while (1) switch (_context6.prev = _context6.next) {
|
|
207
271
|
case 0:
|
|
208
|
-
elementId = selectionElement.id;
|
|
209
272
|
commentId = comment.id;
|
|
273
|
+
elementId = comment.detail.element_id;
|
|
210
274
|
_context6.next = 4;
|
|
211
275
|
return context.updateReply(commentId, replyId, newReply);
|
|
212
276
|
case 4:
|
|
@@ -225,40 +289,58 @@ export default function CommentItemWrapper(_ref) {
|
|
|
225
289
|
}
|
|
226
290
|
}, _callee6);
|
|
227
291
|
}));
|
|
228
|
-
return function (
|
|
292
|
+
return function (_x9, _x10) {
|
|
229
293
|
return _ref7.apply(this, arguments);
|
|
230
294
|
};
|
|
231
|
-
}(), [comment.id, dispatch
|
|
295
|
+
}(), [comment.detail, comment.id, dispatch]);
|
|
232
296
|
var onItemClick = useCallback(function () {
|
|
233
297
|
onCommentClick(comment);
|
|
234
298
|
}, [comment, onCommentClick]);
|
|
299
|
+
var className = classNames('comment-ui-container', {
|
|
300
|
+
'active': isActive,
|
|
301
|
+
'sdoc-resolved': comment.resolved
|
|
302
|
+
});
|
|
303
|
+
var tip = comment.resolved ? 'Reopen_discussion' : 'Enter_a_reply';
|
|
235
304
|
return /*#__PURE__*/React.createElement("div", {
|
|
236
|
-
id: "comment-item-
|
|
237
|
-
className:
|
|
305
|
+
id: "comment-item-wrapper_".concat(comment.id),
|
|
306
|
+
className: className,
|
|
238
307
|
onClick: onItemClick
|
|
239
308
|
}, /*#__PURE__*/React.createElement("ul", {
|
|
240
309
|
ref: listRef,
|
|
241
310
|
className: "comment-item-list"
|
|
242
311
|
}, /*#__PURE__*/React.createElement(CommentItemContent, {
|
|
243
312
|
key: comment.id,
|
|
313
|
+
container: container,
|
|
244
314
|
isActive: isActive,
|
|
245
315
|
comment: comment,
|
|
246
|
-
selectionElement: selectionElement,
|
|
247
316
|
deleteComment: deleteComment,
|
|
248
317
|
updateComment: updateComment,
|
|
249
318
|
updateCommentState: updateCommentState
|
|
250
319
|
}), comment.replies && comment.replies.length > 0 && comment.replies.map(function (reply) {
|
|
251
|
-
|
|
320
|
+
var type = reply.type;
|
|
321
|
+
// type is reply | comment
|
|
322
|
+
if (type === 'reply') {
|
|
323
|
+
var props = {
|
|
324
|
+
key: reply.id,
|
|
325
|
+
isActive: isActive,
|
|
326
|
+
container: container,
|
|
327
|
+
reply: reply,
|
|
328
|
+
deleteReply: deleteReply,
|
|
329
|
+
updateReply: updateReply
|
|
330
|
+
};
|
|
331
|
+
return /*#__PURE__*/React.createElement(CommentItemReply, props);
|
|
332
|
+
}
|
|
333
|
+
return /*#__PURE__*/React.createElement(CommentItemResolvedReply, {
|
|
252
334
|
key: reply.id,
|
|
253
|
-
|
|
254
|
-
reply: reply,
|
|
255
|
-
deleteReply: deleteReply,
|
|
256
|
-
updateReply: updateReply
|
|
335
|
+
reply: reply
|
|
257
336
|
});
|
|
258
337
|
})), isActive && /*#__PURE__*/React.createElement("div", {
|
|
259
338
|
className: "comment-editor-wrapper mt-4"
|
|
260
339
|
}, /*#__PURE__*/React.createElement(CommentEditor, {
|
|
261
|
-
placeholder:
|
|
340
|
+
placeholder: tip,
|
|
262
341
|
insertContent: insertContent
|
|
263
342
|
})));
|
|
264
|
-
}
|
|
343
|
+
}
|
|
344
|
+
CommentItemWrapper.defaultProps = {
|
|
345
|
+
container: 'sdoc-comment-list-container'
|
|
346
|
+
};
|