@seafile/comment-editor 0.0.1-alpha.2 → 0.0.1-alpha.20
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/context.js +2 -1
- package/dist/basic-sdk/editor/comment-editor.css +138 -0
- package/dist/basic-sdk/{comment/components → editor}/comment-editor.js +40 -28
- package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -1
- package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +1 -1
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +1 -2
- package/dist/basic-sdk/hooks/use-comment.js +16 -183
- package/dist/basic-sdk/index.js +3 -10
- package/dist/index.js +0 -12
- package/dist/pages/seafile-comment-editor.js +34 -14
- 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-context-menu/index.css +0 -16
- package/dist/basic-sdk/comment/components/comment-context-menu/index.js +0 -43
- package/dist/basic-sdk/comment/components/comment-context-menu/menu-item.js +0 -57
- 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-operation/index.css +0 -26
- package/dist/basic-sdk/comment/components/comment-operation/index.js +0 -31
- 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 -89
- 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/layout/comment-layout/index.css +0 -15
- package/dist/basic-sdk/layout/comment-layout/index.js +0 -87
- package/dist/basic-sdk/layout/comment-layout/resize-width/index.css +0 -38
- package/dist/basic-sdk/layout/comment-layout/resize-width/index.js +0 -132
- package/dist/basic-sdk/layout/editor-container.js +0 -32
- package/dist/basic-sdk/layout/index.js +0 -13
- 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
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _reactI18next = require("react-i18next");
|
|
11
|
-
var _reactstrap = require("reactstrap");
|
|
12
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
14
|
-
var _context = _interopRequireDefault(require("../../../context"));
|
|
15
|
-
var _core = require("../../../extension/core");
|
|
16
|
-
var _useComment = require("../../../hooks/use-comment");
|
|
17
|
-
var _constants = require("../../constants");
|
|
18
|
-
var _commentEditor = _interopRequireDefault(require("../comment-editor"));
|
|
19
|
-
var _commentItemCollapseWrapper = _interopRequireDefault(require("../comment-item-collapse-wrapper"));
|
|
20
|
-
var _commentItemWrapper = _interopRequireDefault(require("../comment-item-wrapper"));
|
|
21
|
-
var _globalCommentBodyHeader = _interopRequireDefault(require("./global-comment-body-header"));
|
|
22
|
-
var _globalCommentHeader = _interopRequireDefault(require("./global-comment-header"));
|
|
23
|
-
require("./index.css");
|
|
24
|
-
const GlobalComment = _ref => {
|
|
25
|
-
let {
|
|
26
|
-
editor,
|
|
27
|
-
t
|
|
28
|
-
} = _ref;
|
|
29
|
-
const contentRef = (0, _react.useRef)(null);
|
|
30
|
-
const commentDetailRef = (0, _react.useRef)(null);
|
|
31
|
-
const [activeCommentGroup, setActiveCommentGroup] = (0, _react.useState)(null);
|
|
32
|
-
const [showEditor, setShowEditor] = (0, _react.useState)(false);
|
|
33
|
-
const [isScrollDisplayed, setIsScrollDisplayed] = (0, _react.useState)(false);
|
|
34
|
-
const [globalCommentContent, setGlobalCommentContent] = (0, _react.useState)(null);
|
|
35
|
-
const {
|
|
36
|
-
api,
|
|
37
|
-
commentList,
|
|
38
|
-
commentType,
|
|
39
|
-
dispatch,
|
|
40
|
-
setCommentType,
|
|
41
|
-
onCloseCommentPanel,
|
|
42
|
-
deleteUnseenNotifications
|
|
43
|
-
} = (0, _useComment.useComment)();
|
|
44
|
-
const detectScroll = (0, _react.useCallback)(() => {
|
|
45
|
-
if (!contentRef.current) return;
|
|
46
|
-
const contentContainer = contentRef.current;
|
|
47
|
-
const isShowScroll = contentContainer.scrollHeight > contentContainer.clientHeight;
|
|
48
|
-
setIsScrollDisplayed(isShowScroll);
|
|
49
|
-
}, []);
|
|
50
|
-
const onCommentsPanelBodyScroll = (0, _react.useCallback)(position => {
|
|
51
|
-
var _contentRef$current, _contentRef$current2;
|
|
52
|
-
(_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.scrollTo({
|
|
53
|
-
top: position === 'top' ? 0 : (_contentRef$current2 = contentRef.current) === null || _contentRef$current2 === void 0 ? void 0 : _contentRef$current2.scrollHeight,
|
|
54
|
-
behavior: 'smooth'
|
|
55
|
-
});
|
|
56
|
-
}, [contentRef]);
|
|
57
|
-
(0, _react.useEffect)(() => {
|
|
58
|
-
detectScroll();
|
|
59
|
-
// When a comment is updated, update the comment details page
|
|
60
|
-
if (activeCommentGroup) {
|
|
61
|
-
const newActiveCommentGroup = commentList.find(item => item.id === activeCommentGroup.id);
|
|
62
|
-
setActiveCommentGroup(newActiveCommentGroup);
|
|
63
|
-
deleteUnseenNotifications && deleteUnseenNotifications(newActiveCommentGroup);
|
|
64
|
-
}
|
|
65
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
-
}, [commentList, detectScroll]);
|
|
67
|
-
const updateScrollPosition = (0, _react.useCallback)(() => {
|
|
68
|
-
var _contentRef$current3;
|
|
69
|
-
const resolvedDom = document.querySelector('.sdoc-resolved');
|
|
70
|
-
(_contentRef$current3 = contentRef.current) === null || _contentRef$current3 === void 0 ? void 0 : _contentRef$current3.scrollTo({
|
|
71
|
-
top: resolvedDom.offsetTop,
|
|
72
|
-
behavior: 'smooth'
|
|
73
|
-
});
|
|
74
|
-
}, []);
|
|
75
|
-
const insertDocComment = (0, _react.useCallback)(async commentDetail => {
|
|
76
|
-
var _commentDetailRef$cur;
|
|
77
|
-
// Reply to a comment
|
|
78
|
-
if (activeCommentGroup && (_commentDetailRef$cur = commentDetailRef.current) !== null && _commentDetailRef$cur !== void 0 && _commentDetailRef$cur.insertContent) {
|
|
79
|
-
commentDetailRef.current.insertContent(commentDetail);
|
|
80
|
-
} else {
|
|
81
|
-
// Insert global comment
|
|
82
|
-
const user = _context.default.getUserInfo();
|
|
83
|
-
const elementId = _constants.DOC_COMMENT_ELEMENT_ID;
|
|
84
|
-
const time = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
85
|
-
const comment = {
|
|
86
|
-
comment: commentDetail,
|
|
87
|
-
detail: {
|
|
88
|
-
element_id: elementId,
|
|
89
|
-
comment: commentDetail
|
|
90
|
-
},
|
|
91
|
-
author: user.username,
|
|
92
|
-
updated_at: time
|
|
93
|
-
};
|
|
94
|
-
const res = await api.insertComment(comment);
|
|
95
|
-
const {
|
|
96
|
-
comment: returnComment
|
|
97
|
-
} = res.data;
|
|
98
|
-
const newComment = {
|
|
99
|
-
...comment,
|
|
100
|
-
id: returnComment.id,
|
|
101
|
-
user_name: returnComment.user_name,
|
|
102
|
-
avatar_url: returnComment.avatar_url,
|
|
103
|
-
replies: []
|
|
104
|
-
};
|
|
105
|
-
dispatch({
|
|
106
|
-
type: 'INSERT_COMMENT',
|
|
107
|
-
payload: {
|
|
108
|
-
element_id: elementId,
|
|
109
|
-
comment: newComment
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
detectScroll();
|
|
113
|
-
}
|
|
114
|
-
// After the comment is inserted, scroll to the bottom
|
|
115
|
-
setTimeout(() => {
|
|
116
|
-
onCommentsPanelBodyScroll('bottom');
|
|
117
|
-
}, 500);
|
|
118
|
-
}, [activeCommentGroup, api, detectScroll, dispatch, onCommentsPanelBodyScroll]);
|
|
119
|
-
const hiddenCommentEditor = (0, _react.useCallback)(() => {
|
|
120
|
-
setShowEditor(false);
|
|
121
|
-
}, []);
|
|
122
|
-
const isClickCommentPanelBody = (0, _react.useCallback)(event => {
|
|
123
|
-
if (contentRef.current && contentRef.current.contains(event.target)) return true;
|
|
124
|
-
return false;
|
|
125
|
-
}, []);
|
|
126
|
-
const getNodeByElementId = (0, _react.useCallback)(elementId => {
|
|
127
|
-
if (elementId !== _constants.DOC_COMMENT_ELEMENT_ID) {
|
|
128
|
-
return (0, _core.getNodeById)(editor.children, elementId);
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}, [editor.children]);
|
|
132
|
-
const setCurrentCommentGroup = (0, _react.useCallback)(commentGroupId => {
|
|
133
|
-
const activeCommentGroup = commentList.find(item => item.id === commentGroupId);
|
|
134
|
-
if (activeCommentGroup) {
|
|
135
|
-
setActiveCommentGroup(activeCommentGroup);
|
|
136
|
-
deleteUnseenNotifications && deleteUnseenNotifications(activeCommentGroup);
|
|
137
|
-
} else {
|
|
138
|
-
setActiveCommentGroup(null);
|
|
139
|
-
}
|
|
140
|
-
}, [commentList, deleteUnseenNotifications]);
|
|
141
|
-
const commentEditorPlaceholder = !activeCommentGroup ? t('Enter_comment_shift_enter_for_new_line_Enter_to_send') : t('Enter_reply_shift_Enter_for_new_line_Enter_to_send');
|
|
142
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
143
|
-
className: "comment-drawer"
|
|
144
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
145
|
-
className: "comments-panel-wrapper"
|
|
146
|
-
}, /*#__PURE__*/_react.default.createElement(_globalCommentHeader.default, {
|
|
147
|
-
toggle: onCloseCommentPanel,
|
|
148
|
-
activeCommentGroup: activeCommentGroup,
|
|
149
|
-
setCurrentCommentGroup: setCurrentCommentGroup
|
|
150
|
-
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
151
|
-
className: "comments-panel-body"
|
|
152
|
-
}, !activeCommentGroup && /*#__PURE__*/_react.default.createElement(_globalCommentBodyHeader.default, {
|
|
153
|
-
commentList: commentList,
|
|
154
|
-
commentType: commentType,
|
|
155
|
-
setCommentType: setCommentType
|
|
156
|
-
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
157
|
-
ref: contentRef,
|
|
158
|
-
className: "comments-panel-body__content"
|
|
159
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
160
|
-
id: "global-comment-list-container",
|
|
161
|
-
className: "sdoc-comment-list-container"
|
|
162
|
-
}, !activeCommentGroup && Array.isArray(commentList) && commentList.map(comment => {
|
|
163
|
-
var _comment$replies, _comment$replies2;
|
|
164
|
-
const replyCount = (_comment$replies = comment.replies) === null || _comment$replies === void 0 ? void 0 : _comment$replies.length;
|
|
165
|
-
const latestReply = ((_comment$replies2 = comment.replies) === null || _comment$replies2 === void 0 ? void 0 : _comment$replies2.length) > 0 ? comment.replies[comment.replies.length - 1] : null;
|
|
166
|
-
const elementId = comment.detail.element_id;
|
|
167
|
-
const element = getNodeByElementId(elementId);
|
|
168
|
-
return /*#__PURE__*/_react.default.createElement(_commentItemCollapseWrapper.default, {
|
|
169
|
-
key: comment.id,
|
|
170
|
-
editor: editor,
|
|
171
|
-
element: element,
|
|
172
|
-
topLevelComment: comment,
|
|
173
|
-
replyCount: replyCount,
|
|
174
|
-
latestReply: latestReply,
|
|
175
|
-
setCurrentCommentGroup: setCurrentCommentGroup
|
|
176
|
-
});
|
|
177
|
-
}), activeCommentGroup && /*#__PURE__*/_react.default.createElement(_commentItemWrapper.default, {
|
|
178
|
-
key: activeCommentGroup.id,
|
|
179
|
-
editor: editor,
|
|
180
|
-
element: getNodeByElementId(activeCommentGroup.detail.element_id),
|
|
181
|
-
container: "global-comment-list-container",
|
|
182
|
-
commentDetailRef: commentDetailRef,
|
|
183
|
-
comment: activeCommentGroup,
|
|
184
|
-
isGlobalComment: true,
|
|
185
|
-
isActive: true,
|
|
186
|
-
updateScrollPosition: updateScrollPosition,
|
|
187
|
-
isClickCommentPanelBody: isClickCommentPanelBody,
|
|
188
|
-
setCurrentCommentGroup: setCurrentCommentGroup
|
|
189
|
-
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
190
|
-
className: (0, _classnames.default)('global-comment-input-wrapper', {
|
|
191
|
-
'active': globalCommentContent === null || globalCommentContent === void 0 ? void 0 : globalCommentContent.trim()
|
|
192
|
-
})
|
|
193
|
-
}, !showEditor && /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
194
|
-
value: globalCommentContent !== null && globalCommentContent !== void 0 && globalCommentContent.trim() ? '.....' : '',
|
|
195
|
-
readOnly: true,
|
|
196
|
-
placeholder: commentEditorPlaceholder,
|
|
197
|
-
onFocus: () => {
|
|
198
|
-
setShowEditor(true);
|
|
199
|
-
}
|
|
200
|
-
}), showEditor && /*#__PURE__*/_react.default.createElement("div", {
|
|
201
|
-
className: (0, _classnames.default)('global-comment-editor-container', 'sdoc-comment-list-container', {
|
|
202
|
-
'scrolled': isScrollDisplayed
|
|
203
|
-
})
|
|
204
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
205
|
-
className: "global-comment-editor-content"
|
|
206
|
-
}, /*#__PURE__*/_react.default.createElement(_commentEditor.default, {
|
|
207
|
-
type: activeCommentGroup ? 'replay' : 'comment',
|
|
208
|
-
commentContent: globalCommentContent,
|
|
209
|
-
hiddenUserInfo: true,
|
|
210
|
-
insertContent: insertDocComment,
|
|
211
|
-
hiddenComment: hiddenCommentEditor,
|
|
212
|
-
onContentChange: content => {
|
|
213
|
-
setGlobalCommentContent(content);
|
|
214
|
-
}
|
|
215
|
-
})))))));
|
|
216
|
-
};
|
|
217
|
-
var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(GlobalComment);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
Object.defineProperty(exports, "EditorComment", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _editorComment.default;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "GlobalComment", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _globalComment.default;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
var _editorComment = _interopRequireDefault(require("./editor-comment"));
|
|
20
|
-
var _globalComment = _interopRequireDefault(require("./global-comment"));
|
|
21
|
-
require("./style.css");
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/* editor-comment css */
|
|
2
|
-
.sdoc-comment-container {
|
|
3
|
-
position: absolute;
|
|
4
|
-
left: 0;
|
|
5
|
-
top: 0;
|
|
6
|
-
width: 100%;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.sdoc-comment-container .comment-container-main {
|
|
10
|
-
position: absolute;
|
|
11
|
-
width: 100%;
|
|
12
|
-
top: 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.sdoc-comment-container .comment-container-right {
|
|
16
|
-
position: absolute;
|
|
17
|
-
left: 100%;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.sdoc-comment-container .comment-container-right .comment-add-wrapper {
|
|
21
|
-
position: absolute;
|
|
22
|
-
left: -22px;
|
|
23
|
-
width: 20px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.sdoc-comment-container .comment-container-right .comment-add-wrapper .sdocfont {
|
|
27
|
-
color: #999;
|
|
28
|
-
background-color: #FFF;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.sdoc-comment-container .comment-container-right .comment-add-wrapper .sdocfont:hover {
|
|
32
|
-
color: #333;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.sdoc-comment-container .comment-container-right .comment-list-wrapper {
|
|
37
|
-
position: absolute;
|
|
38
|
-
left: 14px;
|
|
39
|
-
width: 280px;
|
|
40
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useCursorPosition = exports.updateElementsAttrs = exports.updateCommentedElementsAttrs = exports.getSelectionRange = exports.getSelectedElemIds = exports.getPrimaryElementId = exports.getElementCommentCountTop = exports.getDomById = exports.getCursorPosition = exports.getCommentedTextsByElementId = exports.getAvatarUrl = void 0;
|
|
8
|
-
var _slate = require("@seafile/slate");
|
|
9
|
-
var _slateReact = require("@seafile/slate-react");
|
|
10
|
-
var _context = _interopRequireDefault(require("../context"));
|
|
11
|
-
var _core = require("../extension/core");
|
|
12
|
-
var _useScrollContext = require("../hooks/use-scroll-context");
|
|
13
|
-
const getSelectionRange = () => {
|
|
14
|
-
if (window.getSelection) {
|
|
15
|
-
const sel = window.getSelection();
|
|
16
|
-
if (sel.getRangeAt && sel.rangeCount) {
|
|
17
|
-
return sel.getRangeAt(0);
|
|
18
|
-
}
|
|
19
|
-
} else if (document.selection && document.selection.createRange) {
|
|
20
|
-
return document.selection.createRange();
|
|
21
|
-
}
|
|
22
|
-
return null;
|
|
23
|
-
};
|
|
24
|
-
exports.getSelectionRange = getSelectionRange;
|
|
25
|
-
const getCursorPosition = () => {
|
|
26
|
-
let x = 0;
|
|
27
|
-
let y = 0;
|
|
28
|
-
let range = getSelectionRange();
|
|
29
|
-
if (range) {
|
|
30
|
-
const rect = range.getBoundingClientRect();
|
|
31
|
-
const headerHeight = 93;
|
|
32
|
-
x = rect.x || 0;
|
|
33
|
-
y = rect.y - headerHeight + (rect.height - 24) / 2 || 0;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
x: x,
|
|
37
|
-
y: y
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
exports.getCursorPosition = getCursorPosition;
|
|
41
|
-
const useCursorPosition = () => {
|
|
42
|
-
const scrollRef = (0, _useScrollContext.useScrollContext)();
|
|
43
|
-
const {
|
|
44
|
-
scrollTop = 0
|
|
45
|
-
} = scrollRef.current || {};
|
|
46
|
-
let position = getCursorPosition();
|
|
47
|
-
if (position.y !== 0) {
|
|
48
|
-
position.y = position.y + scrollTop;
|
|
49
|
-
}
|
|
50
|
-
return position;
|
|
51
|
-
};
|
|
52
|
-
exports.useCursorPosition = useCursorPosition;
|
|
53
|
-
const getAvatarUrl = () => {
|
|
54
|
-
const server = _context.default.getSetting('serviceUrl');
|
|
55
|
-
const avatarUrl = `${server}/media/avatars/default.png`;
|
|
56
|
-
return avatarUrl;
|
|
57
|
-
};
|
|
58
|
-
exports.getAvatarUrl = getAvatarUrl;
|
|
59
|
-
const getElementCommentCountTop = (editor, element, scrollTop) => {
|
|
60
|
-
let minY;
|
|
61
|
-
const children = element.children || [];
|
|
62
|
-
children.forEach(child => {
|
|
63
|
-
const childDom = _slateReact.ReactEditor.toDOMNode(editor, child);
|
|
64
|
-
|
|
65
|
-
// use child real dom
|
|
66
|
-
const childRealDom = childDom.childNodes[0];
|
|
67
|
-
const {
|
|
68
|
-
y
|
|
69
|
-
} = childRealDom ? childRealDom.getBoundingClientRect() : {
|
|
70
|
-
y: 0
|
|
71
|
-
};
|
|
72
|
-
if (!minY) minY = y;
|
|
73
|
-
minY = Math.min(minY, y);
|
|
74
|
-
});
|
|
75
|
-
return minY - 93 + scrollTop; // 100: header height(56) + toolbar height(37)
|
|
76
|
-
};
|
|
77
|
-
exports.getElementCommentCountTop = getElementCommentCountTop;
|
|
78
|
-
const getSelectedElemIds = editor => {
|
|
79
|
-
const {
|
|
80
|
-
selection
|
|
81
|
-
} = editor;
|
|
82
|
-
if (!selection) return;
|
|
83
|
-
const selectedElemId = [];
|
|
84
|
-
const nodeEntries = Array.from(_slate.Editor.nodes(editor, {
|
|
85
|
-
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
|
|
86
|
-
mode: 'lowest'
|
|
87
|
-
}));
|
|
88
|
-
for (const [node] of nodeEntries) {
|
|
89
|
-
selectedElemId.push(node.id);
|
|
90
|
-
}
|
|
91
|
-
return selectedElemId;
|
|
92
|
-
};
|
|
93
|
-
exports.getSelectedElemIds = getSelectedElemIds;
|
|
94
|
-
const getCommentedTextsByElementId = (elementId, textCommentId) => {
|
|
95
|
-
const container = document.querySelector(`[data-id='${elementId}']`);
|
|
96
|
-
if (!container) return [];
|
|
97
|
-
let targetDoms = container.querySelectorAll(`.sdoc_comment_${textCommentId}`);
|
|
98
|
-
if (targetDoms.length === 0) {
|
|
99
|
-
targetDoms = container.querySelectorAll(`.removed_sdoc_comment_${textCommentId}`);
|
|
100
|
-
}
|
|
101
|
-
const texts = [];
|
|
102
|
-
targetDoms.forEach(dom => {
|
|
103
|
-
var _dom$textContent;
|
|
104
|
-
texts.push(((_dom$textContent = dom.textContent) === null || _dom$textContent === void 0 ? void 0 : _dom$textContent.trim()) || '');
|
|
105
|
-
});
|
|
106
|
-
return texts;
|
|
107
|
-
};
|
|
108
|
-
exports.getCommentedTextsByElementId = getCommentedTextsByElementId;
|
|
109
|
-
const getDomById = elementId => {
|
|
110
|
-
const container = document.querySelector(`[data-id='${elementId}']`);
|
|
111
|
-
if (!container) return [];
|
|
112
|
-
const lastCommentedDomWithMarks = container.querySelector('.comment');
|
|
113
|
-
return lastCommentedDomWithMarks;
|
|
114
|
-
};
|
|
115
|
-
exports.getDomById = getDomById;
|
|
116
|
-
const updateElementsAttrs = (activeElementIds, editor, text_comment_id) => {
|
|
117
|
-
if (Array.isArray(activeElementIds)) {
|
|
118
|
-
for (const elemId of activeElementIds) {
|
|
119
|
-
const dom = document.querySelectorAll(`[data-id="${elemId}"]`)[0];
|
|
120
|
-
if (!dom) continue;
|
|
121
|
-
const domNode = _slateReact.ReactEditor.toSlateNode(editor, dom);
|
|
122
|
-
const nodePath = (0, _core.findPath)(editor, domNode);
|
|
123
|
-
domNode.children.forEach((textNode, index) => {
|
|
124
|
-
if (textNode.comment) {
|
|
125
|
-
const textNodePath = [...nodePath, index];
|
|
126
|
-
_slate.Transforms.setNodes(editor, {
|
|
127
|
-
[`sdoc_comment_${text_comment_id}`]: true
|
|
128
|
-
}, {
|
|
129
|
-
at: textNodePath,
|
|
130
|
-
match: _slate.Text.isText,
|
|
131
|
-
split: true
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
exports.updateElementsAttrs = updateElementsAttrs;
|
|
139
|
-
const updateCommentedElementsAttrs = function (activeElementIds, editor, text_comment_id) {
|
|
140
|
-
let resolved = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
141
|
-
let isDeleteComment = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
142
|
-
if (Array.isArray(activeElementIds)) {
|
|
143
|
-
_slate.Editor.withoutNormalizing(editor, () => {
|
|
144
|
-
for (const elemId of activeElementIds) {
|
|
145
|
-
// const { element } = elem;
|
|
146
|
-
const dom = document.querySelector(`[data-id="${elemId}"]`);
|
|
147
|
-
if (!dom) continue;
|
|
148
|
-
const domNode = _slateReact.ReactEditor.toSlateNode(editor, dom);
|
|
149
|
-
const domNodePath = (0, _core.findPath)(editor, domNode);
|
|
150
|
-
domNode.children.forEach((child, index) => {
|
|
151
|
-
const childPath = [...domNodePath, index];
|
|
152
|
-
if (_slate.Text.isText(child) && `sdoc_comment_${text_comment_id}` in child) {
|
|
153
|
-
_slate.Transforms.unsetNodes(editor, [`sdoc_comment_${text_comment_id}`], {
|
|
154
|
-
at: childPath,
|
|
155
|
-
match: _slate.Text.isText
|
|
156
|
-
});
|
|
157
|
-
!isDeleteComment && _slate.Transforms.setNodes(editor, {
|
|
158
|
-
[`sdoc_comment_${text_comment_id}`]: resolved
|
|
159
|
-
}, {
|
|
160
|
-
at: childPath,
|
|
161
|
-
match: _slate.Text.isText
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
exports.updateCommentedElementsAttrs = updateCommentedElementsAttrs;
|
|
170
|
-
const getPrimaryElementId = detail => {
|
|
171
|
-
if (!detail) return null;
|
|
172
|
-
let elementId;
|
|
173
|
-
const {
|
|
174
|
-
element_id,
|
|
175
|
-
element_id_list = []
|
|
176
|
-
} = detail;
|
|
177
|
-
if (element_id_list.length > 0) {
|
|
178
|
-
elementId = element_id_list[0];
|
|
179
|
-
} else {
|
|
180
|
-
elementId = element_id;
|
|
181
|
-
}
|
|
182
|
-
return elementId;
|
|
183
|
-
};
|
|
184
|
-
exports.getPrimaryElementId = getPrimaryElementId;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useCommentContext = exports.CommentContext = void 0;
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
const CommentContext = exports.CommentContext = /*#__PURE__*/_react.default.createContext();
|
|
10
|
-
const useCommentContext = () => {
|
|
11
|
-
const {
|
|
12
|
-
commentsInfo,
|
|
13
|
-
dispatch
|
|
14
|
-
} = (0, _react.useContext)(CommentContext);
|
|
15
|
-
return {
|
|
16
|
-
commentsInfo,
|
|
17
|
-
dispatch
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
exports.useCommentContext = useCommentContext;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _constants = require("../../constants");
|
|
9
|
-
var _useCommentContext = require("./use-comment-context");
|
|
10
|
-
const useCommentList = () => {
|
|
11
|
-
const {
|
|
12
|
-
commentsInfo,
|
|
13
|
-
dispatch
|
|
14
|
-
} = (0, _useCommentContext.useCommentContext)();
|
|
15
|
-
const {
|
|
16
|
-
comment_list
|
|
17
|
-
} = commentsInfo || {};
|
|
18
|
-
const [commentType, setCommentType] = (0, _react.useState)(_constants.COMMENT_TYPES.ALL);
|
|
19
|
-
const [commentList, setCommentList] = (0, _react.useState)([]);
|
|
20
|
-
(0, _react.useEffect)(() => {
|
|
21
|
-
if (commentType === _constants.COMMENT_TYPES.ALL) {
|
|
22
|
-
const commentList = comment_list.map(item => {
|
|
23
|
-
item.replies = item.replies.filter(reply => !['True', 'False'].includes(reply.reply));
|
|
24
|
-
return item;
|
|
25
|
-
});
|
|
26
|
-
setCommentList(commentList);
|
|
27
|
-
} else if (commentType === _constants.COMMENT_TYPES.RESOLVED) {
|
|
28
|
-
const commentList = comment_list.filter(item => item.resolved);
|
|
29
|
-
setCommentList(commentList);
|
|
30
|
-
} else if (commentType === _constants.COMMENT_TYPES.UNRESOLVED) {
|
|
31
|
-
const commentList = comment_list.filter(item => !item.resolved);
|
|
32
|
-
setCommentList(commentList);
|
|
33
|
-
} else if (commentType === _constants.COMMENT_TYPES.DOC) {
|
|
34
|
-
const commentList = comment_list.filter(comment => comment.detail.element_id === _constants.DOC_COMMENT_ELEMENT_ID);
|
|
35
|
-
setCommentList(commentList);
|
|
36
|
-
}
|
|
37
|
-
}, [commentType, comment_list]);
|
|
38
|
-
return {
|
|
39
|
-
dispatch,
|
|
40
|
-
commentList,
|
|
41
|
-
commentType,
|
|
42
|
-
setCommentType
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
var _default = exports.default = useCommentList;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useCommentsMount = void 0;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _constants = require("../../../constants");
|
|
10
|
-
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
|
|
11
|
-
const useCommentsMount = (dispatch, api) => {
|
|
12
|
-
const request = (0, _react.useCallback)(async () => {
|
|
13
|
-
dispatch({
|
|
14
|
-
type: 'FETCHING_STATE'
|
|
15
|
-
});
|
|
16
|
-
try {
|
|
17
|
-
const res = await api.listComments();
|
|
18
|
-
const comments = res.data.comments;
|
|
19
|
-
dispatch({
|
|
20
|
-
type: 'RECEIVE_STATE',
|
|
21
|
-
payload: comments
|
|
22
|
-
});
|
|
23
|
-
} catch (error) {
|
|
24
|
-
console.log(error);
|
|
25
|
-
dispatch({
|
|
26
|
-
type: 'FETCHING_ERROR'
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
-
}, []);
|
|
31
|
-
const reRequest = (0, _react.useCallback)(async () => {
|
|
32
|
-
dispatch({
|
|
33
|
-
type: 'REFETCHING_STATE'
|
|
34
|
-
});
|
|
35
|
-
try {
|
|
36
|
-
const res = await api.listComments();
|
|
37
|
-
const comments = res.data.comments;
|
|
38
|
-
dispatch({
|
|
39
|
-
type: 'RECEIVE_STATE',
|
|
40
|
-
payload: comments
|
|
41
|
-
});
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.log(error);
|
|
44
|
-
// dispatch({type: 'FETCHING_ERROR'});
|
|
45
|
-
}
|
|
46
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
47
|
-
}, []);
|
|
48
|
-
(0, _react.useEffect)(() => {
|
|
49
|
-
request();
|
|
50
|
-
const eventBus = _eventBus.default.getInstance();
|
|
51
|
-
const unsubscribeNewNotification = eventBus.subscribe(_constants.INTERNAL_EVENT.NEW_NOTIFICATION, reRequest);
|
|
52
|
-
return () => {
|
|
53
|
-
unsubscribeNewNotification();
|
|
54
|
-
};
|
|
55
|
-
}, [request, reRequest]);
|
|
56
|
-
};
|
|
57
|
-
exports.useCommentsMount = useCommentsMount;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "NotificationContext", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _useNotificationContext.NotificationContext;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "useNotificationContext", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _useNotificationContext.useNotificationContext;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "useNotificationsMount", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _useNotificationMount.useNotificationsMount;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
var _useNotificationContext = require("./use-notification-context");
|
|
25
|
-
var _useNotificationMount = require("./use-notification-mount");
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useNotificationContext = exports.NotificationContext = void 0;
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
const NotificationContext = exports.NotificationContext = /*#__PURE__*/_react.default.createContext();
|
|
10
|
-
const useNotificationContext = () => {
|
|
11
|
-
const {
|
|
12
|
-
notificationsInfo,
|
|
13
|
-
dispatch
|
|
14
|
-
} = (0, _react.useContext)(NotificationContext);
|
|
15
|
-
return {
|
|
16
|
-
notificationsInfo,
|
|
17
|
-
dispatch
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
exports.useNotificationContext = useNotificationContext;
|