@seafile/sdoc-editor 0.1.27 → 0.1.28-beta
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 +7 -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 +134 -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 +76 -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
|
@@ -8,3 +8,64 @@
|
|
|
8
8
|
margin: 0;
|
|
9
9
|
padding-inline-start: 24px;
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
/* image */
|
|
13
|
+
.sdoc-editor-container .article .sdoc-image {
|
|
14
|
+
position: relative;
|
|
15
|
+
display: inline-block;
|
|
16
|
+
margin: 0 3px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.sdoc-editor-container .article .image-selected {
|
|
20
|
+
box-shadow: 0 0 0 2px #007bff;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.sdoc-editor-container .article .image-resizer {
|
|
24
|
+
width: 10px;
|
|
25
|
+
height: 10px;
|
|
26
|
+
position: absolute;
|
|
27
|
+
right: -5px;
|
|
28
|
+
bottom: -5px;
|
|
29
|
+
background-color: #007bff;
|
|
30
|
+
border: 1px solid #fff;
|
|
31
|
+
cursor: se-resize;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.sdoc-editor-container .article .image-full-screen {
|
|
35
|
+
position: absolute;
|
|
36
|
+
height: 26px;
|
|
37
|
+
display: inline-block;
|
|
38
|
+
width: 26px;
|
|
39
|
+
top: 0;
|
|
40
|
+
right: -32px;
|
|
41
|
+
text-align: center;
|
|
42
|
+
line-height: 20px;
|
|
43
|
+
padding: 2px;
|
|
44
|
+
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.2);
|
|
45
|
+
border-radius: 3px;
|
|
46
|
+
border: 1px solid rgba(0, 40, 100, 0.12);
|
|
47
|
+
background-color: #fff;
|
|
48
|
+
user-select: none!important;
|
|
49
|
+
z-index: 1000;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.sdoc-editor-container .article .image-full-screen:hover {
|
|
53
|
+
display: block;
|
|
54
|
+
background-color: #efefef;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.sdoc-editor-container .article .image-size {
|
|
58
|
+
display: inline-block;
|
|
59
|
+
padding: 5px;
|
|
60
|
+
height: 22px;
|
|
61
|
+
position: absolute;
|
|
62
|
+
bottom: -25px;
|
|
63
|
+
left: 100%;
|
|
64
|
+
transform: translateX(5px);
|
|
65
|
+
border-radius: 3px;
|
|
66
|
+
line-height: 12px;
|
|
67
|
+
color: #fff;
|
|
68
|
+
background-color: #4c4c4c;
|
|
69
|
+
font-size: 12px;
|
|
70
|
+
}
|
|
71
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export var BLOCKQUOTE = 'blockquote';
|
|
2
|
+
export var BOLD = 'bold';
|
|
3
|
+
export var ITALIC = 'italic';
|
|
4
|
+
export var HEADER = 'header';
|
|
5
|
+
export var HEADER1 = 'header1';
|
|
6
|
+
export var HEADER2 = 'header2';
|
|
7
|
+
export var HEADER3 = 'header3';
|
|
8
|
+
export var HEADER4 = 'header4';
|
|
9
|
+
export var HEADER5 = 'header5';
|
|
10
|
+
export var HEADER6 = 'header6';
|
|
11
|
+
export var ORDERED_LIST = 'ordered_list';
|
|
12
|
+
export var UNORDERED_LIST = 'unordered_list'; // unordered_list can not work
|
|
13
|
+
export var LIST_ITEM = 'list-item';
|
|
14
|
+
export var LIST_LIC = 'list-lic'; // placeholder
|
|
15
|
+
export var CHECK_LIST = 'check-list';
|
|
16
|
+
export var CHECK_LIST_ITEM = 'check-list-item';
|
|
17
|
+
export var PARAGRAPH = 'paragraph';
|
|
18
|
+
export var LINK = 'link';
|
|
19
|
+
export var HTML = 'html';
|
|
20
|
+
export var CODE_BLOCK = 'code-block';
|
|
21
|
+
export var CODE_LINE = 'code-line';
|
|
22
|
+
export var IMAGE = 'image';
|
|
23
|
+
export var TABLE = 'table';
|
|
24
|
+
export var TABLE_CELL = 'table-cell';
|
|
25
|
+
export var TABLE_ROW = 'table-row';
|
|
26
|
+
export var FORMULA = 'formula';
|
|
27
|
+
export var COLUMN = 'column';
|
|
28
|
+
export var TEXT_STYLE = 'text-style';
|
|
29
|
+
export var BOLD_ITALIC = 'bold-italic';
|
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
|
|
3
3
|
// extension plugin
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export var ITALIC = 'italic';
|
|
7
|
-
export var HEADER = 'header';
|
|
8
|
-
export var HEADER1 = 'header1';
|
|
9
|
-
export var HEADER2 = 'header2';
|
|
10
|
-
export var HEADER3 = 'header3';
|
|
11
|
-
export var HEADER4 = 'header4';
|
|
12
|
-
export var HEADER5 = 'header5';
|
|
13
|
-
export var HEADER6 = 'header6';
|
|
14
|
-
export var ORDERED_LIST = 'ordered_list';
|
|
15
|
-
export var UNORDERED_LIST = 'unordered_list'; // unordered_list can not work
|
|
16
|
-
export var LIST_ITEM = 'list-item';
|
|
17
|
-
export var LIST_LIC = 'list-lic'; // placeholder
|
|
18
|
-
export var CHECK_LIST = 'check-list';
|
|
19
|
-
export var CHECK_LIST_ITEM = 'check-list-item';
|
|
20
|
-
export var PARAGRAPH = 'paragraph';
|
|
21
|
-
export var LINK = 'link';
|
|
22
|
-
export var HTML = 'html';
|
|
23
|
-
export var CODE_BLOCK = 'code-block';
|
|
24
|
-
export var CODE_LINE = 'code-line';
|
|
25
|
-
export var IMAGE = 'image';
|
|
26
|
-
export var TABLE = 'table';
|
|
27
|
-
export var TABLE_CELL = 'table-cell';
|
|
28
|
-
export var TABLE_ROW = 'table-row';
|
|
29
|
-
export var FORMULA = 'formula';
|
|
30
|
-
export var COLUMN = 'column';
|
|
31
|
-
export var TEXTSTYLE = 'text-style';
|
|
32
|
-
export var BOLD_ITALIC = 'bold-italic';
|
|
4
|
+
import * as ELEMENT_TYPE from './element-type';
|
|
5
|
+
import { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC } from './element-type';
|
|
33
6
|
|
|
34
7
|
// history
|
|
35
8
|
export var UNDO = 'undo';
|
|
@@ -60,7 +33,11 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
|
|
|
60
33
|
id: "sdoc_".concat(LINK),
|
|
61
34
|
iconClass: 'iconfont icon-link',
|
|
62
35
|
text: 'insert_link'
|
|
63
|
-
}), _defineProperty(_MENUS_CONFIG_MAP,
|
|
36
|
+
}), _defineProperty(_MENUS_CONFIG_MAP, IMAGE, {
|
|
37
|
+
id: "sdoc_".concat(IMAGE),
|
|
38
|
+
iconClass: 'iconfont icon-image',
|
|
39
|
+
text: 'insert_image'
|
|
40
|
+
}), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE, [{
|
|
64
41
|
id: ITALIC,
|
|
65
42
|
iconClass: 'iconfont icon-italic',
|
|
66
43
|
text: 'italic',
|
|
@@ -81,4 +58,11 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
|
|
|
81
58
|
text: 'redo',
|
|
82
59
|
type: 'redo'
|
|
83
60
|
}), _MENUS_CONFIG_MAP);
|
|
84
|
-
export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'paragraph'), _HEADER_TITLE_MAP);
|
|
61
|
+
export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'paragraph'), _HEADER_TITLE_MAP);
|
|
62
|
+
export var DIFF_TYPE = {
|
|
63
|
+
ADD: 'add',
|
|
64
|
+
DELETE: 'delete',
|
|
65
|
+
MODIFY: 'modify',
|
|
66
|
+
COMMON: 'common'
|
|
67
|
+
};
|
|
68
|
+
export { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC, ELEMENT_TYPE };
|
|
@@ -6,6 +6,7 @@ import React from 'react';
|
|
|
6
6
|
import { withTranslation } from 'react-i18next';
|
|
7
7
|
import { getHeaderType, isMenuDisabled, setHeaderType } from '../helpers';
|
|
8
8
|
import { HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, HEADER_TITLE_MAP, PARAGRAPH } from '../../../constants';
|
|
9
|
+
import './style.css';
|
|
9
10
|
var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
10
11
|
_inherits(HeaderMenu, _React$Component);
|
|
11
12
|
var _super = _createSuper(HeaderMenu);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
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 from 'react';
|
|
7
|
+
import Lightbox from '@seafile/react-image-lightbox';
|
|
8
|
+
import '@seafile/react-image-lightbox/style.css';
|
|
9
|
+
var ImagePreviewer = /*#__PURE__*/function (_React$Component) {
|
|
10
|
+
_inherits(ImagePreviewer, _React$Component);
|
|
11
|
+
var _super = _createSuper(ImagePreviewer);
|
|
12
|
+
function ImagePreviewer(props) {
|
|
13
|
+
var _this;
|
|
14
|
+
_classCallCheck(this, ImagePreviewer);
|
|
15
|
+
_this = _super.call(this, props);
|
|
16
|
+
_this.getImageNodes = function (nodes) {
|
|
17
|
+
var nodeIndex = 0;
|
|
18
|
+
var list = [];
|
|
19
|
+
while (nodes && nodeIndex <= nodes.length - 1) {
|
|
20
|
+
var currentNode = nodes[nodeIndex];
|
|
21
|
+
if (currentNode.type === 'image') {
|
|
22
|
+
currentNode.data.src && list.push(currentNode.data.src);
|
|
23
|
+
} else {
|
|
24
|
+
list.push.apply(list, _toConsumableArray(_this.getImageNodes(currentNode.children)));
|
|
25
|
+
}
|
|
26
|
+
nodeIndex++;
|
|
27
|
+
}
|
|
28
|
+
return list;
|
|
29
|
+
};
|
|
30
|
+
_this.moveToPrevImage = function () {
|
|
31
|
+
_this.setState(function (prevState) {
|
|
32
|
+
return {
|
|
33
|
+
imageIndex: (prevState.imageIndex + _this.images.length - 1) % _this.images.length
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
_this.moveToNextImage = function () {
|
|
38
|
+
_this.setState(function (prevState) {
|
|
39
|
+
return {
|
|
40
|
+
imageIndex: (prevState.imageIndex + 1) % _this.images.length
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var editor = props.editor,
|
|
45
|
+
imageUrl = props.imageUrl;
|
|
46
|
+
_this.images = _this.getImageNodes(editor.children);
|
|
47
|
+
_this.state = {
|
|
48
|
+
imageIndex: _this.images.findIndex(function (item) {
|
|
49
|
+
return item === imageUrl;
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
return _this;
|
|
53
|
+
}
|
|
54
|
+
_createClass(ImagePreviewer, [{
|
|
55
|
+
key: "render",
|
|
56
|
+
value: function render() {
|
|
57
|
+
var imageIndex = this.state.imageIndex;
|
|
58
|
+
var imageItemsLength = this.images.length;
|
|
59
|
+
var mainSrc = this.images[imageIndex] || '';
|
|
60
|
+
var imageTitle = '';
|
|
61
|
+
try {
|
|
62
|
+
imageTitle = mainSrc ? decodeURI(mainSrc.slice(mainSrc.lastIndexOf('/') + 1)) : '';
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.log(error);
|
|
66
|
+
}
|
|
67
|
+
var imageTitleEl = /*#__PURE__*/React.createElement("span", {
|
|
68
|
+
className: "d-flex"
|
|
69
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
70
|
+
className: "text-truncate"
|
|
71
|
+
}, imageTitle), /*#__PURE__*/React.createElement("span", {
|
|
72
|
+
className: "flex-shrink-0"
|
|
73
|
+
}, "(", imageIndex + 1, "/", this.images.length, ")"));
|
|
74
|
+
return /*#__PURE__*/React.createElement(Lightbox, {
|
|
75
|
+
wrapperClassName: "sf-editor-image-previewer",
|
|
76
|
+
imageTitle: imageTitleEl,
|
|
77
|
+
mainSrc: mainSrc,
|
|
78
|
+
toolbarButtons: [],
|
|
79
|
+
nextSrc: this.images[(imageIndex + 1) % imageItemsLength],
|
|
80
|
+
prevSrc: this.images[(imageIndex + imageItemsLength - 1) % imageItemsLength],
|
|
81
|
+
onCloseRequest: this.props.toggleImagePreviewer,
|
|
82
|
+
onMovePrevRequest: this.moveToPrevImage,
|
|
83
|
+
onMoveNextRequest: this.moveToNextImage,
|
|
84
|
+
imagePadding: 70,
|
|
85
|
+
reactModalStyle: {
|
|
86
|
+
overlay: {
|
|
87
|
+
zIndex: 1071
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}]);
|
|
93
|
+
return ImagePreviewer;
|
|
94
|
+
}(React.Component);
|
|
95
|
+
export default ImagePreviewer;
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { withTranslation } from 'react-i18next';
|
|
7
|
+
import { Modal, ModalHeader, ModalBody, ModalFooter, FormGroup, Label, Input, Button } from 'reactstrap';
|
|
8
|
+
var InsertWebImageDialog = /*#__PURE__*/function (_Component) {
|
|
9
|
+
_inherits(InsertWebImageDialog, _Component);
|
|
10
|
+
var _super = _createSuper(InsertWebImageDialog);
|
|
11
|
+
function InsertWebImageDialog(props) {
|
|
12
|
+
var _this;
|
|
13
|
+
_classCallCheck(this, InsertWebImageDialog);
|
|
14
|
+
_this = _super.call(this, props);
|
|
15
|
+
_this.onValueChanged = function (event) {
|
|
16
|
+
var value = event.target.value;
|
|
17
|
+
_this.setState({
|
|
18
|
+
url: value
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
_this.onKeyDown = function (event) {
|
|
22
|
+
if (event.keyCode === 13) {
|
|
23
|
+
_this.handleSubmit();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
_this.handleSubmit = function () {
|
|
28
|
+
var url = _this.state.url;
|
|
29
|
+
if (!url) return;
|
|
30
|
+
_this.props.onInsertImage(url);
|
|
31
|
+
};
|
|
32
|
+
_this.onDialogToggle = function () {
|
|
33
|
+
_this.props.onDialogToggle();
|
|
34
|
+
};
|
|
35
|
+
_this.state = {
|
|
36
|
+
url: ''
|
|
37
|
+
};
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
_createClass(InsertWebImageDialog, [{
|
|
41
|
+
key: "render",
|
|
42
|
+
value: function render() {
|
|
43
|
+
var t = this.props.t;
|
|
44
|
+
var url = this.state.url;
|
|
45
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
46
|
+
isOpen: true,
|
|
47
|
+
toggle: this.onDialogToggle,
|
|
48
|
+
autoFocus: false
|
|
49
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, null, t('insert_image')), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(FormGroup, null, /*#__PURE__*/React.createElement(Label, {
|
|
50
|
+
for: "insert_image"
|
|
51
|
+
}, t('image_address')), /*#__PURE__*/React.createElement(Input, {
|
|
52
|
+
id: "insert_image",
|
|
53
|
+
autoFocus: true,
|
|
54
|
+
value: url,
|
|
55
|
+
onChange: this.onValueChanged,
|
|
56
|
+
onKeyDown: this.onKeyDown
|
|
57
|
+
}))), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
58
|
+
color: "secondary",
|
|
59
|
+
onClick: this.onDialogToggle
|
|
60
|
+
}, t('cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
61
|
+
color: "primary",
|
|
62
|
+
disabled: url.length === 0,
|
|
63
|
+
onClick: this.handleSubmit
|
|
64
|
+
}, t('submit'))));
|
|
65
|
+
}
|
|
66
|
+
}]);
|
|
67
|
+
return InsertWebImageDialog;
|
|
68
|
+
}(Component);
|
|
69
|
+
export default withTranslation('sdoc-editor')(InsertWebImageDialog);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { Editor, Range, Transforms } from '@seafile/slate';
|
|
4
|
+
import { BLOCKQUOTE, CODE_BLOCK, IMAGE, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
|
|
5
|
+
import { generateEmptyElement, getNodeType } from '../../core';
|
|
6
|
+
export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor) {
|
|
7
|
+
var selection = editor.selection;
|
|
8
|
+
if (selection === null) return true;
|
|
9
|
+
if (!Range.isCollapsed(selection)) return true;
|
|
10
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
11
|
+
match: function match(n) {
|
|
12
|
+
var type = getNodeType(n);
|
|
13
|
+
if (type === CODE_BLOCK) return true;
|
|
14
|
+
if (type === ORDERED_LIST) return true;
|
|
15
|
+
if (type === UNORDERED_LIST) return true;
|
|
16
|
+
if (type.startsWith('header')) return true;
|
|
17
|
+
if (type === BLOCKQUOTE) return true;
|
|
18
|
+
if (Editor.isVoid(editor, n)) return true;
|
|
19
|
+
return false;
|
|
20
|
+
},
|
|
21
|
+
universal: true
|
|
22
|
+
}),
|
|
23
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
24
|
+
match = _Editor$nodes2[0];
|
|
25
|
+
if (match) return true;
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
export var generateImageNode = function generateImageNode(src) {
|
|
29
|
+
var element = generateEmptyElement(IMAGE);
|
|
30
|
+
return _objectSpread(_objectSpread({}, element), {}, {
|
|
31
|
+
data: {
|
|
32
|
+
src: src
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export var insertImage = function insertImage(editor, src, selection) {
|
|
37
|
+
if (!src) return;
|
|
38
|
+
if (isInsertImageMenuDisabled(editor)) return;
|
|
39
|
+
var imageNode = generateImageNode(src);
|
|
40
|
+
Transforms.insertNodes(editor, imageNode, {
|
|
41
|
+
at: selection
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export var updateImage = function updateImage(editor, data) {
|
|
45
|
+
Transforms.setNodes(editor, {
|
|
46
|
+
data: data
|
|
47
|
+
}, {
|
|
48
|
+
match: function match(n) {
|
|
49
|
+
return getNodeType(n) === IMAGE;
|
|
50
|
+
},
|
|
51
|
+
at: editor.selection,
|
|
52
|
+
voids: true
|
|
53
|
+
});
|
|
54
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IMAGE } from '../../constants';
|
|
2
|
+
import ImageMenu from './menu';
|
|
3
|
+
import Image from './model';
|
|
4
|
+
import withImage from './plugin';
|
|
5
|
+
import renderImage from './render-elem';
|
|
6
|
+
var ImagePlugin = {
|
|
7
|
+
type: IMAGE,
|
|
8
|
+
nodeType: 'element',
|
|
9
|
+
model: Image,
|
|
10
|
+
editorMenus: [ImageMenu],
|
|
11
|
+
editorPlugin: withImage,
|
|
12
|
+
renderElements: [renderImage]
|
|
13
|
+
};
|
|
14
|
+
export default ImagePlugin;
|
|
@@ -0,0 +1,150 @@
|
|
|
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, { Fragment } from 'react';
|
|
7
|
+
import { withTranslation } from 'react-i18next';
|
|
8
|
+
import { insertImage, isInsertImageMenuDisabled } from '../helpers';
|
|
9
|
+
import context from '../../../../../context';
|
|
10
|
+
import { IMAGE, MENUS_CONFIG_MAP } from '../../../constants';
|
|
11
|
+
import { MenuItem } from '../../../menu';
|
|
12
|
+
import InsertWebImageDialog from '../dialogs/insert-web-image-dialog';
|
|
13
|
+
import './style.css';
|
|
14
|
+
var ImageMenu = /*#__PURE__*/function (_React$Component) {
|
|
15
|
+
_inherits(ImageMenu, _React$Component);
|
|
16
|
+
var _super = _createSuper(ImageMenu);
|
|
17
|
+
function ImageMenu(props) {
|
|
18
|
+
var _this;
|
|
19
|
+
_classCallCheck(this, ImageMenu);
|
|
20
|
+
_this = _super.call(this, props);
|
|
21
|
+
_this.registerEventHandler = function () {
|
|
22
|
+
document.addEventListener('mousedown', _this.onHideImageMenu);
|
|
23
|
+
};
|
|
24
|
+
_this.unregisterEventHandler = function () {
|
|
25
|
+
document.removeEventListener('mousedown', _this.onHideImageMenu);
|
|
26
|
+
};
|
|
27
|
+
_this.onHideImageMenu = function () {
|
|
28
|
+
_this.setState({
|
|
29
|
+
isShowImagePopover: false
|
|
30
|
+
}, function () {
|
|
31
|
+
_this.unregisterEventHandler();
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
_this.isActive = function () {
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
_this.isDisabled = function () {
|
|
38
|
+
var editor = _this.props.editor;
|
|
39
|
+
return isInsertImageMenuDisabled(editor);
|
|
40
|
+
};
|
|
41
|
+
_this.onToggleClick = function (event) {
|
|
42
|
+
event.stopPropagation();
|
|
43
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
44
|
+
var isShowImagePopover = !_this.state.isShowImagePopover;
|
|
45
|
+
if (isShowImagePopover) {
|
|
46
|
+
_this.setState({
|
|
47
|
+
isShowImagePopover: isShowImagePopover
|
|
48
|
+
}, function () {
|
|
49
|
+
_this.registerEventHandler();
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
_this.setState({
|
|
53
|
+
isShowImagePopover: isShowImagePopover
|
|
54
|
+
}, function () {
|
|
55
|
+
_this.unregisterEventHandler();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
_this.onInsertWebImageToggle = function () {
|
|
60
|
+
var editor = _this.props.editor;
|
|
61
|
+
_this.selection = editor.selection;
|
|
62
|
+
_this.setState({
|
|
63
|
+
isShowInsertImageDialog: true,
|
|
64
|
+
isShowImagePopover: false
|
|
65
|
+
}, function () {
|
|
66
|
+
_this.unregisterEventHandler();
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
_this.onInsertLocalImageToggle = function () {
|
|
70
|
+
var editor = _this.props.editor;
|
|
71
|
+
_this.selection = editor.selection;
|
|
72
|
+
_this.input.click();
|
|
73
|
+
_this.setState({
|
|
74
|
+
isShowImagePopover: false
|
|
75
|
+
}, function () {
|
|
76
|
+
_this.unregisterEventHandler();
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
_this.onInsertImage = function (url) {
|
|
80
|
+
var editor = _this.props.editor;
|
|
81
|
+
insertImage(editor, url, _this.selection);
|
|
82
|
+
_this.onCloseInsertDialog();
|
|
83
|
+
};
|
|
84
|
+
_this.onCloseInsertDialog = function () {
|
|
85
|
+
_this.setState({
|
|
86
|
+
isShowInsertImageDialog: false
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
_this.onFileChanged = function (event) {
|
|
90
|
+
var editor = _this.props.editor;
|
|
91
|
+
var file = event.target.files[0];
|
|
92
|
+
context.uploadLocalImage(file).then(function (fileUrl) {
|
|
93
|
+
console.log(fileUrl);
|
|
94
|
+
insertImage(editor, fileUrl, _this.selection);
|
|
95
|
+
console.log(editor.children);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
_this.setInputRef = function (ref) {
|
|
99
|
+
_this.input = ref;
|
|
100
|
+
};
|
|
101
|
+
_this.state = {
|
|
102
|
+
isShowImagePopover: false,
|
|
103
|
+
isShowInsertImageDialog: false
|
|
104
|
+
};
|
|
105
|
+
return _this;
|
|
106
|
+
}
|
|
107
|
+
_createClass(ImageMenu, [{
|
|
108
|
+
key: "render",
|
|
109
|
+
value: function render() {
|
|
110
|
+
var _this$props = this.props,
|
|
111
|
+
isRichEditor = _this$props.isRichEditor,
|
|
112
|
+
className = _this$props.className,
|
|
113
|
+
t = _this$props.t;
|
|
114
|
+
var _this$state = this.state,
|
|
115
|
+
isShowImagePopover = _this$state.isShowImagePopover,
|
|
116
|
+
isShowInsertImageDialog = _this$state.isShowInsertImageDialog;
|
|
117
|
+
var menuConfig = MENUS_CONFIG_MAP[IMAGE];
|
|
118
|
+
var props = _objectSpread(_objectSpread({
|
|
119
|
+
isRichEditor: isRichEditor,
|
|
120
|
+
className: className
|
|
121
|
+
}, menuConfig), {}, {
|
|
122
|
+
disabled: this.isDisabled(),
|
|
123
|
+
isActive: this.isActive(),
|
|
124
|
+
onMouseDown: this.onToggleClick
|
|
125
|
+
});
|
|
126
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
className: "image-menu"
|
|
128
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
129
|
+
ref: this.setInputRef,
|
|
130
|
+
type: "file",
|
|
131
|
+
accept: "image/*",
|
|
132
|
+
className: "locale-image-uploader",
|
|
133
|
+
onChange: this.onFileChanged
|
|
134
|
+
}), /*#__PURE__*/React.createElement(MenuItem, props), isShowImagePopover && /*#__PURE__*/React.createElement("div", {
|
|
135
|
+
className: "image-popover"
|
|
136
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
137
|
+
className: "image-menu-item",
|
|
138
|
+
onMouseDown: this.onInsertWebImageToggle
|
|
139
|
+
}, t('insert_network_image')), /*#__PURE__*/React.createElement("div", {
|
|
140
|
+
className: "image-menu-item",
|
|
141
|
+
onMouseDown: this.onInsertLocalImageToggle
|
|
142
|
+
}, t('upload_local_image')))), isShowInsertImageDialog && /*#__PURE__*/React.createElement(InsertWebImageDialog, {
|
|
143
|
+
onInsertImage: this.onInsertImage,
|
|
144
|
+
onDialogToggle: this.onCloseInsertDialog
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
}]);
|
|
148
|
+
return ImageMenu;
|
|
149
|
+
}(React.Component);
|
|
150
|
+
export default withTranslation('sdoc-editor')(ImageMenu);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
.image-menu {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.image-menu .image-popover {
|
|
6
|
+
position: absolute;
|
|
7
|
+
top: 36px;
|
|
8
|
+
left: 0px;
|
|
9
|
+
padding: 8px 0;
|
|
10
|
+
background-color: #fff;
|
|
11
|
+
border: 1px solid #e5e6e8;
|
|
12
|
+
border-radius: 2px;
|
|
13
|
+
box-shadow: 0 0 10px #ccc;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
align-items: flex-start;
|
|
17
|
+
z-index: 10;
|
|
18
|
+
white-space:nowrap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.image-menu .image-popover .image-menu-item {
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
height: 30px;
|
|
24
|
+
padding: 4px 24px;
|
|
25
|
+
user-select: none;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
font-size: 0.9375rem;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.image-menu .image-popover .image-menu-item:hover {
|
|
32
|
+
background-color: rgb(245, 245, 245);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.image-menu .locale-image-uploader {
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
width: 0;
|
|
40
|
+
height: 0;
|
|
41
|
+
opacity: 0;
|
|
42
|
+
font-size: 0;
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import { IMAGE } from '../../constants';
|
|
4
|
+
var Image = /*#__PURE__*/_createClass(function Image(options) {
|
|
5
|
+
_classCallCheck(this, Image);
|
|
6
|
+
this.type = options.type || IMAGE;
|
|
7
|
+
this.data = options.data || {
|
|
8
|
+
src: ''
|
|
9
|
+
};
|
|
10
|
+
this.children = options.children || [{
|
|
11
|
+
text: ''
|
|
12
|
+
}];
|
|
13
|
+
});
|
|
14
|
+
export default Image;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import context from '../../../../context';
|
|
2
|
+
import { insertImage } from './helpers';
|
|
3
|
+
var withImage = function withImage(editor) {
|
|
4
|
+
var isInline = editor.isInline,
|
|
5
|
+
isVoid = editor.isVoid,
|
|
6
|
+
insertData = editor.insertData;
|
|
7
|
+
var newEditor = editor;
|
|
8
|
+
|
|
9
|
+
// rewrite isInline
|
|
10
|
+
newEditor.isInline = function (elem) {
|
|
11
|
+
var type = elem.type;
|
|
12
|
+
if (type === 'image') {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return isInline(elem);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// rewrite isVoid
|
|
19
|
+
newEditor.isVoid = function (elem) {
|
|
20
|
+
var type = elem.type;
|
|
21
|
+
if (type === 'image') {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return isVoid(elem);
|
|
25
|
+
};
|
|
26
|
+
newEditor.insertData = function (data) {
|
|
27
|
+
if (data.types && data.types.includes('Files') && data.files[0].type.includes('image')) {
|
|
28
|
+
context.uploadLocalImage(data.files[0]).then(function (fileUrl) {
|
|
29
|
+
insertImage(newEditor, fileUrl, editor.selection);
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
insertData(data);
|
|
34
|
+
};
|
|
35
|
+
return newEditor;
|
|
36
|
+
};
|
|
37
|
+
export default withImage;
|
|
@@ -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,134 @@
|
|
|
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
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
49
|
+
diff_type: DIFF_TYPE.DELETE
|
|
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;
|
|
61
|
+
if (currentElementType !== oldElementType) {
|
|
62
|
+
diffDocument.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
63
|
+
diff_type: DIFF_TYPE.DELETE
|
|
64
|
+
}));
|
|
65
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
66
|
+
diff_type: DIFF_TYPE.ADD
|
|
67
|
+
}));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
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
|
+
switch (currentElementType) {
|
|
80
|
+
//
|
|
81
|
+
case ELEMENT_TYPE.BLOCKQUOTE:
|
|
82
|
+
{
|
|
83
|
+
//
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
{
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export var getDiffValue = function getDiffValue(currentValue, oldValue) {
|
|
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
|
+
|
|
102
|
+
// init
|
|
103
|
+
var currentChildrenMap = {};
|
|
104
|
+
var oldChildrenMap = {};
|
|
105
|
+
currentChildren.forEach(function (element) {
|
|
106
|
+
currentChildrenMap[element.id] = element;
|
|
107
|
+
});
|
|
108
|
+
oldChildren.forEach(function (element) {
|
|
109
|
+
oldChildrenMap[element.id] = element;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// generator diff elements
|
|
113
|
+
for (var i = 0; i < currentChildren.length; i++) {
|
|
114
|
+
var element = currentChildren[i];
|
|
115
|
+
var isAdded = !oldChildrenMap[element.id]; // 增加的
|
|
116
|
+
if (isAdded) {
|
|
117
|
+
diffDocument.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
118
|
+
diff_type: DIFF_TYPE.ADD
|
|
119
|
+
}));
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
updateDiffDocument(diffDocument, element, oldChildrenMap[element.id]);
|
|
123
|
+
}
|
|
124
|
+
oldChildren.forEach(function (oldElement) {
|
|
125
|
+
if (!currentChildrenMap[oldElement.id]) {
|
|
126
|
+
// 删除的
|
|
127
|
+
var elementIndex = getNearestElementIndex(diffDocument, oldChildren, oldElement.id);
|
|
128
|
+
diffDocument.splice(elementIndex, 0, _objectSpread(_objectSpread({}, oldElement), {}, {
|
|
129
|
+
diff_type: DIFF_TYPE.DELETE
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return diffDocument;
|
|
134
|
+
};
|
|
@@ -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,76 @@
|
|
|
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 '../../basic-sdk/extension/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;
|
|
@@ -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;
|
package/dist/utils/index.js
CHANGED
|
@@ -18,4 +18,8 @@ export var generateDefaultDocContent = function generateDefaultDocContent() {
|
|
|
18
18
|
}]
|
|
19
19
|
};
|
|
20
20
|
return defaultValue;
|
|
21
|
+
};
|
|
22
|
+
export var getImageFileNameWithTimestamp = function getImageFileNameWithTimestamp() {
|
|
23
|
+
var d = Date.now();
|
|
24
|
+
return 'image-' + d.toString() + '.png';
|
|
21
25
|
};
|
package/package.json
CHANGED
package/dist/config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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 };
|
|
File without changes
|