@seafile/comment-editor 0.0.1-alpha.7 → 0.0.1-alpha.71

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.
Files changed (34) hide show
  1. package/dist/_i18n/index.js +37 -0
  2. package/dist/basic-sdk/context.js +8 -21
  3. package/dist/basic-sdk/editor/comment-editor.js +219 -234
  4. package/dist/basic-sdk/extension/commons/color-menu/color-item.js +4 -2
  5. package/dist/basic-sdk/extension/commons/color-menu/index.js +4 -2
  6. package/dist/basic-sdk/extension/commons/select/field-setting.js +3 -2
  7. package/dist/basic-sdk/extension/commons/select-file-dialog/local-files/index.js +4 -2
  8. package/dist/basic-sdk/extension/plugins/code-block/hover-menu/index.js +5 -3
  9. package/dist/basic-sdk/extension/plugins/file-link/hover-menu/index.js +5 -3
  10. package/dist/basic-sdk/extension/plugins/header/menu/index.js +3 -2
  11. package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -1
  12. package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +4 -2
  13. package/dist/basic-sdk/extension/plugins/image/render-elem.js +5 -3
  14. package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -1
  15. package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +1 -1
  16. package/dist/basic-sdk/extension/plugins/sdoc-link/hover-menu/index.js +4 -2
  17. package/dist/basic-sdk/extension/plugins/table/menu/color-selector-popover/color-item.js +4 -2
  18. package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/index.js +3 -2
  19. package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/insert-table-element.js +3 -2
  20. package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +1 -2
  21. package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +1 -1
  22. package/dist/basic-sdk/extension/plugins/text-style/menu/comemnt-editor-menu.js +1 -2
  23. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +4 -2
  24. package/dist/basic-sdk/extension/plugins/video/render-elem.js +1 -2
  25. package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +13 -9
  26. package/dist/basic-sdk/hooks/use-comment.js +23 -12
  27. package/dist/basic-sdk/model/index.js +1 -8
  28. package/dist/basic-sdk/socket/helpers.js +312 -0
  29. package/dist/components/error-boundary/error-page.js +4 -4
  30. package/dist/pages/seafile-comment-editor.js +49 -26
  31. package/package.json +6 -6
  32. package/dist/basic-sdk/model/notification.js +0 -18
  33. package/dist/components/tip-message/index.js +0 -194
  34. package/dist/components/tip-message/style.css +0 -15
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.validateOperation = exports.syncRemoteOperations = exports.syncRemoteCursorLocation = exports.revertOperationList = exports.reExecRevertOperationList = exports.getRevertOperationList = exports.getNodePathById = void 0;
9
+ var _slate = require("@seafile/slate");
10
+ var _deepCopy = _interopRequireDefault(require("deep-copy"));
11
+ var _helper = require("../cursor/helper");
12
+ var _core = require("../extension/core");
13
+ var OPERATION = _interopRequireWildcard(require("../node-id/constants"));
14
+ const getNodePathById = function (rootNode, nodeId) {
15
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
16
+ if (rootNode.id === nodeId) return path;
17
+ const {
18
+ children = []
19
+ } = rootNode;
20
+ for (let i = 0; i < children.length; i++) {
21
+ const child = children[i];
22
+ path.push(i);
23
+ const nodePath = getNodePathById(child, nodeId, path);
24
+ if (nodePath) return nodePath;
25
+ path.pop();
26
+ }
27
+ return null;
28
+ };
29
+ exports.getNodePathById = getNodePathById;
30
+ const validateOperation = (editor, operation) => {
31
+ let isValid = false;
32
+ let newOperation = (0, _deepCopy.default)(operation);
33
+ const {
34
+ type
35
+ } = newOperation;
36
+ switch (type) {
37
+ case OPERATION.INSERT_TEXT:
38
+ case OPERATION.REMOVE_TEXT:
39
+ {
40
+ const {
41
+ node_id,
42
+ path
43
+ } = newOperation;
44
+ const node = (0, _core.getNode)(editor, path);
45
+ // node is exist and node path is not changed
46
+ if (node && node.id === node_id) {
47
+ isValid = true;
48
+ break;
49
+ }
50
+
51
+ // node is exist but node path is changed
52
+ const nodePath = getNodePathById(editor, node_id);
53
+ if (nodePath) {
54
+ isValid = true;
55
+ newOperation.path = nodePath;
56
+ break;
57
+ }
58
+ // node is not exist
59
+ isValid = false;
60
+ break;
61
+ }
62
+ case OPERATION.INSERT_NODE:
63
+ {
64
+ let {
65
+ parent_node_id,
66
+ path
67
+ } = newOperation;
68
+ const parentNodePath = getNodePathById(editor, parent_node_id);
69
+ if (!parentNodePath) {
70
+ isValid = false;
71
+ break;
72
+ }
73
+ const parentPath = path.slice(0, path.length - 1);
74
+ if (parentPath.join() === parentNodePath.join()) {
75
+ isValid = true;
76
+ break;
77
+ }
78
+
79
+ // reset insert node path
80
+ const parentNode = (0, _core.getNode)(editor, path);
81
+ if (parentNode) {
82
+ const childLength = parentNode.children.length;
83
+ const index = Math.min(path[path.length - 1], childLength);
84
+ newOperation.path = parentNodePath.concat([index]);
85
+ isValid = true;
86
+ }
87
+ break;
88
+ }
89
+ case OPERATION.REMOVE_NODE:
90
+ {
91
+ const {
92
+ node_id,
93
+ path
94
+ } = newOperation;
95
+ const node = (0, _core.getNode)(editor, path);
96
+ // node is exist and node path is not changed
97
+ if (node && node.id === node_id) {
98
+ isValid = true;
99
+ break;
100
+ }
101
+
102
+ // node is exist but node path is changed
103
+ const nodePath = getNodePathById(editor, node_id);
104
+ if (nodePath) {
105
+ isValid = true;
106
+ newOperation.path = nodePath;
107
+ break;
108
+ }
109
+
110
+ // node is not exist
111
+ isValid = false;
112
+ break;
113
+ }
114
+ case OPERATION.MERGE_NODE:
115
+ {
116
+ // merge next node into prev node
117
+ const {
118
+ node_id,
119
+ path
120
+ } = newOperation;
121
+ const node = (0, _core.getNode)(editor, path);
122
+ // node is exist and node path is not changed
123
+ if (node && node.id === node_id) {
124
+ isValid = true;
125
+ break;
126
+ }
127
+
128
+ // node is exist but node path is changed
129
+ const nodePath = getNodePathById(editor, node_id);
130
+ if (nodePath) {
131
+ isValid = true;
132
+ newOperation.path = nodePath;
133
+ break;
134
+ }
135
+
136
+ // node is not exist
137
+ isValid = false;
138
+ break;
139
+ }
140
+ case OPERATION.SPLIT_NODE:
141
+ {
142
+ const {
143
+ node_id,
144
+ path
145
+ } = newOperation;
146
+ const node = (0, _core.getNode)(editor, path);
147
+ // node is exist and node path is not changed
148
+ if (node && node.id === node_id) {
149
+ isValid = true;
150
+ break;
151
+ }
152
+
153
+ // node is exist but node path is changed
154
+ const nodePath = getNodePathById(editor, node_id);
155
+ if (nodePath) {
156
+ isValid = true;
157
+ newOperation.path = nodePath;
158
+ break;
159
+ }
160
+
161
+ // node is not exist
162
+ isValid = false;
163
+ break;
164
+ }
165
+ case OPERATION.SET_NODE:
166
+ {
167
+ const {
168
+ node_id,
169
+ path,
170
+ properties
171
+ } = newOperation;
172
+ const node = (0, _core.getNode)(editor, path);
173
+ // node is exist and node path is not changed
174
+ if (node && node.id === node_id) {
175
+ isValid = true;
176
+ newOperation.properties = {
177
+ ...properties,
178
+ type: node.type
179
+ };
180
+ break;
181
+ }
182
+
183
+ // node is exist but node path is changed
184
+ const nodePath = getNodePathById(editor, node_id);
185
+ if (nodePath) {
186
+ isValid = true;
187
+ const node = (0, _core.getNode)(editor, nodePath);
188
+ newOperation.properties = {
189
+ ...properties,
190
+ type: node.type
191
+ };
192
+ newOperation.path = nodePath;
193
+ break;
194
+ }
195
+
196
+ // node is not exist
197
+ isValid = false;
198
+ break;
199
+ }
200
+ case OPERATION.MOVE_NODE:
201
+ {
202
+ const {
203
+ node_id,
204
+ path
205
+ } = newOperation;
206
+ const node = (0, _core.getNode)(editor, path);
207
+ // node is exist and node path is not changed
208
+ if (node && node.id === node_id) {
209
+ isValid = true;
210
+ break;
211
+ }
212
+
213
+ // TODO: newPath can not calculate by nodePath
214
+ // node is exist but node path is changed
215
+ // const nodePath = getNodePathById(editor, node_id);
216
+ // if (nodePath) {}
217
+
218
+ // node is not exist
219
+ isValid = false;
220
+ break;
221
+ }
222
+ default:
223
+ {
224
+ // set_selection
225
+ break;
226
+ }
227
+ }
228
+ if (isValid) return newOperation;
229
+ return isValid;
230
+ };
231
+ exports.validateOperation = validateOperation;
232
+ const getRevertOperationList = operationList => {
233
+ if (operationList.length === 0) return [];
234
+
235
+ // Generate a duplicate operationList, The original value cannot be modified here
236
+ let revertOperationList = (0, _deepCopy.default)(operationList);
237
+ revertOperationList = revertOperationList.reverse();
238
+ return revertOperationList.map(operations => {
239
+ const ops = operations.reverse();
240
+ return ops.map(item => _slate.Operation.inverse(item));
241
+ });
242
+ };
243
+ exports.getRevertOperationList = getRevertOperationList;
244
+ const revertOperationList = (editor, operationList) => {
245
+ if (operationList.length === 0) return [];
246
+ const revertOperationList = getRevertOperationList(operationList);
247
+
248
+ // Cancel locale execute operations
249
+ for (let i = 0; i < revertOperationList.length; i++) {
250
+ const operations = revertOperationList[i];
251
+ _slate.Editor.withoutNormalizing(editor, () => {
252
+ for (let j = 0; j < operations.length; j++) {
253
+ const op = operations[j];
254
+ editor.apply(op);
255
+ }
256
+ });
257
+ }
258
+ };
259
+ exports.revertOperationList = revertOperationList;
260
+ const reExecRevertOperationList = (editor, revertOperationList) => {
261
+ if (revertOperationList.length === 0) return;
262
+
263
+ // Re-execute revert operations
264
+ for (let i = 0; i < revertOperationList.length; i++) {
265
+ const operations = revertOperationList[i];
266
+ _slate.Editor.withoutNormalizing(editor, () => {
267
+ for (let j = 0; j < operations.length; j++) {
268
+ const op = validateOperation(editor, operations[j]);
269
+ if (op) {
270
+ editor.apply(op);
271
+ }
272
+ }
273
+ });
274
+ }
275
+ };
276
+ exports.reExecRevertOperationList = reExecRevertOperationList;
277
+ const syncRemoteOperations = (editor, remoteOperations) => {
278
+ if (remoteOperations.length === 0) return;
279
+ _slate.Editor.withoutNormalizing(editor, () => {
280
+ for (let i = 0; i < remoteOperations.length; i++) {
281
+ const op = remoteOperations[i];
282
+ if (op.type === 'set_selection') {
283
+ continue;
284
+ }
285
+ editor.apply(op);
286
+ }
287
+ });
288
+ };
289
+ exports.syncRemoteOperations = syncRemoteOperations;
290
+ const syncRemoteCursorLocation = (editor, user, location, cursorData) => {
291
+ const currentUser = editor.user;
292
+ if (user && user.username !== currentUser.username) {
293
+ // Get front Point as cursor
294
+ const {
295
+ anchor,
296
+ focus
297
+ } = location;
298
+ let newLocation = location;
299
+ if (!_slate.Point.equals(anchor, focus)) {
300
+ const frontPoint = _slate.Editor.start(editor, location);
301
+ newLocation = {
302
+ anchor: frontPoint,
303
+ focus: frontPoint
304
+ };
305
+ }
306
+ (0, _helper.setCursor)(editor, user, newLocation, cursorData);
307
+
308
+ // sync cursor position
309
+ editor.onCursor && editor.onCursor(editor.cursors);
310
+ }
311
+ };
312
+ exports.syncRemoteCursorLocation = syncRemoteCursorLocation;
@@ -10,10 +10,10 @@ var _reactI18next = require("react-i18next");
10
10
  var _reactstrap = require("reactstrap");
