@seafile/sdoc-editor 0.2.18 → 0.2.19

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.
@@ -18,16 +18,16 @@
18
18
  .sdoc-code-block-code .sdoc-code-line {
19
19
  position: relative;
20
20
  counter-increment: number;
21
+ margin-left: 32px;
21
22
  }
22
23
 
23
24
  .sdoc-code-block-code .sdoc-code-line::before {
24
25
  content: counter(number);
25
26
  color: #ccc;
26
- display: inline-block;
27
27
  width: 40px;
28
28
  text-align: end;
29
- margin-left: -16px;
30
- margin-right: 20px;
29
+ position: absolute;
30
+ left: -50px;
31
31
  }
32
32
 
33
33
  .sdoc-code-line
@@ -15,3 +15,24 @@
15
15
  .element-icon {
16
16
  color: #444 !important;
17
17
  }
18
+
19
+ .sdoc-icon-btn {
20
+ height: 24px;
21
+ width: 24px;
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ }
26
+
27
+ .sdoc-icon-btn:hover {
28
+ cursor: pointer;
29
+ }
30
+
31
+ .sdoc-icon-btn .sdocfont {
32
+ color: #999;
33
+ font-size: 16px;
34
+ }
35
+
36
+ .sdoc-icon-btn:hover .sdocfont {
37
+ color: #5a5a5a;
38
+ }
@@ -1,15 +1,35 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useState } from 'react';
3
- import { withTranslation } from 'react-i18next';
3
+ import { useTranslation } from 'react-i18next';
4
4
  import { Dropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap';
5
- import { eventStopPropagation } from '../../utils/mouse-event';
6
- import { COMMENT_TYPES } from '../constants';
7
- import CommentAllParticipants from './comment-all-participants';
8
- function GlobalCommentHeader(_ref) {
9
- var commentType = _ref.commentType,
10
- commentList = _ref.commentList,
11
- t = _ref.t,
12
- onCommentTypeChanged = _ref.onCommentTypeChanged;
5
+ import { eventStopPropagation } from '../../../utils/mouse-event';
6
+ import { COMMENT_TYPES } from '../../constants';
7
+ import CommentAllParticipants from '../comment-all-participants';
8
+ var CommentTypeDropdownItem = function CommentTypeDropdownItem(_ref) {
9
+ var type = _ref.type,
10
+ setCommentType = _ref.setCommentType;
11
+ var _useTranslation = useTranslation(),
12
+ t = _useTranslation.t;
13
+ var handleCommentTypeChanged = useCallback(function (event, type) {
14
+ eventStopPropagation(event);
15
+ setCommentType(type);
16
+
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
18
+ }, []);
19
+ return /*#__PURE__*/React.createElement(DropdownItem, {
20
+ className: "sdoc-dropdown-menu-item",
21
+ tag: 'div',
22
+ onClick: function onClick(event) {
23
+ return handleCommentTypeChanged(event, type);
24
+ }
25
+ }, t(type));
26
+ };
27
+ var GlobalCommentBodyHeader = function GlobalCommentBodyHeader(_ref2) {
28
+ var commentList = _ref2.commentList,
29
+ commentType = _ref2.commentType,
30
+ setCommentType = _ref2.setCommentType;
31
+ var _useTranslation2 = useTranslation(),
32
+ t = _useTranslation2.t;
13
33
  var _useState = useState(false),
14
34
  _useState2 = _slicedToArray(_useState, 2),
15
35
  isDropdownOpen = _useState2[0],
@@ -22,12 +42,6 @@ function GlobalCommentHeader(_ref) {
22
42
  count: commentList.length
23
43
  });
24
44
  }
25
- var handleCommentTypeChanged = useCallback(function (event, type) {
26
- eventStopPropagation(event);
27
- onCommentTypeChanged(type);
28
-
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- }, []);
31
45
  var id = 'comment-type-controller';
32
46
  return /*#__PURE__*/React.createElement("div", {
33
47
  className: "comments-panel-body__header"
@@ -50,26 +64,20 @@ function GlobalCommentHeader(_ref) {
50
64
  }, t(commentType))), /*#__PURE__*/React.createElement(DropdownMenu, {
51
65
  className: "sdoc-dropdown-menu",
52
66
  container: "comment-types"
53
- }, /*#__PURE__*/React.createElement(DropdownItem, {
54
- className: "sdoc-dropdown-menu-item",
55
- tag: 'div',
56
- onClick: function onClick(event) {
57
- return handleCommentTypeChanged(event, COMMENT_TYPES.all);
58
- }
59
- }, t(COMMENT_TYPES.all)), /*#__PURE__*/React.createElement(DropdownItem, {
60
- className: "sdoc-dropdown-menu-item",
61
- tag: 'div',
62
- onClick: function onClick(event) {
63
- return handleCommentTypeChanged(event, COMMENT_TYPES.resolved);
64
- }
65
- }, t(COMMENT_TYPES.resolved)), /*#__PURE__*/React.createElement(DropdownItem, {
66
- className: "sdoc-dropdown-menu-item",
67
- tag: 'div',
68
- onClick: function onClick(event) {
69
- return handleCommentTypeChanged(event, COMMENT_TYPES.unresolved);
70
- }
71
- }, t(COMMENT_TYPES.unresolved))))), /*#__PURE__*/React.createElement("div", {
67
+ }, /*#__PURE__*/React.createElement(CommentTypeDropdownItem, {
68
+ type: COMMENT_TYPES.ALL,
69
+ setCommentType: setCommentType
70
+ }), /*#__PURE__*/React.createElement(CommentTypeDropdownItem, {
71
+ type: COMMENT_TYPES.DOC,
72
+ setCommentType: setCommentType
73
+ }), /*#__PURE__*/React.createElement(CommentTypeDropdownItem, {
74
+ type: COMMENT_TYPES.RESOLVED,
75
+ setCommentType: setCommentType
76
+ }), /*#__PURE__*/React.createElement(CommentTypeDropdownItem, {
77
+ type: COMMENT_TYPES.UNRESOLVED,
78
+ setCommentType: setCommentType
79
+ })))), /*#__PURE__*/React.createElement("div", {
72
80
  className: "comment-count-tip"
73
81
  }, commentTip)));
