@seafile/sdoc-editor 0.1.147 → 0.1.148-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 (32) 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/constants/index.js +14 -1
  4. package/dist/basic-sdk/editor/common-editor.js +50 -0
  5. package/dist/basic-sdk/editor/index.css +29 -0
  6. package/dist/basic-sdk/editor/index.js +129 -0
  7. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  8. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  9. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  10. package/dist/basic-sdk/extension/plugins/font/helpers.js +1 -1
  11. package/dist/basic-sdk/extension/render/render-element.js +209 -1
  12. package/dist/basic-sdk/socket/helpers.js +2 -0
  13. package/dist/basic-sdk/socket/socket-client.js +38 -0
  14. package/dist/basic-sdk/socket/socket-manager.js +25 -2
  15. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  16. package/dist/basic-sdk/utils/diff.js +2 -2
  17. package/dist/basic-sdk/utils/rebase.js +197 -0
  18. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  19. package/dist/basic-sdk/views/viewer.js +8 -11
  20. package/dist/components/doc-operations/index.js +4 -2
  21. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  22. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  23. package/dist/components/tip-dialog/index.css +0 -0
  24. package/dist/components/tip-dialog/index.js +49 -0
  25. package/dist/components/tip-dialog/tip-content.js +56 -0
  26. package/dist/constants/index.js +23 -2
  27. package/dist/context.js +35 -4
  28. package/dist/pages/simple-editor.js +247 -83
  29. package/package.json +1 -1
  30. package/public/locales/en/sdoc-editor.json +11 -1
  31. package/public/locales/zh_CN/sdoc-editor.json +10 -1
  32. 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: "updateSdocRevision",
