@seafile/sdoc-editor 0.1.159-beta11 → 0.1.159-beta12

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.
@@ -88,9 +88,13 @@ var SeafileAPI = /*#__PURE__*/function () {
88
88
  }
89
89
  }, {
90
90
  key: "updateSdocRevision",
91
- value: function updateSdocRevision(docUuid) {
91
+ value: function updateSdocRevision(docUuid, docName) {
92
+ var docContent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
92
93
  var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
93
- return this.req.put(url);
94
+ var formData = new FormData();
95
+ var newFile = new File([JSON.stringify(docContent)], docName);
96
+ formData.append('file', newFile);
97
+ return this.req.put(url, formData);
94
98
  }
95
99
  }, {
96
100
  key: "getRevisionBasicVersionContent",
@@ -97,8 +97,8 @@ var Editor = forwardRef(function (_ref, ref) {
97
97
  publishDocument: function publishDocument(originDocUuid, originDocName, callback) {
98
98
  editor.publishDocument(originDocUuid, originDocName, callback);
99
99
  },
100
- replaceDocument: function replaceDocument(value, originFileVersion) {
101
- editor.replaceDocument(value, originFileVersion);
100
+ replaceDocument: function replaceDocument(value, callback) {
101
+ editor.replaceDocument(value, callback);
102
102
  }
103
103
 
104
104
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -42,10 +42,14 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
42
42
  this.receiveRemoveDocumentError = function () {
43
43
  _this.eventBus.dispatch(EXTERNAL_EVENT.REMOVE_DOCUMENT_ERROR);
44
44
  };
45
- this.sendReplaceDocument = function (document) {
45
+ this.sendReplaceDocument = function (document, callback) {
46
46
  _this.socketClient.sendReplaceDocument(document, function (result) {
47
- var serverVersion = result.version;
48
- _this.document['version'] = serverVersion;
47
+ var serverVersion = result.version,
48
+ success = result.success;
49
+ if (success) {
50
+ _this.document['version'] = serverVersion;
51
+ }
52
+ callback && callback(success);
49
53
  });
50
54
  };
51
55
  this.receiveDocumentReplaced = function () {
@@ -59,10 +59,10 @@ var withSocketIO = function withSocketIO(editor, options) {
59
59
  var socketManager = SocketManager.getInstance(newEditor, document, config);
60
60
  socketManager.sendPublishDocument(originDocUuid, originDocName, callback);
61
61
  };
62
- newEditor.replaceDocument = function (document) {
62
+ newEditor.replaceDocument = function (document, callback) {
63
63
  var config = options.config;
64
64
  var socketManager = SocketManager.getInstance(newEditor, document, config);
65
- socketManager.sendReplaceDocument(document);
65
+ socketManager.sendReplaceDocument(document, callback);
66
66
  };
67
67
  return newEditor;
68
68
  };
package/dist/context.js CHANGED
@@ -193,9 +193,10 @@ var Context = /*#__PURE__*/function () {
193
193
  }
194
194
  }, {
195
195
  key: "updateSdocRevision",
196
- value: function updateSdocRevision() {
196
+ value: function updateSdocRevision(sdocContent) {
197
197
  var docUuid = this.getSetting('docUuid');
198
- return this.api.updateSdocRevision(docUuid);
198
+ var docName = this.getSetting('docName');
199
+ return this.api.updateSdocRevision(docUuid, docName, sdocContent);
199
200
  }
200
201
  }, {
201
202
  key: "deleteSdocRevision",
@@ -84,11 +84,12 @@ var SimpleEditor = function SimpleEditor(_ref) {
84
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
85
  }, []);
86
86
  var onDocumentReplaced = useCallback(function () {
87
+ if (showTip) return;
87
88
  setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
88
89
  setShowTip(true);
89
90
 
90
91
  // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, [editorRef]);
92
+ }, [editorRef, showTip]);
92
93
  var hasPublishRevision = useCallback(function () {
93
94
  if (showTip) return;
94
95
  setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
@@ -270,12 +271,20 @@ var SimpleEditor = function SimpleEditor(_ref) {
270
271
  return;
271
272
  }
272
273
  if (tipType === TIP_TYPE.MERGE) {
273
- context.updateSdocRevision().then(function (res) {
274
+ var _context$getUserInfo = context.getUserInfo(),
275
+ username = _context$getUserInfo.username;
276
+ var doc = {
277
+ children: mergeValue.children,
278
+ version: mergeValue.version,
279
+ format_version: document.format_version,
280
+ docName: document.docName,
281
+ last_modify_user: username
282
+ };
283
+ context.updateSdocRevision(doc).then(function (res) {
274
284
  var origin_file_version = res.data.origin_file_version;
275
285
  context.updateSettings({
276
286
  'originFileVersion': origin_file_version
277
287
  });
278
- editorRef.current.replaceDocument(mergeValue);
279
288
  editorRef.current.setLoading(true);
280
289
  editorRef.current.setSlateValue(mergeValue);
281
290
  setMode(MODE.EDITOR);
@@ -290,7 +299,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
290
299
  setShowTip(false);
291
300
 
292
301
  // eslint-disable-next-line react-hooks/exhaustive-deps
293
- }, [tipType, mergeValue, editorRef.current]);
302
+ }, [tipType, mergeValue, editorRef.current, document]);
294
303
  if (isLoadingSdoc) {
295
304
  return /*#__PURE__*/React.createElement(Loading, null);
296
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.159beta11",
3
+ "version": "0.1.159beta12",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",