@seafile/sdoc-editor 0.1.145 → 0.1.146-beta

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.
Files changed (33) hide show
  1. package/dist/api/sdoc-server-api.js +10 -0
  2. package/dist/api/seafile-api.js +27 -5
  3. package/dist/basic-sdk/assets/css/default.css +5 -2
  4. package/dist/basic-sdk/comment/comment/comment-editor.js +4 -4
  5. package/dist/basic-sdk/constants/index.js +14 -1
  6. package/dist/basic-sdk/editor/common-editor.js +47 -0
  7. package/dist/basic-sdk/editor/index.css +29 -0
  8. package/dist/basic-sdk/editor/index.js +340 -0
  9. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  10. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  11. package/dist/basic-sdk/extension/constants/font.js +1 -1
  12. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  13. package/dist/basic-sdk/socket/helpers.js +2 -0
  14. package/dist/basic-sdk/socket/socket-client.js +41 -0
  15. package/dist/basic-sdk/socket/socket-manager.js +26 -2
  16. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  17. package/dist/basic-sdk/utils/diff.js +2 -2
  18. package/dist/basic-sdk/utils/rebase.js +196 -0
  19. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  20. package/dist/basic-sdk/views/viewer.js +8 -11
  21. package/dist/components/doc-operations/index.js +8 -2
  22. package/dist/components/doc-operations/revision-operations/index.js +11 -3
  23. package/dist/components/doc-operations/revision-operations/publish-button.js +16 -13
  24. package/dist/components/tip-dialog/index.css +0 -0
  25. package/dist/components/tip-dialog/index.js +49 -0
  26. package/dist/components/tip-dialog/tip-content.js +56 -0
  27. package/dist/constants/index.js +23 -2
  28. package/dist/context.js +35 -4
  29. package/dist/pages/simple-editor.js +268 -72
  30. package/package.json +1 -1
  31. package/public/locales/en/sdoc-editor.json +13 -1
  32. package/public/locales/zh_CN/sdoc-editor.json +12 -1
  33. package/dist/basic-sdk/editor.js +0 -105
@@ -58,6 +58,16 @@ var SDocServerApi = /*#__PURE__*/function () {
58
58
  }
59
59
  });
60
60
  }
