@seafile/sdoc-editor 0.1.146-beta → 0.1.146-beta-4

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.
@@ -101,8 +101,8 @@ var Editor = forwardRef(function (_ref, ref) {
101
101
  }));
102
102
  },
103
103
  // send message
104
- publishDocument: function publishDocument(originFileURL) {
105
- editor.publishDocument(originFileURL);
104
+ publishDocument: function publishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc) {
105
+ editor.publishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc);
106
106
  },
107
107
  mergeDocument: function mergeDocument(value, originFileVersion) {
108
108
  editor.mergeDocument(value, originFileVersion);
@@ -123,27 +123,22 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
123
123
  var socketManager = SocketManager.getInstance();
124
124
  socketManager.receiveRebaseContent(document, originFileVersion);
125
125
  };
126
- this.sendRebaseDocument = function (document, originFileVersion, callback) {
127
- debug('=========== send operations ==========');
128
- debug('%O', document);
129
- debug('======================================');
130
- _this.socket.emit('rebase-document', _this.getParams({
131
- document: document,
132
- originFileVersion: originFileVersion
133
- }), function (result) {
134
- callback && callback(result);
135
- });
136
- };
137
- this.sendPublishDocument = function (originFileURL, callback) {
126
+ this.sendPublishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc, callback) {
138
127
  _this.socket.emit('publish-document', _this.getParams({
139
- originFileURL: originFileURL
128
+ origin_doc_uuid: originDocUuid,
129
+ origin_doc_name: originDocName,
130
+ update_origin_doc: isNeedUpdateOriginDoc
140
131
  }), function (result) {
141
132
  callback && callback(result);
142
133
  });
143
134
  };
