@seafile/sdoc-editor 0.1.154-beta → 0.1.154-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.
- package/dist/api/sdoc-server-api.js +0 -10
- package/dist/api/seafile-api.js +14 -9
- package/dist/basic-sdk/editor/index.js +2 -2
- package/dist/basic-sdk/extension/render/render-element.js +1 -27
- package/dist/basic-sdk/socket/socket-client.js +19 -6
- package/dist/basic-sdk/socket/socket-manager.js +8 -2
- package/dist/basic-sdk/socket/with-socket-io.js +2 -2
- package/dist/basic-sdk/utils/rebase.js +50 -85
- package/dist/constants/index.js +7 -4
- package/dist/context.js +12 -9
- package/dist/pages/simple-editor.js +24 -22
- package/package.json +1 -1
|
@@ -58,16 +58,6 @@ 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
|
-
// }
|
|
71
61
|
}, {
|
|
72
62
|
key: "getCollaborators",
|
|
73
63
|
value: function getCollaborators() {
|
package/dist/api/seafile-api.js
CHANGED
|
@@ -3,7 +3,12 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
var SeafileAPI = /*#__PURE__*/function () {
|
|
5
5
|
function SeafileAPI(server, token) {
|
|
6
|
+
var _this = this;
|
|
6
7
|
_classCallCheck(this, SeafileAPI);
|
|
8
|
+
this.deleteSdocRevision = function (docUuid) {
|
|
9
|
+
var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
|
|
10
|
+
return _this.req.delete(url);
|
|
11
|
+
};
|
|
7
12
|
this.req = axios.create({
|
|
8
13
|
baseURL: server,
|
|
9
14
|
headers: {
|
|
@@ -57,9 +62,9 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
57
62
|
return this._sendPostRequest(url, form);
|
|
58
63
|
}
|
|
59
64
|
}, {
|
|
60
|
-
key: "
|
|
61
|
-
value: function
|
|
62
|
-
var url = '/api/v2.1/seadoc/origin-file-download-link/' + docUuid + '/';
|
|
65
|
+
key: "getSeadocOriginFileContentDownloadLink",
|
|
66
|
+
value: function getSeadocOriginFileContentDownloadLink(docUuid) {
|
|
67
|
+
var url = '/api/v2.1/seadoc/revision/origin-file-download-link/' + docUuid + '/';
|
|
63
68
|
return this.req.get(url);
|
|
64
69
|
}
|
|
65
70
|
}, {
|
|
@@ -82,16 +87,16 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
82
87
|
return this.req.put(url);
|
|
83
88
|
}
|
|
84
89
|
}, {
|
|
85
|
-
key: "
|
|
86
|
-
value: function
|
|
87
|
-
var url = 'api/v2.1/seadoc/
|
|
90
|
+
key: "getRevisionBasicVersionContent",
|
|
91
|
+
value: function getRevisionBasicVersionContent(docUuid) {
|
|
92
|
+
var url = 'api/v2.1/seadoc/revision/basic-version-content/' + docUuid + '/';
|
|
88
93
|
return this.req.get(url);
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
// local files
|
|
92
95
|
}, {
|
|
93
96
|
key: "getSdocFiles",
|
|
94
|
-
value:
|
|
97
|
+
value:
|
|
98
|
+
// local files
|
|
99
|
+
function getSdocFiles(docUuid, p, type) {
|
|
95
100
|
var url = 'api/v2.1/seadoc/dir/' + docUuid + '/?p=' + p + '&type=' + type + '&doc_uuid=' + docUuid;
|
|
96
101
|
return this.req.get(url);
|
|
97
102
|
}
|
|
@@ -94,8 +94,8 @@ var Editor = forwardRef(function (_ref, ref) {
|
|
|
94
94
|
}));
|
|
95
95
|
},
|
|
96
96
|
// send message
|
|
97
|
-
publishDocument: function publishDocument(originDocUuid, originDocName,
|
|
98
|
-
editor.publishDocument(originDocUuid, originDocName,
|
|
97
|
+
publishDocument: function publishDocument(originDocUuid, originDocName, callback) {
|
|
98
|
+
editor.publishDocument(originDocUuid, originDocName, callback);
|
|
99
99
|
},
|
|
100
100
|
replaceDocument: function replaceDocument(value, originFileVersion) {
|
|
101
101
|
editor.replaceDocument(value, originFileVersion);
|
|
@@ -10,7 +10,7 @@ import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4,
|
|
|
10
10
|
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin } from '../plugins';
|
|
11
11
|
import EventBus from '../../utils/event-bus';
|
|
12
12
|
import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY, REBASE_ORIGIN } from '../../constants';
|
|
13
|
-
import { findPath, getNode, replaceNode,
|
|
13
|
+
import { findPath, getNode, replaceNode, deleteNodeMark } from '../../extension/core';
|
|
14
14
|
var CustomElement = function CustomElement(props) {
|
|
15
15
|
var editor = useSlateStatic();
|
|
16
16
|
var element = props.element,
|
|
@@ -199,32 +199,6 @@ var RenderElement = function RenderElement(props) {
|
|
|
199
199
|
|
|
200
200
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
201
201
|
}, [editor]);
|
|
202
|
-
|
|
203
|
-
// const addDeletedElement = useCallback((element) => {
|
|
204
|
-
// const path = findPath(editor, element);
|
|
205
|
-
// deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
206
|
-
|
|
207
|
-
// if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
|
|
208
|
-
// const emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
|
|
209
|
-
// Transforms.insertNodes(editor, emptyNode, { at: [ path[0] ] });
|
|
210
|
-
// } else {
|
|
211
|
-
// const emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
|
|
212
|
-
// emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
|
|
213
|
-
// const parentPath = path.slice(0, -1);
|
|
214
|
-
// const parentNode = getNode(editor, parentPath);
|
|
215
|
-
// const newChildren = [ ...parentNode.children ];
|
|
216
|
-
// const index = path[path.length - 1];
|
|
217
|
-
// newChildren.splice(index, 0, emptyNode);
|
|
218
|
-
// replaceNode(editor, { at: parentPath, nodes: { ...parentNode, children: newChildren} });
|
|
219
|
-
// }
|
|
220
|
-
|
|
221
|
-
// if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
222
|
-
// updateParentNodeByPath(path);
|
|
223
|
-
// }
|
|
224
|
-
|
|
225
|
-
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
226
|
-
// }, [ editor]);
|
|
227
|
-
|
|
228
202
|
var useMasterChanges = useCallback(function (element) {
|
|
229
203
|
var path = findPath(editor, element);
|
|
230
204
|
deleteNodeMark(editor, path, element[REBASE_MARK_KEY.OLD_ELEMENT], REBASE_MARKS);
|
|
@@ -119,11 +119,10 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
|
|
|
119
119
|
this.disconnectWithServer = function () {
|
|
120
120
|
_this.socket.disconnect();
|
|
121
121
|
};
|
|
122
|
-
this.sendPublishDocument = function (originDocUuid, originDocName,
|
|
122
|
+
this.sendPublishDocument = function (originDocUuid, originDocName, callback) {
|
|
123
123
|
_this.socket.emit('publish-document', _this.getParams({
|
|
124
124
|
origin_doc_uuid: originDocUuid,
|
|
125
|
-
origin_doc_name: originDocName
|
|
126
|
-
update_origin_doc: isNeedUpdateOriginDoc
|
|
125
|
+
origin_doc_name: originDocName
|
|
127
126
|
}), function (success) {
|
|
128
127
|
callback && callback(success);
|
|
129
128
|
});
|
|
@@ -158,6 +157,14 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
|
|
|
158
157
|
callback && callback(saveFlag);
|
|
159
158
|
});
|
|
160
159
|
};
|
|
160
|
+
this.receiveRemoveDocument = function () {
|
|
161
|
+
var socketManager = SocketManager.getInstance();
|
|
162
|
+
socketManager.receiveRemoveDocument();
|
|
163
|
+
};
|
|
164
|
+
this.receiveRemoveDocumentError = function () {
|
|
165
|
+
var socketManager = SocketManager.getInstance();
|
|
166
|
+
socketManager.receiveRemoveDocumentError();
|
|
167
|
+
};
|
|
161
168
|
this.config = config;
|
|
162
169
|
this.isReconnect = false;
|
|
163
170
|
this.socket = io(config.sdocServer, {
|
|
@@ -173,11 +180,17 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
|
|
|
173
180
|
this.socket.on('leave-room', this.onLeaveRoom);
|
|
174
181
|
this.socket.on('update-document', this.onReceiveRemoteOperations);
|
|
175
182
|
|
|
176
|
-
// doc
|
|
183
|
+
// doc replaced
|
|
177
184
|
this.socket.on('doc-replaced', this.receiveDocumentReplaced);
|
|
178
185
|
this.socket.on('doc-replaced-error', this.receiveDocumentReplacedError);
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
|
|
187
|
+
// doc published
|
|
188
|
+
this.socket.on('doc-published', this.receivePublishDocument);
|
|
189
|
+
this.socket.on('doc-published-error', this.receivePublishDocumentError);
|
|
190
|
+
|
|
191
|
+
// doc removed
|
|
192
|
+
this.socket.on('doc-removed', this.receiveRemoveDocument);
|
|
193
|
+
this.socket.on('doc-removed-error', this.receiveRemoveDocumentError);
|
|
181
194
|
this.socket.on('update-cursor', this.receiveCursorLocation);
|
|
182
195
|
this.socket.io.on('reconnect', this.onReconnect);
|
|
183
196
|
this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
|
|
@@ -27,8 +27,8 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
|
|
|
27
27
|
var version = _this.document.version;
|
|
28
28
|
return version;
|
|
29
29
|
};
|
|
30
|
-
this.sendPublishDocument = function (originDocUuid, originDocName,
|
|
31
|
-
_this.socketClient.sendPublishDocument(originDocUuid, originDocName,
|
|
30
|
+
this.sendPublishDocument = function (originDocUuid, originDocName, callback) {
|
|
31
|
+
_this.socketClient.sendPublishDocument(originDocUuid, originDocName, callback);
|
|
32
32
|
};
|
|
33
33
|
this.receivePublishDocument = function () {
|
|
34
34
|
_this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT);
|
|
@@ -36,6 +36,12 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
|
|
|
36
36
|
this.receivePublishDocumentError = function () {
|
|
37
37
|
_this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR);
|
|
38
38
|
};
|
|
39
|
+
this.receiveRemoveDocument = function () {
|
|
40
|
+
_this.eventBus.dispatch(EXTERNAL_EVENT.REMOVE_DOCUMENT);
|
|
41
|
+
};
|
|
42
|
+
this.receiveRemoveDocumentError = function () {
|
|
43
|
+
_this.eventBus.dispatch(EXTERNAL_EVENT.REMOVE_DOCUMENT_ERROR);
|
|
44
|
+
};
|
|
39
45
|
this.sendReplaceDocument = function (document) {
|
|
40
46
|
_this.socketClient.sendReplaceDocument(document, function (result) {
|
|
41
47
|
var serverVersion = result.version;
|
|
@@ -54,10 +54,10 @@ var withSocketIO = function withSocketIO(editor, options) {
|
|
|
54
54
|
var socketManager = SocketManager.getInstance(newEditor, document, config);
|
|
55
55
|
socketManager.sendRebaseContent(document, originFileVersion);
|
|
56
56
|
};
|
|
57
|
-
newEditor.publishDocument = function (originDocUuid, originDocName,
|
|
57
|
+
newEditor.publishDocument = function (originDocUuid, originDocName, callback) {
|
|
58
58
|
var config = options.config;
|
|
59
59
|
var socketManager = SocketManager.getInstance(newEditor, document, config);
|
|
60
|
-
socketManager.sendPublishDocument(originDocUuid, originDocName,
|
|
60
|
+
socketManager.sendPublishDocument(originDocUuid, originDocName, callback);
|
|
61
61
|
};
|
|
62
62
|
newEditor.replaceDocument = function (document) {
|
|
63
63
|
var config = options.config;
|
|
@@ -59,134 +59,99 @@ var getChanges = function getChanges(masterContent, revisionContent) {
|
|
|
59
59
|
});
|
|
60
60
|
return content;
|
|
61
61
|
};
|
|
62
|
-
var getMergeElement = function getMergeElement(diffElement,
|
|
62
|
+
var getMergeElement = function getMergeElement(diffElement, basicElement) {
|
|
63
63
|
var modifyType = diffElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
64
|
+
var newElement = _objectSpread({}, diffElement);
|
|
65
|
+
newElement[REBASE_MARK_KEY.MODIFY_TYPE] && delete newElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
64
66
|
|
|
65
|
-
// revision
|
|
67
|
+
// revision does not have this element, master has this element
|
|
66
68
|
if (modifyType === MODIFY_TYPE.DELETE) {
|
|
67
|
-
//
|
|
68
|
-
if (!
|
|
69
|
-
var _newElement = _objectSpread({}, diffElement);
|
|
70
|
-
_newElement[REBASE_MARK_KEY.MODIFY_TYPE] && delete _newElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
71
|
-
return [_newElement];
|
|
72
|
-
}
|
|
69
|
+
// basic content does not have this element, indicating that it is newly added by master and needs to be retained, and will not be counted as a conflict.
|
|
70
|
+
if (!basicElement) return [newElement];
|
|
73
71
|
|
|
74
|
-
//
|
|
75
|
-
if (!ObjectUtils.isSameObject(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_newElement2[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.MODIFY_DELETE;
|
|
79
|
-
return [_newElement2];
|
|
72
|
+
// basic content has this element, master modified it, indicating that revision deleted it, and the user manually selected the conflict
|
|
73
|
+
if (!ObjectUtils.isSameObject(basicElement, diffElement, [REBASE_MARK_KEY.MODIFY_TYPE])) {
|
|
74
|
+
newElement[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.MODIFY_DELETE;
|
|
75
|
+
return [newElement];
|
|
80
76
|
}
|
|
81
77
|
|
|
82
|
-
//
|
|
78
|
+
// basic content has this element, but master has not modified it. It means that revision has deleted it and the program has deleted it. The conflict will not be counted.
|
|
83
79
|
return [];
|
|
84
80
|
}
|
|
85
81
|
|
|
86
|
-
// revision
|
|
82
|
+
// revision has this element, master does not have this element
|
|
87
83
|
if (modifyType === MODIFY_TYPE.ADD) {
|
|
88
|
-
//
|
|
89
|
-
if (!
|
|
90
|
-
var _newElement3 = _objectSpread({}, diffElement);
|
|
91
|
-
_newElement3[REBASE_MARK_KEY.MODIFY_TYPE] && delete _newElement3[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
92
|
-
return [_newElement3];
|
|
93
|
-
}
|
|
84
|
+
// basic content does not have this element, indicating that it is newly added by revision and needs to be retained, and will not be counted as a conflict.
|
|
85
|
+
if (!basicElement) return [newElement];
|
|
94
86
|
|
|
95
|
-
// master
|
|
96
|
-
if (!ObjectUtils.isSameObject(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
_newElement4[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.DELETE_MODIFY;
|
|
100
|
-
return [_newElement4];
|
|
87
|
+
// master deleted it, revision modified it, and the user manually selected the conflict
|
|
88
|
+
if (!ObjectUtils.isSameObject(basicElement, diffElement, [REBASE_MARK_KEY.MODIFY_TYPE])) {
|
|
89
|
+
newElement[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.DELETE_MODIFY;
|
|
90
|
+
return [newElement];
|
|
101
91
|
}
|
|
102
92
|
|
|
103
|
-
// master
|
|
93
|
+
// master deleted it, revision did not modify it, the program deleted it, and the conflict is not counted.
|
|
104
94
|
return [];
|
|
105
95
|
}
|
|
106
96
|
|
|
107
|
-
// revision
|
|
97
|
+
// Elements that differ between revision and master
|
|
108
98
|
if (modifyType === MODIFY_TYPE.MODIFY) {
|
|
109
99
|
var _objectSpread7, _objectSpread8;
|
|
110
|
-
var revisionElement = _objectSpread({}, diffElement);
|
|
111
100
|
var masterElement = _objectSpread({}, diffElement[REBASE_MARK_KEY.OLD_ELEMENT]);
|
|
112
|
-
delete
|
|
113
|
-
delete revisionElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
101
|
+
delete newElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
114
102
|
|
|
115
|
-
// revision
|
|
116
|
-
if (!
|
|
103
|
+
// revision and master both add a new element, but the content is different. ===》 At present, this situation does not exist, it only exists in the theoretical stage.
|
|
104
|
+
if (!basicElement) {
|
|
117
105
|
var _objectSpread5, _objectSpread6;
|
|
118
|
-
return [_objectSpread(_objectSpread({}, replaceNodeId(masterElement)), {}, (_objectSpread5 = {}, _defineProperty(_objectSpread5, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread5, REBASE_MARK_KEY.OLD_ELEMENT, masterElement), _defineProperty(_objectSpread5, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.OTHER), _objectSpread5)), _objectSpread(_objectSpread({},
|
|
106
|
+
return [_objectSpread(_objectSpread({}, replaceNodeId(masterElement)), {}, (_objectSpread5 = {}, _defineProperty(_objectSpread5, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread5, REBASE_MARK_KEY.OLD_ELEMENT, masterElement), _defineProperty(_objectSpread5, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.OTHER), _objectSpread5)), _objectSpread(_objectSpread({}, newElement), {}, (_objectSpread6 = {}, _defineProperty(_objectSpread6, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread6, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.MY), _objectSpread6))];
|
|
119
107
|
}
|
|
120
108
|
|
|
121
|
-
// master
|
|
122
|
-
if (ObjectUtils.isSameObject(masterElement,
|
|
123
|
-
return [revisionElement];
|
|
124
|
-
}
|
|
109
|
+
// master is the same as base, indicating that revision has modified the content
|
|
110
|
+
if (ObjectUtils.isSameObject(masterElement, basicElement)) return [newElement];
|
|
125
111
|
|
|
126
|
-
// revision
|
|
127
|
-
if (ObjectUtils.isSameObject(
|
|
128
|
-
return [masterElement];
|
|
129
|
-
}
|
|
112
|
+
// revision is the same as base, indicating that master has modified the content
|
|
113
|
+
if (ObjectUtils.isSameObject(newElement, basicElement)) return [masterElement];
|
|
130
114
|
|
|
131
|
-
//
|
|
132
|
-
return [_objectSpread(_objectSpread({}, replaceNodeId(masterElement)), {}, (_objectSpread7 = {}, _defineProperty(_objectSpread7, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread7, REBASE_MARK_KEY.OLD_ELEMENT, masterElement), _defineProperty(_objectSpread7, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.OTHER), _objectSpread7)), _objectSpread(_objectSpread({},
|
|
115
|
+
// They are all different. Revision and master were modified at the same time. If there is a conflict, the conflict needs to be resolved manually.
|
|
116
|
+
return [_objectSpread(_objectSpread({}, replaceNodeId(masterElement)), {}, (_objectSpread7 = {}, _defineProperty(_objectSpread7, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread7, REBASE_MARK_KEY.OLD_ELEMENT, masterElement), _defineProperty(_objectSpread7, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.OTHER), _objectSpread7)), _objectSpread(_objectSpread({}, newElement), {}, (_objectSpread8 = {}, _defineProperty(_objectSpread8, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread8, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.MY), _objectSpread8))];
|
|
133
117
|
}
|
|
134
118
|
if (modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
|
|
135
|
-
var _revisionElement = _objectSpread({}, diffElement);
|
|
136
119
|
var _masterElement = _objectSpread({}, diffElement[REBASE_MARK_KEY.OLD_ELEMENT]);
|
|
137
|
-
delete
|
|
138
|
-
delete _revisionElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
120
|
+
delete newElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
139
121
|
|
|
140
|
-
// revision
|
|
141
|
-
if (!
|
|
122
|
+
// revision and master both add a new element, but the content is different. ===》 At present, this situation does not exist, it only exists in the theoretical stage.
|
|
123
|
+
if (!basicElement) {
|
|
142
124
|
var _objectSpread9, _objectSpread10;
|
|
143
|
-
return [_objectSpread(_objectSpread({}, replaceNodeId(_masterElement)), {}, (_objectSpread9 = {}, _defineProperty(_objectSpread9, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread9, REBASE_MARK_KEY.OLD_ELEMENT, _masterElement), _defineProperty(_objectSpread9, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.OTHER), _objectSpread9)), _objectSpread(_objectSpread({},
|
|
125
|
+
return [_objectSpread(_objectSpread({}, replaceNodeId(_masterElement)), {}, (_objectSpread9 = {}, _defineProperty(_objectSpread9, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread9, REBASE_MARK_KEY.OLD_ELEMENT, _masterElement), _defineProperty(_objectSpread9, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.OTHER), _objectSpread9)), _objectSpread(_objectSpread({}, newElement), {}, (_objectSpread10 = {}, _defineProperty(_objectSpread10, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread10, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.MY), _objectSpread10))];
|
|
144
126
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (ObjectUtils.isSameObject(_masterElement,
|
|
148
|
-
return [
|
|
127
|
+
if (ObjectUtils.isSameObject(_masterElement, basicElement)) return [newElement];
|
|
128
|
+
if (ObjectUtils.isSameObject(newElement, basicElement)) return [_masterElement];
|
|
129
|
+
if (ObjectUtils.isSameObject(_masterElement, newElement, ['type'])) {
|
|
130
|
+
if (ObjectUtils.isSameObject(_masterElement, basicElement, ['type'])) return [newElement];
|
|
131
|
+
if (ObjectUtils.isSameObject(newElement, basicElement, ['type'])) return [_masterElement];
|
|
149
132
|
}
|
|
150
133
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
return [_masterElement];
|
|
154
|
-
}
|
|
155
|
-
if (ObjectUtils.isSameObject(_masterElement, _revisionElement, ['type'])) {
|
|
156
|
-
// master 和 base 一样,说明 revision 对内容进行了修改
|
|
157
|
-
if (ObjectUtils.isSameObject(_masterElement, baseElement, ['type'])) {
|
|
158
|
-
return [_revisionElement];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// revision 和 base 一样,说明 master 对内容进行了修改
|
|
162
|
-
if (ObjectUtils.isSameObject(_revisionElement, baseElement, ['type'])) {
|
|
163
|
-
return [_masterElement];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// 子节点内容更改了,需要 手动解决
|
|
168
|
-
var _getMergeContent = getMergeContent(baseElement, diffElement.children),
|
|
134
|
+
// The content of the subnode has changed and needs to be solved manually.
|
|
135
|
+
var _getMergeContent = getMergeContent(basicElement, diffElement.children),
|
|
169
136
|
childrenContent = _getMergeContent.content;
|
|
170
|
-
return [_objectSpread(_objectSpread({},
|
|
137
|
+
return [_objectSpread(_objectSpread({}, newElement), {}, _defineProperty({
|
|
171
138
|
children: childrenContent
|
|
172
139
|
}, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.CHILDREN_MODIFY))];
|
|
173
140
|
}
|
|
174
|
-
var newElement = _objectSpread({}, diffElement);
|
|
175
|
-
newElement[REBASE_MARK_KEY.MODIFY_TYPE] && delete newElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
176
141
|
newElement[REBASE_MARK_KEY.OLD_ELEMENT] && delete newElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
177
142
|
return [newElement];
|
|
178
143
|
};
|
|
179
|
-
var getMergeContent = function getMergeContent(
|
|
144
|
+
var getMergeContent = function getMergeContent(basicContent, diffChanges) {
|
|
180
145
|
var _generateIdMapAndIds3 = generateIdMapAndIds(diffChanges),
|
|
181
146
|
diffChangesContentMap = _generateIdMapAndIds3.map,
|
|
182
147
|
diffChangesContentIds = _generateIdMapAndIds3.ids;
|
|
183
|
-
var _generateIdMapAndIds4 = generateIdMapAndIds(
|
|
148
|
+
var _generateIdMapAndIds4 = generateIdMapAndIds(basicContent.children),
|
|
184
149
|
baseContentMap = _generateIdMapAndIds4.map;
|
|
185
150
|
var content = [];
|
|
186
151
|
diffChangesContentIds.forEach(function (elementId) {
|
|
187
152
|
var diffElement = diffChangesContentMap[elementId];
|
|
188
|
-
var
|
|
189
|
-
var mergeElements = getMergeElement(diffElement,
|
|
153
|
+
var basicElement = baseContentMap[elementId];
|
|
154
|
+
var mergeElements = getMergeElement(diffElement, basicElement);
|
|
190
155
|
content.push.apply(content, _toConsumableArray(mergeElements));
|
|
191
156
|
});
|
|
192
157
|
var canMerge = !hasConflict(content);
|
|
@@ -195,9 +160,9 @@ var getMergeContent = function getMergeContent(baseContent, diffChanges) {
|
|
|
195
160
|
canMerge: canMerge
|
|
196
161
|
};
|
|
197
162
|
};
|
|
198
|
-
export var getRebase = function getRebase(masterContent,
|
|
163
|
+
export var getRebase = function getRebase(masterContent, basicContent, revisionContent) {
|
|
199
164
|
// master no changes, merged directly
|
|
200
|
-
if (masterContent.version ===
|
|
165
|
+
if (masterContent.version === basicContent.version) {
|
|
201
166
|
return {
|
|
202
167
|
canMerge: true,
|
|
203
168
|
isNeedReplaceMaster: true,
|
|
@@ -206,7 +171,7 @@ export var getRebase = function getRebase(masterContent, baseContent, revisionCo
|
|
|
206
171
|
}
|
|
207
172
|
|
|
208
173
|
// The revision content has not changed
|
|
209
|
-
if (
|
|
174
|
+
if (basicContent.version === revisionContent.version) {
|
|
210
175
|
return {
|
|
211
176
|
canMerge: true,
|
|
212
177
|
isNeedReplaceMaster: false,
|
|
@@ -214,7 +179,7 @@ export var getRebase = function getRebase(masterContent, baseContent, revisionCo
|
|
|
214
179
|
};
|
|
215
180
|
}
|
|
216
181
|
var diffChanges = getChanges(masterContent, revisionContent);
|
|
217
|
-
var _getMergeContent2 = getMergeContent(
|
|
182
|
+
var _getMergeContent2 = getMergeContent(basicContent, diffChanges),
|
|
218
183
|
canMerge = _getMergeContent2.canMerge,
|
|
219
184
|
content = _getMergeContent2.content;
|
|
220
185
|
return {
|
package/dist/constants/index.js
CHANGED
|
@@ -8,7 +8,9 @@ export var EXTERNAL_EVENT = {
|
|
|
8
8
|
PUBLISH_DOCUMENT: 'publish_document',
|
|
9
9
|
PUBLISH_DOCUMENT_ERROR: 'publish_document_error',
|
|
10
10
|
DOCUMENT_REPLACED: 'document_replaced',
|
|
11
|
-
DOCUMENT_REPLACED_ERROR: 'document_replaced_error'
|
|
11
|
+
DOCUMENT_REPLACED_ERROR: 'document_replaced_error',
|
|
12
|
+
REMOVE_DOCUMENT: 'remove_document',
|
|
13
|
+
REMOVE_DOCUMENT_ERROR: 'remove_document_error'
|
|
12
14
|
};
|
|
13
15
|
export var MODE = {
|
|
14
16
|
DIFF_VIEWER: 'diff_viewer',
|
|
@@ -21,7 +23,8 @@ export var TIP_TYPE = {
|
|
|
21
23
|
HAS_CONFLICT_BEFORE_PUBLISH: 'has_conflict_before_publish',
|
|
22
24
|
HAS_BEEN_PUBLISHED: 'has_been_published',
|
|
23
25
|
HAS_BEEN_REPLACED: 'has_been_merge',
|
|
24
|
-
HAS_CONFLICT_BEFORE_VIEW_CHANGES: 'has_conflict_before_view_changes'
|
|
26
|
+
HAS_CONFLICT_BEFORE_VIEW_CHANGES: 'has_conflict_before_view_changes',
|
|
27
|
+
HAS_BEEN_REMOVED: 'has_been_removed'
|
|
25
28
|
};
|
|
26
|
-
export var TIP_TITLE = (_TIP_TITLE = {}, _defineProperty(_TIP_TITLE, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_REPLACED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Tip'), _TIP_TITLE);
|
|
27
|
-
export var TIP_CONTENT = (_TIP_CONTENT = {}, _defineProperty(_TIP_CONTENT, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Rebase_delete_no_change_revision_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.MERGE, 'Merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Has_conflict_before_publish_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Has_been_published_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_REPLACED, 'Has_been_replaced_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Has_conflict_before_view_changes_tip'), _TIP_CONTENT);
|
|
29
|
+
export var TIP_TITLE = (_TIP_TITLE = {}, _defineProperty(_TIP_TITLE, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_REPLACED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_REMOVED, 'Tip'), _TIP_TITLE);
|
|
30
|
+
export var TIP_CONTENT = (_TIP_CONTENT = {}, _defineProperty(_TIP_CONTENT, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Rebase_delete_no_change_revision_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.MERGE, 'Merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Has_conflict_before_publish_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Has_been_published_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_REPLACED, 'Has_been_replaced_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Has_conflict_before_view_changes_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_REMOVED, 'Has_been_removed_tip'), _TIP_CONTENT);
|
package/dist/context.js
CHANGED
|
@@ -17,9 +17,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
17
17
|
_this.settings['originFileURL'] = originFileURL;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
// saveDocContentByRebase(content) {
|
|
21
|
-
// return this.sdocServerApi.saveDocContentByRebase(content);
|
|
22
|
-
// }
|
|
23
20
|
this.uploadLocalImage = function (imageFile) {
|
|
24
21
|
var docUuid = _this.getSetting('docUuid');
|
|
25
22
|
return _this.api.uploadSdocImage(docUuid, imageFile).then(function (res) {
|
|
@@ -171,10 +168,10 @@ var Context = /*#__PURE__*/function () {
|
|
|
171
168
|
return this.api.startRevise(repoID, fileUuid, filePath);
|
|
172
169
|
}
|
|
173
170
|
}, {
|
|
174
|
-
key: "
|
|
175
|
-
value: function
|
|
171
|
+
key: "getSeadocOriginFileContentDownloadLink",
|
|
172
|
+
value: function getSeadocOriginFileContentDownloadLink() {
|
|
176
173
|
var docUuid = this.getSetting('docUuid');
|
|
177
|
-
return this.api.
|
|
174
|
+
return this.api.getSeadocOriginFileContentDownloadLink(docUuid);
|
|
178
175
|
}
|
|
179
176
|
}, {
|
|
180
177
|
key: "getSdocRevisionsCount",
|
|
@@ -195,10 +192,16 @@ var Context = /*#__PURE__*/function () {
|
|
|
195
192
|
return this.api.updateSdocRevision(docUuid);
|
|
196
193
|
}
|
|
197
194
|
}, {
|
|
198
|
-
key: "
|
|
199
|
-
value: function
|
|
195
|
+
key: "deleteSdocRevision",
|
|
196
|
+
value: function deleteSdocRevision() {
|
|
200
197
|
var docUuid = this.getSetting('docUuid');
|
|
201
|
-
return this.api.
|
|
198
|
+
return this.api.deleteSdocRevision(docUuid);
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "getRevisionBasicVersionContent",
|
|
202
|
+
value: function getRevisionBasicVersionContent() {
|
|
203
|
+
var docUuid = this.getSetting('docUuid');
|
|
204
|
+
return this.api.getRevisionBasicVersionContent(docUuid);
|
|
202
205
|
}
|
|
203
206
|
|
|
204
207
|
// local files
|
|
@@ -105,17 +105,25 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
105
105
|
|
|
106
106
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
107
|
}, []);
|
|
108
|
+
var onDocumentRemoved = useCallback(function () {
|
|
109
|
+
setTipType(TIP_TYPE.HAS_BEEN_REMOVED);
|
|
110
|
+
setShowTip(true);
|
|
111
|
+
|
|
112
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
113
|
+
}, []);
|
|
108
114
|
useEffect(function () {
|
|
109
115
|
var eventBus = EventBus.getInstance();
|
|
110
116
|
var unsubscribeMergeDocument = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED, onDocumentReplaced);
|
|
111
117
|
var unsubscribePublishDocument = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
|
|
112
118
|
var unsubscribeMergeDocumentError = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR, onDocumentReplacedError);
|
|
113
119
|
var unsubscribePublishDocumentError = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, publishDocumentError);
|
|
120
|
+
var unsubscribeRemoveDocument = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT, onDocumentRemoved);
|
|
114
121
|
return function () {
|
|
115
122
|
unsubscribeMergeDocument();
|
|
116
123
|
unsubscribePublishDocument();
|
|
117
124
|
unsubscribeMergeDocumentError();
|
|
118
125
|
unsubscribePublishDocumentError();
|
|
126
|
+
unsubscribeRemoveDocument();
|
|
119
127
|
};
|
|
120
128
|
|
|
121
129
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -147,8 +155,8 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
147
155
|
});
|
|
148
156
|
}, []);
|
|
149
157
|
var setDiffContent = useCallback(function () {
|
|
150
|
-
context.
|
|
151
|
-
var originFileDownloadLink = res.data.
|
|
158
|
+
context.getSeadocOriginFileContentDownloadLink().then(function (res) {
|
|
159
|
+
var originFileDownloadLink = res.data.download_link;
|
|
152
160
|
return fetch(originFileDownloadLink);
|
|
153
161
|
}).then(function (res) {
|
|
154
162
|
return res.json();
|
|
@@ -197,29 +205,27 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
197
205
|
setShowTip(true);
|
|
198
206
|
return;
|
|
199
207
|
}
|
|
200
|
-
var originFileVersion = context.getSetting('originFileVersion'); // changing
|
|
201
|
-
var originFilePath = context.getSetting('originFilePath');
|
|
202
208
|
var originDocName = context.getSetting('originFilename');
|
|
203
209
|
var originDocUuid = context.getSetting('originDocUuid');
|
|
204
|
-
var
|
|
210
|
+
var basicContent;
|
|
205
211
|
var masterContent;
|
|
206
|
-
context.
|
|
207
|
-
var
|
|
208
|
-
|
|
209
|
-
return context.
|
|
212
|
+
context.getRevisionBasicVersionContent().then(function (res) {
|
|
213
|
+
var basicVersionContentString = res.data.content; // commit content
|
|
214
|
+
basicContent = JSON.parse(basicVersionContentString);
|
|
215
|
+
return context.getSeadocOriginFileContentDownloadLink();
|
|
210
216
|
}).then(function (res) {
|
|
211
|
-
var originFileDownloadLink = res.data.
|
|
217
|
+
var originFileDownloadLink = res.data.download_link;
|
|
212
218
|
return fetch(originFileDownloadLink);
|
|
213
219
|
}).then(function (res) {
|
|
214
220
|
return res.json();
|
|
215
221
|
}).then(function (content) {
|
|
216
222
|
masterContent = content;
|
|
217
|
-
var _getRebase = getRebase(masterContent,
|
|
223
|
+
var _getRebase = getRebase(masterContent, basicContent, revisionContent),
|
|
218
224
|
canMerge = _getRebase.canMerge,
|
|
219
225
|
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
220
226
|
value = _getRebase.value;
|
|
221
227
|
if (canMerge && isNeedReplaceMaster) {
|
|
222
|
-
editorRef.current.publishDocument(originDocUuid, originDocName,
|
|
228
|
+
editorRef.current.publishDocument(originDocUuid, originDocName, function (success) {
|
|
223
229
|
if (success) {
|
|
224
230
|
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
225
231
|
setShowTip(true);
|
|
@@ -266,16 +272,12 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
266
272
|
}, [tipType]);
|
|
267
273
|
var tipSubmit = useCallback(function () {
|
|
268
274
|
if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
jumpToURL(originFileURL);
|
|
276
|
-
} else {
|
|
277
|
-
toaster.danger(t('Error'));
|
|
278
|
-
}
|
|
275
|
+
context.deleteSdocRevision().then(function (res) {
|
|
276
|
+
setShowTip(false);
|
|
277
|
+
var originFileURL = context.getSetting('originFileURL');
|
|
278
|
+
jumpToURL(originFileURL);
|
|
279
|
+
}).catch(function (error) {
|
|
280
|
+
toaster.danger(t('Error'));
|
|
279
281
|
});
|
|
280
282
|
return;
|
|
281
283
|
}
|