94
+ value: function updateSdocRevision(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) {
@@ -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,50 @@
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
+ import InsertElementDialog from '../extension/commons/insert-element-dialog';
8
+ var CommonEditor = function CommonEditor(_ref) {
9
+ var slateValue = _ref.slateValue,
10
+ updateSlateValue = _ref.updateSlateValue,
11
+ editor = _ref.editor,
12
+ renderElement = _ref.renderElement;
13
+ // useMount: focus editor
14
+ useEffect(function () {
15
+ var timer = setTimeout(function () {
16
+ var _editor$children = _slicedToArray(editor.children, 1),
17
+ firstNode = _editor$children[0];
18
+ if (firstNode) {
19
+ var _firstNode$children = _slicedToArray(firstNode.children, 1),
20
+ firstNodeFirstChild = _firstNode$children[0];
21
+ if (firstNodeFirstChild) {
22
+ var endOfFirstNode = Editor.end(editor, [0, 0]);
23
+ var range = {
24
+ anchor: endOfFirstNode,
25
+ focus: endOfFirstNode
26
+ };
27
+ focusEditor(editor, range);
28
+ }
29
+ }
30
+ }, 300);
31
+ return function () {
32
+ clearTimeout(timer);
33
+ };
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
37
+ editor: editor
38
+ }, /*#__PURE__*/React.createElement(EditorContent, {
39
+ docValue: slateValue,
40
+ showOutline: true
41
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
42
+ editor: editor,
43
+ slateValue: slateValue,
44
+ setSlateValue: updateSlateValue,
45
+ renderElement: renderElement
46
+ }))), /*#__PURE__*/React.createElement(InsertElementDialog, {
47
+ editor: editor
48
+ }));
49
+ };
50
+ 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,129 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import React, { useMemo, useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react';
4
+ import deepCopy from 'deep-copy';
5
+ import { createDefaultEditor, renderElement } from '../extension';
6
+ import { withSocketIO } from '../socket';
7
+ import withNodeId from '../node-id';
8
+ import { PAGE_EDIT_AREA_WIDTH } from '../constants';
9
+ import { MODE } from '../../constants';
10
+ import DiffViewer from '../views/diff-viewer';
11
+ import SDocEditor from './common-editor';
12
+ import CommonLoading from '../../components/common-loading';
13
+ import context from '../../context';
14
+ import './index.css';
15
+ var Editor = forwardRef(function (_ref, ref) {
16
+ var mode = _ref.mode,
17
+ document = _ref.document,
18
+ setDiffChanges = _ref.setDiffChanges;
19
+ var editor = useMemo(function () {
20
+ var defaultEditor = createDefaultEditor();
21
+ var editorConfig = context.getEditorConfig();
22
+ defaultEditor.mode = MODE.EDITOR;
23
+ var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
+ document: document,
25
+ config: editorConfig
26
+ }));
27
+ var cursors = document.cursors;
28
+ newEditor.cursors = cursors || {};
29
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
30
+ return newEditor;
31
+
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
34
+ var _useState = useState(document.children),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ slateValue = _useState2[0],
37
+ _setSlateValue = _useState2[1];
38
+ var _useState3 = useState(false),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ isLoading = _useState4[0],
41
+ _setLoading = _useState4[1];
42
+ var _useState5 = useState(null),
43
+ _useState6 = _slicedToArray(_useState5, 2),
44
+ diffContent = _useState6[0],
45
+ _setDiffContent = _useState6[1];
46
+ var _useState7 = useState(null),
47
+ _useState8 = _slicedToArray(_useState7, 2),
48
+ currentContent = _useState8[0],
49
+ setCurrentContent = _useState8[1];
50
+
51
+ // useMount: init socket connection
52
+ useEffect(function () {
53
+ editor.openConnection();
54
+ return function () {
55
+ editor.closeConnection();
56
+ };
57
+
58
+ // eslint-disable-next-line react-hooks/exhaustive-deps
59
+ }, []);
60
+ var updateSlateValue = useCallback(function (value) {
61
+ _setSlateValue(value);
62
+
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ }, []);
65
+
66
+ // The parent component can call the method of this component through ref
67
+ useImperativeHandle(ref, function () {
68
+ return {
69
+ // set value
70
+ setLoading: function setLoading(isLoading) {
71
+ _setLoading(isLoading);
72
+ },
73
+ setDiffContent: function setDiffContent(content) {
74
+ setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
75
+ children: slateValue
76
+ })));
77
+ _setDiffContent(content);
78
+ },
79
+ setEditorMode: function setEditorMode(mode) {
80
+ editor.cursors = {};
81
+ editor.selection = null;
82
+ if (mode === MODE.EDITOR) {
83
+ editor.operations = [];
84
+ }
85
+ editor.mode = mode;
86
+ },
87
+ setSlateValue: function setSlateValue(document) {
88
+ _setSlateValue(document.children);
89
+ },
90
+ // get value
91
+ getSlateValue: function getSlateValue() {
92
+ return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
93
+ children: slateValue
94
+ }));
95
+ },
96
+ // send message
97
+ publishDocument: function publishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc) {
98
+ editor.publishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc);
99
+ },
100
+ replaceDocument: function replaceDocument(value, originFileVersion) {
101
+ editor.replaceDocument(value, originFileVersion);
102
+ }
103
+
104
+ // eslint-disable-next-line react-hooks/exhaustive-deps
105
+ };
106
+ }, [document, editor, slateValue]);
107
+ if (isLoading) {
108
+ return /*#__PURE__*/React.createElement("div", {
109
+ className: "h-100 w-100 d-flex align-items-center justify-content-center"
110
+ }, /*#__PURE__*/React.createElement(CommonLoading, null));
111
+ }
112
+ if (mode === MODE.DIFF_VIEWER) {
113
+ return /*#__PURE__*/React.createElement(DiffViewer, {
114
+ showToolbar: true,
115
+ showOutline: true,
116
+ editor: editor,
117
+ currentContent: currentContent,
118
+ lastContent: diffContent,
119
+ didMountCallback: setDiffChanges
120
+ });
121
+ }
122
+ return /*#__PURE__*/React.createElement(SDocEditor, {
123
+ slateValue: slateValue,
124
+ editor: editor,
125
+ updateSlateValue: updateSlateValue,
126
+ renderElement: renderElement
127
+ });
128
+ });
129
+ 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';
@@ -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
  };
@@ -131,7 +131,7 @@ export var loadFont = function loadFont() {
131
131
  };