11
11
  var _basicSdk = require("../../basic-sdk");
12
12
  require("./error-page.css");
13
- function ErrorPage(_ref) {
14
- let {
13
+ function ErrorPage() {
14
+ const {
15
15
  t
16
- } = _ref;
16
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
17
17
  const normalizeSdoc = (0, _react.useCallback)(async () => {
18
18
  const res = await _basicSdk.context.normalizeSdocContent();
19
19
  const {
@@ -33,4 +33,4 @@ function ErrorPage(_ref) {
33
33
  onClick: () => normalizeSdoc()
34
34
  }, t('Repair')));
35
35
  }
36
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(ErrorPage);
36
+ var _default = exports.default = ErrorPage;
@@ -6,41 +6,64 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
- var _reactI18next = require("react-i18next");
10
9
  var _basicSdk = require("../basic-sdk");
11
10
  var _errorBoundary = _interopRequireDefault(require("../components/error-boundary"));
11
+ // import { I18nextProvider } from 'react-i18next';
12
+
13
+ // import { getI18n } from '../_i18n';
14
+
12
15
  const SeafileCommentEditor = _ref => {
13
16
  let {
17
+ // Provider
14
18
  type,
15
- userInfo,
16
- pluginName = '',
19
+ // comment or replay
17
20
  className = '',
18
- commentContent,
19
- hiddenUserInfo,
21
+ pluginName = '',
22
+ // sdoc or wiki or txt ...
23
+ pluginEventBus,
24
+ pluginEvent,
25
+ // Comment editor
26
+ content,
20
27
  insertContent,
21
- hiddenComment,
22
28
  onContentChange,
29
+ hiddenUserInfo,
30
+ hiddenComment,
31
+ toolMenus,
32
+ closePanel,
33
+ collaborators,
34
+ participants,
23
35
  addParticipants,
24
- pluginEventBus,
25
- pluginEvent,
36
+ // settings
37
+ settings,
26
38
  api
27
39
  } = _ref;
28
- _basicSdk.context.init();
29
- return /*#__PURE__*/_react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
30
- type: type,
31
- userInfo: userInfo,
32
- pluginName: pluginName,
33
- className: className,
34
- pluginEventBus: pluginEventBus,
35
- pluginEvent: pluginEvent,
36
- api: api
37
- }, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentEditor, {
38
- commentContent: commentContent,
39
- hiddenUserInfo: hiddenUserInfo,
40
- insertContent: insertContent,
41
- hiddenComment: hiddenComment,
42
- onContentChange: onContentChange,
43
- addParticipants: addParticipants
44
- })));
40
+ const {
41
+ lang
42
+ } = settings || {};
43
+ _basicSdk.context.init(settings, api);
44
+ return (
45
+ /*#__PURE__*/
46
+ // <I18nextProvider i18n={ getI18n(lang || 'en') }>
47
+ _react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
48
+ type: type,
49
+ className: className,
50
+ pluginName: pluginName,
51
+ pluginEventBus: pluginEventBus,
52
+ pluginEvent: pluginEvent,
53
+ collaborators: collaborators,
54
+ participants: participants,
55
+ addParticipants: addParticipants
56
+ }, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentEditor, {
57
+ content: content,
58
+ insertContent: insertContent,
59
+ onContentChange: onContentChange,
60
+ hiddenUserInfo: hiddenUserInfo,
61
+ hiddenComment: hiddenComment,
62
+ toolMenus: toolMenus,
63
+ closePanel: closePanel,
64
+ addParticipants: addParticipants
65
+ })))
66
+ // </I18nextProvider>
67
+ );
45
68
  };
