@seafile/comment-editor 0.0.1-alpha.3 → 0.0.1-alpha.5
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/basic-sdk/assets/css/layout.css +1 -45
- package/dist/basic-sdk/comment/utils.js +39 -0
- package/dist/basic-sdk/editor/comment-editor.css +138 -0
- package/dist/basic-sdk/{comment/components → editor}/comment-editor.js +27 -20
- package/dist/basic-sdk/hooks/use-comment.js +8 -169
- package/dist/basic-sdk/index.js +3 -10
- package/dist/index.js +0 -12
- package/dist/pages/seafile-comment-editor.js +16 -10
- package/package.json +1 -1
- package/dist/assets/css/plugin-editor.css +0 -7
- package/dist/assets/css/simple-viewer.css +0 -6
- package/dist/basic-sdk/comment/components/comment-all-participants/index.css +0 -83
- package/dist/basic-sdk/comment/components/comment-all-participants/index.js +0 -67
- package/dist/basic-sdk/comment/components/comment-all-participants/participant-avatar.js +0 -43
- package/dist/basic-sdk/comment/components/comment-delete-popover.js +0 -80
- package/dist/basic-sdk/comment/components/comment-item-collapse-wrapper.js +0 -160
- package/dist/basic-sdk/comment/components/comment-item-content.js +0 -154
- package/dist/basic-sdk/comment/components/comment-item-reply.js +0 -124
- package/dist/basic-sdk/comment/components/comment-item-resolved-reply.js +0 -38
- package/dist/basic-sdk/comment/components/comment-item-wrapper.js +0 -364
- package/dist/basic-sdk/comment/components/comment-list.css +0 -422
- package/dist/basic-sdk/comment/components/comment-list.js +0 -216
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.css +0 -132
- package/dist/basic-sdk/comment/components/comment-participants-editor/index.js +0 -69
- package/dist/basic-sdk/comment/components/comment-participants-editor/searched-collaborators.js +0 -62
- package/dist/basic-sdk/comment/components/comment-participants-editor/selected-participants.js +0 -48
- package/dist/basic-sdk/comment/components/editor-comment.js +0 -183
- package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +0 -64
- package/dist/basic-sdk/comment/components/elements-comment-count/index.css +0 -29
- package/dist/basic-sdk/comment/components/elements-comment-count/index.js +0 -49
- package/dist/basic-sdk/comment/components/global-comment/global-comment-body-header.js +0 -88
- package/dist/basic-sdk/comment/components/global-comment/global-comment-header.js +0 -90
- package/dist/basic-sdk/comment/components/global-comment/index.css +0 -328
- package/dist/basic-sdk/comment/components/global-comment/index.js +0 -217
- package/dist/basic-sdk/comment/components/index.js +0 -21
- package/dist/basic-sdk/comment/components/style.css +0 -40
- package/dist/basic-sdk/comment/helper.js +0 -184
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-list.js +0 -45
- package/dist/basic-sdk/comment/hooks/comment-hooks/use-comment-mount.js +0 -57
- package/dist/basic-sdk/comment/hooks/notification-hooks/index.js +0 -25
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-context.js +0 -20
- package/dist/basic-sdk/comment/hooks/notification-hooks/use-notification-mount.js +0 -70
- package/dist/basic-sdk/comment/hooks/use-participants.js +0 -26
- package/dist/basic-sdk/comment/index.js +0 -21
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +0 -353
- package/dist/basic-sdk/comment/reducer/notification-reducer.js +0 -89
- package/dist/basic-sdk/comment/utils/get-event-transfer.js +0 -77
- package/dist/basic-sdk/comment/utils/index.js +0 -281
- package/dist/basic-sdk/comment/utils/notification-utils.js +0 -62
- package/dist/basic-sdk/socket/helpers.js +0 -299
- package/dist/basic-sdk/socket/index.js +0 -20
- package/dist/basic-sdk/socket/socket-client.js +0 -211
- package/dist/basic-sdk/socket/socket-manager.js +0 -386
- package/dist/basic-sdk/socket/with-socket-io.js +0 -73
- /package/dist/basic-sdk/comment/{constants/index.js → constants.js} +0 -0
|
@@ -113,48 +113,4 @@
|
|
|
113
113
|
margin: 0 auto;
|
|
114
114
|
padding-top: 20px;
|
|
115
115
|
padding-bottom: 20px;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/* article style --> ./sdoc-editor-article.css */
|
|
119
|
-
|
|
120
|
-
.sdoc-editor-container .seafile-block-container {
|
|
121
|
-
position: relative;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
.sdoc-editor-container .seafile-block-container .comment-count {
|
|
125
|
-
position: absolute;
|
|
126
|
-
right: -55px;
|
|
127
|
-
top: 0px;
|
|
128
|
-
border-radius: 4px;
|
|
129
|
-
width: 15px;
|
|
130
|
-
height: 15px;
|
|
131
|
-
line-height: 18px;
|
|
132
|
-
pointer-events: none;
|
|
133
|
-
display: flex;
|
|
134
|
-
align-items: center;
|
|
135
|
-
justify-content: center;
|
|
136
|
-
color: #fff;
|
|
137
|
-
background: rgba(0, 0, 0, .3);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
.sdoc-editor-container .seafile-block-container .comment-count__btn {
|
|
141
|
-
font-size: 12px;
|
|
142
|
-
transform: scale(.75);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
.comment-editor-toolbar {
|
|
146
|
-
display: flex;
|
|
147
|
-
justify-content: space-between;
|
|
148
|
-
align-items: center;
|
|
149
|
-
height: 32px;
|
|
150
|
-
user-select: none;
|
|
151
|
-
border-top: 1px solid #e5e6e8;
|
|
152
|
-
z-index: 102;
|
|
153
|
-
margin: 0 8px;
|
|
154
|
-
margin-top: 5px;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.comment-editor-menu-group {
|
|
158
|
-
border-right: none;
|
|
159
|
-
padding-left: 0 !important;
|
|
160
|
-
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.searchCollaborators = void 0;
|
|
7
|
+
var _helper = require("../extension/plugins/mention/helper");
|
|
8
|
+
const searchCollaborators = (collaborators, searchValue, editor) => {
|
|
9
|
+
const validSearchValue = searchValue ? searchValue.trim().toLowerCase() : '';
|
|
10
|
+
const validCollaborators = Array.isArray(collaborators) && collaborators.length > 0 ? collaborators : [];
|
|
11
|
+
if (!validSearchValue) return validCollaborators;
|
|
12
|
+
|
|
13
|
+
// The current character is '@' and the previous character is a null character
|
|
14
|
+
const beforeStr = (0, _helper.getPreCharacters)(editor);
|
|
15
|
+
const isEmptyStr = beforeStr.slice(-2, -1).trim().length === 0;
|
|
16
|
+
if (beforeStr.slice(-1) === '@' && isEmptyStr) {
|
|
17
|
+
return validCollaborators;
|
|
18
|
+
}
|
|
19
|
+
return validCollaborators.filter(collaborator => {
|
|
20
|
+
const {
|
|
21
|
+
name,
|
|
22
|
+
name_pinyin = ''
|
|
23
|
+
} = collaborator;
|
|
24
|
+
if (name.toString().toLowerCase().indexOf(validSearchValue) > -1) return true;
|
|
25
|
+
if (!name_pinyin) return false;
|
|
26
|
+
const validNamePinyin = name_pinyin.toString().toLowerCase();
|
|
27
|
+
const validSearchPinyinValue = validSearchValue.replace(/ |'/g, '');
|
|
28
|
+
|
|
29
|
+
// complete: For example, seatable can be retrieved when searching for sea.
|
|
30
|
+
if (validNamePinyin.indexOf(validSearchPinyinValue) > -1) return true;
|
|
31
|
+
if (validNamePinyin.replace(/'/g, '').indexOf(validSearchPinyinValue) > -1) return true;
|
|
32
|
+
const validNamePinyinList = validNamePinyin.split('\'');
|
|
33
|
+
// acronym: For example, sea table can be retrieved when searching for st.
|
|
34
|
+
const namePinyinAcronym = validNamePinyinList.map(item => item && item.trim() ? item.trim().slice(0, 1) : '');
|
|
35
|
+
if (namePinyinAcronym.join('').indexOf(validSearchPinyinValue) > -1) return true;
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
exports.searchCollaborators = searchCollaborators;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
.comment-editor-wrapper {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
cursor: text;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.comment-editor-wrapper .comment-editor-container {
|
|
9
|
+
flex: 1;
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
min-height: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.comment-editor-wrapper .comment-editor-content {
|
|
16
|
+
border: 1px solid #ececec;
|
|
17
|
+
border-radius: 3px;
|
|
18
|
+
transition: border-color .3s ease;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.comment-editor-wrapper .comment-editor-content:focus-within {
|
|
22
|
+
border-color: #ff8e03;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* comment-editor */
|
|
26
|
+
.comment-editor-wrapper .comment-editor-content .article.comment-editor {
|
|
27
|
+
width: 100%;
|
|
28
|
+
padding: 8px;
|
|
29
|
+
padding-bottom: 0;
|
|
30
|
+
min-height: 60px;
|
|
31
|
+
max-height: 130px;
|
|
32
|
+
box-shadow: none;
|
|
33
|
+
overflow-y: auto;
|
|
34
|
+
overflow-x: hidden;
|
|
35
|
+
border: none;
|
|
36
|
+
background-color: transparent;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.comment-editor-wrapper .comment-editor-content .article.comment-editor :first-child {
|
|
40
|
+
margin-top: 0 !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.comment-editor-wrapper .comment-editor:empty:before {
|
|
44
|
+
content: attr(placeholder);
|
|
45
|
+
opacity: .6;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.comment-editor-wrapper .comment-editor:focus-visible {
|
|
49
|
+
outline: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.comment-editor-wrapper .comment-editor:focus {
|
|
53
|
+
border: 1px solid rgba(0, 0, 0, .12);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.comment-editor-wrapper .comment-editor-user-info {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
margin-bottom: 10px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.comment-editor-wrapper .comment-editor-user-info .comment-editor-user-img {
|
|
63
|
+
height: 30px;
|
|
64
|
+
width: 30px;
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
margin-right: 8px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.comment-editor-wrapper .comment-editor-user-info .comment-editor-user-name {
|
|
71
|
+
flex: 1;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
text-overflow: ellipsis;
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
user-select: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.comment-editor-wrapper .comment-operations {
|
|
79
|
+
display: flex;
|
|
80
|
+
justify-content: flex-end;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* comment-editor-toolbar */
|
|
84
|
+
.comment-editor-wrapper .comment-editor-toolbar {
|
|
85
|
+
display: flex;
|
|
86
|
+
justify-content: space-between;
|
|
87
|
+
align-items: center;
|
|
88
|
+
height: 32px;
|
|
89
|
+
user-select: none;
|
|
90
|
+
z-index: 102;
|
|
91
|
+
margin: 0 8px;
|
|
92
|
+
margin-top: 5px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.comment-editor-wrapper .comment-editor-toolbar .comment-editor-menu-group {
|
|
96
|
+
border-right: none !important;
|
|
97
|
+
padding-left: 0 !important;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group {
|
|
101
|
+
height: 100%;
|
|
102
|
+
padding: 6px 0 6px 8px;
|
|
103
|
+
font-size: 0.75rem;
|
|
104
|
+
border-right: 1px solid #e5e6e8;
|
|
105
|
+
border-radius: 0 !important;
|
|
106
|
+
color: #444;
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
justify-content: center;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item {
|
|
113
|
+
width: 24px;
|
|
114
|
+
height: 24px;
|
|
115
|
+
line-height: 24px;
|
|
116
|
+
margin-right: 8px;
|
|
117
|
+
border: none !important;
|
|
118
|
+
color: #444;
|
|
119
|
+
background-color: transparent;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item:disabled {
|
|
123
|
+
color: #BDBDBD;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item:hover {
|
|
127
|
+
background-color: #F2F2F2;
|
|
128
|
+
border-radius: 2px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item[data-active='true'] {
|
|
132
|
+
color: #eb8205;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.comment-editor-wrapper .comment-editor-toolbar .menu-group .menu-group-item .sdocfont,
|
|
136
|
+
.sdoc-menu-with-dropdown .sdoc-menu-with-dropdown-icon .sdocfont {
|
|
137
|
+
font-size: 12px;
|
|
138
|
+
}
|
|
@@ -13,23 +13,24 @@ var _slateReact = require("@seafile/slate-react");
|
|
|
13
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
14
|
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
15
15
|
var _scrollIntoViewIfNeeded = _interopRequireDefault(require("scroll-into-view-if-needed"));
|
|
16
|
-
var _constants = require("
|
|
17
|
-
var _context = _interopRequireDefault(require("
|
|
18
|
-
var _useCursors = require("
|
|
19
|
-
var _decorates = require("
|
|
20
|
-
var _extension = require("
|
|
21
|
-
var _constants2 = require("
|
|
22
|
-
var _core = require("
|
|
23
|
-
var _renderCommentEditorElement = _interopRequireDefault(require("
|
|
24
|
-
var _commentEditorToolbar = _interopRequireDefault(require("
|
|
25
|
-
var _useComment = require("
|
|
26
|
-
var _useScrollContext = require("
|
|
27
|
-
var _layout = require("
|
|
28
|
-
var _nodeId = _interopRequireDefault(require("
|
|
29
|
-
var _mdToSlate = _interopRequireDefault(require("
|
|
30
|
-
var _slateToMd = _interopRequireDefault(require("
|
|
31
|
-
var _eventBus = _interopRequireDefault(require("
|
|
32
|
-
var _eventHandler = _interopRequireDefault(require("
|
|
16
|
+
var _constants = require("../constants");
|
|
17
|
+
var _context = _interopRequireDefault(require("../context"));
|
|
18
|
+
var _useCursors = require("../cursor/use-cursors");
|
|
19
|
+
var _decorates = require("../decorates");
|
|
20
|
+
var _extension = require("../extension");
|
|
21
|
+
var _constants2 = require("../extension/constants");
|
|
22
|
+
var _core = require("../extension/core");
|
|
23
|
+
var _renderCommentEditorElement = _interopRequireDefault(require("../extension/render/render-comment-editor-element"));
|
|
24
|
+
var _commentEditorToolbar = _interopRequireDefault(require("../extension/toolbar/comment-editor-toolbar"));
|
|
25
|
+
var _useComment = require("../hooks/use-comment");
|
|
26
|
+
var _useScrollContext = require("../hooks/use-scroll-context");
|
|
27
|
+
var _layout = require("../layout");
|
|
28
|
+
var _nodeId = _interopRequireDefault(require("../node-id"));
|
|
29
|
+
var _mdToSlate = _interopRequireDefault(require("../slate-convert/md-to-slate"));
|
|
30
|
+
var _slateToMd = _interopRequireDefault(require("../slate-convert/slate-to-md"));
|
|
31
|
+
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
|
|
32
|
+
var _eventHandler = _interopRequireDefault(require("../utils/event-handler"));
|
|
33
|
+
require("./comment-editor.css");
|
|
33
34
|
const getSubmitTip = (type, content) => {
|
|
34
35
|
if (content) return 'Save';
|
|
35
36
|
return type === 'comment' ? 'Comment' : 'Reply';
|
|
@@ -38,7 +39,6 @@ const DEFAULT_PLACEHOLDER = 'Enter_comment_shift_enter_for_new_line_Enter_to_sen
|
|
|
38
39
|
const CommentEditor = _ref => {
|
|
39
40
|
let {
|
|
40
41
|
type,
|
|
41
|
-
className,
|
|
42
42
|
content,
|
|
43
43
|
commentContent,
|
|
44
44
|
placeholder = DEFAULT_PLACEHOLDER,
|
|
@@ -56,7 +56,8 @@ const CommentEditor = _ref => {
|
|
|
56
56
|
t
|
|
57
57
|
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
58
58
|
const {
|
|
59
|
-
addParticipants
|
|
59
|
+
addParticipants,
|
|
60
|
+
className
|
|
60
61
|
} = (0, _useComment.useComment)();
|
|
61
62
|
const submitTip = (0, _react.useMemo)(() => getSubmitTip(type, content), [content, type]);
|
|
62
63
|
const userInfo = _context.default.getUserInfo();
|
|
@@ -112,6 +113,8 @@ const CommentEditor = _ref => {
|
|
|
112
113
|
if (!_slateReact.ReactEditor.isFocused(editor)) return;
|
|
113
114
|
onSubmit(event);
|
|
114
115
|
}, [editor, onSubmit]);
|
|
116
|
+
|
|
117
|
+
// addEventListener
|
|
115
118
|
(0, _react.useEffect)(() => {
|
|
116
119
|
const eventBus = _eventBus.default.getInstance();
|
|
117
120
|
const unsubscribePostComment = eventBus.subscribe(_constants.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmitByEnterKey);
|
|
@@ -148,6 +151,8 @@ const CommentEditor = _ref => {
|
|
|
148
151
|
}
|
|
149
152
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
150
153
|
}, [setIsEditing]);
|
|
154
|
+
|
|
155
|
+
// set editor children
|
|
151
156
|
(0, _react.useEffect)(() => {
|
|
152
157
|
let children = (0, _mdToSlate.default)(content);
|
|
153
158
|
if (commentContent) {
|
|
@@ -239,7 +244,9 @@ const CommentEditor = _ref => {
|
|
|
239
244
|
width: "100%"
|
|
240
245
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
241
246
|
className: "comment-editor-user-name"
|
|
242
|
-
}, userInfo.name)), /*#__PURE__*/_react.default.createElement(
|
|
247
|
+
}, userInfo.name)), /*#__PURE__*/_react.default.createElement("div", {
|
|
248
|
+
className: "comment-editor-container"
|
|
249
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
243
250
|
className: "comment-editor-content"
|
|
244
251
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
245
252
|
ref: commentEditorContainerRef,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
@@ -8,181 +7,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
7
|
exports.useComment = exports.CommentProvider = void 0;
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
9
|
var _reactI18next = require("react-i18next");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var _toast = _interopRequireDefault(require("../components/toast"));
|
|
18
|
-
var _constants2 = require("../constants");
|
|
19
|
-
var _model = require("../model");
|
|
20
|
-
var _commonUtils = require("../utils/common-utils");
|
|
21
|
-
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
|
|
10
|
+
require("../assets/css/layout.css");
|
|
11
|
+
require("../assets/css/default.css");
|
|
12
|
+
require("../assets/css/sdoc-editor-article.css");
|
|
13
|
+
require("../assets/css/sdoc-editor-plugins.css");
|
|
14
|
+
require("../assets/css/sdoc-comment-editor-plugin.css");
|
|
15
|
+
require("../assets/css/dropdown-menu.css");
|
|
22
16
|
const CommentContext = /*#__PURE__*/_react.default.createContext(null);
|
|
23
17
|
const CommentProvider = _ref => {
|
|
24
18
|
let {
|
|
25
19
|
children,
|
|
26
|
-
editor,
|
|
27
20
|
pluginName = '',
|
|
28
21
|
className = '',
|
|
29
22
|
pluginEventBus,
|
|
30
23
|
pluginEvent,
|
|
31
|
-
api
|
|
32
|
-
onCloseCommentPanel
|
|
24
|
+
api
|
|
33
25
|
} = _ref;
|
|
34
26
|
const {
|
|
35
27
|
t
|
|
36
28
|
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
37
29
|
const [collaborators, setCollaborators] = (0, _react.useState)([]);
|
|
38
|
-
const [participants, setParticipants] = (0, _react.useState)([]);
|
|
39
|
-
const [commentType, setCommentType] = (0, _react.useState)(_constants.COMMENT_TYPES.ALL);
|
|
40
|
-
const [commentList, setCommentList] = (0, _react.useState)([]);
|
|
41
|
-
const [commentsInfo, dispatch] = (0, _react.useReducer)(_commentReducer.commentReducer, _commentReducer.initCommentsInfo);
|
|
42
|
-
(0, _useCommentMount.useCommentsMount)(dispatch, api);
|
|
43
|
-
const [notificationsInfo, notificationsDispatch] = (0, _react.useReducer)(_notificationReducer.notificationReducer, _notificationReducer.initNotificationsInfo);
|
|
44
|
-
(0, _notificationHooks.useNotificationsMount)(dispatch, api, collaborators);
|
|
45
|
-
(0, _react.useEffect)(() => {
|
|
46
|
-
if (Object.keys(commentsInfo.element_comments_map).length) {
|
|
47
|
-
editor.element_comments_map = commentsInfo.element_comments_map;
|
|
48
|
-
}
|
|
49
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
-
}, [commentsInfo.element_comments_map]);
|
|
51
|
-
(0, _react.useEffect)(() => {
|
|
52
|
-
editor.notifications_map = {
|
|
53
|
-
...notificationsInfo.notifications_map
|
|
54
|
-
};
|
|
55
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
-
}, [notificationsInfo]);
|
|
57
|
-
(0, _react.useEffect)(() => {
|
|
58
|
-
const {
|
|
59
|
-
comment_list
|
|
60
|
-
} = commentsInfo;
|
|
61
|
-
if (commentType === _constants.COMMENT_TYPES.ALL) {
|
|
62
|
-
const commentList = comment_list.map(item => {
|
|
63
|
-
item.replies = item.replies.filter(reply => !['True', 'False'].includes(reply.reply));
|
|
64
|
-
return item;
|
|
65
|
-
});
|
|
66
|
-
setCommentList(commentList);
|
|
67
|
-
} else if (commentType === _constants.COMMENT_TYPES.RESOLVED) {
|
|
68
|
-
const commentList = comment_list.filter(item => item.resolved);
|
|
69
|
-
setCommentList(commentList);
|
|
70
|
-
} else if (commentType === _constants.COMMENT_TYPES.UNRESOLVED) {
|
|
71
|
-
const commentList = comment_list.filter(item => !item.resolved);
|
|
72
|
-
setCommentList(commentList);
|
|
73
|
-
} else if (commentType === _constants.COMMENT_TYPES.DOC) {
|
|
74
|
-
const commentList = comment_list.filter(comment => comment.detail.element_id === _constants.DOC_COMMENT_ELEMENT_ID);
|
|
75
|
-
setCommentList(commentList);
|
|
76
|
-
}
|
|
77
|
-
}, [commentType, commentsInfo]);
|
|
78
|
-
|
|
79
|
-
// Participants
|
|
80
|
-
const updateLocalParticipants = (0, _react.useCallback)(function () {
|
|
81
|
-
let added = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
82
|
-
if (!Array.isArray(added) || added.length === 0) return;
|
|
83
|
-
let newParticipants = participants.slice(0);
|
|
84
|
-
added.forEach(participant => {
|
|
85
|
-
const newParticipant = new _model.User(participant);
|
|
86
|
-
if (!newParticipants.find(item => item.username === newParticipant.username)) {
|
|
87
|
-
newParticipants.push(newParticipant);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
setParticipants(newParticipants);
|
|
91
|
-
}, [participants]);
|
|
92
|
-
const deleteLocalParticipant = (0, _react.useCallback)(email => {
|
|
93
|
-
if (!participants.find(participant => participant.username === email)) return;
|
|
94
|
-
let newParticipants = participants.slice(0);
|
|
95
|
-
newParticipants = newParticipants.filter(participant => participant.username !== email);
|
|
96
|
-
setParticipants(newParticipants);
|
|
97
|
-
}, [participants]);
|
|
98
|
-
const addParticipants = (0, _react.useCallback)(otherEmail => {
|
|
99
|
-
if (participants.find(participant => participant.username === otherEmail)) return;
|
|
100
|
-
api.addParticipants([otherEmail]).then(res => {
|
|
101
|
-
const {
|
|
102
|
-
success
|
|
103
|
-
} = res.data;
|
|
104
|
-
updateLocalParticipants(success);
|
|
105
|
-
}).catch(error => {
|
|
106
|
-
const errorMessage = (0, _commonUtils.getErrorMsg)(error);
|
|
107
|
-
_toast.default.danger(t(errorMessage));
|
|
108
|
-
});
|
|
109
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
-
}, [updateLocalParticipants, participants]);
|
|
111
|
-
const deleteParticipant = (0, _react.useCallback)(email => {
|
|
112
|
-
if (!participants.find(participant => participant.username === email)) return;
|
|
113
|
-
api.deleteParticipants(email).then(res => {
|
|
114
|
-
let newParticipants = participants.slice(0);
|
|
115
|
-
newParticipants = newParticipants.filter(participant => participant.username !== email);
|
|
116
|
-
setParticipants(newParticipants);
|
|
117
|
-
}).catch(error => {
|
|
118
|
-
const errorMessage = (0, _commonUtils.getErrorMsg)(error);
|
|
119
|
-
_toast.default.danger(t(errorMessage));
|
|
120
|
-
});
|
|
121
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
122
|
-
}, [participants]);
|
|
123
|
-
|
|
124
|
-
// Notifications
|
|
125
|
-
const deleteUnseenNotifications = (0, _react.useCallback)(comment => {
|
|
126
|
-
let unseenCommentIds = [];
|
|
127
|
-
let unseenNotificationKeys = [];
|
|
128
|
-
const commentNotificationKey = (0, _utils.generatorNotificationKey)(comment.id);
|
|
129
|
-
const commentNotification = notificationsInfo.notifications_map[commentNotificationKey];
|
|
130
|
-
if (commentNotification) {
|
|
131
|
-
unseenNotificationKeys.push(commentNotification.key);
|
|
132
|
-
unseenCommentIds.push(commentNotification.id);
|
|
133
|
-
}
|
|
134
|
-
Array.isArray(comment.replies) && comment.replies.forEach(reply => {
|
|
135
|
-
const replyNotificationKey = (0, _utils.generatorNotificationKey)(reply.comment_id, reply.id);
|
|
136
|
-
const replyNotification = notificationsInfo.notifications_map[replyNotificationKey];
|
|
137
|
-
if (replyNotification) {
|
|
138
|
-
unseenNotificationKeys.push(replyNotification.key);
|
|
139
|
-
unseenCommentIds.push(replyNotification.id);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
api.deleteUnseenNotifications(unseenCommentIds).then(res => {
|
|
143
|
-
notificationsDispatch({
|
|
144
|
-
type: _constants.DOC_NOTIFICATION_REDUCER_TYPE.DEL,
|
|
145
|
-
payload: unseenNotificationKeys
|
|
146
|
-
});
|
|
147
|
-
}).catch(error => {
|
|
148
|
-
//
|
|
149
|
-
});
|
|
150
|
-
}, [api, notificationsInfo.notifications_map]);
|
|
151
30
|
|
|
152
31
|
// Mount
|
|
153
32
|
(0, _react.useEffect)(() => {
|
|
154
|
-
// get participants
|
|
155
|
-
api.listParticipants().then(res => {
|
|
156
|
-
const participants = res.data.participant_list;
|
|
157
|
-
updateLocalParticipants(participants);
|
|
158
|
-
}).catch(error => {
|
|
159
|
-
console.log(error);
|
|
160
|
-
});
|
|
161
33
|
|
|
162
|
-
// get collaborators
|
|
163
|
-
api.listRelatedUsers().then(res => {
|
|
164
|
-
const collaborators = [];
|
|
165
|
-
res.data.related_users.forEach(user => {
|
|
166
|
-
const collaborator = new _model.User(user);
|
|
167
|
-
collaborators.push(collaborator);
|
|
168
|
-
});
|
|
169
|
-
setCollaborators(collaborators);
|
|
170
|
-
}).catch(error => {
|
|
171
|
-
console.log(error);
|
|
172
|
-
});
|
|
173
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
174
35
|
}, []);
|
|
175
|
-
|
|
176
|
-
// Listening
|
|
177
|
-
(0, _react.useEffect)(() => {
|
|
178
|
-
const eventBus = _eventBus.default.getInstance();
|
|
179
|
-
const unsubscribeParticipantAdded = eventBus.subscribe(_constants2.INTERNAL_EVENT.PARTICIPANT_ADDED, updateLocalParticipants);
|
|
180
|
-
const unsubscribeParticipantRemoved = eventBus.subscribe(_constants2.INTERNAL_EVENT.PARTICIPANT_REMOVED, deleteLocalParticipant);
|
|
181
|
-
return () => {
|
|
182
|
-
unsubscribeParticipantAdded();
|
|
183
|
-
unsubscribeParticipantRemoved();
|
|
184
|
-
};
|
|
185
|
-
}, [updateLocalParticipants, deleteLocalParticipant]);
|
|
186
36
|
return /*#__PURE__*/_react.default.createElement(CommentContext.Provider, {
|
|
187
37
|
value: {
|
|
188
38
|
pluginName,
|
|
@@ -190,18 +40,7 @@ const CommentProvider = _ref => {
|
|
|
190
40
|
api,
|
|
191
41
|
pluginEventBus,
|
|
192
42
|
pluginEvent,
|
|
193
|
-
|
|
194
|
-
commentType,
|
|
195
|
-
commentList,
|
|
196
|
-
dispatch,
|
|
197
|
-
setCommentType,
|
|
198
|
-
onCloseCommentPanel,
|
|
199
|
-
collaborators,
|
|
200
|
-
notificationsInfo,
|
|
201
|
-
deleteUnseenNotifications,
|
|
202
|
-
addParticipants,
|
|
203
|
-
deleteParticipant,
|
|
204
|
-
participants
|
|
43
|
+
collaborators
|
|
205
44
|
}
|
|
206
45
|
}, children);
|
|
207
46
|
};
|
package/dist/basic-sdk/index.js
CHANGED
|
@@ -4,10 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "CommentEditor", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function () {
|
|
10
|
-
return
|
|
10
|
+
return _commentEditor.default;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "CommentProvider", {
|
|
@@ -148,26 +148,19 @@ Object.defineProperty(exports, "withNodeId", {
|
|
|
148
148
|
return _nodeId.default;
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
|
-
Object.defineProperty(exports, "withSocketIO", {
|
|
152
|
-
enumerable: true,
|
|
153
|
-
get: function () {
|
|
154
|
-
return _socket.withSocketIO;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
151
|
var _fileLoading = _interopRequireDefault(require("./components/file-loading"));
|
|
158
152
|
var _loading = _interopRequireDefault(require("./components/loading"));
|
|
159
153
|
var _toast = _interopRequireDefault(require("./components/toast"));
|
|
160
154
|
var _tooltip = _interopRequireDefault(require("./components/tooltip"));
|
|
161
155
|
var _constants = require("./constants");
|
|
162
156
|
var _context = _interopRequireDefault(require("./context"));
|
|
157
|
+
var _commentEditor = _interopRequireDefault(require("./editor/comment-editor"));
|
|
163
158
|
var _extension = require("./extension");
|
|
164
159
|
var _dropdownMenuItem = _interopRequireDefault(require("./extension/commons/dropdown-menu-item"));
|
|
165
160
|
var _menuShortcutIndicator = _interopRequireDefault(require("./extension/commons/menu-shortcut-indicator"));
|
|
166
161
|
var _useComment = require("./hooks/use-comment");
|
|
167
|
-
var _commentLayout = _interopRequireDefault(require("./layout/comment-layout"));
|
|
168
162
|
var _nodeId = _interopRequireDefault(require("./node-id"));
|
|
169
163
|
var _slateConvert = require("./slate-convert");
|
|
170
|
-
var _socket = require("./socket");
|
|
171
164
|
var _commonUtils = require("./utils/common-utils");
|
|
172
165
|
var _eventBus = _interopRequireDefault(require("./utils/event-bus"));
|
|
173
166
|
var _localStorageUtils = _interopRequireDefault(require("./utils/local-storage-utils"));
|
package/dist/index.js
CHANGED
|
@@ -22,18 +22,6 @@ Object.defineProperty(exports, "SeafileCommentEditor", {
|
|
|
22
22
|
return _seafileCommentEditor.default;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
Object.defineProperty(exports, "createCommentEditor", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _basicSdk.createCommentEditor;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "withNodeId", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return _basicSdk.withNodeId;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
25
|
var _basicSdk = require("./basic-sdk");
|
|
38
26
|
var _constants = require("./constants");
|
|
39
27
|
var _seafileCommentEditor = _interopRequireDefault(require("./pages/seafile-comment-editor"));
|
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
9
|
var _reactI18next = require("react-i18next");
|
|
11
10
|
var _basicSdk = require("../basic-sdk");
|
|
12
11
|
var _errorBoundary = _interopRequireDefault(require("../components/error-boundary"));
|
|
13
12
|
const SeafileCommentEditor = _ref => {
|
|
14
13
|
let {
|
|
15
|
-
editor,
|
|
16
14
|
pluginName = '',
|
|
17
15
|
className = '',
|
|
16
|
+
type,
|
|
17
|
+
commentContent,
|
|
18
|
+
hiddenUserInfo,
|
|
19
|
+
insertContent,
|
|
20
|
+
hiddenComment,
|
|
21
|
+
onContentChange,
|
|
18
22
|
pluginEventBus,
|
|
19
23
|
pluginEvent,
|
|
20
|
-
api
|
|
21
|
-
onCloseCommentPanel
|
|
24
|
+
api
|
|
22
25
|
} = _ref;
|
|
23
26
|
_basicSdk.context.init();
|
|
24
27
|
return /*#__PURE__*/_react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
|
|
25
|
-
editor: editor,
|
|
26
28
|
pluginName: pluginName,
|
|
27
29
|
className: className,
|
|
28
30
|
pluginEventBus: pluginEventBus,
|
|
29
31
|
pluginEvent: pluginEvent,
|
|
30
|
-
api: api
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
api: api
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentEditor, {
|
|
34
|
+
type: type,
|
|
35
|
+
commentContent: commentContent,
|
|
36
|
+
hiddenUserInfo: hiddenUserInfo,
|
|
37
|
+
insertContent: insertContent,
|
|
38
|
+
hiddenComment: hiddenComment,
|
|
39
|
+
onContentChange: onContentChange
|
|
34
40
|
})));
|
|
35
41
|
};
|
|
36
42
|
var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(SeafileCommentEditor);
|
package/package.json
CHANGED