132
132
  export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight, leaf) {
133
133
  var isCodeBlock = leaf && Object.keys(leaf).includes('token');
134
- if (isCodeBlock) return {};
134
+ if (isCodeBlock) return '';
135
135
  var lang = context.getSetting('lang') || 'zh-cn';
136
136
  if (fontName === DEFAULT_FONT) {
137
137
  return "'Arial', ".concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");
@@ -1,10 +1,16 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
4
  import React, { useCallback } from 'react';
3
5
  import { useSlateStatic } from '@seafile/slate-react';
6
+ import { Transforms } from '@seafile/slate';
7
+ import deepCopy from 'deep-copy';
8
+ import { useTranslation } from 'react-i18next';
4
9
  import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, CODE_LINE, IMAGE, ELEMENT_TYPE, SDOC_LINK, TITLE, SUBTITLE } from '../constants';
5
10
  import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin } from '../plugins';
6
11
  import EventBus from '../../utils/event-bus';
7
- import { INTERNAL_EVENT } from '../../constants';
12
+ import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS } from '../../constants';
13
+ import { findPath, getNode, replaceNode, generateEmptyElement, deleteNodeMark } from '../../extension/core';
8
14
  var CustomElement = function CustomElement(props) {
9
15
  var editor = useSlateStatic();
10
16
  var element = props.element,
@@ -140,6 +146,208 @@ var CustomElement = function CustomElement(props) {
140
146
  }
141
147
  };
