@seafile/sdoc-editor 0.1.144 → 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 (34) 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/layout/article-container.js +17 -19
  14. package/dist/basic-sdk/socket/helpers.js +2 -0
  15. package/dist/basic-sdk/socket/socket-client.js +41 -0
  16. package/dist/basic-sdk/socket/socket-manager.js +26 -2
  17. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  18. package/dist/basic-sdk/utils/diff.js +2 -2
  19. package/dist/basic-sdk/utils/rebase.js +196 -0
  20. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  21. package/dist/basic-sdk/views/viewer.js +8 -11
  22. package/dist/components/doc-operations/index.js +8 -2
  23. package/dist/components/doc-operations/revision-operations/index.js +11 -3
  24. package/dist/components/doc-operations/revision-operations/publish-button.js +16 -13
  25. package/dist/components/tip-dialog/index.css +0 -0
  26. package/dist/components/tip-dialog/index.js +49 -0
  27. package/dist/components/tip-dialog/tip-content.js +56 -0
  28. package/dist/constants/index.js +23 -2
  29. package/dist/context.js +35 -4
  30. package/dist/pages/simple-editor.js +268 -72
  31. package/package.json +1 -1
  32. package/public/locales/en/sdoc-editor.json +13 -1
  33. package/public/locales/zh_CN/sdoc-editor.json +12 -1
  34. package/dist/basic-sdk/editor.js +0 -105
