@seafile/sdoc-editor 0.1.27 → 0.1.28-beta1
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/assets/css/diff-viewer.css +13 -0
- package/dist/basic-sdk/assets/css/layout.css +0 -5
- package/dist/basic-sdk/assets/css/sdoc-editor-plugins.css +61 -0
- package/dist/basic-sdk/extension/constants/element-type.js +29 -0
- package/dist/basic-sdk/extension/constants/index.js +15 -31
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +1 -0
- package/dist/basic-sdk/extension/plugins/image/dialogs/image-previewer.js +95 -0
- package/dist/basic-sdk/extension/plugins/image/dialogs/insert-web-image-dialog.js +69 -0
- package/dist/basic-sdk/extension/plugins/image/helpers.js +54 -0
- package/dist/basic-sdk/extension/plugins/image/index.js +14 -0
- package/dist/basic-sdk/extension/plugins/image/menu/index.js +150 -0
- package/dist/basic-sdk/extension/plugins/image/menu/style.css +43 -0
- package/dist/basic-sdk/extension/plugins/image/model.js +14 -0
- package/dist/basic-sdk/extension/plugins/image/plugin.js +37 -0
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +146 -0
- package/dist/basic-sdk/extension/plugins/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +2 -2
- package/dist/basic-sdk/extension/render/render-element.js +8 -2
- package/dist/basic-sdk/extension/toolbar/index.js +5 -3
- package/dist/basic-sdk/utils/diff.js +210 -0
- package/dist/basic-sdk/utils/object-utils.js +54 -0
- package/dist/context.js +29 -1
- package/dist/pages/diff-viewer/diff-viewer.js +89 -0
- package/dist/pages/diff-viewer/history-version-viewer.js +10 -0
- package/dist/pages/diff-viewer/index.js +32 -0
- package/dist/utils/index.js +4 -0
- package/package.json +1 -1
- package/dist/config.js +0 -16
- /package/dist/basic-sdk/{assets/css/sdoc-editor-toolbar.css → extension/plugins/header/menu/style.css} +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
+
import { useSelected } from '@seafile/slate-react';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { updateImage } from './helpers';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import { withTranslation } from 'react-i18next';
|
|
11
|
+
import ImagePreviewer from './dialogs/image-previewer';
|
|
12
|
+
var Image = /*#__PURE__*/function (_React$Component) {
|
|
13
|
+
_inherits(Image, _React$Component);
|
|
14
|
+
var _super = _createSuper(Image);
|
|
15
|
+
function Image(props) {
|
|
16
|
+
var _this;
|
|
17
|
+
_classCallCheck(this, Image);
|
|
18
|
+
_this = _super.call(this, props);
|
|
19
|
+
_this.registerEvent = function () {
|
|
20
|
+
document.addEventListener('mousemove', _this.onMouseMove);
|
|
21
|
+
document.addEventListener('mouseup', _this.onResizeEnd);
|
|
22
|
+
};
|
|
23
|
+
_this.unregisterEvent = function () {
|
|
24
|
+
document.removeEventListener('mousemove', _this.onMouseMove);
|
|
25
|
+
document.removeEventListener('mouseup', _this.onResizeEnd);
|
|
26
|
+
};
|
|
27
|
+
_this.onResizeStart = function (event) {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
// event.stopPropagation();
|
|
30
|
+
_this.setState({
|
|
31
|
+
isResizing: true
|
|
32
|
+
}, function () {
|
|
33
|
+
_this.registerEvent();
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
_this.onMouseMove = function (event) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
event.stopPropagation();
|
|
39
|
+
var changeX = event.clientX - _this.resizer.getBoundingClientRect().left - 5;
|
|
40
|
+
var imageWidth = _this.image.width + changeX;
|
|
41
|
+
if (imageWidth < 20) return;
|
|
42
|
+
_this.setState({
|
|
43
|
+
width: imageWidth
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
_this.onResizeEnd = function (event) {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
_this.unregisterEvent();
|
|
50
|
+
var width = _this.state.width;
|
|
51
|
+
var _this$props = _this.props,
|
|
52
|
+
editor = _this$props.editor,
|
|
53
|
+
element = _this$props.element;
|
|
54
|
+
var newData = _objectSpread(_objectSpread({}, element.data), {}, {
|
|
55
|
+
width: width
|
|
56
|
+
});
|
|
57
|
+
updateImage(editor, newData);
|
|
58
|
+
_this.setState({
|
|
59
|
+
isResizing: false
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
_this.getImageStyle = function () {
|
|
63
|
+
var element = _this.props.element;
|
|
64
|
+
var width = _this.state.width;
|
|
65
|
+
var imageWidth = element.data.width || '';
|
|
66
|
+
if (width) imageWidth = width;
|
|
67
|
+
return {
|
|
68
|
+
width: imageWidth
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
_this.setFullScreen = function () {
|
|
72
|
+
_this.setState({
|
|
73
|
+
isShowImagePreview: !_this.state.isShowImagePreview
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
_this.setImageRef = function (ref) {
|
|
77
|
+
_this.image = ref;
|
|
78
|
+
};
|
|
79
|
+
_this.setResizerRef = function (ref) {
|
|
80
|
+
_this.resizer = ref;
|
|
81
|
+
};
|
|
82
|
+
_this.state = {
|
|
83
|
+
width: null,
|
|
84
|
+
isResizing: false,
|
|
85
|
+
isShowImagePreview: false
|
|
86
|
+
};
|
|
87
|
+
return _this;
|
|
88
|
+
}
|
|
89
|
+
_createClass(Image, [{
|
|
90
|
+
key: "render",
|
|
91
|
+
value: function render() {
|
|
92
|
+
var _this$props2 = this.props,
|
|
93
|
+
className = _this$props2.className,
|
|
94
|
+
attributes = _this$props2.attributes,
|
|
95
|
+
element = _this$props2.element,
|
|
96
|
+
children = _this$props2.children,
|
|
97
|
+
isSelected = _this$props2.isSelected,
|
|
98
|
+
t = _this$props2.t;
|
|
99
|
+
var _this$state = this.state,
|
|
100
|
+
isResizing = _this$state.isResizing,
|
|
101
|
+
isShowImagePreview = _this$state.isShowImagePreview;
|
|
102
|
+
var data = element.data;
|
|
103
|
+
var imageClassName = isSelected ? 'image-selected' : '';
|
|
104
|
+
var imageStyle = this.getImageStyle();
|
|
105
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", Object.assign({
|
|
106
|
+
className: classNames('sdoc-image', className)
|
|
107
|
+
}, attributes), /*#__PURE__*/React.createElement("img", {
|
|
108
|
+
className: imageClassName,
|
|
109
|
+
ref: this.setImageRef,
|
|
110
|
+
src: data.src,
|
|
111
|
+
style: imageStyle,
|
|
112
|
+
draggable: false,
|
|
113
|
+
alt: ""
|
|
114
|
+
}), isSelected && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
|
|
115
|
+
className: "image-resizer",
|
|
116
|
+
ref: this.setResizerRef,
|
|
117
|
+
onMouseDown: this.onResizeStart
|
|
118
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
119
|
+
className: "image-full-screen",
|
|
120
|
+
contentEditable: false,
|
|
121
|
+
onClick: this.setFullScreen
|
|
122
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
123
|
+
className: 'iconfont icon-fullscreen',
|
|
124
|
+
title: t('Full_screen')
|
|
125
|
+
}))), isResizing && /*#__PURE__*/React.createElement("span", {
|
|
126
|
+
className: "image-size",
|
|
127
|
+
contentEditable: false
|
|
128
|
+
}, /*#__PURE__*/React.createElement("span", null, t('width'), ':', parseInt(this.state.width || this.image.clientWidth)), /*#__PURE__*/React.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/React.createElement("span", null, t('height'), ':', this.image.clientHeight)), children), isShowImagePreview && /*#__PURE__*/React.createElement(ImagePreviewer, {
|
|
129
|
+
imageUrl: data.src,
|
|
130
|
+
editor: this.props.editor,
|
|
131
|
+
toggleImagePreviewer: this.setFullScreen
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
}]);
|
|
135
|
+
return Image;
|
|
136
|
+
}(React.Component);
|
|
137
|
+
var SdocImage = withTranslation('sdoc-editor')(Image);
|
|
138
|
+
function renderImage(props, editor) {
|
|
139
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
140
|
+
var isSelected = useSelected();
|
|
141
|
+
return /*#__PURE__*/React.createElement(SdocImage, Object.assign({}, props, {
|
|
142
|
+
editor: editor,
|
|
143
|
+
isSelected: isSelected
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
export default renderImage;
|
|
@@ -6,6 +6,7 @@ import ListPlugin from './list';
|
|
|
6
6
|
import CheckListPlugin from './check-list';
|
|
7
7
|
import TextPlugin from './text-style';
|
|
8
8
|
import CodeBlockPlugin from './code-block';
|
|
9
|
-
|
|
9
|
+
import ImagePlugin from './image';
|
|
10
|
+
var Plugins = [MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, CodeBlockPlugin, ImagePlugin];
|
|
10
11
|
export default Plugins;
|
|
11
|
-
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, CodeBlockPlugin };
|
|
12
|
+
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, CodeBlockPlugin, ImagePlugin };
|
|
@@ -4,7 +4,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
4
4
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
5
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
6
|
import React from 'react';
|
|
7
|
-
import {
|
|
7
|
+
import { TEXT_STYLE, MENUS_CONFIG_MAP } from '../../../constants';
|
|
8
8
|
import { focusEditor } from '../../../core';
|
|
9
9
|
import { MenuItem } from '../../../menu';
|
|
10
10
|
import { getValue, isMenuDisabled, addMark, removeMark } from '../helpers';
|
|
@@ -68,7 +68,7 @@ var TextStyleMenuList = /*#__PURE__*/function (_React$Component) {
|
|
|
68
68
|
value: function render() {
|
|
69
69
|
var textStyleMenuList = this.getTextStyleMenuList();
|
|
70
70
|
return /*#__PURE__*/React.createElement(React.Fragment, null, textStyleMenuList.map(function (menuItem, index) {
|
|
71
|
-
var menuItemConfig = MENUS_CONFIG_MAP[
|
|
71
|
+
var menuItemConfig = MENUS_CONFIG_MAP[TEXT_STYLE][index];
|
|
72
72
|
var menuItemProps = _objectSpread(_objectSpread({}, menuItem), menuItemConfig);
|
|
73
73
|
return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
|
|
74
74
|
key: index
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK } from '../constants';
|
|
4
|
-
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin } from '../plugins';
|
|
3
|
+
import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, IMAGE } from '../constants';
|
|
4
|
+
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin } from '../plugins';
|
|
5
5
|
var renderElement = function renderElement(props, editor) {
|
|
6
6
|
var attributes = props.attributes,
|
|
7
7
|
children = props.children,
|
|
@@ -67,6 +67,12 @@ var renderElement = function renderElement(props, editor) {
|
|
|
67
67
|
renderCodeBlock = _CodeBlockPlugin$rend[0];
|
|
68
68
|
return renderCodeBlock(props, editor);
|
|
69
69
|
}
|
|
70
|
+
case IMAGE:
|
|
71
|
+
{
|
|
72
|
+
var _ImagePlugin$renderEl = _slicedToArray(ImagePlugin.renderElements, 1),
|
|
73
|
+
renderImage = _ImagePlugin$renderEl[0];
|
|
74
|
+
return renderImage(props, editor);
|
|
75
|
+
}
|
|
70
76
|
default:
|
|
71
77
|
{
|
|
72
78
|
return /*#__PURE__*/React.createElement("p", Object.assign({
|
|
@@ -3,17 +3,17 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
3
3
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
4
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import { ORDERED_LIST, UNORDERED_LIST } from '../constants';
|
|
7
|
+
import { MenuGroup } from '../menu';
|
|
6
8
|
import QuoteMenu from '../plugins/blockquote/menu';
|
|
7
9
|
import LinkMenu from '../plugins/link/menu';
|
|
8
10
|
import ListMenu from '../plugins/list/menu';
|
|
9
|
-
import
|
|
11
|
+
import ImageMenu from '../plugins/image/menu';
|
|
10
12
|
import HeaderMenu from '../plugins/header/menu';
|
|
11
13
|
import CheckListMenu from '../plugins/check-list/menu';
|
|
12
|
-
import { MenuGroup } from '../menu';
|
|
13
14
|
import TextStyleMenuList from '../plugins/text-style/menu';
|
|
14
15
|
import CodeBlockMenu from '../plugins/code-block/menu';
|
|
15
16
|
import HistoryMenu from './redo-undo';
|
|
16
|
-
import '../../assets/css/sdoc-editor-toolbar.css';
|
|
17
17
|
var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
18
18
|
_inherits(Toolbar, _React$Component);
|
|
19
19
|
var _super = _createSuper(Toolbar);
|
|
@@ -46,6 +46,8 @@ var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
|
46
46
|
editor: this.props.editor
|
|
47
47
|
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(CodeBlockMenu, {
|
|
48
48
|
editor: this.props.editor
|
|
49
|
+
})), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(ImageMenu, {
|
|
50
|
+
editor: this.props.editor
|
|
49
51
|
})));
|
|
50
52
|
}
|
|
51
53
|
}]);
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
// import shallowEqual from 'shallowequal';
|
|
3
|
+
import { DIFF_TYPE, ELEMENT_TYPE } from '../../basic-sdk/extension/constants';
|
|
4
|
+
import ObjectUtils from './object-utils';
|
|
5
|
+
var getElementIndexInDiffDocument = function getElementIndexInDiffDocument(diffDocument, element) {
|
|
6
|
+
return diffDocument.findIndex(function (item) {
|
|
7
|
+
return item.id === element.id;
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var getNearestElementIndex = function getNearestElementIndex(diffDocument, oldDocument, elementId) {
|
|
11
|
+
var elementInDiffDocument = getElementIndexInDiffDocument(diffDocument, elementId);
|
|
12
|
+
if (elementInDiffDocument > -1) {
|
|
13
|
+
return elementInDiffDocument;
|
|
14
|
+
}
|
|
15
|
+
var oldElementCount = oldDocument.length;
|
|
16
|
+
var elementInOldDocumentIndex = oldDocument.findIndex(function (item) {
|
|
17
|
+
return item.id === elementId;
|
|
18
|
+
});
|
|
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 oldLeftElement = oldDocument[leftIndex];
|
|
25
|
+
elementInDiffDocument = getElementIndexInDiffDocument(diffDocument, oldLeftElement);
|
|
26
|
+
if (elementInDiffDocument > -1) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
var oldLastElement = oldDocument[rightIndex];
|
|
30
|
+
elementInDiffDocument = getElementIndexInDiffDocument(diffDocument, oldLastElement);
|
|
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
|
+
var updateDiffDocument = function updateDiffDocument(diffDocument, element, oldElement) {
|
|
41
|
+
if (!diffDocument || !element || !oldElement) return;
|
|
42
|
+
if (ObjectUtils.isSameObject(element, oldElement)) {
|
|
43
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
44
|
+
diff_type: DIFF_TYPE.COMMON
|
|
45
|
+
}));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var currentElementType = element.type;
|
|
49
|
+
var oldElementType = oldElement.type;
|
|
50
|
+
if (currentElementType !== oldElementType) {
|
|
51
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
52
|
+
diff_type: DIFF_TYPE.DELETE
|
|
53
|
+
}));
|
|
54
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
55
|
+
diff_type: DIFF_TYPE.ADD
|
|
56
|
+
}));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
switch (currentElementType) {
|
|
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:
|
|
67
|
+
{
|
|
68
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
69
|
+
diff_type: DIFF_TYPE.DELETE
|
|
70
|
+
}));
|
|
71
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
72
|
+
diff_type: DIFF_TYPE.ADD
|
|
73
|
+
}));
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case ELEMENT_TYPE.LINK:
|
|
77
|
+
{
|
|
78
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
79
|
+
diff_type: DIFF_TYPE.DELETE
|
|
80
|
+
}));
|
|
81
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
82
|
+
diff_type: DIFF_TYPE.ADD
|
|
83
|
+
}));
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case ELEMENT_TYPE.BLOCKQUOTE:
|
|
87
|
+
{
|
|
88
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
89
|
+
diff_type: DIFF_TYPE.DELETE
|
|
90
|
+
}));
|
|
91
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
92
|
+
diff_type: DIFF_TYPE.ADD
|
|
93
|
+
}));
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case ELEMENT_TYPE.ORDERED_LIST:
|
|
97
|
+
case ELEMENT_TYPE.UNORDERED_LIST:
|
|
98
|
+
{
|
|
99
|
+
var orderDiff = getDiffValue(element, oldElement);
|
|
100
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
101
|
+
children: orderDiff,
|
|
102
|
+
diff_type: DIFF_TYPE.MODIFY
|
|
103
|
+
}));
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case ELEMENT_TYPE.LIST_ITEM:
|
|
107
|
+
{
|
|
108
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
109
|
+
diff_type: DIFF_TYPE.DELETE
|
|
110
|
+
}));
|
|
111
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
112
|
+
diff_type: DIFF_TYPE.ADD
|
|
113
|
+
}));
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case ELEMENT_TYPE.LIST_LIC:
|
|
117
|
+
{
|
|
118
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
119
|
+
diff_type: DIFF_TYPE.DELETE
|
|
120
|
+
}));
|
|
121
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
122
|
+
diff_type: DIFF_TYPE.ADD
|
|
123
|
+
}));
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case ELEMENT_TYPE.CHECK_LIST_ITEM:
|
|
127
|
+
{
|
|
128
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
129
|
+
diff_type: DIFF_TYPE.DELETE
|
|
130
|
+
}));
|
|
131
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
132
|
+
diff_type: DIFF_TYPE.ADD
|
|
133
|
+
}));
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case ELEMENT_TYPE.CODE_BLOCK:
|
|
137
|
+
{
|
|
138
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
139
|
+
diff_type: DIFF_TYPE.DELETE
|
|
140
|
+
}));
|
|
141
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
142
|
+
diff_type: DIFF_TYPE.ADD
|
|
143
|
+
}));
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case ELEMENT_TYPE.IMAGE:
|
|
147
|
+
{
|
|
148
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
149
|
+
diff_type: DIFF_TYPE.DELETE
|
|
150
|
+
}));
|
|
151
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
152
|
+
diff_type: DIFF_TYPE.ADD
|
|
153
|
+
}));
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default:
|
|
157
|
+
{
|
|
158
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
159
|
+
diff_type: DIFF_TYPE.DELETE
|
|
160
|
+
}));
|
|
161
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
162
|
+
diff_type: DIFF_TYPE.ADD
|
|
163
|
+
}));
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
export var getDiffValue = function getDiffValue(currentValue, oldValue) {
|
|
169
|
+
var currentVersion = currentValue.version,
|
|
170
|
+
currentChildren = currentValue.children;
|
|
171
|
+
var oldVersion = oldValue.version,
|
|
172
|
+
oldChildren = oldValue.children;
|
|
173
|
+
if (currentVersion === oldVersion) return currentChildren;
|
|
174
|
+
var diffDocument = [];
|
|
175
|
+
console.log('currentChildren: ', currentChildren);
|
|
176
|
+
console.log('oldChildren: ', oldChildren);
|
|
177
|
+
|
|
178
|
+
// init
|
|
179
|
+
var currentChildrenMap = {};
|
|
180
|
+
var oldChildrenMap = {};
|
|
181
|
+
currentChildren.forEach(function (element) {
|
|
182
|
+
currentChildrenMap[element.id] = element;
|
|
183
|
+
});
|
|
184
|
+
oldChildren.forEach(function (element) {
|
|
185
|
+
oldChildrenMap[element.id] = element;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// generator diff elements
|
|
189
|
+
for (var i = 0; i < currentChildren.length; i++) {
|
|
190
|
+
var element = currentChildren[i];
|
|
191
|
+
var isAdded = !oldChildrenMap[element.id]; // 增加的
|
|
192
|
+
if (isAdded) {
|
|
193
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
194
|
+
diff_type: DIFF_TYPE.ADD
|
|
195
|
+
}));
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
updateDiffDocument(diffDocument, element, oldChildrenMap[element.id]);
|
|
199
|
+
}
|
|
200
|
+
oldChildren.forEach(function (oldElement) {
|
|
201
|
+
if (!currentChildrenMap[oldElement.id]) {
|
|
202
|
+
// 删除的
|
|
203
|
+
var elementIndex = getNearestElementIndex(diffDocument, oldChildren, oldElement.id);
|
|
204
|
+
diffDocument.splice(elementIndex, 0, _objectSpread(_objectSpread({}, oldElement), {}, {
|
|
205
|
+
diff_type: DIFF_TYPE.DELETE
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
return diffDocument;
|
|
210
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
var ObjectUtils = /*#__PURE__*/function () {
|
|
5
|
+
function ObjectUtils() {
|
|
6
|
+
_classCallCheck(this, ObjectUtils);
|
|
7
|
+
}
|
|
8
|
+
_createClass(ObjectUtils, null, [{
|
|
9
|
+
key: "getDataType",
|
|
10
|
+
value: function getDataType(data) {
|
|
11
|
+
var type = typeof data;
|
|
12
|
+
if (type !== 'object') {
|
|
13
|
+
return type;
|
|
14
|
+
}
|
|
15
|
+
return Object.prototype.toString.call(data).replace(/^\[object (\S+)\]$/, '$1');
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
key: "iterable",
|
|
19
|
+
value: function iterable(data) {
|
|
20
|
+
return ['Object', 'Array'].includes(this.getDataType(data));
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "isObjectChanged",
|
|
24
|
+
value: function isObjectChanged(source, comparison) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
if (!this.iterable(source)) {
|
|
27
|
+
throw new Error("source should be a Object or Array , but got ".concat(this.getDataType(source)));
|
|
28
|
+
}
|
|
29
|
+
if (this.getDataType(source) !== this.getDataType(comparison)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
var sourceKeys = Object.keys(source);
|
|
33
|
+
var comparisonKeys = Object.keys(_objectSpread(_objectSpread({}, source), comparison));
|
|
34
|
+
if (sourceKeys.length !== comparisonKeys.length) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return comparisonKeys.some(function (key) {
|
|
38
|
+
if (_this.iterable(source[key])) {
|
|
39
|
+
return _this.isObjectChanged(source[key], comparison[key]);
|
|
40
|
+
} else {
|
|
41
|
+
return source[key] !== comparison[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "isSameObject",
|
|
47
|
+
value: function isSameObject(source, comparison) {
|
|
48
|
+
if (!source || !comparison) return false;
|
|
49
|
+
return !this.isObjectChanged(source, comparison);
|
|
50
|
+
}
|
|
51
|
+
}]);
|
|
52
|
+
return ObjectUtils;
|
|
53
|
+
}();
|
|
54
|
+
export default ObjectUtils;
|
package/dist/context.js
CHANGED
|
@@ -4,7 +4,7 @@ import cookie from 'react-cookies';
|
|
|
4
4
|
import { SeafileAPI } from 'seafile-js';
|
|
5
5
|
import Url from 'url-parse';
|
|
6
6
|
import SDocServerApi from './api/sdoc-server-api';
|
|
7
|
-
import { getDirPath } from './utils';
|
|
7
|
+
import { getDirPath, getImageFileNameWithTimestamp } from './utils';
|
|
8
8
|
var Context = /*#__PURE__*/function () {
|
|
9
9
|
function Context() {
|
|
10
10
|
var _this = this;
|
|
@@ -16,6 +16,25 @@ var Context = /*#__PURE__*/function () {
|
|
|
16
16
|
_this.sdocServerApi = new SDocServerApi(_this.settings);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
+
this.uploadLocalImage = function (imageFile) {
|
|
20
|
+
var repoID = _this.getSetting('repoID');
|
|
21
|
+
var docUuid = _this.getSetting('docUuid');
|
|
22
|
+
var relativePath = "images/sdoc/".concat(docUuid);
|
|
23
|
+
return _this.api.getFileServerUploadLink(repoID, '/').then(function (res) {
|
|
24
|
+
var uploadLink = res.data + '?ret-json=1';
|
|
25
|
+
var name = getImageFileNameWithTimestamp();
|
|
26
|
+
var newFile = new File([imageFile], name, {
|
|
27
|
+
type: imageFile.type
|
|
28
|
+
});
|
|
29
|
+
var formData = new FormData();
|
|
30
|
+
formData.append('parent_dir', '/');
|
|
31
|
+
formData.append('relative_path', relativePath);
|
|
32
|
+
formData.append('file', newFile);
|
|
33
|
+
return _this.api.uploadImage(uploadLink, formData);
|
|
34
|
+
}).then(function (res) {
|
|
35
|
+
return _this._getImageURL(res.data[0].name);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
19
38
|
this.settings = null;
|
|
20
39
|
this.sdocServerApi = null;
|
|
21
40
|
this.api = null;
|
|
@@ -146,6 +165,15 @@ var Context = /*#__PURE__*/function () {
|
|
|
146
165
|
return _this3.api.updateFile(uploadLink, docPath, docName, content);
|
|
147
166
|
});
|
|
148
167
|
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "_getImageURL",
|
|
170
|
+
value: function _getImageURL(fileName) {
|
|
171
|
+
var repoID = this.getSetting('repoID');
|
|
172
|
+
var serviceUrl = this.getSetting('serviceUrl');
|
|
173
|
+
var docUuid = this.getSetting('docUuid');
|
|
174
|
+
var url = serviceUrl + '/lib/' + repoID + '/file/images/sdoc/' + docUuid + '/' + fileName + '?raw=1';
|
|
175
|
+
return url;
|
|
176
|
+
}
|
|
149
177
|
}, {
|
|
150
178
|
key: "getCollaborators",
|
|
151
179
|
value: function getCollaborators() {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
+
import React, { Component } from 'react';
|
|
7
|
+
import { Editable, Slate } from '@seafile/slate-react';
|
|
8
|
+
import editor, { renderLeaf, renderElement } from '../../basic-sdk/extension';
|
|
9
|
+
import withNodeId from '../../basic-sdk/node-id';
|
|
10
|
+
import { getDiffValue } from '../../basic-sdk/utils/diff';
|
|
11
|
+
import { DIFF_TYPE } from '../../basic-sdk/extension/constants';
|
|
12
|
+
import '../../assets/css/diff-viewer.css';
|
|
13
|
+
var DiffViewer = /*#__PURE__*/function (_Component) {
|
|
14
|
+
_inherits(DiffViewer, _Component);
|
|
15
|
+
var _super = _createSuper(DiffViewer);
|
|
16
|
+
function DiffViewer(_props) {
|
|
17
|
+
var _this;
|
|
18
|
+
_classCallCheck(this, DiffViewer);
|
|
19
|
+
_this = _super.call(this, _props);
|
|
20
|
+
_this.renderLeaf = function (props) {
|
|
21
|
+
return renderLeaf(props, _this.editor);
|
|
22
|
+
};
|
|
23
|
+
_this.renderElement = function (props) {
|
|
24
|
+
var element = props.element;
|
|
25
|
+
var diff_type = element.diff_type;
|
|
26
|
+
if (diff_type === DIFF_TYPE.ADD) {
|
|
27
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
28
|
+
className: "sdoc-diff-added"
|
|
29
|
+
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
30
|
+
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
31
|
+
className: 'sdoc-diff-added'
|
|
32
|
+
})
|
|
33
|
+
}), _this.editor));
|
|
34
|
+
}
|
|
35
|
+
if (diff_type === DIFF_TYPE.DELETE) {
|
|
36
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
37
|
+
className: "sdoc-diff-removed"
|
|
38
|
+
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
39
|
+
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
40
|
+
className: 'sdoc-diff-removed'
|
|
41
|
+
})
|
|
42
|
+
}), _this.editor));
|
|
43
|
+
}
|
|
44
|
+
if (diff_type === DIFF_TYPE.MODIFY) {
|
|
45
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
46
|
+
className: "sdoc-diff-modify"
|
|
47
|
+
}, renderElement(_objectSpread(_objectSpread({}, props), {}, {
|
|
48
|
+
attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
|
|
49
|
+
className: 'sdoc-diff-modify'
|
|
50
|
+
})
|
|
51
|
+
}), _this.editor));
|
|
52
|
+
}
|
|
53
|
+
return renderElement(props, _this.editor);
|
|
54
|
+
};
|
|
55
|
+
_this.editor = withNodeId(editor);
|
|
56
|
+
return _this;
|
|
57
|
+
}
|
|
58
|
+
_createClass(DiffViewer, [{
|
|
59
|
+
key: "render",
|
|
60
|
+
value: function render() {
|
|
61
|
+
var _this$props = this.props,
|
|
62
|
+
currentContent = _this$props.currentContent,
|
|
63
|
+
lastContent = _this$props.lastContent;
|
|
64
|
+
var value = getDiffValue(currentContent, lastContent);
|
|
65
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
className: "sdoc-editor-container"
|
|
67
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
68
|
+
className: "sdoc-editor-content"
|
|
69
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
className: "flex-fill o-auto"
|
|
71
|
+
}, /*#__PURE__*/React.createElement(Slate, {
|
|
72
|
+
editor: this.editor,
|
|
73
|
+
value: value,
|
|
74
|
+
onChange: function onChange() {}
|
|
75
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
76
|
+
className: "article mx-auto"
|
|
77
|
+
}, /*#__PURE__*/React.createElement(Editable, {
|
|
78
|
+
readOnly: true,
|
|
79
|
+
placeholder: "",
|
|
80
|
+
renderElement: this.renderElement,
|
|
81
|
+
renderLeaf: this.renderLeaf,
|
|
82
|
+
onDOMBeforeInput: function onDOMBeforeInput() {},
|
|
83
|
+
onKeyDown: function onKeyDown() {}
|
|
84
|
+
}))))));
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
return DiffViewer;
|
|
88
|
+
}(Component);
|
|
89
|
+
export default DiffViewer;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,32 @@
|
|
|
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;
|