61
+
62
+ // saveDocContentByRebase(content) {
63
+ // const { server, docUuid, accessToken } = this;
64
+ // const url = `${server}/api/v1/docs/${docUuid}/rebase/`;
65
+
66
+ // const formData = new FormData();
67
+ // formData.append('doc_content', JSON.stringify(content));
68
+
69
+ // return axios.post(url, formData, {headers: {Authorization: `Token ${accessToken}`}});
70
+ // }
61
71
  }, {
62
72
  key: "getCollaborators",
63
73
  value: function getCollaborators() {
@@ -48,9 +48,11 @@ var SeafileAPI = /*#__PURE__*/function () {
48
48
  }
49
49
  }, {
50
50
  key: "sdocPublishRevision",
51
- value: function sdocPublishRevision(docUuid) {
51
+ value: function sdocPublishRevision(docUuid, replace) {
52
52
  var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
53
- return this.req.post(url);
53
+ var form = new FormData();
54
+ form.append('replace', replace);
55
+ return this._sendPostRequest(url, form);
54
56
  }
55
57
  }, {
56
58
  key: "startRevise",
@@ -63,9 +65,9 @@ var SeafileAPI = /*#__PURE__*/function () {
63
65
  return this._sendPostRequest(url, form);
64
66
  }
65
67
  }, {
66
- key: "getSeadocRevisionDownloadLinks",
67
- value: function getSeadocRevisionDownloadLinks(docUuid) {
68
- var url = '/api/v2.1/seadoc/revision/download-links/' + docUuid + '/';
68
+ key: "getSeadocOriginFileDownloadLink",
69
+ value: function getSeadocOriginFileDownloadLink(docUuid) {
70
+ var url = '/api/v2.1/seadoc/origin-file-download-link/' + docUuid + '/';
69
71
  return this.req.get(url);
70
72
  }
71
73
  }, {
@@ -81,6 +83,26 @@ var SeafileAPI = /*#__PURE__*/function () {
81
83
  var url = 'api/v2.1/seadoc/revisions/' + docUuid + '/?page=' + page + '&per_page=' + perPage;
82
84
  return this.req.get(url);
83
85
  }
86
+ }, {
87
+ key: "deleteSdocRevision",
88
+ value: function deleteSdocRevision(docUuid) {
89
+ var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
90
+ return this.req.delete(url);
91
+ }
92
+ }, {
93
+ key: "mergeSdocRevision",
94
+ value: function mergeSdocRevision(docUuid) {
95
+ var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
96
+ return this.req.put(url);
97
+ }
98
+ }, {
99
+ key: "getFileHistoryVersion",
100
+ value: function getFileHistoryVersion(docUuid, fileVersion, docPath) {
101
+ var url = 'api/v2.1/seadoc/history-content/' + docUuid + '/?p=' + encodeURIComponent(docPath) + '&file_version=' + fileVersion;
102
+ return this.req.get(url);
103
+ }
104
+
105
+ // local files
84
106
  }, {
85
107
  key: "getSdocFiles",
86
108
  value: function getSdocFiles(docUuid, p) {
@@ -1,9 +1,12 @@
1
1
  /* modify default css */
2
- .sdoc-editor-container .article,
3
- .sdoc-editor-container .sdoc-code-block-pre {
2
+ .sdoc-editor-container .article {
4
3
  font-size: 11pt;
5
4
  }
6
5
 
6
+ .sdoc-editor-container .sdoc-code-block-pre {
7
+ font-size: 10pt;
8
+ }
9
+
7
10
  .sdoc-editor-container .article p {
8
11
  padding: 5px 0;
9
12
  margin: 0;
@@ -25,7 +25,7 @@ var CommentEditor = function CommentEditor(_ref) {
25
25
  // onMount
26
26
  useEffect(function () {
27
27
  if (content) {
28
- commentRef.current.innerHTML = content;
28
+ commentRef.current.textContent = content;
29
29
  }
30
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
31
31
  }, []);
@@ -39,14 +39,14 @@ var CommentEditor = function CommentEditor(_ref) {
39
39
  }, [content, insertContent, updateContent]);
40
40
  var onSubmit = useCallback(function (event) {
41
41
  event && event.stopPropagation();
42
- var value = commentRef.current.innerHTML;
42
+ var value = commentRef.current.textContent;
43
43
  updateValue(value);
44
- commentRef.current.innerHTML = '';
44
+ commentRef.current.textContent = '';
45
45
  }, [updateValue]);
46
46
  var onCancel = useCallback(function (event) {
47
47
  event.stopPropagation();
48
48
  setIsFocus(false);
49
- commentRef.current.innerHTML = '';
49
+ commentRef.current.textContent = '';
50
50
  setIsEditing && setIsEditing(false);
51
51
  }, [setIsEditing]);
52
52
  var onKeyDown = useCallback(function (event) {
@@ -5,4 +5,17 @@ export var INTERNAL_EVENT = {
5
5
  ON_MOUSE_ENTER_BLOCK: 'on_mouse_enter_block',
6
6
  INSERT_ELEMENT: 'insert_element'
7
7
  };
8
- export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
8
+ export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
9
+
10
+ export var MODIFY_TYPE = {
11
+ ADD: 'add',
12
+ DELETE: 'delete',
13
+ MODIFY: 'modify',
14
+ CHILDREN_MODIFY: 'children-modify'
15
+ };
16
+ export var REBASE_TYPE = {
17
+ MODIFY_MODIFY: 'modify-modify',
18
+ DELETE_MODIFY: 'delete-modify',
19
+ CHILDREN_MODIFY: 'children-modify'
20
+ };
21
+ export var REBASE_MARKS = ['origin', 'rebaseType', 'oldElement'];
@@ -0,0 +1,47 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect } from 'react';
3
+ import { Editor } from '@seafile/slate';
4
+ import { focusEditor } from '../extension/core';
5
+ import { EditorContainer, EditorContent } from '../layout';
6
+ import SlateEditor from './slate-editor';
7
+ var CommonEditor = function CommonEditor(_ref) {
8
+ var slateValue = _ref.slateValue,
9
+ updateSlateValue = _ref.updateSlateValue,
10
+ editor = _ref.editor,
11
+ renderElement = _ref.renderElement;
12
+ // useMount: focus editor
13
+ useEffect(function () {
14
+ var timer = setTimeout(function () {
15
+ var _editor$children = _slicedToArray(editor.children, 1),
16
+ firstNode = _editor$children[0];
17
+ if (firstNode) {
18
+ var _firstNode$children = _slicedToArray(firstNode.children, 1),
19
+ firstNodeFirstChild = _firstNode$children[0];
20
+ if (firstNodeFirstChild) {
21
+ var endOfFirstNode = Editor.end(editor, [0, 0]);
22
+ var range = {
23
+ anchor: endOfFirstNode,
24
+ focus: endOfFirstNode
25
+ };
26
+ focusEditor(editor, range);
27
+ }
28
+ }
29
+ }, 300);
30
+ return function () {
31
+ clearTimeout(timer);
32
+ };
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ }, []);
35
+ return /*#__PURE__*/React.createElement(EditorContainer, {
36
+ editor: editor
37
+ }, /*#__PURE__*/React.createElement(EditorContent, {
38
+ docValue: slateValue,
39
+ showOutline: true
40
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
41
+ editor: editor,
42
+ slateValue: slateValue,
43
+ setSlateValue: updateSlateValue,
44
+ renderElement: renderElement
45
+ })));
46
+ };
47
+ export default CommonEditor;
@@ -0,0 +1,29 @@
1
+ .sdoc-rebase-btn-group {
2
+ color: #aaa;
3
+ }
4
+
5
+ .sdoc-rebase-btn-group .sdoc-rebase-btn {
6
+ cursor: pointer;
7
+ }
8
+
9
+ .sdoc-rebase-current-changes-start {
10
+ background-color: rgb(202, 232, 254);
11
+ }
12
+
13
+ .sdoc-rebase-current-changes {
14
+ background-color: rgba(202, 232, 254, .8);
15
+ }
16
+
17
+ .sdoc-rebase-incoming-changes {
18
+ background-color: rgb(222, 232, 254);
19
+ }
20
+
21
+ .sdoc-rebase-incoming-changes > *:first-child,
22
+ .sdoc-rebase-current-changes > *:first-child {
23
+ margin: 0;
24
+ padding: 0.8em 0 0.8em 0.2em;
25
+ }
26
+
27
+ .sdoc-rebase-incoming-changes-end {
28
+ background-color: rgb(212, 212, 254);
29
+ }
@@ -0,0 +1,340 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import React, { useMemo, useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react';
5
+ import deepCopy from 'deep-copy';
6
+ import { Transforms } from '@seafile/slate';
7
+ import { useTranslation } from 'react-i18next';
8
+ import { createDefaultEditor, renderElement } from '../extension';
9
+ import { withSocketIO } from '../socket';
10
+ import withNodeId from '../node-id';
11
+ import { PAGE_EDIT_AREA_WIDTH, REBASE_TYPE, REBASE_MARKS } from '../constants';
12
+ import { MODE } from '../../constants';
13
+ import DiffViewer from '../views/diff-viewer';
14
+ import SDocEditor from './common-editor';
15
+ import CommonLoading from '../../components/common-loading';
16
+ import context from '../../context';
17
+ import { findPath, getNode, replaceNode, generateEmptyElement, deleteNodeMark } from '../extension/core';
18
+ import { ELEMENT_TYPE } from '../extension/constants';
19
+ import './index.css';
20
+ var Editor = forwardRef(function (_ref, ref) {
21
+ var mode = _ref.mode,
22
+ document = _ref.document,
23
+ setDiffChanges = _ref.setDiffChanges;
24
+ var _useTranslation = useTranslation(),
25
+ t = _useTranslation.t;
26
+ var editor = useMemo(function () {
27
+ var defaultEditor = createDefaultEditor();
28
+ var editorConfig = context.getEditorConfig();
29
+ defaultEditor.mode = MODE.EDITOR;
30
+ var newEditor = withNodeId(withSocketIO(defaultEditor, {
31
+ document: document,
32
+ config: editorConfig
33
+ }));
34
+ var cursors = document.cursors;
35
+ newEditor.cursors = cursors || {};
36
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
37
+ return newEditor;
38
+
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, []);
41
+ var _useState = useState(document.children),
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ slateValue = _useState2[0],
44
+ _setSlateValue = _useState2[1];
45
+ var _useState3 = useState(false),
46
+ _useState4 = _slicedToArray(_useState3, 2),
47
+ isLoading = _useState4[0],
48
+ _setLoading = _useState4[1];
49
+ var _useState5 = useState(null),
50
+ _useState6 = _slicedToArray(_useState5, 2),
51
+ diffContent = _useState6[0],
52
+ _setDiffContent = _useState6[1];
53
+ var _useState7 = useState(null),
54
+ _useState8 = _slicedToArray(_useState7, 2),
55
+ currentContent = _useState8[0],
56
+ setCurrentContent = _useState8[1];
57
+
58
+ // useMount: init socket connection
59
+ useEffect(function () {
60
+ editor.openConnection();
61
+ return function () {
62
+ editor.closeConnection();
63
+ };
64
+
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, []);
67
+ var updateSlateValue = useCallback(function (value) {
68
+ _setSlateValue(value);
69
+
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, []);
72
+
73
+ // The parent component can call the method of this component through ref
74
+ useImperativeHandle(ref, function () {
75
+ return {
76
+ // set value
77
+ setLoading: function setLoading(isLoading) {
78
+ _setLoading(isLoading);
79
+ },
80
+ setDiffContent: function setDiffContent(content) {
81
+ setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
82
+ children: slateValue
83
+ })));
84
+ _setDiffContent(content);
85
+ },
86
+ setEditorMode: function setEditorMode(mode) {
87
+ editor.cursors = {};
88
+ editor.selection = null;
89
+ if (mode === MODE.EDITOR) {
90
+ editor.operations = [];
91
+ }
92
+ editor.mode = mode;
93
+ },
94
+ setSlateValue: function setSlateValue(document) {
95
+ _setSlateValue(document.children);
96
+ },
97
+ // get value
98
+ getSlateValue: function getSlateValue() {
99
+ return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
100
+ children: slateValue
101
+ }));
102
+ },
103
+ // send message
104
+ publishDocument: function publishDocument(originFileURL) {
105
+ editor.publishDocument(originFileURL);
106
+ },
107
+ mergeDocument: function mergeDocument(value, originFileVersion) {
108
+ editor.mergeDocument(value, originFileVersion);
109
+ }
110
+
111
+ // eslint-disable-next-line react-hooks/exhaustive-deps
112
+ };
113
+ }, [document, editor, slateValue]);
114
+ var updateParentNodeByPath = useCallback(function (path) {
115
+ var parentPath = path.slice(0, -1);
116
+ var parentNode = getNode(editor, parentPath);
117
+ if (parentNode.children.filter(function (item) {
118
+ return item.rebaseType;
119
+ }).length === 0) {
120
+ var newParentElement = _objectSpread({}, parentNode);
121
+ newParentElement['rebaseType'] && delete newParentElement['rebaseType'];
122
+ newParentElement['oldElement'] && delete newParentElement['oldElement'];
123
+ newParentElement['origin'] && delete newParentElement['origin'];
124
+ newParentElement['children'] = newParentElement['children'].map(function (item) {
125
+ item['rebaseType'] && delete item['rebaseType'];
126
+ item['oldElement'] && delete item['oldElement'];
127
+ item['origin'] && delete item['origin'];
128
+ return item;
129
+ });
130
+ replaceNode(editor, {
131
+ at: parentPath,
132
+ nodes: newParentElement
133
+ });
134
+ }
135
+
136
+ // eslint-disable-next-line react-hooks/exhaustive-deps
137
+ }, [editor]);
138
+ var deleteElement = useCallback(function (element) {
139
+ var path = findPath(editor, element);
140
+ Transforms.removeNodes(editor, {
141
+ at: path
142
+ });
143
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
144
+ updateParentNodeByPath(path);
145
+ }
146
+
147
+ // eslint-disable-next-line react-hooks/exhaustive-deps
148
+ }, [slateValue, editor]);
149
+ var deleteMark = useCallback(function (element) {
150
+ var path = findPath(editor, element);
151
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
152
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
153
+ updateParentNodeByPath(path);
154
+ }
155
+
156
+ // eslint-disable-next-line react-hooks/exhaustive-deps
157
+ }, [slateValue, editor]);
158
+ var addDeletedElement = useCallback(function (element) {
159
+ var path = findPath(editor, element);
160
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
161
+ if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
162
+ var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
163
+ Transforms.insertNodes(editor, emptyNode, {
164
+ at: [path[0]]
165
+ });
166
+ } else {
167
+ var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
168
+ _emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
169
+ var parentPath = path.slice(0, -1);
170
+ var parentNode = getNode(editor, parentPath);
171
+ var newChildren = _toConsumableArray(parentNode.children);
172
+ var index = path[path.length - 1];
173
+ newChildren.splice(index, 0, _emptyNode);
174
+ replaceNode(editor, {
175
+ at: parentPath,
176
+ nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
177
+ children: newChildren
178
+ })
179
+ });
180
+ }
181
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
182
+ updateParentNodeByPath(path);
183
+ }
184
+
185
+ // eslint-disable-next-line react-hooks/exhaustive-deps
186
+ }, [slateValue, editor]);
187
+ var useMasterChanges = useCallback(function (element) {
188
+ var path = findPath(editor, element);
189
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
190
+ var nextElementPath = _toConsumableArray(path);
191
+ nextElementPath[path.length - 1] = path[path.length - 1] + 1;
192
+ Transforms.removeNodes(editor, {
193
+ at: nextElementPath
194
+ });
195
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
196
+ updateParentNodeByPath(path);
197
+ }
198
+
199
+ // eslint-disable-next-line react-hooks/exhaustive-deps
200
+ }, [slateValue, editor]);
201
+ var useCurrentChanges = useCallback(function (element) {
202
+ var path = findPath(editor, element);
203
+ var currentElementPath = _toConsumableArray(path);
204
+ currentElementPath[path.length - 1] = path[path.length - 1] + 1;
205
+ var currentElement = getNode(editor, currentElementPath);
206
+ var newCurrentElement = deepCopy(currentElement);
207
+ deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
208
+ Transforms.removeNodes(editor, {
209
+ at: path
210
+ });
211
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
212
+ updateParentNodeByPath(path);
213
+ }
214
+
215
+ // eslint-disable-next-line react-hooks/exhaustive-deps
216
+ }, [slateValue, editor]);
217
+ var useBothChanges = useCallback(function (element) {
218
+ // delete element marks
219
+ var path = findPath(editor, element);
220
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
221
+
222
+ // delete next element marks
223
+ var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
224
+ var nextElement = getNode(editor, nextElementPath);
225
+ deleteNodeMark(editor, nextElementPath, nextElement, REBASE_MARKS);
226
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
227
+ updateParentNodeByPath(path);
228
+ }
229
+
230
+ // eslint-disable-next-line react-hooks/exhaustive-deps
231
+ }, [slateValue, editor]);
232
+ var customRenderElement = useCallback(function (props) {
233
+ var element = props.element;
234
+ if (!element.rebaseType) {
235
+ return renderElement(props);
236
+ }
237
+ if (element.rebaseType === REBASE_TYPE.DELETE_MODIFY) {
238
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
239
+ className: "w-100 d-flex sdoc-rebase-btn-group",
240
+ contentEditable: false
241
+ }, /*#__PURE__*/React.createElement("div", {
242
+ className: "sdoc-rebase-btn",
243
+ onClick: function onClick() {
244
+ return deleteElement(element);
245
+ }
246
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
247
+ className: "mr-2 ml-2"
248
+ }, '|'), /*#__PURE__*/React.createElement("div", {
249
+ className: "sdoc-rebase-btn",
250
+ onClick: function onClick() {
251
+ return deleteMark(element);
252
+ }
253
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
254
+ className: "mr-2 ml-2"
255
+ }, '|'), /*#__PURE__*/React.createElement("div", {
256
+ className: "sdoc-rebase-btn",
257
+ onClick: function onClick() {
258
+ return addDeletedElement(element);
259
+ }
260
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
261
+ className: "w-100 sdoc-rebase-current-changes-start",
262
+ contentEditable: false
263
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
264
+ className: "w-100",
265
+ contentEditable: false
266
+ }, '======='), /*#__PURE__*/React.createElement("div", {
267
+ className: "w-100 sdoc-rebase-incoming-changes"
268
+ }, renderElement(props)), /*#__PURE__*/React.createElement("div", {
269
+ className: "w-100 sdoc-rebase-incoming-changes-end",
270
+ contentEditable: false
271
+ }, '>>>>>>>'));
272
+ }
273
+ if (element.rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
274
+ if (element.origin === 'master') {
275
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
276
+ className: "w-100 d-flex sdoc-rebase-btn-group",
277
+ contentEditable: false
278
+ }, /*#__PURE__*/React.createElement("div", {
279
+ className: "sdoc-rebase-btn",
280
+ onClick: function onClick() {
281
+ return useMasterChanges(element);
282
+ }
283
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
284
+ className: "mr-2 ml-2"
285
+ }, '|'), /*#__PURE__*/React.createElement("div", {
286
+ className: "sdoc-rebase-btn",
287
+ onClick: function onClick() {
288
+ return useCurrentChanges(element);
289
+ }
290
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
291
+ className: "mr-2 ml-2"
292
+ }, '|'), /*#__PURE__*/React.createElement("div", {
293
+ className: "sdoc-rebase-btn",
294
+ onClick: function onClick() {
295
+ return useBothChanges(element);
296
+ }
297
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
298
+ className: "w-100 sdoc-rebase-current-changes-start",
299
+ contentEditable: false
300
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
301
+ className: "w-100 sdoc-rebase-current-changes"
302
+ }, renderElement(props)));
303
+ }
304
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
305
+ className: "w-100",
306
+ contentEditable: false
307
+ }, '======='), /*#__PURE__*/React.createElement("div", {
308
+ className: "w-100 sdoc-rebase-incoming-changes"
309
+ }, renderElement(props)), /*#__PURE__*/React.createElement("div", {
310
+ className: "w-100 sdoc-rebase-incoming-changes-end",
311
+ contentEditable: false
312
+ }, '>>>>>>>'));
313
+ }
314
+ return renderElement(props);
315
+
316
+ // eslint-disable-next-line react-hooks/exhaustive-deps
317
+ }, []);
318
+ if (isLoading) {
319
+ return /*#__PURE__*/React.createElement("div", {
320
+ className: "h-100 w-100 d-flex align-items-center justify-content-center"
321
+ }, /*#__PURE__*/React.createElement(CommonLoading, null));
322
+ }
323
+ if (mode === MODE.DIFF_VIEWER) {
324
+ return /*#__PURE__*/React.createElement(DiffViewer, {
325
+ showToolbar: true,
326
+ showOutline: true,
327
+ editor: editor,
328
+ currentContent: currentContent,
329
+ lastContent: diffContent,
330
+ didMountCallback: setDiffChanges
331
+ });
332
+ }
333
+ return /*#__PURE__*/React.createElement(SDocEditor, {
334
+ slateValue: slateValue,
335
+ editor: editor,
336
+ updateSlateValue: updateSlateValue,
337
+ renderElement: customRenderElement
338
+ });
339
+ });
340
+ export default Editor;
@@ -1,22 +1,24 @@
1
1
  import React, { useCallback, useMemo, Fragment } from 'react';
