@seafile/sdoc-editor 0.1.154-beta5 → 0.1.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/seafile-api.js +9 -22
- package/dist/basic-sdk/comment/comment-decorate.js +1 -1
- package/dist/basic-sdk/constants/index.js +1 -25
- package/dist/basic-sdk/editor.js +105 -0
- package/dist/basic-sdk/extension/constants/color.js +2 -2
- package/dist/basic-sdk/extension/constants/diff-view.js +2 -2
- package/dist/basic-sdk/extension/constants/element-type.js +1 -6
- package/dist/basic-sdk/extension/constants/index.js +2 -2
- package/dist/basic-sdk/extension/constants/menus-config.js +0 -5
- package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +0 -26
- package/dist/basic-sdk/extension/plugins/file-link/render-elem.js +2 -2
- package/dist/basic-sdk/extension/plugins/sdoc-link/render-elem.js +2 -2
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +3 -3
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-bg-color-menu.js +13 -9
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +11 -11
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +2 -2
- package/dist/basic-sdk/extension/render/render-element.js +1 -221
- package/dist/basic-sdk/hooks/use-color-context.js +10 -10
- package/dist/basic-sdk/{editor/slate-editor.js → slate-editor.js} +16 -21
- package/dist/basic-sdk/socket/helpers.js +0 -2
- package/dist/basic-sdk/socket/socket-client.js +0 -58
- package/dist/basic-sdk/socket/socket-manager.js +2 -34
- package/dist/basic-sdk/socket/with-socket-io.js +12 -35
- package/dist/basic-sdk/utils/diff.js +3 -4
- package/dist/basic-sdk/views/diff-viewer.js +2 -4
- package/dist/basic-sdk/views/viewer.js +12 -9
- package/dist/components/doc-operations/index.js +2 -4
- package/dist/components/doc-operations/revision-operations/index.js +2 -5
- package/dist/components/doc-operations/revision-operations/publish-button.js +13 -6
- package/dist/constants/index.js +2 -26
- package/dist/context.js +9 -37
- package/dist/pages/simple-editor.js +84 -251
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +1 -11
- package/public/locales/zh_CN/sdoc-editor.json +1 -10
- package/dist/basic-sdk/editor/common-editor.js +0 -50
- package/dist/basic-sdk/editor/index.css +0 -29
- package/dist/basic-sdk/editor/index.js +0 -129
- package/dist/basic-sdk/utils/rebase.js +0 -193
- package/dist/components/tip-dialog/index.js +0 -48
- package/dist/components/tip-dialog/tip-content.js +0 -47
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Fragment } from 'react';
|
|
1
|
+
import React, { Fragment, useMemo } from 'react';
|
|
2
2
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
3
3
|
import { renderLeaf as _renderLeaf, renderElement as _renderElement, createDefaultEditor } from '../extension';
|
|
4
4
|
import withNodeId from '../node-id';
|
|
@@ -8,15 +8,18 @@ import { usePipDecorate } from '../decorates';
|
|
|
8
8
|
import { ArticleContainer, EditorContainer, EditorContent } from '../layout';
|
|
9
9
|
import '../assets/css/simple-viewer.css';
|
|
10
10
|
var SDocViewer = function SDocViewer(_ref) {
|
|
11
|
-
var
|
|
12
|
-
document = _ref.document,
|
|
11
|
+
var document = _ref.document,
|
|
13
12
|
customRenderLeaf = _ref.renderLeaf,
|
|
14
13
|
customRenderElement = _ref.renderElement,
|
|
15
14
|
showToolbar = _ref.showToolbar,
|
|
16
15
|
showOutline = _ref.showOutline;
|
|
17
|
-
var
|
|
16
|
+
var editor = useMemo(function () {
|
|
17
|
+
var defaultEditor = createDefaultEditor();
|
|
18
|
+
return withNodeId(defaultEditor);
|
|
19
|
+
}, []);
|
|
20
|
+
editor.readonly = true;
|
|
18
21
|
var slateValue = (document || generateDefaultDocContent()).children;
|
|
19
|
-
var decorate = usePipDecorate(
|
|
22
|
+
var decorate = usePipDecorate(editor);
|
|
20
23
|
return /*#__PURE__*/React.createElement(EditorContainer, {
|
|
21
24
|
editor: editor,
|
|
22
25
|
showToolbar: showToolbar,
|
|
@@ -26,19 +29,19 @@ var SDocViewer = function SDocViewer(_ref) {
|
|
|
26
29
|
readonly: true,
|
|
27
30
|
showOutline: showOutline
|
|
28
31
|
}, /*#__PURE__*/React.createElement(Slate, {
|
|
29
|
-
editor:
|
|
32
|
+
editor: editor,
|
|
30
33
|
value: slateValue
|
|
31
34
|
}, /*#__PURE__*/React.createElement(ArticleContainer, {
|
|
32
|
-
editor:
|
|
35
|
+
editor: editor,
|
|
33
36
|
readOnly: true
|
|
34
37
|
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
35
38
|
readOnly: true,
|
|
36
39
|
placeholder: "",
|
|
37
40
|
renderElement: function renderElement(props) {
|
|
38
|
-
return (customRenderElement || _renderElement)(props,
|
|
41
|
+
return (customRenderElement || _renderElement)(props, editor);
|
|
39
42
|
},
|
|
40
43
|
renderLeaf: function renderLeaf(props) {
|
|
41
|
-
return (customRenderLeaf || _renderLeaf)(props,
|
|
44
|
+
return (customRenderLeaf || _renderLeaf)(props, editor);
|
|
42
45
|
},
|
|
43
46
|
onDOMBeforeInput: function onDOMBeforeInput(event) {},
|
|
44
47
|
decorate: decorate
|
|
@@ -11,16 +11,14 @@ import './style.css';
|
|
|
11
11
|
var DocOperations = function DocOperations(_ref) {
|
|
12
12
|
var isShowChanges = _ref.isShowChanges,
|
|
13
13
|
changes = _ref.changes,
|
|
14
|
-
toggleViewChanges = _ref.toggleViewChanges
|
|
15
|
-
publishRevision = _ref.publishRevision;
|
|
14
|
+
toggleViewChanges = _ref.toggleViewChanges;
|
|
16
15
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
17
16
|
return /*#__PURE__*/React.createElement("div", {
|
|
18
17
|
className: "doc-ops"
|
|
19
18
|
}, /*#__PURE__*/React.createElement(RevisionOperations, {
|
|
20
19
|
isShowChanges: isShowChanges,
|
|
21
20
|
changes: changes,
|
|
22
|
-
toggleViewChanges: toggleViewChanges
|
|
23
|
-
publishRevision: publishRevision
|
|
21
|
+
toggleViewChanges: toggleViewChanges
|
|
24
22
|
}), /*#__PURE__*/React.createElement(CommentsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(ShareOperation, null), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(MoreOperations, null));
|
|
25
23
|
};
|
|
26
24
|
export default withTranslation('sdoc-editor')(DocOperations);
|
|
@@ -8,8 +8,7 @@ import ChangesCount from './changes-count';
|
|
|
8
8
|
var RevisionOperations = function RevisionOperations(_ref) {
|
|
9
9
|
var isShowChanges = _ref.isShowChanges,
|
|
10
10
|
changes = _ref.changes,
|
|
11
|
-
toggleViewChanges = _ref.toggleViewChanges
|
|
12
|
-
publishRevision = _ref.publishRevision;
|
|
11
|
+
toggleViewChanges = _ref.toggleViewChanges;
|
|
13
12
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
14
13
|
var isPublished = context.getSetting('isPublished');
|
|
15
14
|
return /*#__PURE__*/React.createElement(React.Fragment, null, !isSdocRevision && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MoreRevisionOperations, null), /*#__PURE__*/React.createElement(Revisions, null)), isSdocRevision && isShowChanges && /*#__PURE__*/React.createElement(ChangesCount, {
|
|
@@ -17,8 +16,6 @@ var RevisionOperations = function RevisionOperations(_ref) {
|
|
|
17
16
|
}), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
|
|
18
17
|
isShowChanges: isShowChanges,
|
|
19
18
|
toggleViewChanges: toggleViewChanges
|
|
20
|
-
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision,
|
|
21
|
-
publishRevision: publishRevision
|
|
22
|
-
}));
|
|
19
|
+
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, null));
|
|
23
20
|
};
|
|
24
21
|
export default RevisionOperations;
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
-
import { useTranslation } from 'react-i18next';
|
|
3
2
|
import { Button } from 'reactstrap';
|
|
3
|
+
import { withTranslation } from 'react-i18next';
|
|
4
|
+
import context from '../../../context';
|
|
5
|
+
import toaster from '../../../components/toast';
|
|
4
6
|
var PublishRevision = function PublishRevision(_ref) {
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
7
|
+
var t = _ref.t;
|
|
8
|
+
var repoID = context.getSetting('repoID');
|
|
9
|
+
var siteRoot = context.getSetting('siteRoot');
|
|
8
10
|
var publish = useCallback(function (event) {
|
|
9
11
|
event.stopPropagation();
|
|
10
12
|
event.nativeEvent.stopImmediatePropagation();
|
|
11
|
-
|
|
13
|
+
context.publishSdocRevision().then(function (res) {
|
|
14
|
+
var origin_file_path = res.data.origin_file_path;
|
|
15
|
+
window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
|
|
16
|
+
}).catch(function (error) {
|
|
17
|
+
toaster.danger(t('Error'));
|
|
18
|
+
});
|
|
12
19
|
|
|
13
20
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
21
|
}, []);
|
|
@@ -18,4 +25,4 @@ var PublishRevision = function PublishRevision(_ref) {
|
|
|
18
25
|
className: "ml-4"
|
|
19
26
|
}, t('Publish'));
|
|
20
27
|
};
|
|
21
|
-
export default PublishRevision;
|
|
28
|
+
export default withTranslation('sdoc-editor')(PublishRevision);
|
package/dist/constants/index.js
CHANGED
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
var _TIP_TITLE, _TIP_CONTENT;
|
|
3
1
|
export var EXTERNAL_EVENT = {
|
|
4
2
|
INTERNAL_LINK_CLICK: 'internal_link_click',
|
|
5
3
|
TOGGLE_STAR: 'toggle_star',
|
|
6
4
|
UNMARK_AS_DRAFT: 'unmark_as_draft',
|
|
7
|
-
SHARE_SDOC: 'share_sdoc'
|
|
8
|
-
|
|
9
|
-
PUBLISH_DOCUMENT_ERROR: 'publish_document_error',
|
|
10
|
-
DOCUMENT_REPLACED: 'document_replaced',
|
|
11
|
-
DOCUMENT_REPLACED_ERROR: 'document_replaced_error',
|
|
12
|
-
REMOVE_DOCUMENT: 'remove_document',
|
|
13
|
-
REMOVE_DOCUMENT_ERROR: 'remove_document_error'
|
|
14
|
-
};
|
|
15
|
-
export var MODE = {
|
|
16
|
-
DIFF_VIEWER: 'diff_viewer',
|
|
17
|
-
VIEWER: 'viewer',
|
|
18
|
-
EDITOR: 'editor'
|
|
19
|
-
};
|
|
20
|
-
export var TIP_TYPE = {
|
|
21
|
-
DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
|
|
22
|
-
MERGE: 'merge',
|
|
23
|
-
HAS_CONFLICT_BEFORE_PUBLISH: 'has_conflict_before_publish',
|
|
24
|
-
HAS_BEEN_PUBLISHED: 'has_been_published',
|
|
25
|
-
HAS_BEEN_REPLACED: 'has_been_merge',
|
|
26
|
-
HAS_CONFLICT_BEFORE_VIEW_CHANGES: 'has_conflict_before_view_changes',
|
|
27
|
-
HAS_BEEN_REMOVED: 'has_been_removed'
|
|
28
|
-
};
|
|
29
|
-
export var TIP_TITLE = (_TIP_TITLE = {}, _defineProperty(_TIP_TITLE, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_REPLACED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_REMOVED, 'Tip'), _TIP_TITLE);
|
|
30
|
-
export var TIP_CONTENT = (_TIP_CONTENT = {}, _defineProperty(_TIP_CONTENT, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Rebase_delete_no_change_revision_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.MERGE, 'Merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Has_conflict_before_publish_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Has_been_published_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_REPLACED, 'Has_been_replaced_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Has_conflict_before_view_changes_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_REMOVED, 'Has_been_removed_tip'), _TIP_CONTENT);
|
|
5
|
+
SHARE_SDOC: 'share_sdoc'
|
|
6
|
+
};
|
package/dist/context.js
CHANGED
|
@@ -9,13 +9,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
9
9
|
_classCallCheck(this, Context);
|
|
10
10
|
this.initSettings = function () {
|
|
11
11
|
_this.settings = window.seafile ? window.seafile : window.seafileConfig;
|
|
12
|
-
if (_this.settings['isSdocRevision']) {
|
|
13
|
-
var repoID = _this.getSetting('repoID');
|
|
14
|
-
var siteRoot = _this.getSetting('siteRoot');
|
|
15
|
-
var originFilePath = _this.getSetting('originFilePath');
|
|
16
|
-
var originFileURL = "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath);
|
|
17
|
-
_this.settings['originFileURL'] = originFileURL;
|
|
18
|
-
}
|
|
19
12
|
};
|
|
20
13
|
this.uploadLocalImage = function (imageFile) {
|
|
21
14
|
var docUuid = _this.getSetting('docUuid');
|
|
@@ -52,13 +45,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
52
45
|
if (this.settings[key] === false) return this.settings[key];
|
|
53
46
|
return this.settings[key] || '';
|
|
54
47
|
}
|
|
55
|
-
}, {
|
|
56
|
-
key: "updateSettings",
|
|
57
|
-
value: function updateSettings(update) {
|
|
58
|
-
for (var key in update) {
|
|
59
|
-
this.settings[key] = update[key];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
48
|
}, {
|
|
63
49
|
key: "getViewConfig",
|
|
64
50
|
value: function getViewConfig() {
|
|
@@ -168,10 +154,16 @@ var Context = /*#__PURE__*/function () {
|
|
|
168
154
|
return this.api.startRevise(repoID, fileUuid, filePath);
|
|
169
155
|
}
|
|
170
156
|
}, {
|
|
171
|
-
key: "
|
|
172
|
-
value: function
|
|
157
|
+
key: "publishSdocRevision",
|
|
158
|
+
value: function publishSdocRevision() {
|
|
173
159
|
var docUuid = this.getSetting('docUuid');
|
|
174
|
-
return this.api.
|
|
160
|
+
return this.api.sdocPublishRevision(docUuid);
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "getSeadocRevisionDownloadLinks",
|
|
164
|
+
value: function getSeadocRevisionDownloadLinks() {
|
|
165
|
+
var docUuid = this.getSetting('docUuid');
|
|
166
|
+
return this.api.getSeadocRevisionDownloadLinks(docUuid);
|
|
175
167
|
}
|
|
176
168
|
}, {
|
|
177
169
|
key: "getSdocRevisionsCount",
|
|
@@ -185,26 +177,6 @@ var Context = /*#__PURE__*/function () {
|
|
|
185
177
|
var docUuid = this.getSetting('docUuid');
|
|
186
178
|
return this.api.getSdocRevisions(docUuid, page, perPage);
|
|
187
179
|
}
|
|
188
|
-
}, {
|
|
189
|
-
key: "updateSdocRevision",
|
|
190
|
-
value: function updateSdocRevision() {
|
|
191
|
-
var docUuid = this.getSetting('docUuid');
|
|
192
|
-
return this.api.updateSdocRevision(docUuid);
|
|
193
|
-
}
|
|
194
|
-
}, {
|
|
195
|
-
key: "deleteSdocRevision",
|
|
196
|
-
value: function deleteSdocRevision() {
|
|
197
|
-
var docUuid = this.getSetting('docUuid');
|
|
198
|
-
return this.api.deleteSdocRevision(docUuid);
|
|
199
|
-
}
|
|
200
|
-
}, {
|
|
201
|
-
key: "getRevisionBasicVersionContent",
|
|
202
|
-
value: function getRevisionBasicVersionContent() {
|
|
203
|
-
var docUuid = this.getSetting('docUuid');
|
|
204
|
-
return this.api.getRevisionBasicVersionContent(docUuid);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// local files
|
|
208
180
|
}, {
|
|
209
181
|
key: "getSdocLocalFiles",
|
|
210
182
|
value: function getSdocLocalFiles(p, type) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
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
3
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
4
|
import { withTranslation } from 'react-i18next';
|
|
5
|
+
import deepCopy from 'deep-copy';
|
|
6
|
+
import { SDocEditor, DiffViewer } from '../basic-sdk';
|
|
6
7
|
import Loading from '../components/loading';
|
|
7
8
|
import DocInfo from '../components/doc-info';
|
|
8
9
|
import DocOperations from '../components/doc-operations';
|
|
@@ -10,124 +11,49 @@ import Layout, { Header, Content } from '../layout';
|
|
|
10
11
|
import { generateDefaultDocContent } from '../utils';
|
|
11
12
|
import context from '../context';
|
|
12
13
|
import ErrorBoundary from './error-boundary';
|
|
13
|
-
import TipDialog from '../components/tip-dialog';
|
|
14
|
-
import { EXTERNAL_EVENT, MODE, TIP_TYPE } from '../constants';
|
|
15
|
-
import { getRebase, hasConflict } from '../basic-sdk/utils/rebase';
|
|
16
|
-
import toaster from '../components/toast';
|
|
17
|
-
import { EventBus, SDocEditor } from '../basic-sdk';
|
|
18
14
|
import '../assets/css/simple-editor.css';
|
|
19
15
|
var SimpleEditor = function SimpleEditor(_ref) {
|
|
20
16
|
var isStarred = _ref.isStarred,
|
|
21
17
|
isDraft = _ref.isDraft,
|
|
22
18
|
t = _ref.t;
|
|
23
|
-
context.initApi();
|
|
24
19
|
var editorRef = useRef(null);
|
|
25
20
|
var _useState = useState(true),
|
|
26
21
|
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _useState3 = useState(
|
|
22
|
+
isFirstLoad = _useState2[0],
|
|
23
|
+
setFirstLoad = _useState2[1];
|
|
24
|
+
var _useState3 = useState(true),
|
|
30
25
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _useState5 = useState(
|
|
26
|
+
isLoadingSdoc = _useState4[0],
|
|
27
|
+
setLoadingSdoc = _useState4[1];
|
|
28
|
+
var _useState5 = useState(''),
|
|
34
29
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var _useState7 = useState(
|
|
30
|
+
errorMessage = _useState6[0],
|
|
31
|
+
setErrorMessage = _useState6[1];
|
|
32
|
+
var _useState7 = useState(false),
|
|
38
33
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var _useState9 = useState(
|
|
34
|
+
isShowChanges = _useState8[0],
|
|
35
|
+
setShowChanges = _useState8[1];
|
|
36
|
+
var _useState9 = useState(null),
|
|
42
37
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var _useState11 = useState(
|
|
38
|
+
document = _useState10[0],
|
|
39
|
+
setDocument = _useState10[1];
|
|
40
|
+
var _useState11 = useState(null),
|
|
46
41
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var _useState13 = useState(
|
|
42
|
+
currentContent = _useState12[0],
|
|
43
|
+
setCurrentContent = _useState12[1];
|
|
44
|
+
var _useState13 = useState(null),
|
|
50
45
|
_useState14 = _slicedToArray(_useState13, 2),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var _useState15 = useState(''),
|
|
54
|
-
_useState16 = _slicedToArray(_useState15, 2),
|
|
55
|
-
tipType = _useState16[0],
|
|
56
|
-
setTipType = _useState16[1];
|
|
57
|
-
var _useState17 = useState([]),
|
|
58
|
-
_useState18 = _slicedToArray(_useState17, 2),
|
|
59
|
-
mergeValue = _useState18[0],
|
|
60
|
-
setMergeValue = _useState18[1];
|
|
46
|
+
lastContent = _useState14[0],
|
|
47
|
+
setLastContent = _useState14[1];
|
|
61
48
|
useEffect(function () {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
setLoadingSdoc(false);
|
|
65
|
-
}, function (errorMessage) {
|
|
66
|
-
setErrorMessage(errorMessage);
|
|
67
|
-
setDocument(null);
|
|
68
|
-
setLoadingSdoc(false);
|
|
69
|
-
}, function () {
|
|
70
|
-
setLoadingSdoc(true);
|
|
71
|
-
});
|
|
49
|
+
context.initApi();
|
|
50
|
+
initDocumentData(true);
|
|
72
51
|
|
|
73
52
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
53
|
}, []);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
79
|
-
var originFilename = context.getSetting('originFilename');
|
|
80
|
-
if (isSdocRevision) {
|
|
81
|
-
window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
85
|
-
}, []);
|
|
86
|
-
var onDocumentReplaced = useCallback(function () {
|
|
87
|
-
setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
|
|
88
|
-
setShowTip(true);
|
|
89
|
-
|
|
90
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
|
-
}, [editorRef]);
|
|
92
|
-
var hasPublishRevision = useCallback(function () {
|
|
93
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
94
|
-
setShowTip(true);
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
|
-
}, [editorRef]);
|
|
98
|
-
var onError = useCallback(function () {
|
|
99
|
-
toaster.danger(t('Error'));
|
|
100
|
-
|
|
101
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
-
}, []);
|
|
103
|
-
var onDocumentRemoved = useCallback(function () {
|
|
104
|
-
if (showTip) return;
|
|
105
|
-
setTipType(TIP_TYPE.HAS_BEEN_REMOVED);
|
|
106
|
-
setShowTip(true);
|
|
107
|
-
|
|
108
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
-
}, [showTip]);
|
|
110
|
-
useEffect(function () {
|
|
111
|
-
var eventBus = EventBus.getInstance();
|
|
112
|
-
var unsubscribeMergeDocument = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED, onDocumentReplaced);
|
|
113
|
-
var unsubscribePublishDocument = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
|
|
114
|
-
var unsubscribeMergeDocumentError = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR, onError);
|
|
115
|
-
var unsubscribePublishDocumentError = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, onError);
|
|
116
|
-
var unsubscribeRemoveDocument = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT, onDocumentRemoved);
|
|
117
|
-
var unsubscribeRemoveDocumentError = eventBus.subscribe(EXTERNAL_EVENT.REMOVE_DOCUMENT_ERROR, onError);
|
|
118
|
-
return function () {
|
|
119
|
-
unsubscribeMergeDocument();
|
|
120
|
-
unsubscribePublishDocument();
|
|
121
|
-
unsubscribeMergeDocumentError();
|
|
122
|
-
unsubscribePublishDocumentError();
|
|
123
|
-
unsubscribeRemoveDocument();
|
|
124
|
-
unsubscribeRemoveDocumentError();
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
128
|
-
}, []);
|
|
129
|
-
var loadDocument = useCallback(function (successCallback, errorCallback, callback) {
|
|
130
|
-
callback && callback();
|
|
54
|
+
var initDocumentData = useCallback(function (isFirstLoad) {
|
|
55
|
+
setShowChanges(false);
|
|
56
|
+
setLoadingSdoc(true);
|
|
131
57
|
context.getFileContent().then(function (res) {
|
|
132
58
|
var result = res.data || generateDefaultDocContent();
|
|
133
59
|
if (result && !result.children) {
|
|
@@ -137,174 +63,74 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
137
63
|
cursors: result.cursors || {}
|
|
138
64
|
};
|
|
139
65
|
}
|
|
140
|
-
|
|
66
|
+
setDocument(result);
|
|
67
|
+
setLoadingSdoc(false);
|
|
68
|
+
isFirstLoad && setFirstLoad(false);
|
|
141
69
|
}).catch(function (error) {
|
|
142
70
|
// eslint-disable-next-line
|
|
143
71
|
console.log(error);
|
|
144
|
-
|
|
72
|
+
setErrorMessage('Load_doc_content_error');
|
|
145
73
|
if (error && error.response) {
|
|
146
74
|
var _ref2 = error.response.data || {},
|
|
147
75
|
error_type = _ref2.error_type;
|
|
148
76
|
if (error_type === 'content_invalid') {
|
|
149
|
-
|
|
77
|
+
setErrorMessage('Sdoc_format_invalid');
|
|
150
78
|
}
|
|
151
79
|
}
|
|
152
|
-
|
|
80
|
+
setDocument(null);
|
|
81
|
+
setLoadingSdoc(false);
|
|
153
82
|
});
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
154
85
|
}, []);
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
86
|
+
var initChangesData = useCallback(function () {
|
|
87
|
+
setShowChanges(true);
|
|
88
|
+
setLoadingSdoc(true);
|
|
89
|
+
context.getSeadocRevisionDownloadLinks().then(function (res) {
|
|
90
|
+
var originFileDownloadLink = res.data.origin_file_download_link;
|
|
158
91
|
return fetch(originFileDownloadLink);
|
|
159
92
|
}).then(function (res) {
|
|
160
93
|
return res.json();
|
|
161
94
|
}).then(function (originContent) {
|
|
162
|
-
|
|
163
|
-
|
|
95
|
+
setLastContent(originContent);
|
|
96
|
+
setErrorMessage(null);
|
|
97
|
+
setLoadingSdoc(false);
|
|
164
98
|
}).catch(function (error) {
|
|
165
|
-
|
|
99
|
+
setErrorMessage('Load_doc_content_error');
|
|
100
|
+
setLoadingSdoc(false);
|
|
166
101
|
});
|
|
167
|
-
|
|
102
|
+
|
|
103
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
104
|
+
}, [document]);
|
|
168
105
|
var toggleViewChanges = useCallback(function (isShowChanges) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
106
|
+
if (isShowChanges) {
|
|
107
|
+
var newestValue = editorRef.current.getValue();
|
|
108
|
+
setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
109
|
+
children: newestValue
|
|
110
|
+
})));
|
|
174
111
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
|
|
178
|
-
setMode(mode);
|
|
179
|
-
editorRef.current.setEditorMode(mode);
|
|
180
|
-
if (!isShowChanges) {
|
|
181
|
-
loadDocument(function (document) {
|
|
182
|
-
setDocument(document);
|
|
183
|
-
editorRef.current.setSlateValue(document);
|
|
184
|
-
editorRef.current.setLoading(false);
|
|
185
|
-
}, function (errorMessage) {
|
|
186
|
-
setErrorMessage(errorMessage);
|
|
187
|
-
editorRef.current.setLoading(false);
|
|
188
|
-
});
|
|
112
|
+
if (isShowChanges) {
|
|
113
|
+
initChangesData();
|
|
189
114
|
return;
|
|
190
115
|
}
|
|
191
|
-
|
|
116
|
+
setChanges([]);
|
|
117
|
+
initDocumentData(false);
|
|
192
118
|
|
|
193
119
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
194
|
-
}, [document
|
|
195
|
-
var
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
loadDocument(function (document) {
|
|
200
|
-
var revisionContent = document;
|
|
201
|
-
if (hasConflict(revisionContent.children)) {
|
|
202
|
-
setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
|
|
203
|
-
setShowTip(true);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
var originDocName = context.getSetting('originFilename');
|
|
207
|
-
var originDocUuid = context.getSetting('originDocUuid');
|
|
208
|
-
var basicContent;
|
|
209
|
-
var masterContent;
|
|
210
|
-
context.getRevisionBasicVersionContent().then(function (res) {
|
|
211
|
-
var basicVersionContentString = res.data.content; // commit content
|
|
212
|
-
basicContent = JSON.parse(basicVersionContentString);
|
|
213
|
-
return context.getSeadocOriginFileContentDownloadLink();
|
|
214
|
-
}).then(function (res) {
|
|
215
|
-
var originFileDownloadLink = res.data.download_link;
|
|
216
|
-
return fetch(originFileDownloadLink);
|
|
217
|
-
}).then(function (res) {
|
|
218
|
-
return res.json();
|
|
219
|
-
}).then(function (content) {
|
|
220
|
-
masterContent = content;
|
|
221
|
-
var _getRebase = getRebase(masterContent, basicContent, revisionContent),
|
|
222
|
-
canMerge = _getRebase.canMerge,
|
|
223
|
-
isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
|
|
224
|
-
value = _getRebase.value;
|
|
225
|
-
if (canMerge && isNeedReplaceMaster) {
|
|
226
|
-
editorRef.current.publishDocument(originDocUuid, originDocName, function (success) {
|
|
227
|
-
if (success) {
|
|
228
|
-
setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
|
|
229
|
-
setShowTip(true);
|
|
230
|
-
} else {
|
|
231
|
-
toaster.danger(t('Error'));
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
if (canMerge && !isNeedReplaceMaster) {
|
|
237
|
-
setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
|
|
238
|
-
setShowTip(true);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
setMergeValue(value);
|
|
242
|
-
setTipType(TIP_TYPE.MERGE);
|
|
243
|
-
setShowTip(true);
|
|
244
|
-
}).catch(function (error) {
|
|
245
|
-
toaster.danger(t('Error'));
|
|
246
|
-
});
|
|
247
|
-
}, function (errorMessage) {
|
|
248
|
-
toaster.danger(t(errorMessage));
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
252
|
-
case 1:
|
|
253
|
-
case "end":
|
|
254
|
-
return _context.stop();
|
|
255
|
-
}
|
|
256
|
-
}, _callee);
|
|
257
|
-
})), [isShowChanges, mode]);
|
|
120
|
+
}, [document]);
|
|
121
|
+
var _useState15 = useState([]),
|
|
122
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
123
|
+
changes = _useState16[0],
|
|
124
|
+
setChanges = _useState16[1];
|
|
258
125
|
var setDiffChanges = useCallback(function (diff) {
|
|
259
126
|
setChanges(diff.changes);
|
|
260
127
|
|
|
261
128
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
262
129
|
}, [isShowChanges]);
|
|
263
|
-
|
|
264
|
-
window.location.href = url;
|
|
265
|
-
}, []);
|
|
266
|
-
var closeTip = useCallback(function () {
|
|
267
|
-
setShowTip(false);
|
|
268
|
-
|
|
269
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
270
|
-
}, [tipType]);
|
|
271
|
-
var tipSubmit = useCallback(function () {
|
|
272
|
-
if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
|
|
273
|
-
context.deleteSdocRevision().then(function (res) {
|
|
274
|
-
setShowTip(false);
|
|
275
|
-
var originFileURL = context.getSetting('originFileURL');
|
|
276
|
-
jumpToURL(originFileURL);
|
|
277
|
-
}).catch(function (error) {
|
|
278
|
-
toaster.danger(t('Error'));
|
|
279
|
-
});
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (tipType === TIP_TYPE.MERGE) {
|
|
283
|
-
context.updateSdocRevision().then(function (res) {
|
|
284
|
-
var origin_file_version = res.data.origin_file_version;
|
|
285
|
-
context.updateSettings({
|
|
286
|
-
'originFileVersion': origin_file_version
|
|
287
|
-
});
|
|
288
|
-
editorRef.current.replaceDocument(mergeValue);
|
|
289
|
-
editorRef.current.setLoading(true);
|
|
290
|
-
editorRef.current.setSlateValue(mergeValue);
|
|
291
|
-
setMode(MODE.EDITOR);
|
|
292
|
-
editorRef.current.setEditorMode(MODE.EDITOR);
|
|
293
|
-
editorRef.current.setLoading(false);
|
|
294
|
-
setShowTip(false);
|
|
295
|
-
}).catch(function (error) {
|
|
296
|
-
toaster.danger(t('Error'));
|
|
297
|
-
});
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
setShowTip(false);
|
|
301
|
-
|
|
302
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
303
|
-
}, [tipType, mergeValue, editorRef.current]);
|
|
304
|
-
if (isLoadingSdoc) {
|
|
130
|
+
if (isFirstLoad && !errorMessage) {
|
|
305
131
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
306
132
|
}
|
|
307
|
-
if (errorMessage) {
|
|
133
|
+
if (isFirstLoad && errorMessage) {
|
|
308
134
|
return /*#__PURE__*/React.createElement("div", {
|
|
309
135
|
className: "error-page"
|
|
310
136
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -318,17 +144,24 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
318
144
|
}), /*#__PURE__*/React.createElement(DocOperations, {
|
|
319
145
|
isShowChanges: isShowChanges,
|
|
320
146
|
changes: changes,
|
|
321
|
-
toggleViewChanges: toggleViewChanges
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
147
|
+
toggleViewChanges: toggleViewChanges
|
|
148
|
+
})), /*#__PURE__*/React.createElement(Content, null, isLoadingSdoc && /*#__PURE__*/React.createElement("div", {
|
|
149
|
+
className: "w-100 h-100 d-flex align-items-center justify-content-center"
|
|
150
|
+
}, /*#__PURE__*/React.createElement(Loading, null)), !isLoadingSdoc && errorMessage && /*#__PURE__*/React.createElement("div", {
|
|
151
|
+
className: "error-page"
|
|
152
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
153
|
+
className: "error-tip"
|
|
154
|
+
}, t(errorMessage))), !isLoadingSdoc && !errorMessage && /*#__PURE__*/React.createElement(React.Fragment, null, isShowChanges ? /*#__PURE__*/React.createElement(DiffViewer, {
|
|
155
|
+
showToolbar: true,
|
|
156
|
+
showOutline: true,
|
|
157
|
+
currentContent: currentContent,
|
|
158
|
+
lastContent: lastContent,
|
|
159
|
+
didMountCallback: setDiffChanges
|
|
160
|
+
}) : /*#__PURE__*/React.createElement(SDocEditor, {
|
|
161
|
+
config: context.getEditorConfig(),
|
|
325
162
|
document: document,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
})))
|
|
329
|
-
toggle: closeTip,
|
|
330
|
-
submit: tipSubmit,
|
|
331
|
-
tipType: tipType
|
|
332
|
-
}));
|
|
163
|
+
ref: editorRef,
|
|
164
|
+
isOpenSocket: context.getSetting('isOpenSocket')
|
|
165
|
+
})))));
|
|
333
166
|
};
|
|
334
167
|
export default withTranslation('sdoc-editor')(SimpleEditor);
|