142
148
  var RenderElement = function RenderElement(props) {
149
+ var editor = useSlateStatic();
150
+ var _useTranslation = useTranslation(),
151
+ t = _useTranslation.t;
152
+ var updateParentNodeByPath = useCallback(function (path) {
153
+ var parentPath = path.slice(0, -1);
154
+ var parentNode = getNode(editor, parentPath);
155
+ if (parentNode.children.filter(function (item) {
156
+ return item.rebaseType;
157
+ }).length === 0) {
158
+ var newParentElement = _objectSpread({}, parentNode);
159
+ newParentElement['rebaseType'] && delete newParentElement['rebaseType'];
160
+ newParentElement['oldElement'] && delete newParentElement['oldElement'];
161
+ newParentElement['origin'] && delete newParentElement['origin'];
162
+ newParentElement['children'] = newParentElement['children'].map(function (item) {
163
+ item['rebaseType'] && delete item['rebaseType'];
164
+ item['oldElement'] && delete item['oldElement'];
165
+ item['origin'] && delete item['origin'];
166
+ return item;
167
+ });
168
+ replaceNode(editor, {
169
+ at: parentPath,
170
+ nodes: newParentElement
171
+ });
172
+ }
173
+
174
+ // eslint-disable-next-line react-hooks/exhaustive-deps
175
+ }, [editor]);
176
+ var deleteElement = useCallback(function (element) {
177
+ var path = findPath(editor, element);
178
+ Transforms.removeNodes(editor, {
179
+ at: path
180
+ });
181
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
182
+ updateParentNodeByPath(path);
183
+ }
184
+
185
+ // eslint-disable-next-line react-hooks/exhaustive-deps
186
+ }, [editor]);
187
+ var deleteMark = useCallback(function (element) {
188
+ var path = findPath(editor, element);
189
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
190
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
191
+ updateParentNodeByPath(path);
192
+ }
193
+
194
+ // eslint-disable-next-line react-hooks/exhaustive-deps
195
+ }, [editor]);
196
+ var addDeletedElement = useCallback(function (element) {
197
+ var path = findPath(editor, element);
198
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
199
+ if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
200
+ var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
201
+ Transforms.insertNodes(editor, emptyNode, {
202
+ at: [path[0]]
203
+ });
204
+ } else {
205
+ var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
206
+ _emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
207
+ var parentPath = path.slice(0, -1);
208
+ var parentNode = getNode(editor, parentPath);
209
+ var newChildren = _toConsumableArray(parentNode.children);
210
+ var index = path[path.length - 1];
211
+ newChildren.splice(index, 0, _emptyNode);
212
+ replaceNode(editor, {
213
+ at: parentPath,
214
+ nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
215
+ children: newChildren
216
+ })
217
+ });
218
+ }
219
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
220
+ updateParentNodeByPath(path);
221
+ }
222
+
223
+ // eslint-disable-next-line react-hooks/exhaustive-deps
224
+ }, [editor]);
225
+ var useMasterChanges = useCallback(function (element) {
226
+ var path = findPath(editor, element);
227
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
228
+ var nextElementPath = _toConsumableArray(path);
229
+ nextElementPath[path.length - 1] = path[path.length - 1] + 1;
230
+ Transforms.removeNodes(editor, {
231
+ at: nextElementPath
232
+ });
233
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
234
+ updateParentNodeByPath(path);
235
+ }
236
+
237
+ // eslint-disable-next-line react-hooks/exhaustive-deps
238
+ }, [editor]);
239
+ var useCurrentChanges = useCallback(function (element) {
240
+ var path = findPath(editor, element);
241
+ var currentElementPath = _toConsumableArray(path);
242
+ currentElementPath[path.length - 1] = path[path.length - 1] + 1;
243
+ var currentElement = getNode(editor, currentElementPath);
244
+ var newCurrentElement = deepCopy(currentElement);
245
+ deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
246
+ Transforms.removeNodes(editor, {
247
+ at: path
248
+ });
249
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
250
+ updateParentNodeByPath(path);
251
+ }
252
+
253
+ // eslint-disable-next-line react-hooks/exhaustive-deps
254
+ }, [editor]);
255
+ var useBothChanges = useCallback(function (element) {
256
+ // delete element marks
257
+ var path = findPath(editor, element);
258
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
259
+
260
+ // delete next element marks
261
+ var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
262
+ var nextElement = getNode(editor, nextElementPath);
263
+ deleteNodeMark(editor, nextElementPath, nextElement, REBASE_MARKS);
264
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
265
+ updateParentNodeByPath(path);
266
+ }
267
+
268
+ // eslint-disable-next-line react-hooks/exhaustive-deps
269
+ }, [editor]);
270
+ var element = props.element;
271
+ if (!element.rebaseType) {
272
+ return /*#__PURE__*/React.createElement(CustomElement, props);
273
+ }
274
+ if (element.rebaseType === REBASE_TYPE.DELETE_MODIFY) {
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 deleteElement(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 deleteMark(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 addDeletedElement(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",
302
+ contentEditable: false
303
+ }, '======='), /*#__PURE__*/React.createElement("div", {
304
+ className: "w-100 sdoc-rebase-incoming-changes"
305
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
306
+ className: "w-100 sdoc-rebase-incoming-changes-end",
307
+ contentEditable: false
308
+ }, '>>>>>>>'));
309
+ }
310
+ if (element.rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
311
+ if (element.origin === 'master') {
312
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
313
+ className: "w-100 d-flex sdoc-rebase-btn-group",
314
+ contentEditable: false
315
+ }, /*#__PURE__*/React.createElement("div", {
316
+ className: "sdoc-rebase-btn",
317
+ onClick: function onClick() {
318
+ return useMasterChanges(element);
319
+ }
320
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
321
+ className: "mr-2 ml-2"
322
+ }, '|'), /*#__PURE__*/React.createElement("div", {
323
+ className: "sdoc-rebase-btn",
324
+ onClick: function onClick() {
325
+ return useCurrentChanges(element);
326
+ }
327
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
328
+ className: "mr-2 ml-2"
329
+ }, '|'), /*#__PURE__*/React.createElement("div", {
330
+ className: "sdoc-rebase-btn",
331
+ onClick: function onClick() {
332
+ return useBothChanges(element);
333
+ }
334
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
335
+ className: "w-100 sdoc-rebase-current-changes-start",
336
+ contentEditable: false
337
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
338
+ className: "w-100 sdoc-rebase-current-changes"
339
+ }, /*#__PURE__*/React.createElement(CustomElement, props)));
340
+ }
341
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
342
+ className: "w-100",
343
+ contentEditable: false
344
+ }, '======='), /*#__PURE__*/React.createElement("div", {
345
+ className: "w-100 sdoc-rebase-incoming-changes"
346
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
347
+ className: "w-100 sdoc-rebase-incoming-changes-end",
348
+ contentEditable: false
349
+ }, '>>>>>>>'));
350
+ }
143
351
  return /*#__PURE__*/React.createElement(CustomElement, props);
144
352
 
145
353
  // const { element } = props;
@@ -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++) {