@seafile/sdoc-editor 0.1.167 → 0.1.169-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/basic-sdk/editor/index.js +11 -14
- package/dist/basic-sdk/views/sdoc-diff-viewer.js +3 -1
- package/dist/components/doc-operations/index.js +4 -4
- package/dist/components/doc-operations/revision-operations/index.js +186 -5
- package/dist/components/doc-operations/revision-operations/more-revision-operations/index.js +2 -2
- package/dist/components/doc-operations/revision-operations/{publish-button.js → publish-revision/index.js} +2 -2
- package/dist/components/doc-operations/revision-operations/view-changes/index.js +8 -8
- package/dist/components/tip-dialog/index.js +25 -15
- package/dist/hooks/use-document.js +80 -0
- package/dist/pages/simple-editor.js +33 -269
- package/package.json +1 -1
- package/dist/components/doc-operations/revision-operations/revision-operations.js +0 -60
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
4
|
import React, { useMemo, useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react';
|
|
4
5
|
import deepCopy from 'deep-copy';
|
|
@@ -11,7 +12,9 @@ import { withSocketIO } from '../socket';
|
|
|
11
12
|
import SDocEditor from './sdoc-editor';
|
|
12
13
|
import './index.css';
|
|
13
14
|
var Editor = forwardRef(function (_ref, ref) {
|
|
14
|
-
var document = _ref.document
|
|
15
|
+
var document = _ref.document,
|
|
16
|
+
_ref$isReloading = _ref.isReloading,
|
|
17
|
+
isReloading = _ref$isReloading === void 0 ? false : _ref$isReloading;
|
|
15
18
|
var editor = useMemo(function () {
|
|
16
19
|
var defaultEditor = createDefaultEditor();
|
|
17
20
|
var editorConfig = context.getEditorConfig();
|
|
@@ -26,14 +29,10 @@ var Editor = forwardRef(function (_ref, ref) {
|
|
|
26
29
|
|
|
27
30
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
31
|
}, []);
|
|
29
|
-
var _useState = useState(
|
|
32
|
+
var _useState = useState(document.children),
|
|
30
33
|
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _useState3 = useState(document.children),
|
|
34
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
-
slateValue = _useState4[0],
|
|
36
|
-
_setSlateValue = _useState4[1];
|
|
34
|
+
slateValue = _useState2[0],
|
|
35
|
+
_setSlateValue = _useState2[1];
|
|
37
36
|
|
|
38
37
|
// useMount: init socket connection
|
|
39
38
|
useEffect(function () {
|
|
@@ -53,12 +52,10 @@ var Editor = forwardRef(function (_ref, ref) {
|
|
|
53
52
|
// The parent component can call the method of this component through ref
|
|
54
53
|
useImperativeHandle(ref, function () {
|
|
55
54
|
return {
|
|
56
|
-
// set value
|
|
57
|
-
setLoading: function setLoading(isLoading) {
|
|
58
|
-
_setLoading(isLoading);
|
|
59
|
-
},
|
|
60
55
|
setSlateValue: function setSlateValue(document) {
|
|
61
|
-
|
|
56
|
+
// Force update of editor's child elements
|
|
57
|
+
editor.children = document.children;
|
|
58
|
+
_setSlateValue(_toConsumableArray(document.children));
|
|
62
59
|
},
|
|
63
60
|
updateDocumentVersion: function updateDocumentVersion(document) {
|
|
64
61
|
editor.updateDocumentVersion(document);
|
|
@@ -73,7 +70,7 @@ var Editor = forwardRef(function (_ref, ref) {
|
|
|
73
70
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
71
|
};
|
|
75
72
|
}, [document, editor, slateValue]);
|
|
76
|
-
if (
|
|
73
|
+
if (isReloading) {
|
|
77
74
|
return /*#__PURE__*/React.createElement("div", {
|
|
78
75
|
className: "h-100 w-100 d-flex align-items-center justify-content-center"
|
|
79
76
|
}, /*#__PURE__*/React.createElement(CommonLoading, null));
|
|
@@ -9,7 +9,9 @@ var DiffViewer = function DiffViewer(_ref) {
|
|
|
9
9
|
var diff = getDiff(currentContent, lastContent);
|
|
10
10
|
useEffect(function () {
|
|
11
11
|
didMountCallback && didMountCallback(diff);
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
}, []);
|
|
13
15
|
return /*#__PURE__*/React.createElement(SDocViewer, {
|
|
14
16
|
showToolbar: false,
|
|
15
17
|
showOutline: false,
|
|
@@ -11,16 +11,16 @@ import './style.css';
|
|
|
11
11
|
var DocOperations = function DocOperations(_ref) {
|
|
12
12
|
var isShowChanges = _ref.isShowChanges,
|
|
13
13
|
changes = _ref.changes,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
handleViewChangesToggle = _ref.handleViewChangesToggle,
|
|
15
|
+
handleRevisionPublished = _ref.handleRevisionPublished;
|
|
16
16
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
17
17
|
return /*#__PURE__*/React.createElement("div", {
|
|
18
18
|
className: "doc-ops"
|
|
19
19
|
}, /*#__PURE__*/React.createElement(RevisionOperations, {
|
|
20
20
|
isShowChanges: isShowChanges,
|
|
21
21
|
changes: changes,
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
handleViewChangesToggle: handleViewChangesToggle,
|
|
23
|
+
handleRevisionPublished: handleRevisionPublished
|
|
24
24
|
}), /*#__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));
|
|
25
25
|
};
|
|
26
26
|
export default withTranslation('sdoc-editor')(DocOperations);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import { EventBus } from '../../../basic-sdk';
|
|
4
|
+
import { getRebase, hasConflict } from '../../../basic-sdk/utils/rebase';
|
|
2
5
|
import context from '../../../context';
|
|
3
|
-
import
|
|
6
|
+
import { EXTERNAL_EVENT, TIP_TYPE } from '../../../constants';
|
|
7
|
+
import { useDocument } from '../../../hooks/use-document';
|
|
8
|
+
import toaster from '../../toast';
|
|
9
|
+
import TipDialog from '../../tip-dialog';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
11
|
+
import PublishRevision from './publish-revision';
|
|
4
12
|
import ViewChanges from './view-changes';
|
|
5
13
|
import MoreRevisionOperations from './more-revision-operations';
|
|
6
14
|
import Revisions from './revisions';
|
|
@@ -8,17 +16,190 @@ import ChangesCount from './changes-count';
|
|
|
8
16
|
var RevisionOperations = function RevisionOperations(_ref) {
|
|
9
17
|
var isShowChanges = _ref.isShowChanges,
|
|
10
18
|
changes = _ref.changes,
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
handleViewChangesToggle = _ref.handleViewChangesToggle,
|
|
20
|
+
handleRevisionPublished = _ref.handleRevisionPublished;
|
|
13
21
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
14
22
|
var isPublished = context.getSetting('isPublished');
|
|
23
|
+
var _useTranslation = useTranslation(),
|
|
24
|
+
t = _useTranslation.t;
|
|
25
|
+
var _useState = useState(false),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
isShowTip = _useState2[0],
|
|
28
|
+
setShowTip = _useState2[1];
|
|
29
|
+
var _useState3 = useState(false),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
tipType = _useState4[0],
|
|
32
|
+
setTipType = _useState4[1];
|
|
33
|
+
var _useState5 = useState(null),
|
|
34
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
35
|
+
mergeValue = _useState6[0],
|
|
36
|
+
setMergeValue = _useState6[1];
|
|
37
|
+
var onDocumentReplaced = useCallback(function () {
|
|
38
|
+
if (isShowTip) return;
|
|
39
|
+
setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
|
|
40
|
+
setShowTip(true);
|
|
41
|
+
}, [isShowTip]);
|
|
42
|
+
var hasPublishRevision = useCallback(function () {
|
|
43
|
+
if (isShowTip) return;
|
|
44
|
+
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
45
|
+
setShowTip(true);
|
|
46
|
+
}, [isShowTip]);
|
|
47
|
+
var onDocumentRemoved = useCallback(function () {
|
|
48
|
+
if (isShowTip) return;
|
|
49
|
+
setTipType(TIP_TYPE.HAS_BEEN_REMOVED);
|
|
50
|
+
setShowTip(true);
|
|
51
|
+
}, [isShowTip]);
|
|
52
|
+
var onError = useCallback(function () {
|
|
53
|
+
toaster.danger(t('Error'));
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
+
}, []);
|
|
57
|
+
useEffect(function () {
|
|
58
|
+
var eventBus = EventBus.getInstance();
|
|
59
|
+
var unsubscribeMergeDocument = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED, onDocumentReplaced);
|
|
60
|
+
var unsubscribeMergeDocumentError = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR, onError);
|
|
61
|
+
var unsubscribePublishDocument = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
|
|
62
|
+
var unsubscribePublishDocumentError = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, onError);
|
|
63
|
+
var unsubscribeRemoveDocument = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT, onDocumentRemoved);
|
|
64
|
+
var unsubscribeRemoveDocumentError = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT_ERROR, onError);
|
|
65
|
+
return function () {
|
|
66
|
+
unsubscribeMergeDocument();
|
|
67
|
+
unsubscribeMergeDocumentError();
|
|
68
|
+
unsubscribePublishDocument();
|
|
69
|
+
unsubscribePublishDocumentError();
|
|
70
|
+
unsubscribeRemoveDocument();
|
|
71
|
+
unsubscribeRemoveDocumentError();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
+
}, []);
|
|
76
|
+
var _useDocument = useDocument(),
|
|
77
|
+
loadDocument = _useDocument.loadDocument;
|
|
78
|
+
|
|
79
|
+
// solve show change view in revision editor
|
|
80
|
+
var onViewChangesToggle = useCallback(function (isShowChanges) {
|
|
81
|
+
if (isShowChanges) {
|
|
82
|
+
// The trick here is to send one more api request in order to use the same information box.
|
|
83
|
+
loadDocument().then(function (revisionContent) {
|
|
84
|
+
// Prevent users from switching if document contains conflicting content
|
|
85
|
+
if (hasConflict(revisionContent.children)) {
|
|
86
|
+
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
|
|
87
|
+
setShowTip(true);
|
|
88
|
+
} else {
|
|
89
|
+
handleViewChangesToggle(isShowChanges);
|
|
90
|
+
}
|
|
91
|
+
}).catch(function (errorMessage) {
|
|
92
|
+
toaster.danger(t(errorMessage));
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
handleViewChangesToggle(isShowChanges);
|
|
97
|
+
}, [handleViewChangesToggle, loadDocument, t]);
|
|
98
|
+
|
|
99
|
+
// publish revision
|
|
100
|
+
var publishRevision = useCallback(function () {
|
|
101
|
+
setShowTip(true);
|
|
102
|
+
setTipType(TIP_TYPE.CHECKING);
|
|
103
|
+
var revisionPromise = loadDocument();
|
|
104
|
+
var baseVersionPromise = context.getRevisionBaseVersionContent();
|
|
105
|
+
var originVersionPromise = context.getSeadocOriginFileContent();
|
|
106
|
+
Promise.all([revisionPromise, baseVersionPromise, originVersionPromise]).then(function (results) {
|
|
107
|
+
var _results = _slicedToArray(results, 3),
|
|
108
|
+
revisionContent = _results[0],
|
|
109
|
+
baseRes = _results[1],
|
|
110
|
+
masterRes = _results[2];
|
|
111
|
+
var baseContent = JSON.parse(baseRes.data.content);
|
|
112
|
+
var masterContent = JSON.parse(masterRes.data.content);
|
|
113
|
+
if (hasConflict(revisionContent.children)) {
|
|
114
|
+
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
var _getRebase = getRebase(masterContent, baseContent, revisionContent),
|
|
118
|
+
canMerge = _getRebase.canMerge,
|
|
119
|
+
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
120
|
+
value = _getRebase.value;
|
|
121
|
+
// change to HAS_BEEN_PUBLISHED
|
|
122
|
+
if (canMerge && isNeedReplaceMaster) {
|
|
123
|
+
setTipType(TIP_TYPE.PUBLISHING);
|
|
124
|
+
context.publishRevision().then(function (res) {
|
|
125
|
+
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
126
|
+
}).catch(function (error) {
|
|
127
|
+
toaster.danger(t('Error'));
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// change to DELETE_NO_CHANGES_REVISION
|
|
133
|
+
if (canMerge && !isNeedReplaceMaster) {
|
|
134
|
+
setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// change to MERGE
|
|
139
|
+
setMergeValue(value);
|
|
140
|
+
setTipType(TIP_TYPE.MERGE);
|
|
141
|
+
}).catch(function (error) {
|
|
142
|
+
if (typeof error === 'string') {
|
|
143
|
+
toaster.danger(t(error));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
toaster.danger(t('Error'));
|
|
147
|
+
});
|
|
148
|
+
}, [loadDocument, t]);
|
|
149
|
+
|
|
150
|
+
// confirm publish
|
|
151
|
+
var onSubmit = useCallback(function () {
|
|
152
|
+
if (tipType === TIP_TYPE.HAS_BEEN_PUBLISHED) {
|
|
153
|
+
// nothing todo
|
|
154
|
+
}
|
|
155
|
+
if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
|
|
156
|
+
context.deleteSdocRevision().then(function (res) {
|
|
157
|
+
// update current location
|
|
158
|
+
var originFileURL = context.getSetting('originFileURL');
|
|
159
|
+
window.location.href = originFileURL;
|
|
160
|
+
}).catch(function (error) {
|
|
161
|
+
toaster.danger(t('Error'));
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (tipType === TIP_TYPE.MERGE) {
|
|
166
|
+
var _context$getUserInfo = context.getUserInfo(),
|
|
167
|
+
username = _context$getUserInfo.username;
|
|
168
|
+
var doc = {
|
|
169
|
+
children: mergeValue.children,
|
|
170
|
+
version: mergeValue.version,
|
|
171
|
+
format_version: mergeValue.format_version,
|
|
172
|
+
last_modify_user: username
|
|
173
|
+
};
|
|
174
|
+
context.updateSdocRevision(doc).then(function (res) {
|
|
175
|
+
var origin_file_version = res.data.origin_file_version;
|
|
176
|
+
context.updateSettings({
|
|
177
|
+
'originFileVersion': origin_file_version
|
|
178
|
+
});
|
|
179
|
+
handleRevisionPublished && handleRevisionPublished(mergeValue);
|
|
180
|
+
setShowTip(false);
|
|
181
|
+
}).catch(function (error) {
|
|
182
|
+
toaster.danger(t('Error'));
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
188
|
+
}, [tipType, mergeValue, document]);
|
|
189
|
+
var onClose = useCallback(function () {
|
|
190
|
+
setShowTip(false);
|
|
191
|
+
}, []);
|
|
15
192
|
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, {
|
|
16
193
|
changes: changes
|
|
17
194
|
}), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
|
|
18
195
|
isShowChanges: isShowChanges,
|
|
19
|
-
|
|
196
|
+
onViewChangesToggle: onViewChangesToggle
|
|
20
197
|
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, {
|
|
21
198
|
publishRevision: publishRevision
|
|
199
|
+
}), isShowTip && /*#__PURE__*/React.createElement(TipDialog, {
|
|
200
|
+
tipType: tipType,
|
|
201
|
+
onSubmit: onSubmit,
|
|
202
|
+
onClose: onClose
|
|
22
203
|
}));
|
|
23
204
|
};
|
|
24
205
|
export default RevisionOperations;
|
package/dist/components/doc-operations/revision-operations/more-revision-operations/index.js
CHANGED
|
@@ -8,8 +8,6 @@ import { REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../../../../
|
|
|
8
8
|
import './index.css';
|
|
9
9
|
var MoreRevisionOperations = function MoreRevisionOperations(_ref) {
|
|
10
10
|
var t = _ref.t;
|
|
11
|
-
var repoID = context.getSetting('repoID');
|
|
12
|
-
var siteRoot = context.getSetting('siteRoot');
|
|
13
11
|
var _useState = useState(false),
|
|
14
12
|
_useState2 = _slicedToArray(_useState, 2),
|
|
15
13
|
isDropdownOpen = _useState2[0],
|
|
@@ -19,6 +17,8 @@ var MoreRevisionOperations = function MoreRevisionOperations(_ref) {
|
|
|
19
17
|
}, []);
|
|
20
18
|
var startRevise = useCallback(function () {
|
|
21
19
|
context.startRevise().then(function (res) {
|
|
20
|
+
var repoID = context.getSetting('repoID');
|
|
21
|
+
var siteRoot = context.getSetting('siteRoot');
|
|
22
22
|
window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/revisions/").concat(res.data.revision_id, "/?").concat(REVISION_FIRST_LOAD_KEY, "=").concat(REVISION_FIRST_LOAD_VALUE);
|
|
23
23
|
}).catch(function (error) {
|
|
24
24
|
toaster.danger(t('Error'));
|
|
@@ -5,7 +5,7 @@ var PublishRevision = function PublishRevision(_ref) {
|
|
|
5
5
|
var publishRevision = _ref.publishRevision;
|
|
6
6
|
var _useTranslation = useTranslation(),
|
|
7
7
|
t = _useTranslation.t;
|
|
8
|
-
var
|
|
8
|
+
var onPublishRevision = useCallback(function (event) {
|
|
9
9
|
event.stopPropagation();
|
|
10
10
|
event.nativeEvent.stopImmediatePropagation();
|
|
11
11
|
publishRevision();
|
|
@@ -14,7 +14,7 @@ var PublishRevision = function PublishRevision(_ref) {
|
|
|
14
14
|
}, []);
|
|
15
15
|
return /*#__PURE__*/React.createElement(Button, {
|
|
16
16
|
color: "success",
|
|
17
|
-
onClick:
|
|
17
|
+
onClick: onPublishRevision,
|
|
18
18
|
className: "ml-4"
|
|
19
19
|
}, t('Publish'));
|
|
20
20
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { UncontrolledTooltip } from 'reactstrap';
|
|
4
4
|
import Switch from '../../../switch';
|
|
5
5
|
import './index.css';
|
|
6
6
|
var ViewChanges = function ViewChanges(_ref) {
|
|
7
7
|
var isShowChanges = _ref.isShowChanges,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
propsOnViewChangesToggle = _ref.onViewChangesToggle;
|
|
9
|
+
var _useTranslation = useTranslation(),
|
|
10
|
+
t = _useTranslation.t;
|
|
11
|
+
var onViewChangesToggle = useCallback(function () {
|
|
12
|
+
propsOnViewChangesToggle(!isShowChanges);
|
|
13
13
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
14
|
}, [isShowChanges]);
|
|
15
15
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -17,11 +17,11 @@ var ViewChanges = function ViewChanges(_ref) {
|
|
|
17
17
|
className: "h-100 ml-4 d-flex align-items-center "
|
|
18
18
|
}, /*#__PURE__*/React.createElement(Switch, {
|
|
19
19
|
checked: isShowChanges,
|
|
20
|
-
onChange:
|
|
20
|
+
onChange: onViewChangesToggle,
|
|
21
21
|
className: "sdoc-toggle-revision-changes d-flex align-items-center"
|
|
22
22
|
})), /*#__PURE__*/React.createElement(UncontrolledTooltip, {
|
|
23
23
|
target: "sdoc-toggle-revision-changes-container",
|
|
24
24
|
fade: false
|
|
25
25
|
}, t('View_changes')));
|
|
26
26
|
};
|
|
27
|
-
export default
|
|
27
|
+
export default ViewChanges;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
|
5
5
|
import classnames from 'classnames';
|
|
@@ -11,28 +11,38 @@ var NOT_CLOSE_DIALOG_TIP_TYPE = [TIP_TYPE.HAS_BEEN_REPLACED, TIP_TYPE.HAS_BEEN_P
|
|
|
11
11
|
var TipDialog = function TipDialog(_ref) {
|
|
12
12
|
var className = _ref.className,
|
|
13
13
|
tipType = _ref.tipType,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
onClose = _ref.onClose,
|
|
15
|
+
propsOnSubmit = _ref.onSubmit;
|
|
16
16
|
var _useTranslation = useTranslation(),
|
|
17
17
|
t = _useTranslation.t;
|
|
18
|
-
var _useState = useState(
|
|
18
|
+
var _useState = useState(),
|
|
19
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
20
20
|
isSubmitting = _useState2[0],
|
|
21
21
|
setSubmitting = _useState2[1];
|
|
22
22
|
var closeDialog = useCallback(function () {
|
|
23
23
|
if (NOT_CLOSE_DIALOG_TIP_TYPE.includes(tipType)) return;
|
|
24
24
|
if (isSubmitting) return;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
onClose && onClose();
|
|
27
26
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
27
|
}, [tipType, isSubmitting]);
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
var onSubmit = useCallback(function () {
|
|
29
|
+
if (tipType === TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES) {
|
|
30
|
+
closeDialog();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setSubmitting(true);
|
|
34
|
+
propsOnSubmit && propsOnSubmit();
|
|
35
|
+
}, [closeDialog, propsOnSubmit, tipType]);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
if (isSubmitting) {
|
|
38
|
+
var timer = setTimeout(function () {
|
|
39
|
+
setSubmitting(false);
|
|
40
|
+
}, 3000);
|
|
41
|
+
return function () {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}, [isSubmitting]);
|
|
36
46
|
return /*#__PURE__*/React.createElement(Modal, {
|
|
37
47
|
isOpen: true,
|
|
38
48
|
autoFocus: false,
|
|
@@ -56,8 +66,8 @@ var TipDialog = function TipDialog(_ref) {
|
|
|
56
66
|
className: classnames('highlight-bg-color', {
|
|
57
67
|
'd-flex align-items-center': isSubmitting
|
|
58
68
|
}),
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
disabled: isSubmitting,
|
|
70
|
+
onClick: onSubmit
|
|
61
71
|
}, isSubmitting && /*#__PURE__*/React.createElement("span", {
|
|
62
72
|
className: "submit-loading-container mr-2"
|
|
63
73
|
}, /*#__PURE__*/React.createElement(CommonLoading, null)), t('Confirm'))));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import context from '../context';
|
|
4
|
+
export var useDocument = function useDocument() {
|
|
5
|
+
var _useState = useState(true),
|
|
6
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
7
|
+
isFirstLoading = _useState2[0],
|
|
8
|
+
setIsFirstLoading = _useState2[1];
|
|
9
|
+
var _useState3 = useState(false),
|
|
10
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
11
|
+
isReloading = _useState4[0],
|
|
12
|
+
setIsReloading = _useState4[1];
|
|
13
|
+
var _useState5 = useState(true),
|
|
14
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
15
|
+
document = _useState6[0],
|
|
16
|
+
setDocument = _useState6[1];
|
|
17
|
+
var _useState7 = useState(''),
|
|
18
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
19
|
+
errorMessage = _useState8[0],
|
|
20
|
+
setErrorMessage = _useState8[1];
|
|
21
|
+
var loadDocument = useCallback(function () {
|
|
22
|
+
return new Promise(function (resolve, reject) {
|
|
23
|
+
context.getFileContent().then(function (res) {
|
|
24
|
+
var result = res.data;
|
|
25
|
+
if (result && !result.children) {
|
|
26
|
+
result = {
|
|
27
|
+
version: 0,
|
|
28
|
+
children: result.content,
|
|
29
|
+
cursors: result.cursors || {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
resolve(result);
|
|
33
|
+
}).catch(function (error) {
|
|
34
|
+
// eslint-disable-next-line
|
|
35
|
+
console.log(error);
|
|
36
|
+
var errorMessage = 'Load_doc_content_error';
|
|
37
|
+
if (error && error.response) {
|
|
38
|
+
var _ref = error.response.data || {},
|
|
39
|
+
error_type = _ref.error_type;
|
|
40
|
+
if (error_type === 'content_invalid') {
|
|
41
|
+
errorMessage = 'Sdoc_format_invalid';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
reject(errorMessage);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
var reloadDocument = useCallback(function () {
|
|
49
|
+
setIsReloading(true);
|
|
50
|
+
loadDocument().then(function (document) {
|
|
51
|
+
setDocument(document);
|
|
52
|
+
setIsReloading(false);
|
|
53
|
+
}).catch(function (errorMessage) {
|
|
54
|
+
setIsReloading(false);
|
|
55
|
+
setErrorMessage(errorMessage);
|
|
56
|
+
setDocument(null);
|
|
57
|
+
setIsReloading(false);
|
|
58
|
+
});
|
|
59
|
+
}, [loadDocument]);
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
loadDocument().then(function (document) {
|
|
62
|
+
setDocument(document);
|
|
63
|
+
setIsFirstLoading(false);
|
|
64
|
+
}).catch(function (errorMessage) {
|
|
65
|
+
setErrorMessage(errorMessage);
|
|
66
|
+
setDocument(null);
|
|
67
|
+
setIsFirstLoading(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
+
}, []);
|
|
72
|
+
return {
|
|
73
|
+
isFirstLoading: isFirstLoading,
|
|
74
|
+
isReloading: isReloading,
|
|
75
|
+
errorMessage: errorMessage,
|
|
76
|
+
document: document,
|
|
77
|
+
loadDocument: loadDocument,
|
|
78
|
+
reloadDocument: reloadDocument
|
|
79
|
+
};
|
|
80
|
+
};
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
2
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
3
|
import { withTranslation } from 'react-i18next';
|
|
6
4
|
import Loading from '../components/loading';
|
|
7
5
|
import DocInfo from '../components/doc-info';
|
|
8
6
|
import DocOperations from '../components/doc-operations';
|
|
9
7
|
import Layout, { Header, Content } from '../layout';
|
|
10
|
-
import { generateDefaultDocContent } from '../utils';
|
|
11
8
|
import context from '../context';
|
|
12
9
|
import ErrorBoundary from './error-boundary';
|
|
13
|
-
import
|
|
14
|
-
import { EXTERNAL_EVENT, TIP_TYPE, REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
|
|
15
|
-
import { getRebase, hasConflict } from '../basic-sdk/utils/rebase';
|
|
10
|
+
import { REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
|
|
16
11
|
import toaster from '../components/toast';
|
|
17
|
-
import {
|
|
12
|
+
import { SDocEditor } from '../basic-sdk';
|
|
18
13
|
import { RevisionDiffViewer } from '../basic-sdk/views';
|
|
14
|
+
import { useDocument } from '../hooks/use-document';
|
|
19
15
|
import '../assets/css/simple-editor.css';
|
|
20
16
|
var SimpleEditor = function SimpleEditor(_ref) {
|
|
21
17
|
var isStarred = _ref.isStarred,
|
|
@@ -23,56 +19,24 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
23
19
|
t = _ref.t;
|
|
24
20
|
context.initApi();
|
|
25
21
|
var editorRef = useRef(null);
|
|
26
|
-
var
|
|
22
|
+
var _useDocument = useDocument(),
|
|
23
|
+
isFirstLoading = _useDocument.isFirstLoading,
|
|
24
|
+
isReloading = _useDocument.isReloading,
|
|
25
|
+
errorMessage = _useDocument.errorMessage,
|
|
26
|
+
document = _useDocument.document,
|
|
27
|
+
reloadDocument = _useDocument.reloadDocument;
|
|
28
|
+
var _useState = useState(false),
|
|
27
29
|
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var _useState3 = useState(
|
|
30
|
+
isShowChanges = _useState2[0],
|
|
31
|
+
setShowChanges = _useState2[1];
|
|
32
|
+
var _useState3 = useState(null),
|
|
31
33
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var _useState5 = useState(
|
|
34
|
+
revisionContent = _useState4[0],
|
|
35
|
+
setRevisionContent = _useState4[1];
|
|
36
|
+
var _useState5 = useState([]),
|
|
35
37
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _useState7 = useState(null),
|
|
39
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
40
|
-
revisionContent = _useState8[0],
|
|
41
|
-
setRevisionContent = _useState8[1];
|
|
42
|
-
var _useState9 = useState(null),
|
|
43
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
44
|
-
document = _useState10[0],
|
|
45
|
-
setDocument = _useState10[1];
|
|
46
|
-
var _useState11 = useState([]),
|
|
47
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
48
|
-
changes = _useState12[0],
|
|
49
|
-
setChanges = _useState12[1];
|
|
50
|
-
var _useState13 = useState(false),
|
|
51
|
-
_useState14 = _slicedToArray(_useState13, 2),
|
|
52
|
-
showTip = _useState14[0],
|
|
53
|
-
setShowTip = _useState14[1];
|
|
54
|
-
var _useState15 = useState(''),
|
|
55
|
-
_useState16 = _slicedToArray(_useState15, 2),
|
|
56
|
-
tipType = _useState16[0],
|
|
57
|
-
setTipType = _useState16[1];
|
|
58
|
-
var _useState17 = useState([]),
|
|
59
|
-
_useState18 = _slicedToArray(_useState17, 2),
|
|
60
|
-
mergeValue = _useState18[0],
|
|
61
|
-
setMergeValue = _useState18[1];
|
|
62
|
-
useEffect(function () {
|
|
63
|
-
loadDocument(function (document) {
|
|
64
|
-
setDocument(document);
|
|
65
|
-
setLoadingSdoc(false);
|
|
66
|
-
}, function (errorMessage) {
|
|
67
|
-
setErrorMessage(errorMessage);
|
|
68
|
-
setDocument(null);
|
|
69
|
-
setLoadingSdoc(false);
|
|
70
|
-
}, function () {
|
|
71
|
-
setLoadingSdoc(true);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
-
}, []);
|
|
38
|
+
changes = _useState6[0],
|
|
39
|
+
setChanges = _useState6[1];
|
|
76
40
|
|
|
77
41
|
// useMount: reset title
|
|
78
42
|
useEffect(function () {
|
|
@@ -96,226 +60,29 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
96
60
|
|
|
97
61
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
62
|
}, []);
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
|
|
102
|
-
setShowTip(true);
|
|
103
|
-
|
|
104
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
-
}, [editorRef, showTip]);
|
|
106
|
-
var hasPublishRevision = useCallback(function () {
|
|
107
|
-
if (showTip) return;
|
|
108
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
109
|
-
setShowTip(true);
|
|
110
|
-
|
|
111
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
|
-
}, [editorRef, showTip]);
|
|
113
|
-
var onError = useCallback(function () {
|
|
114
|
-
toaster.danger(t('Error'));
|
|
115
|
-
|
|
116
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
-
}, []);
|
|
118
|
-
var onDocumentRemoved = useCallback(function () {
|
|
119
|
-
if (showTip) return;
|
|
120
|
-
setTipType(TIP_TYPE.HAS_BEEN_REMOVED);
|
|
121
|
-
setShowTip(true);
|
|
122
|
-
|
|
123
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
124
|
-
}, [showTip]);
|
|
125
|
-
useEffect(function () {
|
|
126
|
-
var eventBus = EventBus.getInstance();
|
|
127
|
-
var unsubscribeMergeDocument = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED, onDocumentReplaced);
|
|
128
|
-
var unsubscribePublishDocument = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
|
|
129
|
-
var unsubscribeMergeDocumentError = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR, onError);
|
|
130
|
-
var unsubscribePublishDocumentError = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, onError);
|
|
131
|
-
var unsubscribeRemoveDocument = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT, onDocumentRemoved);
|
|
132
|
-
var unsubscribeRemoveDocumentError = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT_ERROR, onError);
|
|
133
|
-
return function () {
|
|
134
|
-
unsubscribeMergeDocument();
|
|
135
|
-
unsubscribePublishDocument();
|
|
136
|
-
unsubscribeMergeDocumentError();
|
|
137
|
-
unsubscribePublishDocumentError();
|
|
138
|
-
unsubscribeRemoveDocument();
|
|
139
|
-
unsubscribeRemoveDocumentError();
|
|
140
|
-
};
|
|
141
|
-
|
|
63
|
+
var setDiffChanges = useCallback(function (diff) {
|
|
64
|
+
setChanges(diff.changes);
|
|
142
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
143
|
-
}, []);
|
|
144
|
-
var
|
|
145
|
-
callback && callback();
|
|
146
|
-
context.getFileContent().then(function (res) {
|
|
147
|
-
var result = res.data || generateDefaultDocContent();
|
|
148
|
-
if (result && !result.children) {
|
|
149
|
-
result = {
|
|
150
|
-
version: 0,
|
|
151
|
-
children: result.content,
|
|
152
|
-
cursors: result.cursors || {}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
successCallback && successCallback(result);
|
|
156
|
-
}).catch(function (error) {
|
|
157
|
-
// eslint-disable-next-line
|
|
158
|
-
console.log(error);
|
|
159
|
-
var errorMessage = 'Load_doc_content_error';
|
|
160
|
-
if (error && error.response) {
|
|
161
|
-
var _ref2 = error.response.data || {},
|
|
162
|
-
error_type = _ref2.error_type;
|
|
163
|
-
if (error_type === 'content_invalid') {
|
|
164
|
-
errorMessage = 'Sdoc_format_invalid';
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
errorCallback && errorCallback(errorMessage);
|
|
168
|
-
});
|
|
169
|
-
}, []);
|
|
170
|
-
var toggleViewChanges = useCallback(function (isShowChanges) {
|
|
66
|
+
}, [isShowChanges]);
|
|
67
|
+
var handleViewChangesToggle = useCallback(function (isShowChanges) {
|
|
171
68
|
if (!isShowChanges) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
setShowChanges(isShowChanges);
|
|
175
|
-
editorRef.current.setLoading(false);
|
|
176
|
-
}, function (errorMessage) {
|
|
177
|
-
setErrorMessage(errorMessage);
|
|
178
|
-
editorRef.current.setLoading(false);
|
|
179
|
-
});
|
|
69
|
+
setShowChanges(isShowChanges);
|
|
70
|
+
reloadDocument();
|
|
180
71
|
return;
|
|
181
72
|
}
|
|
182
73
|
|
|
183
74
|
// Get the contents of the current revision
|
|
184
75
|
var revisionContent = editorRef.current.getSlateValue();
|
|
185
|
-
|
|
186
|
-
// Prevent users from switching if document contains conflicting content
|
|
187
|
-
if (hasConflict(revisionContent.children)) {
|
|
188
|
-
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
|
|
189
|
-
setShowTip(true);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Record the contents of the current revision
|
|
194
76
|
setRevisionContent(revisionContent);
|
|
195
77
|
setShowChanges(isShowChanges);
|
|
196
78
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
197
79
|
}, [document, editorRef.current]);
|
|
198
|
-
var
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
var publishRevision = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
203
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
204
|
-
while (1) switch (_context.prev = _context.next) {
|
|
205
|
-
case 0:
|
|
206
|
-
setTipType(TIP_TYPE.CHECKING);
|
|
207
|
-
setShowTip(true);
|
|
208
|
-
loadDocument(function (document) {
|
|
209
|
-
var revisionContent = document;
|
|
210
|
-
if (hasConflict(revisionContent.children)) {
|
|
211
|
-
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
|
|
212
|
-
setShowTip(true);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
var baseContent;
|
|
216
|
-
var masterContent;
|
|
217
|
-
context.getRevisionBaseVersionContent().then(function (res) {
|
|
218
|
-
var baseVersionContentString = res.data.content; // commit content
|
|
219
|
-
baseContent = JSON.parse(baseVersionContentString);
|
|
220
|
-
return context.getSeadocOriginFileContent();
|
|
221
|
-
}).then(function (res) {
|
|
222
|
-
var masterContentString = res.data.content;
|
|
223
|
-
masterContent = JSON.parse(masterContentString);
|
|
224
|
-
var _getRebase = getRebase(masterContent, baseContent, revisionContent),
|
|
225
|
-
canMerge = _getRebase.canMerge,
|
|
226
|
-
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
227
|
-
value = _getRebase.value;
|
|
228
|
-
if (canMerge && isNeedReplaceMaster) {
|
|
229
|
-
setTipType(TIP_TYPE.PUBLISHING);
|
|
230
|
-
context.publishRevision().then(function (res) {
|
|
231
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
232
|
-
setShowTip(true);
|
|
233
|
-
}).catch(function (error) {
|
|
234
|
-
toaster.danger(t('Error'));
|
|
235
|
-
});
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (canMerge && !isNeedReplaceMaster) {
|
|
239
|
-
setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
|
|
240
|
-
setShowTip(true);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
setMergeValue(value);
|
|
244
|
-
setTipType(TIP_TYPE.MERGE);
|
|
245
|
-
setShowTip(true);
|
|
246
|
-
}).catch(function (error) {
|
|
247
|
-
toaster.danger(t('Error'));
|
|
248
|
-
});
|
|
249
|
-
}, function (errorMessage) {
|
|
250
|
-
toaster.danger(t(errorMessage));
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
-
case 3:
|
|
255
|
-
case "end":
|
|
256
|
-
return _context.stop();
|
|
257
|
-
}
|
|
258
|
-
}, _callee);
|
|
259
|
-
})), [isShowChanges]);
|
|
260
|
-
var jumpToURL = useCallback(function (url) {
|
|
261
|
-
window.location.href = url;
|
|
80
|
+
var handleRevisionPublished = useCallback(function (value) {
|
|
81
|
+
setShowChanges(false);
|
|
82
|
+
editorRef.current.setSlateValue(value);
|
|
83
|
+
editorRef.current.updateDocumentVersion(value);
|
|
262
84
|
}, []);
|
|
263
|
-
|
|
264
|
-
setShowTip(false);
|
|
265
|
-
|
|
266
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
267
|
-
}, [tipType]);
|
|
268
|
-
var tipSubmit = useCallback(function (callback) {
|
|
269
|
-
if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
|
|
270
|
-
callback && callback(true);
|
|
271
|
-
context.deleteSdocRevision().then(function (res) {
|
|
272
|
-
callback && callback(false);
|
|
273
|
-
setShowTip(false);
|
|
274
|
-
var originFileURL = context.getSetting('originFileURL');
|
|
275
|
-
jumpToURL(originFileURL);
|
|
276
|
-
}).catch(function (error) {
|
|
277
|
-
callback && callback(false);
|
|
278
|
-
toaster.danger(t('Error'));
|
|
279
|
-
});
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (tipType === TIP_TYPE.MERGE) {
|
|
283
|
-
callback && callback(true);
|
|
284
|
-
var _context$getUserInfo = context.getUserInfo(),
|
|
285
|
-
username = _context$getUserInfo.username;
|
|
286
|
-
var doc = {
|
|
287
|
-
children: mergeValue.children,
|
|
288
|
-
version: mergeValue.version,
|
|
289
|
-
format_version: document.format_version,
|
|
290
|
-
docName: document.docName,
|
|
291
|
-
last_modify_user: username
|
|
292
|
-
};
|
|
293
|
-
context.updateSdocRevision(doc).then(function (res) {
|
|
294
|
-
callback && callback(false);
|
|
295
|
-
var origin_file_version = res.data.origin_file_version;
|
|
296
|
-
context.updateSettings({
|
|
297
|
-
'originFileVersion': origin_file_version
|
|
298
|
-
});
|
|
299
|
-
// if revision diff view change to sdoc editor
|
|
300
|
-
if (isShowChanges) {
|
|
301
|
-
setShowChanges(false);
|
|
302
|
-
}
|
|
303
|
-
editorRef.current.setLoading(true);
|
|
304
|
-
editorRef.current.setSlateValue(mergeValue);
|
|
305
|
-
editorRef.current.updateDocumentVersion(mergeValue);
|
|
306
|
-
editorRef.current.setLoading(false);
|
|
307
|
-
setShowTip(false);
|
|
308
|
-
}).catch(function (error) {
|
|
309
|
-
callback && callback(false);
|
|
310
|
-
toaster.danger(t('Error'));
|
|
311
|
-
});
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
setShowTip(false);
|
|
315
|
-
|
|
316
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
317
|
-
}, [tipType, mergeValue, editorRef.current, document]);
|
|
318
|
-
if (isLoadingSdoc) {
|
|
85
|
+
if (isFirstLoading) {
|
|
319
86
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
320
87
|
}
|
|
321
88
|
if (errorMessage) {
|
|
@@ -332,18 +99,15 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
332
99
|
}), /*#__PURE__*/React.createElement(DocOperations, {
|
|
333
100
|
isShowChanges: isShowChanges,
|
|
334
101
|
changes: changes,
|
|
335
|
-
|
|
336
|
-
|
|
102
|
+
handleViewChangesToggle: handleViewChangesToggle,
|
|
103
|
+
handleRevisionPublished: handleRevisionPublished
|
|
337
104
|
})), /*#__PURE__*/React.createElement(Content, null, !isShowChanges && /*#__PURE__*/React.createElement(SDocEditor, {
|
|
338
105
|
ref: editorRef,
|
|
106
|
+
isReloading: isReloading,
|
|
339
107
|
document: document
|
|
340
108
|
}), isShowChanges && /*#__PURE__*/React.createElement(RevisionDiffViewer, {
|
|
341
109
|
revisionContent: revisionContent,
|
|
342
110
|
didMountCallback: setDiffChanges
|
|
343
|
-
})))
|
|
344
|
-
toggle: closeTip,
|
|
345
|
-
submit: tipSubmit,
|
|
346
|
-
tipType: tipType
|
|
347
|
-
}));
|
|
111
|
+
}))));
|
|
348
112
|
};
|
|
349
113
|
export default withTranslation('sdoc-editor')(SimpleEditor);
|
package/package.json
CHANGED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
2
|
-
import { Button } from 'reactstrap';
|
|
3
|
-
import { withTranslation } from 'react-i18next';
|
|
4
|
-
import context from '../../../context';
|
|
5
|
-
import toaster from '../../toast';
|
|
6
|
-
var RevisionOperations = function RevisionOperations(_ref) {
|
|
7
|
-
var t = _ref.t;
|
|
8
|
-
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
9
|
-
var revisionURL = context.getSetting('revisionURL');
|
|
10
|
-
var isPublished = context.getSetting('isPublished');
|
|
11
|
-
var repoID = context.getSetting('repoID');
|
|
12
|
-
var siteRoot = context.getSetting('siteRoot');
|
|
13
|
-
var viewChanges = useCallback(function (event) {
|
|
14
|
-
event.stopPropagation();
|
|
15
|
-
event.nativeEvent.stopImmediatePropagation();
|
|
16
|
-
window.location.href = revisionURL;
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
|
-
}, []);
|
|
20
|
-
var publishRevision = useCallback(function (event) {
|
|
21
|
-
event.stopPropagation();
|
|
22
|
-
event.nativeEvent.stopImmediatePropagation();
|
|
23
|
-
context.publishSdocRevision().then(function (res) {
|
|
24
|
-
var origin_file_path = res.data.origin_file_path;
|
|
25
|
-
window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
|
|
26
|
-
}).catch(function (error) {
|
|
27
|
-
toaster.danger(t('Error'));
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
-
}, []);
|
|
32
|
-
var startRevise = useCallback(function () {
|
|
33
|
-
context.startRevise().then(function (res) {
|
|
34
|
-
window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(res.data.file_path);
|
|
35
|
-
}).catch(function (error) {
|
|
36
|
-
toaster.danger(t('Error'));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
}, []);
|
|
41
|
-
var startReviseBtn = useCallback(function (className) {
|
|
42
|
-
return /*#__PURE__*/React.createElement(Button, {
|
|
43
|
-
color: "success",
|
|
44
|
-
className: className,
|
|
45
|
-
onClick: startRevise
|
|
46
|
-
}, t('Start_revise'));
|
|
47
|
-
|
|
48
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
-
}, []);
|
|
50
|
-
if (!isSdocRevision) return startReviseBtn();
|
|
51
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, !isPublished && revisionURL && /*#__PURE__*/React.createElement(Button, {
|
|
52
|
-
color: "success",
|
|
53
|
-
className: "mr-4",
|
|
54
|
-
onClick: viewChanges
|
|
55
|
-
}, t('View_changes')), !isPublished && /*#__PURE__*/React.createElement(Button, {
|
|
56
|
-
color: "success",
|
|
57
|
-
onClick: publishRevision
|
|
58
|
-
}, t('Publish')));
|
|
59
|
-
};
|
|
60
|
-
export default withTranslation('sdoc-editor')(RevisionOperations);
|