@seafile/sdoc-editor 0.1.146-beta3 → 0.1.147

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 (32) hide show
  1. package/dist/api/sdoc-server-api.js +0 -10
  2. package/dist/api/seafile-api.js +5 -27
  3. package/dist/basic-sdk/constants/index.js +1 -14
  4. package/dist/basic-sdk/editor.js +105 -0
  5. package/dist/basic-sdk/extension/constants/element-type.js +1 -4
  6. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +0 -26
  7. package/dist/basic-sdk/extension/plugins/link/hover/index.js +6 -2
  8. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +4 -2
  9. package/dist/basic-sdk/{editor/slate-editor.js → slate-editor.js} +16 -21
  10. package/dist/basic-sdk/socket/helpers.js +0 -2
  11. package/dist/basic-sdk/socket/socket-client.js +0 -30
  12. package/dist/basic-sdk/socket/socket-manager.js +11 -22
  13. package/dist/basic-sdk/socket/with-socket-io.js +12 -35
  14. package/dist/basic-sdk/utils/diff.js +2 -2
  15. package/dist/basic-sdk/views/diff-viewer.js +1 -3
  16. package/dist/basic-sdk/views/viewer.js +11 -8
  17. package/dist/components/doc-operations/index.js +2 -8
  18. package/dist/components/doc-operations/revision-operations/index.js +3 -11
  19. package/dist/components/doc-operations/revision-operations/publish-button.js +13 -16
  20. package/dist/constants/index.js +2 -23
  21. package/dist/context.js +4 -35
  22. package/dist/pages/simple-editor.js +72 -268
  23. package/package.json +1 -1
  24. package/public/locales/en/sdoc-editor.json +1 -13
  25. package/public/locales/zh_CN/sdoc-editor.json +1 -12
  26. package/dist/basic-sdk/editor/common-editor.js +0 -47
  27. package/dist/basic-sdk/editor/index.css +0 -29
  28. package/dist/basic-sdk/editor/index.js +0 -340
  29. package/dist/basic-sdk/utils/rebase.js +0 -196
  30. package/dist/components/tip-dialog/index.css +0 -0
  31. package/dist/components/tip-dialog/index.js +0 -49
  32. package/dist/components/tip-dialog/tip-content.js +0 -56
@@ -58,16 +58,6 @@ var SDocServerApi = /*#__PURE__*/function () {
58
58
  }
59
59
  });
60
60
  }