74
- }
75
- export default withTranslation('sdoc-editor')(GlobalCommentHeader);
82
+ };
83
+ export default GlobalCommentBodyHeader;
@@ -0,0 +1,32 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import CommentEditor from '../comment-editor';
3
+ var GlobalCommentEditor = function GlobalCommentEditor(_ref) {
4
+ var insertDocComment = _ref.insertDocComment,
5
+ hiddenCommentEditor = _ref.hiddenCommentEditor;
6
+ var ref = useRef(null);
7
+ useEffect(function () {
8
+ var hidden = function hidden(event) {
9
+ if (!ref.current.contains(event.target)) {
10
+ hiddenCommentEditor();
11
+ }
12
+ };
13
+ document.addEventListener('click', hidden);
14
+ return function () {
15
+ document.removeEventListener('click', hidden);
16
+ };
17
+
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
+ }, []);
20
+ return /*#__PURE__*/React.createElement("div", {
21
+ className: "sdoc-doc-comment-editor-container sdoc-comment-list-container",
22
+ ref: ref
23
+ }, /*#__PURE__*/React.createElement("div", {
24
+ className: "comment-ui-container active"
25
+ }, /*#__PURE__*/React.createElement(CommentEditor, {
26
+ type: "comment",
27
+ className: "sdoc-doc-comment-editor",
28
+ insertContent: insertDocComment,
29
+ hiddenComment: hiddenCommentEditor
30
+ })));
31
+ };
32
+ export default GlobalCommentEditor;
@@ -0,0 +1,31 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { eventStopPropagation } from '../../../utils/mouse-event';
4
+ var GlobalCommentHeader = function GlobalCommentHeader(_ref) {
5
+ var toggle = _ref.toggle,
6
+ toggleGlobalCommentEditor = _ref.toggleGlobalCommentEditor;
7
+ var _useTranslation = useTranslation(),
8
+ t = _useTranslation.t;
9
+ var toggleADDComment = useCallback(function (event) {
10
+ eventStopPropagation(event);
11
+ toggleGlobalCommentEditor();
12
+ }, [toggleGlobalCommentEditor]);
13
+ return /*#__PURE__*/React.createElement("div", {
14
+ className: "comments-panel-header"
15
+ }, /*#__PURE__*/React.createElement("span", {
16
+ className: "title"
17
+ }, t('Comments')), /*#__PURE__*/React.createElement("div", {
18
+ className: "comments-panel-header-right"
19
+ }, /*#__PURE__*/React.createElement("div", {
20
+ className: "sdoc-icon-btn",
21
+ onClick: toggleADDComment
22
+ }, /*#__PURE__*/React.createElement("i", {
23
+ className: "sdocfont sdoc-add-comment"
24
+ })), /*#__PURE__*/React.createElement("div", {
25
+ className: "sdoc-icon-btn",
26
+ onClick: toggle
27
+ }, /*#__PURE__*/React.createElement("i", {
28
+ className: "sdocfont sdoc-sm-close"
29
+ }))));
30
+ };
31
+ export default GlobalCommentHeader;
@@ -0,0 +1,130 @@
1
+ .global-comments-popover {
2
+ position: absolute;
3
+ right: 10px;
4
+ top: 50px;
5
+ z-index: 103;
6
+ width: 340px;
7
+ height: 540px;
8
+ }
9
+
10
+ .global-comments-popover .comments-panel-wrapper {
11
+ height: 100%;
12
+ display: flex;
13
+ flex-direction: column;
14
+ background: #fff;
15
+ border: 1px solid #EAECEF;
16
+ border-radius: 4px;
17
+ box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
18
+ }
19
+
20
+ .global-comments-popover .comments-panel-header {
21
+ padding: 0 16px;
22
+ height: 46px;
23
+ display: flex;
24
+ align-items: center;
25
+ justify-content: space-between;
26
+ border-bottom: 1px solid #EAECEF;
27
+ }
28
+
29
+ .global-comments-popover .comments-panel-header .title {
30
+ color: #212529;
31
+ font-size: 16px;
32
+ font-weight: 500;
33
+ }
34
+
35
+ .global-comments-popover .comments-panel-header .comments-panel-header-right {
36
+ display: flex;
37
+ }
38
+
39
+ .global-comments-popover .comments-panel-header-right .sdoc-icon-btn:not(:last-child) {
40
+ margin-right: 4px;
41
+ }
42
+
43
+ .global-comments-popover .comments-panel-header .sdoc-icon-btn .sdocfont {
44
+ font-weight: 700;
45
+ }
46
+
47
+ .global-comments-popover .comments-panel-body {
48
+ flex: 1;
49
+ display: flex;
50
+ flex-direction: column;
51
+ min-height: 0;
52
+ position: relative;
53
+ }
54
+
55
+ .global-comments-popover .comments-panel-body__header {
56
+ height: 80px;
57
+ display: flex;
58
+ flex-direction: column;
59
+ padding: 0 16px;
60
+ }
61
+
62
+ .global-comments-popover .comments-panel-body__header .comments-types-count {
63
+ height: 38px;
64
+ display: flex;
65
+ justify-content: space-between;
66
+ align-items: center;
67
+ padding: 16px 0;
68
+ }
69
+
70
+ .global-comments-popover .comments-panel-body__header .comment-type {
71
+ color: #212529;
72
+ font-size: 12px;
73
+ }
74
+
75
+ .global-comments-popover .comments-panel-body__header .comment-type{
76
+ color: #212529;
77
+ font-size: 12px;
78
+ }
79
+
80
+ .global-comments-popover .comments-panel-body__header .comment-count-tip {
81
+ color: #999;
82
+ font-size: 12px;
83
+ }
84
+
85
+ .global-comments-popover .comments-panel-body__content {
86
+ flex: 1;
87
+ display: flex;
88
+ flex-direction: column;
89
+ padding: 16px;
90
+ overflow: auto;
91
+ }
92
+
93
+ .global-comments-popover .comments-panel-body__content .sdoc-comment-list-container {
94
+ position: relative;
95
+ }
96
+
97
+ .global-comments-popover .comments-panel-body__content .comment-item-list {
98
+ max-width: 308px;
99
+ }
100
+
101
+ .global-comments-popover .comments-panel-body__content .comment-ui-container.active {
102
+ left: 0;
103
+ }
104
+
105
+ .global-comments-popover .comments-panel-body__content .comment-ui-container.sdoc-resolved {
106
+ background: #f5f5f5;
107
+ }
108
+
109
+ .global-comments-popover .comments-panel-body__content .comment-ui-container.active.sdoc-resolved {
110
+ background: #f5f5f5;
111
+ }
112
+
113
+ .sdoc-dropdown-menu .dropdown-item {
114
+ font-size: 14px;
115
+ color: #212529;
116
+ }
117
+
118
+ /* doc comment add editor */
119
+ .global-comments-popover .comments-panel-body .sdoc-doc-comment-editor-container {
120
+ position: absolute;
121
+ left: 16px;
122
+ width: calc(100% - 32px);
123
+ background-color: #fff;
124
+ top: 78px;
125
+ }
126
+
127
+ .global-comments-popover .sdoc-doc-comment-editor-container .comment-ui-container.active {
128
+ left: 0;
129
+ margin-bottom: 0;
130
+ }
@@ -0,0 +1,176 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
6
+ import dayjs from 'dayjs';
7
+ import { ElementPopover } from '../../../extension/commons';
8
+ import EventBus from '../../../utils/event-bus';
9
+ import useCommentList from '../../hooks/use-comment-list';
10
+ import CommentItemWrapper from '../comment-item-wrapper';
11
+ import GlobalCommentHeader from './global-comment-header';
12
+ import GlobalCommentBodyHeader from './global-comment-body-header';
13
+ import { DOC_COMMENT_ELEMENT_ID } from '../../constants';
14
+ import context from '../../../../context';
15
+ import { useCommentContext } from '../../hooks/use-comment-context';
16
+ import GlobalCommentEditor from './global-comment-editor';
17
+ import './index.css';
18
+ var GlobalComment = function GlobalComment() {
19
+ var _useState = useState(null),
20
+ _useState2 = _slicedToArray(_useState, 2),
21
+ activeComment = _useState2[0],
22
+ setActiveComment = _useState2[1];
23
+ var commentRef = useRef(null);
24
+ var contentRef = useRef(null);
25
+ var _useCommentList = useCommentList(),
26
+ commentList = _useCommentList.commentList,
27
+ commentType = _useCommentList.commentType,
28
+ setCommentType = _useCommentList.setCommentType;
29
+ var _useState3 = useState(false),
30
+ _useState4 = _slicedToArray(_useState3, 2),
31
+ isShowCommentList = _useState4[0],
32
+ setShowCommentList = _useState4[1];
33
+ var _useState5 = useState(false),
34
+ _useState6 = _slicedToArray(_useState5, 2),
35
+ showEditor = _useState6[0],
36
+ setShowEditor = _useState6[1];
37
+ var toggle = useCallback(function () {
38
+ if (isShowCommentList) {
39
+ setActiveComment(null);
40
+ setShowCommentList(false);
41
+ setShowEditor(false);
42
+ return;
43
+ }
44
+ setShowCommentList(true);
45
+ }, [isShowCommentList]);
46
+ useEffect(function () {
47
+ if (!isShowCommentList) return;
48
+ var toggleOuterSide = function toggleOuterSide(e) {
49
+ var commentWrapper = commentRef.current;
50
+ var clickIsInComment = commentWrapper && commentWrapper.contains(e.target) && commentWrapper !== e.target;
51
+ if (clickIsInComment) return;
52
+ toggle();
53
+ };
54
+ document.addEventListener('click', toggleOuterSide);
55
+ return function () {
56
+ document.removeEventListener('click', toggleOuterSide);
57
+ };
58
+ }, [isShowCommentList, toggle]);
59
+ useEffect(function () {
60
+ var eventBus = EventBus.getInstance();
61
+ var unsubscribe = eventBus.subscribe('COMMENT_LIST_CLICK', toggle);
62
+ return function () {
63
+ unsubscribe();
64
+ };
65
+ }, [toggle]);
66
+ var updateScrollPosition = useCallback(function () {
67
+ var resolvedDom = document.querySelector('.sdoc-resolved');
68
+ contentRef.current.scrollTo({
69
+ top: resolvedDom.offsetTop,
70
+ behavior: 'smooth'
71
+ });
72
+ }, []);
73
+ var hiddenComment = useCallback(function () {
74
+ setActiveComment(null);
75
+ }, []);
76
+ var onCommentClick = useCallback(function (comment) {
77
+ if (activeComment && activeComment.id === comment.id) return;
78
+ setActiveComment(comment);
79
+ }, [activeComment]);
80
+ var _useCommentContext = useCommentContext(),
81
+ dispatch = _useCommentContext.dispatch;
82
+ var insertComment = useCallback( /*#__PURE__*/function () {
83
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(elementId, comment) {
84
+ var res, returnComment, newComment;
85
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
86
+ while (1) switch (_context.prev = _context.next) {
87
+ case 0:
88
+ _context.next = 2;
89
+ return context.insertComment(comment);
90
+ case 2:
91
+ res = _context.sent;
92
+ returnComment = res.data.comment;
93
+ newComment = _objectSpread(_objectSpread({}, comment), {}, {
94
+ id: returnComment.id,
95
+ user_name: returnComment.user_name,
96
+ avatar_url: returnComment.avatar_url,
97
+ replies: []
98
+ });
99
+ dispatch({
100
+ type: 'INSERT_COMMENT',
101
+ payload: {
102
+ element_id: elementId,
103
+ comment: newComment
104
+ }
105
+ });
106
+ setShowEditor(false);
107
+ case 7:
108
+ case "end":
109
+ return _context.stop();
110
+ }
111
+ }, _callee);
112
+ }));
113
+ return function (_x, _x2) {
114
+ return _ref.apply(this, arguments);
115
+ };
116
+ }(), [dispatch]);
117
+ var insertDocComment = useCallback(function (commentDetail) {
118
+ var user = context.getUserInfo();
119
+ var elementId = DOC_COMMENT_ELEMENT_ID;
120
+ var time = dayjs().format('YYYY-MM-DD HH:mm:ss');
121
+ var comment = {
122
+ comment: commentDetail,
123
+ detail: {
124
+ element_id: elementId,
125
+ comment: commentDetail
126
+ },
127
+ author: user.username,
128
+ updated_at: time
129
+ };
130
+ insertComment(elementId, comment);
131
+ }, [insertComment]);
132
+ var toggleGlobalCommentEditor = useCallback(function () {
133
+ setShowEditor(!showEditor);
134
+ setActiveComment(null);
135
+ }, [showEditor]);
136
+ var hiddenCommentEditor = useCallback(function () {
137
+ setShowEditor(false);
138
+ }, []);
139
+ if (!isShowCommentList) return null;
140
+ return /*#__PURE__*/React.createElement(ElementPopover, {
141
+ className: "global-comments-popover"
142
+ }, /*#__PURE__*/React.createElement("div", {
143
+ ref: commentRef,
144
+ className: "comments-panel-wrapper"
145
+ }, /*#__PURE__*/React.createElement(GlobalCommentHeader, {
146
+ toggle: toggle,
147
+ toggleGlobalCommentEditor: toggleGlobalCommentEditor
148
+ }), /*#__PURE__*/React.createElement("div", {
149
+ className: "comments-panel-body"
150
+ }, /*#__PURE__*/React.createElement(GlobalCommentBodyHeader, {
151
+ commentList: commentList,
152
+ commentType: commentType,
153
+ setCommentType: setCommentType
154
+ }), /*#__PURE__*/React.createElement("div", {
155
+ ref: contentRef,
156
+ className: "comments-panel-body__content"
157
+ }, /*#__PURE__*/React.createElement("div", {
158
+ id: "global-comment-list-container",
159
+ className: "sdoc-comment-list-container"
160
+ }, commentList.map(function (comment) {
161
+ var isActive = activeComment && activeComment.id === comment.id;
162
+ return /*#__PURE__*/React.createElement(CommentItemWrapper, {
163
+ key: comment.id,
164
+ container: "global-comment-list-container",
165
+ comment: comment,
166
+ isActive: isActive,
167
+ onCommentClick: onCommentClick,
168
+ hiddenComment: hiddenComment,
169
+ updateScrollPosition: updateScrollPosition
170
+ });
171
+ }))), showEditor && /*#__PURE__*/React.createElement(GlobalCommentEditor, {
172
+ hiddenCommentEditor: hiddenCommentEditor,
173
+ insertDocComment: insertDocComment
174
+ }))));
175
+ };
176
+ export default GlobalComment;
@@ -37,122 +37,3 @@
37
37
  left: 14px;
