@seafile/sdoc-editor 0.1.143-beta1 → 0.1.143-beta3

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.
@@ -16,7 +16,7 @@ var Editor = forwardRef(function (_ref, ref) {
16
16
  var mode = _ref.mode,
17
17
  document = _ref.document,
18
18
  setDiffChanges = _ref.setDiffChanges,
19
- toggleViewChanges = _ref.toggleViewChanges;
19
+ rebaseEnd = _ref.rebaseEnd;
20
20
  context.initApi();
21
21
  var editor = useMemo(function () {
22
22
  var defaultEditor = createDefaultEditor();
@@ -127,7 +127,7 @@ var Editor = forwardRef(function (_ref, ref) {
127
127
  editor: editor,
128
128
  version: document.version,
129
129
  updateSlateValue: updateSlateValue,
130
- toggleViewChanges: toggleViewChanges
130
+ rebaseEnd: rebaseEnd
131
131
  });
132
132
  }
133
133
  return null;
@@ -19,7 +19,7 @@ var SDocRebaseEditor = function SDocRebaseEditor(_ref) {
19
19
  editor = _ref.editor,
20
20
  version = _ref.version,
21
21
  updateSlateValue = _ref.updateSlateValue,
22
- toggleViewChanges = _ref.toggleViewChanges;
22
+ rebaseEnd = _ref.rebaseEnd;
23
23
  var _useTranslation = useTranslation(),
24
24
  t = _useTranslation.t;
25
25
 
@@ -39,14 +39,15 @@ var SDocRebaseEditor = function SDocRebaseEditor(_ref) {
39
39
  return item.rebaseType;
40
40
  }).length === 0) {
41
41
  context.rebaseSdocRevision().then(function (res) {
42
+ var origin_file_version = res.data.origin_file_version;
43
+ context.updateSettings({
44
+ 'originFileVersion': origin_file_version
45
+ });
42
46
  editor.rebaseContent({
43
47
  children: slateValue
44
- });
45
-
46
- // return context.saveDocContentByRebase();
48
+ }, origin_file_version);
47
49
  }).then(function (res) {
48
- // toaster.success(t('Successfully_rebase_'));
49
- // toggleViewChanges(false, true);
50
+ rebaseEnd();
50
51
  }).catch(function (error) {
51
52
  toaster.danger(t('Error'));
52
53
  });
@@ -187,14 +188,14 @@ var SDocRebaseEditor = function SDocRebaseEditor(_ref) {
187
188
  onClick: function onClick() {
188
189
  return deleteElement(element);
189
190
  }
190
- }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
191
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
191
192
  className: "mr-2 ml-2"
192
193
  }, '|'), /*#__PURE__*/React.createElement("div", {
193
194
  className: "sdoc-rebase-btn",
194
195
  onClick: function onClick() {
195
196
  return deleteMark(element);
196
197
  }
197
- }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
198
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
198
199
  className: "mr-2 ml-2"
199
200
  }, '|'), /*#__PURE__*/React.createElement("div", {
200
201
  className: "sdoc-rebase-btn",
@@ -224,14 +225,14 @@ var SDocRebaseEditor = function SDocRebaseEditor(_ref) {
224
225
  onClick: function onClick() {
225
226
  return useMasterChanges(element);
226
227
  }
227
- }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
228
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
228
229
  className: "mr-2 ml-2"
229
230
  }, '|'), /*#__PURE__*/React.createElement("div", {
230
231
  className: "sdoc-rebase-btn",
231
232
  onClick: function onClick() {
232
233
  return useCurrentChanges(element);
233
234
  }
234
- }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
235
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
235
236
  className: "mr-2 ml-2"
236
237
  }, '|'), /*#__PURE__*/React.createElement("div", {
237
238
  className: "sdoc-rebase-btn",
@@ -4,6 +4,7 @@ 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';
7
8
  export var getNodePathById = function getNodePathById(rootNode, nodeId) {
8
9
  var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
9
10
  if (rootNode.id === nodeId) return path;
@@ -252,7 +253,7 @@ export var reExecRevertOperationList = function reExecRevertOperationList(editor
252
253
  }
253
254
  };
254
255
  export var syncRemoteOperations = function syncRemoteOperations(editor, remoteOperations) {
255
- if (editor.isReadonly) return;
256
+ if (editor.mode !== MODE.EDITOR) return;
256
257
  if (remoteOperations.length === 0) return;
257
258
  Editor.withoutNormalizing(editor, function () {
258
259
  for (var i = 0; i < remoteOperations.length; i++) {
@@ -123,16 +123,17 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
123
123
  this.disconnectWithServer = function () {
124
124
  _this.socket.disconnect();
125
125
  };
126
- this.receiveRebaseDocument = function (document) {
126
+ this.receiveRebaseDocument = function (document, originFileVersion) {
127
127
  var socketManager = SocketManager.getInstance();
128
- socketManager.receiveRebaseContent(document);
128
+ socketManager.receiveRebaseContent(document, originFileVersion);
129
129
  };
130
- this.sendRebaseDocument = function (document, callback) {
130
+ this.sendRebaseDocument = function (document, originFileVersion, callback) {
131
131
  debug('=========== send operations ==========');
132
132
  debug('%O', document);
133
133
  debug('======================================');
134
134
  _this.socket.emit('rebase-document', _this.getParams({
135
- document: document
135
+ document: document,
136
+ originFileVersion: originFileVersion
136
137
  }), function (result) {
137
138
  callback && callback(result);
138
139
  });
@@ -7,7 +7,7 @@ import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, s
7
7
  import SocketClient from './socket-client';
8
8
  import debug from '../utils/debug';
9
9
  import { deleteCursor } from '../cursor/helper';
10
- import { EXTERNAL_EVENT } from '../../constants';
10
+ import { EXTERNAL_EVENT, MODE } from '../../constants';
11
11
 
12
12
  // idle --> sending --> conflict --> idle
13
13
  // --> conflict --> idle
@@ -27,12 +27,15 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
27
27
  var version = _this.document.version;
28
28
  return version;
29
29
  };
30
- this.sendRebaseContent = function (document) {
31
- _this.socketClient.sendRebaseDocument(document);
30
+ this.sendRebaseContent = function (document, originFileVersion) {
31
+ _this.socketClient.sendRebaseDocument(document, originFileVersion, function (result) {
32
+ var serverVersion = result.version;
33
+ _this.document['version'] = serverVersion;
34
+ });
32
35
  };
33
- this.receiveRebaseContent = function (document) {
36
+ this.receiveRebaseContent = function (document, originFileVersion) {
34
37
  _this.document = document;
35
- _this.eventBus.dispatch(EXTERNAL_EVENT.REBASE_DOCUMENT, document);
38
+ _this.eventBus.dispatch(EXTERNAL_EVENT.REBASE_DOCUMENT, document, originFileVersion);
36
39
  };
37
40
  this.onReceiveLocalOperations = function (operations) {
38
41
  _this.pendingOperationList.push(operations);
@@ -42,7 +45,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
42
45
  _this.sendOperations();
43
46
  };
44
47
  this.sendOperations = function () {
45
- if (_this.editor.isReadonly) return;
48
+ if (_this.editor.mode !== MODE.EDITOR) return;
46
49
  if (_this.state !== STATE.IDLE) return;
47
50
  _this.state = STATE.SENDING;
48
51
  _this.sendNextOperations();
@@ -49,11 +49,10 @@ var withSocketIO = function withSocketIO(editor, options) {
49
49
  }
50
50
  onChange();
51
51
  };
52
- newEditor.rebaseContent = function (document) {
53
- console.log('send rebase document: ', document);
52
+ newEditor.rebaseContent = function (document, originFileVersion) {
54
53
  var config = options.config;
55
54
  var socketManager = SocketManager.getInstance(newEditor, document, config);
56
- socketManager.sendRebaseContent(document);
55
+ socketManager.sendRebaseContent(document, originFileVersion);
57
56
  };
58
57
  return newEditor;
59
58
  };
package/dist/context.js CHANGED
@@ -48,6 +48,13 @@ var Context = /*#__PURE__*/function () {
48
48
  if (this.settings[key] === false) return this.settings[key];
49
49
  return this.settings[key] || '';
50
50
  }
51
+ }, {
52
+ key: "updateSettings",
53
+ value: function updateSettings(update) {
54
+ for (var key in update) {
55
+ this.settings[key] = update[key];
56
+ }
57
+ }
51
58
  }, {
52
59
  key: "getViewConfig",
53
60
  value: function getViewConfig() {
@@ -53,15 +53,15 @@ var SimpleEditor = function SimpleEditor(_ref) {
53
53
 
54
54
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
55
  }, []);
56
- var rebaseDocument = useCallback(function (document) {
57
- toaster.warning(t('Document_has_rebased'));
56
+ var rebaseDocument = useCallback(function (document, originFileVersion) {
57
+ toaster.warning(t('Document_rebased_tip'));
58
+ context.updateSettings({
59
+ originFileVersion: originFileVersion
60
+ });
58
61
  editorRef.current.setLoading(true);
59
62
  setShowChanges(false);
60
63
  setMode(MODE.EDITOR);
61
64
  editorRef.current.setEditorMode(MODE.EDITOR);
62
-
63
- //
64
- console.log('document: ', document);
65
65
  setDocument(document);
66
66
  editorRef.current.setSlateValue(document);
67
67
  editorRef.current.setLoading(false);
@@ -250,6 +250,15 @@ var SimpleEditor = function SimpleEditor(_ref) {
250
250
 
251
251
  // eslint-disable-next-line react-hooks/exhaustive-deps
252
252
  }, [document, isShowChanges, mode]);
253
+ var rebaseEnd = useCallback(function () {
254
+ editorRef.current.setLoading(true);
255
+ setShowChanges(false);
256
+ setMode(MODE.EDITOR);
257
+ editorRef.current.setEditorMode(MODE.EDITOR);
258
+ setFileContent();
259
+
260
+ // eslint-disable-next-line react-hooks/exhaustive-deps
261
+ }, []);
253
262
  var abortRebase = useCallback(function () {
254
263
  toggleViewChanges(isShowChanges, true);
255
264
 
@@ -307,7 +316,8 @@ var SimpleEditor = function SimpleEditor(_ref) {
307
316
  document: document,
308
317
  mode: mode,
309
318
  setDiffChanges: setDiffChanges,
310
- toggleViewChanges: toggleViewChanges
319
+ toggleViewChanges: toggleViewChanges,
320
+ rebaseEnd: rebaseEnd
311
321
  }))), showTip && /*#__PURE__*/React.createElement(TipDialog, {
312
322
  toggle: closeTipDialog,
313
323
  submit: deleteRevision,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.143beta1",
3
+ "version": "0.1.143beta3",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -369,5 +369,6 @@
369
369
  "Need_rebase": "Need rebase",
370
370
  "Abort": "Abort",
371
371
  "Tip": "Tip",
372
- "Rebase_delete_no_change_revision_tip": "No changes have been made in the revision, should the revision be deleted directly ?"
372
+ "Rebase_delete_no_change_revision_tip": "No changes have been made in the revision, should the revision be deleted directly ?",
373
+ "Document_rebased_tip": "Document has been rebased"
373
374
  }
@@ -368,5 +368,6 @@
368
368
  "Keep_both_modification": "保留两个更改",
369
369
  "Need_rebase": "需要变基",
370
370
  "Abort": "中止",
371
- "Rebase_delete_no_change_revision_tip": "修订稿未做任何改动,是否直接删除修订稿?"
371
+ "Rebase_delete_no_change_revision_tip": "修订稿未做任何改动,是否直接删除修订稿?",
372
+ "Document_rebased_tip": "文档已经变基了"
372
373
  }