@seafile/sdoc-editor 0.1.142 → 0.1.143-beta1

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 (45) 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/dropdown-menu.css +5 -1
  4. package/dist/basic-sdk/constants/index.js +14 -1
  5. package/dist/basic-sdk/editor/common-editor.js +45 -0
  6. package/dist/basic-sdk/editor/index.js +135 -0
  7. package/dist/basic-sdk/editor/rebase-editor/index.css +29 -0
  8. package/dist/basic-sdk/editor/rebase-editor/index.js +275 -0
  9. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  10. package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +12 -3
  11. package/dist/basic-sdk/extension/constants/index.js +2 -0
  12. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  13. package/dist/basic-sdk/extension/plugins/code-block/plugin.js +2 -20
  14. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +7 -6
  15. package/dist/basic-sdk/extension/plugins/html/plugin.js +23 -2
  16. package/dist/basic-sdk/extension/plugins/image/helpers.js +13 -3
  17. package/dist/basic-sdk/extension/plugins/link/dialog/add-link-dialog/index.js +2 -1
  18. package/dist/basic-sdk/extension/plugins/link/helpers.js +14 -4
  19. package/dist/basic-sdk/extension/plugins/link/plugin.js +8 -13
  20. package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +30 -2
  21. package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +2 -3
  22. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-below-menu.js +5 -2
  23. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +13 -8
  24. package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +7 -4
  25. package/dist/basic-sdk/extension/toolbar/side-toolbar/transform-menus.js +13 -2
  26. package/dist/basic-sdk/socket/helpers.js +1 -0
  27. package/dist/basic-sdk/socket/socket-client.js +15 -0
  28. package/dist/basic-sdk/socket/socket-manager.js +11 -2
  29. package/dist/basic-sdk/socket/with-socket-io.js +26 -12
  30. package/dist/basic-sdk/utils/diff.js +2 -2
  31. package/dist/basic-sdk/utils/rebase.js +193 -0
  32. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  33. package/dist/basic-sdk/views/viewer.js +8 -11
  34. package/dist/components/doc-operations/index.js +8 -2
  35. package/dist/components/doc-operations/revision-operations/index.js +11 -3
  36. package/dist/components/doc-operations/revision-operations/publish-button.js +16 -13
  37. package/dist/components/tip-dialog/index.css +0 -0
  38. package/dist/components/tip-dialog/index.js +45 -0
  39. package/dist/constants/index.js +8 -1
  40. package/dist/context.js +28 -4
  41. package/dist/pages/simple-editor.js +221 -71
  42. package/package.json +1 -1
  43. package/public/locales/en/sdoc-editor.json +8 -1
  44. package/public/locales/zh_CN/sdoc-editor.json +7 -1
  45. 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: "rebaseSdocRevision",
