@seafile/sdoc-editor 0.1.28 → 0.1.30
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/api/seafile-api.js +31 -0
- package/dist/assets/css/simple-editor.css +11 -0
- package/dist/basic-sdk/extension/plugins/image/menu/index.js +0 -2
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +11 -2
- package/dist/components/doc-info/index.js +47 -0
- package/dist/constants/index.js +3 -0
- package/dist/context.js +9 -102
- package/dist/index.js +3 -2
- package/dist/pages/simple-editor.js +2 -8
- package/package.json +2 -1
- package/dist/config.js +0 -16
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
var SeafileAPI = /*#__PURE__*/function () {
|
|
5
|
+
function SeafileAPI(server, token) {
|
|
6
|
+
_classCallCheck(this, SeafileAPI);
|
|
7
|
+
this.req = axios.create({
|
|
8
|
+
baseURL: server,
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: 'Token ' + token
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
_createClass(SeafileAPI, [{
|
|
15
|
+
key: "uploadSdocImage",
|
|
16
|
+
value: function uploadSdocImage(docUuid, file) {
|
|
17
|
+
var url = '/api/v2.1/seadoc/upload-image/' + docUuid + '/';
|
|
18
|
+
var form = new FormData();
|
|
19
|
+
form.append('file', file);
|
|
20
|
+
return this.req.post(url, form);
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "getSdocDownloadImageUrl",
|
|
24
|
+
value: function getSdocDownloadImageUrl(docUuid, imageName) {
|
|
25
|
+
var url = '/api/v2.1/seadoc/download-image/' + docUuid + '/' + encodeURIComponent(imageName);
|
|
26
|
+
return this.req.get(url);
|
|
27
|
+
}
|
|
28
|
+
}]);
|
|
29
|
+
return SeafileAPI;
|
|
30
|
+
}();
|
|
31
|
+
export default SeafileAPI;
|
|
@@ -7,3 +7,14 @@
|
|
|
7
7
|
font-size: 18px;
|
|
8
8
|
color: #212529;
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
.sdoc-editor-page-header .doc-info .doc-icon {
|
|
12
|
+
margin-left: 0.5rem;
|
|
13
|
+
color: #999;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sdoc-editor-page-header .doc-info .doc-icon:hover {
|
|
18
|
+
margin-left: 0.5rem;
|
|
19
|
+
color: #333;
|
|
20
|
+
}
|
|
@@ -90,9 +90,7 @@ var ImageMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
90
90
|
var editor = _this.props.editor;
|
|
91
91
|
var file = event.target.files[0];
|
|
92
92
|
context.uploadLocalImage(file).then(function (fileUrl) {
|
|
93
|
-
console.log(fileUrl);
|
|
94
93
|
insertImage(editor, fileUrl, _this.selection);
|
|
95
|
-
console.log(editor.children);
|
|
96
94
|
});
|
|
97
95
|
};
|
|
98
96
|
_this.setInputRef = function (ref) {
|
|
@@ -5,10 +5,12 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
|
5
5
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
6
|
import { useSelected } from '@seafile/slate-react';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import { updateImage } from './helpers';
|
|
9
8
|
import classNames from 'classnames';
|
|
10
9
|
import { withTranslation } from 'react-i18next';
|
|
10
|
+
import urlJoin from 'url-join';
|
|
11
|
+
import { updateImage } from './helpers';
|
|
11
12
|
import ImagePreviewer from './dialogs/image-previewer';
|
|
13
|
+
import context from '../../../../context';
|
|
12
14
|
var Image = /*#__PURE__*/function (_React$Component) {
|
|
13
15
|
_inherits(Image, _React$Component);
|
|
14
16
|
var _super = _createSuper(Image);
|
|
@@ -87,6 +89,13 @@ var Image = /*#__PURE__*/function (_React$Component) {
|
|
|
87
89
|
return _this;
|
|
88
90
|
}
|
|
89
91
|
_createClass(Image, [{
|
|
92
|
+
key: "getImageURL",
|
|
93
|
+
value: function getImageURL(url) {
|
|
94
|
+
var serviceUrl = context.getSetting('serviceUrl');
|
|
95
|
+
var assetsUrl = context.getSetting('assetsUrl');
|
|
96
|
+
return urlJoin(serviceUrl, assetsUrl, url);
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
90
99
|
key: "render",
|
|
91
100
|
value: function render() {
|
|
92
101
|
var _this$props2 = this.props,
|
|
@@ -107,7 +116,7 @@ var Image = /*#__PURE__*/function (_React$Component) {
|
|
|
107
116
|
}, attributes), /*#__PURE__*/React.createElement("img", {
|
|
108
117
|
className: imageClassName,
|
|
109
118
|
ref: this.setImageRef,
|
|
110
|
-
src: data.src,
|
|
119
|
+
src: this.getImageURL(data.src),
|
|
111
120
|
style: imageStyle,
|
|
112
121
|
draggable: false,
|
|
113
122
|
alt: ""
|
|
@@ -0,0 +1,47 @@
|
|
|
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 from 'react';
|
|
6
|
+
import TipMessage from '../tip-message';
|
|
7
|
+
import { withTranslation } from 'react-i18next';
|
|
8
|
+
import context from '../../context';
|
|
9
|
+
import { EventBus } from '../../basic-sdk';
|
|
10
|
+
import { EXTERNAL_EVENT } from '../../constants';
|
|
11
|
+
var DocInfo = /*#__PURE__*/function (_React$Component) {
|
|
12
|
+
_inherits(DocInfo, _React$Component);
|
|
13
|
+
var _super = _createSuper(DocInfo);
|
|
14
|
+
function DocInfo() {
|
|
15
|
+
var _this;
|
|
16
|
+
_classCallCheck(this, DocInfo);
|
|
17
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
|
+
args[_key] = arguments[_key];
|
|
19
|
+
}
|
|
20
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
21
|
+
_this.onInternalLinkClick = function () {
|
|
22
|
+
var eventBus = EventBus.getInstance();
|
|
23
|
+
eventBus.dispatch(EXTERNAL_EVENT.INTERNAL_LINK_CLICK);
|
|
24
|
+
};
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
_createClass(DocInfo, [{
|
|
28
|
+
key: "render",
|
|
29
|
+
value: function render() {
|
|
30
|
+
var t = this.props.t;
|
|
31
|
+
var docName = context.getSetting('docName');
|
|
32
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
className: "doc-info"
|
|
34
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
35
|
+
className: "doc-name"
|
|
36
|
+
}, docName), /*#__PURE__*/React.createElement("span", {
|
|
37
|
+
className: "doc-icon"
|
|
38
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
39
|
+
className: "internal-link iconfont icon-link",
|
|
40
|
+
title: t('internal_link'),
|
|
41
|
+
onClick: this.onInternalLinkClick
|
|
42
|
+
})), /*#__PURE__*/React.createElement(TipMessage, null));
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
return DocInfo;
|
|
46
|
+
}(React.Component);
|
|
47
|
+
export default withTranslation('sdoc-editor')(DocInfo);
|
package/dist/context.js
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import cookie from 'react-cookies';
|
|
4
|
-
import { SeafileAPI } from 'seafile-js';
|
|
5
3
|
import Url from 'url-parse';
|
|
6
4
|
import SDocServerApi from './api/sdoc-server-api';
|
|
7
|
-
import
|
|
5
|
+
import SeafileAPI from './api/seafile-api';
|
|
8
6
|
var Context = /*#__PURE__*/function () {
|
|
9
7
|
function Context() {
|
|
10
8
|
var _this = this;
|
|
11
9
|
_classCallCheck(this, Context);
|
|
12
10
|
this.initSettings = function () {
|
|
13
11
|
_this.settings = window.seafile ? window.seafile : window.seafileConfig;
|
|
14
|
-
var isOpenSocket = _this.getSetting('isOpenSocket');
|
|
15
|
-
if (isOpenSocket) {
|
|
16
|
-
_this.sdocServerApi = new SDocServerApi(_this.settings);
|
|
17
|
-
}
|
|
18
12
|
};
|
|
19
13
|
this.uploadLocalImage = function (imageFile) {
|
|
20
|
-
var repoID = _this.getSetting('repoID');
|
|
21
14
|
var docUuid = _this.getSetting('docUuid');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
15
|
+
return _this.api.uploadSdocImage(docUuid, imageFile).then(function (res) {
|
|
16
|
+
var relative_path = res.data.relative_path;
|
|
17
|
+
return relative_path;
|
|
36
18
|
});
|
|
37
19
|
};
|
|
38
20
|
this.settings = null;
|
|
@@ -44,27 +26,10 @@ var Context = /*#__PURE__*/function () {
|
|
|
44
26
|
key: "initApi",
|
|
45
27
|
value: function initApi() {
|
|
46
28
|
this.initSettings(); // lazy init context class
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var password = this.getSetting('password');
|
|
52
|
-
seafileAPI.init({
|
|
53
|
-
server: server,
|
|
54
|
-
username: username,
|
|
55
|
-
password: password
|
|
56
|
-
});
|
|
57
|
-
this.api = seafileAPI;
|
|
58
|
-
return seafileAPI.login();
|
|
59
|
-
} else {
|
|
60
|
-
var siteRoot = this.getSetting('siteRoot');
|
|
61
|
-
var xcsrfHeaders = cookie.load('dtable_csrftoken');
|
|
62
|
-
seafileAPI.initForSeahubUsage({
|
|
63
|
-
siteRoot: siteRoot,
|
|
64
|
-
xcsrfHeaders: xcsrfHeaders
|
|
65
|
-
});
|
|
66
|
-
this.api = seafileAPI;
|
|
67
|
-
}
|
|
29
|
+
var server = this.getSetting('serviceUrl');
|
|
30
|
+
var token = this.getSetting('accessToken');
|
|
31
|
+
this.api = new SeafileAPI(server, token);
|
|
32
|
+
this.sdocServerApi = new SDocServerApi(this.settings);
|
|
68
33
|
}
|
|
69
34
|
}, {
|
|
70
35
|
key: "getSettings",
|
|
@@ -109,71 +74,13 @@ var Context = /*#__PURE__*/function () {
|
|
|
109
74
|
}, {
|
|
110
75
|
key: "getFileContent",
|
|
111
76
|
value: function getFileContent() {
|
|
112
|
-
|
|
113
|
-
if (isOpenSocket) {
|
|
114
|
-
return this.getFileContent1();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// visit by shared link
|
|
118
|
-
var rawPath = this.getSetting('rawPath');
|
|
119
|
-
if (rawPath) {
|
|
120
|
-
return this.api.getFileContent(rawPath);
|
|
121
|
-
}
|
|
122
|
-
return this.getFileContent2();
|
|
77
|
+
return this.sdocServerApi.getDocContent();
|
|
123
78
|
}
|
|
124
79
|
}, {
|
|
125
80
|
key: "saveContent",
|
|
126
81
|
value: function saveContent(content) {
|
|
127
|
-
var isOpenSocket = this.getSetting('isOpenSocket');
|
|
128
|
-
if (isOpenSocket) {
|
|
129
|
-
return this.saveContent1(content);
|
|
130
|
-
}
|
|
131
|
-
return this.saveContent2(content);
|
|
132
|
-
}
|
|
133
|
-
}, {
|
|
134
|
-
key: "getFileContent1",
|
|
135
|
-
value: function getFileContent1() {
|
|
136
|
-
return this.sdocServerApi.getDocContent();
|
|
137
|
-
}
|
|
138
|
-
}, {
|
|
139
|
-
key: "saveContent1",
|
|
140
|
-
value: function saveContent1(content) {
|
|
141
82
|
return this.sdocServerApi.saveDocContent(content);
|
|
142
83
|
}
|
|
143
|
-
}, {
|
|
144
|
-
key: "getFileContent2",
|
|
145
|
-
value: function getFileContent2() {
|
|
146
|
-
var _this2 = this;
|
|
147
|
-
var repoID = this.getSetting('repoID');
|
|
148
|
-
var docPath = this.getSetting('docPath');
|
|
149
|
-
return this.api.getFileDownloadLink(repoID, docPath).then(function (res) {
|
|
150
|
-
var downloadLink = res.data;
|
|
151
|
-
return _this2.api.getFileContent(downloadLink);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}, {
|
|
155
|
-
key: "saveContent2",
|
|
156
|
-
value: function saveContent2(content) {
|
|
157
|
-
var _this3 = this;
|
|
158
|
-
var settings = this.getSettings();
|
|
159
|
-
var repoID = settings.repoID,
|
|
160
|
-
docPath = settings.docPath,
|
|
161
|
-
docName = settings.docName;
|
|
162
|
-
var dirPath = getDirPath(docPath);
|
|
163
|
-
return this.api.getUpdateLink(repoID, dirPath).then(function (res) {
|
|
164
|
-
var uploadLink = res.data;
|
|
165
|
-
return _this3.api.updateFile(uploadLink, docPath, docName, content);
|
|
166
|
-
});
|
|
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
|
-
}
|
|
177
84
|
}, {
|
|
178
85
|
key: "getCollaborators",
|
|
179
86
|
value: function getCollaborators() {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SDocViewer } from './basic-sdk';
|
|
1
|
+
import { SDocViewer, EventBus } from './basic-sdk';
|
|
2
|
+
import { EXTERNAL_EVENT } from './constants';
|
|
2
3
|
import SimpleEditor from './pages/simple-editor';
|
|
3
4
|
import SimpleViewer from './pages/simple-viewer';
|
|
4
|
-
export { SDocViewer, SimpleEditor, SimpleViewer };
|
|
5
|
+
export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT };
|
|
@@ -7,7 +7,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { SDocEditor } from '../basic-sdk';
|
|
9
9
|
import Loading from '../components/loading';
|
|
10
|
-
import
|
|
10
|
+
import DocInfo from '../components/doc-info';
|
|
11
11
|
import DocOperations from '../components/doc-operations';
|
|
12
12
|
import Layout, { Header, Content } from '../layout';
|
|
13
13
|
import { generateDefaultDocContent } from '../utils';
|
|
@@ -115,14 +115,8 @@ var SimpleEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
115
115
|
className: "d-flex justify-content-center"
|
|
116
116
|
}, errorMessage);
|
|
117
117
|
}
|
|
118
|
-
var docName = context.getSetting('docName');
|
|
119
118
|
var isOpenSocket = context.getSetting('isOpenSocket');
|
|
120
|
-
|
|
121
|
-
return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", {
|
|
122
|
-
className: "doc-info"
|
|
123
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
124
|
-
className: "doc-name"
|
|
125
|
-
}, docName), internalLink, /*#__PURE__*/React.createElement(TipMessage, null)), /*#__PURE__*/React.createElement(DocOperations, null)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
|
|
119
|
+
return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(DocInfo, null), /*#__PURE__*/React.createElement(DocOperations, null)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
|
|
126
120
|
ref: this.setEditorRef,
|
|
127
121
|
config: context.getEditorConfig(),
|
|
128
122
|
document: document,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This is a sdoc editor",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"reactstrap": "8.9.0",
|
|
19
19
|
"slugid": "3.2.0",
|
|
20
20
|
"socket.io-client": "4.6.1",
|
|
21
|
+
"url-join": "5.0.0",
|
|
21
22
|
"url-parse": "1.5.10",
|
|
22
23
|
"uuid": "9.0.0"
|
|
23
24
|
},
|
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 };
|