@seafile/sdoc-editor 0.1.115 → 0.1.117

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.
@@ -0,0 +1,6 @@
1
+ export var INTERNAL_EVENT = {
2
+ CANCEL_TABLE_SELECT_RANGE: 'cancel_table_select_range',
3
+ SET_TABLE_SELECT_RANGE: 'set_table_select_range',
4
+ HIDDEN_CODE_BLOCK_HOVER_MENU: 'hidden_code_block_hover_menu'
5
+ };
6
+ export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
@@ -8,7 +8,7 @@ import withNodeId from './node-id';
8
8
  import SDocOutline from './outline';
9
9
  import EventProxy from './utils/event-handler';
10
10
  import { useCursors } from './cursor/use-cursors';
11
- import { EXTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../constants';
11
+ import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from './constants';
12
12
  import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
13
13
  import { ScrollContext } from './hooks/use-scroll-context';
14
14
  import CommentContextProvider from './comment/comment-context-provider';
@@ -88,7 +88,7 @@ var SDocEditor = forwardRef(function (_ref, ref) {
88
88
  if (event.button === 0) {
89
89
  editor.reSetTableSelectedRange();
90
90
  var eventBus = EventBus.getInstance();
91
- eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
91
+ eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
92
92
  }
93
93
  // eslint-disable-next-line react-hooks/exhaustive-deps
94
94
  }, []);
@@ -7,7 +7,7 @@ import EventBus from '../../../utils/event-bus';
7
7
  import { useScrollContext } from '../../../hooks/use-scroll-context';
8
8
  import CodeBlockHoverMenu from './hover-menu';
9
9
  import { setClipboardData } from './helpers';
10
- import { EXTERNAL_EVENT } from '../../../../constants';
10
+ import { INTERNAL_EVENT } from '../../../constants';
11
11
  import '../../../assets/css/code-block.css';
12
12
  var CodeBlock = function CodeBlock(_ref) {
13
13
  var codeBlockProps = _ref.codeBlockProps;
@@ -122,7 +122,7 @@ var CodeBlock = function CodeBlock(_ref) {
122
122
  }, []);
123
123
  useEffect(function () {
124
124
  var eventBus = EventBus.getInstance();
125
- eventBus.subscribe(EXTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU, onHiddenHoverMenu);
125
+ eventBus.subscribe(INTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU, onHiddenHoverMenu);
126
126
  // eslint-disable-next-line react-hooks/exhaustive-deps
127
127
  }, []);
128
128
  return /*#__PURE__*/React.createElement("div", {
@@ -9,7 +9,7 @@ import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelec
9
9
  import { ELEMENT_TYPE, KEYBOARD, CLIPBOARD_FORMAT_KEY } from '../../constants';
10
10
  import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
11
11
  import EventBus from '../../../utils/event-bus';
12
- import { EXTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../../constants';
12
+ import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../constants';
13
13
  import ObjectUtils from '../../../utils/object-utils';
14
14
  import { replacePastedDataId } from '../../../node-id/helpers';
15
15
  export var isTableMenuDisabled = function isTableMenuDisabled(editor) {
@@ -226,7 +226,7 @@ export var insertTableElement = function insertTableElement(editor, type) {
226
226
  rowIndex = _getSelectedInfo2.rowIndex,
227
227
  cellIndex = _getSelectedInfo2.cellIndex;
228
228
  var eventBus = EventBus.getInstance();
229
- eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
229
+ eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
230
230
  if (type === TABLE_ELEMENT.ROW) {
231
231
  if (tableSize[0] >= TABLE_MAX_ROWS) return;
232
232
  var targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [].concat(_toConsumableArray(tablePath), [rowIndex + 1]) : [].concat(_toConsumableArray(tablePath), [rowIndex]);
@@ -287,7 +287,7 @@ export var removeTableElement = function removeTableElement(editor, type) {
287
287
  rowIndex = _getSelectedInfo4.rowIndex,
288
288
  cellIndex = _getSelectedInfo4.cellIndex;
289
289
  var eventBus = EventBus.getInstance();
290
- eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
290
+ eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
291
291
  if (type === TABLE_ELEMENT.TABLE) {
292
292
  removeTable(editor, tablePath);
293
293
  return;
@@ -517,7 +517,7 @@ export var insertMultipleRowsAndColumns = function insertMultipleRowsAndColumns(
517
517
  rowIndex = _getSelectedInfo6.rowIndex,
518
518
  cellIndex = _getSelectedInfo6.cellIndex;
519
519
  var eventBus = EventBus.getInstance();
520
- eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
520
+ eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
521
521
  var insertRows = rows.slice(tableSize[0] - rowIndex);
522
522
  var insertColumns = columns.slice(tableSize[1] - cellIndex);
523
523
  var validInsertRows = insertRows.slice(0, Math.min(TABLE_MAX_ROWS - tableSize[0], insertRows.length));
@@ -623,7 +623,7 @@ export var deleteTableRangeData = function deleteTableRangeData(editor) {
623
623
  if (forceCellPath) {
624
624
  editor.tableSelectedRange = EMPTY_SELECTED_RANGE;
625
625
  var eventBus = EventBus.getInstance();
626
- eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
626
+ eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
627
627
  focusEditor(editor, forceCellPath);
628
628
  var newFocus = editor.selection.focus;
629
629
  Transforms.select(editor, {
@@ -9,7 +9,7 @@ import { TABLE_MAX_ROWS, EMPTY_SELECTED_RANGE, TABLE_ELEMENT, TABLE_ELEMENT_POSI
9
9
  import ObjectUtils from '../../../utils/object-utils';
10
10
  import { getSelectedInfo, insertTableElement, removeTable, insertMultipleRowsAndColumns, setTableFragmentData, deleteTableRangeData, focusCell, deleteHandler, isTableLocation, isLastTableCell } from './helpers';
11
11
  import EventBus from '../../../utils/event-bus';
12
- import { EXTERNAL_EVENT } from '../../../../constants';
12
+ import { INTERNAL_EVENT } from '../../../constants';
13
13
  var withTable = function withTable(editor) {
14
14
  var insertBreak = editor.insertBreak,
15
15
  deleteBackward = editor.deleteBackward,
@@ -39,7 +39,7 @@ var withTable = function withTable(editor) {
39
39
  maxColIndex: tableSize[1] - 1
40
40
  };
41
41
  newEditor.tableSelectedRange = allTableRange;
42
- eventBus.dispatch(EXTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, allTableRange);
42
+ eventBus.dispatch(INTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, allTableRange);
43
43
  }
44
44
  if (isHotkey(KEYBOARD.UP, event)) {
45
45
  focusCell(newEditor, event, KEYBOARD.UP);
@@ -227,7 +227,7 @@ var withTable = function withTable(editor) {
227
227
  var _getSelectedInfo4 = getSelectedInfo(newEditor),
228
228
  table = _getSelectedInfo4.table,
229
229
  tableSize = _getSelectedInfo4.tableSize;
230
- eventBus.dispatch(EXTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, {
230
+ eventBus.dispatch(INTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, {
231
231
  minRowIndex: 0,
232
232
  maxRowIndex: tableSize[0] - 1,
233
233
  minColIndex: 0,
@@ -8,7 +8,7 @@ import { Transforms, Editor } from '@seafile/slate';
8
8
  import { EMPTY_SELECTED_RANGE } from '../constants';
9
9
  import { ResizeHandlersContext, TableSelectedRangeContext, SettingSelectRangeContext } from './hooks';
10
10
  import EventBus from '../../../../utils/event-bus';
11
- import { EXTERNAL_EVENT } from '../../../../../constants';
11
+ import { INTERNAL_EVENT } from '../../../../constants';
12
12
  import { getTableColumns, setTableSelectedRange, getFirstTableCell } from '../helpers';
13
13
  import ObjectUtils from '../../../../utils/object-utils';
14
14
  import ResizeHandlers from './resize-handlers';
@@ -68,8 +68,8 @@ var Table = function Table(_ref) {
68
68
  useEffect(function () {
69
69
  if (isSelected) {
70
70
  var eventBus = EventBus.getInstance();
71
- var cancelTableSelectRangeSubscribe = eventBus.subscribe(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE, clearRange);
72
- var setTableSelectRangeSubscribe = eventBus.subscribe(EXTERNAL_EVENT.SET_TABLE_SELECT_RANGE, setRange);
71
+ var cancelTableSelectRangeSubscribe = eventBus.subscribe(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE, clearRange);
72
+ var setTableSelectRangeSubscribe = eventBus.subscribe(INTERNAL_EVENT.SET_TABLE_SELECT_RANGE, setRange);
73
73
  return function () {
74
74
  cancelTableSelectRangeSubscribe();
75
75
  setTableSelectRangeSubscribe();
@@ -29,13 +29,16 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
29
29
  _this.isSending = false;
30
30
  return;
31
31
  }
32
+ if (_this._sendingOperations || _this.disconnect) return;
32
33
  _this.dispatchConnectState('is-saving');
33
34
  var version = _this.document.version;
34
35
  var operations = _this.pendingOperationList.shift();
35
36
  var selection = _this.editor.selection;
37
+ _this._sendingOperations = operations;
36
38
  _this.socketClient.sendOperations(operations, version, selection, _this.sendOperationsCallback);
37
39
  };
38
40
  this.sendOperationsCallback = function (result) {
41
+ _this._sendingOperations = null;
39
42
  if (result && result.success) {
40
43
  var serverVersion = result.version;
41
44
  _this.document['version'] = serverVersion;
@@ -55,6 +58,8 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
55
58
  } else if (error_type === 'document_content_load_failed') {
56
59
  // After a short-term reconnection, the content of the document fails to load
57
60
  _this.dispatchConnectState(error_type);
61
+ } else if (error_type === 'Internal_server_error') {
62
+ _this.dispatchConnectState(error_type);
58
63
  } else if (error_type === 'operation_exec_error') {
59
64
  _this.editor.isRemote = true;
60
65
  revertOperationList(_this.editor, [operations]);
@@ -76,15 +81,11 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
76
81
  });
77
82
  }
78
83
  if (_this.isExecRemoteOperations) return;
84
+
85
+ // update execute remote operations flag
79
86
  _this.isExecRemoteOperations = true;
80
87
  _this.editor.isRemote = true;
81
88
  _this.execRemoteOperations();
82
-
83
- // reset control flag
84
- Promise.resolve().then(function (_) {
85
- _this.isExecRemoteOperations = false;
86
- _this.editor.isRemote = false;
87
- });
88
89
  };
89
90
  this.execRemoteOperations = function () {
90
91
  if (_this.remoteOperationsList.length > 0) {
@@ -123,11 +124,14 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
123
124
  // Re-execute undone operations after isRemote is set to false
124
125
  // Need resend this operations to server
125
126
  Promise.resolve().then(function (_) {
126
- debug('Editor isRemote is false: %s', _this.editor.isRemote);
127
- debug('Re-execute pending operations, %O', _this.revertOperationList);
127
+ // reset execute remote operations flag
128
+ _this.isExecRemoteOperations = false;
129
+ _this.editor.isRemote = false;
128
130
 
129
131
  // 3. Execute pending operations
130
132
  // 3.1 Re-execute operations
133
+ debug('Editor isRemote is false: %s', _this.editor.isRemote);
134
+ debug('Re-execute pending operations, %O', _this.revertOperationList);
131
135
  reExecRevertOperationList(_this.editor, _this.revertOperationList);
132
136
 
133
137
  // 3.2 Clear revert operationList
@@ -168,15 +172,11 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
168
172
  // sync operations
169
173
  // content is [{version, operations}, {version, operations}, ...]
170
174
  _this.remoteOperationsList = content;
175
+
176
+ // update execute remote operations flag
171
177
  _this.isExecRemoteOperations = true;
172
178
  _this.editor.isRemote = true;
173
179
  _this.execRemoteOperations();
174
-
175
- // reset control flag
176
- Promise.resolve().then(function (_) {
177
- _this.isExecRemoteOperations = false;
178
- _this.editor.isRemote = false;
179
- });
180
180
  };
181
181
  this.sendCursorLocation = function (location) {
182
182
  _this.socketClient.sendCursorLocation(location);
@@ -193,6 +193,21 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
193
193
  deleteCursor(_this.editor, message);
194
194
  _this.editor.onCursor && _this.editor.onCursor(_this.editor.cursors);
195
195
  }
196
+ if (type === 'disconnect') {
197
+ if (_this._sendingOperations) {
198
+ _this.pendingOperationList.unshift(_this._sendingOperations.slice());
199
+ _this._sendingOperations = null;
200
+ }
201
+ _this.isSending = false;
202
+ _this.disconnect = true;
203
+
204
+ // Update saved state
205
+ var lastSavedAt = new Date().getTime();
206
+ _this.dispatchConnectState('saved', lastSavedAt);
207
+ }
208
+ if (type === 'reconnect') {
209
+ _this.disconnect = false;
210
+ }
196
211
  _this.eventBus.dispatch(type, message);
197
212
  };
198
213
  this.closeSocketConnect = function () {
@@ -4,7 +4,7 @@ import isHotkey from 'is-hotkey';
4
4
  import EventBus from '../utils/event-bus';
5
5
  import { getSelectedNodeByType } from '../extension/core/queries/';
6
6
  import { ELEMENT_TYPE } from '../extension/constants';
7
- import { EXTERNAL_EVENT } from '../../constants';
7
+ import { INTERNAL_EVENT } from '../constants';
8
8
  var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
9
9
  var _this = this;
10
10
  _classCallCheck(this, EventProxy);
@@ -70,7 +70,7 @@ var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
70
70
  }
71
71
  if (getSelectedNodeByType(editor, ELEMENT_TYPE.CODE_BLOCK)) {
72
72
  var eventBus = EventBus.getInstance();
73
- eventBus.dispatch(EXTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU);
73
+ eventBus.dispatch(INTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU);
74
74
  }
75
75
  };
76
76
  this.onCopy = function (event) {
@@ -39,6 +39,14 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
39
39
  duration: null
40
40
  });
41
41
  };
42
+ _this.onOperationsSaveError = function () {
43
+ var t = _this.props.t;
44
+ var message = t('Operations_save_error_tip');
45
+ toaster.danger(message, {
46
+ hasCloseButton: false,
47
+ duration: null
48
+ });
49
+ };
42
50
  _this.onDisconnect = function () {
43
51
  var _this$props = _this.props,
44
52
  t = _this$props.t,
@@ -138,6 +146,7 @@ var TipMessage = /*#__PURE__*/function (_React$Component) {
138
146
  this.unsubscribeOpExecError = eventBus.subscribe('operation_exec_error', this.onOperationExecuteError);
139
147
  this.unsubscribePendingOpExceedLimit = eventBus.subscribe('pending_operations_exceed_limit', this.onPendingOpExceedLimit);
140
148
  this.unsubscribeDocumentLoadError = eventBus.subscribe('document_content_load_failed', this.onDocumentLoadError);
149
+ this.unsubscribeOperationsSaveError = eventBus.subscribe('Internal_server_error', this.onOperationsSaveError);
141
150
  }
142
151
  }, {
143
152
  key: "componentWillUnmount",
@@ -2,9 +2,5 @@ export var EXTERNAL_EVENT = {
2
2
  INTERNAL_LINK_CLICK: 'internal_link_click',
3
3
  TOGGLE_STAR: 'toggle_star',
4
4
  UNMARK_AS_DRAFT: 'unmark_as_draft',
5
- SHARE_SDOC: 'share_sdoc',
6
- CANCEL_TABLE_SELECT_RANGE: 'cancel_table_select_range',
7
- SET_TABLE_SELECT_RANGE: 'set_table_select_range',
8
- HIDDEN_CODE_BLOCK_HOVER_MENU: 'hidden_code_block_hover_menu'
9
- };
10
- export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
5
+ SHARE_SDOC: 'share_sdoc'
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.115",
3
+ "version": "0.1.117",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -349,5 +349,6 @@
349
349
  "Icon_and_text_Link": "Icon and text Link",
350
350
  "Card": "Card",
351
351
  "Select_sdoc_document": "Select sdoc document",
352
- "Local_file": "Local file"
352
+ "Local_file": "Local file",
353
+ "Operations_save_error_tip": "Operation execution failed, internal server error, please refresh the page"
353
354
  }
@@ -351,5 +351,6 @@
351
351
  "Icon_and_text_Link": "图标+文字链",
352
352
  "Card": "卡片",
353
353
  "Select_sdoc_document": "选择sdoc文档",
354
- "Local_file": "本地文件"
354
+ "Local_file": "本地文件",
355
+ "Operations_save_error_tip": "操作执行失败,服务器内部错误,请刷新页面"
355
356
  }