@seafile/sdoc-editor 0.1.166 → 0.1.167-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.
@@ -1,25 +1,23 @@
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';
5
6
  import context from '../../context';
6
- import { MODE } from '../../constants';
7
7
  import CommonLoading from '../../components/common-loading';
8
8
  import { PAGE_EDIT_AREA_WIDTH } from '../constants';
9
9
  import { createDefaultEditor } from '../extension';
10
10
  import withNodeId from '../node-id';
11
11
  import { withSocketIO } from '../socket';
12
- import DiffViewer from '../views/diff-viewer';
13
12
  import SDocEditor from './sdoc-editor';
14
13
  import './index.css';
15
14
  var Editor = forwardRef(function (_ref, ref) {
16
- var mode = _ref.mode,
17
- document = _ref.document,
18
- setDiffChanges = _ref.setDiffChanges;
15
+ var document = _ref.document,
16
+ _ref$isReloading = _ref.isReloading,
17
+ isReloading = _ref$isReloading === void 0 ? false : _ref$isReloading;
19
18
  var editor = useMemo(function () {
20
19
  var defaultEditor = createDefaultEditor();
21
20
  var editorConfig = context.getEditorConfig();
22
- defaultEditor.mode = MODE.EDITOR;
23
21
  var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
22
  document: document,
25
23
  config: editorConfig
@@ -35,18 +33,6 @@ var Editor = forwardRef(function (_ref, ref) {
35
33
  _useState2 = _slicedToArray(_useState, 2),
36
34
  slateValue = _useState2[0],
37
35
  _setSlateValue = _useState2[1];
38
- var _useState3 = useState(false),
39
- _useState4 = _slicedToArray(_useState3, 2),
40
- isLoading = _useState4[0],
41
- _setLoading = _useState4[1];
42
- var _useState5 = useState(null),
43
- _useState6 = _slicedToArray(_useState5, 2),
44
- diffContent = _useState6[0],
45
- _setDiffContent = _useState6[1];
46
- var _useState7 = useState(null),
47
- _useState8 = _slicedToArray(_useState7, 2),
48
- currentContent = _useState8[0],
49
- setCurrentContent = _useState8[1];
50
36
 
51
37
  // useMount: init socket connection
52
38
  useEffect(function () {
@@ -66,26 +52,10 @@ var Editor = forwardRef(function (_ref, ref) {
66
52
  // The parent component can call the method of this component through ref
67
53
  useImperativeHandle(ref, function () {
68
54
  return {
69
- // set value
70
- setLoading: function setLoading(isLoading) {
71
- _setLoading(isLoading);
72
- },
73
- setDiffContent: function setDiffContent(content) {
74
- setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
75
- children: slateValue
76
- })));
77
- _setDiffContent(content);
78
- },
79
- setEditorMode: function setEditorMode(mode) {
80
- editor.cursors = {};
81
- editor.selection = null;
82
- if (mode === MODE.EDITOR) {
83
- editor.operations = [];
84
- }
85
- editor.mode = mode;
86
- },
87
55
  setSlateValue: function setSlateValue(document) {
88
- _setSlateValue(document.children);
56
+ _setSlateValue(_toConsumableArray(document.children));
57
+ // Force update of editor's child elements
58
+ editor.children = document.children;
89
59
  },
90
60
  updateDocumentVersion: function updateDocumentVersion(document) {
91
61
  editor.updateDocumentVersion(document);
@@ -100,21 +70,11 @@ var Editor = forwardRef(function (_ref, ref) {
100
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
101
71
  };
102
72
  }, [document, editor, slateValue]);
103
- if (isLoading) {
73
+ if (isReloading) {
104
74
  return /*#__PURE__*/React.createElement("div", {
105
75
  className: "h-100 w-100 d-flex align-items-center justify-content-center"
106
76
  }, /*#__PURE__*/React.createElement(CommonLoading, null));
107
77
  }
108
- if (mode === MODE.DIFF_VIEWER) {
109
- return /*#__PURE__*/React.createElement(DiffViewer, {
110
- showToolbar: true,
111
- showOutline: true,
112
- editor: editor,
113
- currentContent: currentContent,
114
- lastContent: diffContent,
115
- didMountCallback: setDiffChanges
116
- });
117
- }
118
78
  return /*#__PURE__*/React.createElement(SDocEditor, {
119
79
  slateValue: slateValue,
120
80
  editor: editor,
@@ -4,7 +4,6 @@ import { Editor, Operation } from '@seafile/slate';
4
4
  import { getNode } from '../extension/core';
5
5
  import * as OPERATION from '../node-id/constants';
6
6
  import { setCursor } from '../cursor/helper';
7
- import { MODE } from '../../constants';
8
7
  export var getNodePathById = function getNodePathById(rootNode, nodeId) {
9
8
  var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
10
9
  if (rootNode.id === nodeId) return path;
@@ -253,7 +252,6 @@ export var reExecRevertOperationList = function reExecRevertOperationList(editor
253
252
  }
254
253
  };
255
254
  export var syncRemoteOperations = function syncRemoteOperations(editor, remoteOperations) {
256
- if (editor.mode !== MODE.EDITOR) return;
257
255
  if (remoteOperations.length === 0) return;
258
256
  Editor.withoutNormalizing(editor, function () {
259
257
  for (var i = 0; i < remoteOperations.length; i++) {
@@ -7,7 +7,7 @@ import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, s
7
7
  import SocketClient from './socket-client';
8
8
  import { clientDebug, conflictDebug, serverDebug, stateDebug } from '../utils/debug';
9
9
  import { deleteCursor } from '../cursor/helper';
10
- import { EXTERNAL_EVENT, MODE } from '../../constants';
10
+ import { EXTERNAL_EVENT } from '../../constants';
11
11
 
12
12
  // idle --> sending --> conflict --> idle
13
13
  // --> conflict --> idle
@@ -56,7 +56,6 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
56
56
  _this.sendOperations();
57
57
  };
58
58
  this.sendOperations = function () {
59
- if (_this.editor.mode !== MODE.EDITOR) return;
60
59
  if (_this.state !== STATE.IDLE) return;
61
60
  stateDebug("State changed: ".concat(_this.state, " -> ").concat(STATE.SENDING));
62
61
  _this.state = STATE.SENDING;
@@ -1,4 +1,3 @@
1
- import { MODE } from '../../constants';
2
1
  import { generateCursorData } from '../cursor/helper';
3
2
  import EventBus from '../utils/event-bus';
4
3
  import SocketManager from './socket-manager';
@@ -22,7 +21,6 @@ var withSocketIO = function withSocketIO(editor, options) {
22
21
  newEditor.onChange = function () {
23
22
  var document = options.document,
24
23
  config = options.config;
25
- if (newEditor.mode === MODE.DIFF_VIEWER) return;
26
24
  var operations = newEditor.operations;
27
25
  if (!newEditor.isRemote && operations.length > 0) {
28
26
  var isAllSetSelection = operations.every(function (operation) {
@@ -30,23 +28,18 @@ var withSocketIO = function withSocketIO(editor, options) {
30
28
  });
31
29
  var _socketManager = SocketManager.getInstance(newEditor, document, config);
32
30
  if (!isAllSetSelection) {
33
- if (newEditor.mode === MODE.EDITOR) {
34
- // get update content value operations
35
- var updateOperations = operations.filter(function (operation) {
36
- return operation.type !== 'set_selection';
37
- });
38
- _socketManager.onReceiveLocalOperations(updateOperations);
39
- }
31
+ // get update content value operations
32
+ var updateOperations = operations.filter(function (operation) {
33
+ return operation.type !== 'set_selection';
34
+ });
35
+ _socketManager.onReceiveLocalOperations(updateOperations);
40
36
  }
41
- if (newEditor.mode === MODE.EDITOR) {
42
- _socketManager.sendCursorLocation(editor.selection);
43
- }
44
- }
45
- if (newEditor.mode === MODE.EDITOR) {
46
- // dispatch editor change event
47
- var eventBus = EventBus.getInstance(newEditor, document, config);
48
- eventBus.dispatch('change');
37
+ _socketManager.sendCursorLocation(editor.selection);
49
38
  }
39
+
40
+ // dispatch editor change event
41
+ var eventBus = EventBus.getInstance(newEditor, document, config);
42
+ eventBus.dispatch('change');
50
43
  onChange();
51
44
  };
52
45
  newEditor.rebaseContent = function (document, originFileVersion) {
@@ -1,3 +1,4 @@
1
- import DiffViewer from './diff-viewer';
2
1
  import SDocViewer from './sdoc-viewer';
3
- export { DiffViewer, SDocViewer };
2
+ import DiffViewer from './sdoc-diff-viewer';
3
+ import RevisionDiffViewer from './revision-diff-viewer';
4
+ export { SDocViewer, DiffViewer, RevisionDiffViewer };
@@ -0,0 +1,44 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect, useState } from 'react';
3
+ import context from '../../context';
4
+ import { getDiff } from '../utils/diff';
5
+ import SDocViewer from './sdoc-viewer';
6
+ import Loading from '../../components/loading';
7
+ import '../../assets/css/diff-viewer.css';
8
+ var RevisionDiffViewer = function RevisionDiffViewer(_ref) {
9
+ var revisionContent = _ref.revisionContent,
10
+ didMountCallback = _ref.didMountCallback;
11
+ var _useState = useState(true),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ isLoading = _useState2[0],
14
+ setIsLoading = _useState2[1];
15
+ var _useState3 = useState(null),
16
+ _useState4 = _slicedToArray(_useState3, 2),
17
+ diff = _useState4[0],
18
+ setDiff = _useState4[1];
19
+ useEffect(function () {
20
+ setIsLoading(true);
21
+ context.getSeadocOriginFileContent().then(function (res) {
22
+ var originContentString = res.data.content;
23
+ var originContent = JSON.parse(originContentString);
24
+ var diff = getDiff(revisionContent, originContent);
25
+ setDiff(diff);
26
+ didMountCallback && didMountCallback(diff);
27
+ setIsLoading(false);
28
+ }).catch(function (error) {
29
+ console.log('error');
30
+ setIsLoading(false);
31
+ });
32
+ }, [revisionContent, didMountCallback]);
33
+ if (isLoading) {
34
+ return /*#__PURE__*/React.createElement(Loading, null);
35
+ }
36
+ return /*#__PURE__*/React.createElement(SDocViewer, {
37
+ showToolbar: true,
38
+ showOutline: true,
39
+ document: {
40
+ children: diff.value
41
+ }
42
+ });
43
+ };
44
+ export default RevisionDiffViewer;
@@ -0,0 +1,21 @@
1
+ import React, { useEffect } from 'react';
2
+ import { getDiff } from '../utils/diff';
3
+ import SDocViewer from './sdoc-viewer';
4
+ import '../../assets/css/diff-viewer.css';
5
+ var DiffViewer = function DiffViewer(_ref) {
6
+ var currentContent = _ref.currentContent,
7
+ lastContent = _ref.lastContent,
8
+ didMountCallback = _ref.didMountCallback;
9
+ var diff = getDiff(currentContent, lastContent);
10
+ useEffect(function () {
11
+ didMountCallback && didMountCallback(diff);
12
+ }, [didMountCallback, diff]);
13
+ return /*#__PURE__*/React.createElement(SDocViewer, {
14
+ showToolbar: false,
15
+ showOutline: false,
16
+ document: {
17
+ children: diff.value
18
+ }
19
+ });
20
+ };
21
+ export default DiffViewer;
@@ -14,11 +14,6 @@ export var EXTERNAL_EVENT = {
14
14
  REMOVE_DOCUMENT: 'remove_document',
15
15
  REMOVE_DOCUMENT_ERROR: 'remove_document_error'
16
16
  };
17
- export var MODE = {
18
- DIFF_VIEWER: 'diff_viewer',
19
- VIEWER: 'viewer',
20
- EDITOR: 'editor'
21
- };
22
17
  export var TIP_TYPE = {
23
18
  DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
24
19
  MERGE: 'merge',
@@ -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
+ };
@@ -7,14 +7,15 @@ import Loading from '../components/loading';
7
7
  import DocInfo from '../components/doc-info';
8
8
  import DocOperations from '../components/doc-operations';
9
9
  import Layout, { Header, Content } from '../layout';
10
- import { generateDefaultDocContent } from '../utils';
11
10
  import context from '../context';
12
11
  import ErrorBoundary from './error-boundary';
13
12
  import TipDialog from '../components/tip-dialog';
14
- import { EXTERNAL_EVENT, MODE, TIP_TYPE, REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
13
+ import { EXTERNAL_EVENT, TIP_TYPE, REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
15
14
  import { getRebase, hasConflict } from '../basic-sdk/utils/rebase';
16
15
  import toaster from '../components/toast';
17
16
  import { EventBus, SDocEditor } from '../basic-sdk';
17
+ import { RevisionDiffViewer } from '../basic-sdk/views';
18
+ import { useDocument } from '../hooks/use-document';
18
19
  import '../assets/css/simple-editor.css';
19
20
  var SimpleEditor = function SimpleEditor(_ref) {
20
21
  var isStarred = _ref.isStarred,
@@ -22,56 +23,37 @@ var SimpleEditor = function SimpleEditor(_ref) {
22
23
  t = _ref.t;
23
24
  context.initApi();
24
25
  var editorRef = useRef(null);
25
- var _useState = useState(true),
26
+ var _useState = useState(false),
26
27
  _useState2 = _slicedToArray(_useState, 2),
27
- isLoadingSdoc = _useState2[0],
28
- setLoadingSdoc = _useState2[1];
29
- var _useState3 = useState(''),
28
+ isShowChanges = _useState2[0],
29
+ setShowChanges = _useState2[1];
30
+ var _useState3 = useState(null),
30
31
  _useState4 = _slicedToArray(_useState3, 2),
31
- errorMessage = _useState4[0],
32
- setErrorMessage = _useState4[1];
33
- var _useState5 = useState(false),
32
+ revisionContent = _useState4[0],
33
+ setRevisionContent = _useState4[1];
34
+ var _useState5 = useState([]),
34
35
  _useState6 = _slicedToArray(_useState5, 2),
35
- isShowChanges = _useState6[0],
36
- setShowChanges = _useState6[1];
37
- var _useState7 = useState(null),
36
+ changes = _useState6[0],
37
+ setChanges = _useState6[1];
38
+ var _useState7 = useState(false),
38
39
  _useState8 = _slicedToArray(_useState7, 2),
39
- document = _useState8[0],
40
- setDocument = _useState8[1];
41
- var _useState9 = useState(MODE.EDITOR),
40
+ showTip = _useState8[0],
41
+ setShowTip = _useState8[1];
42
+ var _useState9 = useState(''),
42
43
  _useState10 = _slicedToArray(_useState9, 2),
43
- mode = _useState10[0],
44
- setMode = _useState10[1];
44
+ tipType = _useState10[0],
45
+ setTipType = _useState10[1];
45
46
  var _useState11 = useState([]),
46
47
  _useState12 = _slicedToArray(_useState11, 2),
47
- changes = _useState12[0],
48
- setChanges = _useState12[1];
49
- var _useState13 = useState(false),
50
- _useState14 = _slicedToArray(_useState13, 2),
51
- showTip = _useState14[0],
52
- setShowTip = _useState14[1];
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];
61
- useEffect(function () {
62
- loadDocument(function (document) {
63
- setDocument(document);
64
- setLoadingSdoc(false);
65
- }, function (errorMessage) {
66
- setErrorMessage(errorMessage);
67
- setDocument(null);
68
- setLoadingSdoc(false);
69
- }, function () {
70
- setLoadingSdoc(true);
71
- });
72
-
73
- // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, []);
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;
75
57
 
76
58
  // useMount: reset title
77
59
  useEffect(function () {
@@ -140,132 +122,89 @@ var SimpleEditor = function SimpleEditor(_ref) {
140
122
 
141
123
  // eslint-disable-next-line react-hooks/exhaustive-deps
142
124
  }, []);
143
- var loadDocument = useCallback(function (successCallback, errorCallback, callback) {
144
- callback && callback();
145
- context.getFileContent().then(function (res) {
146
- var result = res.data || generateDefaultDocContent();
147
- if (result && !result.children) {
148
- result = {
149
- version: 0,
150
- children: result.content,
151
- cursors: result.cursors || {}
152
- };
153
- }
154
- successCallback && successCallback(result);
155
- }).catch(function (error) {
156
- // eslint-disable-next-line
157
- console.log(error);
158
- var errorMessage = 'Load_doc_content_error';
159
- if (error && error.response) {
160
- var _ref2 = error.response.data || {},
161
- error_type = _ref2.error_type;
162
- if (error_type === 'content_invalid') {
163
- errorMessage = 'Sdoc_format_invalid';
164
- }
165
- }
166
- errorCallback && errorCallback(errorMessage);
167
- });
168
- }, []);
169
- var setDiffContent = useCallback(function () {
170
- context.getSeadocOriginFileContent().then(function (res) {
171
- var originContentString = res.data.content;
172
- var originContent = JSON.parse(originContentString);
173
- editorRef.current.setDiffContent(originContent);
174
- editorRef.current.setLoading(false);
175
- }).catch(function (error) {
176
- console.log('error');
177
- });
178
- }, []);
179
125
  var toggleViewChanges = useCallback(function (isShowChanges) {
126
+ if (!isShowChanges) {
127
+ setShowChanges(isShowChanges);
128
+ reloadDocument();
129
+ return;
130
+ }
131
+
132
+ // Get the contents of the current revision
180
133
  var revisionContent = editorRef.current.getSlateValue();
181
- if (isShowChanges && hasConflict(revisionContent.children)) {
134
+
135
+ // Prevent users from switching if document contains conflicting content
136
+ if (hasConflict(revisionContent.children)) {
182
137
  setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
183
138
  setShowTip(true);
184
139
  return;
185
140
  }
186
- editorRef.current.setLoading(true);
187
- setShowChanges(isShowChanges);
188
- var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
189
- setMode(mode);
190
- editorRef.current.setEditorMode(mode);
191
- if (!isShowChanges) {
192
- loadDocument(function (document) {
193
- setDocument(document);
194
- editorRef.current.setSlateValue(document);
195
- editorRef.current.setLoading(false);
196
- }, function (errorMessage) {
197
- setErrorMessage(errorMessage);
198
- editorRef.current.setLoading(false);
199
- });
200
- return;
201
- }
202
- setDiffContent();
203
141
 
142
+ // Record the contents of the current revision
143
+ setRevisionContent(revisionContent);
144
+ setShowChanges(isShowChanges);
204
145
  // eslint-disable-next-line react-hooks/exhaustive-deps
205
146
  }, [document, editorRef.current]);
147
+ var setDiffChanges = useCallback(function (diff) {
148
+ setChanges(diff.changes);
149
+ // eslint-disable-next-line react-hooks/exhaustive-deps
150
+ }, [isShowChanges]);
206
151
  var publishRevision = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
152
+ var revisionPromise, baseVersionPromise, originVersionPromise;
207
153
  return _regeneratorRuntime().wrap(function _callee$(_context) {
208
154
  while (1) switch (_context.prev = _context.next) {
209
155
  case 0:
210
156
  setTipType(TIP_TYPE.CHECKING);
211
157
  setShowTip(true);
212
- loadDocument(function (document) {
213
- var revisionContent = document;
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);
214
168
  if (hasConflict(revisionContent.children)) {
215
169
  setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
216
170
  setShowTip(true);
217
171
  return;
218
172
  }
219
- var baseContent;
220
- var masterContent;
221
- context.getRevisionBaseVersionContent().then(function (res) {
222
- var baseVersionContentString = res.data.content; // commit content
223
- baseContent = JSON.parse(baseVersionContentString);
224
- return context.getSeadocOriginFileContent();
225
- }).then(function (res) {
226
- var masterContentString = res.data.content;
227
- masterContent = JSON.parse(masterContentString);
228
- var _getRebase = getRebase(masterContent, baseContent, revisionContent),
229
- canMerge = _getRebase.canMerge,
230
- isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
231
- value = _getRebase.value;
232
- if (canMerge && isNeedReplaceMaster) {
233
- setTipType(TIP_TYPE.PUBLISHING);
234
- context.publishRevision().then(function (res) {
235
- setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
236
- setShowTip(true);
237
- }).catch(function (error) {
238
- toaster.danger(t('Error'));
239
- });
240
- return;
241
- }
242
- if (canMerge && !isNeedReplaceMaster) {
243
- setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
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);
244
181
  setShowTip(true);
245
- return;
246
- }
247
- setMergeValue(value);
248
- setTipType(TIP_TYPE.MERGE);
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);
249
189
  setShowTip(true);
250
- }).catch(function (error) {
251
- toaster.danger(t('Error'));
252
- });
253
- }, function (errorMessage) {
254
- toaster.danger(t(errorMessage));
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'));
255
201
  });
256
-
257
- // eslint-disable-next-line react-hooks/exhaustive-deps
258
- case 3:
202
+ case 6:
259
203
  case "end":
260
204
  return _context.stop();
261
205
  }
262
206
  }, _callee);
263
- })), [isShowChanges, mode]);
264
- var setDiffChanges = useCallback(function (diff) {
265
- setChanges(diff.changes);
266
-
267
- // eslint-disable-next-line react-hooks/exhaustive-deps
268
- }, [isShowChanges]);
207
+ })), [loadDocument, t]);
269
208
  var jumpToURL = useCallback(function (url) {
270
209
  window.location.href = url;
271
210
  }, []);
@@ -305,12 +244,12 @@ var SimpleEditor = function SimpleEditor(_ref) {
305
244
  context.updateSettings({
306
245
  'originFileVersion': origin_file_version
307
246
  });
308
- editorRef.current.setLoading(true);
247
+ // if revision diff view change to sdoc editor
248
+ if (isShowChanges) {
249
+ setShowChanges(false);
250
+ }
309
251
  editorRef.current.setSlateValue(mergeValue);
310
252
  editorRef.current.updateDocumentVersion(mergeValue);
311
- setMode(MODE.EDITOR);
312
- editorRef.current.setEditorMode(MODE.EDITOR);
313
- editorRef.current.setLoading(false);
314
253
  setShowTip(false);
315
254
  }).catch(function (error) {
316
255
  callback && callback(false);
@@ -322,7 +261,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
322
261
 
323
262
  // eslint-disable-next-line react-hooks/exhaustive-deps
324
263
  }, [tipType, mergeValue, editorRef.current, document]);
325
- if (isLoadingSdoc) {
264
+ if (isFirstLoading) {
326
265
  return /*#__PURE__*/React.createElement(Loading, null);
327
266
  }
328
267
  if (errorMessage) {
@@ -341,11 +280,13 @@ var SimpleEditor = function SimpleEditor(_ref) {
341
280
  changes: changes,
342
281
  toggleViewChanges: toggleViewChanges,
343
282
  publishRevision: publishRevision
344
- })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
283
+ })), /*#__PURE__*/React.createElement(Content, null, !isShowChanges && /*#__PURE__*/React.createElement(SDocEditor, {
345
284
  ref: editorRef,
346
- document: document,
347
- mode: mode,
348
- setDiffChanges: setDiffChanges
285
+ isReloading: isReloading,
286
+ document: document
287
+ }), isShowChanges && /*#__PURE__*/React.createElement(RevisionDiffViewer, {
288
+ revisionContent: revisionContent,
289
+ didMountCallback: setDiffChanges
349
290
  }))), showTip && /*#__PURE__*/React.createElement(TipDialog, {
350
291
  toggle: closeTip,
351
292
  submit: tipSubmit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.166",
3
+ "version": "0.1.167beta",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -1,33 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import context from '../../context';
3
- import { getDiff } from '../utils/diff';
4
- import SDocViewer from './sdoc-viewer';
5
- import '../../assets/css/diff-viewer.css';
6
- var DiffViewer = function DiffViewer(_ref) {
7
- var editor = _ref.editor,
8
- currentContent = _ref.currentContent,
9
- lastContent = _ref.lastContent,
10
- didMountCallback = _ref.didMountCallback,
11
- showToolbar = _ref.showToolbar,
12
- showOutline = _ref.showOutline;
13
- var diff = getDiff(currentContent, lastContent);
14
- context.initSettings();
15
- useEffect(function () {
16
- didMountCallback && didMountCallback(diff);
17
-
18
- // eslint-disable-next-line react-hooks/exhaustive-deps
19
- }, []);
20
- return /*#__PURE__*/React.createElement(SDocViewer, {
21
- editor: editor,
22
- showToolbar: showToolbar,
23
- showOutline: showOutline,
24
- document: {
25
- children: diff.value
26
- }
27
- });
28
- };
29
- DiffViewer.defaultProps = {
30
- showToolbar: false,
31
- showOutline: false
32
- };
33
- export default DiffViewer;