@seafile/sdoc-editor 0.1.142 → 0.1.143-beta2

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 +272 -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 +25 -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 +228 -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
+ rebaseEnd = _ref.rebaseEnd;
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
+ rebaseEnd: rebaseEnd
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,272 @@
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
+ rebaseEnd = _ref.rebaseEnd;
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
+ }).then(function (res) {
46
+ rebaseEnd();
47
+ }).catch(function (error) {
48
+ toaster.danger(t('Error'));
49
+ });
50
+ }
51
+
52
+ // eslint-disable-next-line react-hooks/exhaustive-deps
53
+ }, [version]);
54
+ var updateParentNodeByPath = useCallback(function (path) {
55
+ var parentPath = path.slice(0, -1);
56
+ var parentNode = getNode(editor, parentPath);
57
+ if (parentNode.children.filter(function (item) {
58
+ return item.rebaseType;
59
+ }).length === 0) {
60
+ var newParentElement = _objectSpread({}, parentNode);
61
+ newParentElement['rebaseType'] && delete newParentElement['rebaseType'];
62
+ newParentElement['oldElement'] && delete newParentElement['oldElement'];
63
+ newParentElement['origin'] && delete newParentElement['origin'];
64
+ newParentElement['children'] = newParentElement['children'].map(function (item) {
65
+ item['rebaseType'] && delete item['rebaseType'];
66
+ item['oldElement'] && delete item['oldElement'];
67
+ item['origin'] && delete item['origin'];
68
+ return item;
69
+ });
70
+ replaceNode(editor, {
71
+ at: parentPath,
72
+ nodes: newParentElement
73
+ });
74
+ }
75
+
76
+ // eslint-disable-next-line react-hooks/exhaustive-deps
77
+ }, [editor]);
78
+ var deleteElement = useCallback(function (element) {
79
+ var path = findPath(editor, element);
80
+ Transforms.removeNodes(editor, {
81
+ at: path
82
+ });
83
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
84
+ updateParentNodeByPath(path);
85
+ }
86
+
87
+ // eslint-disable-next-line react-hooks/exhaustive-deps
88
+ }, [slateValue, editor]);
89
+ var deleteMark = useCallback(function (element) {
90
+ var path = findPath(editor, element);
91
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
92
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
93
+ updateParentNodeByPath(path);
94
+ }
95
+
96
+ // eslint-disable-next-line react-hooks/exhaustive-deps
97
+ }, [slateValue, editor]);
98
+ var addDeletedElement = useCallback(function (element) {
99
+ var path = findPath(editor, element);
100
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
101
+ if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
102
+ var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
103
+ Transforms.insertNodes(editor, emptyNode, {
104
+ at: [path[0]]
105
+ });
106
+ } else {
107
+ var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
108
+ _emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
109
+ var parentPath = path.slice(0, -1);
110
+ var parentNode = getNode(editor, parentPath);
111
+ var newChildren = _toConsumableArray(parentNode.children);
112
+ var index = path[path.length - 1];
113
+ newChildren.splice(index, 0, _emptyNode);
114
+ replaceNode(editor, {
115
+ at: parentPath,
116
+ nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
117
+ children: newChildren
118
+ })
119
+ });
120
+ }
121
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
122
+ updateParentNodeByPath(path);
123
+ }
124
+
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [slateValue, editor]);
127
+ var useMasterChanges = useCallback(function (element) {
128
+ var path = findPath(editor, element);
129
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
130
+ var nextElementPath = _toConsumableArray(path);
131
+ nextElementPath[path.length - 1] = path[path.length - 1] + 1;
132
+ Transforms.removeNodes(editor, {
133
+ at: nextElementPath
134
+ });
135
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
136
+ updateParentNodeByPath(path);
137
+ }
138
+
139
+ // eslint-disable-next-line react-hooks/exhaustive-deps
140
+ }, [slateValue, editor]);
141
+ var useCurrentChanges = useCallback(function (element) {
142
+ var path = findPath(editor, element);
143
+ var currentElementPath = _toConsumableArray(path);
144
+ currentElementPath[path.length - 1] = path[path.length - 1] + 1;
145
+ var currentElement = getNode(editor, currentElementPath);
146
+ var newCurrentElement = deepCopy(currentElement);
147
+ deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
148
+ Transforms.removeNodes(editor, {
149
+ at: path
150
+ });
151
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
152
+ updateParentNodeByPath(path);
153
+ }
154
+
155
+ // eslint-disable-next-line react-hooks/exhaustive-deps
156
+ }, [slateValue, editor]);
157
+ var useBothChanges = useCallback(function (element) {
158
+ // delete element marks
159
+ var path = findPath(editor, element);
160
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
161
+
162
+ // delete next element marks
163
+ var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
164
+ var nextElement = getNode(editor, nextElementPath);
165
+ var newNextElement = replaceNodeId(deepCopy(nextElement));
166
+ deleteNodeMark(editor, nextElementPath, newNextElement, REBASE_MARKS);
167
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
168
+ updateParentNodeByPath(path);
169
+ }
170
+
171
+ // eslint-disable-next-line react-hooks/exhaustive-deps
172
+ }, [slateValue, editor]);
173
+ var renderRebaseElement = useCallback(function (props) {
174
+ var element = props.element;
175
+ if (!element.rebaseType) {
176
+ return renderElement(props);
177
+ }
178
+ if (element.rebaseType === REBASE_TYPE.DELETE_MODIFY) {
179
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
180
+ className: "w-100 d-flex sdoc-rebase-btn-group",
181
+ contentEditable: false
182
+ }, /*#__PURE__*/React.createElement("div", {
183
+ className: "sdoc-rebase-btn",
184
+ onClick: function onClick() {
185
+ return deleteMark(element);
186
+ }
187
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
188
+ className: "mr-2 ml-2"
189
+ }, '|'), /*#__PURE__*/React.createElement("div", {
190
+ className: "sdoc-rebase-btn",
191
+ onClick: function onClick() {
192
+ return deleteElement(element);
193
+ }
194
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
195
+ className: "mr-2 ml-2"
196
+ }, '|'), /*#__PURE__*/React.createElement("div", {
197
+ className: "sdoc-rebase-btn",
198
+ onClick: function onClick() {
199
+ return addDeletedElement(element);
200
+ }
201
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
202
+ className: "w-100 sdoc-rebase-current-changes-start",
203
+ contentEditable: false
204
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
205
+ className: "w-100",
206
+ contentEditable: false
207
+ }, '======='), /*#__PURE__*/React.createElement("div", {
208
+ className: "w-100 sdoc-rebase-incoming-changes"
209
+ }, renderElement(props)), /*#__PURE__*/React.createElement("div", {
210
+ className: "w-100 sdoc-rebase-incoming-changes-end",
211
+ contentEditable: false
212
+ }, '>>>>>>>'));
213
+ }
214
+ if (element.rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
215
+ if (element.origin === 'master') {
216
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
217
+ className: "w-100 d-flex sdoc-rebase-btn-group",
218
+ contentEditable: false
219
+ }, /*#__PURE__*/React.createElement("div", {
220
+ className: "sdoc-rebase-btn",
221
+ onClick: function onClick() {
222
+ return useCurrentChanges(element);
223
+ }
224
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
225
+ className: "mr-2 ml-2"
226
+ }, '|'), /*#__PURE__*/React.createElement("div", {
227
+ className: "sdoc-rebase-btn",
228
+ onClick: function onClick() {
229
+ return useMasterChanges(element);
230
+ }
231
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
232
+ className: "mr-2 ml-2"
233
+ }, '|'), /*#__PURE__*/React.createElement("div", {
234
+ className: "sdoc-rebase-btn",
235
+ onClick: function onClick() {
236
+ return useBothChanges(element);
237
+ }
238
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
239
+ className: "w-100 sdoc-rebase-current-changes-start",
240
+ contentEditable: false
241
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
242
+ className: "w-100 sdoc-rebase-current-changes"
243
+ }, renderElement(props)));
244
+ }
245
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
246
+ className: "w-100",
247
+ contentEditable: false
248
+ }, '======='), /*#__PURE__*/React.createElement("div", {
249
+ className: "w-100 sdoc-rebase-incoming-changes"
250
+ }, renderElement(props)), /*#__PURE__*/React.createElement("div", {
251
+ className: "w-100 sdoc-rebase-incoming-changes-end",
252
+ contentEditable: false
253
+ }, '>>>>>>>'));
254
+ }
255
+ return renderElement(props);
256
+
257
+ // eslint-disable-next-line react-hooks/exhaustive-deps
258
+ }, []);
259
+ return /*#__PURE__*/React.createElement(EditorContainer, {
260
+ editor: editor
261
+ }, /*#__PURE__*/React.createElement(EditorContent, {
262
+ docValue: slateValue,
263
+ showOutline: true
264
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
265
+ isShowComment: false,
266
+ editor: editor,
267
+ slateValue: slateValue,
268
+ setSlateValue: onChange,
269
+ renderElement: renderRebaseElement
270
+ })));
271
+ };
272
+ 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;