144
- this.receivePublishDocument = function (originFileURL) {
135
+ this.receivePublishDocument = function () {
145
136
  var socketManager = SocketManager.getInstance();
146
- socketManager.receivePublishDocument(originFileURL);
137
+ socketManager.receivePublishDocument();
138
+ };
139
+ this.receivePublishDocumentError = function () {
140
+ var socketManager = SocketManager.getInstance();
141
+ socketManager.receivePublishDocumentError();
147
142
  };
148
143
  this.sendMergeDocument = function (document, originFileVersion, callback) {
149
144
  _this.socket.emit('merge-document', _this.getParams({
@@ -157,6 +152,14 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
157
152
  var socketManager = SocketManager.getInstance();
158
153
  socketManager.receiveMergeDocument(document, originFileVersion);
159
154
  };
155
+ this.receiveMergeDocumentError = function () {
156
+ var socketManager = SocketManager.getInstance();
157
+ socketManager.receiveMergeDocumentError();
158
+ };
159
+ this.receiveUpdateDocumentFromHardDisk = function (document) {
160
+ var socketManager = SocketManager.getInstance();
161
+ socketManager.receiveUpdateDocumentFromHardDisk(document);
162
+ };
160
163
  this.config = config;
161
164
  this.isReconnect = false;
162
165
  this.socket = io(config.sdocServer, {
@@ -173,7 +176,10 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
173
176
  this.socket.on('update-document', this.onReceiveRemoteOperations);
174
177
  this.socket.on('rebase-document', this.receiveRebaseDocument);
175
178
  this.socket.on('merge-document', this.receiveMergeDocument);
179
+ this.socket.on('merge-document-error', this.receiveMergeDocumentError);
176
180
  this.socket.on('publish-document', this.receivePublishDocument);
181
+ this.socket.on('publish-document-error', this.receivePublishDocumentError);
182
+ this.socket.on('update-document-from-hard-disk', this.receiveUpdateDocumentFromHardDisk);
177
183
  this.socket.on('update-cursor', this.receiveCursorLocation);
178
184
  this.socket.io.on('reconnect', this.onReconnect);
179
185
  this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
@@ -27,17 +27,14 @@ 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, originFileVersion) {
31
- _this.socketClient.sendRebaseDocument(document, originFileVersion, function (result) {
32
- var serverVersion = result.version;
33
- _this.document['version'] = serverVersion;
34
- });
30
+ this.sendPublishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc) {
31
+ _this.socketClient.sendPublishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc);
35
32
  };
36
- this.sendPublishDocument = function (originFileURL) {
37
- _this.socketClient.sendPublishDocument(originFileURL);
33
+ this.receivePublishDocument = function () {
34
+ _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT);
38
35
  };
39
- this.receivePublishContent = function (originFileURL) {
40
- _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT, originFileURL);
36
+ this.receivePublishDocumentError = function () {
37
+ _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR);
41
38
  };
42
39
  this.sendMergeDocument = function (document, originFileVersion) {
43
40
  _this.socketClient.sendMergeDocument(document, originFileVersion, function (result) {
@@ -49,6 +46,13 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
49
46
  _this.document = document;
50
47
  _this.eventBus.dispatch(EXTERNAL_EVENT.MERGE_DOCUMENT, document, originFileVersion);
51
48
  };
49
+ this.receiveMergeDocumentError = function () {
50
+ _this.eventBus.dispatch(EXTERNAL_EVENT.MERGE_DOCUMENT_ERROR);
51
+ };
52
+ this.receiveUpdateDocumentFromHardDisk = function (document) {
53
+ _this.document = document;
54
+ _this.eventBus.dispatch(EXTERNAL_EVENT.UPDATE_DOCUMENT_FROM_HARD_DISK, document);
55
+ };
52
56
  this.onReceiveLocalOperations = function (operations) {
53
57
  _this.pendingOperationList.push(operations);
54
58
  if (_this.pendingOperationList.length > 5) {
@@ -54,10 +54,10 @@ var withSocketIO = function withSocketIO(editor, options) {
54
54
  var socketManager = SocketManager.getInstance(newEditor, document, config);
55
55
  socketManager.sendRebaseContent(document, originFileVersion);
56
56
  };
57
- newEditor.publishDocument = function (originFileURL) {
57
+ newEditor.publishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc) {
58
58
  var config = options.config;
59
59
  var socketManager = SocketManager.getInstance(newEditor, document, config);
60
- socketManager.sendPublishDocument(document, originFileURL);
60
+ socketManager.sendPublishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc);
61
61
  };
62
62
  newEditor.mergeDocument = function (document, originFileVersion) {
63
63
  var config = options.config;
@@ -32,7 +32,7 @@ var TipContent = function TipContent(_ref) {
32
32
  var siteRoot = context.getSetting('siteRoot');
33
33
  var originFilePath = context.getSetting('originFilePath');
34
34
  var originFileURL = "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath);
35
- window.href = originFileURL;
35
+ window.location.href = originFileURL;
36
36
  }
37
37
  }, [time]);
38
38
  var _useTranslation = useTranslation(),
@@ -5,15 +5,16 @@ export var EXTERNAL_EVENT = {
5
5
  TOGGLE_STAR: 'toggle_star',
6
6
  UNMARK_AS_DRAFT: 'unmark_as_draft',
7
7
  SHARE_SDOC: 'share_sdoc',
8
- // REBASE_DOCUMENT: 'rebase_document',
9
8
  PUBLISH_DOCUMENT: 'publish_document',
10
- MERGE_DOCUMENT: 'merge_document'
9
+ PUBLISH_DOCUMENT_ERROR: 'publish_document_error',
10
+ MERGE_DOCUMENT: 'merge_document',
11
+ MERGE_DOCUMENT_ERROR: 'merge_document_error',
12
+ UPDATE_DOCUMENT_FROM_HARD_DISK: 'update-document-from-hard-disk'
11
13
  };
12
14
  export var MODE = {
13
15
  DIFF_VIEWER: 'diff-viewer',
14
16
  VIEWER: 'viewer',
15
- EDITOR: 'editor',
16
- REBASE: 'rebase'
17
+ EDITOR: 'editor'
17
18
  };
18
19
  export var TIP_TYPE = {
19
20
  DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
@@ -24,6 +24,8 @@ var SimpleEditor = function SimpleEditor(_ref) {
24
24
  var originFilePath = context.getSetting('originFilePath');
25
25
  var isRevision = context.getSetting('isSdocRevision');
26
26
  var originFileURL = isRevision ? "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath) : '';
27
+ var originDocName = isRevision ? context.getSetting('originFilename') : '';
28
+ var originDocUuid = isRevision ? context.getSetting('originDocUuid') : '';
27
29
  var editorRef = useRef(null);
28
30
  var _useState = useState(true),
29
31
  _useState2 = _slicedToArray(_useState, 2),
@@ -66,29 +68,39 @@ var SimpleEditor = function SimpleEditor(_ref) {
66
68
 
67
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
68
70
  }, []);
69
-
70
- // 提示刷新界面: 主动刷新
71
- var mergeDocument = useCallback(function (document, originFileVersion) {
71
+ var mergeDocument = useCallback(function () {
72
72
  setTipType(TIP_TYPE.HAS_BEEN_MERGE);
73
73
  setShowTip(true);
74
74
 
75
75
  // eslint-disable-next-line react-hooks/exhaustive-deps
76
76
  }, [editorRef]);
77
-
78
- // 提示刷新界面: 被动跳转
79
77
  var hasPublishRevision = useCallback(function () {
80
78
  setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
81
79
  setShowTip(true);
82
80
 
83
81
  // eslint-disable-next-line react-hooks/exhaustive-deps
84
82
  }, [editorRef]);
83
+ var mergeDocumentError = useCallback(function () {}, []);
84
+ var publishDocumentError = useCallback(function () {}, []);
85
+ var updateDocumentFromHardDisk = useCallback(function (document) {
86
+ setDocument(document);
87
+ editorRef.current.setSlateValue(document);
88
+
89
+ // eslint-disable-next-line react-hooks/exhaustive-deps
90
+ }, [editorRef.current]);
85
91
  useEffect(function () {
86
92
  var eventBus = EventBus.getInstance();
87
93
  var mergeDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.MERGE_DOCUMENT, mergeDocument);
88
94
  var publishDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
95
+ var mergeDocumentErrorSubscribe = eventBus.subscribe(EXTERNAL_EVENT.MERGE_DOCUMENT_ERROR, mergeDocumentError);
96
+ var publishDocumentErrorSubscribe = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, publishDocumentError);
97
+ var updateDocumentFromHardDiskSubscribe = eventBus.subscribe(EXTERNAL_EVENT.UPDATE_DOCUMENT_FROM_HARD_DISK, updateDocumentFromHardDisk);
89
98
  return function () {
90
99
  mergeDocumentSubscribe();
91
100
  publishDocumentSubscribe();
101
+ mergeDocumentErrorSubscribe();
102
+ publishDocumentErrorSubscribe();
103
+ updateDocumentFromHardDiskSubscribe();
92
104
  };
93
105
 
94
106
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -224,8 +236,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
224
236
  setShowTip(true);
225
237
  return;
226
238
  }
227
- var originFileVersion = context.getSetting('originFileVersion');
228
- var originFilePath = context.getSetting('originFilePath');
239
+ var originFileVersion = context.getSetting('originFileVersion'); // changing
229
240
  var revisionMasterContent;
230
241
  var masterContent;
231
242
  context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
@@ -245,7 +256,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
245
256
  value = _getRebase.value;
246
257
  if (canMerge && isNeedReplaceMaster) {
247
258
  context.publishSdocRevision().then(function (res) {
248
- editorRef.current.publishDocument(originFileURL);
259
+ editorRef.current.publishDocument(originDocUuid, originDocName, true);
249
260
  setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
250
261
  setShowTip(true);
251
262
  }).catch(function (error) {
@@ -266,7 +277,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
266
277
  });
267
278
 
268
279
  // eslint-disable-next-line react-hooks/exhaustive-deps
269
- }, [document, isShowChanges, mode]);
280
+ }, [document, isShowChanges, mode, originDocUuid, originDocName, originFilePath]);
270
281
  var abortRebase = useCallback(function () {
271
282
  toggleViewChanges(isShowChanges, true);
272
283
 
@@ -278,7 +289,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
278
289
  // eslint-disable-next-line react-hooks/exhaustive-deps
279
290
  }, [isShowChanges]);
280
291
  var jumpToURL = useCallback(function (url) {
281
- window.href = url;
292
+ window.location.href = url;
282
293
  }, []);
283
294
  var closeTip = useCallback(function () {
284
295
  setShowTip(false);
@@ -289,12 +300,9 @@ var SimpleEditor = function SimpleEditor(_ref) {
289
300
  if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
290
301
  context.deleteSdocRevision().then(function (res) {
291
302
  if (res.data.success) {
292
- // 通知其他用户文档已经发布
293
- var targetURL = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(originFilePath);
294
- editorRef.current.publishDocument(targetURL);
303
+ editorRef.current.publishDocument(originDocUuid, originDocName, false);
295
304
  setShowTip(false);
296
- // 跳转页面
297
- jumpToURL(targetURL);
305
+ jumpToURL(originFileURL);
298
306
  }
299
307
  }).catch(function (error) {
300
308
  toaster.danger(t('Error'));
@@ -307,11 +315,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
307
315
  context.updateSettings({
308
316
  'originFileVersion': origin_file_version
309
317
  });
310
-
311
- // 通知其他用户合并文档 并更新
312
318
  editorRef.current.mergeDocument(mergeValue, origin_file_version);
313
-
314
- // 当前用户更新内容
315
319
  editorRef.current.setLoading(true);
316
320
  editorRef.current.setSlateValue(mergeValue);
317
321
  setMode(MODE.EDITOR);
@@ -326,7 +330,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
326
330
  setShowTip(false);
327
331
 
328
332
  // eslint-disable-next-line react-hooks/exhaustive-deps
329
- }, [tipType, originFileURL, mergeValue, editorRef.current]);
333
+ }, [tipType, originFileURL, mergeValue, editorRef.current, originDocUuid, originDocName]);
330
334
  if (isLoadingSdoc) {
331
335
  return /*#__PURE__*/React.createElement(Loading, null);
332
336
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.146beta",
3
+ "version": "0.1.146beta-4",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",