46
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(SeafileCommentEditor);
69
+ var _default = exports.default = SeafileCommentEditor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/comment-editor",
3
- "version": "0.0.1-alpha.7",
3
+ "version": "0.0.1-alpha.71",
4
4
  "private": false,
5
5
  "description": "This is a comment editor",
6
6
  "main": "dist/index.js",
@@ -115,10 +115,10 @@
115
115
  "fs-extra": "^10.0.0",
116
116
  "html-webpack-plugin": "^5.5.0",
117
117
  "husky": "8.0.3",
118
- "i18next": "22.4.9",
119
- "i18next-browser-languagedetector": "7.0.1",
120
- "i18next-xhr-backend": "3.2.2",
121
- "identity-obj-proxy": "3.0.0",
118
+ "i18next": "^25.2.1",
119
+ "i18next-browser-languagedetector": "^8.1.0",
120
+ "i18next-http-backend": "^3.0.2",
121
+ "identity-obj-proxy": "^3.0.0",
122
122
  "is-wsl": "^1.1.0",
123
123
  "jest": "29.7.0",
124
124
  "jest-environment-jsdom": "29.7.0",
@@ -141,7 +141,7 @@
141
141
  "react-app-polyfill": "^3.0.0",
142
142
  "react-dev-utils": "^12.0.1",
