@seafile/sdoc-editor 0.1.109 → 0.1.111

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.
@@ -10,6 +10,9 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
10
10
  _classCallCheck(this, SocketManager);
11
11
  this.addOperations = function (operations) {
12
12
  _this.pendingOperationList.push(operations);
13
+ if (_this.pendingOperationList.length > 5) {
14
+ _this.dispatchConnectState('pending_operations_exceed_limit');
15
+ }
13
16
  _this.sendOperations();
14
17
  };
15
18
  this.getDocumentVersion = function () {
@@ -36,7 +39,8 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
36
39
  if (result && result.success) {
37
40
  var serverVersion = result.version;
38
41
  _this.document['version'] = serverVersion;
39
- _this.dispatchConnectState('saved');
42
+ var lastSavedAt = new Date().getTime();
43
+ _this.dispatchConnectState('saved', lastSavedAt);
40
44
  _this.sendNextOperations();
41
45
  return;
42
46
  }
@@ -48,6 +52,9 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
48
52
  // Put the failed operation into the pending list and re-execute it
49
53
  _this.pendingOperationList.unshift(operations);
50
54
  _this.sendNextOperations();
55
+ } else if (error_type === 'document_content_load_failed') {
56
+ // After a short-term reconnection, the content of the document fails to load
57
+ _this.dispatchConnectState(error_type);
51
58
  } else if (error_type === 'operation_exec_error') {
52
59
  _this.editor.isRemote = true;
53
60
  revertOperationList(_this.editor, [operations]);
@@ -4,6 +4,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import { withTranslation } from 'react-i18next';
7
+ import dayjs from 'dayjs';
7
8
  import { EventBus } from '../../basic-sdk';
8
9
  import toaster from '../toast';
9
10
  import './style.css';
@@ -22,6 +23,22 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
22
23
  duration: null
23
24
  });
24
25
  };
26
+ _this.onPendingOpExceedLimit = function () {
27
+ var t = _this.props.t;
28
+ toaster.closeAll();
29
+ var message = t('Pending_operations_exceed_limit');
30
+ toaster.warning(message, {
31
+ duration: 5
32
+ });
33
+ };
34
+ _this.onDocumentLoadError = function () {
35
+ var t = _this.props.t;
36
+ var message = t('Document_content_load_failed');
37
+ toaster.danger(message, {
38
+ hasCloseButton: true,
39
+ duration: null
40
+ });
41
+ };
25
42
  _this.onDisconnect = function () {
26
43
  var _this$props = _this.props,
27
44
  t = _this$props.t,
@@ -58,11 +75,12 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
58
75
  isSaved: false
59
76
  });
60
77
  };
61
- _this.onDocumentSaved = function () {
78
+ _this.onDocumentSaved = function (lastSavedAt) {
62
79
  if (_this.saveTimer) clearTimeout(_this.saveTimer);
63
80
  if (_this.resetTimer) clearTimeout(_this.resetTimer);
64
81
  _this.saveTimer = setTimeout(function () {
65
82
  _this.setState({
83
+ lastSavedAt: lastSavedAt,
66
84
  isSaving: false,
67
85
  isSaved: true
68
86
  });
@@ -78,7 +96,8 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
78
96
  var t = _this.props.t;
79
97
  var _this$state = _this.state,
80
98
  isSaved = _this$state.isSaved,
81
- isSaving = _this$state.isSaving;
99
+ isSaving = _this$state.isSaving,
100
+ lastSavedAt = _this$state.lastSavedAt;
82
101
  if (isSaving && !isSaved) {
83
102
  return /*#__PURE__*/React.createElement("span", {
84
103
  className: "tip-message"
@@ -89,11 +108,17 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
89
108
  className: "tip-message"
90
109
  }, t('All_changes_saved'));
91
110
  }
111
+ if (lastSavedAt) {
112
+ return /*#__PURE__*/React.createElement("span", {
113
+ className: "tip-message"
114
+ }, /*#__PURE__*/React.createElement("span", null, t('Recently_saved'), ' '), /*#__PURE__*/React.createElement("span", null, dayjs(lastSavedAt).format('HH:mm')));
115
+ }
92
116
  return null;
93
117
  };
94
118
  _this.state = {
95
119
  isSaved: false,
96
- isSaving: false
120
+ isSaving: false,
121
+ lastSavedAt: ''
97
122
  };
98
123
  _this.saveTimer = null;
99
124
  return _this;
@@ -111,12 +136,15 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
111
136
 
112
137
  // op execute error
113
138
  this.unsubscribeOpExecError = eventBus.subscribe('operation_exec_error', this.onOperationExecuteError);
139
+ this.unsubscribePendingOpExceedLimit = eventBus.subscribe('pending_operations_exceed_limit', this.onPendingOpExceedLimit);
140
+ this.unsubscribeDocumentLoadError = eventBus.subscribe('document_content_load_failed', this.onDocumentLoadError);
114
141
  }
115
142
  }, {
116
143
  key: "componentWillUnmount",
117
144
  value: function componentWillUnmount() {
118
145
  this.unsubscribeSavingEvent();
119
146
  this.unsubscribeSavedEvent();
147
+ this.unsubscribeDocumentLoadError();
120
148
  clearTimeout(this.saveTimer);
121
149
  }
122
150
  }]);
@@ -17,7 +17,7 @@ var wrapperClass = css({
17
17
  left: 0,
18
18
  right: 0,
19
19
  position: 'fixed',
20
- zIndex: 30
20
+ zIndex: 120
21
21
  });
22
22
  var hasCustomId = function hasCustomId(settings) {
23
23
  return Object.hasOwnProperty.call(settings, 'id');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.109",
3
+ "version": "0.1.111",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -339,5 +339,8 @@
339
339
  "Reduce_font_size": "Reduce font size",
340
340
  "Font": "Font",
341
341
  "All_fonts": "All fonts",
342
- "Default_font": "Default font"
342
+ "Default_font": "Default font",
343
+ "Document_content_load_failed": "Document content failed to load, please refresh the page to try again",
344
+ "Pending_operations_exceed_limit": "There are multiple operations not synced to the server. Please check your network.",
345
+ "Recently_saved": "Recently saved"
343
346
  }
@@ -341,5 +341,8 @@
341
341
  "Reduce_font_size": "减小字号",
342
342
  "Font": "字体",
343
343
  "All_fonts": "所有字体",
344
- "Default_font": "默认字体"
344
+ "Default_font": "默认字体",
345
+ "Document_content_load_failed": "文档内容加载失败, 请刷新页面重新访问",
346
+ "Pending_operations_exceed_limit": "有多个操作未同步到服务器。请检查你的网络。",
347
+ "Recently_saved": "最近保存"
345
348
  }