@seafile/sdoc-editor 0.1.142-beta → 0.1.143
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 -15
- package/dist/api/seafile-api.js +5 -27
- package/dist/basic-sdk/constants/index.js +1 -14
- package/dist/basic-sdk/editor.js +105 -0
- package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +12 -3
- package/dist/basic-sdk/extension/constants/index.js +2 -0
- package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +0 -26
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +2 -20
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +7 -6
- package/dist/basic-sdk/extension/plugins/html/plugin.js +23 -2
- package/dist/basic-sdk/extension/plugins/image/helpers.js +13 -3
- package/dist/basic-sdk/extension/plugins/link/dialog/add-link-dialog/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/helpers.js +14 -4
- package/dist/basic-sdk/extension/plugins/link/plugin.js +8 -13
- package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +30 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +2 -3
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-below-menu.js +5 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +13 -8
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +7 -4
- package/dist/basic-sdk/extension/toolbar/side-toolbar/transform-menus.js +13 -2
- package/dist/basic-sdk/{editor/slate-editor.js → slate-editor.js} +16 -21
- package/dist/basic-sdk/socket/helpers.js +0 -1
- package/dist/basic-sdk/socket/socket-client.js +0 -5
- package/dist/basic-sdk/socket/socket-manager.js +2 -8
- package/dist/basic-sdk/socket/with-socket-io.js +12 -20
- package/dist/basic-sdk/utils/diff.js +2 -2
- package/dist/basic-sdk/views/diff-viewer.js +1 -3
- package/dist/basic-sdk/views/viewer.js +11 -8
- package/dist/components/doc-operations/index.js +2 -8
- package/dist/components/doc-operations/revision-operations/index.js +3 -11
- package/dist/components/doc-operations/revision-operations/publish-button.js +13 -16
- package/dist/constants/index.js +1 -8
- package/dist/context.js +4 -30
- package/dist/pages/simple-editor.js +71 -221
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +1 -7
- package/public/locales/zh_CN/sdoc-editor.json +1 -7
- package/dist/basic-sdk/editor/common-editor.js +0 -45
- package/dist/basic-sdk/editor/index.js +0 -135
- package/dist/basic-sdk/editor/rebase-editor/index.css +0 -29
- package/dist/basic-sdk/editor/rebase-editor/index.js +0 -276
- package/dist/basic-sdk/utils/rebase.js +0 -193
- package/dist/components/tip-dialog/index.css +0 -0
- package/dist/components/tip-dialog/index.js +0 -45
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import React, { useCallback, useEffect } from 'react';
|
|
4
|
-
import deepCopy from 'deep-copy';
|
|
5
|
-
import { useTranslation } from 'react-i18next';
|
|
6
|
-
import { Transforms } from '@seafile/slate';
|
|
7
|
-
import { renderElement } from '../../extension';
|
|
8
|
-
import { focusEditor, findPath, getNode, replaceNode, generateEmptyElement, deleteNodeMark } from '../../extension/core';
|
|
9
|
-
import { REBASE_TYPE, REBASE_MARKS } from '../../constants';
|
|
10
|
-
import context from '../../../context';
|
|
11
|
-
import toaster from '../../../components/toast';
|
|
12
|
-
import { ELEMENT_TYPE } from '../../extension/constants';
|
|
13
|
-
import { replaceNodeId } from '../../node-id/helpers';
|
|
14
|
-
import { EditorContainer, EditorContent } from '../../layout';
|
|
15
|
-
import SlateEditor from '../slate-editor';
|
|
16
|
-
import './index.css';
|
|
17
|
-
var SDocRebaseEditor = function SDocRebaseEditor(_ref) {
|
|
18
|
-
var slateValue = _ref.slateValue,
|
|
19
|
-
editor = _ref.editor,
|
|
20
|
-
version = _ref.version,
|
|
21
|
-
updateSlateValue = _ref.updateSlateValue,
|
|
22
|
-
toggleViewChanges = _ref.toggleViewChanges;
|
|
23
|
-
var _useTranslation = useTranslation(),
|
|
24
|
-
t = _useTranslation.t;
|
|
25
|
-
|
|
26
|
-
// useMount: focus editor
|
|
27
|
-
useEffect(function () {
|
|
28
|
-
var timer = setTimeout(function () {
|
|
29
|
-
focusEditor(editor);
|
|
30
|
-
}, 300);
|
|
31
|
-
return function () {
|
|
32
|
-
clearTimeout(timer);
|
|
33
|
-
};
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
}, []);
|
|
36
|
-
var onChange = useCallback(function (slateValue) {
|
|
37
|
-
updateSlateValue(slateValue);
|
|
38
|
-
if (slateValue.filter(function (item) {
|
|
39
|
-
return item.rebaseType;
|
|
40
|
-
}).length === 0) {
|
|
41
|
-
var user = context.getUserInfo();
|
|
42
|
-
context.rebaseSdocRevision().then(function (res) {
|
|
43
|
-
return context.saveDocContentByRebase({
|
|
44
|
-
children: slateValue,
|
|
45
|
-
version: version + 1,
|
|
46
|
-
last_modify_user: user.username
|
|
47
|
-
});
|
|
48
|
-
}).then(function (res) {
|
|
49
|
-
toaster.success(t('Successfully_rebase_'));
|
|
50
|
-
toggleViewChanges(false, true);
|
|
51
|
-
}).catch(function (error) {
|
|
52
|
-
toaster.danger(t('Error'));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
-
}, [version, toggleViewChanges]);
|
|
58
|
-
var updateParentNodeByPath = useCallback(function (path) {
|
|
59
|
-
var parentPath = path.slice(0, -1);
|
|
60
|
-
var parentNode = getNode(editor, parentPath);
|
|
61
|
-
if (parentNode.children.filter(function (item) {
|
|
62
|
-
return item.rebaseType;
|
|
63
|
-
}).length === 0) {
|
|
64
|
-
var newParentElement = _objectSpread({}, parentNode);
|
|
65
|
-
newParentElement['rebaseType'] && delete newParentElement['rebaseType'];
|
|
66
|
-
newParentElement['oldElement'] && delete newParentElement['oldElement'];
|
|
67
|
-
newParentElement['origin'] && delete newParentElement['origin'];
|
|
68
|
-
newParentElement['children'] = newParentElement['children'].map(function (item) {
|
|
69
|
-
item['rebaseType'] && delete item['rebaseType'];
|
|
70
|
-
item['oldElement'] && delete item['oldElement'];
|
|
71
|
-
item['origin'] && delete item['origin'];
|
|
72
|
-
return item;
|
|
73
|
-
});
|
|
74
|
-
replaceNode(editor, {
|
|
75
|
-
at: parentPath,
|
|
76
|
-
nodes: newParentElement
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
81
|
-
}, [editor]);
|
|
82
|
-
var deleteElement = useCallback(function (element) {
|
|
83
|
-
var path = findPath(editor, element);
|
|
84
|
-
Transforms.removeNodes(editor, {
|
|
85
|
-
at: path
|
|
86
|
-
});
|
|
87
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
88
|
-
updateParentNodeByPath(path);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
-
}, [slateValue, editor]);
|
|
93
|
-
var deleteMark = useCallback(function (element) {
|
|
94
|
-
var path = findPath(editor, element);
|
|
95
|
-
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
96
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
97
|
-
updateParentNodeByPath(path);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
|
-
}, [slateValue, editor]);
|
|
102
|
-
var addDeletedElement = useCallback(function (element) {
|
|
103
|
-
var path = findPath(editor, element);
|
|
104
|
-
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
105
|
-
if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
|
|
106
|
-
var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
|
|
107
|
-
Transforms.insertNodes(editor, emptyNode, {
|
|
108
|
-
at: [path[0]]
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
|
|
112
|
-
_emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
|
|
113
|
-
var parentPath = path.slice(0, -1);
|
|
114
|
-
var parentNode = getNode(editor, parentPath);
|
|
115
|
-
var newChildren = _toConsumableArray(parentNode.children);
|
|
116
|
-
var index = path[path.length - 1];
|
|
117
|
-
newChildren.splice(index, 0, _emptyNode);
|
|
118
|
-
replaceNode(editor, {
|
|
119
|
-
at: parentPath,
|
|
120
|
-
nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
|
|
121
|
-
children: newChildren
|
|
122
|
-
})
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
126
|
-
updateParentNodeByPath(path);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
|
-
}, [slateValue, editor]);
|
|
131
|
-
var useMasterChanges = useCallback(function (element) {
|
|
132
|
-
var path = findPath(editor, element);
|
|
133
|
-
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
134
|
-
var nextElementPath = _toConsumableArray(path);
|
|
135
|
-
nextElementPath[path.length - 1] = path[path.length - 1] + 1;
|
|
136
|
-
Transforms.removeNodes(editor, {
|
|
137
|
-
at: nextElementPath
|
|
138
|
-
});
|
|
139
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
140
|
-
updateParentNodeByPath(path);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
144
|
-
}, [slateValue, editor]);
|
|
145
|
-
var useCurrentChanges = useCallback(function (element) {
|
|
146
|
-
var path = findPath(editor, element);
|
|
147
|
-
var currentElementPath = _toConsumableArray(path);
|
|
148
|
-
currentElementPath[path.length - 1] = path[path.length - 1] + 1;
|
|
149
|
-
var currentElement = getNode(editor, currentElementPath);
|
|
150
|
-
var newCurrentElement = deepCopy(currentElement);
|
|
151
|
-
deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
|
|
152
|
-
Transforms.removeNodes(editor, {
|
|
153
|
-
at: path
|
|
154
|
-
});
|
|
155
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
156
|
-
updateParentNodeByPath(path);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
160
|
-
}, [slateValue, editor]);
|
|
161
|
-
var useBothChanges = useCallback(function (element) {
|
|
162
|
-
// delete element marks
|
|
163
|
-
var path = findPath(editor, element);
|
|
164
|
-
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
165
|
-
|
|
166
|
-
// delete next element marks
|
|
167
|
-
var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
|
|
168
|
-
var nextElement = getNode(editor, nextElementPath);
|
|
169
|
-
var newNextElement = replaceNodeId(deepCopy(nextElement));
|
|
170
|
-
deleteNodeMark(editor, nextElementPath, newNextElement, REBASE_MARKS);
|
|
171
|
-
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
172
|
-
updateParentNodeByPath(path);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
176
|
-
}, [slateValue, editor]);
|
|
177
|
-
var renderRebaseElement = useCallback(function (props) {
|
|
178
|
-
var element = props.element;
|
|
179
|
-
if (!element.rebaseType) {
|
|
180
|
-
return renderElement(props);
|
|
181
|
-
}
|
|
182
|
-
if (element.rebaseType === REBASE_TYPE.DELETE_MODIFY) {
|
|
183
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
184
|
-
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
185
|
-
contentEditable: false
|
|
186
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
187
|
-
className: "sdoc-rebase-btn",
|
|
188
|
-
onClick: function onClick() {
|
|
189
|
-
return deleteElement(element);
|
|
190
|
-
}
|
|
191
|
-
}, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
|
|
192
|
-
className: "mr-2 ml-2"
|
|
193
|
-
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
194
|
-
className: "sdoc-rebase-btn",
|
|
195
|
-
onClick: function onClick() {
|
|
196
|
-
return deleteMark(element);
|
|
197
|
-
}
|
|
198
|
-
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
199
|
-
className: "mr-2 ml-2"
|
|
200
|
-
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
201
|
-
className: "sdoc-rebase-btn",
|
|
202
|
-
onClick: function onClick() {
|
|
203
|
-
return addDeletedElement(element);
|
|
204
|
-
}
|
|
205
|
-
}, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
206
|
-
className: "w-100 sdoc-rebase-current-changes-start",
|
|
207
|
-
contentEditable: false
|
|
208
|
-
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
209
|
-
className: "w-100",
|
|
210
|
-
contentEditable: false
|
|
211
|
-
}, '======='), /*#__PURE__*/React.createElement("div", {
|
|
212
|
-
className: "w-100 sdoc-rebase-incoming-changes"
|
|
213
|
-
}, renderElement(props)), /*#__PURE__*/React.createElement("div", {
|
|
214
|
-
className: "w-100 sdoc-rebase-incoming-changes-end",
|
|
215
|
-
contentEditable: false
|
|
216
|
-
}, '>>>>>>>'));
|
|
217
|
-
}
|
|
218
|
-
if (element.rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
|
|
219
|
-
if (element.origin === 'master') {
|
|
220
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
221
|
-
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
222
|
-
contentEditable: false
|
|
223
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
224
|
-
className: "sdoc-rebase-btn",
|
|
225
|
-
onClick: function onClick() {
|
|
226
|
-
return useMasterChanges(element);
|
|
227
|
-
}
|
|
228
|
-
}, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
|
|
229
|
-
className: "mr-2 ml-2"
|
|
230
|
-
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
231
|
-
className: "sdoc-rebase-btn",
|
|
232
|
-
onClick: function onClick() {
|
|
233
|
-
return useCurrentChanges(element);
|
|
234
|
-
}
|
|
235
|
-
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
236
|
-
className: "mr-2 ml-2"
|
|
237
|
-
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
238
|
-
className: "sdoc-rebase-btn",
|
|
239
|
-
onClick: function onClick() {
|
|
240
|
-
return useBothChanges(element);
|
|
241
|
-
}
|
|
242
|
-
}, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
243
|
-
className: "w-100 sdoc-rebase-current-changes-start",
|
|
244
|
-
contentEditable: false
|
|
245
|
-
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
246
|
-
className: "w-100 sdoc-rebase-current-changes"
|
|
247
|
-
}, renderElement(props)));
|
|
248
|
-
}
|
|
249
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
250
|
-
className: "w-100",
|
|
251
|
-
contentEditable: false
|
|
252
|
-
}, '======='), /*#__PURE__*/React.createElement("div", {
|
|
253
|
-
className: "w-100 sdoc-rebase-incoming-changes"
|
|
254
|
-
}, renderElement(props)), /*#__PURE__*/React.createElement("div", {
|
|
255
|
-
className: "w-100 sdoc-rebase-incoming-changes-end",
|
|
256
|
-
contentEditable: false
|
|
257
|
-
}, '>>>>>>>'));
|
|
258
|
-
}
|
|
259
|
-
return renderElement(props);
|
|
260
|
-
|
|
261
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
262
|
-
}, []);
|
|
263
|
-
return /*#__PURE__*/React.createElement(EditorContainer, {
|
|
264
|
-
editor: editor
|
|
265
|
-
}, /*#__PURE__*/React.createElement(EditorContent, {
|
|
266
|
-
docValue: slateValue,
|
|
267
|
-
showOutline: true
|
|
268
|
-
}, /*#__PURE__*/React.createElement(SlateEditor, {
|
|
269
|
-
isShowComment: false,
|
|
270
|
-
editor: editor,
|
|
271
|
-
slateValue: slateValue,
|
|
272
|
-
setSlateValue: onChange,
|
|
273
|
-
renderElement: renderRebaseElement
|
|
274
|
-
})));
|
|
275
|
-
};
|
|
276
|
-
export default SDocRebaseEditor;
|
|
@@ -1,193 +0,0 @@
|
|
|
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
|
-
var getRevisionChanges = function getRevisionChanges(masterContent, currentContent) {
|
|
8
|
-
var _generateIdMapAndIds = generateIdMapAndIds(currentContent.children),
|
|
9
|
-
currentContentMap = _generateIdMapAndIds.map,
|
|
10
|
-
currentIds = _generateIdMapAndIds.ids;
|
|
11
|
-
var _generateIdMapAndIds2 = generateIdMapAndIds(masterContent.children),
|
|
12
|
-
masterContentMap = _generateIdMapAndIds2.map,
|
|
13
|
-
masterIds = _generateIdMapAndIds2.ids;
|
|
14
|
-
var idDiffs = getIdDiffs(masterIds, currentIds);
|
|
15
|
-
var content = [];
|
|
16
|
-
idDiffs.forEach(function (idDiff) {
|
|
17
|
-
var value = idDiff.value,
|
|
18
|
-
added = idDiff.added,
|
|
19
|
-
removed = idDiff.removed;
|
|
20
|
-
if (added) {
|
|
21
|
-
var addedList = value.map(function (item) {
|
|
22
|
-
return _objectSpread(_objectSpread({}, currentContentMap[item]), {}, {
|
|
23
|
-
modifyType: MODIFY_TYPE.ADD
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
content.push.apply(content, _toConsumableArray(addedList));
|
|
27
|
-
} else if (removed) {
|
|
28
|
-
var deletedList = value.map(function (item) {
|
|
29
|
-
return _objectSpread(_objectSpread({}, masterContentMap[item]), {}, {
|
|
30
|
-
modifyType: MODIFY_TYPE.DELETE
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
content.push.apply(content, _toConsumableArray(deletedList));
|
|
34
|
-
} else {
|
|
35
|
-
value.forEach(function (elementId) {
|
|
36
|
-
if (ObjectUtils.isSameObject(masterContentMap[elementId], currentContentMap[elementId])) {
|
|
37
|
-
content.push(currentContentMap[elementId]);
|
|
38
|
-
} else {
|
|
39
|
-
var oldElement = masterContentMap[elementId];
|
|
40
|
-
var currentElement = currentContentMap[elementId];
|
|
41
|
-
var newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
|
|
42
|
-
modifyType: MODIFY_TYPE.MODIFY,
|
|
43
|
-
oldElement: oldElement
|
|
44
|
-
});
|
|
45
|
-
if (currentElement.type === oldElement.type) {
|
|
46
|
-
var elementType = currentElement.type;
|
|
47
|
-
if ([ELEMENT_TYPE.UNORDERED_LIST, ELEMENT_TYPE.ORDERED_LIST].includes(elementType)) {
|
|
48
|
-
var listContent = getRevisionChanges(oldElement, currentElement);
|
|
49
|
-
newElement['modifyType'] = MODIFY_TYPE.CHILDREN_MODIFY;
|
|
50
|
-
newElement['children'] = listContent;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
content.push(newElement);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return content;
|
|
59
|
-
};
|
|
60
|
-
var getMasterChanges = function getMasterChanges(masterContent, revisionChanges) {
|
|
61
|
-
var canMerge = true;
|
|
62
|
-
var _generateIdMapAndIds3 = generateIdMapAndIds(revisionChanges),
|
|
63
|
-
currentContentMap = _generateIdMapAndIds3.map,
|
|
64
|
-
currentIds = _generateIdMapAndIds3.ids;
|
|
65
|
-
var _generateIdMapAndIds4 = generateIdMapAndIds(masterContent.children),
|
|
66
|
-
masterContentMap = _generateIdMapAndIds4.map,
|
|
67
|
-
masterIds = _generateIdMapAndIds4.ids;
|
|
68
|
-
var idDiffs = getIdDiffs(masterIds, currentIds);
|
|
69
|
-
var content = [];
|
|
70
|
-
idDiffs.forEach(function (idDiff) {
|
|
71
|
-
var value = idDiff.value,
|
|
72
|
-
added = idDiff.added,
|
|
73
|
-
removed = idDiff.removed;
|
|
74
|
-
if (added) {
|
|
75
|
-
value.forEach(function (elementId) {
|
|
76
|
-
var element = currentContentMap[elementId];
|
|
77
|
-
var newElement = {
|
|
78
|
-
id: element.id,
|
|
79
|
-
children: element.children,
|
|
80
|
-
type: element.type
|
|
81
|
-
};
|
|
82
|
-
// 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
|
|
83
|
-
// ==> delete | use modification
|
|
84
|
-
if (element.modifyType === MODIFY_TYPE.MODIFY) {
|
|
85
|
-
newElement['rebaseType'] = REBASE_TYPE.DELETE_MODIFY;
|
|
86
|
-
content.push(newElement);
|
|
87
|
-
canMerge = false;
|
|
88
|
-
} else {
|
|
89
|
-
// new direct append
|
|
90
|
-
content.push(newElement);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
} else if (removed) {
|
|
94
|
-
var deletedList = value.map(function (item) {
|
|
95
|
-
return _objectSpread({}, masterContentMap[item]);
|
|
96
|
-
});
|
|
97
|
-
content.push.apply(content, _toConsumableArray(deletedList));
|
|
98
|
-
} else {
|
|
99
|
-
value.forEach(function (elementId) {
|
|
100
|
-
var currentElement = currentContentMap[elementId];
|
|
101
|
-
var masterElement = masterContentMap[elementId];
|
|
102
|
-
|
|
103
|
-
// Unchanged
|
|
104
|
-
if (ObjectUtils.isSameObject(masterElement, currentElement)) {
|
|
105
|
-
content.push(currentElement);
|
|
106
|
-
|
|
107
|
-
// 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
|
|
108
|
-
} else if (ObjectUtils.isSameObject(masterElement, currentElement.oldElement)) {
|
|
109
|
-
var newElement = _objectSpread({}, currentElement);
|
|
110
|
-
newElement['oldElement'] && delete newElement['oldElement'];
|
|
111
|
-
newElement['modifyType'] && delete newElement['modifyType'];
|
|
112
|
-
content.push(newElement);
|
|
113
|
-
|
|
114
|
-
// Modify at the same time
|
|
115
|
-
} else if (currentElement.modifyType === MODIFY_TYPE.MODIFY) {
|
|
116
|
-
content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
|
|
117
|
-
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
118
|
-
origin: 'master'
|
|
119
|
-
}));
|
|
120
|
-
var _newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
|
|
121
|
-
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
122
|
-
origin: 'current'
|
|
123
|
-
});
|
|
124
|
-
_newElement['modifyType'] && delete _newElement['modifyType'];
|
|
125
|
-
_newElement['oldElement'] && delete _newElement['oldElement'];
|
|
126
|
-
content.push(_newElement);
|
|
127
|
-
canMerge = false;
|
|
128
|
-
|
|
129
|
-
// children modify
|
|
130
|
-
} else if (currentElement.modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
|
|
131
|
-
canMerge = false;
|
|
132
|
-
if (currentElement.type === masterElement.type) {
|
|
133
|
-
var _getMasterChanges = getMasterChanges(masterElement, currentElement.children),
|
|
134
|
-
childrenContent = _getMasterChanges.content;
|
|
135
|
-
content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
|
|
136
|
-
children: childrenContent,
|
|
137
|
-
rebaseType: REBASE_TYPE.CHILDREN_MODIFY
|
|
138
|
-
}));
|
|
139
|
-
} else {
|
|
140
|
-
content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
|
|
141
|
-
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
142
|
-
origin: 'master'
|
|
143
|
-
}));
|
|
144
|
-
var _newElement2 = _objectSpread(_objectSpread({}, currentElement.oldElement), {}, {
|
|
145
|
-
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
146
|
-
origin: 'current'
|
|
147
|
-
});
|
|
148
|
-
content.push(_newElement2);
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
var _newElement3 = _objectSpread({}, currentElement);
|
|
152
|
-
_newElement3['oldElement'] && delete _newElement3['oldElement'];
|
|
153
|
-
_newElement3['modifyType'] && delete _newElement3['modifyType'];
|
|
154
|
-
content.push(_newElement3);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return {
|
|
160
|
-
content: content,
|
|
161
|
-
canMerge: canMerge
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
export var getRebase = function getRebase(masterContent, revisionMasterContent, revisionCurrentContent) {
|
|
165
|
-
// master no changes, merged directly
|
|
166
|
-
if (masterContent.version === revisionMasterContent.version) {
|
|
167
|
-
return {
|
|
168
|
-
canMerge: true,
|
|
169
|
-
isNeedReplaceMaster: true,
|
|
170
|
-
value: revisionCurrentContent
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// The revision content has not changed
|
|
175
|
-
if (revisionMasterContent.version === revisionCurrentContent.version) {
|
|
176
|
-
return {
|
|
177
|
-
canMerge: true,
|
|
178
|
-
isNeedReplaceMaster: false,
|
|
179
|
-
value: masterContent
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
var revisionChanges = getRevisionChanges(revisionMasterContent, revisionCurrentContent);
|
|
183
|
-
var _getMasterChanges2 = getMasterChanges(masterContent, revisionChanges),
|
|
184
|
-
canMerge = _getMasterChanges2.canMerge,
|
|
185
|
-
content = _getMasterChanges2.content;
|
|
186
|
-
return {
|
|
187
|
-
canMerge: canMerge,
|
|
188
|
-
isNeedReplaceMaster: true,
|
|
189
|
-
value: _objectSpread(_objectSpread({}, revisionCurrentContent), {}, {
|
|
190
|
-
children: content
|
|
191
|
-
})
|
|
192
|
-
};
|
|
193
|
-
};
|
|
File without changes
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
3
|
-
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
import './index.css';
|
|
6
|
-
var TipDialog = function TipDialog(_ref) {
|
|
7
|
-
var title = _ref.title,
|
|
8
|
-
children = _ref.children,
|
|
9
|
-
className = _ref.className,
|
|
10
|
-
toggle = _ref.toggle,
|
|
11
|
-
submit = _ref.submit;
|
|
12
|
-
var _useTranslation = useTranslation(),
|
|
13
|
-
t = _useTranslation.t;
|
|
14
|
-
var closeDialog = useCallback(function () {
|
|
15
|
-
toggle && toggle(false);
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
|
-
}, []);
|
|
19
|
-
var confirmTip = useCallback(function () {
|
|
20
|
-
submit && submit();
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
|
-
}, []);
|
|
24
|
-
return /*#__PURE__*/React.createElement(Modal, {
|
|
25
|
-
isOpen: true,
|
|
26
|
-
autoFocus: false,
|
|
27
|
-
zIndex: 1071,
|
|
28
|
-
returnFocusAfterClose: false,
|
|
29
|
-
className: classnames('sdoc-tip-dialog', className),
|
|
30
|
-
contentClassName: "sdoc-tip-modal"
|
|
31
|
-
}, /*#__PURE__*/React.createElement(ModalHeader, {
|
|
32
|
-
toggle: closeDialog
|
|
33
|
-
}, title), /*#__PURE__*/React.createElement(ModalBody, {
|
|
34
|
-
className: "sdoc-tip-body"
|
|
35
|
-
}, children), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
36
|
-
color: "secondary",
|
|
37
|
-
className: "mr-2",
|
|
38
|
-
onClick: closeDialog
|
|
39
|
-
}, t('Cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
40
|
-
color: "primary",
|
|
41
|
-
className: "highlight-bg-color",
|
|
42
|
-
onClick: confirmTip
|
|
43
|
-
}, t('Confirm'))));
|
|
44
|
-
};
|
|
45
|
-
export default TipDialog;
|