@seafile/sdoc-editor 0.1.169 → 0.1.170
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/comment/comment/comment-editor.js +8 -3
- package/dist/basic-sdk/comment/comment/comment-item-wrapper.js +4 -2
- package/dist/basic-sdk/comment/comment/comment-list.js +8 -3
- package/dist/basic-sdk/comment/comment/editor-comment.js +9 -3
- package/dist/basic-sdk/editor/index.js +1 -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/pages/simple-editor.js +19 -202
- package/package.json +1 -1
- package/dist/components/doc-operations/revision-operations/revision-operations.js +0 -60
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { Button } from 'reactstrap';
|
|
6
6
|
var getSubmitTip = function getSubmitTip(type, content) {
|
|
7
7
|
if (content) return 'Save';
|
|
@@ -15,8 +15,10 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
15
15
|
insertContent = _ref.insertContent,
|
|
16
16
|
updateContent = _ref.updateContent,
|
|
17
17
|
setIsEditing = _ref.setIsEditing,
|
|
18
|
-
|
|
18
|
+
hiddenComment = _ref.hiddenComment;
|
|
19
19
|
var commentRef = useRef();
|
|
20
|
+
var _useTranslation = useTranslation(),
|
|
21
|
+
t = _useTranslation.t;
|
|
20
22
|
var _useState = useState(false),
|
|
21
23
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
24
|
isFocus = _useState2[0],
|
|
@@ -48,6 +50,9 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
48
50
|
setIsFocus(false);
|
|
49
51
|
commentRef.current.textContent = '';
|
|
50
52
|
setIsEditing && setIsEditing(false);
|
|
53
|
+
hiddenComment && hiddenComment(false);
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
56
|
}, [setIsEditing]);
|
|
52
57
|
var onKeyDown = useCallback(function (event) {
|
|
53
58
|
// enter
|
|
@@ -88,4 +93,4 @@ var CommentEditor = function CommentEditor(_ref) {
|
|
|
88
93
|
CommentEditor.defaultProps = {
|
|
89
94
|
placeholder: 'Enter_a_comment'
|
|
90
95
|
};
|
|
91
|
-
export default
|
|
96
|
+
export default CommentEditor;
|
|
@@ -17,7 +17,8 @@ export default function CommentItemWrapper(_ref) {
|
|
|
17
17
|
isActive = _ref.isActive,
|
|
18
18
|
comment = _ref.comment,
|
|
19
19
|
onCommentClick = _ref.onCommentClick,
|
|
20
|
-
updateScrollPosition = _ref.updateScrollPosition
|
|
20
|
+
updateScrollPosition = _ref.updateScrollPosition,
|
|
21
|
+
hiddenComment = _ref.hiddenComment;
|
|
21
22
|
var listRef = useRef(null);
|
|
22
23
|
var _useCommentContext = useCommentContext(),
|
|
23
24
|
dispatch = _useCommentContext.dispatch;
|
|
@@ -360,7 +361,8 @@ export default function CommentItemWrapper(_ref) {
|
|
|
360
361
|
className: "mt-4",
|
|
361
362
|
type: "reply",
|
|
362
363
|
placeholder: tip,
|
|
363
|
-
insertContent: insertContent
|
|
364
|
+
insertContent: insertContent,
|
|
365
|
+
hiddenComment: hiddenComment
|
|
364
366
|
}), isShowDeleteDialog && isActive && /*#__PURE__*/React.createElement(CommentDeleteShadow, {
|
|
365
367
|
type: 'comment',
|
|
366
368
|
deleteConfirm: _deleteComment,
|
|
@@ -12,7 +12,8 @@ import CommentItemWrapper from './comment-item-wrapper';
|
|
|
12
12
|
import './comment-list.css';
|
|
13
13
|
var CommentList = function CommentList(_ref) {
|
|
14
14
|
var comments = _ref.comments,
|
|
15
|
-
selectionElement = _ref.selectionElement
|
|
15
|
+
selectionElement = _ref.selectionElement,
|
|
16
|
+
hiddenComment = _ref.hiddenComment;
|
|
16
17
|
var commentRef = useRef(null);
|
|
17
18
|
var position = useCommentListPosition();
|
|
18
19
|
var _useState = useState(false),
|
|
@@ -102,7 +103,10 @@ var CommentList = function CommentList(_ref) {
|
|
|
102
103
|
key: comment.id,
|
|
103
104
|
comment: comment,
|
|
104
105
|
isActive: isActive,
|
|
105
|
-
onCommentClick: onCommentClick
|
|
106
|
+
onCommentClick: onCommentClick,
|
|
107
|
+
hiddenComment: function hiddenComment() {
|
|
108
|
+
return setActiveComment(null);
|
|
109
|
+
}
|
|
106
110
|
};
|
|
107
111
|
return /*#__PURE__*/React.createElement(CommentItemWrapper, props);
|
|
108
112
|
})), comments.length === 0 && /*#__PURE__*/React.createElement("div", {
|
|
@@ -110,7 +114,8 @@ var CommentList = function CommentList(_ref) {
|
|
|
110
114
|
}, /*#__PURE__*/React.createElement(CommentEditor, {
|
|
111
115
|
type: "comment",
|
|
112
116
|
insertContent: insertContent,
|
|
113
|
-
selectionElement: selectionElement
|
|
117
|
+
selectionElement: selectionElement,
|
|
118
|
+
hiddenComment: hiddenComment
|
|
114
119
|
})));
|
|
115
120
|
};
|
|
116
121
|
export default CommentList;
|
|
@@ -51,11 +51,16 @@ var EditorComment = function EditorComment() {
|
|
|
51
51
|
setComments([]);
|
|
52
52
|
setIsShowComments(false);
|
|
53
53
|
}, [element_comments_map, selectionElement, editor.selection]);
|
|
54
|
+
var hiddenComment = useCallback(function () {
|
|
55
|
+
setComments([]);
|
|
56
|
+
setIsShowComments(false);
|
|
57
|
+
}, []);
|
|
54
58
|
var onHiddenComment = useCallback(function (e) {
|
|
55
59
|
if (e.target.className === 'article') {
|
|
56
|
-
|
|
57
|
-
setIsShowComments(false);
|
|
60
|
+
hiddenComment();
|
|
58
61
|
}
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
64
|
}, []);
|
|
60
65
|
useEffect(function () {
|
|
61
66
|
window.addEventListener('click', onHiddenComment);
|
|
@@ -85,7 +90,8 @@ var EditorComment = function EditorComment() {
|
|
|
85
90
|
} : null
|
|
86
91
|
}, isShowComments && /*#__PURE__*/React.createElement(CommentList, {
|
|
87
92
|
comments: comments,
|
|
88
|
-
selectionElement: selectionElement
|
|
93
|
+
selectionElement: selectionElement,
|
|
94
|
+
hiddenComment: hiddenComment
|
|
89
95
|
}))));
|
|
90
96
|
};
|
|
91
97
|
export default EditorComment;
|
|
@@ -53,9 +53,9 @@ var Editor = forwardRef(function (_ref, ref) {
|
|
|
53
53
|
useImperativeHandle(ref, function () {
|
|
54
54
|
return {
|
|
55
55
|
setSlateValue: function setSlateValue(document) {
|
|
56
|
-
_setSlateValue(_toConsumableArray(document.children));
|
|
57
56
|
// Force update of editor's child elements
|
|
58
57
|
editor.children = document.children;
|
|
58
|
+
_setSlateValue(_toConsumableArray(document.children));
|
|
59
59
|
},
|
|
60
60
|
updateDocumentVersion: function updateDocumentVersion(document) {
|
|
61
61
|
editor.updateDocumentVersion(document);
|
|
@@ -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'))));
|
|
@@ -1,6 +1,4 @@
|
|
|
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';
|
|
@@ -9,11 +7,9 @@ import DocOperations from '../components/doc-operations';
|
|
|
9
7
|
import Layout, { Header, Content } from '../layout';
|
|
10
8
|
import context from '../context';
|
|
11
9
|
import ErrorBoundary from './error-boundary';
|
|
12
|
-
import
|
|
13
|
-
import { EXTERNAL_EVENT, TIP_TYPE, REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
|
|
14
|
-
import { getRebase, hasConflict } from '../basic-sdk/utils/rebase';
|
|
10
|
+
import { REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
|
|
15
11
|
import toaster from '../components/toast';
|
|
16
|
-
import {
|
|
12
|
+
import { SDocEditor } from '../basic-sdk';
|
|
17
13
|
import { RevisionDiffViewer } from '../basic-sdk/views';
|
|
18
14
|
import { useDocument } from '../hooks/use-document';
|
|
19
15
|
import '../assets/css/simple-editor.css';
|
|
@@ -23,6 +19,12 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
23
19
|
t = _ref.t;
|
|
24
20
|
context.initApi();
|
|
25
21
|
var editorRef = useRef(null);
|
|
22
|
+
var _useDocument = useDocument(),
|
|
23
|
+
isFirstLoading = _useDocument.isFirstLoading,
|
|
24
|
+
isReloading = _useDocument.isReloading,
|
|
25
|
+
errorMessage = _useDocument.errorMessage,
|
|
26
|
+
document = _useDocument.document,
|
|
27
|
+
reloadDocument = _useDocument.reloadDocument;
|
|
26
28
|
var _useState = useState(false),
|
|
27
29
|
_useState2 = _slicedToArray(_useState, 2),
|
|
28
30
|
isShowChanges = _useState2[0],
|
|
@@ -35,25 +37,6 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
35
37
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
36
38
|
changes = _useState6[0],
|
|
37
39
|
setChanges = _useState6[1];
|
|
38
|
-
var _useState7 = useState(false),
|
|
39
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
40
|
-
showTip = _useState8[0],
|
|
41
|
-
setShowTip = _useState8[1];
|
|
42
|
-
var _useState9 = useState(''),
|
|
43
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
44
|
-
tipType = _useState10[0],
|
|
45
|
-
setTipType = _useState10[1];
|
|
46
|
-
var _useState11 = useState([]),
|
|
47
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
48
|
-
mergeValue = _useState12[0],
|
|
49
|
-
setMergeValue = _useState12[1];
|
|
50
|
-
var _useDocument = useDocument(),
|
|
51
|
-
isFirstLoading = _useDocument.isFirstLoading,
|
|
52
|
-
isReloading = _useDocument.isReloading,
|
|
53
|
-
errorMessage = _useDocument.errorMessage,
|
|
54
|
-
document = _useDocument.document,
|
|
55
|
-
loadDocument = _useDocument.loadDocument,
|
|
56
|
-
reloadDocument = _useDocument.reloadDocument;
|
|
57
40
|
|
|
58
41
|
// useMount: reset title
|
|
59
42
|
useEffect(function () {
|
|
@@ -77,52 +60,11 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
77
60
|
|
|
78
61
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
62
|
}, []);
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
|
|
83
|
-
setShowTip(true);
|
|
84
|
-
|
|
85
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
|
-
}, [editorRef, showTip]);
|
|
87
|
-
var hasPublishRevision = useCallback(function () {
|
|
88
|
-
if (showTip) return;
|
|
89
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
90
|
-
setShowTip(true);
|
|
91
|
-
|
|
92
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
-
}, [editorRef, showTip]);
|
|
94
|
-
var onError = useCallback(function () {
|
|
95
|
-
toaster.danger(t('Error'));
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
|
-
}, []);
|
|
99
|
-
var onDocumentRemoved = useCallback(function () {
|
|
100
|
-
if (showTip) return;
|
|
101
|
-
setTipType(TIP_TYPE.HAS_BEEN_REMOVED);
|
|
102
|
-
setShowTip(true);
|
|
103
|
-
|
|
104
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
-
}, [showTip]);
|
|
106
|
-
useEffect(function () {
|
|
107
|
-
var eventBus = EventBus.getInstance();
|
|
108
|
-
var unsubscribeMergeDocument = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED, onDocumentReplaced);
|
|
109
|
-
var unsubscribePublishDocument = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
|
|
110
|
-
var unsubscribeMergeDocumentError = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR, onError);
|
|
111
|
-
var unsubscribePublishDocumentError = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, onError);
|
|
112
|
-
var unsubscribeRemoveDocument = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT, onDocumentRemoved);
|
|
113
|
-
var unsubscribeRemoveDocumentError = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT_ERROR, onError);
|
|
114
|
-
return function () {
|
|
115
|
-
unsubscribeMergeDocument();
|
|
116
|
-
unsubscribePublishDocument();
|
|
117
|
-
unsubscribeMergeDocumentError();
|
|
118
|
-
unsubscribePublishDocumentError();
|
|
119
|
-
unsubscribeRemoveDocument();
|
|
120
|
-
unsubscribeRemoveDocumentError();
|
|
121
|
-
};
|
|
122
|
-
|
|
63
|
+
var setDiffChanges = useCallback(function (diff) {
|
|
64
|
+
setChanges(diff.changes);
|
|
123
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
124
|
-
}, []);
|
|
125
|
-
var
|
|
66
|
+
}, [isShowChanges]);
|
|
67
|
+
var handleViewChangesToggle = useCallback(function (isShowChanges) {
|
|
126
68
|
if (!isShowChanges) {
|
|
127
69
|
setShowChanges(isShowChanges);
|
|
128
70
|
reloadDocument();
|
|
@@ -131,136 +73,15 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
131
73
|
|
|
132
74
|
// Get the contents of the current revision
|
|
133
75
|
var revisionContent = editorRef.current.getSlateValue();
|
|
134
|
-
|
|
135
|
-
// Prevent users from switching if document contains conflicting content
|
|
136
|
-
if (hasConflict(revisionContent.children)) {
|
|
137
|
-
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
|
|
138
|
-
setShowTip(true);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Record the contents of the current revision
|
|
143
76
|
setRevisionContent(revisionContent);
|
|
144
77
|
setShowChanges(isShowChanges);
|
|
145
78
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
79
|
}, [document, editorRef.current]);
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
var publishRevision = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
152
|
-
var revisionPromise, baseVersionPromise, originVersionPromise;
|
|
153
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
154
|
-
while (1) switch (_context.prev = _context.next) {
|
|
155
|
-
case 0:
|
|
156
|
-
setTipType(TIP_TYPE.CHECKING);
|
|
157
|
-
setShowTip(true);
|
|
158
|
-
revisionPromise = loadDocument();
|
|
159
|
-
baseVersionPromise = context.getRevisionBaseVersionContent();
|
|
160
|
-
originVersionPromise = context.getSeadocOriginFileContent();
|
|
161
|
-
Promise.all([revisionPromise, baseVersionPromise, originVersionPromise]).then(function (results) {
|
|
162
|
-
var _results = _slicedToArray(results, 3),
|
|
163
|
-
revisionContent = _results[0],
|
|
164
|
-
baseRes = _results[1],
|
|
165
|
-
masterRes = _results[2];
|
|
166
|
-
var baseContent = JSON.parse(baseRes.data.content);
|
|
167
|
-
var masterContent = JSON.parse(masterRes.data.content);
|
|
168
|
-
if (hasConflict(revisionContent.children)) {
|
|
169
|
-
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
|
|
170
|
-
setShowTip(true);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
var _getRebase = getRebase(masterContent, baseContent, revisionContent),
|
|
174
|
-
canMerge = _getRebase.canMerge,
|
|
175
|
-
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
176
|
-
value = _getRebase.value;
|
|
177
|
-
if (canMerge && isNeedReplaceMaster) {
|
|
178
|
-
setTipType(TIP_TYPE.PUBLISHING);
|
|
179
|
-
context.publishRevision().then(function (res) {
|
|
180
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
181
|
-
setShowTip(true);
|
|
182
|
-
}).catch(function (error) {
|
|
183
|
-
toaster.danger(t('Error'));
|
|
184
|
-
});
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (canMerge && !isNeedReplaceMaster) {
|
|
188
|
-
setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
|
|
189
|
-
setShowTip(true);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
setMergeValue(value);
|
|
193
|
-
setTipType(TIP_TYPE.MERGE);
|
|
194
|
-
setShowTip(true);
|
|
195
|
-
}).catch(function (error) {
|
|
196
|
-
if (typeof error === 'string') {
|
|
197
|
-
toaster.danger(t(error));
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
toaster.danger(t('Error'));
|
|
201
|
-
});
|
|
202
|
-
case 6:
|
|
203
|
-
case "end":
|
|
204
|
-
return _context.stop();
|
|
205
|
-
}
|
|
206
|
-
}, _callee);
|
|
207
|
-
})), [loadDocument, t]);
|
|
208
|
-
var jumpToURL = useCallback(function (url) {
|
|
209
|
-
window.location.href = url;
|
|
80
|
+
var handleRevisionPublished = useCallback(function (value) {
|
|
81
|
+
setShowChanges(false);
|
|
82
|
+
editorRef.current.setSlateValue(value);
|
|
83
|
+
editorRef.current.updateDocumentVersion(value);
|
|
210
84
|
}, []);
|
|
211
|
-
var closeTip = useCallback(function () {
|
|
212
|
-
setShowTip(false);
|
|
213
|
-
|
|
214
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
215
|
-
}, [tipType]);
|
|
216
|
-
var tipSubmit = useCallback(function (callback) {
|
|
217
|
-
if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
|
|
218
|
-
callback && callback(true);
|
|
219
|
-
context.deleteSdocRevision().then(function (res) {
|
|
220
|
-
callback && callback(false);
|
|
221
|
-
setShowTip(false);
|
|
222
|
-
var originFileURL = context.getSetting('originFileURL');
|
|
223
|
-
jumpToURL(originFileURL);
|
|
224
|
-
}).catch(function (error) {
|
|
225
|
-
callback && callback(false);
|
|
226
|
-
toaster.danger(t('Error'));
|
|
227
|
-
});
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
if (tipType === TIP_TYPE.MERGE) {
|
|
231
|
-
callback && callback(true);
|
|
232
|
-
var _context$getUserInfo = context.getUserInfo(),
|
|
233
|
-
username = _context$getUserInfo.username;
|
|
234
|
-
var doc = {
|
|
235
|
-
children: mergeValue.children,
|
|
236
|
-
version: mergeValue.version,
|
|
237
|
-
format_version: document.format_version,
|
|
238
|
-
docName: document.docName,
|
|
239
|
-
last_modify_user: username
|
|
240
|
-
};
|
|
241
|
-
context.updateSdocRevision(doc).then(function (res) {
|
|
242
|
-
callback && callback(false);
|
|
243
|
-
var origin_file_version = res.data.origin_file_version;
|
|
244
|
-
context.updateSettings({
|
|
245
|
-
'originFileVersion': origin_file_version
|
|
246
|
-
});
|
|
247
|
-
// if revision diff view change to sdoc editor
|
|
248
|
-
if (isShowChanges) {
|
|
249
|
-
setShowChanges(false);
|
|
250
|
-
}
|
|
251
|
-
editorRef.current.setSlateValue(mergeValue);
|
|
252
|
-
editorRef.current.updateDocumentVersion(mergeValue);
|
|
253
|
-
setShowTip(false);
|
|
254
|
-
}).catch(function (error) {
|
|
255
|
-
callback && callback(false);
|
|
256
|
-
toaster.danger(t('Error'));
|
|
257
|
-
});
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
setShowTip(false);
|
|
261
|
-
|
|
262
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
263
|
-
}, [tipType, mergeValue, editorRef.current, document]);
|
|
264
85
|
if (isFirstLoading) {
|
|
265
86
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
266
87
|
}
|
|
@@ -278,8 +99,8 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
278
99
|
}), /*#__PURE__*/React.createElement(DocOperations, {
|
|
279
100
|
isShowChanges: isShowChanges,
|
|
280
101
|
changes: changes,
|
|
281
|
-
|
|
282
|
-
|
|
102
|
+
handleViewChangesToggle: handleViewChangesToggle,
|
|
103
|
+
handleRevisionPublished: handleRevisionPublished
|
|
283
104
|
})), /*#__PURE__*/React.createElement(Content, null, !isShowChanges && /*#__PURE__*/React.createElement(SDocEditor, {
|
|
284
105
|
ref: editorRef,
|
|
285
106
|
isReloading: isReloading,
|
|
@@ -287,10 +108,6 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
287
108
|
}), isShowChanges && /*#__PURE__*/React.createElement(RevisionDiffViewer, {
|
|
288
109
|
revisionContent: revisionContent,
|
|
289
110
|
didMountCallback: setDiffChanges
|
|
290
|
-
})))
|
|
291
|
-
toggle: closeTip,
|
|
292
|
-
submit: tipSubmit,
|
|
293
|
-
tipType: tipType
|
|
294
|
-
}));
|
|
111
|
+
}))));
|
|
295
112
|
};
|
|
296
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);
|