@@ -1,10 +1,9 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import React, { useEffect, useRef, useState } from 'react';
3
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { useScrollContext } from '../hooks/use-scroll-context';
5
5
  export default function ArticleContainer(_ref) {
6
6
  var editor = _ref.editor,
7
- readOnly = _ref.readOnly,
8
7
  children = _ref.children;
9
8
  var articleRef = useRef(null);
10
9
  useEffect(function () {
@@ -16,24 +15,26 @@ export default function ArticleContainer(_ref) {
16
15
  _useState2 = _slicedToArray(_useState, 2),
17
16
  containerStyle = _useState2[0],
18
17
  setContainerStyle = _useState2[1];
18
+ var handleWindowResize = useCallback(function () {
19
+ var rect = scrollRef.current.getBoundingClientRect();
20
+ var articleRect = articleRef.current.getBoundingClientRect();
21
+ if ((rect.width - articleRect.width) / 2 < 280) {
22
+ setContainerStyle({
23
+ marginLeft: '280px'
24
+ });
25
+ } else {
26
+ setContainerStyle({});
27
+ }
28
+ // eslint-disable-next-line react-hooks/exhaustive-deps
29
+ }, []);
19
30
  useEffect(function () {
20
- if (readOnly) return;
21
- var handleWindowResize = function handleWindowResize() {
22
- var rect = scrollRef.current.getBoundingClientRect();
23
- var articleRect = articleRef.current.getBoundingClientRect();
24
- if ((rect.width - articleRect.width) / 2 < 280) {
25
- setContainerStyle({
26
- marginLeft: '280px'
27
- });
28
- } else {
29
- setContainerStyle({});
30
- }
31
- };
31
+ handleWindowResize();
32
32
  window.addEventListener('resize', handleWindowResize);
33
33
  return function () {
34
34
  window.removeEventListener('resize', handleWindowResize);
35
35
  };
36
- }, [readOnly, scrollRef]);
36
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ }, []);
37
38
  return /*#__PURE__*/React.createElement("div", {
38
39
  className: "sdoc-article-container",
39
40
  style: containerStyle
@@ -44,7 +45,4 @@ export default function ArticleContainer(_ref) {
44
45
  className: "article",
45
46
  ref: articleRef
46
47
  }, children[0]), _toConsumableArray(children.slice(1))));
47
- }
48
- ArticleContainer.defaultProps = {
49
- readOnly: false
50
- };
48
+ }
@@ -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++) {
@@ -119,6 +119,44 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
119
119
  this.disconnectWithServer = function () {
120
120
  _this.socket.disconnect();
121
121
  };
122
+ this.receiveRebaseDocument = function (document, originFileVersion) {
123
+ var socketManager = SocketManager.getInstance();
124
+ socketManager.receiveRebaseContent(document, originFileVersion);
125
+ };
126
+ this.sendRebaseDocument = function (document, originFileVersion, callback) {
127
+ debug('=========== send operations ==========');
128
+ debug('%O', document);
129
+ debug('======================================');
130
+ _this.socket.emit('rebase-document', _this.getParams({
131
+ document: document,
132
+ originFileVersion: originFileVersion
133
+ }), function (result) {
134
+ callback && callback(result);
135
+ });
136
+ };
137
+ this.sendPublishDocument = function (originFileURL, callback) {
138
+ _this.socket.emit('publish-document', _this.getParams({
139
+ originFileURL: originFileURL
140
+ }), function (result) {
141
+ callback && callback(result);
142
+ });
143
+ };
144
+ this.receivePublishDocument = function (originFileURL) {
145
+ var socketManager = SocketManager.getInstance();
146
+ socketManager.receivePublishDocument(originFileURL);
147
+ };
148
+ this.sendMergeDocument = function (document, originFileVersion, callback) {
149
+ _this.socket.emit('merge-document', _this.getParams({
150
+ document: document,
151
+ originFileVersion: originFileVersion
152
+ }), function (result) {
153
+ callback && callback(result);
154
+ });
155
+ };
156
+ this.receiveMergeDocument = function (document, originFileVersion) {
157
+ var socketManager = SocketManager.getInstance();
158
+ socketManager.receiveMergeDocument(document, originFileVersion);
159
+ };
122
160
  this.config = config;
123
161
  this.isReconnect = false;
124
162
  this.socket = io(config.sdocServer, {
@@ -133,6 +171,9 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
133
171
  this.socket.on('join-room', this.onJoinRoom);
134
172
  this.socket.on('leave-room', this.onLeaveRoom);
135
173
  this.socket.on('update-document', this.onReceiveRemoteOperations);
174
+ this.socket.on('rebase-document', this.receiveRebaseDocument);
175
+ this.socket.on('merge-document', this.receiveMergeDocument);
176
+ this.socket.on('publish-document', this.receivePublishDocument);
136
177
  this.socket.on('update-cursor', this.receiveCursorLocation);
137
178
  this.socket.io.on('reconnect', this.onReconnect);
138
179
  this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
@@ -7,6 +7,7 @@ import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, s
7
7
  import SocketClient from './socket-client';
8
8
  import { conflictDebug, serverDebug, stateDebug } from '../utils/debug';
9
9
  import { deleteCursor } from '../cursor/helper';
10
+ import { EXTERNAL_EVENT, MODE } from '../../constants';
10
11
 
11
12
  // idle --> sending --> conflict --> idle
12
13
  // --> conflict --> idle
@@ -19,13 +20,35 @@ var STATE = {
19
20
  DISCONNECT: 'disconnect',
20
21
  NEED_RELOAD: 'need_reload'
21
22
  };
22
- var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, document, config) {
23
+ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _document, config) {
23
24
  var _this = this;
24
25
  _classCallCheck(this, SocketManager);
25
26
  this.getDocumentVersion = function () {
26
27
  var version = _this.document.version;
27
28
  return version;
28
29
  };
30
+ this.sendRebaseContent = function (document, originFileVersion) {
31
+ _this.socketClient.sendRebaseDocument(document, originFileVersion, function (result) {
32
+ var serverVersion = result.version;
33
+ _this.document['version'] = serverVersion;
34
+ });
35
+ };
36
+ this.sendPublishDocument = function (originFileURL) {
37
+ _this.socketClient.sendPublishDocument(originFileURL);
38
+ };
39
+ this.receivePublishContent = function (originFileURL) {
40
+ _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT, originFileURL);
41
+ };
42
+ this.sendMergeDocument = function (document, originFileVersion) {
43
+ _this.socketClient.sendMergeDocument(document, originFileVersion, function (result) {
44
+ var serverVersion = result.version;
45
+ _this.document['version'] = serverVersion;
46
+ });
47
+ };
48
+ this.receiveMergeDocument = function (document, originFileVersion) {
49
+ _this.document = document;
50
+ _this.eventBus.dispatch(EXTERNAL_EVENT.MERGE_DOCUMENT, document, originFileVersion);
51
+ };
29
52
  this.onReceiveLocalOperations = function (operations) {
30
53
  _this.pendingOperationList.push(operations);
31
54
  if (_this.pendingOperationList.length > 5) {
@@ -34,6 +57,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
34
57
  _this.sendOperations();
35
58
  };
36
59
  this.sendOperations = function () {
60
+ if (_this.editor.mode !== MODE.EDITOR) return;
37
61
  if (_this.state !== STATE.IDLE) return;
38
62
  stateDebug("State changed: ".concat(_this.state, " -> ").concat(STATE.SENDING));
39
63
  _this.state = STATE.SENDING;
@@ -285,7 +309,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
285
309
  _this.socketClient.disconnectWithServer();
286
310
  };
287
311
  this.editor = editor;
288
- this.document = document;
312
+ this.document = _document;
289
313
  this.socketClient = new SocketClient(config);
290
314
  this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
291
315
  this.remoteOperationsList = []; // Same with pending operations
@@ -1,3 +1,4 @@
1
+ import { MODE } from '../../constants';
1
2
  import { generateCursorData } from '../cursor/helper';
2
3
  import EventBus from '../utils/event-bus';
3
4
  import SocketManager from './socket-manager';
@@ -19,28 +20,50 @@ var withSocketIO = function withSocketIO(editor, options) {
19
20
  SocketManager.destroy();
20
21
  };
21
22
  newEditor.onChange = function () {
22
- if (newEditor.readonly) return;
23
+ var document = options.document,
24
+ config = options.config;
25
+ if (newEditor.mode === MODE.DIFF_VIEWER) return;
23
26
  var operations = newEditor.operations;
24
27
  if (!newEditor.isRemote && operations.length > 0) {
25
28
  var isAllSetSelection = operations.every(function (operation) {
26
29
  return operation.type === 'set_selection';
27
30
  });
28
- var _socketManager = SocketManager.getInstance();
31
+ var _socketManager = SocketManager.getInstance(newEditor, document, config);
29
32
  if (!isAllSetSelection) {
30
- // get update content value operations
31
- var updateOperations = operations.filter(function (operation) {
32
- return operation.type !== 'set_selection';
33
- });
34
- _socketManager.onReceiveLocalOperations(updateOperations);
33
+ if (newEditor.mode === MODE.EDITOR) {
34
+ // get update content value operations
35
+ var updateOperations = operations.filter(function (operation) {
36
+ return operation.type !== 'set_selection';
37
+ });
38
+ _socketManager.onReceiveLocalOperations(updateOperations);
39
+ }
35
40
  }
36
- _socketManager.sendCursorLocation(editor.selection);
41
+ if (newEditor.mode === MODE.EDITOR) {
42
+ _socketManager.sendCursorLocation(editor.selection);
43
+ }
44
+ }
45
+ if (newEditor.mode === MODE.EDITOR) {
46
+ // dispatch editor change event
47
+ var eventBus = EventBus.getInstance(newEditor, document, config);
48
+ eventBus.dispatch('change');
37
49
  }
38
-
39
- // dispatch editor change event
40
- var eventBus = EventBus.getInstance();
41
- eventBus.dispatch('change');
42
50
  onChange();
43
51
  };
52
+ newEditor.rebaseContent = function (document, originFileVersion) {
53
+ var config = options.config;
54
+ var socketManager = SocketManager.getInstance(newEditor, document, config);
55
+ socketManager.sendRebaseContent(document, originFileVersion);
56
+ };
57
+ newEditor.publishDocument = function (originFileURL) {
58
+ var config = options.config;
59
+ var socketManager = SocketManager.getInstance(newEditor, document, config);
60
+ socketManager.sendPublishDocument(document, originFileURL);
61
+ };
62
+ newEditor.mergeDocument = function (document, originFileVersion) {
63
+ var config = options.config;
64
+ var socketManager = SocketManager.getInstance(newEditor, document, config);
65
+ socketManager.sendMergeDocument(document, originFileVersion);
66
+ };
44
67
  return newEditor;
45
68
  };
46
69
  export default withSocketIO;
@@ -31,7 +31,7 @@ var generatorDiffElement = function generatorDiffElement(element, diffType) {
31
31
  return generatorDiffElement(item, diffType, style);
32
32
  })), _objectSpread3));
