@seafile/sdoc-editor 0.1.149-beta5 → 0.1.149-beta6
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.
|
@@ -16,6 +16,7 @@ export var MODIFY_TYPE = {
|
|
|
16
16
|
export var REBASE_TYPE = {
|
|
17
17
|
MODIFY_MODIFY: 'modify_modify',
|
|
18
18
|
DELETE_MODIFY: 'delete_modify',
|
|
19
|
+
MODIFY_DELETE: 'modify_delete',
|
|
19
20
|
CHILDREN_MODIFY: 'children_modify'
|
|
20
21
|
};
|
|
21
22
|
export var REBASE_MARK_KEY = {
|
|
@@ -24,4 +25,8 @@ export var REBASE_MARK_KEY = {
|
|
|
24
25
|
MODIFY_TYPE: 'modify_type',
|
|
25
26
|
OLD_ELEMENT: 'old_element'
|
|
26
27
|
};
|
|
28
|
+
export var REBASE_ORIGIN = {
|
|
29
|
+
OTHER: 'other',
|
|
30
|
+
MY: 'my'
|
|
31
|
+
};
|
|
27
32
|
export var REBASE_MARKS = [REBASE_MARK_KEY.ORIGIN, REBASE_MARK_KEY.REBASE_TYPE, REBASE_MARK_KEY.MODIFY_TYPE, REBASE_MARK_KEY.OLD_ELEMENT];
|
|
@@ -9,7 +9,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
9
9
|
import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, CODE_LINE, IMAGE, ELEMENT_TYPE, SDOC_LINK, TITLE, SUBTITLE } from '../constants';
|
|
10
10
|
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin } from '../plugins';
|
|
11
11
|
import EventBus from '../../utils/event-bus';
|
|
12
|
-
import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY } from '../../constants';
|
|
12
|
+
import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY, REBASE_ORIGIN } from '../../constants';
|
|
13
13
|
import { findPath, getNode, replaceNode, generateEmptyElement, deleteNodeMark } from '../../extension/core';
|
|
14
14
|
var CustomElement = function CustomElement(props) {
|
|
15
15
|
var editor = useSlateStatic();
|
|
@@ -193,35 +193,32 @@ var RenderElement = function RenderElement(props) {
|
|
|
193
193
|
|
|
194
194
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
195
195
|
}, [editor]);
|
|
196
|
-
var addDeletedElement = useCallback(function (element) {
|
|
197
|
-
var path = findPath(editor, element);
|
|
198
|
-
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
199
|
-
if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
|
|
200
|
-
var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
|
|
201
|
-
Transforms.insertNodes(editor, emptyNode, {
|
|
202
|
-
at: [path[0]]
|
|
203
|
-
});
|
|
204
|
-
} else {
|
|
205
|
-
var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
|
|
206
|
-
_emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
|
|
207
|
-
var parentPath = path.slice(0, -1);
|
|
208
|
-
var parentNode = getNode(editor, parentPath);
|
|
209
|
-
var newChildren = _toConsumableArray(parentNode.children);
|
|
210
|
-
var index = path[path.length - 1];
|
|
211
|
-
newChildren.splice(index, 0, _emptyNode);
|
|
212
|
-
replaceNode(editor, {
|
|
213
|
-
at: parentPath,
|
|
214
|
-
nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
|
|
215
|
-
children: newChildren
|
|
216
|
-
})
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
220
|
-
updateParentNodeByPath(path);
|
|
221
|
-
}
|
|
222
196
|
|
|
223
|
-
|
|
224
|
-
|
|
197
|
+
// const addDeletedElement = useCallback((element) => {
|
|
198
|
+
// const path = findPath(editor, element);
|
|
199
|
+
// deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
200
|
+
|
|
201
|
+
// if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
|
|
202
|
+
// const emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
|
|
203
|
+
// Transforms.insertNodes(editor, emptyNode, { at: [ path[0] ] });
|
|
204
|
+
// } else {
|
|
205
|
+
// const emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
|
|
206
|
+
// emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
|
|
207
|
+
// const parentPath = path.slice(0, -1);
|
|
208
|
+
// const parentNode = getNode(editor, parentPath);
|
|
209
|
+
// const newChildren = [ ...parentNode.children ];
|
|
210
|
+
// const index = path[path.length - 1];
|
|
211
|
+
// newChildren.splice(index, 0, emptyNode);
|
|
212
|
+
// replaceNode(editor, { at: parentPath, nodes: { ...parentNode, children: newChildren} });
|
|
213
|
+
// }
|
|
214
|
+
|
|
215
|
+
// if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
216
|
+
// updateParentNodeByPath(path);
|
|
217
|
+
// }
|
|
218
|
+
|
|
219
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
220
|
+
// }, [ editor]);
|
|
221
|
+
|
|
225
222
|
var useMasterChanges = useCallback(function (element) {
|
|
226
223
|
var path = findPath(editor, element);
|
|
227
224
|
deleteNodeMark(editor, path, element[REBASE_MARK_KEY.OLD_ELEMENT], REBASE_MARKS);
|
|
@@ -272,30 +269,53 @@ var RenderElement = function RenderElement(props) {
|
|
|
272
269
|
if (!rebaseType) {
|
|
273
270
|
return /*#__PURE__*/React.createElement(CustomElement, props);
|
|
274
271
|
}
|
|
275
|
-
if (rebaseType === REBASE_TYPE.
|
|
272
|
+
if (rebaseType === REBASE_TYPE.MODIFY_DELETE) {
|
|
276
273
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
277
274
|
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
278
275
|
contentEditable: false
|
|
279
276
|
}, /*#__PURE__*/React.createElement("div", {
|
|
280
277
|
className: "sdoc-rebase-btn",
|
|
281
278
|
onClick: function onClick() {
|
|
282
|
-
return
|
|
279
|
+
return deleteMark(element);
|
|
283
280
|
}
|
|
284
281
|
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
285
282
|
className: "mr-2 ml-2"
|
|
286
283
|
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
287
284
|
className: "sdoc-rebase-btn",
|
|
288
285
|
onClick: function onClick() {
|
|
289
|
-
return
|
|
286
|
+
return deleteElement(element);
|
|
290
287
|
}
|
|
291
|
-
}, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
|
|
288
|
+
}, t('Keep_my_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
289
|
+
className: "w-100 sdoc-rebase-current-changes-start",
|
|
290
|
+
contentEditable: false
|
|
291
|
+
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
292
|
+
className: "w-100 sdoc-rebase-incoming-changes",
|
|
293
|
+
contentEditable: false
|
|
294
|
+
}, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
|
|
295
|
+
className: "w-100",
|
|
296
|
+
contentEditable: false
|
|
297
|
+
}, '======='), /*#__PURE__*/React.createElement("div", {
|
|
298
|
+
className: "w-100 sdoc-rebase-incoming-changes-end",
|
|
299
|
+
contentEditable: false
|
|
300
|
+
}, '>>>>>>>'));
|
|
301
|
+
}
|
|
302
|
+
if (rebaseType === REBASE_TYPE.DELETE_MODIFY) {
|
|
303
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
304
|
+
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
305
|
+
contentEditable: false
|
|
306
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
307
|
+
className: "sdoc-rebase-btn",
|
|
308
|
+
onClick: function onClick() {
|
|
309
|
+
return deleteElement(element);
|
|
310
|
+
}
|
|
311
|
+
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
292
312
|
className: "mr-2 ml-2"
|
|
293
313
|
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
294
314
|
className: "sdoc-rebase-btn",
|
|
295
315
|
onClick: function onClick() {
|
|
296
|
-
return
|
|
316
|
+
return deleteMark(element);
|
|
297
317
|
}
|
|
298
|
-
}, t('
|
|
318
|
+
}, t('Keep_my_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
299
319
|
className: "w-100 sdoc-rebase-current-changes-start",
|
|
300
320
|
contentEditable: false
|
|
301
321
|
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
@@ -310,7 +330,7 @@ var RenderElement = function RenderElement(props) {
|
|
|
310
330
|
}, '>>>>>>>'));
|
|
311
331
|
}
|
|
312
332
|
if (rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
|
|
313
|
-
if (element[REBASE_MARK_KEY.ORIGIN] ===
|
|
333
|
+
if (element[REBASE_MARK_KEY.ORIGIN] === REBASE_ORIGIN.OTHER) {
|
|
314
334
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
315
335
|
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
316
336
|
contentEditable: false
|
|
@@ -3,16 +3,22 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import { generateIdMapAndIds, getIdDiffs } from './diff';
|
|
5
5
|
import ObjectUtils from './object-utils';
|
|
6
|
-
import { MODIFY_TYPE, REBASE_TYPE, REBASE_MARK_KEY } from '../constants';
|
|
6
|
+
import { MODIFY_TYPE, REBASE_TYPE, REBASE_MARK_KEY, REBASE_ORIGIN } from '../constants';
|
|
7
7
|
import { ELEMENT_TYPE } from '../extension/constants';
|
|
8
8
|
import { replaceNodeId } from '../node-id/helpers';
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export var hasConflict = function hasConflict(content) {
|
|
10
|
+
if (!Array.isArray(content) || content.length === 0) return false;
|
|
11
|
+
return content.filter(function (item) {
|
|
12
|
+
return item.rebase_type;
|
|
13
|
+
}).length !== 0;
|
|
14
|
+
};
|
|
15
|
+
var getChanges = function getChanges(masterContent, revisionContent) {
|
|
16
|
+
var _generateIdMapAndIds = generateIdMapAndIds(masterContent.children),
|
|
17
|
+
masterContentMap = _generateIdMapAndIds.map,
|
|
18
|
+
masterIds = _generateIdMapAndIds.ids;
|
|
19
|
+
var _generateIdMapAndIds2 = generateIdMapAndIds(revisionContent.children),
|
|
20
|
+
currentContentMap = _generateIdMapAndIds2.map,
|
|
21
|
+
currentIds = _generateIdMapAndIds2.ids;
|
|
16
22
|
var idDiffs = getIdDiffs(masterIds, currentIds);
|
|
17
23
|
var content = [];
|
|
18
24
|
idDiffs.forEach(function (idDiff) {
|
|
@@ -41,7 +47,7 @@ var getRevisionChanges = function getRevisionChanges(masterContent, currentConte
|
|
|
41
47
|
if (currentElement.type === oldElement.type) {
|
|
42
48
|
var elementType = currentElement.type;
|
|
43
49
|
if ([ELEMENT_TYPE.UNORDERED_LIST, ELEMENT_TYPE.ORDERED_LIST].includes(elementType)) {
|
|
44
|
-
var listContent =
|
|
50
|
+
var listContent = getChanges(oldElement, currentElement);
|
|
45
51
|
newElement[REBASE_MARK_KEY.MODIFY_TYPE] = MODIFY_TYPE.CHILDREN_MODIFY;
|
|
46
52
|
newElement['children'] = listContent;
|
|
47
53
|
}
|
|
@@ -53,129 +59,170 @@ var getRevisionChanges = function getRevisionChanges(masterContent, currentConte
|
|
|
53
59
|
});
|
|
54
60
|
return content;
|
|
55
61
|
};
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var _generateIdMapAndIds3 = generateIdMapAndIds(revisionChanges),
|
|
59
|
-
currentContentMap = _generateIdMapAndIds3.map,
|
|
60
|
-
currentIds = _generateIdMapAndIds3.ids;
|
|
61
|
-
var _generateIdMapAndIds4 = generateIdMapAndIds(masterContent.children),
|
|
62
|
-
masterContentMap = _generateIdMapAndIds4.map,
|
|
63
|
-
masterIds = _generateIdMapAndIds4.ids;
|
|
64
|
-
var idDiffs = getIdDiffs(masterIds, currentIds);
|
|
65
|
-
var content = [];
|
|
66
|
-
idDiffs.forEach(function (idDiff) {
|
|
67
|
-
var value = idDiff.value,
|
|
68
|
-
added = idDiff.added,
|
|
69
|
-
removed = idDiff.removed;
|
|
70
|
-
if (added) {
|
|
71
|
-
value.forEach(function (elementId) {
|
|
72
|
-
var element = currentContentMap[elementId];
|
|
73
|
-
var newElement = {
|
|
74
|
-
id: element.id,
|
|
75
|
-
children: element.children,
|
|
76
|
-
type: element.type
|
|
77
|
-
};
|
|
78
|
-
// 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
|
|
79
|
-
// ==> delete | use modification
|
|
80
|
-
if (element[REBASE_MARK_KEY.MODIFY_TYPE] === MODIFY_TYPE.MODIFY) {
|
|
81
|
-
newElement[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.DELETE_MODIFY;
|
|
82
|
-
content.push(newElement);
|
|
83
|
-
canMerge = false;
|
|
84
|
-
} else {
|
|
85
|
-
// new direct append
|
|
86
|
-
content.push(newElement);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
} else if (removed) {
|
|
90
|
-
var deletedList = value.map(function (item) {
|
|
91
|
-
return _objectSpread({}, masterContentMap[item]);
|
|
92
|
-
});
|
|
93
|
-
content.push.apply(content, _toConsumableArray(deletedList));
|
|
94
|
-
} else {
|
|
95
|
-
value.forEach(function (elementId) {
|
|
96
|
-
var currentElement = currentContentMap[elementId];
|
|
97
|
-
var masterElement = masterContentMap[elementId];
|
|
98
|
-
|
|
99
|
-
// Unchanged
|
|
100
|
-
if (ObjectUtils.isSameObject(masterElement, currentElement)) {
|
|
101
|
-
content.push(currentElement);
|
|
102
|
-
|
|
103
|
-
// 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
|
|
104
|
-
} else if (ObjectUtils.isSameObject(masterElement, currentElement[REBASE_MARK_KEY.OLD_ELEMENT])) {
|
|
105
|
-
var newElement = _objectSpread({}, currentElement);
|
|
106
|
-
newElement[REBASE_MARK_KEY.OLD_ELEMENT] && delete newElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
107
|
-
newElement[REBASE_MARK_KEY.MODIFY_TYPE] && delete newElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
108
|
-
content.push(newElement);
|
|
62
|
+
var getMergeElement = function getMergeElement(diffElement, baseElement) {
|
|
63
|
+
var modifyType = diffElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
109
64
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
65
|
+
// revision 没有该元素,master 有该元素
|
|
66
|
+
if (modifyType === MODIFY_TYPE.DELETE) {
|
|
67
|
+
// baseContent没有该元素,说明是 master 新增的,需要保留,不计入冲突
|
|
68
|
+
if (!baseElement) {
|
|
69
|
+
var _newElement = _objectSpread({}, diffElement);
|
|
70
|
+
_newElement[REBASE_MARK_KEY.MODIFY_TYPE] && delete _newElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
71
|
+
return [_newElement];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// baseContent有该元素, master 对其进行了修改,说明 revision 将其删除了, 用户手动选择冲突
|
|
75
|
+
if (!ObjectUtils.isSameObject(baseElement, diffElement, [REBASE_MARK_KEY.MODIFY_TYPE])) {
|
|
76
|
+
var _newElement2 = _objectSpread({}, diffElement);
|
|
77
|
+
_newElement2[REBASE_MARK_KEY.MODIFY_TYPE] && delete _newElement2[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
78
|
+
_newElement2[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.MODIFY_DELETE;
|
|
79
|
+
return [_newElement2];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// baseContent有该元素,master 没有对其进行了修改, 说明 revision 将其删除了,程序删除,不计入冲突
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// revision 有该元素,master 没有该元素
|
|
87
|
+
if (modifyType === MODIFY_TYPE.ADD) {
|
|
88
|
+
// baseContent没有该元素,说明是 revision 新增的,需要保留,不计入冲突
|
|
89
|
+
if (!baseElement) {
|
|
90
|
+
var _newElement3 = _objectSpread({}, diffElement);
|
|
91
|
+
_newElement3[REBASE_MARK_KEY.MODIFY_TYPE] && delete _newElement3[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
92
|
+
return [_newElement3];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// master 将其删除了, revision 对其进行了修改, 用户手动选择冲突
|
|
96
|
+
if (!ObjectUtils.isSameObject(baseElement, diffElement, [REBASE_MARK_KEY.MODIFY_TYPE])) {
|
|
97
|
+
var _newElement4 = _objectSpread({}, diffElement);
|
|
98
|
+
_newElement4[REBASE_MARK_KEY.MODIFY_TYPE] && delete _newElement4[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
99
|
+
_newElement4[REBASE_MARK_KEY.REBASE_TYPE] = REBASE_TYPE.DELETE_MODIFY;
|
|
100
|
+
return [_newElement4];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// master 将其删除了, revision 没有对其进行了修改, 程序删除,不计入冲突
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// revision 和 master 有差异的元素
|
|
108
|
+
if (modifyType === MODIFY_TYPE.MODIFY) {
|
|
109
|
+
var _objectSpread7, _objectSpread8;
|
|
110
|
+
var revisionElement = _objectSpread({}, diffElement);
|
|
111
|
+
var masterElement = _objectSpread({}, diffElement[REBASE_MARK_KEY.OLD_ELEMENT]);
|
|
112
|
+
delete revisionElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
113
|
+
delete revisionElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
114
|
+
|
|
115
|
+
// revision 和 master 同时新增了一个元素,但且内容不一样。 ===》 目前这种情况不存在,仅存在理论阶段
|
|
116
|
+
if (!baseElement) {
|
|
117
|
+
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({}, revisionElement), {}, (_objectSpread6 = {}, _defineProperty(_objectSpread6, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread6, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.MY), _objectSpread6))];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// master 和 base 一样,说明 revision 对内容进行了修改
|
|
122
|
+
if (ObjectUtils.isSameObject(masterElement, baseElement)) {
|
|
123
|
+
return [revisionElement];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// revision 和 base 一样,说明 master 对内容进行了修改
|
|
127
|
+
if (ObjectUtils.isSameObject(revisionElement, baseElement)) {
|
|
128
|
+
return [masterElement];
|
|
144
129
|
}
|
|
130
|
+
|
|
131
|
+
// 都不一样,revision 和 master 同时修改了,有冲突,需要手动解决冲突
|
|
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({}, revisionElement), {}, (_objectSpread8 = {}, _defineProperty(_objectSpread8, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread8, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.MY), _objectSpread8))];
|
|
133
|
+
}
|
|
134
|
+
if (modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
|
|
135
|
+
var _revisionElement = _objectSpread({}, diffElement);
|
|
136
|
+
var _masterElement = _objectSpread({}, diffElement[REBASE_MARK_KEY.OLD_ELEMENT]);
|
|
137
|
+
delete _revisionElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
138
|
+
delete _revisionElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
139
|
+
|
|
140
|
+
// revision 和 master 同时新增了一个元素,但且内容不一样。 ===》 目前这种情况不存在,仅存在理论阶段
|
|
141
|
+
if (!baseElement) {
|
|
142
|
+
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({}, _revisionElement), {}, (_objectSpread10 = {}, _defineProperty(_objectSpread10, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.MODIFY_MODIFY), _defineProperty(_objectSpread10, REBASE_MARK_KEY.ORIGIN, REBASE_ORIGIN.MY), _objectSpread10))];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// master 和 base 一样,说明 revision 对内容进行了修改
|
|
147
|
+
if (ObjectUtils.isSameObject(_masterElement, baseElement)) {
|
|
148
|
+
return [_revisionElement];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// revision 和 base 一样,说明 master 对内容进行了修改
|
|
152
|
+
if (ObjectUtils.isSameObject(_revisionElement, baseElement)) {
|
|
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),
|
|
169
|
+
childrenContent = _getMergeContent.content;
|
|
170
|
+
return [_objectSpread(_objectSpread({}, _revisionElement), {}, _defineProperty({
|
|
171
|
+
children: childrenContent
|
|
172
|
+
}, REBASE_MARK_KEY.REBASE_TYPE, REBASE_TYPE.CHILDREN_MODIFY))];
|
|
173
|
+
}
|
|
174
|
+
var newElement = _objectSpread({}, diffElement);
|
|
175
|
+
newElement[REBASE_MARK_KEY.MODIFY_TYPE] && delete newElement[REBASE_MARK_KEY.MODIFY_TYPE];
|
|
176
|
+
newElement[REBASE_MARK_KEY.OLD_ELEMENT] && delete newElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
177
|
+
return [newElement];
|
|
178
|
+
};
|
|
179
|
+
var getMergeContent = function getMergeContent(baseContent, diffChanges) {
|
|
180
|
+
var _generateIdMapAndIds3 = generateIdMapAndIds(diffChanges),
|
|
181
|
+
diffChangesContentMap = _generateIdMapAndIds3.map,
|
|
182
|
+
diffChangesContentIds = _generateIdMapAndIds3.ids;
|
|
183
|
+
var _generateIdMapAndIds4 = generateIdMapAndIds(baseContent.children),
|
|
184
|
+
baseContentMap = _generateIdMapAndIds4.map;
|
|
185
|
+
var content = [];
|
|
186
|
+
diffChangesContentIds.forEach(function (elementId) {
|
|
187
|
+
var diffElement = diffChangesContentMap[elementId];
|
|
188
|
+
var baseElement = baseContentMap[elementId];
|
|
189
|
+
var mergeElements = getMergeElement(diffElement, baseElement);
|
|
190
|
+
content.push.apply(content, _toConsumableArray(mergeElements));
|
|
145
191
|
});
|
|
192
|
+
var canMerge = !hasConflict(content);
|
|
146
193
|
return {
|
|
147
194
|
content: content,
|
|
148
195
|
canMerge: canMerge
|
|
149
196
|
};
|
|
150
197
|
};
|
|
151
|
-
export var getRebase = function getRebase(masterContent,
|
|
198
|
+
export var getRebase = function getRebase(masterContent, baseContent, revisionContent) {
|
|
152
199
|
// master no changes, merged directly
|
|
153
|
-
if (masterContent.version ===
|
|
200
|
+
if (masterContent.version === baseContent.version) {
|
|
154
201
|
return {
|
|
155
202
|
canMerge: true,
|
|
156
203
|
isNeedReplaceMaster: true,
|
|
157
|
-
value:
|
|
204
|
+
value: revisionContent
|
|
158
205
|
};
|
|
159
206
|
}
|
|
160
207
|
|
|
161
208
|
// The revision content has not changed
|
|
162
|
-
if (
|
|
209
|
+
if (baseContent.version === revisionContent.version) {
|
|
163
210
|
return {
|
|
164
211
|
canMerge: true,
|
|
165
212
|
isNeedReplaceMaster: false,
|
|
166
213
|
value: masterContent
|
|
167
214
|
};
|
|
168
215
|
}
|
|
169
|
-
var
|
|
170
|
-
var
|
|
171
|
-
canMerge =
|
|
172
|
-
content =
|
|
216
|
+
var diffChanges = getChanges(masterContent, revisionContent);
|
|
217
|
+
var _getMergeContent2 = getMergeContent(baseContent, diffChanges),
|
|
218
|
+
canMerge = _getMergeContent2.canMerge,
|
|
219
|
+
content = _getMergeContent2.content;
|
|
173
220
|
return {
|
|
174
221
|
canMerge: canMerge,
|
|
175
222
|
isNeedReplaceMaster: true,
|
|
176
|
-
value: _objectSpread(_objectSpread({},
|
|
223
|
+
value: _objectSpread(_objectSpread({}, revisionContent), {}, {
|
|
177
224
|
children: content,
|
|
178
|
-
version: Math.max(masterContent.version,
|
|
225
|
+
version: Math.max(masterContent.version, revisionContent.version) + 1
|
|
179
226
|
})
|
|
180
227
|
};
|
|
181
228
|
};
|
|
@@ -12,7 +12,7 @@ import context from '../context';
|
|
|
12
12
|
import ErrorBoundary from './error-boundary';
|
|
13
13
|
import TipDialog from '../components/tip-dialog';
|
|
14
14
|
import { EXTERNAL_EVENT, MODE, TIP_TYPE } from '../constants';
|
|
15
|
-
import { getRebase } from '../basic-sdk/utils/rebase';
|
|
15
|
+
import { getRebase, hasConflict } from '../basic-sdk/utils/rebase';
|
|
16
16
|
import toaster from '../components/toast';
|
|
17
17
|
import { EventBus, SDocEditor } from '../basic-sdk';
|
|
18
18
|
import '../assets/css/simple-editor.css';
|
|
@@ -160,10 +160,8 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
160
160
|
});
|
|
161
161
|
}, []);
|
|
162
162
|
var toggleViewChanges = useCallback(function (isShowChanges) {
|
|
163
|
-
var
|
|
164
|
-
if (isShowChanges &&
|
|
165
|
-
return item.rebase_type;
|
|
166
|
-
}).length !== 0) {
|
|
163
|
+
var revisionContent = editorRef.current.getSlateValue();
|
|
164
|
+
if (isShowChanges && hasConflict(revisionContent.children)) {
|
|
167
165
|
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
|
|
168
166
|
setShowTip(true);
|
|
169
167
|
return;
|
|
@@ -193,10 +191,8 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
193
191
|
while (1) switch (_context.prev = _context.next) {
|
|
194
192
|
case 0:
|
|
195
193
|
loadDocument(function (document) {
|
|
196
|
-
var
|
|
197
|
-
if (
|
|
198
|
-
return item.rebase_type;
|
|
199
|
-
}).length !== 0) {
|
|
194
|
+
var revisionContent = document;
|
|
195
|
+
if (hasConflict(revisionContent.children)) {
|
|
200
196
|
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
|
|
201
197
|
setShowTip(true);
|
|
202
198
|
return;
|
|
@@ -205,11 +201,11 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
205
201
|
var originFilePath = context.getSetting('originFilePath');
|
|
206
202
|
var originDocName = context.getSetting('originFilename');
|
|
207
203
|
var originDocUuid = context.getSetting('originDocUuid');
|
|
208
|
-
var
|
|
204
|
+
var baseContent;
|
|
209
205
|
var masterContent;
|
|
210
206
|
context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
|
|
211
207
|
var fileHistoryRevisionContent = res.data.content; // commit content
|
|
212
|
-
|
|
208
|
+
baseContent = JSON.parse(fileHistoryRevisionContent);
|
|
213
209
|
return context.getSeadocOriginFileDownloadLink();
|
|
214
210
|
}).then(function (res) {
|
|
215
211
|
var originFileDownloadLink = res.data.origin_file_download_link;
|
|
@@ -218,7 +214,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
218
214
|
return res.json();
|
|
219
215
|
}).then(function (content) {
|
|
220
216
|
masterContent = content;
|
|
221
|
-
var _getRebase = getRebase(masterContent,
|
|
217
|
+
var _getRebase = getRebase(masterContent, baseContent, revisionContent),
|
|
222
218
|
canMerge = _getRebase.canMerge,
|
|
223
219
|
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
224
220
|
value = _getRebase.value;
|