@seafile/sdoc-editor 0.1.28-beta → 0.1.28-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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import shallowEqual from 'shallowequal';
|
|
2
|
+
// import shallowEqual from 'shallowequal';
|
|
3
3
|
import { DIFF_TYPE, ELEMENT_TYPE } from '../../basic-sdk/extension/constants';
|
|
4
4
|
import ObjectUtils from './object-utils';
|
|
5
5
|
var getElementIndexInDiffDocument = function getElementIndexInDiffDocument(diffDocument, element) {
|
|
@@ -40,24 +40,13 @@ var getNearestElementIndex = function getNearestElementIndex(diffDocument, oldDo
|
|
|
40
40
|
var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldElement) {
|
|
41
41
|
if (!diffDocument || !element || !oldElement) return;
|
|
42
42
|
if (ObjectUtils.isSameObject(element, oldElement)) {
|
|
43
|
-
diffDocument.push(_objectSpread(_objectSpread({},
|
|
43
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
44
44
|
diff_type: DIFF_TYPE.COMMON
|
|
45
45
|
}));
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}));
|
|
51
|
-
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
52
|
-
diff_type: DIFF_TYPE.ADD
|
|
53
|
-
}));
|
|
54
|
-
return;
|
|
55
|
-
var currentElementId = element.id,
|
|
56
|
-
currentElementType = element.type,
|
|
57
|
-
currentElementChildren = element.children;
|
|
58
|
-
var oldElementId = oldElement.id,
|
|
59
|
-
oldElementType = oldElement.type,
|
|
60
|
-
oldElementChildren = oldElement.children;
|
|
48
|
+
var currentElementType = element.type;
|
|
49
|
+
var oldElementType = oldElement.type;
|
|
61
50
|
if (currentElementType !== oldElementType) {
|
|
62
51
|
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
63
52
|
diff_type: DIFF_TYPE.DELETE
|
|
@@ -67,39 +56,55 @@ var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldE
|
|
|
67
56
|
}));
|
|
68
57
|
return;
|
|
69
58
|
}
|
|
70
|
-
|
|
71
|
-
// if (shallowEqual(oldElement, element)) {
|
|
72
|
-
// diffDocument.push({ ...element, diff_type: DIFF_TYPE.COMMON });
|
|
73
|
-
// } else {
|
|
74
|
-
// // 深度比较: 需要修改编辑器,暂时不做
|
|
75
|
-
// diffDocument.push({ ...oldElement, diff_type: DIFF_TYPE.DELETE });
|
|
76
|
-
// diffDocument.push({ ...element, diff_type: DIFF_TYPE.ADD });
|
|
77
|
-
// }
|
|
78
|
-
|
|
79
59
|
switch (currentElementType) {
|
|
80
|
-
|
|
60
|
+
case ELEMENT_TYPE.PARAGRAPH:
|
|
61
|
+
case ELEMENT_TYPE.HEADER1:
|
|
62
|
+
case ELEMENT_TYPE.HEADER2:
|
|
63
|
+
case ELEMENT_TYPE.HEADER3:
|
|
64
|
+
case ELEMENT_TYPE.HEADER4:
|
|
65
|
+
case ELEMENT_TYPE.HEADER5:
|
|
66
|
+
case ELEMENT_TYPE.HEADER6:
|
|
81
67
|
case ELEMENT_TYPE.BLOCKQUOTE:
|
|
68
|
+
case ELEMENT_TYPE.LINK:
|
|
69
|
+
case ELEMENT_TYPE.CHECK_LIST_ITEM:
|
|
70
|
+
case ELEMENT_TYPE.CODE_BLOCK:
|
|
71
|
+
case ELEMENT_TYPE.IMAGE:
|
|
72
|
+
{
|
|
73
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
74
|
+
diff_type: DIFF_TYPE.DELETE
|
|
75
|
+
}));
|
|
76
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
77
|
+
diff_type: DIFF_TYPE.ADD
|
|
78
|
+
}));
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case ELEMENT_TYPE.ORDERED_LIST:
|
|
82
|
+
case ELEMENT_TYPE.UNORDERED_LIST:
|
|
83
|
+
case ELEMENT_TYPE.LIST_ITEM:
|
|
84
|
+
case ELEMENT_TYPE.LIST_LIC:
|
|
82
85
|
{
|
|
83
|
-
|
|
86
|
+
var orderDiff = getElementDiffValue(element.children, oldElement.children);
|
|
87
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
88
|
+
children: orderDiff,
|
|
89
|
+
diff_type: DIFF_TYPE.MODIFY
|
|
90
|
+
}));
|
|
84
91
|
break;
|
|
85
92
|
}
|
|
86
93
|
default:
|
|
87
94
|
{
|
|
95
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
96
|
+
diff_type: DIFF_TYPE.DELETE
|
|
97
|
+
}));
|
|
98
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
99
|
+
diff_type: DIFF_TYPE.ADD
|
|
100
|
+
}));
|
|
88
101
|
break;
|
|
89
102
|
}
|
|
90
103
|
}
|
|
91
104
|
};
|
|
92
|
-
|
|
93
|
-
var currentVersion = currentValue.version,
|
|
94
|
-
currentChildren = currentValue.children;
|
|
95
|
-
var oldVersion = oldValue.version,
|
|
96
|
-
oldChildren = oldValue.children;
|
|
97
|
-
if (currentVersion === oldVersion) return currentChildren;
|
|
98
|
-
var diffDocument = [];
|
|
99
|
-
console.log('currentChildren: ', currentChildren);
|
|
100
|
-
console.log('oldChildren: ', oldChildren);
|
|
101
|
-
|
|
105
|
+
var getElementDiffValue = function getElementDiffValue(currentChildren, oldChildren) {
|
|
102
106
|
// init
|
|
107
|
+
var diffDocument = [];
|
|
103
108
|
var currentChildrenMap = {};
|
|
104
109
|
var oldChildrenMap = {};
|
|
105
110
|
currentChildren.forEach(function (element) {
|
|
@@ -131,4 +136,12 @@ export var getDiffValue = function getDiffValue(currentValue, oldValue) {
|
|
|
131
136
|
}
|
|
132
137
|
});
|
|
133
138
|
return diffDocument;
|
|
139
|
+
};
|
|
140
|
+
export var getDiffValue = function getDiffValue(currentValue, oldValue) {
|
|
141
|
+
var currentVersion = currentValue.version,
|
|
142
|
+
currentChildren = currentValue.children;
|
|
143
|
+
var oldVersion = oldValue.version,
|
|
144
|
+
oldChildren = oldValue.children;
|
|
145
|
+
if (currentVersion === oldVersion) return currentChildren;
|
|
146
|
+
return getElementDiffValue(currentChildren, oldChildren);
|
|
134
147
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
4
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
@@ -25,17 +26,29 @@ var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
|
25
26
|
if (diff_type === DIFF_TYPE.ADD) {
|
|
26
27
|
return /*#__PURE__*/React.createElement("div", {
|
|
27
28
|
className: "sdoc-diff-added"
|
|
28
|
-
}, renderElement(props,
|
|
29
|
+
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
30
|
+
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
31
|
+
className: 'sdoc-diff-added'
|
|
32
|
+
})
|
|
33
|
+
}), _this.editor));
|
|
29
34
|
}
|
|
30
35
|
if (diff_type === DIFF_TYPE.DELETE) {
|
|
31
36
|
return /*#__PURE__*/React.createElement("div", {
|
|
32
37
|
className: "sdoc-diff-removed"
|
|
33
|
-
}, renderElement(props,
|
|
38
|
+
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
39
|
+
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
40
|
+
className: 'sdoc-diff-removed'
|
|
41
|
+
})
|
|
42
|
+
}), _this.editor));
|
|
34
43
|
}
|
|
35
44
|
if (diff_type === DIFF_TYPE.MODIFY) {
|
|
36
45
|
return /*#__PURE__*/React.createElement("div", {
|
|
37
46
|
className: "sdoc-diff-modify"
|
|
38
|
-
}, renderElement(props,
|
|
47
|
+
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
48
|
+
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
49
|
+
className: 'sdoc-diff-modify'
|
|
50
|
+
})
|
|
51
|
+
}), _this.editor));
|
|
39
52
|
}
|
|
40
53
|
return renderElement(props, _this.editor);
|
|
41
54
|
};
|