@seafile/comment-editor 0.0.1-alpha.68 → 0.0.1-alpha.69
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/editor/comment-editor.js +171 -173
- package/package.json +1 -1
|
@@ -30,10 +30,11 @@ var _slateToMd = _interopRequireDefault(require("../slate-convert/slate-to-md"))
|
|
|
30
30
|
var _eventBus = _interopRequireDefault(require("../utils/event-bus"));
|
|
31
31
|
var _eventHandler = _interopRequireDefault(require("../utils/event-handler"));
|
|
32
32
|
require("./comment-editor.css");
|
|
33
|
-
const getSubmitTip = (type, content) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
33
|
+
// const getSubmitTip = (type, content) => {
|
|
34
|
+
// if (content) return 'Save';
|
|
35
|
+
// return type === 'comment' ? 'Comment' : 'Reply';
|
|
36
|
+
// };
|
|
37
|
+
|
|
37
38
|
const DEFAULT_PLACEHOLDER = 'Enter_comment_shift_enter_for_new_line_Enter_to_send';
|
|
38
39
|
const CommentEditor = _ref => {
|
|
39
40
|
let {
|
|
@@ -46,178 +47,175 @@ const CommentEditor = _ref => {
|
|
|
46
47
|
toolMenus = ['text_style', _constants2.BLOCKQUOTE, _constants2.UNORDERED_LIST, _constants2.ORDERED_LIST, _constants2.LINK, _constants2.IMAGE],
|
|
47
48
|
closePanel
|
|
48
49
|
} = _ref;
|
|
49
|
-
const commentWrapperRef =
|
|
50
|
-
const {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
50
|
+
// const commentWrapperRef = useRef();
|
|
51
|
+
// const { t } = useTranslation('sdoc-editor');
|
|
52
|
+
// const { className, userInfo, type, addParticipants } = useComment();
|
|
53
|
+
// const submitTip = useMemo(() => getSubmitTip(type, content), [content, type]);
|
|
54
|
+
|
|
55
|
+
// const document = useMemo(() => {
|
|
56
|
+
// const cursor = {};
|
|
57
|
+
// let elements = null;
|
|
58
|
+
// elements = [generateEmptyElement(PARAGRAPH, { placeholder })];
|
|
59
|
+
// return { elements, cursor };
|
|
60
|
+
// }, [placeholder]);
|
|
61
|
+
|
|
62
|
+
// const [slateValue, setSlateValue] = useState(document.elements);
|
|
63
|
+
// const commentEditorContainerRef = useRef(null);
|
|
64
|
+
|
|
65
|
+
// const editor = useMemo(() => {
|
|
66
|
+
// const defaultEditor = createCommentEditor();
|
|
67
|
+
// const newEditor = withNodeId(defaultEditor);
|
|
68
|
+
// const { cursors } = document;
|
|
69
|
+
// newEditor.cursors = cursors || {};
|
|
70
|
+
// newEditor.width = COMMENT_EDITOR_EDIT_AREA_WIDTH; // default width
|
|
71
|
+
// newEditor.editorType = COMMENT_EDITOR;
|
|
72
|
+
|
|
73
|
+
// return newEditor;
|
|
74
|
+
// }, [document]);
|
|
75
|
+
|
|
76
|
+
// const { cursors } = useCursors(editor);
|
|
77
|
+
// const decorate = usePipDecorate(editor);
|
|
78
|
+
// // init eventHandler
|
|
79
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
+
// const eventProxy = useMemo(() => new EventProxy(editor), []);
|
|
81
|
+
|
|
82
|
+
// const onSubmit = useCallback((event) => {
|
|
83
|
+
// event && event.stopPropagation();
|
|
84
|
+
|
|
85
|
+
// const mdString = slateToMdString(editor.children);
|
|
86
|
+
// if (mdString && mdString.trim()) insertContent(mdString);
|
|
87
|
+
|
|
88
|
+
// addParticipants && addParticipants(userInfo.username);
|
|
89
|
+
|
|
90
|
+
// editor.children = [generateEmptyElement(PARAGRAPH, { placeholder })];
|
|
91
|
+
// Transforms.select(editor, Editor.start(editor, []));
|
|
92
|
+
|
|
93
|
+
// onContentChange && onContentChange(null);
|
|
94
|
+
// closePanel && closePanel();
|
|
95
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
// }, [editor, insertContent, addParticipants, placeholder, onContentChange, closePanel]);
|
|
97
|
+
|
|
98
|
+
// const onSubmitByEnterKey = useCallback((event) => {
|
|
99
|
+
// if (!ReactEditor.isFocused(editor)) return;
|
|
100
|
+
// onSubmit(event);
|
|
101
|
+
// }, [editor, onSubmit]);
|
|
102
|
+
|
|
103
|
+
// // addEventListener
|
|
104
|
+
// useEffect(() => {
|
|
105
|
+
// const eventBus = EventBus.getInstance();
|
|
106
|
+
// const unsubscribePostComment = eventBus.subscribe(INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmitByEnterKey);
|
|
107
|
+
|
|
108
|
+
// return () => {
|
|
109
|
+
// unsubscribePostComment();
|
|
110
|
+
// };
|
|
111
|
+
// }, [onSubmitByEnterKey]);
|
|
112
|
+
|
|
113
|
+
// const onCancel = useCallback((event) => {
|
|
114
|
+
// event.stopPropagation();
|
|
115
|
+
// const { type: eventType, keyCode, target } = event;
|
|
116
|
+
// if (eventType === 'keydown' && keyCode !== KeyCodes.Esc) return;
|
|
117
|
+
// if (eventType === 'click') {
|
|
118
|
+
// const isSdocContentWrapper = target.classList.contains('sdoc-content-wrapper');
|
|
119
|
+
// const listContainer = window.document.querySelector('#global-comment-list-container');
|
|
120
|
+
// const resizeContainer = window.document.querySelector('.sdoc-comment-resize-handler');
|
|
121
|
+
// const isClickOnListContainer = listContainer && listContainer.contains(target);
|
|
122
|
+
// const isClickOnCommentEditorContainer = commentWrapperRef.current.contains(target);
|
|
123
|
+
// const isClickResizeContainer = resizeContainer && resizeContainer.contains(target);
|
|
124
|
+
// const isPreventCancel = isClickOnListContainer || isClickOnCommentEditorContainer || isClickResizeContainer || isSdocContentWrapper;
|
|
125
|
+
// if (isPreventCancel) return;
|
|
126
|
+
// }
|
|
127
|
+
// hiddenComment && hiddenComment(false);
|
|
128
|
+
|
|
129
|
+
// if (onContentChange) {
|
|
130
|
+
// if (editor.children.find(n => Node.string(n).trim())) {
|
|
131
|
+
// onContentChange(slateToMdString(editor.children));
|
|
132
|
+
// } else {
|
|
133
|
+
// onContentChange(null);
|
|
134
|
+
// }
|
|
135
|
+
// }
|
|
136
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
137
|
+
// }, []);
|
|
138
|
+
|
|
139
|
+
// // set editor children
|
|
140
|
+
// useEffect(() => {
|
|
141
|
+
// let children = mdStringToSlate(content);
|
|
142
|
+
// editor.children = children;
|
|
143
|
+
// // Transforms.select(editor, Editor.end(editor, []));
|
|
144
|
+
// }, [editor, content]);
|
|
145
|
+
|
|
146
|
+
// // useMount: focus editor
|
|
147
|
+
// useEffect(() => {
|
|
148
|
+
// const [firstNode] = editor.children;
|
|
149
|
+
// if (firstNode) {
|
|
150
|
+
// const [firstNodeFirstChild] = firstNode.children;
|
|
151
|
+
|
|
152
|
+
// if (firstNodeFirstChild) {
|
|
153
|
+
// const endOfFirstNode = Editor.end(editor, [0, 0]);
|
|
154
|
+
// const range = {
|
|
155
|
+
// anchor: endOfFirstNode,
|
|
156
|
+
// focus: endOfFirstNode,
|
|
157
|
+
// };
|
|
158
|
+
// // focusEditor(editor, range);
|
|
159
|
+
// }
|
|
160
|
+
// // Force refresh to fix comment list
|
|
161
|
+
// // setSlateValue([...editor.children]);
|
|
162
|
+
// }
|
|
163
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
164
|
+
// }, []);
|
|
165
|
+
|
|
166
|
+
// const handleFocusEditor = (e) => {
|
|
167
|
+
// if (e.target === commentEditorContainerRef.current) {
|
|
168
|
+
// const focusPoint = Editor.end(editor, []);
|
|
169
|
+
// focusEditor(editor, focusPoint);
|
|
170
|
+
// }
|
|
171
|
+
// };
|
|
172
|
+
|
|
173
|
+
// const handleScrollIntoView = useCallback((editor, domRange) => {
|
|
174
|
+
// try {
|
|
175
|
+
// const { selection } = editor;
|
|
176
|
+
// // Do not scroll into view, when focus on image
|
|
177
|
+
// const [imageNodeEntry] = Editor.nodes(editor, {
|
|
178
|
+
// match: n => [IMAGE, IMAGE_BLOCK].includes(n.type),
|
|
179
|
+
// at: selection
|
|
180
|
+
// });
|
|
181
|
+
// if (imageNodeEntry) return;
|
|
182
|
+
// const focusedNode = Node.get(editor, selection.focus.path);
|
|
183
|
+
// const domNode = ReactEditor.toDOMNode(editor, focusedNode);
|
|
184
|
+
// if (!domNode) return;
|
|
185
|
+
// scrollIntoView(domNode, { 'scrollMode': 'if-needed' });
|
|
186
|
+
// } catch (error) {
|
|
187
|
+
// //
|
|
188
|
+
// }
|
|
189
|
+
// }, []);
|
|
190
|
+
|
|
191
|
+
// const onMouseDown = useCallback((event) => {
|
|
192
|
+
// if (event.button === 0) {
|
|
193
|
+
// // Compatible with the editor which unload table plugin
|
|
194
|
+
// editor.reSetTableSelectedRange && editor.reSetTableSelectedRange();
|
|
195
|
+
// const eventBus = EventBus.getInstance();
|
|
196
|
+
// eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
197
|
+
// }
|
|
198
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
199
|
+
// }, []);
|
|
200
|
+
|
|
201
|
+
// const onKeyDown = useCallback((event) => {
|
|
202
|
+
// if (isHotkey('enter', event)) {
|
|
203
|
+
// event.preventDefault();
|
|
204
|
+
// const eventBus = EventBus.getInstance();
|
|
205
|
+
// eventBus.dispatch(INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, event);
|
|
206
|
+
// return;
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
// if (isHotkey('shift+enter', event)) {
|
|
210
|
+
// event.preventDefault();
|
|
211
|
+
// Editor.insertBreak(editor);
|
|
212
|
+
// return;
|
|
213
|
+
// }
|
|
108
214
|
|
|
109
|
-
//
|
|
110
|
-
(0, _react.useEffect)(() => {
|
|
111
|
-
const eventBus = _eventBus.default.getInstance();
|
|
112
|
-
const unsubscribePostComment = eventBus.subscribe(_constants.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, onSubmitByEnterKey);
|
|
113
|
-
return () => {
|
|
114
|
-
unsubscribePostComment();
|
|
115
|
-
};
|
|
116
|
-
}, [onSubmitByEnterKey]);
|
|
117
|
-
const onCancel = (0, _react.useCallback)(event => {
|
|
118
|
-
event.stopPropagation();
|
|
119
|
-
const {
|
|
120
|
-
type: eventType,
|
|
121
|
-
keyCode,
|
|
122
|
-
target
|
|
123
|
-
} = event;
|
|
124
|
-
if (eventType === 'keydown' && keyCode !== _constants.KeyCodes.Esc) return;
|
|
125
|
-
if (eventType === 'click') {
|
|
126
|
-
const isSdocContentWrapper = target.classList.contains('sdoc-content-wrapper');
|
|
127
|
-
const listContainer = window.document.querySelector('#global-comment-list-container');
|
|
128
|
-
const resizeContainer = window.document.querySelector('.sdoc-comment-resize-handler');
|
|
129
|
-
const isClickOnListContainer = listContainer && listContainer.contains(target);
|
|
130
|
-
const isClickOnCommentEditorContainer = commentWrapperRef.current.contains(target);
|
|
131
|
-
const isClickResizeContainer = resizeContainer && resizeContainer.contains(target);
|
|
132
|
-
const isPreventCancel = isClickOnListContainer || isClickOnCommentEditorContainer || isClickResizeContainer || isSdocContentWrapper;
|
|
133
|
-
if (isPreventCancel) return;
|
|
134
|
-
}
|
|
135
|
-
hiddenComment && hiddenComment(false);
|
|
136
|
-
if (onContentChange) {
|
|
137
|
-
if (editor.children.find(n => _slate.Node.string(n).trim())) {
|
|
138
|
-
onContentChange((0, _slateToMd.default)(editor.children));
|
|
139
|
-
} else {
|
|
140
|
-
onContentChange(null);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
144
|
-
}, []);
|
|
215
|
+
// eventProxy.onKeyDown(event);
|
|
145
216
|
|
|
146
|
-
//
|
|
147
|
-
(0, _react.useEffect)(() => {
|
|
148
|
-
let children = (0, _mdToSlate.default)(content);
|
|
149
|
-
editor.children = children;
|
|
150
|
-
// Transforms.select(editor, Editor.end(editor, []));
|
|
151
|
-
}, [editor, content]);
|
|
217
|
+
// }, [eventProxy, editor]);
|
|
152
218
|
|
|
153
|
-
// useMount: focus editor
|
|
154
|
-
(0, _react.useEffect)(() => {
|
|
155
|
-
const [firstNode] = editor.children;
|
|
156
|
-
if (firstNode) {
|
|
157
|
-
const [firstNodeFirstChild] = firstNode.children;
|
|
158
|
-
if (firstNodeFirstChild) {
|
|
159
|
-
const endOfFirstNode = _slate.Editor.end(editor, [0, 0]);
|
|
160
|
-
const range = {
|
|
161
|
-
anchor: endOfFirstNode,
|
|
162
|
-
focus: endOfFirstNode
|
|
163
|
-
};
|
|
164
|
-
// focusEditor(editor, range);
|
|
165
|
-
}
|
|
166
|
-
// Force refresh to fix comment list
|
|
167
|
-
// setSlateValue([...editor.children]);
|
|
168
|
-
}
|
|
169
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
170
|
-
}, []);
|
|
171
|
-
const handleFocusEditor = e => {
|
|
172
|
-
if (e.target === commentEditorContainerRef.current) {
|
|
173
|
-
const focusPoint = _slate.Editor.end(editor, []);
|
|
174
|
-
(0, _core.focusEditor)(editor, focusPoint);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const handleScrollIntoView = (0, _react.useCallback)((editor, domRange) => {
|
|
178
|
-
try {
|
|
179
|
-
const {
|
|
180
|
-
selection
|
|
181
|
-
} = editor;
|
|
182
|
-
// Do not scroll into view, when focus on image
|
|
183
|
-
const [imageNodeEntry] = _slate.Editor.nodes(editor, {
|
|
184
|
-
match: n => [_constants2.IMAGE, _constants2.IMAGE_BLOCK].includes(n.type),
|
|
185
|
-
at: selection
|
|
186
|
-
});
|
|
187
|
-
if (imageNodeEntry) return;
|
|
188
|
-
const focusedNode = _slate.Node.get(editor, selection.focus.path);
|
|
189
|
-
const domNode = _slateReact.ReactEditor.toDOMNode(editor, focusedNode);
|
|
190
|
-
if (!domNode) return;
|
|
191
|
-
(0, _scrollIntoViewIfNeeded.default)(domNode, {
|
|
192
|
-
'scrollMode': 'if-needed'
|
|
193
|
-
});
|
|
194
|
-
} catch (error) {
|
|
195
|
-
//
|
|
196
|
-
}
|
|
197
|
-
}, []);
|
|
198
|
-
const onMouseDown = (0, _react.useCallback)(event => {
|
|
199
|
-
if (event.button === 0) {
|
|
200
|
-
// Compatible with the editor which unload table plugin
|
|
201
|
-
editor.reSetTableSelectedRange && editor.reSetTableSelectedRange();
|
|
202
|
-
const eventBus = _eventBus.default.getInstance();
|
|
203
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
204
|
-
}
|
|
205
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
206
|
-
}, []);
|
|
207
|
-
const onKeyDown = (0, _react.useCallback)(event => {
|
|
208
|
-
if ((0, _isHotkey.default)('enter', event)) {
|
|
209
|
-
event.preventDefault();
|
|
210
|
-
const eventBus = _eventBus.default.getInstance();
|
|
211
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.COMMENT_EDITOR_POST_COMMENT, event);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if ((0, _isHotkey.default)('shift+enter', event)) {
|
|
215
|
-
event.preventDefault();
|
|
216
|
-
_slate.Editor.insertBreak(editor);
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
eventProxy.onKeyDown(event);
|
|
220
|
-
}, [eventProxy, editor]);
|
|
221
219
|
console.log('toolMenus', toolMenus);
|
|
222
220
|
return /*#__PURE__*/_react.default.createElement("div", null, "123")
|
|
223
221
|
// <div className={classNames('comment-editor-wrapper', className)} ref={commentWrapperRef}>
|