2
2
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
3
- import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from './extension';
4
- import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
5
- import EventProxy from './utils/event-handler';
6
- import { useCursors } from './cursor/use-cursors';
7
- import { INTERNAL_EVENT } from './constants';
8
- import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
9
- import CommentContextProvider from './comment/comment-context-provider';
10
- import CommentWrapper from './comment';
11
- import { usePipDecorate } from './decorates';
12
- import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
13
- import EventBus from './utils/event-bus';
14
- import { ArticleContainer } from './layout';
15
- import { useScrollContext } from './hooks/use-scroll-context';
3
+ import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '../extension';
4
+ import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
5
+ import EventProxy from '../utils/event-handler';
6
+ import { useCursors } from '../cursor/use-cursors';
7
+ import { INTERNAL_EVENT } from '../constants';
8
+ import { SetNodeToDecorations } from '../highlight-decorate/setNodeToDecorations';
9
+ import CommentContextProvider from '../comment/comment-context-provider';
10
+ import CommentWrapper from '../comment';
11
+ import { usePipDecorate } from '../decorates';
12
+ import { getCursorPosition, getDomHeight, getDomMarginTop } from '../utils/dom-utils';
13
+ import EventBus from '../utils/event-bus';
14
+ import { ArticleContainer } from '../layout';
15
+ import { useScrollContext } from '../hooks/use-scroll-context';
16
16
  var SlateEditor = function SlateEditor(_ref) {
17
17
  var editor = _ref.editor,
18
18
  setSlateValue = _ref.setSlateValue,
19
- slateValue = _ref.slateValue;
19
+ slateValue = _ref.slateValue,
20
+ customRenderElement = _ref.renderElement,
21
+ isShowComment = _ref.isShowComment;
20
22
  var _useCursors = useCursors(editor),
21
23
  cursors = _useCursors.cursors;
22
24
  var decorate = usePipDecorate(editor);
@@ -138,12 +140,15 @@ var SlateEditor = function SlateEditor(_ref) {
138
140
  editor: editor
139
141
  }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
140
142
  cursors: cursors,
141
- renderElement: renderElement,
143
+ renderElement: customRenderElement || renderElement,
142
144
  renderLeaf: renderLeaf,
143
145
  onKeyDown: onKeyDown,
144
146
  onMouseDown: onMouseDown,
145
147
  decorate: decorate,
146
148
  onCut: eventProxy.onCut
147
- })), /*#__PURE__*/React.createElement(SideToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
149
+ })), /*#__PURE__*/React.createElement(SideToolbar, null), isShowComment && /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
150
+ };
151
+ SlateEditor.defaultProps = {
152
+ isShowComment: true
148
153
  };
