@seafile/sdoc-editor 0.1.27-beta4 → 0.1.27
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/config.js +16 -0
- package/package.json +1 -2
- package/dist/assets/css/diff-viewer.css +0 -7
- package/dist/basic-sdk/utils/diff.js +0 -104
- package/dist/constants/index.js +0 -6
- package/dist/pages/diff-viewer/diff-viewer.js +0 -76
- package/dist/pages/diff-viewer/history-version-viewer.js +0 -10
- package/dist/pages/diff-viewer/index.js +0 -32
package/dist/config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var serverConfig = {
|
|
2
|
+
//serviceUrl: "http://127.0.0.1:8000",
|
|
3
|
+
serviceUrl: "http://192.168.1.100:8000",
|
|
4
|
+
username: "lj@11.com",
|
|
5
|
+
password: "11",
|
|
6
|
+
repoID: "79d1fa93-4b5f-4d6c-8fb5-ad3958e1fa47",
|
|
7
|
+
userInfo: {
|
|
8
|
+
username: 'lj@11.com',
|
|
9
|
+
name: 'lj-',
|
|
10
|
+
contact_email: 'lj@11.com'
|
|
11
|
+
},
|
|
12
|
+
filePath: '/xxx.md',
|
|
13
|
+
fileName: 'xxx.md',
|
|
14
|
+
dirPath: '/'
|
|
15
|
+
};
|
|
16
|
+
export { serverConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This is a sdoc editor",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"is-url": "^1.2.4",
|
|
17
17
|
"react-cookies": "0.1.1",
|
|
18
18
|
"reactstrap": "8.9.0",
|
|
19
|
-
"shallowequal": "^1.1.0",
|
|
20
19
|
"slugid": "3.2.0",
|
|
21
20
|
"socket.io-client": "4.6.1",
|
|
22
21
|
"url-parse": "1.5.10",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import shallowEqual from 'shallowequal';
|
|
3
|
-
import { DIFF_TYPE } from '../../constants';
|
|
4
|
-
var getElementIndexInDiffDocument = function getElementIndexInDiffDocument(diffDocument, elementId) {
|
|
5
|
-
return diffDocument.findIndex(function (element) {
|
|
6
|
-
return element.id === elementId;
|
|
7
|
-
});
|
|
8
|
-
};
|
|
9
|
-
var getNearestElementIndex = function getNearestElementIndex(diffDocument, oldDocument, elementId) {
|
|
10
|
-
var elementInDiffDocument = getElementIndexInDiffDocument(diffDocument, elementId);
|
|
11
|
-
if (elementInDiffDocument > -1) {
|
|
12
|
-
return elementInDiffDocument;
|
|
13
|
-
}
|
|
14
|
-
var oldDocumentIds = oldDocument.map(function (item) {
|
|
15
|
-
return typeof item === 'string' ? item : item.id;
|
|
16
|
-
});
|
|
17
|
-
var oldElementCount = oldDocumentIds.length;
|
|
18
|
-
var elementInOldDocumentIndex = oldDocumentIds.indexOf(elementId);
|
|
19
|
-
var leftIndex = elementInOldDocumentIndex - 1;
|
|
20
|
-
leftIndex = leftIndex === -1 ? 0 : leftIndex;
|
|
21
|
-
var rightIndex = elementInOldDocumentIndex + 1;
|
|
22
|
-
rightIndex = rightIndex === oldElementCount - 1 ? oldElementCount - 1 : rightIndex;
|
|
23
|
-
while (elementInDiffDocument === -1 && leftIndex > -1 && rightIndex < oldElementCount) {
|
|
24
|
-
var oldLeftElementId = oldDocumentIds[leftIndex];
|
|
25
|
-
elementInDiffDocument = getElementIndexInDiffDocument(diffDocument, oldLeftElementId);
|
|
26
|
-
if (elementInDiffDocument > -1) {
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
var oldLastElementId = oldDocumentIds[rightIndex];
|
|
30
|
-
elementInDiffDocument = getElementIndexInDiffDocument(diffDocument, oldLastElementId);
|
|
31
|
-
if (elementInDiffDocument > -1) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
leftIndex--;
|
|
35
|
-
rightIndex++;
|
|
36
|
-
}
|
|
37
|
-
if (elementInDiffDocument === -1) return diffDocument.length - 1;
|
|
38
|
-
return elementInDiffDocument;
|
|
39
|
-
};
|
|
40
|
-
export var getDiffValue = function getDiffValue(currentValue, oldValue) {
|
|
41
|
-
var currentVersion = currentValue.version,
|
|
42
|
-
currentChildren = currentValue.children;
|
|
43
|
-
var oldVersion = oldValue.version,
|
|
44
|
-
oldChildren = oldValue.children;
|
|
45
|
-
if (currentVersion === oldVersion) return currentChildren;
|
|
46
|
-
var diffDocument = [];
|
|
47
|
-
|
|
48
|
-
// init
|
|
49
|
-
var currentChildrenMap = {};
|
|
50
|
-
var oldChildrenMap = {};
|
|
51
|
-
var currentChildrenIds = [];
|
|
52
|
-
var oldChildrenIds = [];
|
|
53
|
-
currentChildren.forEach(function (element) {
|
|
54
|
-
currentChildrenMap[element.id] = element;
|
|
55
|
-
currentChildrenIds.push(element.id);
|
|
56
|
-
});
|
|
57
|
-
oldChildren.forEach(function (element) {
|
|
58
|
-
oldChildrenMap[element.id] = element;
|
|
59
|
-
oldChildrenIds.push(element.id);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// element ids
|
|
63
|
-
var addedChildrenIds = currentChildrenIds.filter(function (item) {
|
|
64
|
-
return !oldChildrenIds.includes(item);
|
|
65
|
-
}); // 增加的
|
|
66
|
-
var deletedChildrenIds = oldChildrenIds.filter(function (item) {
|
|
67
|
-
return !currentChildrenIds.includes(item);
|
|
68
|
-
}); // 删除的
|
|
69
|
-
|
|
70
|
-
// generator diff elements
|
|
71
|
-
for (var i = 0; i < currentChildren.length; i++) {
|
|
72
|
-
var element = currentChildren[i];
|
|
73
|
-
var isAdded = addedChildrenIds.includes(element.id);
|
|
74
|
-
if (isAdded) {
|
|
75
|
-
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
76
|
-
diff_type: DIFF_TYPE.ADD
|
|
77
|
-
}));
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
var oldElement = oldChildrenMap[element.id];
|
|
81
|
-
if (shallowEqual(oldElement, element)) {
|
|
82
|
-
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
83
|
-
diff_type: DIFF_TYPE.COMMON
|
|
84
|
-
}));
|
|
85
|
-
} else {
|
|
86
|
-
// 深度比较: 需要修改编辑器,暂时不做
|
|
87
|
-
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
88
|
-
diff_type: DIFF_TYPE.ADD
|
|
89
|
-
}));
|
|
90
|
-
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
91
|
-
diff_type: DIFF_TYPE.DELETE
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
for (var _i = 0; _i < deletedChildrenIds.length; _i++) {
|
|
96
|
-
var deletedElementId = deletedChildrenIds[_i];
|
|
97
|
-
var deletedElement = oldChildrenMap[deletedElementId];
|
|
98
|
-
var elementIndex = getNearestElementIndex(diffDocument, oldChildrenIds, deletedElementId);
|
|
99
|
-
diffDocument.splice(elementIndex, 0, _objectSpread(_objectSpread({}, deletedElement), {}, {
|
|
100
|
-
diff_type: DIFF_TYPE.DELETE
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
return diffDocument;
|
|
104
|
-
};
|
package/dist/constants/index.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
-
import React, { Component } from 'react';
|
|
6
|
-
import { Editable, Slate } from '@seafile/slate-react';
|
|
7
|
-
import editor, { renderLeaf, renderElement } from '../../basic-sdk/extension';
|
|
8
|
-
import withNodeId from '../../basic-sdk/node-id';
|
|
9
|
-
import { getDiffValue } from '../../basic-sdk/utils/diff';
|
|
10
|
-
import { DIFF_TYPE } from '../../constants';
|
|
11
|
-
import '../../assets/css/diff-viewer.css';
|
|
12
|
-
var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
13
|
-
_inherits(DiffViewer, _Component);
|
|
14
|
-
var _super = _createSuper(DiffViewer);
|
|
15
|
-
function DiffViewer(_props) {
|
|
16
|
-
var _this;
|
|
17
|
-
_classCallCheck(this, DiffViewer);
|
|
18
|
-
_this = _super.call(this, _props);
|
|
19
|
-
_this.renderLeaf = function (props) {
|
|
20
|
-
return renderLeaf(props, _this.editor);
|
|
21
|
-
};
|
|
22
|
-
_this.renderElement = function (props) {
|
|
23
|
-
var element = props.element;
|
|
24
|
-
var diff_type = element.diff_type;
|
|
25
|
-
if (diff_type === DIFF_TYPE.ADD) {
|
|
26
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
27
|
-
className: "sdoc-diff-added"
|
|
28
|
-
}, renderElement(props, _this.editor));
|
|
29
|
-
}
|
|
30
|
-
if (diff_type === DIFF_TYPE.DELETE) {
|
|
31
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
-
className: "sdoc-diff-removed"
|
|
33
|
-
}, renderElement(props, _this.editor));
|
|
34
|
-
}
|
|
35
|
-
if (diff_type === DIFF_TYPE.MODIFY) {
|
|
36
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
37
|
-
className: "sdoc-diff-modify"
|
|
38
|
-
}, renderElement(props, _this.editor));
|
|
39
|
-
}
|
|
40
|
-
return renderElement(props, _this.editor);
|
|
41
|
-
};
|
|
42
|
-
_this.editor = withNodeId(editor);
|
|
43
|
-
return _this;
|
|
44
|
-
}
|
|
45
|
-
_createClass(DiffViewer, [{
|
|
46
|
-
key: "render",
|
|
47
|
-
value: function render() {
|
|
48
|
-
var _this$props = this.props,
|
|
49
|
-
currentContent = _this$props.currentContent,
|
|
50
|
-
lastContent = _this$props.lastContent;
|
|
51
|
-
var value = getDiffValue(currentContent, lastContent);
|
|
52
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
53
|
-
className: "sdoc-editor-container"
|
|
54
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
55
|
-
className: "sdoc-editor-content"
|
|
56
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
57
|
-
className: "flex-fill o-auto"
|
|
58
|
-
}, /*#__PURE__*/React.createElement(Slate, {
|
|
59
|
-
editor: this.editor,
|
|
60
|
-
value: value,
|
|
61
|
-
onChange: function onChange() {}
|
|
62
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
63
|
-
className: "article mx-auto"
|
|
64
|
-
}, /*#__PURE__*/React.createElement(Editable, {
|
|
65
|
-
readOnly: true,
|
|
66
|
-
placeholder: "",
|
|
67
|
-
renderElement: this.renderElement,
|
|
68
|
-
renderLeaf: this.renderLeaf,
|
|
69
|
-
onDOMBeforeInput: function onDOMBeforeInput() {},
|
|
70
|
-
onKeyDown: function onKeyDown() {}
|
|
71
|
-
}))))));
|
|
72
|
-
}
|
|
73
|
-
}]);
|
|
74
|
-
return DiffViewer;
|
|
75
|
-
}(Component);
|
|
76
|
-
export default DiffViewer;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { SDocViewer } from '../../basic-sdk';
|
|
3
|
-
import { generateDefaultDocContent } from '../../utils';
|
|
4
|
-
function HistoryVersionViewer(props) {
|
|
5
|
-
var document = props.document;
|
|
6
|
-
return /*#__PURE__*/React.createElement(SDocViewer, {
|
|
7
|
-
document: document || generateDefaultDocContent()
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export default HistoryVersionViewer;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
-
import React, { Component } from 'react';
|
|
6
|
-
import HistoryVersionViewer from './history-version-viewer';
|
|
7
|
-
import DiffViewer from './diff-viewer';
|
|
8
|
-
var Index = /*#__PURE__*/function (_Component) {
|
|
9
|
-
_inherits(Index, _Component);
|
|
10
|
-
var _super = _createSuper(Index);
|
|
11
|
-
function Index() {
|
|
12
|
-
_classCallCheck(this, Index);
|
|
13
|
-
return _super.apply(this, arguments);
|
|
14
|
-
}
|
|
15
|
-
_createClass(Index, [{
|
|
16
|
-
key: "render",
|
|
17
|
-
value: function render() {
|
|
18
|
-
var _this$props = this.props,
|
|
19
|
-
currentContent = _this$props.currentContent,
|
|
20
|
-
lastContent = _this$props.lastContent;
|
|
21
|
-
if (!currentContent) return null;
|
|
22
|
-
if (!lastContent) {
|
|
23
|
-
return /*#__PURE__*/React.createElement(HistoryVersionViewer, {
|
|
24
|
-
document: currentContent
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return /*#__PURE__*/React.createElement(DiffViewer, this.props);
|
|
28
|
-
}
|
|
29
|
-
}]);
|
|
30
|
-
return Index;
|
|
31
|
-
}(Component);
|
|
32
|
-
export default Index;
|