@seafile/comment-editor 0.0.1-alpha.14 → 0.0.1-alpha.16
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.
|
@@ -38,10 +38,11 @@ const DEFAULT_PLACEHOLDER = 'Enter_comment_shift_enter_for_new_line_Enter_to_sen
|
|
|
38
38
|
const CommentEditor = _ref => {
|
|
39
39
|
let {
|
|
40
40
|
content,
|
|
41
|
-
commentContent,
|
|
42
41
|
placeholder = DEFAULT_PLACEHOLDER,
|
|
43
42
|
insertContent,
|
|
43
|
+
// add
|
|
44
44
|
updateContent,
|
|
45
|
+
// edit
|
|
45
46
|
onContentChange,
|
|
46
47
|
setIsEditing,
|
|
47
48
|
hiddenComment,
|
|
@@ -90,24 +91,20 @@ const CommentEditor = _ref => {
|
|
|
90
91
|
// init eventHandler
|
|
91
92
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
93
|
const eventProxy = (0, _react.useMemo)(() => new _eventHandler.default(editor), []);
|
|
93
|
-
const updateValue = (0, _react.useCallback)(value => {
|
|
94
|
-
if (!value || value.trim() === '') return;
|
|
95
|
-
if (!content) return insertContent(value);
|
|
96
|
-
updateContent && updateContent(value);
|
|
97
|
-
}, [content, insertContent, updateContent]);
|
|
98
94
|
const onSubmit = (0, _react.useCallback)(event => {
|
|
99
95
|
event && event.stopPropagation();
|
|
100
96
|
const mdString = (0, _slateToMd.default)(editor.children);
|
|
101
|
-
|
|
97
|
+
if (mdString.trim()) {
|
|
98
|
+
content ? insertContent(mdString) : updateContent(mdString);
|
|
99
|
+
}
|
|
102
100
|
addParticipants(userInfo.username);
|
|
103
101
|
editor.children = [(0, _core.generateEmptyElement)(_constants2.PARAGRAPH, {
|
|
104
102
|
placeholder
|
|
105
103
|
})];
|
|
106
104
|
_slate.Transforms.select(editor, _slate.Editor.start(editor, []));
|
|
107
105
|
onContentChange && onContentChange(null);
|
|
108
|
-
console.log('closeComment', closeComment);
|
|
109
106
|
closeComment && closeComment();
|
|
110
|
-
}, [editor,
|
|
107
|
+
}, [editor, addParticipants, userInfo.username, placeholder, onContentChange, closeComment, content, insertContent, updateContent]);
|
|
111
108
|
const onSubmitByEnterKey = (0, _react.useCallback)(event => {
|
|
112
109
|
if (!_slateReact.ReactEditor.isFocused(editor)) return;
|
|
113
110
|
onSubmit(event);
|
|
@@ -122,6 +119,7 @@ const CommentEditor = _ref => {
|
|
|
122
119
|
};
|
|
123
120
|
}, [onSubmitByEnterKey]);
|
|
124
121
|
const onCancel = (0, _react.useCallback)(event => {
|
|
122
|
+
console.log('onCancel');
|
|
125
123
|
event.stopPropagation();
|
|
126
124
|
const {
|
|
127
125
|
type: eventType,
|
|
@@ -154,12 +152,9 @@ const CommentEditor = _ref => {
|
|
|
154
152
|
// set editor children
|
|
155
153
|
(0, _react.useEffect)(() => {
|
|
156
154
|
let children = (0, _mdToSlate.default)(content);
|
|
157
|
-
if (commentContent) {
|
|
158
|
-
children = (0, _mdToSlate.default)(commentContent);
|
|
159
|
-
}
|
|
160
155
|
editor.children = children;
|
|
161
156
|
_slate.Transforms.select(editor, _slate.Editor.end(editor, []));
|
|
162
|
-
}, [editor, content
|
|
157
|
+
}, [editor, content]);
|
|
163
158
|
|
|
164
159
|
// useMount: focus editor
|
|
165
160
|
(0, _react.useEffect)(() => {
|
|
@@ -19,8 +19,9 @@ const CommentProvider = _ref => {
|
|
|
19
19
|
type,
|
|
20
20
|
// comment or replay
|
|
21
21
|
userInfo,
|
|
22
|
-
pluginName = '',
|
|
23
22
|
className = '',
|
|
23
|
+
pluginName = '',
|
|
24
|
+
// sdoc or wiki or txt ...
|
|
24
25
|
pluginEventBus,
|
|
25
26
|
pluginEvent
|
|
26
27
|
} = _ref;
|
|
@@ -29,8 +30,8 @@ const CommentProvider = _ref => {
|
|
|
29
30
|
value: {
|
|
30
31
|
type,
|
|
31
32
|
userInfo,
|
|
32
|
-
pluginName,
|
|
33
33
|
className,
|
|
34
|
+
pluginName,
|
|
34
35
|
pluginEventBus,
|
|
35
36
|
pluginEvent,
|
|
36
37
|
collaborators
|
|
@@ -11,35 +11,38 @@ var _basicSdk = require("../basic-sdk");
|
|
|
11
11
|
var _errorBoundary = _interopRequireDefault(require("../components/error-boundary"));
|
|
12
12
|
const SeafileCommentEditor = _ref => {
|
|
13
13
|
let {
|
|
14
|
+
// Provider
|
|
14
15
|
type,
|
|
16
|
+
// comment or replay
|
|
15
17
|
userInfo,
|
|
16
|
-
pluginName = '',
|
|
17
18
|
className = '',
|
|
19
|
+
pluginName = '',
|
|
20
|
+
// sdoc or wiki or txt ...
|
|
21
|
+
pluginEventBus,
|
|
22
|
+
pluginEvent,
|
|
23
|
+
// Comment editor
|
|
18
24
|
content,
|
|
19
25
|
updateContent,
|
|
20
26
|
insertContent,
|
|
21
27
|
onContentChange,
|
|
22
|
-
commentContent,
|
|
23
28
|
hiddenUserInfo,
|
|
24
29
|
hiddenComment,
|
|
25
30
|
closeComment,
|
|
26
31
|
setIsEditing,
|
|
27
32
|
addParticipants,
|
|
28
|
-
|
|
29
|
-
pluginEvent,
|
|
33
|
+
// api
|
|
30
34
|
api
|
|
31
35
|
} = _ref;
|
|
32
36
|
_basicSdk.context.init(api);
|
|
33
37
|
return /*#__PURE__*/_react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
|
|
34
38
|
type: type,
|
|
35
39
|
userInfo: userInfo,
|
|
36
|
-
pluginName: pluginName,
|
|
37
40
|
className: className,
|
|
41
|
+
pluginName: pluginName,
|
|
38
42
|
pluginEventBus: pluginEventBus,
|
|
39
43
|
pluginEvent: pluginEvent
|
|
40
44
|
}, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentEditor, {
|
|
41
45
|
content: content,
|
|
42
|
-
commentContent: commentContent,
|
|
43
46
|
updateContent: updateContent,
|
|
44
47
|
insertContent: insertContent,
|
|
45
48
|
onContentChange: onContentChange,
|