149
154
  export default SlateEditor;
@@ -46,4 +46,7 @@ export var SDOC_LINK = 'sdoc-link';
46
46
  // font
47
47
  export var FONT_SIZE = 'font-size';
48
48
  export var FONT_SIZE_INCREASE = 'font-size-increase';
49
- export var FONT_SIZE_REDUCE = 'font-size-reduce';
49
+ export var FONT_SIZE_REDUCE = 'font-size-reduce';
50
+
51
+ // rebase
52
+ export var REBASE_ELEMENT = 'rebase-element';
@@ -522,4 +522,4 @@ export var FONT = [
522
522
 
523
523
  export var SDOC_FONT_SIZE = (_SDOC_FONT_SIZE = {
524
524
  DEFAULT: 11
525
- }, _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.TITLE, 26), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.SUBTITLE, 15), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER1, 20), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER2, 16), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER3, 14), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER4, 12), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER5, 11), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER6, 11), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.CODE_LINE, 11), _SDOC_FONT_SIZE);
525
+ }, _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.TITLE, 26), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.SUBTITLE, 15), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER1, 20), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER2, 16), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER3, 14), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER4, 12), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER5, 11), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.HEADER6, 11), _defineProperty(_SDOC_FONT_SIZE, ELEMENT_TYPE.CODE_LINE, 10), _SDOC_FONT_SIZE);
@@ -12,4 +12,30 @@ export var replaceNodeChildren = function replaceNodeChildren(editor, _ref) {
12
12
  at: at.concat([0])
13
13
  }));