33
33
  };
34
- var generateIdMapAndIds = function generateIdMapAndIds(elements) {
34
+ export var generateIdMapAndIds = function generateIdMapAndIds(elements) {
35
35
  var map = {};
36
36
  var ids = [];
37
37
  if (!Array.isArray(elements) || elements.length === 0) return {
@@ -54,7 +54,7 @@ var hasChildren = function hasChildren(element) {
54
54
  };
55
55
 
56
56
  // id diffs
57
- var getIdDiffs = function getIdDiffs(oldIds, newIds) {
57
+ export var getIdDiffs = function getIdDiffs(oldIds, newIds) {
58
58
  var diff = new DiffText(oldIds, newIds);
59
59
  return diff.getDiffs();
60
60
  };
@@ -0,0 +1,196 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { generateIdMapAndIds, getIdDiffs } from './diff';
4
+ import ObjectUtils from './object-utils';
5
+ import { MODIFY_TYPE, REBASE_TYPE } from '../constants';
6
+ import { ELEMENT_TYPE } from '../extension/constants';
7
+ import { replaceNodeId } from '../node-id/helpers';
8
+ var getRevisionChanges = function getRevisionChanges(masterContent, currentContent) {
9
+ var _generateIdMapAndIds = generateIdMapAndIds(currentContent.children),
10
+ currentContentMap = _generateIdMapAndIds.map,
11
+ currentIds = _generateIdMapAndIds.ids;
12
+ var _generateIdMapAndIds2 = generateIdMapAndIds(masterContent.children),
13
+ masterContentMap = _generateIdMapAndIds2.map,
14
+ masterIds = _generateIdMapAndIds2.ids;
15
+ var idDiffs = getIdDiffs(masterIds, currentIds);
16
+ var content = [];
17
+ idDiffs.forEach(function (idDiff) {
18
+ var value = idDiff.value,
19
+ added = idDiff.added,
20
+ removed = idDiff.removed;
21
+ if (added) {
22
+ var addedList = value.map(function (item) {
23
+ return _objectSpread(_objectSpread({}, currentContentMap[item]), {}, {
24
+ modifyType: MODIFY_TYPE.ADD
25
+ });
26
+ });
27
+ content.push.apply(content, _toConsumableArray(addedList));
28
+ } else if (removed) {
29
+ var deletedList = value.map(function (item) {
30
+ return _objectSpread(_objectSpread({}, masterContentMap[item]), {}, {
31
+ modifyType: MODIFY_TYPE.DELETE
32
+ });
33
+ });
34
+ content.push.apply(content, _toConsumableArray(deletedList));
35
+ } else {
36
+ value.forEach(function (elementId) {
37
+ if (ObjectUtils.isSameObject(masterContentMap[elementId], currentContentMap[elementId])) {
38
+ content.push(currentContentMap[elementId]);
39
+ } else {
40
+ var oldElement = masterContentMap[elementId];
41
+ var currentElement = currentContentMap[elementId];
42
+ var newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
43
+ modifyType: MODIFY_TYPE.MODIFY,
44
+ oldElement: oldElement
45
+ });
46
+ if (currentElement.type === oldElement.type) {
47
+ var elementType = currentElement.type;
48
+ if ([ELEMENT_TYPE.UNORDERED_LIST, ELEMENT_TYPE.ORDERED_LIST].includes(elementType)) {
49
+ var listContent = getRevisionChanges(oldElement, currentElement);
50
+ newElement['modifyType'] = MODIFY_TYPE.CHILDREN_MODIFY;
51
+ newElement['children'] = listContent;
52
+ }
53
+ }
54
+ content.push(newElement);
55
+ }
56
+ });
57
+ }
58
+ });
59
+ return content;
60
+ };
61
+ var getMasterChanges = function getMasterChanges(masterContent, revisionChanges) {
62
+ var canMerge = true;
63
+ var _generateIdMapAndIds3 = generateIdMapAndIds(revisionChanges),
64
+ currentContentMap = _generateIdMapAndIds3.map,
65
+ currentIds = _generateIdMapAndIds3.ids;
66
+ var _generateIdMapAndIds4 = generateIdMapAndIds(masterContent.children),
67
+ masterContentMap = _generateIdMapAndIds4.map,
68
+ masterIds = _generateIdMapAndIds4.ids;
69
+ var idDiffs = getIdDiffs(masterIds, currentIds);
70
+ var content = [];
71
+ idDiffs.forEach(function (idDiff) {
72
+ var value = idDiff.value,
73
+ added = idDiff.added,
74
+ removed = idDiff.removed;
75
+ if (added) {
76
+ value.forEach(function (elementId) {
77
+ var element = currentContentMap[elementId];
78
+ var newElement = {
79
+ id: element.id,
80
+ children: element.children,
81
+ type: element.type
82
+ };
83
+ // The content has been deleted from the master, but this branch has been modified. At this time, rebase is required, and the user needs to confirm the selected content
84
+ // ==> delete | use modification
85
+ if (element.modifyType === MODIFY_TYPE.MODIFY) {
86
+ newElement['rebaseType'] = REBASE_TYPE.DELETE_MODIFY;
87
+ content.push(newElement);
88
+ canMerge = false;
89
+ } else {
90
+ // new direct append
91
+ content.push(newElement);
92
+ }
93
+ });
94
+ } else if (removed) {
95
+ var deletedList = value.map(function (item) {
96
+ return _objectSpread({}, masterContentMap[item]);
97
+ });
98
+ content.push.apply(content, _toConsumableArray(deletedList));
99
+ } else {
100
+ value.forEach(function (elementId) {
101
+ var currentElement = currentContentMap[elementId];
102
+ var masterElement = masterContentMap[elementId];
103
+
104
+ // Unchanged
105
+ if (ObjectUtils.isSameObject(masterElement, currentElement)) {
106
+ content.push(currentElement);
107
+
108
+ // The content of the master branch is modified in the current branch, but the content of the master branch is the same as that of origin
109
+ } else if (ObjectUtils.isSameObject(masterElement, currentElement.oldElement)) {
110
+ var newElement = _objectSpread({}, currentElement);
111
+ newElement['oldElement'] && delete newElement['oldElement'];
112
+ newElement['modifyType'] && delete newElement['modifyType'];
113
+ content.push(newElement);
114
+
115
+ // Modify at the same time
116
+ } else if (currentElement.modifyType === MODIFY_TYPE.MODIFY) {
117
+ var oldMasterElement = replaceNodeId(_objectSpread(_objectSpread({}, masterElement), {}, {
118
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
119
+ origin: 'master'
120
+ }));
121
+ content.push(oldMasterElement);
122
+ var _newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
123
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
124
+ origin: 'current'
125
+ });
126
+ _newElement['modifyType'] && delete _newElement['modifyType'];
127
+ _newElement['oldElement'] && delete _newElement['oldElement'];
128
+ content.push(_newElement);
129
+ canMerge = false;
130
+
131
+ // children modify
132
+ } else if (currentElement.modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
133
+ canMerge = false;
134
+ if (currentElement.type === masterElement.type) {
135
+ var _getMasterChanges = getMasterChanges(masterElement, currentElement.children),
136
+ childrenContent = _getMasterChanges.content;
137
+ content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
138
+ children: childrenContent,
139
+ rebaseType: REBASE_TYPE.CHILDREN_MODIFY
140
+ }));
141
+ } else {
142
+ var _oldMasterElement = replaceNodeId(_objectSpread(_objectSpread({}, masterElement), {}, {
143
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
144
+ origin: 'master'
145
+ }));
146
+ content.push(_oldMasterElement);
147
+ var _newElement2 = _objectSpread(_objectSpread({}, currentElement.oldElement), {}, {
148
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
149
+ origin: 'current'
150
+ });
151
+ content.push(_newElement2);
152
+ }
153
+ } else {
154
+ var _newElement3 = _objectSpread({}, currentElement);
155
+ _newElement3['oldElement'] && delete _newElement3['oldElement'];
156
+ _newElement3['modifyType'] && delete _newElement3['modifyType'];
157
+ content.push(_newElement3);
158
+ }
159
+ });
160
+ }
161
+ });
162
+ return {
163
+ content: content,
164
+ canMerge: canMerge
165
+ };
166
+ };
167
+ export var getRebase = function getRebase(masterContent, revisionMasterContent, revisionCurrentContent) {
168
+ // master no changes, merged directly
169
+ if (masterContent.version === revisionMasterContent.version) {
170
+ return {
171
+ canMerge: true,
172
+ isNeedReplaceMaster: true,
173
+ value: revisionCurrentContent
174
+ };
175
+ }
176
+
177
+ // The revision content has not changed
178
+ if (revisionMasterContent.version === revisionCurrentContent.version) {
179
+ return {
180
+ canMerge: true,
181
+ isNeedReplaceMaster: false,
182
+ value: masterContent
183
+ };
184
+ }
185
+ var revisionChanges = getRevisionChanges(revisionMasterContent, revisionCurrentContent);
186
+ var _getMasterChanges2 = getMasterChanges(masterContent, revisionChanges),
187
+ canMerge = _getMasterChanges2.canMerge,
188
+ content = _getMasterChanges2.content;
189
+ return {
190
+ canMerge: canMerge,
191
+ isNeedReplaceMaster: true,
192
+ value: _objectSpread(_objectSpread({}, revisionCurrentContent), {}, {
193
+ children: content
194
+ })
195
+ };
196
+ };
@@ -6,7 +6,8 @@ import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../extension/constants
6
6
  import SDocViewer from './viewer';