143
143
  "react-dom": "18.3.1",
144
- "react-i18next": "12.1.4",
144
+ "react-i18next": "15.5.2",
145
145
  "react-refresh": "^0.11.0",
146
146
  "react-router": "7.5.2",
147
147
  "react-router-dom": "7.1.3",
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _utils = require("../comment/utils");
8
- class Notification {
9
- constructor(options) {
10
- var _options$detail, _options$detail2, _options$detail3;
11
- this.id = options.id || '';
12
- this.comment_id = (options === null || options === void 0 ? void 0 : (_options$detail = options.detail) === null || _options$detail === void 0 ? void 0 : _options$detail.comment_id) || '';
13
- this.reply_id = (options === null || options === void 0 ? void 0 : (_options$detail2 = options.detail) === null || _options$detail2 === void 0 ? void 0 : _options$detail2.reply_id) || '';
14
- this.type = (options === null || options === void 0 ? void 0 : (_options$detail3 = options.detail) === null || _options$detail3 === void 0 ? void 0 : _options$detail3.msg_type) || '';
15
- this.key = this.type !== 'reply' ? (0, _utils.generatorNotificationKey)(this.comment_id) : (0, _utils.generatorNotificationKey)(this.comment_id, this.reply_id);
16
- }
17
- }
18
- var _default = exports.default = Notification;
@@ -1,194 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
9
- var _react = _interopRequireDefault(require("react"));
10
- var _reactI18next = require("react-i18next");
11
- var _dayjs = _interopRequireDefault(require("dayjs"));
12
- var _basicSdk = require("../../basic-sdk");
13
- require("./style.css");
14
- class TipMessage extends _react.default.Component {
15
- constructor(props) {
16
- super(props);
17
- (0, _defineProperty2.default)(this, "onOperationExecuteError", () => {
18
- const {
19
- t
20
- } = this.props;
21
- const message = t('Failed_to_execute_operation_on_server');
22
- _basicSdk.toaster.warning(message, {
23
- hasCloseButton: true
24
- });
25
- });
26
- (0, _defineProperty2.default)(this, "onSyncServerOperationError", () => {
27
- const {
28
- t
29
- } = this.props;
30
- const message = t('Failed_to_sync_with_server_operations');
31
- _basicSdk.toaster.danger(message, {
32
- hasCloseButton: false,
33
- duration: null
34
- });
35
- });
36
- (0, _defineProperty2.default)(this, "onInternalServerExecError", () => {
37
- const {
38
- t
39
- } = this.props;
40
- const message = t('Internal_server_exec_operations_error');
41
- _basicSdk.toaster.danger(message, {
42
- hasCloseButton: false,
43
- duration: null
44
- });
45
- });
46
- (0, _defineProperty2.default)(this, "onTokenExpiredError", msg => {
47
- const {
48
- t
49
- } = this.props;
50
- const message = t('Token_expired_Please_refresh_the_page');
51
- _basicSdk.toaster.closeAll();
52
- _basicSdk.toaster.danger(message, {
53
- duration: null
54
- });
55
- });
56
- (0, _defineProperty2.default)(this, "onPendingOpExceedLimit", () => {
57
- const {
58
- t
59
- } = this.props;
60
- _basicSdk.toaster.closeAll();
61
- const message = t('Pending_operations_exceed_limit');
62
- _basicSdk.toaster.warning(message, {
63
- duration: 5
64
- });
65
- });
66
- (0, _defineProperty2.default)(this, "onDisconnect", () => {
67
- const {
68
- t,
69
- isEditMode
70
- } = this.props;
71
- if (!isEditMode) return;
72
- const message = t('Server_is_not_connected_Operation_will_be_sent_to_server_later');
73
- _basicSdk.toaster.warning(message, {
74
- hasCloseButton: true,
75
- duration: null
76
- });
77
- });
78
- (0, _defineProperty2.default)(this, "onReconnectError", () => {
79
- if (!this.isConnectError) {
80
- this.isConnectError = true;
81
- const {
82
- t
83
- } = this.props;
84
- const message = t('Server_is_disconnected_Reconnecting');
85
- _basicSdk.toaster.closeAll();
86
- _basicSdk.toaster.warning(message, {
87
- hasCloseButton: true,
88
- duration: null
89
- });
90
- }
91
- });
92
- (0, _defineProperty2.default)(this, "onReconnect", () => {
93
- this.isConnectError = false;
94
- const {
95
- t
96
- } = this.props;
97
- const message = t('Server_is_reconnected');
98
- _basicSdk.toaster.closeAll();
99
- _basicSdk.toaster.success(message); // close after serval seconds
100
- });
101
- (0, _defineProperty2.default)(this, "onDocumentSaving", () => {
102
- this.setState({
103
- isSaving: true,
104
- isSaved: false
105
- });
106
- });
107
- (0, _defineProperty2.default)(this, "onDocumentSaved", lastSavedAt => {
108
- if (this.saveTimer) clearTimeout(this.saveTimer);
109
- if (this.resetTimer) clearTimeout(this.resetTimer);
110
- this.saveTimer = setTimeout(() => {
111
- this.setState({
112
- lastSavedAt,
113
- isSaving: false,
114
- isSaved: true
115
- });
116
- }, 1000);
117
- this.resetTimer = setTimeout(() => {
118
- this.setState({
119
- isSaving: false,
120
- isSaved: false
121
- });
122
- }, 2000);
123
- });
124
- (0, _defineProperty2.default)(this, "render", () => {
125
- const {
126
- t
127
- } = this.props;
128
- const {
129
- isSaved,
130
- isSaving,
131
- lastSavedAt
132
- } = this.state;
133
- if (isSaving && !isSaved) {
134
- return /*#__PURE__*/_react.default.createElement("span", {
135
- className: "tip-message"
136
- }, t('Saving'));
137
- }
138
- if (!isSaving && isSaved) {
139
- return /*#__PURE__*/_react.default.createElement("span", {
140
- className: "tip-message"
141
- }, t('All_changes_saved'));
142
- }
143
- if (lastSavedAt) {
144
- return /*#__PURE__*/_react.default.createElement("span", {
145
- className: "tip-message"
146
- }, /*#__PURE__*/_react.default.createElement("span", {
147
- className: "sdocfont sdoc-save-tip mr-2"
148
- }), /*#__PURE__*/_react.default.createElement("span", {
149
- className: "save-time"
150
- }, (0, _dayjs.default)(lastSavedAt).format('HH:mm')));
151
- }
152
- return null;
153
- });
154
- this.state = {
155
- isSaved: false,
156
- isSaving: false,
157
- lastSavedAt: ''
158
- };
159
- this.saveTimer = null;
160
- }
161
- componentDidMount() {
162
- const eventBus = _basicSdk.EventBus.getInstance();
163
- this.unsubscribeSavingEvent = eventBus.subscribe('is-saving', this.onDocumentSaving);
164
- this.unsubscribeSavedEvent = eventBus.subscribe('saved', this.onDocumentSaved);
165
- // offline reconnect
166
- this.unsubscribeDisconnectEvent = eventBus.subscribe('disconnect', this.onDisconnect);
167
- this.unsubscribeReconnectErrorEvent = eventBus.subscribe('reconnect_error', this.onReconnectError);
168
- this.unsubscribeReconnectEvent = eventBus.subscribe('reconnect', this.onReconnect);
169
-
170
- // server return error
171
- this.unsubscribeOpExecError = eventBus.subscribe('execute_client_operations_error', this.onOperationExecuteError);
172
- this.unsubscribeSyncServerOpError = eventBus.subscribe('sync_server_operations_error', this.onSyncServerOperationError);
173
- this.unsubscribeDocumentLoadError = eventBus.subscribe('load_document_content_error', this.onInternalServerExecError);
174
- this.unsubscribeOperationsSaveError = eventBus.subscribe('save_operations_to_database_error', this.onInternalServerExecError);
175
- this.unsubscribeOperationsSaveError = eventBus.subscribe('token_expired', this.onTokenExpiredError);
176
-
177
- // local error
178
- this.unsubscribePendingOpExceedLimit = eventBus.subscribe('pending_operations_exceed_limit', this.onPendingOpExceedLimit);
179
- }
180
- componentWillUnmount() {
181
- this.unsubscribeSavingEvent();
182
- this.unsubscribeSavedEvent();
183
- this.unsubscribeDisconnectEvent();
184
- this.unsubscribeReconnectErrorEvent();
185
- this.unsubscribeReconnectEvent();
186
- this.unsubscribeOpExecError();
187
- this.unsubscribeSyncServerOpError();
188
- this.unsubscribePendingOpExceedLimit();
189
- this.unsubscribeDocumentLoadError();
190
- this.unsubscribeOperationsSaveError();
191
- clearTimeout(this.saveTimer);
192
- }
193
- }
194
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(TipMessage);
@@ -1,15 +0,0 @@
1
- .sdoc-editor-page-wrapper .tip-message {
2
- margin-left: 12px;
3
- font-size: 12px;
4
- opacity: 0.75;
5
- color: #999;
6
- width: max-content;
7
- height: 27px;
8
- line-height: 27px;
9
- display: inline-flex;
10
- }
11
-
12
- .sdoc-editor-page-wrapper .tip-message .sdocfont {
13
- padding-top: 1px;
14
- font-size: 14px;
15
- }