@seafile/sdoc-editor 1.0.105 → 1.0.106
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.
|
@@ -32,15 +32,16 @@ const hasConflict = content => {
|
|
|
32
32
|
return flag;
|
|
33
33
|
};
|
|
34
34
|
exports.hasConflict = hasConflict;
|
|
35
|
-
const getChanges = (masterContent, revisionContent)
|
|
35
|
+
const getChanges = function (masterContent, revisionContent) {
|
|
36
|
+
let childrenName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
36
37
|
const {
|
|
37
38
|
map: masterContentMap,
|
|
38
39
|
ids: masterIds
|
|
39
|
-
} = (0, _diff.generateIdMapAndIds)(masterContent
|
|
40
|
+
} = (0, _diff.generateIdMapAndIds)(masterContent[childrenName]);
|
|
40
41
|
const {
|
|
41
42
|
map: currentContentMap,
|
|
42
43
|
ids: currentIds
|
|
43
|
-
} = (0, _diff.generateIdMapAndIds)(revisionContent
|
|
44
|
+
} = (0, _diff.generateIdMapAndIds)(revisionContent[childrenName]);
|
|
44
45
|
const idDiffs = (0, _diff.getIdDiffs)(masterIds, currentIds);
|
|
45
46
|
let content = [];
|
|
46
47
|
idDiffs.forEach(idDiff => {
|
|
@@ -200,14 +201,15 @@ const getMergeElement = (diffElement, baseElement) => {
|
|
|
200
201
|
newElement[_constants.REBASE_MARK_KEY.OLD_ELEMENT] && delete newElement[_constants.REBASE_MARK_KEY.OLD_ELEMENT];
|
|
201
202
|
return [newElement];
|
|
202
203
|
};
|
|
203
|
-
const getMergeContent = (baseContent, diffChanges)
|
|
204
|
+
const getMergeContent = function (baseContent, diffChanges) {
|
|
205
|
+
let childrenName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
204
206
|
const {
|
|
205
207
|
map: diffChangesContentMap,
|
|
206
208
|
ids: diffChangesContentIds
|
|
207
209
|
} = (0, _diff.generateIdMapAndIds)(diffChanges);
|
|
208
210
|
const {
|
|
209
211
|
map: baseContentMap
|
|
210
|
-
} = (0, _diff.generateIdMapAndIds)(baseContent
|
|
212
|
+
} = (0, _diff.generateIdMapAndIds)(baseContent[childrenName]);
|
|
211
213
|
let content = [];
|
|
212
214
|
diffChangesContentIds.forEach(elementId => {
|
|
213
215
|
const diffElement = diffChangesContentMap[elementId];
|
|
@@ -239,7 +241,18 @@ const canMerge = (content, reference) => {
|
|
|
239
241
|
return flag;
|
|
240
242
|
};
|
|
241
243
|
exports.canMerge = canMerge;
|
|
244
|
+
const updateContentToFormatVersion4 = content => {
|
|
245
|
+
if (content.format_version === 4) return;
|
|
246
|
+
content.format_version = 4;
|
|
247
|
+
content.elements = content.children;
|
|
248
|
+
delete content['children'];
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Only the data in baseContent needs to be formatted.
|
|
252
|
+
// The data in the other two does not need to be formatted. They are directly obtained from sdoc-server.
|
|
242
253
|
const getRebase = (masterContent, baseContent, revisionContent) => {
|
|
254
|
+
updateContentToFormatVersion4(baseContent);
|
|
255
|
+
|
|
243
256
|
// master no changes, merged directly
|
|
244
257
|
if (masterContent.version === baseContent.version) {
|
|
245
258
|
return {
|
|
@@ -257,14 +270,14 @@ const getRebase = (masterContent, baseContent, revisionContent) => {
|
|
|
257
270
|
value: masterContent
|
|
258
271
|
};
|
|
259
272
|
}
|
|
260
|
-
const diffChanges = getChanges(masterContent, revisionContent);
|
|
261
|
-
const content = getMergeContent(baseContent, diffChanges);
|
|
273
|
+
const diffChanges = getChanges(masterContent, revisionContent, 'elements');
|
|
274
|
+
const content = getMergeContent(baseContent, diffChanges, 'elements');
|
|
262
275
|
return {
|
|
263
|
-
canMerge: canMerge(content, revisionContent.
|
|
276
|
+
canMerge: canMerge(content, revisionContent.elements),
|
|
264
277
|
isNeedReplaceMaster: true,
|
|
265
278
|
value: {
|
|
266
279
|
...revisionContent,
|
|
267
|
-
|
|
280
|
+
elements: content,
|
|
268
281
|
version: Math.max(masterContent.version, revisionContent.version) + 1
|
|
269
282
|
}
|
|
270
283
|
};
|
|
@@ -118,7 +118,7 @@ const RevisionOperations = _ref => {
|
|
|
118
118
|
// The trick here is to send one more api request in order to use the same information box.
|
|
119
119
|
loadDocument().then(revisionContent => {
|
|
120
120
|
// Prevent users from switching if document contains conflicting content
|
|
121
|
-
if ((0, _rebase.hasConflict)(revisionContent.
|
|
121
|
+
if ((0, _rebase.hasConflict)(revisionContent.elements)) {
|
|
122
122
|
setTipType(_constants.TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
|
|
123
123
|
setShowTip(true);
|
|
124
124
|
} else {
|
|
@@ -146,7 +146,7 @@ const RevisionOperations = _ref => {
|
|
|
146
146
|
const [revisionContent, baseRes, masterRes] = results;
|
|
147
147
|
const baseContent = JSON.parse(baseRes.data.content);
|
|
148
148
|
const masterContent = JSON.parse(masterRes.data.content);
|
|
149
|
-
if ((0, _rebase.hasConflict)(revisionContent.
|
|
149
|
+
if ((0, _rebase.hasConflict)(revisionContent.elements)) {
|
|
150
150
|
setTipType(_constants.TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
@@ -206,7 +206,7 @@ const RevisionOperations = _ref => {
|
|
|
206
206
|
username
|
|
207
207
|
} = _context.default.getUserInfo();
|
|
208
208
|
const doc = {
|
|
209
|
-
|
|
209
|
+
elements: mergeValue.elements,
|
|
210
210
|
version: mergeValue.version,
|
|
211
211
|
format_version: mergeValue.format_version,
|
|
212
212
|
last_modify_user: username
|