7
7
  import '../../assets/css/diff-viewer.css';
8
8
  var DiffViewer = function DiffViewer(_ref) {
9
- var currentContent = _ref.currentContent,
9
+ var editor = _ref.editor,
10
+ currentContent = _ref.currentContent,
10
11
  lastContent = _ref.lastContent,
11
12
  didMountCallback = _ref.didMountCallback,
12
13
  showToolbar = _ref.showToolbar,
@@ -38,6 +39,7 @@ var DiffViewer = function DiffViewer(_ref) {
38
39
  return renderElement(props, editor);
39
40
  }, []);
40
41
  return /*#__PURE__*/React.createElement(SDocViewer, {
42
+ editor: editor,
41
43
  showToolbar: showToolbar,
42
44
  showOutline: showOutline,
43
45
  document: {
@@ -1,4 +1,4 @@
1
- import React, { Fragment, useMemo } from 'react';
1
+ import React, { Fragment } from 'react';
2
2
  import { Editable, Slate } from '@seafile/slate-react';
3
3
  import { renderLeaf as _renderLeaf, renderElement as _renderElement, createDefaultEditor } from '../extension';
4
4
  import withNodeId from '../node-id';
@@ -8,16 +8,13 @@ import { usePipDecorate } from '../decorates';
8
8
  import { ArticleContainer, EditorContainer, EditorContent } from '../layout';
9
9
  import '../assets/css/simple-viewer.css';
10
10
  var SDocViewer = function SDocViewer(_ref) {
11
- var document = _ref.document,
11
+ var editor = _ref.editor,
12
+ document = _ref.document,
12
13
  customRenderLeaf = _ref.renderLeaf,
13
14
  customRenderElement = _ref.renderElement,
14
15
  showToolbar = _ref.showToolbar,
15
16
  showOutline = _ref.showOutline;
16
- var editor = useMemo(function () {
17
- var defaultEditor = createDefaultEditor();
18
- return withNodeId(defaultEditor);
19
- }, []);
20
- editor.readonly = true;
17
+ var validEditor = editor || withNodeId(createDefaultEditor());
21
18
  var slateValue = (document || generateDefaultDocContent()).children;
22
19
  var decorate = usePipDecorate(editor);
23
20
  return /*#__PURE__*/React.createElement(EditorContainer, {
@@ -29,19 +26,19 @@ var SDocViewer = function SDocViewer(_ref) {
29
26
  readonly: true,
30
27
  showOutline: showOutline
31
28
  }, /*#__PURE__*/React.createElement(Slate, {
32
- editor: editor,
29
+ editor: validEditor,
33
30
  value: slateValue
34
31
  }, /*#__PURE__*/React.createElement(ArticleContainer, {
35
- editor: editor,
32
+ editor: validEditor,
36
33
  readOnly: true
37
34
  }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
38
35
  readOnly: true,
39
36
  placeholder: "",
40
37
  renderElement: function renderElement(props) {
41
- return (customRenderElement || _renderElement)(props, editor);
38
+ return (customRenderElement || _renderElement)(props, validEditor);
42
39
  },
43
40
  renderLeaf: function renderLeaf(props) {
44
- return (customRenderLeaf || _renderLeaf)(props, editor);
41
+ return (customRenderLeaf || _renderLeaf)(props, validEditor);
45
42
  },
46
43
  onDOMBeforeInput: function onDOMBeforeInput(event) {},
47
44
  decorate: decorate
@@ -11,14 +11,20 @@ import './style.css';
11
11
  var DocOperations = function DocOperations(_ref) {
12
12
  var isShowChanges = _ref.isShowChanges,
13
13
  changes = _ref.changes,
14
- toggleViewChanges = _ref.toggleViewChanges;
14
+ toggleViewChanges = _ref.toggleViewChanges,
15
+ publishRevision = _ref.publishRevision,
16
+ mode = _ref.mode,
17
+ abortRebase = _ref.abortRebase;
15
18
  var isSdocRevision = context.getSetting('isSdocRevision');
16
19
  return /*#__PURE__*/React.createElement("div", {
17
20
  className: "doc-ops"
18
21
  }, /*#__PURE__*/React.createElement(RevisionOperations, {
19
22
  isShowChanges: isShowChanges,
20
23
  changes: changes,
21
- toggleViewChanges: toggleViewChanges
24
+ mode: mode,
25
+ toggleViewChanges: toggleViewChanges,
26
+ publishRevision: publishRevision,
27
+ abortRebase: abortRebase
22
28
  }), /*#__PURE__*/React.createElement(CommentsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(ShareOperation, null), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(MoreOperations, null));
23
29
  };
24
30
  export default withTranslation('sdoc-editor')(DocOperations);
@@ -5,17 +5,25 @@ import ViewChanges from './view-changes';
5
5
  import MoreRevisionOperations from './more-revision-operations';
6
6
  import Revisions from './revisions';
7
7
  import ChangesCount from './changes-count';
8
+ import { MODE } from '../../../constants';
8
9
  var RevisionOperations = function RevisionOperations(_ref) {
9
10
  var isShowChanges = _ref.isShowChanges,
10
11
  changes = _ref.changes,
11
- toggleViewChanges = _ref.toggleViewChanges;
12
+ toggleViewChanges = _ref.toggleViewChanges,
13
+ publishRevision = _ref.publishRevision,
14
+ mode = _ref.mode,
15
+ abortRebase = _ref.abortRebase;
12
16
  var isSdocRevision = context.getSetting('isSdocRevision');
13
17
  var isPublished = context.getSetting('isPublished');
14
18
  return /*#__PURE__*/React.createElement(React.Fragment, null, !isSdocRevision && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MoreRevisionOperations, null), /*#__PURE__*/React.createElement(Revisions, null)), isSdocRevision && isShowChanges && /*#__PURE__*/React.createElement(ChangesCount, {
15
19
  changes: changes
16
- }), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
20
+ }), isSdocRevision && mode !== MODE.REBASE && /*#__PURE__*/React.createElement(ViewChanges, {
17
21
  isShowChanges: isShowChanges,
18
22
  toggleViewChanges: toggleViewChanges
19
- }), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, null));
23
+ }), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, {
24
+ publishRevision: publishRevision,
25
+ mode: mode,
26
+ abortRebase: abortRebase
27
+ }));
20
28
  };
