@seafile/sdoc-editor 0.1.159-beta10 → 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.
@@ -84,13 +84,17 @@ var SeafileAPI = /*#__PURE__*/function () {
84
84
  key: "publishRevision",
85
85
  value: function publishRevision(docUuid) {
86
86
  var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
87
- return this._sendPostRequest(url);
87
+ return this.req.post(url);
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",
@@ -93,15 +93,12 @@ var Editor = forwardRef(function (_ref, ref) {
93
93
  children: slateValue
94
94
  }));
95
95
  },
96
- saveDocument: function saveDocument(callback) {
97
- return editor.saveDocument(callback);
98
- },
99
96
  // send message
100
97
  publishDocument: function publishDocument(originDocUuid, originDocName, callback) {
101
98
  editor.publishDocument(originDocUuid, originDocName, callback);
102
99
  },
103
- replaceDocument: function replaceDocument(value, originFileVersion) {
104
- editor.replaceDocument(value, originFileVersion);
100
+ replaceDocument: function replaceDocument(value, callback) {
101
+ editor.replaceDocument(value, callback);
105
102
  }
106
103
 
107
104
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -150,13 +150,6 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
150
150
  var socketManager = SocketManager.getInstance();
151
151
  socketManager.receiveDocumentReplacedError();
152
152
  };
153
- this.sendSaveDocument = function (callback) {
154
- _this.socket.emit('save-document', _this.getParams({
155
- document: document
156
- }), function (saveFlag) {
157
- callback && callback(saveFlag);
158
- });
159
- };
160
153
  this.receiveRemoveDocument = function () {
161
154
  var socketManager = SocketManager.getInstance();
162
155
  socketManager.receiveRemoveDocument();
@@ -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 () {
@@ -54,9 +58,6 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
54
58
  this.receiveDocumentReplacedError = function () {
55
59
  _this.eventBus.dispatch(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR);
56
60
  };
57
- this.sendSaveDocument = function (callback) {
58
- _this.socketClient.sendSaveDocument(callback);
59
- };
60
61
  this.onReceiveLocalOperations = function (operations) {
61
62
  _this.pendingOperationList.push(operations);
62
63
  if (_this.pendingOperationList.length > 5) {
@@ -59,15 +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);
66
- };
67
- newEditor.saveDocument = function (callback) {
68
- var config = options.config;
69
- var socketManager = SocketManager.getInstance(newEditor, document, config);
70
- socketManager.sendSaveDocument(callback);
65
+ socketManager.sendReplaceDocument(document, callback);
71
66
  };
72
67
  return newEditor;
73
68
  };
@@ -4,6 +4,7 @@ import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
4
4
  import classnames from 'classnames';
5
5
  import { TIP_TYPE, TIP_TITLE } from '../../constants';
6
6
  import TipContent from './tip-content';
7
+ var NOT_CLOSE_DIALOG_TIP_TYPE = [TIP_TYPE.HAS_BEEN_REPLACED, TIP_TYPE.HAS_BEEN_PUBLISHED];
7
8
  var TipDialog = function TipDialog(_ref) {
8
9
  var className = _ref.className,
9
10
  tipType = _ref.tipType,
@@ -12,7 +13,8 @@ var TipDialog = function TipDialog(_ref) {
12
13
  var _useTranslation = useTranslation(),
13
14
  t = _useTranslation.t;
14
15
  var closeDialog = useCallback(function () {
15
- toggle && toggle(false);
16
+ if (NOT_CLOSE_DIALOG_TIP_TYPE.includes(tipType)) return;
17
+ toggle && toggle();
16
18
 
17
19
  // eslint-disable-next-line react-hooks/exhaustive-deps
18
20
  }, [tipType]);
@@ -30,12 +32,12 @@ var TipDialog = function TipDialog(_ref) {
30
32
  className: classnames('sdoc-tip-dialog', className),
31
33
  contentClassName: "sdoc-tip-modal"
32
34
  }, /*#__PURE__*/React.createElement(ModalHeader, {
33
- toggle: [TIP_TYPE.HAS_BEEN_REPLACED, TIP_TYPE.HAS_BEEN_PUBLISHED].includes(tipType) ? undefined : closeDialog
35
+ toggle: NOT_CLOSE_DIALOG_TIP_TYPE.includes(tipType) ? undefined : closeDialog
34
36
  }, t(TIP_TITLE[tipType])), /*#__PURE__*/React.createElement(ModalBody, {
35
37
  className: "sdoc-tip-body"
36
38
  }, /*#__PURE__*/React.createElement(TipContent, {
37
39
  tipType: tipType
38
- })), ![TIP_TYPE.HAS_BEEN_REPLACED, TIP_TYPE.HAS_BEEN_PUBLISHED].includes(tipType) && /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
40
+ })), !NOT_CLOSE_DIALOG_TIP_TYPE.includes(tipType) && /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
39
41
  color: "secondary",
40
42
  className: "mr-2",
41
43
  onClick: closeDialog
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.159beta10",
3
+ "version": "0.1.159beta12",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",