@seafile/sdoc-editor 0.1.146-beta3 → 0.1.147
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/sdoc-server-api.js +0 -10
- package/dist/api/seafile-api.js +5 -27
- package/dist/basic-sdk/constants/index.js +1 -14
- package/dist/basic-sdk/editor.js +105 -0
- package/dist/basic-sdk/extension/constants/element-type.js +1 -4
- package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +0 -26
- package/dist/basic-sdk/extension/plugins/link/hover/index.js +6 -2
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +4 -2
- package/dist/basic-sdk/{editor/slate-editor.js → slate-editor.js} +16 -21
- package/dist/basic-sdk/socket/helpers.js +0 -2
- package/dist/basic-sdk/socket/socket-client.js +0 -30
- package/dist/basic-sdk/socket/socket-manager.js +11 -22
- package/dist/basic-sdk/socket/with-socket-io.js +12 -35
- package/dist/basic-sdk/utils/diff.js +2 -2
- package/dist/basic-sdk/views/diff-viewer.js +1 -3
- package/dist/basic-sdk/views/viewer.js +11 -8
- package/dist/components/doc-operations/index.js +2 -8
- package/dist/components/doc-operations/revision-operations/index.js +3 -11
- package/dist/components/doc-operations/revision-operations/publish-button.js +13 -16
- package/dist/constants/index.js +2 -23
- package/dist/context.js +4 -35
- package/dist/pages/simple-editor.js +72 -268
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +1 -13
- package/public/locales/zh_CN/sdoc-editor.json +1 -12
- package/dist/basic-sdk/editor/common-editor.js +0 -47
- package/dist/basic-sdk/editor/index.css +0 -29
- package/dist/basic-sdk/editor/index.js +0 -340
- package/dist/basic-sdk/utils/rebase.js +0 -196
- package/dist/components/tip-dialog/index.css +0 -0
- package/dist/components/tip-dialog/index.js +0 -49
- package/dist/components/tip-dialog/tip-content.js +0 -56
|
@@ -11,20 +11,14 @@ import './style.css';
|
|
|
11
11
|
var DocOperations = function DocOperations(_ref) {
|
|
12
12
|
var isShowChanges = _ref.isShowChanges,
|
|
13
13
|
changes = _ref.changes,
|
|
14
|
-
toggleViewChanges = _ref.toggleViewChanges
|
|
15
|
-
publishRevision = _ref.publishRevision,
|
|
16
|
-
mode = _ref.mode,
|
|
17
|
-
abortRebase = _ref.abortRebase;
|
|
14
|
+
toggleViewChanges = _ref.toggleViewChanges;
|
|
18
15
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
19
16
|
return /*#__PURE__*/React.createElement("div", {
|
|
20
17
|
className: "doc-ops"
|
|
21
18
|
}, /*#__PURE__*/React.createElement(RevisionOperations, {
|
|
22
19
|
isShowChanges: isShowChanges,
|
|
23
20
|
changes: changes,
|
|
24
|
-
|
|
25
|
-
toggleViewChanges: toggleViewChanges,
|
|
26
|
-
publishRevision: publishRevision,
|
|
27
|
-
abortRebase: abortRebase
|
|
21
|
+
toggleViewChanges: toggleViewChanges
|
|
28
22
|
}), /*#__PURE__*/React.createElement(CommentsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(ShareOperation, null), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(MoreOperations, null));
|
|
29
23
|
};
|
|
30
24
|
export default withTranslation('sdoc-editor')(DocOperations);
|
|
@@ -5,25 +5,17 @@ import ViewChanges from './view-changes';
|
|
|
5
5
|
import MoreRevisionOperations from './more-revision-operations';
|
|
6
6
|
import Revisions from './revisions';
|
|
7
7
|
import ChangesCount from './changes-count';
|
|
8
|
-
import { MODE } from '../../../constants';
|
|
9
8
|
var RevisionOperations = function RevisionOperations(_ref) {
|
|
10
9
|
var isShowChanges = _ref.isShowChanges,
|
|
11
10
|
changes = _ref.changes,
|
|
12
|
-
toggleViewChanges = _ref.toggleViewChanges
|
|
13
|
-
publishRevision = _ref.publishRevision,
|
|
14
|
-
mode = _ref.mode,
|
|
15
|
-
abortRebase = _ref.abortRebase;
|
|
11
|
+
toggleViewChanges = _ref.toggleViewChanges;
|
|
16
12
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
17
13
|
var isPublished = context.getSetting('isPublished');
|
|
18
14
|
return /*#__PURE__*/React.createElement(React.Fragment, null, !isSdocRevision && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MoreRevisionOperations, null), /*#__PURE__*/React.createElement(Revisions, null)), isSdocRevision && isShowChanges && /*#__PURE__*/React.createElement(ChangesCount, {
|
|
19
15
|
changes: changes
|
|
20
|
-
}), isSdocRevision &&
|
|
16
|
+
}), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
|
|
21
17
|
isShowChanges: isShowChanges,
|
|
22
18
|
toggleViewChanges: toggleViewChanges
|
|
23
|
-
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision,
|
|
24
|
-
publishRevision: publishRevision,
|
|
25
|
-
mode: mode,
|
|
26
|
-
abortRebase: abortRebase
|
|
27
|
-
}));
|
|
19
|
+
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, null));
|
|
28
20
|
};
|
|
29
21
|
export default RevisionOperations;
|
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
3
2
|
import { Button } from 'reactstrap';
|
|
4
|
-
import {
|
|
3
|
+
import { withTranslation } from 'react-i18next';
|
|
4
|
+
import context from '../../../context';
|
|
5
|
+
import toaster from '../../../components/toast';
|
|
5
6
|
var PublishRevision = function PublishRevision(_ref) {
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _useTranslation = useTranslation(),
|
|
10
|
-
t = _useTranslation.t;
|
|
7
|
+
var t = _ref.t;
|
|
8
|
+
var repoID = context.getSetting('repoID');
|
|
9
|
+
var siteRoot = context.getSetting('siteRoot');
|
|
11
10
|
var publish = useCallback(function (event) {
|
|
12
11
|
event.stopPropagation();
|
|
13
12
|
event.nativeEvent.stopImmediatePropagation();
|
|
14
|
-
|
|
13
|
+
context.publishSdocRevision().then(function (res) {
|
|
14
|
+
var origin_file_path = res.data.origin_file_path;
|
|
15
|
+
window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
|
|
16
|
+
}).catch(function (error) {
|
|
17
|
+
toaster.danger(t('Error'));
|
|
18
|
+
});
|
|
15
19
|
|
|
16
20
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
17
21
|
}, []);
|
|
18
|
-
if (mode === MODE.REBASE) {
|
|
19
|
-
return /*#__PURE__*/React.createElement(Button, {
|
|
20
|
-
color: "success",
|
|
21
|
-
onClick: abortRebase,
|
|
22
|
-
className: "ml-4"
|
|
23
|
-
}, t('Abort'));
|
|
24
|
-
}
|
|
25
22
|
return /*#__PURE__*/React.createElement(Button, {
|
|
26
23
|
color: "success",
|
|
27
24
|
onClick: publish,
|
|
28
25
|
className: "ml-4"
|
|
29
26
|
}, t('Publish'));
|
|
30
27
|
};
|
|
31
|
-
export default PublishRevision;
|
|
28
|
+
export default withTranslation('sdoc-editor')(PublishRevision);
|
package/dist/constants/index.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
var _TIP_TITLE, _TIP_CONTENT;
|
|
3
1
|
export var EXTERNAL_EVENT = {
|
|
4
2
|
INTERNAL_LINK_CLICK: 'internal_link_click',
|
|
5
3
|
TOGGLE_STAR: 'toggle_star',
|
|
6
4
|
UNMARK_AS_DRAFT: 'unmark_as_draft',
|
|
7
|
-
SHARE_SDOC: 'share_sdoc'
|
|
8
|
-
|
|
9
|
-
PUBLISH_DOCUMENT: 'publish_document',
|
|
10
|
-
MERGE_DOCUMENT: 'merge_document'
|
|
11
|
-
};
|
|
12
|
-
export var MODE = {
|
|
13
|
-
DIFF_VIEWER: 'diff-viewer',
|
|
14
|
-
VIEWER: 'viewer',
|
|
15
|
-
EDITOR: 'editor',
|
|
16
|
-
REBASE: 'rebase'
|
|
17
|
-
};
|
|
18
|
-
export var TIP_TYPE = {
|
|
19
|
-
DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
|
|
20
|
-
MERGE: 'merge',
|
|
21
|
-
HAS_CONFLICT_BEFORE_PUBLISH: 'has_conflict_before_publish',
|
|
22
|
-
HAS_BEEN_PUBLISHED: 'has_been_published',
|
|
23
|
-
HAS_BEEN_MERGE: 'has_been_merge',
|
|
24
|
-
HAS_CONFLICT_BEFORE_VIEW_CHANGES: 'has_conflict_before_view_changes'
|
|
25
|
-
};
|
|
26
|
-
export var TIP_TITLE = (_TIP_TITLE = {}, _defineProperty(_TIP_TITLE, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Tip'), _TIP_TITLE);
|
|
27
|
-
export var TIP_CONTENT = (_TIP_CONTENT = {}, _defineProperty(_TIP_CONTENT, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Rebase_delete_no_change_revision_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.MERGE, 'Merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Has_conflict_before_publish_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Has_been_published_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_MERGE, 'Has_been_merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Has_conflict_before_view_changes_tip'), _TIP_CONTENT);
|
|
5
|
+
SHARE_SDOC: 'share_sdoc'
|
|
6
|
+
};
|
package/dist/context.js
CHANGED
|
@@ -10,9 +10,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
10
10
|
this.initSettings = function () {
|
|
11
11
|
_this.settings = window.seafile ? window.seafile : window.seafileConfig;
|
|
12
12
|
};
|
|
13
|
-
// saveDocContentByRebase(content) {
|
|
14
|
-
// return this.sdocServerApi.saveDocContentByRebase(content);
|
|
15
|
-
// }
|
|
16
13
|
this.uploadLocalImage = function (imageFile) {
|
|
17
14
|
var docUuid = _this.getSetting('docUuid');
|
|
18
15
|
return _this.api.uploadSdocImage(docUuid, imageFile).then(function (res) {
|
|
@@ -48,13 +45,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
48
45
|
if (this.settings[key] === false) return this.settings[key];
|
|
49
46
|
return this.settings[key] || '';
|
|
50
47
|
}
|
|
51
|
-
}, {
|
|
52
|
-
key: "updateSettings",
|
|
53
|
-
value: function updateSettings(update) {
|
|
54
|
-
for (var key in update) {
|
|
55
|
-
this.settings[key] = update[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
48
|
}, {
|
|
59
49
|
key: "getViewConfig",
|
|
60
50
|
value: function getViewConfig() {
|
|
@@ -166,15 +156,14 @@ var Context = /*#__PURE__*/function () {
|
|
|
166
156
|
}, {
|
|
167
157
|
key: "publishSdocRevision",
|
|
168
158
|
value: function publishSdocRevision() {
|
|
169
|
-
var replace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
170
159
|
var docUuid = this.getSetting('docUuid');
|
|
171
|
-
return this.api.sdocPublishRevision(docUuid
|
|
160
|
+
return this.api.sdocPublishRevision(docUuid);
|
|
172
161
|
}
|
|
173
162
|
}, {
|
|
174
|
-
key: "
|
|
175
|
-
value: function
|
|
163
|
+
key: "getSeadocRevisionDownloadLinks",
|
|
164
|
+
value: function getSeadocRevisionDownloadLinks() {
|
|
176
165
|
var docUuid = this.getSetting('docUuid');
|
|
177
|
-
return this.api.
|
|
166
|
+
return this.api.getSeadocRevisionDownloadLinks(docUuid);
|
|
178
167
|
}
|
|
179
168
|
}, {
|
|
180
169
|
key: "getSdocRevisionsCount",
|
|
@@ -188,26 +177,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
188
177
|
var docUuid = this.getSetting('docUuid');
|
|
189
178
|
return this.api.getSdocRevisions(docUuid, page, perPage);
|
|
190
179
|
}
|
|
191
|
-
}, {
|
|
192
|
-
key: "deleteSdocRevision",
|
|
193
|
-
value: function deleteSdocRevision() {
|
|
194
|
-
var docUuid = this.getSetting('docUuid');
|
|
195
|
-
return this.api.deleteSdocRevision(docUuid);
|
|
196
|
-
}
|
|
197
|
-
}, {
|
|
198
|
-
key: "mergeSdocRevision",
|
|
199
|
-
value: function mergeSdocRevision() {
|
|
200
|
-
var docUuid = this.getSetting('docUuid');
|
|
201
|
-
return this.api.mergeSdocRevision(docUuid);
|
|
202
|
-
}
|
|
203
|
-
}, {
|
|
204
|
-
key: "getFileHistoryVersion",
|
|
205
|
-
value: function getFileHistoryVersion(fileVersion, filePath) {
|
|
206
|
-
var docUuid = this.getSetting('docUuid');
|
|
207
|
-
return this.api.getFileHistoryVersion(docUuid, fileVersion, filePath);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// local files
|
|
211
180
|
}, {
|
|
212
181
|
key: "getSdocLocalFiles",
|
|
213
182
|
value: function getSdocLocalFiles(p) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { withTranslation } from 'react-i18next';
|
|
5
|
+
import deepCopy from 'deep-copy';
|
|
6
|
+
import { SDocEditor, DiffViewer } from '../basic-sdk';
|
|
4
7
|
import Loading from '../components/loading';
|
|
5
8
|
import DocInfo from '../components/doc-info';
|
|
6
9
|
import DocOperations from '../components/doc-operations';
|
|
@@ -8,103 +11,47 @@ import Layout, { Header, Content } from '../layout';
|
|
|
8
11
|
import { generateDefaultDocContent } from '../utils';
|
|
9
12
|
import context from '../context';
|
|
10
13
|
import ErrorBoundary from './error-boundary';
|
|
11
|
-
import TipDialog from '../components/tip-dialog';
|
|
12
|
-
import { EXTERNAL_EVENT, MODE, TIP_TYPE } from '../constants';
|
|
13
|
-
import { getRebase } from '../basic-sdk/utils/rebase';
|
|
14
|
-
import toaster from '../components/toast';
|
|
15
|
-
import { EventBus, SDocEditor } from '../basic-sdk';
|
|
16
14
|
import '../assets/css/simple-editor.css';
|
|
17
15
|
var SimpleEditor = function SimpleEditor(_ref) {
|
|
18
16
|
var isStarred = _ref.isStarred,
|
|
19
17
|
isDraft = _ref.isDraft,
|
|
20
18
|
t = _ref.t;
|
|
21
|
-
context.initApi();
|
|
22
|
-
var repoID = context.getSetting('repoID');
|
|
23
|
-
var siteRoot = context.getSetting('siteRoot');
|
|
24
|
-
var originFilePath = context.getSetting('originFilePath');
|
|
25
|
-
var isRevision = context.getSetting('isSdocRevision');
|
|
26
|
-
var originFileURL = isRevision ? "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath) : '';
|
|
27
19
|
var editorRef = useRef(null);
|
|
28
20
|
var _useState = useState(true),
|
|
29
21
|
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var _useState3 = useState(
|
|
22
|
+
isFirstLoad = _useState2[0],
|
|
23
|
+
setFirstLoad = _useState2[1];
|
|
24
|
+
var _useState3 = useState(true),
|
|
33
25
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var _useState5 = useState(
|
|
26
|
+
isLoadingSdoc = _useState4[0],
|
|
27
|
+
setLoadingSdoc = _useState4[1];
|
|
28
|
+
var _useState5 = useState(''),
|
|
37
29
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var _useState7 = useState(
|
|
30
|
+
errorMessage = _useState6[0],
|
|
31
|
+
setErrorMessage = _useState6[1];
|
|
32
|
+
var _useState7 = useState(false),
|
|
41
33
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _useState9 = useState(
|
|
34
|
+
isShowChanges = _useState8[0],
|
|
35
|
+
setShowChanges = _useState8[1];
|
|
36
|
+
var _useState9 = useState(null),
|
|
45
37
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var _useState11 = useState(
|
|
38
|
+
document = _useState10[0],
|
|
39
|
+
setDocument = _useState10[1];
|
|
40
|
+
var _useState11 = useState(null),
|
|
49
41
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var _useState13 = useState(
|
|
42
|
+
currentContent = _useState12[0],
|
|
43
|
+
setCurrentContent = _useState12[1];
|
|
44
|
+
var _useState13 = useState(null),
|
|
53
45
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var _useState15 = useState(''),
|
|
57
|
-
_useState16 = _slicedToArray(_useState15, 2),
|
|
58
|
-
tipType = _useState16[0],
|
|
59
|
-
setTipType = _useState16[1];
|
|
60
|
-
var _useState17 = useState([]),
|
|
61
|
-
_useState18 = _slicedToArray(_useState17, 2),
|
|
62
|
-
mergeValue = _useState18[0],
|
|
63
|
-
setMergeValue = _useState18[1];
|
|
64
|
-
useEffect(function () {
|
|
65
|
-
initDocumentData();
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
-
}, []);
|
|
69
|
-
|
|
70
|
-
// 提示刷新界面: 主动刷新
|
|
71
|
-
var mergeDocument = useCallback(function (document, originFileVersion) {
|
|
72
|
-
setTipType(TIP_TYPE.HAS_BEEN_MERGE);
|
|
73
|
-
setShowTip(true);
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
-
}, [editorRef]);
|
|
77
|
-
|
|
78
|
-
// 提示刷新界面: 被动跳转
|
|
79
|
-
var hasPublishRevision = useCallback(function () {
|
|
80
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
81
|
-
setShowTip(true);
|
|
82
|
-
|
|
83
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
|
-
}, [editorRef]);
|
|
46
|
+
lastContent = _useState14[0],
|
|
47
|
+
setLastContent = _useState14[1];
|
|
85
48
|
useEffect(function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var publishDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
|
|
89
|
-
return function () {
|
|
90
|
-
mergeDocumentSubscribe();
|
|
91
|
-
publishDocumentSubscribe();
|
|
92
|
-
};
|
|
49
|
+
context.initApi();
|
|
50
|
+
initDocumentData(true);
|
|
93
51
|
|
|
94
52
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
53
|
}, []);
|
|
96
|
-
|
|
97
|
-
// useMount: reset title
|
|
98
|
-
useEffect(function () {
|
|
99
|
-
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
100
|
-
var originFilename = context.getSetting('originFilename');
|
|
101
|
-
if (isSdocRevision) {
|
|
102
|
-
window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
-
}, []);
|
|
107
|
-
var initDocumentData = useCallback(function () {
|
|
54
|
+
var initDocumentData = useCallback(function (isFirstLoad) {
|
|
108
55
|
setShowChanges(false);
|
|
109
56
|
setLoadingSdoc(true);
|
|
110
57
|
context.getFileContent().then(function (res) {
|
|
@@ -118,6 +65,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
118
65
|
}
|
|
119
66
|
setDocument(result);
|
|
120
67
|
setLoadingSdoc(false);
|
|
68
|
+
isFirstLoad && setFirstLoad(false);
|
|
121
69
|
}).catch(function (error) {
|
|
122
70
|
// eslint-disable-next-line
|
|
123
71
|
console.log(error);
|
|
@@ -135,202 +83,54 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
135
83
|
|
|
136
84
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
137
85
|
}, []);
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
result = {
|
|
143
|
-
version: 0,
|
|
144
|
-
children: result.content,
|
|
145
|
-
cursors: result.cursors || {}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
setDocument(result);
|
|
149
|
-
editorRef.current.setSlateValue(result);
|
|
150
|
-
editorRef.current.setLoading(false);
|
|
151
|
-
}).catch(function (error) {
|
|
152
|
-
// eslint-disable-next-line
|
|
153
|
-
console.log(error);
|
|
154
|
-
setErrorMessage('Load_doc_content_error');
|
|
155
|
-
editorRef.current.setLoading(false);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// eslint-disable-next-line no-trailing-spaces
|
|
159
|
-
}, []);
|
|
160
|
-
var setDiffContent = useCallback(function () {
|
|
161
|
-
context.getSeadocOriginFileDownloadLink().then(function (res) {
|
|
86
|
+
var initChangesData = useCallback(function () {
|
|
87
|
+
setShowChanges(true);
|
|
88
|
+
setLoadingSdoc(true);
|
|
89
|
+
context.getSeadocRevisionDownloadLinks().then(function (res) {
|
|
162
90
|
var originFileDownloadLink = res.data.origin_file_download_link;
|
|
163
91
|
return fetch(originFileDownloadLink);
|
|
164
92
|
}).then(function (res) {
|
|
165
93
|
return res.json();
|
|
166
94
|
}).then(function (originContent) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
console.log('error');
|
|
171
|
-
});
|
|
172
|
-
}, []);
|
|
173
|
-
var toggleViewChanges = useCallback(function (isShowChanges) {
|
|
174
|
-
var needFetchNewContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
175
|
-
var revisionCurrentContent = editorRef.current.getSlateValue();
|
|
176
|
-
if (revisionCurrentContent.children.filter(function (item) {
|
|
177
|
-
return item.rebaseType;
|
|
178
|
-
}).length !== 0) {
|
|
179
|
-
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
|
|
180
|
-
setShowTip(true);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
editorRef.current.setLoading(true);
|
|
184
|
-
setShowChanges(isShowChanges);
|
|
185
|
-
var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
|
|
186
|
-
setMode(mode);
|
|
187
|
-
editorRef.current.setEditorMode(mode);
|
|
188
|
-
if (!isShowChanges) {
|
|
189
|
-
setFileContent();
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (!needFetchNewContent) {
|
|
193
|
-
setDiffContent();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
context.getFileContent().then(function (res) {
|
|
197
|
-
var result = res.data || generateDefaultDocContent();
|
|
198
|
-
if (result && !result.children) {
|
|
199
|
-
result = {
|
|
200
|
-
version: 0,
|
|
201
|
-
children: result.content,
|
|
202
|
-
cursors: result.cursors || {}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
setDocument(result);
|
|
206
|
-
editorRef.current.setSlateValue(result);
|
|
207
|
-
}).then(function () {
|
|
208
|
-
setDiffContent();
|
|
95
|
+
setLastContent(originContent);
|
|
96
|
+
setErrorMessage(null);
|
|
97
|
+
setLoadingSdoc(false);
|
|
209
98
|
}).catch(function (error) {
|
|
210
|
-
// eslint-disable-next-line
|
|
211
|
-
console.log(error);
|
|
212
99
|
setErrorMessage('Load_doc_content_error');
|
|
213
|
-
|
|
100
|
+
setLoadingSdoc(false);
|
|
214
101
|
});
|
|
215
102
|
|
|
216
103
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
217
|
-
}, [document
|
|
218
|
-
var
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
104
|
+
}, [document]);
|
|
105
|
+
var toggleViewChanges = useCallback(function (isShowChanges) {
|
|
106
|
+
if (isShowChanges) {
|
|
107
|
+
var newestValue = editorRef.current.getValue();
|
|
108
|
+
setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
109
|
+
children: newestValue
|
|
110
|
+
})));
|
|
111
|
+
}
|
|
112
|
+
if (isShowChanges) {
|
|
113
|
+
initChangesData();
|
|
225
114
|
return;
|
|
226
115
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
var revisionMasterContent;
|
|
230
|
-
var masterContent;
|
|
231
|
-
context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
|
|
232
|
-
var fileHistoryRevisionContent = res.data.content; // commit content
|
|
233
|
-
revisionMasterContent = JSON.parse(fileHistoryRevisionContent);
|
|
234
|
-
return context.getSeadocOriginFileDownloadLink();
|
|
235
|
-
}).then(function (res) {
|
|
236
|
-
var originFileDownloadLink = res.data.origin_file_download_link;
|
|
237
|
-
return fetch(originFileDownloadLink);
|
|
238
|
-
}).then(function (res) {
|
|
239
|
-
return res.json();
|
|
240
|
-
}).then(function (content) {
|
|
241
|
-
masterContent = content;
|
|
242
|
-
var _getRebase = getRebase(masterContent, revisionMasterContent, revisionCurrentContent),
|
|
243
|
-
canMerge = _getRebase.canMerge,
|
|
244
|
-
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
245
|
-
value = _getRebase.value;
|
|
246
|
-
if (canMerge && isNeedReplaceMaster) {
|
|
247
|
-
context.publishSdocRevision().then(function (res) {
|
|
248
|
-
editorRef.current.publishDocument(originFileURL);
|
|
249
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
250
|
-
setShowTip(true);
|
|
251
|
-
}).catch(function (error) {
|
|
252
|
-
toaster.danger(t('Error'));
|
|
253
|
-
});
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
if (canMerge && !isNeedReplaceMaster) {
|
|
257
|
-
setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
|
|
258
|
-
setShowTip(true);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
setMergeValue(value);
|
|
262
|
-
setTipType(TIP_TYPE.MERGE);
|
|
263
|
-
setShowTip(true);
|
|
264
|
-
}).catch(function (error) {
|
|
265
|
-
toaster.danger(t('Error'));
|
|
266
|
-
});
|
|
116
|
+
setChanges([]);
|
|
117
|
+
initDocumentData(false);
|
|
267
118
|
|
|
268
119
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
269
|
-
}, [document
|
|
270
|
-
var
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}, [isShowChanges, document]);
|
|
120
|
+
}, [document]);
|
|
121
|
+
var _useState15 = useState([]),
|
|
122
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
123
|
+
changes = _useState16[0],
|
|
124
|
+
setChanges = _useState16[1];
|
|
275
125
|
var setDiffChanges = useCallback(function (diff) {
|
|
276
126
|
setChanges(diff.changes);
|
|
277
127
|
|
|
278
128
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
279
129
|
}, [isShowChanges]);
|
|
280
|
-
|
|
281
|
-
window.location.href = url;
|
|
282
|
-
}, []);
|
|
283
|
-
var closeTip = useCallback(function () {
|
|
284
|
-
setShowTip(false);
|
|
285
|
-
|
|
286
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
287
|
-
}, [tipType]);
|
|
288
|
-
var tipSubmit = useCallback(function () {
|
|
289
|
-
if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
|
|
290
|
-
context.deleteSdocRevision().then(function (res) {
|
|
291
|
-
if (res.data.success) {
|
|
292
|
-
// 通知其他用户文档已经发布
|
|
293
|
-
var targetURL = "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath);
|
|
294
|
-
editorRef.current.publishDocument(targetURL);
|
|
295
|
-
// 跳转页面
|
|
296
|
-
jumpToURL(targetURL);
|
|
297
|
-
setShowTip(false);
|
|
298
|
-
}
|
|
299
|
-
}).catch(function (error) {
|
|
300
|
-
toaster.danger(t('Error'));
|
|
301
|
-
});
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (tipType === TIP_TYPE.MERGE) {
|
|
305
|
-
context.mergeSdocRevision().then(function (res) {
|
|
306
|
-
var origin_file_version = res.data.origin_file_version;
|
|
307
|
-
context.updateSettings({
|
|
308
|
-
'originFileVersion': origin_file_version
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// 通知其他用户合并文档 并更新
|
|
312
|
-
editorRef.current.mergeDocument(mergeValue, origin_file_version);
|
|
313
|
-
|
|
314
|
-
// 当前用户更新内容
|
|
315
|
-
editorRef.current.setLoading(true);
|
|
316
|
-
editorRef.current.setSlateValue(mergeValue);
|
|
317
|
-
setMode(MODE.EDITOR);
|
|
318
|
-
editorRef.current.setEditorMode(MODE.EDITOR);
|
|
319
|
-
editorRef.current.setLoading(false);
|
|
320
|
-
setShowTip(false);
|
|
321
|
-
}).catch(function (error) {
|
|
322
|
-
toaster.danger(t('Error'));
|
|
323
|
-
});
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
setShowTip(false);
|
|
327
|
-
|
|
328
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
329
|
-
}, [tipType, originFileURL, mergeValue, editorRef.current]);
|
|
330
|
-
if (isLoadingSdoc) {
|
|
130
|
+
if (isFirstLoad && !errorMessage) {
|
|
331
131
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
332
132
|
}
|
|
333
|
-
if (errorMessage) {
|
|
133
|
+
if (isFirstLoad && errorMessage) {
|
|
334
134
|
return /*#__PURE__*/React.createElement("div", {
|
|
335
135
|
className: "error-page"
|
|
336
136
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -343,21 +143,25 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
343
143
|
isEditMode: !isShowChanges
|
|
344
144
|
}), /*#__PURE__*/React.createElement(DocOperations, {
|
|
345
145
|
isShowChanges: isShowChanges,
|
|
346
|
-
mode: mode,
|
|
347
146
|
changes: changes,
|
|
348
|
-
toggleViewChanges: toggleViewChanges,
|
|
349
|
-
publishRevision: publishRevision,
|
|
350
|
-
abortRebase: abortRebase
|
|
351
|
-
})), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
|
|
352
|
-
ref: editorRef,
|
|
353
|
-
document: document,
|
|
354
|
-
mode: mode,
|
|
355
|
-
setDiffChanges: setDiffChanges,
|
|
356
147
|
toggleViewChanges: toggleViewChanges
|
|
357
|
-
}))
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
148
|
+
})), /*#__PURE__*/React.createElement(Content, null, isLoadingSdoc && /*#__PURE__*/React.createElement("div", {
|
|
149
|
+
className: "w-100 h-100 d-flex align-items-center justify-content-center"
|
|
150
|
+
}, /*#__PURE__*/React.createElement(Loading, null)), !isLoadingSdoc && errorMessage && /*#__PURE__*/React.createElement("div", {
|
|
151
|
+
className: "error-page"
|
|
152
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
153
|
+
className: "error-tip"
|
|
154
|
+
}, t(errorMessage))), !isLoadingSdoc && !errorMessage && /*#__PURE__*/React.createElement(React.Fragment, null, isShowChanges ? /*#__PURE__*/React.createElement(DiffViewer, {
|
|
155
|
+
showToolbar: true,
|
|
156
|
+
showOutline: true,
|
|
157
|
+
currentContent: currentContent,
|
|
158
|
+
lastContent: lastContent,
|
|
159
|
+
didMountCallback: setDiffChanges
|
|
160
|
+
}) : /*#__PURE__*/React.createElement(SDocEditor, {
|
|
161
|
+
config: context.getEditorConfig(),
|
|
162
|
+
document: document,
|
|
163
|
+
ref: editorRef,
|
|
164
|
+
isOpenSocket: context.getSetting('isOpenSocket')
|
|
165
|
+
})))));
|
|
362
166
|
};
|
|
363
167
|
export default withTranslation('sdoc-editor')(SimpleEditor);
|
package/package.json
CHANGED
|
@@ -362,17 +362,5 @@
|
|
|
362
362
|
"No_changes": "No changes",
|
|
363
363
|
"Title": "Title",
|
|
364
364
|
"Subtitle": "Subtitle",
|
|
365
|
-
"Link_sdoc": "Link sdoc"
|
|
366
|
-
"Keep_my_modification": "Keep my modification",
|
|
367
|
-
"Keep_other_modification": "Keep other's modification",
|
|
368
|
-
"Keep_both_modification": "Keep my modification",
|
|
369
|
-
"Need_rebase": "Need rebase",
|
|
370
|
-
"Abort": "Abort",
|
|
371
|
-
"Tip": "Tip",
|
|
372
|
-
"Rebase_delete_no_change_revision_tip": "Revision has not made any change compared to original document. Do you want to delete this revision?",
|
|
373
|
-
"Has_been_merge_tip": "Revision has been merged, please refresh the page to see the latest content.",
|
|
374
|
-
"Has_been_published_tip": "Revision has been published, Automatically jump to source content after {{ time }} seconds.",
|
|
375
|
-
"Has_conflict_before_publish_tip": "There are conflicts in the document, please resolve it before publishing!",
|
|
376
|
-
"Merge_tip": "There are conflicts in the documents. Do you want to merge them?",
|
|
377
|
-
"Has_conflict_before_view_changes_tip": "There are conflicts in the document. Please resolve the conflict before viewing the changes!"
|
|
365
|
+
"Link_sdoc": "Link sdoc"
|
|
378
366
|
}
|
|
@@ -362,16 +362,5 @@
|
|
|
362
362
|
"No_changes": "没有变化",
|
|
363
363
|
"Title": "标题",
|
|
364
364
|
"Subtitle": "副标题",
|
|
365
|
-
"Link_sdoc": "链接 sdoc"
|
|
366
|
-
"Keep_my_modification": "保留我的更改",
|
|
367
|
-
"Keep_other_modification": "保留其他的更改",
|
|
368
|
-
"Keep_both_modification": "保留两个更改",
|
|
369
|
-
"Need_rebase": "需要变基",
|
|
370
|
-
"Abort": "中止",
|
|
371
|
-
"Rebase_delete_no_change_revision_tip": "修订改没有更改,是否删除修订稿?",
|
|
372
|
-
"Has_been_merge_tip": "修订稿被合并了,请刷新页面查看最新内容。",
|
|
373
|
-
"Has_been_published_tip": "修订稿已经发布了,{{ time }} 秒后自动跳转到源文件.",
|
|
374
|
-
"Has_conflict_before_publish_tip": "文档有冲突,请解决冲突后再发布!",
|
|
375
|
-
"Merge_tip": "文档有冲突,是否合并?",
|
|
376
|
-
"Has_conflict_before_view_changes_tip": "文档有冲突,请解决冲突后再查看更改!"
|
|
365
|
+
"Link_sdoc": "链接 sdoc"
|
|
377
366
|
}
|