21
29
  export default RevisionOperations;
@@ -1,28 +1,31 @@
1
1
  import React, { useCallback } from 'react';
2
+ import { useTranslation } from 'react-i18next';
2
3
  import { Button } from 'reactstrap';
3
- import { withTranslation } from 'react-i18next';
4
- import context from '../../../context';
5
- import toaster from '../../../components/toast';
4
+ import { MODE } from '../../../constants';
6
5
  var PublishRevision = function PublishRevision(_ref) {
7
- var t = _ref.t;
8
- var repoID = context.getSetting('repoID');
9
- var siteRoot = context.getSetting('siteRoot');
6
+ var mode = _ref.mode,
7
+ publishRevision = _ref.publishRevision,
8
+ abortRebase = _ref.abortRebase;
9
+ var _useTranslation = useTranslation(),
10
+ t = _useTranslation.t;
10
11
  var publish = useCallback(function (event) {
11
12
  event.stopPropagation();
12
13
  event.nativeEvent.stopImmediatePropagation();
13
- context.publishSdocRevision().then(function (res) {
14
- var origin_file_path = res.data.origin_file_path;
15
- window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
16
- }).catch(function (error) {
17
- toaster.danger(t('Error'));
18
- });
14
+ publishRevision();
19
15
 
20
16
  // eslint-disable-next-line react-hooks/exhaustive-deps
21
17
  }, []);
18
+ if (mode === MODE.REBASE) {
19
+ return /*#__PURE__*/React.createElement(Button, {
20
+ color: "success",
21
+ onClick: abortRebase,
22
+ className: "ml-4"
23
+ }, t('Abort'));
24
+ }
22
25
  return /*#__PURE__*/React.createElement(Button, {
23
26
  color: "success",
24
27
  onClick: publish,
25
28
  className: "ml-4"
26
29
  }, t('Publish'));
27
30
  };
28
- export default withTranslation('sdoc-editor')(PublishRevision);
31
+ export default PublishRevision;
File without changes