61
-
62
- // saveDocContentByRebase(content) {
63
- // const { server, docUuid, accessToken } = this;
64
- // const url = `${server}/api/v1/docs/${docUuid}/rebase/`;
65
-
66
- // const formData = new FormData();
67
- // formData.append('doc_content', JSON.stringify(content));
68
-
69
- // return axios.post(url, formData, {headers: {Authorization: `Token ${accessToken}`}});
70
- // }
71
61
  }, {
72
62
  key: "getCollaborators",
73
63
  value: function getCollaborators() {
@@ -48,11 +48,9 @@ var SeafileAPI = /*#__PURE__*/function () {
48
48
  }
49
49
  }, {
50
50
  key: "sdocPublishRevision",
51
- value: function sdocPublishRevision(docUuid, replace) {
51
+ value: function sdocPublishRevision(docUuid) {
52
52
  var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
53
- var form = new FormData();
54
- form.append('replace', replace);
55
- return this._sendPostRequest(url, form);
53
+ return this.req.post(url);
56
54
  }
57
55
  }, {
58
56
  key: "startRevise",
@@ -65,9 +63,9 @@ var SeafileAPI = /*#__PURE__*/function () {
65
63
  return this._sendPostRequest(url, form);
66
64
  }
67
65
  }, {
68
- key: "getSeadocOriginFileDownloadLink",
69
- value: function getSeadocOriginFileDownloadLink(docUuid) {
70
- var url = '/api/v2.1/seadoc/origin-file-download-link/' + docUuid + '/';
66
+ key: "getSeadocRevisionDownloadLinks",
67
+ value: function getSeadocRevisionDownloadLinks(docUuid) {
68
+ var url = '/api/v2.1/seadoc/revision/download-links/' + docUuid + '/';
71
69
  return this.req.get(url);
72
70
  }
73
71
  }, {
@@ -83,26 +81,6 @@ var SeafileAPI = /*#__PURE__*/function () {
83
81
  var url = 'api/v2.1/seadoc/revisions/' + docUuid + '/?page=' + page + '&per_page=' + perPage;
84
82
  return this.req.get(url);
85
83
  }
86
- }, {
87
- key: "deleteSdocRevision",
88
- value: function deleteSdocRevision(docUuid) {
89
- var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
90
- return this.req.delete(url);
91
- }
92
- }, {
93
- key: "mergeSdocRevision",
94
- value: function mergeSdocRevision(docUuid) {
95
- var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
96
- return this.req.put(url);
97
- }
98
- }, {
99
- key: "getFileHistoryVersion",
100
- value: function getFileHistoryVersion(docUuid, fileVersion, docPath) {
101
- var url = 'api/v2.1/seadoc/history-content/' + docUuid + '/?p=' + encodeURIComponent(docPath) + '&file_version=' + fileVersion;
102
- return this.req.get(url);
103
- }
104
-
105
- // local files
106
84
  }, {
107
85
  key: "getSdocFiles",
108
86
  value: function getSdocFiles(docUuid, p) {
@@ -5,17 +5,4 @@ export var INTERNAL_EVENT = {
5
5
  ON_MOUSE_ENTER_BLOCK: 'on_mouse_enter_block',
6
6
  INSERT_ELEMENT: 'insert_element'
7
7
  };
8
- export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
9
-
10
- export var MODIFY_TYPE = {
11
- ADD: 'add',
12
- DELETE: 'delete',
13
- MODIFY: 'modify',
14
- CHILDREN_MODIFY: 'children-modify'
15
- };
16
- export var REBASE_TYPE = {
17
- MODIFY_MODIFY: 'modify-modify',
18
- DELETE_MODIFY: 'delete-modify',
19
- CHILDREN_MODIFY: 'children-modify'
20
- };
21
- export var REBASE_MARKS = ['origin', 'rebaseType', 'oldElement'];
8
+ export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
@@ -0,0 +1,105 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
3
+ import { Editor } from '@seafile/slate';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { createDefaultEditor } from './extension';
6
+ import { focusEditor } from './extension/core';
7
+ import { withSocketIO } from './socket';
8
+ import withNodeId from './node-id';
9
+ import { PAGE_EDIT_AREA_WIDTH } from './constants';
10
+ import context from '../context';
11
+ import { EditorContainer, EditorContent } from './layout';
12
+ import SlateEditor from './slate-editor';
13
+ import InsertElementDialog from './extension/commons/insert-element-dialog';
14
+ var SDocEditor = forwardRef(function (_ref, ref) {
15
+ var document = _ref.document,
16
+ config = _ref.config;
17
+ var _useTranslation = useTranslation(),
18
+ t = _useTranslation.t;
19
+
20
+ // init editor
21
+ var editor = useMemo(function () {
22
+ var defaultEditor = createDefaultEditor();
23
+ var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
+ document: document,
25
+ config: config
26
+ }));
27
+ var cursors = document.cursors;
28
+ newEditor.cursors = cursors || {};
29
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
30
+ newEditor.readonly = false;
31
+ return newEditor;
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
34
+ var _useState = useState(document.children),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ slateValue = _useState2[0],
37
+ setSlateValue = _useState2[1];
38
+
39
+ // The parent component can call the method of this component through ref
40
+ useImperativeHandle(ref, function () {
41
+ return {
42
+ // get latest value
43
+ getValue: function getValue() {
44
+ return slateValue;
45
+ }
46
+ };
47
+ }, [slateValue]);
48
+
49
+ // useMount: init socket connection
50
+ useEffect(function () {
51
+ editor.openConnection();
52
+ return function () {
53
+ editor.closeConnection();
54
+ };
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, []);
57
+
58
+ // useMount: focus editor
59
+ useEffect(function () {
60
+ var timer = setTimeout(function () {
61
+ var _editor$children = _slicedToArray(editor.children, 1),
62
+ firstNode = _editor$children[0];
63
+ if (firstNode) {
64
+ var _firstNode$children = _slicedToArray(firstNode.children, 1),
65
+ firstNodeFirstChild = _firstNode$children[0];
66
+ if (firstNodeFirstChild) {
67
+ var endOfFirstNode = Editor.end(editor, [0, 0]);
68
+ var range = {
69
+ anchor: endOfFirstNode,
70
+ focus: endOfFirstNode
71
+ };
72
+ focusEditor(editor, range);
73
+ }
74
+ }
75
+ }, 300);
76
+ return function () {
77
+ clearTimeout(timer);
78
+ };
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, []);
81
+
82
+ // useMount: reset title
83
+ useEffect(function () {
84
+ var isSdocRevision = context.getSetting('isSdocRevision');
85
+ var originFilename = context.getSetting('originFilename');
86
+ if (isSdocRevision) {
87
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
88
+ }
89
+
90
+ // eslint-disable-next-line react-hooks/exhaustive-deps
91
+ }, []);
92
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
93
+ editor: editor
94
+ }, /*#__PURE__*/React.createElement(EditorContent, {
95
+ docValue: slateValue,
96
+ showOutline: true
97
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
98
+ editor: editor,
99
+ slateValue: slateValue,
100
+ setSlateValue: setSlateValue
101
+ }))), /*#__PURE__*/React.createElement(InsertElementDialog, {
102
+ editor: editor
103
+ }));
104
+ });
105
+ export default SDocEditor;
@@ -46,7 +46,4 @@ export var SDOC_LINK = 'sdoc-link';
46
46
  // font
47
47
  export var FONT_SIZE = 'font-size';
48
48
  export var FONT_SIZE_INCREASE = 'font-size-increase';
49
- export var FONT_SIZE_REDUCE = 'font-size-reduce';
50
-
51
- // rebase
52
- export var REBASE_ELEMENT = 'rebase-element';
49
+ export var FONT_SIZE_REDUCE = 'font-size-reduce';
@@ -12,30 +12,4 @@ export var replaceNodeChildren = function replaceNodeChildren(editor, _ref) {
12
12
  at: at.concat([0])
13
13
  }));
