@seafile/sdoc-editor 0.1.28-beta3 → 0.1.28-beta4
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,4 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
// import shallowEqual from 'shallowequal';
|
|
3
2
|
import { DIFF_TYPE, ELEMENT_TYPE } from '../../basic-sdk/extension/constants';
|
|
4
3
|
import ObjectUtils from './object-utils';
|
|
5
4
|
var getElementIndexInDiffDocument = function getElementIndexInDiffDocument(diffDocument, element) {
|
|
@@ -37,7 +36,7 @@ var getNearestElementIndex = function getNearestElementIndex(diffDocument, oldDo
|
|
|
37
36
|
if (elementInDiffDocument === -1) return diffDocument.length - 1;
|
|
38
37
|
return elementInDiffDocument;
|
|
39
38
|
};
|
|
40
|
-
var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldElement) {
|
|
39
|
+
var updateDiffDocument = function updateDiffDocument(diffDocument, count, element, oldElement) {
|
|
41
40
|
if (!diffDocument || !element || !oldElement) return;
|
|
42
41
|
if (ObjectUtils.isSameObject(element, oldElement)) {
|
|
43
42
|
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
@@ -48,6 +47,7 @@ var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldE
|
|
|
48
47
|
var currentElementType = element.type;
|
|
49
48
|
var oldElementType = oldElement.type;
|
|
50
49
|
if (currentElementType !== oldElementType) {
|
|
50
|
+
count++;
|
|
51
51
|
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
52
52
|
diff_type: DIFF_TYPE.DELETE
|
|
53
53
|
}));
|
|
@@ -70,6 +70,7 @@ var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldE
|
|
|
70
70
|
case ELEMENT_TYPE.CODE_BLOCK:
|
|
71
71
|
case ELEMENT_TYPE.IMAGE:
|
|
72
72
|
{
|
|
73
|
+
count++;
|
|
73
74
|
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
74
75
|
diff_type: DIFF_TYPE.DELETE
|
|
75
76
|
}));
|
|
@@ -83,15 +84,19 @@ var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldE
|
|
|
83
84
|
case ELEMENT_TYPE.LIST_ITEM:
|
|
84
85
|
case ELEMENT_TYPE.LIST_LIC:
|
|
85
86
|
{
|
|
86
|
-
var
|
|
87
|
+
var _getElementDiffValue = getElementDiffValue(element.children, oldElement.children),
|
|
88
|
+
diffValue = _getElementDiffValue.value,
|
|
89
|
+
diffCount = _getElementDiffValue.count;
|
|
90
|
+
count += diffCount;
|
|
87
91
|
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
88
|
-
children:
|
|
92
|
+
children: diffValue,
|
|
89
93
|
diff_type: DIFF_TYPE.MODIFY
|
|
90
94
|
}));
|
|
91
95
|
break;
|
|
92
96
|
}
|
|
93
97
|
default:
|
|
94
98
|
{
|
|
99
|
+
count++;
|
|
95
100
|
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
96
101
|
diff_type: DIFF_TYPE.DELETE
|
|
97
102
|
}));
|
|
@@ -105,6 +110,7 @@ var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldE
|
|
|
105
110
|
var getElementDiffValue = function getElementDiffValue(currentChildren, oldChildren) {
|
|
106
111
|
// init
|
|
107
112
|
var diffDocument = [];
|
|
113
|
+
var count = 0;
|
|
108
114
|
var currentChildrenMap = {};
|
|
109
115
|
var oldChildrenMap = {};
|
|
110
116
|
currentChildren.forEach(function (element) {
|
|
@@ -117,31 +123,39 @@ var getElementDiffValue = function getElementDiffValue(currentChildren, oldChild
|
|
|
117
123
|
// generator diff elements
|
|
118
124
|
for (var i = 0; i < currentChildren.length; i++) {
|
|
119
125
|
var element = currentChildren[i];
|
|
120
|
-
var isAdded = !oldChildrenMap[element.id]; //
|
|
126
|
+
var isAdded = !oldChildrenMap[element.id]; // added
|
|
121
127
|
if (isAdded) {
|
|
128
|
+
count++;
|
|
122
129
|
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
123
130
|
diff_type: DIFF_TYPE.ADD
|
|
124
131
|
}));
|
|
125
132
|
continue;
|
|
126
133
|
}
|
|
127
|
-
updateDiffDocument(diffDocument, element, oldChildrenMap[element.id]);
|
|
134
|
+
updateDiffDocument(diffDocument, count, element, oldChildrenMap[element.id]);
|
|
128
135
|
}
|
|
129
136
|
oldChildren.forEach(function (oldElement) {
|
|
130
137
|
if (!currentChildrenMap[oldElement.id]) {
|
|
131
|
-
//
|
|
138
|
+
// deleted
|
|
139
|
+
count++;
|
|
132
140
|
var elementIndex = getNearestElementIndex(diffDocument, oldChildren, oldElement.id);
|
|
133
141
|
diffDocument.splice(elementIndex, 0, _objectSpread(_objectSpread({}, oldElement), {}, {
|
|
134
142
|
diff_type: DIFF_TYPE.DELETE
|
|
135
143
|
}));
|
|
136
144
|
}
|
|
137
145
|
});
|
|
138
|
-
return
|
|
146
|
+
return {
|
|
147
|
+
value: diffDocument,
|
|
148
|
+
count: count
|
|
149
|
+
};
|
|
139
150
|
};
|
|
140
|
-
export var
|
|
151
|
+
export var getDiff = function getDiff(currentValue, oldValue) {
|
|
141
152
|
var currentVersion = currentValue.version,
|
|
142
153
|
currentChildren = currentValue.children;
|
|
143
154
|
var oldVersion = oldValue.version,
|
|
144
155
|
oldChildren = oldValue.children;
|
|
145
|
-
if (currentVersion === oldVersion) return
|
|
156
|
+
if (currentVersion === oldVersion) return {
|
|
157
|
+
value: currentChildren,
|
|
158
|
+
count: 0
|
|
159
|
+
};
|
|
146
160
|
return getElementDiffValue(currentChildren, oldChildren);
|
|
147
161
|
};
|
|
@@ -7,7 +7,7 @@ import React, { Component } from 'react';
|
|
|
7
7
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
8
8
|
import editor, { renderLeaf, renderElement } from '../../basic-sdk/extension';
|
|
9
9
|
import withNodeId from '../../basic-sdk/node-id';
|
|
10
|
-
import {
|
|
10
|
+
import { getDiff } from '../../basic-sdk/utils/diff';
|
|
11
11
|
import { DIFF_TYPE, ELEMENT_TYPE } from '../../basic-sdk/extension/constants';
|
|
12
12
|
import '../../assets/css/diff-viewer.css';
|
|
13
13
|
var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
@@ -65,7 +65,7 @@ var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
|
65
65
|
}), _this.editor);
|
|
66
66
|
}
|
|
67
67
|
return /*#__PURE__*/React.createElement("div", {
|
|
68
|
-
className: "sdoc-diff
|
|
68
|
+
className: "sdoc-diff-modify"
|
|
69
69
|
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
70
70
|
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
71
71
|
className: 'sdoc-diff-modify'
|
|
@@ -74,16 +74,27 @@ var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
|
74
74
|
}
|
|
75
75
|
return renderElement(props, _this.editor);
|
|
76
76
|
};
|
|
77
|
+
var currentContent = _props.currentContent,
|
|
78
|
+
lastContent = _props.lastContent;
|
|
79
|
+
var _getDiff = getDiff(currentContent, lastContent),
|
|
80
|
+
value = _getDiff.value,
|
|
81
|
+
count = _getDiff.count;
|
|
77
82
|
_this.editor = withNodeId(editor);
|
|
83
|
+
_this.value = value;
|
|
84
|
+
_this.count = count;
|
|
78
85
|
return _this;
|
|
79
86
|
}
|
|
80
87
|
_createClass(DiffViewer, [{
|
|
88
|
+
key: "componentDidMount",
|
|
89
|
+
value: function componentDidMount() {
|
|
90
|
+
this.props.didMountCallback && this.props.didMountCallback({
|
|
91
|
+
value: this.value,
|
|
92
|
+
count: this.count
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
81
96
|
key: "render",
|
|
82
97
|
value: function render() {
|
|
83
|
-
var _this$props = this.props,
|
|
84
|
-
currentContent = _this$props.currentContent,
|
|
85
|
-
lastContent = _this$props.lastContent;
|
|
86
|
-
var value = getDiffValue(currentContent, lastContent);
|
|
87
98
|
return /*#__PURE__*/React.createElement("div", {
|
|
88
99
|
className: "sdoc-editor-container"
|
|
89
100
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -92,7 +103,7 @@ var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
|
92
103
|
className: "flex-fill o-auto"
|
|
93
104
|
}, /*#__PURE__*/React.createElement(Slate, {
|
|
94
105
|
editor: this.editor,
|
|
95
|
-
value: value,
|
|
106
|
+
value: this.value,
|
|
96
107
|
onChange: function onChange() {}
|
|
97
108
|
}, /*#__PURE__*/React.createElement("div", {
|
|
98
109
|
className: "article mx-auto"
|