38
38
  width: 280px;
39
39
  }
40
-
41
- /* global comment css */
42
- .global-comments-popover {
43
- position: absolute;
44
- right: 10px;
45
- top: 50px;
46
- z-index: 103;
47
- width: 340px;
48
- height: 540px;
49
- }
50
-
51
- .global-comments-popover .comments-panel-wrapper {
52
- height: 100%;
53
- display: flex;
54
- flex-direction: column;
55
- background: #fff;
56
- border: 1px solid #EAECEF;
57
- border-radius: 4px;
58
- box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
59
- }
60
-
61
- .global-comments-popover .comments-panel-header {
62
- padding: 0 16px;
63
- height: 46px;
64
- display: flex;
65
- align-items: center;
66
- justify-content: space-between;
67
- border-bottom: 1px solid #EAECEF;
68
- }
69
-
70
- .global-comments-popover .comments-panel-header .title {
71
- color: #212529;
72
- font-size: 16px;
73
- font-weight: 500;
74
- }
75
-
76
- .global-comments-popover .comments-panel-header .sdoc-sm-close {
77
- display: flex;
78
- align-items: center;
79
- justify-content: center;
80
- font-size: 16px;
81
- font-weight: 700;
82
- color: #999;
83
- cursor: pointer;
84
- }
85
-
86
- .global-comments-popover .comments-panel-header .sdoc-sm-close:hover {
87
- color: #5a5a5a;
88
- }
89
-
90
- .global-comments-popover .comments-panel-body {
91
- flex: 1;
92
- display: flex;
93
- flex-direction: column;
94
- min-height: 0;
95
- }
96
-
97
- .global-comments-popover .comments-panel-body__header {
98
- height: 80px;
99
- display: flex;
100
- flex-direction: column;
101
- padding: 0 16px;
102
- }
103
-
104
- .global-comments-popover .comments-panel-body__header .comments-types-count {
105
- height: 38px;
106
- display: flex;
107
- justify-content: space-between;
108
- align-items: center;
109
- padding: 16px 0;
110
- }
111
-
112
- .global-comments-popover .comments-panel-body__header .comment-type {
113
- color: #212529;
114
- font-size: 12px;
115
- }
116
-
117
- .global-comments-popover .comments-panel-body__header .comment-type{
118
- color: #212529;
119
- font-size: 12px;
120
- }
121
-
122
- .global-comments-popover .comments-panel-body__header .comment-count-tip {
123
- color: #999;
124
- font-size: 12px;
125
- }
126
-
127
- .global-comments-popover .comments-panel-body__content {
128
- flex: 1;
129
- display: flex;
130
- flex-direction: column;
131
- padding: 16px;
132
- overflow: auto;
133
- }
134
-
135
- .global-comments-popover .comments-panel-body__content .sdoc-comment-list-container {
136
- position: relative;
137
- }
138
-
139
- .global-comments-popover .comments-panel-body__content .comment-item-list {
140
- max-width: 308px;
141
- }
142
-
143
- .global-comments-popover .comments-panel-body__content .comment-ui-container.active {
144
- left: 0;
145
- }
146
-
147
- .global-comments-popover .comments-panel-body__content .comment-ui-container.sdoc-resolved {
148
- background: #f5f5f5;
149
- }
150
-
151
- .global-comments-popover .comments-panel-body__content .comment-ui-container.active.sdoc-resolved {
152
- background: #f5f5f5;
153
- }
154
-
155
- .sdoc-dropdown-menu .dropdown-item {
156
- font-size: 14px;
157
- color: #212529;
158
- }
@@ -1,11 +1,13 @@
1
1
  export var COMMENT_TYPES = {
2
- all: 'All_comments',
3
- resolved: 'Resolved_comments',
4
- unresolved: 'Unresolved_comments'
2
+ DOC: 'Doc_comments',
3
+ ALL: 'All_comments',
4
+ RESOLVED: 'Resolved_comments',
5
+ UNRESOLVED: 'Unresolved_comments'
5
6
  };