14
14
  });
15
- };
16
- export var replaceNode = function replaceNode(editor) {
17
- var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
18
- at = _ref2.at,
19
- nodes = _ref2.nodes,
20
- insertOptions = _ref2.insertOptions,
21
- removeOptions = _ref2.removeOptions;
22
- Editor.withoutNormalizing(editor, function () {
23
- Transforms.removeNodes(editor, _objectSpread({
24
- at: at
25
- }, removeOptions));
26
- Transforms.insertNodes(editor, nodes, _objectSpread(_objectSpread({}, insertOptions), {}, {
27
- at: at
28
- }));
29
- });
30
- };
31
- export var deleteNodeMark = function deleteNodeMark(editor, path, element) {
32
- var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
33
- var newElement = _objectSpread({}, element);
34
- marks.forEach(function (markItem) {
35
- newElement[markItem] && delete newElement[markItem];
36
- });
37
- replaceNode(editor, {
38
- at: path,
39
- nodes: newElement
40
- });
41
15
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import '../../../../assets/css/textlink-hovermenu.css';
@@ -10,10 +10,14 @@ var LinkHover = function LinkHover(_ref) {
10
10
  onEditLink = _ref.onEditLink;
11
11
  var _useTranslation = useTranslation(),
12
12
  t = _useTranslation.t;
13
+ var onMouseDown = useCallback(function (event) {
14
+ event.stopPropagation();
15
+ }, []);
13
16
  return /*#__PURE__*/React.createElement(React.Fragment, null, createPortal( /*#__PURE__*/React.createElement("div", {
14
17
  id: "link-op-menu",
15
18
  className: "link-op-menu",
16
- style: menuPosition
19
+ style: menuPosition,
20
+ onMouseDown: onMouseDown
17
21
  }, /*#__PURE__*/React.createElement("a", {
18
22
  href: element.href,
19
23
  target: "_blank",
@@ -55,7 +55,8 @@ var TableCell = function TableCell(_ref) {
55
55
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
56
56
  style: _objectSpread(_objectSpread(_objectSpread({}, element.style), style), {}, {
57
57
  minWidth: columnWidth,
58
- width: columnWidth
58
+ width: columnWidth,
59
+ maxWidth: columnWidth
59
60
  }),
60
61
  className: classnames('table-cell', attributes.className, {
61
62
  'cell-selected': isSelected,
@@ -96,7 +97,8 @@ function renderTableCell(props) {
96
97
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
97
98
  style: _objectSpread(_objectSpread(_objectSpread({}, element.style), style), {}, {
98
99
  minWidth: width,
99
- width: width
100
+ width: width,
101
+ maxWidth: width
100
102
  }),
101
103
  className: classnames('table-cell', attributes.className),
102
104
  "data-id": element.id
@@ -1,24 +1,22 @@
1
1
  import React, { useCallback, useMemo, Fragment } from 'react';
2
2
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
3
- import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '../extension';
4
- import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
5
- import EventProxy from '../utils/event-handler';
6
- import { useCursors } from '../cursor/use-cursors';
7
- import { INTERNAL_EVENT } from '../constants';
8
- import { SetNodeToDecorations } from '../highlight-decorate/setNodeToDecorations';
9
- import CommentContextProvider from '../comment/comment-context-provider';
10
- import CommentWrapper from '../comment';
11
- import { usePipDecorate } from '../decorates';
12
- import { getCursorPosition, getDomHeight, getDomMarginTop } from '../utils/dom-utils';
13
- import EventBus from '../utils/event-bus';
14
- import { ArticleContainer } from '../layout';
15
- import { useScrollContext } from '../hooks/use-scroll-context';
3
+ import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from './extension';
4
+ import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
5
+ import EventProxy from './utils/event-handler';
6
+ import { useCursors } from './cursor/use-cursors';
7
+ import { INTERNAL_EVENT } from './constants';
8
+ import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
9
+ import CommentContextProvider from './comment/comment-context-provider';
10
+ import CommentWrapper from './comment';
11
+ import { usePipDecorate } from './decorates';
12
+ import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
13
+ import EventBus from './utils/event-bus';
14
+ import { ArticleContainer } from './layout';
15
+ import { useScrollContext } from './hooks/use-scroll-context';
16
16
  var SlateEditor = function SlateEditor(_ref) {
17
17
  var editor = _ref.editor,
18
18
  setSlateValue = _ref.setSlateValue,
19
- slateValue = _ref.slateValue,
20
- customRenderElement = _ref.renderElement,
21
- isShowComment = _ref.isShowComment;
19
+ slateValue = _ref.slateValue;
22
20
  var _useCursors = useCursors(editor),
23
21
  cursors = _useCursors.cursors;
24
22
  var decorate = usePipDecorate(editor);
@@ -140,15 +138,12 @@ var SlateEditor = function SlateEditor(_ref) {
140
138
  editor: editor
141
139
  }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
142
140
  cursors: cursors,
143
- renderElement: customRenderElement || renderElement,
141
+ renderElement: renderElement,
144
142
  renderLeaf: renderLeaf,
145
143
  onKeyDown: onKeyDown,
146
144
  onMouseDown: onMouseDown,
147
145
  decorate: decorate,
148
146
  onCut: eventProxy.onCut
149
- })), /*#__PURE__*/React.createElement(SideToolbar, null), isShowComment && /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
150
- };
151
- SlateEditor.defaultProps = {
152
- isShowComment: true
147
+ })), /*#__PURE__*/React.createElement(SideToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
153
148
  };
154
149
  export default SlateEditor;
@@ -4,7 +4,6 @@ import { Editor, Operation } from '@seafile/slate';
4
4
  import { getNode } from '../extension/core';
5
5
  import * as OPERATION from '../node-id/constants';
6
6
  import { setCursor } from '../cursor/helper';
7
- import { MODE } from '../../constants';
8
7
  export var getNodePathById = function getNodePathById(rootNode, nodeId) {
9
8
  var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
10
9
  if (rootNode.id === nodeId) return path;
@@ -253,7 +252,6 @@ export var reExecRevertOperationList = function reExecRevertOperationList(editor
253
252
  }
254
253
  };
255
254
  export var syncRemoteOperations = function syncRemoteOperations(editor, remoteOperations) {
256
- if (editor.mode !== MODE.EDITOR) return;
257
255
  if (remoteOperations.length === 0) return;
258
256
  Editor.withoutNormalizing(editor, function () {
259
257
  for (var i = 0; i < remoteOperations.length; i++) {
@@ -119,33 +119,6 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
119
119
  this.disconnectWithServer = function () {
120
120
  _this.socket.disconnect();
121
121
  };
122
- this.receiveRebaseDocument = function (document, originFileVersion) {
123
- var socketManager = SocketManager.getInstance();
124
- socketManager.receiveRebaseContent(document, originFileVersion);
125
- };
126
- this.sendPublishDocument = function (originFileURL, callback) {
127
- _this.socket.emit('publish-document', _this.getParams({
128
- originFileURL: originFileURL
129
- }), function (result) {
130
- callback && callback(result);
131
- });
132
- };
133
- this.receivePublishDocument = function (originFileURL) {
134
- var socketManager = SocketManager.getInstance();
135
- socketManager.receivePublishDocument(originFileURL);
136
- };
137
- this.sendMergeDocument = function (document, originFileVersion, callback) {
138
- _this.socket.emit('merge-document', _this.getParams({
139
- document: document,
140
- originFileVersion: originFileVersion
141
- }), function (result) {
142
- callback && callback(result);
143
- });
144
- };
145
- this.receiveMergeDocument = function (document, originFileVersion) {
146
- var socketManager = SocketManager.getInstance();
147
- socketManager.receiveMergeDocument(document, originFileVersion);
148
- };
149
122
  this.config = config;
150
123
  this.isReconnect = false;
151
124
  this.socket = io(config.sdocServer, {
@@ -160,9 +133,6 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
160
133
  this.socket.on('join-room', this.onJoinRoom);
161
134
  this.socket.on('leave-room', this.onLeaveRoom);
162
135
  this.socket.on('update-document', this.onReceiveRemoteOperations);
163
- this.socket.on('rebase-document', this.receiveRebaseDocument);
164
- this.socket.on('merge-document', this.receiveMergeDocument);
165
- this.socket.on('publish-document', this.receivePublishDocument);
166
136
  this.socket.on('update-cursor', this.receiveCursorLocation);
167
137
  this.socket.io.on('reconnect', this.onReconnect);
168
138
  this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
@@ -5,9 +5,8 @@ var _class;
5
5
  import EventBus from '../utils/event-bus';
6
6
  import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, syncRemoteCursorLocation } from './helpers';
7
7
  import SocketClient from './socket-client';
8
- import { conflictDebug, serverDebug, stateDebug } from '../utils/debug';
8
+ import { clientDebug, conflictDebug, serverDebug, stateDebug } from '../utils/debug';
9
9
  import { deleteCursor } from '../cursor/helper';
10
- import { EXTERNAL_EVENT, MODE } from '../../constants';
11
10
 
12
11
  // idle --> sending --> conflict --> idle
13
12
  // --> conflict --> idle
@@ -20,29 +19,13 @@ var STATE = {
20
19
  DISCONNECT: 'disconnect',
21
20
  NEED_RELOAD: 'need_reload'
22
21
  };
23
- var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _document, config) {
22
+ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, document, config) {
24
23
  var _this = this;
25
24
  _classCallCheck(this, SocketManager);
26
25
  this.getDocumentVersion = function () {
27
26
  var version = _this.document.version;
28
27
  return version;
29
28
  };
30
- this.sendPublishDocument = function (originFileURL) {
31
- _this.socketClient.sendPublishDocument(originFileURL);
32
- };
33
- this.receivePublishDocument = function (originFileURL) {
34
- _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT, originFileURL);
35
- };
36
- this.sendMergeDocument = function (document, originFileVersion) {
37
- _this.socketClient.sendMergeDocument(document, originFileVersion, function (result) {
38
- var serverVersion = result.version;
39
- _this.document['version'] = serverVersion;
40
- });
41
- };
42
- this.receiveMergeDocument = function (document, originFileVersion) {
43
- _this.document = document;
44
- _this.eventBus.dispatch(EXTERNAL_EVENT.MERGE_DOCUMENT, document, originFileVersion);
45
- };
46
29
  this.onReceiveLocalOperations = function (operations) {
47
30
  _this.pendingOperationList.push(operations);
48
31
  if (_this.pendingOperationList.length > 5) {
@@ -51,7 +34,6 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
51
34
  _this.sendOperations();
52
35
  };
53
36
  this.sendOperations = function () {
54
- if (_this.editor.mode !== MODE.EDITOR) return;
55
37
  if (_this.state !== STATE.IDLE) return;
56
38
  stateDebug("State changed: ".concat(_this.state, " -> ").concat(STATE.SENDING));
57
39
  _this.state = STATE.SENDING;
@@ -166,6 +148,12 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
166
148
  // The version consistency indicates that there is no conflict and no processing is required
167
149
  stateDebug("State Changed: ".concat(_this.state, " -> ").concat(STATE.IDLE));
168
150
  _this.state = STATE.IDLE;
151
+ if (_this.pendingOperationList.length > 0) {
152
+ clientDebug('After reconnection, manually trigger the execution of ops.');
153
+ stateDebug("State Changed: ".concat(_this.state, " -> ").concat(STATE.SENDING));
154
+ _this.state = STATE.SENDING;
155
+ _this.sendNextOperations();
156
+ }
169
157
  };
170
158
  this.onConflictHappen = function () {
171
159
  stateDebug("State Changed: ".concat(_this.state, " -> ").concat(STATE.CONFLICT));
@@ -290,11 +278,12 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
290
278
  _this.editor.onCursor && _this.editor.onCursor(_this.editor.cursors);
291
279
  }
292
280
  if (type === 'disconnect') {
281
+ // current state is sending
293
282
  if (_this._sendingOperations) {
294
283
  _this.pendingOperationList.unshift(_this._sendingOperations.slice());
295
284
  _this._sendingOperations = null;
296
285
  }
297
- stateDebug("State Changed: ".concat(_this.state, " -> ").concat(STATE.IDLE));
286
+ stateDebug("State Changed: ".concat(_this.state, " -> ").concat(STATE.DISCONNECT));
298
287
  _this.state = STATE.DISCONNECT;
299
288
  }
300
289
  _this.eventBus.dispatch(type, message);
@@ -303,7 +292,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
303
292
  _this.socketClient.disconnectWithServer();
304
293
  };
305
294
  this.editor = editor;
306
- this.document = _document;
295
+ this.document = document;
307
296
  this.socketClient = new SocketClient(config);
308
297
  this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
309
298
  this.remoteOperationsList = []; // Same with pending operations
@@ -1,4 +1,3 @@
1
- import { MODE } from '../../constants';
2
1
  import { generateCursorData } from '../cursor/helper';
3
2
  import EventBus from '../utils/event-bus';
4
3
  import SocketManager from './socket-manager';
@@ -20,50 +19,28 @@ var withSocketIO = function withSocketIO(editor, options) {
20
19
  SocketManager.destroy();
21
20
  };
22
21
  newEditor.onChange = function () {
23
- var document = options.document,
24
- config = options.config;
25
- if (newEditor.mode === MODE.DIFF_VIEWER) return;
22
+ if (newEditor.readonly) return;
26
23
  var operations = newEditor.operations;
27
24
  if (!newEditor.isRemote && operations.length > 0) {
28
25
  var isAllSetSelection = operations.every(function (operation) {
29
26
  return operation.type === 'set_selection';
30
27
  });
31
- var _socketManager = SocketManager.getInstance(newEditor, document, config);
28
+ var _socketManager = SocketManager.getInstance();
32
29
  if (!isAllSetSelection) {
33
- if (newEditor.mode === MODE.EDITOR) {
34
- // get update content value operations
35
- var updateOperations = operations.filter(function (operation) {
36
- return operation.type !== 'set_selection';
37
- });
38
- _socketManager.onReceiveLocalOperations(updateOperations);
39
- }
30
+ // get update content value operations
31
+ var updateOperations = operations.filter(function (operation) {
32
+ return operation.type !== 'set_selection';
33
+ });
34
+ _socketManager.onReceiveLocalOperations(updateOperations);
40
35
  }
41
- if (newEditor.mode === MODE.EDITOR) {
42
- _socketManager.sendCursorLocation(editor.selection);
43
- }
44
- }
45
- if (newEditor.mode === MODE.EDITOR) {
46
- // dispatch editor change event
47
- var eventBus = EventBus.getInstance(newEditor, document, config);
48
- eventBus.dispatch('change');
36
+ _socketManager.sendCursorLocation(editor.selection);
49
37
  }
38
+
39
+ // dispatch editor change event
40
+ var eventBus = EventBus.getInstance();
41
+ eventBus.dispatch('change');
50
42
  onChange();
51
43
  };
52
- newEditor.rebaseContent = function (document, originFileVersion) {
53
- var config = options.config;
54
- var socketManager = SocketManager.getInstance(newEditor, document, config);
55
- socketManager.sendRebaseContent(document, originFileVersion);
56
- };
57
- newEditor.publishDocument = function (originFileURL) {
58
- var config = options.config;
59
- var socketManager = SocketManager.getInstance(newEditor, document, config);
60
- socketManager.sendPublishDocument(document, originFileURL);
61
- };
62
- newEditor.mergeDocument = function (document, originFileVersion) {
63
- var config = options.config;
64
- var socketManager = SocketManager.getInstance(newEditor, document, config);
65
- socketManager.sendMergeDocument(document, originFileVersion);
66
- };
67
44
  return newEditor;
68
45
  };
69
46
  export default withSocketIO;
@@ -31,7 +31,7 @@ var generatorDiffElement = function generatorDiffElement(element, diffType) {
31
31
  return generatorDiffElement(item, diffType, style);
32
32
  })), _objectSpread3));
33
33
  };
34
- export var generateIdMapAndIds = function generateIdMapAndIds(elements) {
34
+ var generateIdMapAndIds = function generateIdMapAndIds(elements) {
35
35
  var map = {};
36
36
  var ids = [];
37
37
  if (!Array.isArray(elements) || elements.length === 0) return {
@@ -54,7 +54,7 @@ var hasChildren = function hasChildren(element) {
54
54
  };
55
55
 
56
56
  // id diffs
57
- export var getIdDiffs = function getIdDiffs(oldIds, newIds) {
57
+ var getIdDiffs = function getIdDiffs(oldIds, newIds) {
58
58
  var diff = new DiffText(oldIds, newIds);
59
59
  return diff.getDiffs();
60
60
  };
@@ -6,8 +6,7 @@ import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../extension/constants
6
6
  import SDocViewer from './viewer';
7
7
  import '../../assets/css/diff-viewer.css';
8
8
  var DiffViewer = function DiffViewer(_ref) {
9
- var editor = _ref.editor,
10
- currentContent = _ref.currentContent,
9
+ var currentContent = _ref.currentContent,
11
10
  lastContent = _ref.lastContent,
12
11
  didMountCallback = _ref.didMountCallback,
13
12
  showToolbar = _ref.showToolbar,
@@ -39,7 +38,6 @@ var DiffViewer = function DiffViewer(_ref) {
39
38
  return renderElement(props, editor);
40
39
  }, []);
41
40
  return /*#__PURE__*/React.createElement(SDocViewer, {
42
- editor: editor,
43
41
  showToolbar: showToolbar,
44
42
  showOutline: showOutline,
45
43
  document: {
@@ -1,4 +1,4 @@
1
- import React, { Fragment } from 'react';
1
+ import React, { Fragment, useMemo } from 'react';
2
2
  import { Editable, Slate } from '@seafile/slate-react';
3
3
  import { renderLeaf as _renderLeaf, renderElement as _renderElement, createDefaultEditor } from '../extension';
4
4
  import withNodeId from '../node-id';
@@ -8,13 +8,16 @@ import { usePipDecorate } from '../decorates';
8
8
  import { ArticleContainer, EditorContainer, EditorContent } from '../layout';
9
9
  import '../assets/css/simple-viewer.css';
10
10
  var SDocViewer = function SDocViewer(_ref) {
11
- var editor = _ref.editor,
12
- document = _ref.document,
11
+ var document = _ref.document,
13
12
  customRenderLeaf = _ref.renderLeaf,
14
13
  customRenderElement = _ref.renderElement,
15
14
  showToolbar = _ref.showToolbar,
16
15
  showOutline = _ref.showOutline;
17
- var validEditor = editor || withNodeId(createDefaultEditor());
16
+ var editor = useMemo(function () {
17
+ var defaultEditor = createDefaultEditor();
18
+ return withNodeId(defaultEditor);
19
+ }, []);
20
+ editor.readonly = true;
18
21
  var slateValue = (document || generateDefaultDocContent()).children;
19
22
  var decorate = usePipDecorate(editor);
20
23
  return /*#__PURE__*/React.createElement(EditorContainer, {
@@ -26,19 +29,19 @@ var SDocViewer = function SDocViewer(_ref) {
26
29
  readonly: true,
27
30
  showOutline: showOutline
28
31
  }, /*#__PURE__*/React.createElement(Slate, {
29
- editor: validEditor,
32
+ editor: editor,
30
33
  value: slateValue
31
34
  }, /*#__PURE__*/React.createElement(ArticleContainer, {
32
- editor: validEditor,
35
+ editor: editor,
33
36
  readOnly: true
34
37
  }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
35
38
  readOnly: true,
36
39
  placeholder: "",
37
40
  renderElement: function renderElement(props) {
38
- return (customRenderElement || _renderElement)(props, validEditor);
41
+ return (customRenderElement || _renderElement)(props, editor);
39
42
  },
40
43
  renderLeaf: function renderLeaf(props) {
41
- return (customRenderLeaf || _renderLeaf)(props, validEditor);
44
+ return (customRenderLeaf || _renderLeaf)(props, editor);
42
45
  },
43
46
  onDOMBeforeInput: function onDOMBeforeInput(event) {},
44
47
  decorate: decorate