94
+ value: function rebaseSdocRevision(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) {
@@ -71,5 +71,9 @@
71
71
 
72
72
  /* sub menu */
73
73
  .sdoc-sub-dropdown-menu .popover {
74
- left: -24px !important;
74
+ left: -8px !important;
75
+ }
76
+
77
+ .sdoc-sub-dropdown-menu .bs-popover-auto[x-placement^="left"] {
78
+ left: 8px !important;
75
79
  }
@@ -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,45 @@
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
+ // useMount: focus editor
12
+ useEffect(function () {
13
+ var timer = setTimeout(function () {
14
+ var _editor$children = _slicedToArray(editor.children, 1),
15
+ firstNode = _editor$children[0];
16
+ if (firstNode) {
17
+ var _firstNode$children = _slicedToArray(firstNode.children, 1),
18
+ firstNodeFirstChild = _firstNode$children[0];
19
+ if (firstNodeFirstChild) {
20
+ var endOfFirstNode = Editor.end(editor, [0, 0]);
21
+ var range = {
22
+ anchor: endOfFirstNode,
23
+ focus: endOfFirstNode
24
+ };
25
+ focusEditor(editor, range);
26
+ }
27
+ }
28
+ }, 300);
29
+ return function () {
30
+ clearTimeout(timer);
31
+ };
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
34
+ return /*#__PURE__*/React.createElement(EditorContainer, {
35
+ editor: editor
36
+ }, /*#__PURE__*/React.createElement(EditorContent, {
37
+ docValue: slateValue,
38
+ showOutline: true
39
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
40
+ editor: editor,
41
+ slateValue: slateValue,
42
+ setSlateValue: updateSlateValue
43
+ })));
44
+ };
45
+ export default CommonEditor;
@@ -0,0 +1,135 @@
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 } 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 SDocRebaseEditor from './rebase-editor';
12
+ import SDocEditor from './common-editor';
13
+ import CommonLoading from '../../components/common-loading';
14
+ import context from '../../context';
15
+ var Editor = forwardRef(function (_ref, ref) {
16
+ var mode = _ref.mode,
17
+ document = _ref.document,
18
+ setDiffChanges = _ref.setDiffChanges,
19
+ toggleViewChanges = _ref.toggleViewChanges;
20
+ context.initApi();
21
+ var editor = useMemo(function () {
22
+ var defaultEditor = createDefaultEditor();
23
+ var editorConfig = context.getEditorConfig();
24
+ defaultEditor.mode = MODE.EDITOR;
25
+ var newEditor = withNodeId(withSocketIO(defaultEditor, {
26
+ document: document,
27
+ config: editorConfig
28
+ }));
29
+ var cursors = document.cursors;
30
+ newEditor.cursors = cursors || {};
31
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
32
+ return newEditor;
33
+
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+ var _useState = useState(document.children),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ slateValue = _useState2[0],
39
+ _setSlateValue = _useState2[1];
40
+ var _useState3 = useState(false),
41
+ _useState4 = _slicedToArray(_useState3, 2),
42
+ isLoading = _useState4[0],
43
+ _setLoading = _useState4[1];
44
+ var _useState5 = useState(null),
45
+ _useState6 = _slicedToArray(_useState5, 2),
46
+ diffContent = _useState6[0],
47
+ _setDiffContent = _useState6[1];
48
+ var _useState7 = useState(null),
49
+ _useState8 = _slicedToArray(_useState7, 2),
50
+ currentContent = _useState8[0],
51
+ setCurrentContent = _useState8[1];
52
+
53
+ // useMount: init socket connection
54
+ useEffect(function () {
55
+ editor.openConnection();
56
+ return function () {
57
+ editor.closeConnection();
58
+ };
59
+
60
+ // eslint-disable-next-line react-hooks/exhaustive-deps
61
+ }, []);
62
+ var updateSlateValue = useCallback(function (value) {
63
+ _setSlateValue(value);
64
+
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, []);
67
+
68
+ // The parent component can call the method of this component through ref
69
+ useImperativeHandle(ref, function () {
70
+ return {
71
+ // set value
72
+ setLoading: function setLoading(isLoading) {
73
+ _setLoading(isLoading);
74
+ },
75
+ setDiffContent: function setDiffContent(content) {
76
+ setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
77
+ children: slateValue
78
+ })));
79
+ _setDiffContent(content);
80
+ },
81
+ setEditorMode: function setEditorMode(mode) {
82
+ editor.cursors = {};
83
+ editor.selection = null;
84
+ if (mode === MODE.EDITOR) {
85
+ editor.operations = [];
86
+ }
87
+ editor.mode = mode;
88
+ },
89
+ setSlateValue: function setSlateValue(document) {
90
+ _setSlateValue(document.children);
91
+ },
92
+ // get value
93
+ getSlateValue: function getSlateValue() {
94
+ return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
95
+ children: slateValue
96
+ }));
97
+ }
98
+
99
+ // eslint-disable-next-line react-hooks/exhaustive-deps
100
+ };
101
+ }, [document, editor, slateValue]);
102
+ if (isLoading) {
103
+ return /*#__PURE__*/React.createElement("div", {
104
+ className: "h-100 w-100 d-flex align-items-center justify-content-center"
105
+ }, /*#__PURE__*/React.createElement(CommonLoading, null));
106
+ }
107
+ if (mode === MODE.DIFF_VIEWER) {
108
+ return /*#__PURE__*/React.createElement(DiffViewer, {
109
+ showToolbar: true,
110
+ showOutline: true,
111
+ editor: editor,
112
+ currentContent: currentContent,
113
+ lastContent: diffContent,
114
+ didMountCallback: setDiffChanges
115
+ });
116
+ }
117
+ if (mode === MODE.EDITOR) {
118
+ return /*#__PURE__*/React.createElement(SDocEditor, {
119
+ slateValue: slateValue,
120
+ editor: editor,
121
+ updateSlateValue: updateSlateValue
122
+ });
123
+ }
124
+ if (mode === MODE.REBASE) {
125
+ return /*#__PURE__*/React.createElement(SDocRebaseEditor, {
126
+ slateValue: slateValue,
127
+ editor: editor,
128
+ version: document.version,
129
+ updateSlateValue: updateSlateValue,
130
+ toggleViewChanges: toggleViewChanges
131
+ });
132
+ }
133
+ return null;
134
+ });
135
+ export default Editor;
@@ -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,275 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import React, { useCallback, useEffect } from 'react';
4
+ import deepCopy from 'deep-copy';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { Transforms } from '@seafile/slate';
7
+ import { renderElement } from '../../extension';
8
+ import { focusEditor, findPath, getNode, replaceNode, generateEmptyElement, deleteNodeMark } from '../../extension/core';
9
+ import { REBASE_TYPE, REBASE_MARKS } from '../../constants';
10
+ import context from '../../../context';
11
+ import toaster from '../../../components/toast';
12
+ import { ELEMENT_TYPE } from '../../extension/constants';
13
+ import { replaceNodeId } from '../../node-id/helpers';
14
+ import { EditorContainer, EditorContent } from '../../layout';
15
+ import SlateEditor from '../slate-editor';
16
+ import './index.css';
17
+ var SDocRebaseEditor = function SDocRebaseEditor(_ref) {
18
+ var slateValue = _ref.slateValue,
19
+ editor = _ref.editor,
20
+ version = _ref.version,
21
+ updateSlateValue = _ref.updateSlateValue,
22
+ toggleViewChanges = _ref.toggleViewChanges;
23
+ var _useTranslation = useTranslation(),
24
+ t = _useTranslation.t;
25
+
26
+ // useMount: focus editor
27
+ useEffect(function () {
28
+ var timer = setTimeout(function () {
29
+ focusEditor(editor);
30
+ }, 300);
31
+ return function () {
32
+ clearTimeout(timer);
33
+ };
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+ var onChange = useCallback(function (slateValue) {
37
+ updateSlateValue(slateValue);
38
+ if (slateValue.filter(function (item) {
39
+ return item.rebaseType;
40
+ }).length === 0) {
41
+ context.rebaseSdocRevision().then(function (res) {
42
+ editor.rebaseContent({
43
+ children: slateValue
44
+ });
45
+
46
+ // return context.saveDocContentByRebase();
47
+ }).then(function (res) {
48
+ // toaster.success(t('Successfully_rebase_'));
49
+ // toggleViewChanges(false, true);
50
+ }).catch(function (error) {
51
+ toaster.danger(t('Error'));
52
+ });
53
+ }
54
+
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, [version]);
57
+ var updateParentNodeByPath = useCallback(function (path) {
58
+ var parentPath = path.slice(0, -1);
59
+ var parentNode = getNode(editor, parentPath);
60
+ if (parentNode.children.filter(function (item) {
61
+ return item.rebaseType;
62
+ }).length === 0) {
63
+ var newParentElement = _objectSpread({}, parentNode);
64
+ newParentElement['rebaseType'] && delete newParentElement['rebaseType'];
65
+ newParentElement['oldElement'] && delete newParentElement['oldElement'];
66
+ newParentElement['origin'] && delete newParentElement['origin'];
67
+ newParentElement['children'] = newParentElement['children'].map(function (item) {
68
+ item['rebaseType'] && delete item['rebaseType'];
69
+ item['oldElement'] && delete item['oldElement'];
70
+ item['origin'] && delete item['origin'];
71
+ return item;
72
+ });
73
+ replaceNode(editor, {
74
+ at: parentPath,
75
+ nodes: newParentElement
76
+ });
77
+ }
78
+
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, [editor]);
81
+ var deleteElement = useCallback(function (element) {
82
+ var path = findPath(editor, element);
83
+ Transforms.removeNodes(editor, {
84
+ at: path
85
+ });
86
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
87
+ updateParentNodeByPath(path);
88
+ }
89
+
90
+ // eslint-disable-next-line react-hooks/exhaustive-deps
91
+ }, [slateValue, editor]);
92
+ var deleteMark = useCallback(function (element) {
93
+ var path = findPath(editor, element);
94
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
95
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
96
+ updateParentNodeByPath(path);
97
+ }
98
+
99
+ // eslint-disable-next-line react-hooks/exhaustive-deps
100
+ }, [slateValue, editor]);
101
+ var addDeletedElement = useCallback(function (element) {
102
+ var path = findPath(editor, element);
103
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
104
+ if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
105
+ var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
106
+ Transforms.insertNodes(editor, emptyNode, {
107
+ at: [path[0]]
108
+ });
109
+ } else {
110
+ var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
111
+ _emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
112
+ var parentPath = path.slice(0, -1);
113
+ var parentNode = getNode(editor, parentPath);
114
+ var newChildren = _toConsumableArray(parentNode.children);
115
+ var index = path[path.length - 1];
116
+ newChildren.splice(index, 0, _emptyNode);
117
+ replaceNode(editor, {
118
+ at: parentPath,
119
+ nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
120
+ children: newChildren
121
+ })
122
+ });
123
+ }
124
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
125
+ updateParentNodeByPath(path);
126
+ }
127
+
128
+ // eslint-disable-next-line react-hooks/exhaustive-deps
129
+ }, [slateValue, editor]);
130
+ var useMasterChanges = useCallback(function (element) {
131
+ var path = findPath(editor, element);
132
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
133
+ var nextElementPath = _toConsumableArray(path);
134
+ nextElementPath[path.length - 1] = path[path.length - 1] + 1;
135
+ Transforms.removeNodes(editor, {
136
+ at: nextElementPath
137
+ });
138
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
139
+ updateParentNodeByPath(path);
140
+ }
141
+
142
+ // eslint-disable-next-line react-hooks/exhaustive-deps
143
+ }, [slateValue, editor]);
144
+ var useCurrentChanges = useCallback(function (element) {
145
+ var path = findPath(editor, element);
146
+ var currentElementPath = _toConsumableArray(path);
147
+ currentElementPath[path.length - 1] = path[path.length - 1] + 1;
148
+ var currentElement = getNode(editor, currentElementPath);
149
+ var newCurrentElement = deepCopy(currentElement);
150
+ deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
151
+ Transforms.removeNodes(editor, {
152
+ at: path
153
+ });
154
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
155
+ updateParentNodeByPath(path);
156
+ }
157
+
158
+ // eslint-disable-next-line react-hooks/exhaustive-deps
159
+ }, [slateValue, editor]);
160
+ var useBothChanges = useCallback(function (element) {
161
+ // delete element marks
162
+ var path = findPath(editor, element);
163
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
164
+
165
+ // delete next element marks
166
+ var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
167
+ var nextElement = getNode(editor, nextElementPath);
168
+ var newNextElement = replaceNodeId(deepCopy(nextElement));
169
+ deleteNodeMark(editor, nextElementPath, newNextElement, REBASE_MARKS);
170
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
171
+ updateParentNodeByPath(path);
172
+ }
173
+
174
+ // eslint-disable-next-line react-hooks/exhaustive-deps
175
+ }, [slateValue, editor]);
176
+ var renderRebaseElement = useCallback(function (props) {
177
+ var element = props.element;
178
+ if (!element.rebaseType) {
179
+ return renderElement(props);
180
+ }
181
+ if (element.rebaseType === REBASE_TYPE.DELETE_MODIFY) {
182
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
183
+ className: "w-100 d-flex sdoc-rebase-btn-group",
184
+ contentEditable: false
185
+ }, /*#__PURE__*/React.createElement("div", {
186
+ className: "sdoc-rebase-btn",
187
+ onClick: function onClick() {
188
+ return deleteElement(element);
189
+ }
190
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
191
+ className: "mr-2 ml-2"
192
+ }, '|'), /*#__PURE__*/React.createElement("div", {
193
+ className: "sdoc-rebase-btn",
194
+ onClick: function onClick() {
195
+ return deleteMark(element);
196
+ }
197
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
198
+ className: "mr-2 ml-2"
199
+ }, '|'), /*#__PURE__*/React.createElement("div", {
200
+ className: "sdoc-rebase-btn",
201
+ onClick: function onClick() {
202
+ return addDeletedElement(element);
203
+ }
204
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
205
+ className: "w-100 sdoc-rebase-current-changes-start",
206
+ contentEditable: false
207
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
208
+ className: "w-100",
209
+ contentEditable: false
210
+ }, '======='), /*#__PURE__*/React.createElement("div", {
211
+ className: "w-100 sdoc-rebase-incoming-changes"
212
+ }, renderElement(props)), /*#__PURE__*/React.createElement("div", {
213
+ className: "w-100 sdoc-rebase-incoming-changes-end",
214
+ contentEditable: false
215
+ }, '>>>>>>>'));
216
+ }
217
+ if (element.rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
218
+ if (element.origin === 'master') {
219
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
220
+ className: "w-100 d-flex sdoc-rebase-btn-group",
221
+ contentEditable: false
222
+ }, /*#__PURE__*/React.createElement("div", {
223
+ className: "sdoc-rebase-btn",
224
+ onClick: function onClick() {
225
+ return useMasterChanges(element);
226
+ }
227
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
228
+ className: "mr-2 ml-2"
229
+ }, '|'), /*#__PURE__*/React.createElement("div", {
230
+ className: "sdoc-rebase-btn",
231
+ onClick: function onClick() {
232
+ return useCurrentChanges(element);
233
+ }
234
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
235
+ className: "mr-2 ml-2"
236
+ }, '|'), /*#__PURE__*/React.createElement("div", {
237
+ className: "sdoc-rebase-btn",
238
+ onClick: function onClick() {
239
+ return useBothChanges(element);
240
+ }
241
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
242
+ className: "w-100 sdoc-rebase-current-changes-start",
243
+ contentEditable: false
244
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
245
+ className: "w-100 sdoc-rebase-current-changes"
246
+ }, renderElement(props)));
247
+ }
248
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
249
+ className: "w-100",
250
+ contentEditable: false
251
+ }, '======='), /*#__PURE__*/React.createElement("div", {
252
+ className: "w-100 sdoc-rebase-incoming-changes"
253
+ }, renderElement(props)), /*#__PURE__*/React.createElement("div", {
254
+ className: "w-100 sdoc-rebase-incoming-changes-end",
255
+ contentEditable: false
256
+ }, '>>>>>>>'));
257
+ }
258
+ return renderElement(props);
259
+
260
+ // eslint-disable-next-line react-hooks/exhaustive-deps
261
+ }, []);
262
+ return /*#__PURE__*/React.createElement(EditorContainer, {
263
+ editor: editor
264
+ }, /*#__PURE__*/React.createElement(EditorContent, {
265
+ docValue: slateValue,
266
+ showOutline: true
267
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
268
+ isShowComment: false,
269
+ editor: editor,
270
+ slateValue: slateValue,
271
+ setSlateValue: onChange,
272
+ renderElement: renderRebaseElement
273
+ })));
274
+ };
275
+ export default SDocRebaseEditor;
@@ -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;