14
14
  });
15
+ };
16
+ export var replaceNode = function replaceNode(editor) {
17
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
18
+ at = _ref2.at,
19
+ nodes = _ref2.nodes,
20
+ insertOptions = _ref2.insertOptions,
21
+ removeOptions = _ref2.removeOptions;
22
+ Editor.withoutNormalizing(editor, function () {
23
+ Transforms.removeNodes(editor, _objectSpread({
24
+ at: at
25
+ }, removeOptions));
26
+ Transforms.insertNodes(editor, nodes, _objectSpread(_objectSpread({}, insertOptions), {}, {
27
+ at: at
28
+ }));
29
+ });
30
+ };
31
+ export var deleteNodeMark = function deleteNodeMark(editor, path, element) {
32
+ var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
33
+ var newElement = _objectSpread({}, element);
34
+ marks.forEach(function (markItem) {
35
+ newElement[markItem] && delete newElement[markItem];
36
+ });
37
+ replaceNode(editor, {
38
+ at: path,
39
+ nodes: newElement
40
+ });
15
41
  };
@@ -4,6 +4,7 @@ import { Editor, Operation } from '@seafile/slate';
4
4
  import { getNode } from '../extension/core';
5
5
  import * as OPERATION from '../node-id/constants';
6
6
  import { setCursor } from '../cursor/helper';
7
+ import { MODE } from '../../constants';
7
8
  export var getNodePathById = function getNodePathById(rootNode, nodeId) {
8
9
  var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
9
10
  if (rootNode.id === nodeId) return path;
@@ -252,6 +253,7 @@ export var reExecRevertOperationList = function reExecRevertOperationList(editor
252
253
  }
253
254
  };
254
255
  export var syncRemoteOperations = function syncRemoteOperations(editor, remoteOperations) {
256
+ if (editor.mode !== MODE.EDITOR) return;
255
257
  if (remoteOperations.length === 0) return;
256
258
  Editor.withoutNormalizing(editor, function () {
257
259
  for (var i = 0; i < remoteOperations.length; i++) {