6
7
  export var DOWN = 'down';
7
8
  export var UP = 'up';
8
9
  export var FONT_SIZE_WIDTH = 15;
9
10
  export var LINE_HEIGHT = 22;
10
11
  export var POPOVER_ADDING_HEIGHT = 10;
11
- export var COMMENT_URL_CLASSNAME = 'sdoc-comment-url';
12
+ export var COMMENT_URL_CLASSNAME = 'sdoc-comment-url';
13
+ export var DOC_COMMENT_ELEMENT_ID = '0';
@@ -1,13 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import { useEffect, useState } from 'react';
3
3
  import { useCommentContext } from './use-comment-context';
4
- import { COMMENT_TYPES } from '../constants';
4
+ import { COMMENT_TYPES, DOC_COMMENT_ELEMENT_ID } from '../constants';
5
5
  var useCommentList = function useCommentList() {
6
6
  var _useCommentContext = useCommentContext(),
7
7
  commentsInfo = _useCommentContext.commentsInfo;
8
8
  var _ref = commentsInfo || [],
9
9
  comment_list = _ref.comment_list;
10
- var _useState = useState(COMMENT_TYPES.all),
10
+ var _useState = useState(COMMENT_TYPES.ALL),
11
11
  _useState2 = _slicedToArray(_useState, 2),
12
12
  commentType = _useState2[0],
13
13
  setCommentType = _useState2[1];
@@ -16,18 +16,23 @@ var useCommentList = function useCommentList() {
16
16
  commentList = _useState4[0],
17
17
  setCommentList = _useState4[1];
18
18
  useEffect(function () {
19
- if (commentType === COMMENT_TYPES.all) {
19
+ if (commentType === COMMENT_TYPES.ALL) {
20
20
  setCommentList(comment_list);
21
- } else if (commentType === COMMENT_TYPES.resolved) {
21
+ } else if (commentType === COMMENT_TYPES.RESOLVED) {
22
22
  var _commentList = comment_list.filter(function (item) {
23
23
  return item.resolved;
24
24
  });
25
25
  setCommentList(_commentList);
26
- } else if (commentType === COMMENT_TYPES.unresolved) {
26
+ } else if (commentType === COMMENT_TYPES.UNRESOLVED) {
27
27
  var _commentList2 = comment_list.filter(function (item) {
28
28
  return !item.resolved;
29
29
  });
30
30
  setCommentList(_commentList2);
31
+ } else if (commentType === COMMENT_TYPES.DOC) {
32
+ var _commentList3 = comment_list.filter(function (comment) {
33
+ return comment.detail.element_id === DOC_COMMENT_ELEMENT_ID;
34
+ });
35
+ setCommentList(_commentList3);
31
36
  }
32
37
  }, [commentType, comment_list]);
33
38
  return {
@@ -8,6 +8,7 @@ import { Editor, Text, Path, Span, Element, Node, Range } from '@seafile/slate';
8
8
  import { ReactEditor } from '@seafile/slate-react';
9
9
  import { match } from '../utils';
10
10
  import ObjectUtils from '../../../utils/object-utils';
11
+ import { CODE_LINE } from '../../constants';
11
12
 
12
13
  // options
13
14
  export var getQueryOptions = function getQueryOptions(editor, options) {
@@ -479,16 +480,19 @@ export var isBlockAboveEmpty = function isBlockAboveEmpty(editor) {
479
480
  return isAncestorEmpty(editor, block);
480
481
  };
481
482
  export var isSelectionAtBlockStart = function isSelectionAtBlockStart(editor, options) {
482
- var _getAboveBlockNode2;
483
483
  var selection = editor.selection;
484
484
  if (!selection) return false;
485
- var path = (_getAboveBlockNode2 = getAboveBlockNode(editor, options)) === null || _getAboveBlockNode2 === void 0 ? void 0 : _getAboveBlockNode2[1];
485
+ var nodeEntry = getAboveBlockNode(editor, options);
486
+ var path = nodeEntry === null || nodeEntry === void 0 ? void 0 : nodeEntry[1];
487
+ if ((nodeEntry === null || nodeEntry === void 0 ? void 0 : nodeEntry[0].type) === CODE_LINE) {
488
+ path = [path[0]];
489
+ }
486
490
  if (!path) return false;
487
491
  return isStartPoint(editor, selection.focus, path) || Range.isExpanded(editor.selection) && isStartPoint(editor, selection.anchor, path);
488
492
  };
489
493
  export var isSelectionAtBlockEnd = function isSelectionAtBlockEnd(editor, options) {
490
- var _getAboveBlockNode3, _editor$selection;
491
- var path = (_getAboveBlockNode3 = getAboveBlockNode(editor, options)) === null || _getAboveBlockNode3 === void 0 ? void 0 : _getAboveBlockNode3[1];
494
+ var _getAboveBlockNode2, _editor$selection;
495
+ var path = (_getAboveBlockNode2 = getAboveBlockNode(editor, options)) === null || _getAboveBlockNode2 === void 0 ? void 0 : _getAboveBlockNode2[1];
492
496
  return !!path && isEndPoint(editor, (_editor$selection = editor.selection) === null || _editor$selection === void 0 ? void 0 : _editor$selection.focus, path);
493
497
  };
494
498
  export var isLastNode = function isLastNode(editor, node) {
@@ -112,7 +112,7 @@ var FileLink = function FileLink(_ref) {
112
112
  className: "sdoc-file-link-icon",
113
113
  style: style
114
114
  }, /*#__PURE__*/React.createElement("i", {
115
- className: "sdocfont sdoc-document"
115
+ className: "sdocfont sdoc-link-file"
116
116
  })), /*#__PURE__*/React.createElement("span", {
117
117
  className: "sdoc-file-text-link",
118
118
  style: style
@@ -25,6 +25,7 @@ var CollaboratorsPopover = /*#__PURE__*/function (_React$PureComponent) {
25
25
  popperClassName: "collaborators-popover",
26
26
  trigger: "legacy",
27
27
  hideArrow: true,
28
+ fade: false,
28
29
  security: "fixed"
29
30
  }, /*#__PURE__*/React.createElement(PopoverHeader, {
30
31
  className: "popover-header"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -391,5 +391,6 @@
391
391
  "Delete_failed": "Delete failed",
392
392
  "Insert_caption": "Insert caption",
393
393
  "No_collaborators_available": "No_collaborators_available",
394
- "Find_a_collaborator": "Find a collaborator"
394
+ "Find_a_collaborator": "Find a collaborator",
395
+ "Doc_comments": "Document comments"
395
396
  }
@@ -14,6 +14,10 @@
14
14
  />
15
15
  <missing-glyph />
16
16
 
17
+ <glyph glyph-name="check-mark" unicode="&#58971;" d="M329.6 96l-284.8 275.2c-25.6 22.4-25.6 60.8-3.2 86.4 25.6 25.6 64 25.6 89.6 0l265.6-256L892.8 697.6c22.4 22.4 64 25.6 86.4 0 22.4-22.4 25.6-60.8 3.2-83.2L464 99.2c-35.2-38.4-96-38.4-134.4-3.2z" horiz-adv-x="1024" />
18
+
19
+ <glyph glyph-name="add" unicode="&#58970;" d="M448 448V832h128v-384h384v-128H576v-384h-128V320H64v128h384z" horiz-adv-x="1024" />
20
+
17
21
  <glyph glyph-name="sdoc-add" unicode="&#58968;" d="M512-128C227.2-128 0 99.2 0 384S227.2 896 512 896s512-227.2 512-512-227.2-512-512-512z m-51.2 563.2H291.2c-19.2 0-35.2-12.8-35.2-35.2v-35.2c0-19.2 12.8-35.2 35.2-35.2h169.6V160c0-19.2 12.8-35.2 35.2-35.2h35.2c19.2 0 35.2 12.8 35.2 35.2v169.6H736c19.2 0 35.2 12.8 35.2 35.2v35.2c0 19.2-12.8 35.2-35.2 35.2h-169.6V604.8c0 19.2-12.8 35.2-35.2 35.2h-35.2c-19.2 0-35.2-12.8-35.2-35.2v-169.6z" horiz-adv-x="1024" />
18
22
 
19
23
  <glyph glyph-name="sdoc-tag" unicode="&#58969;" d="M521.353986 860.33363l466.979644-466.979644c22.389435-22.389435 35.183398-51.175851 35.183398-83.160758s-12.793963-60.771324-35.183398-83.160759l-323.047562-319.849071c-22.389435-22.389435-51.175851-35.183398-79.962268-35.183398-31.984907 0-60.771324 12.793963-83.160758 35.183398L35.183398 374.163042c-25.587926 25.587926-38.381889 60.771324-31.984907 95.954721l31.984907 291.062655c6.396981 54.374342 47.977361 95.954721 102.351703 102.351703l291.062654 31.984907c31.984907 3.198491 67.168305-9.595472 92.756231-35.183398zM444.590209 767.577399L159.924536 735.592492l-31.984908-281.467182L578.926819-0.060372l316.65058 313.45209L444.590209 767.577399z m12.793963-127.939628c57.572833-57.572833 57.572833-147.130573 0-204.703406-25.587926-25.587926-63.969814-41.580379-102.351703-41.580379-38.381889 0-73.565286 12.793963-102.351703 41.580379-57.572833 57.572833-57.572833 147.130573 0 204.703406 57.572833 57.572833 150.329063 57.572833 204.703406 0z m-102.351703-70.366796c-6.396981 0-15.992454-3.198491-22.389435-9.595472-12.793963-12.793963-12.793963-31.984907 0-44.77887 12.793963-12.793963 31.984907-12.793963 44.77887 0 12.793963 12.793963 12.793963 31.984907 0 44.77887-6.396981 6.396981-12.793963 9.595472-22.389435 9.595472z" horiz-adv-x="1024" />
@@ -1,11 +1,11 @@
1
1
  @font-face {
2
2
  font-family: "sdocfont"; /* Project id 4097705 */
3
- src: url('./sdoc-editor-font/iconfont.eot?t=1698637167502'); /* IE9 */
4
- src: url('./sdoc-editor-font/iconfont.eot?t=1698637167502#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
- url('./sdoc-editor-font/iconfont.woff2?t=1698637167502') format('woff2'),
6
- url('./sdoc-editor-font/iconfont.woff?t=1698637167502') format('woff'),
7
- url('./sdoc-editor-font/iconfont.ttf?t=1698637167502') format('truetype'),
8
- url('./sdoc-editor-font/iconfont.svg?t=1698637167502#sdocfont') format('svg');
3
+ src: url('./sdoc-editor-font/iconfont.eot?t=1699007792511'); /* IE9 */
4
+ src: url('./sdoc-editor-font/iconfont.eot?t=1699007792511#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
+ url('./sdoc-editor-font/iconfont.woff2?t=1699007792511') format('woff2'),
6
+ url('./sdoc-editor-font/iconfont.woff?t=1699007792511') format('woff'),
7
+ url('./sdoc-editor-font/iconfont.ttf?t=1699007792511') format('truetype'),
8
+ url('./sdoc-editor-font/iconfont.svg?t=1699007792511#sdocfont') format('svg');
9
9
  }
10
10
 
11
11
  .sdocfont {
@@ -16,6 +16,14 @@
16
16
  -moz-osx-font-smoothing: grayscale;
17
17
  }
18
18
 
19
+ .check-mark:before {
20
+ content: "\e65b";
21
+ }
22
+
23
+ .add:before {
24
+ content: "\e65a";
25
+ }
26
+
19
27
  .sdoc-add:before {
20
28
  content: "\e658";
21
29
  }
@@ -1,105 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import React, { useCallback, useEffect, useRef, useState } from 'react';
3
- import { ElementPopover } from '../../extension/commons';
4
- import EventBus from '../../utils/event-bus';
5
- import useCommentList from '../hooks/use-comment-list';
6
- import CommentItemWrapper from './comment-item-wrapper';
7
- import { withTranslation } from 'react-i18next';
8
- import GlobalCommentHeader from './global-comment-header';
9
- var GlobalComment = function GlobalComment(_ref) {
10
- var t = _ref.t;
11
- var _useState = useState(null),
12
- _useState2 = _slicedToArray(_useState, 2),
13
- activeComment = _useState2[0],
14
- setActiveComment = _useState2[1];
15
- var onCommentClick = useCallback(function (comment) {
16
- if (activeComment && activeComment.id === comment.id) return;
17
- setActiveComment(comment);
18
- }, [activeComment]);
19
- var commentRef = useRef(null);
20
- var _useCommentList = useCommentList(),
21
- commentList = _useCommentList.commentList,
22
- commentType = _useCommentList.commentType,
23
- setCommentType = _useCommentList.setCommentType;
24
- var _useState3 = useState(false),
25
- _useState4 = _slicedToArray(_useState3, 2),
26
- isShowCommentList = _useState4[0],
27
- setShowCommentList = _useState4[1];
28
- useEffect(function () {
29
- if (!isShowCommentList) return;
30
- var toggleOuterSide = function toggleOuterSide(e) {
31
- var commentWrapper = commentRef.current;
32
- var clickIsInComment = commentWrapper && commentWrapper.contains(e.target) && commentWrapper !== e.target;
33
- if (clickIsInComment) return;
34
- setActiveComment(null);
35
- setShowCommentList(false);
36
- };
37
- document.addEventListener('click', toggleOuterSide);
38
- return function () {
39
- document.removeEventListener('click', toggleOuterSide);
40
- };
41
- }, [isShowCommentList]);
42
- useEffect(function () {
43
- var eventBus = EventBus.getInstance();
44
- var unsubscribe = eventBus.subscribe('COMMENT_LIST_CLICK', function () {
45
- setActiveComment(null);
46
- setShowCommentList(!isShowCommentList);
47
- });
48
- return function () {
49
- unsubscribe();
50
- };
51
- }, [isShowCommentList]);
52
- var contentRef = useRef(null);
53
- var updateScrollPosition = useCallback(function () {
54
- var resolvedDom = document.querySelector('.sdoc-resolved');
55
- contentRef.current.scrollTo({
56
- top: resolvedDom.offsetTop,
57
- behavior: 'smooth'
58
- });
59
- }, []);
60
- var hiddenComment = useCallback(function () {
61
- setActiveComment(null);
62
- }, []);
63
- if (!isShowCommentList) return null;
64
- return /*#__PURE__*/React.createElement(ElementPopover, {
65
- className: "global-comments-popover"
66
- }, /*#__PURE__*/React.createElement("div", {
67
- ref: commentRef,
68
- className: "comments-panel-wrapper"
69
- }, /*#__PURE__*/React.createElement("div", {
70
- className: "comments-panel-header"
71
- }, /*#__PURE__*/React.createElement("span", {
72
- className: "title"
73
- }, t('Comments')), /*#__PURE__*/React.createElement("span", {
74
- className: "close-wrapper",
75
- onClick: function onClick() {
76
- return setShowCommentList(false);
77
- }
78
- }, /*#__PURE__*/React.createElement("i", {
79
- className: "sdocfont sdoc-sm-close"
80
- }))), /*#__PURE__*/React.createElement("div", {
81
- className: "comments-panel-body"
82
- }, /*#__PURE__*/React.createElement(GlobalCommentHeader, {
83
- commentType: commentType,
84
- commentList: commentList,
85
- onCommentTypeChanged: setCommentType
86
- }), /*#__PURE__*/React.createElement("div", {
87
- ref: contentRef,
88
- className: "comments-panel-body__content"
89
- }, /*#__PURE__*/React.createElement("div", {
90
- id: "global-comment-list-container",
91
- className: "sdoc-comment-list-container"
92
- }, commentList.map(function (comment) {
93
- var isActive = activeComment && activeComment.id === comment.id;
94
- return /*#__PURE__*/React.createElement(CommentItemWrapper, {
95
- key: comment.id,
96
- container: 'global-comment-list-container',
97
- comment: comment,
98
- isActive: isActive,
99
- onCommentClick: onCommentClick,
100
- hiddenComment: hiddenComment,
101
- updateScrollPosition: updateScrollPosition
102
- });
103
- }))))));
104
- };
105
- export default withTranslation('sdoc-editor')(GlobalComment);