@seafile/sdoc-editor 0.1.149-beta4 → 0.1.150

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 (41) hide show
  1. package/dist/api/sdoc-server-api.js +0 -10
  2. package/dist/api/seafile-api.js +18 -17
  3. package/dist/basic-sdk/assets/images/image-placeholder.png +0 -0
  4. package/dist/basic-sdk/constants/index.js +3 -21
  5. package/dist/basic-sdk/editor.js +105 -0
  6. package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +3 -8
  7. package/dist/basic-sdk/extension/constants/index.js +1 -4
  8. package/dist/basic-sdk/extension/core/queries/index.js +21 -0
  9. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +0 -26
  10. package/dist/basic-sdk/extension/plugins/image/helpers.js +3 -1
  11. package/dist/basic-sdk/extension/plugins/image/menu/index.js +2 -12
  12. package/dist/basic-sdk/extension/plugins/image/plugin.js +2 -2
  13. package/dist/basic-sdk/extension/plugins/image/render-elem.js +67 -10
  14. package/dist/basic-sdk/extension/render/render-element.js +1 -213
  15. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +2 -2
  16. package/dist/basic-sdk/layout/article-container.js +12 -3
  17. package/dist/basic-sdk/outline/index.js +14 -8
  18. package/dist/basic-sdk/{editor/slate-editor.js → slate-editor.js} +16 -21
  19. package/dist/basic-sdk/socket/helpers.js +0 -2
  20. package/dist/basic-sdk/socket/socket-client.js +0 -45
  21. package/dist/basic-sdk/socket/socket-manager.js +2 -28
  22. package/dist/basic-sdk/socket/with-socket-io.js +12 -35
  23. package/dist/basic-sdk/utils/diff.js +2 -2
  24. package/dist/basic-sdk/views/diff-viewer.js +1 -3
  25. package/dist/basic-sdk/views/viewer.js +12 -9
  26. package/dist/components/doc-operations/index.js +2 -4
  27. package/dist/components/doc-operations/revision-operations/index.js +2 -5
  28. package/dist/components/doc-operations/revision-operations/publish-button.js +13 -6
  29. package/dist/constants/index.js +2 -23
  30. package/dist/context.js +15 -27
  31. package/dist/pages/simple-editor.js +83 -255
  32. package/package.json +1 -1
  33. package/public/locales/en/sdoc-editor.json +1 -11
  34. package/public/locales/zh_CN/sdoc-editor.json +1 -10
  35. package/dist/basic-sdk/editor/common-editor.js +0 -50
  36. package/dist/basic-sdk/editor/index.css +0 -29
  37. package/dist/basic-sdk/editor/index.js +0 -129
  38. package/dist/basic-sdk/extension/plugins/image/dialogs/insert-web-image-dialog.js +0 -58
  39. package/dist/basic-sdk/utils/rebase.js +0 -181
  40. package/dist/components/tip-dialog/index.js +0 -48
  41. package/dist/components/tip-dialog/tip-content.js +0 -50
@@ -1,16 +1,10 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
2
  import React, { useCallback } from 'react';
5
3
  import { useSlateStatic } from '@seafile/slate-react';
6
- import { Transforms } from '@seafile/slate';
7
- import deepCopy from 'deep-copy';
8
- import { useTranslation } from 'react-i18next';
9
4
  import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, CODE_LINE, IMAGE, ELEMENT_TYPE, SDOC_LINK, TITLE, SUBTITLE } from '../constants';
10
5
  import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin } from '../plugins';
11
6
  import EventBus from '../../utils/event-bus';
12
- import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY } from '../../constants';
13
- import { findPath, getNode, replaceNode, generateEmptyElement, deleteNodeMark } from '../../extension/core';
7
+ import { INTERNAL_EVENT } from '../../constants';
14
8
  var CustomElement = function CustomElement(props) {
15
9
  var editor = useSlateStatic();
16
10
  var element = props.element,
@@ -146,212 +140,6 @@ var CustomElement = function CustomElement(props) {
146
140
  }
147
141
  };
148
142
  var RenderElement = function RenderElement(props) {
149
- var editor = useSlateStatic();
150
- var _useTranslation = useTranslation(),
151
- t = _useTranslation.t;
152
- var updateParentNodeByPath = useCallback(function (path) {
153
- var parentPath = path.slice(0, -1);
154
- var parentNode = getNode(editor, parentPath);
155
- if (parentNode.children.filter(function (item) {
156
- return item[REBASE_MARK_KEY.REBASE_TYPE];
157
- }).length === 0) {
158
- var newParentElement = _objectSpread({}, parentNode);
159
- newParentElement[REBASE_MARK_KEY.REBASE_TYPE] && delete newParentElement[REBASE_MARK_KEY.REBASE_TYPE];
160
- newParentElement[REBASE_MARK_KEY.OLD_ELEMENT] && delete newParentElement[REBASE_MARK_KEY.OLD_ELEMENT];
161
- newParentElement[REBASE_MARK_KEY.ORIGIN] && delete newParentElement[REBASE_MARK_KEY.ORIGIN];
162
- newParentElement['children'] = newParentElement['children'].map(function (item) {
163
- item[REBASE_MARK_KEY.REBASE_TYPE] && delete item[REBASE_MARK_KEY.REBASE_TYPE];
164
- item[REBASE_MARK_KEY.OLD_ELEMENT] && delete item[REBASE_MARK_KEY.OLD_ELEMENT];
165
- item[REBASE_MARK_KEY.ORIGIN] && delete item[REBASE_MARK_KEY.ORIGIN];
166
- return item;
167
- });
168
- replaceNode(editor, {
169
- at: parentPath,
170
- nodes: newParentElement
171
- });
172
- }
173
-
174
- // eslint-disable-next-line react-hooks/exhaustive-deps
175
- }, [editor]);
176
- var deleteElement = useCallback(function (element) {
177
- var path = findPath(editor, element);
178
- Transforms.removeNodes(editor, {
179
- at: path
180
- });
181
- if (element.type === ELEMENT_TYPE.LIST_ITEM) {
182
- updateParentNodeByPath(path);
183
- }
184
-
185
- // eslint-disable-next-line react-hooks/exhaustive-deps
186
- }, [editor]);
187
- var deleteMark = useCallback(function (element) {
188
- var path = findPath(editor, element);
189
- deleteNodeMark(editor, path, element, REBASE_MARKS);
190
- if (element.type === ELEMENT_TYPE.LIST_ITEM) {
191
- updateParentNodeByPath(path);
192
- }
193
-
194
- // eslint-disable-next-line react-hooks/exhaustive-deps
195
- }, [editor]);
196
- var addDeletedElement = useCallback(function (element) {
197
- var path = findPath(editor, element);
198
- deleteNodeMark(editor, path, element, REBASE_MARKS);
199
- if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
200
- var emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
201
- Transforms.insertNodes(editor, emptyNode, {
202
- at: [path[0]]
203
- });
204
- } else {
205
- var _emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
206
- _emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
207
- var parentPath = path.slice(0, -1);
208
- var parentNode = getNode(editor, parentPath);
209
- var newChildren = _toConsumableArray(parentNode.children);
210
- var index = path[path.length - 1];
211
- newChildren.splice(index, 0, _emptyNode);
212
- replaceNode(editor, {
213
- at: parentPath,
214
- nodes: _objectSpread(_objectSpread({}, parentNode), {}, {
215
- children: newChildren
216
- })
217
- });
218
- }
219
- if (element.type === ELEMENT_TYPE.LIST_ITEM) {
220
- updateParentNodeByPath(path);
221
- }
222
-
223
- // eslint-disable-next-line react-hooks/exhaustive-deps
224
- }, [editor]);
225
- var useMasterChanges = useCallback(function (element) {
226
- var path = findPath(editor, element);
227
- deleteNodeMark(editor, path, element[REBASE_MARK_KEY.OLD_ELEMENT], REBASE_MARKS);
228
- var nextElementPath = _toConsumableArray(path);
229
- nextElementPath[path.length - 1] = path[path.length - 1] + 1;
230
- Transforms.removeNodes(editor, {
231
- at: nextElementPath
232
- });
233
- if (element.type === ELEMENT_TYPE.LIST_ITEM) {
234
- updateParentNodeByPath(path);
235
- }
236
-
237
- // eslint-disable-next-line react-hooks/exhaustive-deps
238
- }, [editor]);
239
- var useCurrentChanges = useCallback(function (element) {
240
- var path = findPath(editor, element);
241
- var currentElementPath = _toConsumableArray(path);
242
- currentElementPath[path.length - 1] = path[path.length - 1] + 1;
243
- var currentElement = getNode(editor, currentElementPath);
244
- var newCurrentElement = deepCopy(currentElement);
245
- deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
246
- Transforms.removeNodes(editor, {
247
- at: path
248
- });
249
- if (element.type === ELEMENT_TYPE.LIST_ITEM) {
250
- updateParentNodeByPath(path);
251
- }
252
-
253
- // eslint-disable-next-line react-hooks/exhaustive-deps
254
- }, [editor]);
255
- var useBothChanges = useCallback(function (element) {
256
- // delete element marks
257
- var path = findPath(editor, element);
258
- deleteNodeMark(editor, path, element, REBASE_MARKS);
259
-
260
- // delete next element marks
261
- var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
262
- var nextElement = getNode(editor, nextElementPath);
263
- deleteNodeMark(editor, nextElementPath, nextElement, REBASE_MARKS);
264
- if (element.type === ELEMENT_TYPE.LIST_ITEM) {
265
- updateParentNodeByPath(path);
266
- }
267
-
268
- // eslint-disable-next-line react-hooks/exhaustive-deps
269
- }, [editor]);
270
- var element = props.element;
271
- var rebaseType = element[REBASE_MARK_KEY.REBASE_TYPE];
272
- if (!rebaseType) {
273
- return /*#__PURE__*/React.createElement(CustomElement, props);
274
- }
275
- if (rebaseType === REBASE_TYPE.DELETE_MODIFY) {
276
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
277
- className: "w-100 d-flex sdoc-rebase-btn-group",
278
- contentEditable: false
279
- }, /*#__PURE__*/React.createElement("div", {
280
- className: "sdoc-rebase-btn",
281
- onClick: function onClick() {
282
- return deleteElement(element);
283
- }
284
- }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
285
- className: "mr-2 ml-2"
286
- }, '|'), /*#__PURE__*/React.createElement("div", {
287
- className: "sdoc-rebase-btn",
288
- onClick: function onClick() {
289
- return deleteMark(element);
290
- }
291
- }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
292
- className: "mr-2 ml-2"
293
- }, '|'), /*#__PURE__*/React.createElement("div", {
294
- className: "sdoc-rebase-btn",
295
- onClick: function onClick() {
296
- return addDeletedElement(element);
297
- }
298
- }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
299
- className: "w-100 sdoc-rebase-current-changes-start",
300
- contentEditable: false
301
- }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
302
- className: "w-100",
303
- contentEditable: false
304
- }, '======='), /*#__PURE__*/React.createElement("div", {
305
- className: "w-100 sdoc-rebase-incoming-changes",
306
- contentEditable: false
307
- }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
308
- className: "w-100 sdoc-rebase-incoming-changes-end",
309
- contentEditable: false
310
- }, '>>>>>>>'));
311
- }
312
- if (rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
313
- if (element[REBASE_MARK_KEY.ORIGIN] === 'master') {
314
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
315
- className: "w-100 d-flex sdoc-rebase-btn-group",
316
- contentEditable: false
317
- }, /*#__PURE__*/React.createElement("div", {
318
- className: "sdoc-rebase-btn",
319
- onClick: function onClick() {
320
- return useMasterChanges(element);
321
- }
322
- }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
323
- className: "mr-2 ml-2"
324
- }, '|'), /*#__PURE__*/React.createElement("div", {
325
- className: "sdoc-rebase-btn",
326
- onClick: function onClick() {
327
- return useCurrentChanges(element);
328
- }
329
- }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
330
- className: "mr-2 ml-2"
331
- }, '|'), /*#__PURE__*/React.createElement("div", {
332
- className: "sdoc-rebase-btn",
333
- onClick: function onClick() {
334
- return useBothChanges(element);
335
- }
336
- }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
337
- className: "w-100 sdoc-rebase-current-changes-start",
338
- contentEditable: false
339
- }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
340
- className: "w-100 sdoc-rebase-current-changes",
341
- contentEditable: false
342
- }, /*#__PURE__*/React.createElement(CustomElement, props)));
343
- }
344
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
345
- className: "w-100",
346
- contentEditable: false
347
- }, '======='), /*#__PURE__*/React.createElement("div", {
348
- className: "w-100 sdoc-rebase-incoming-changes",
349
- contentEditable: false
350
- }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
351
- className: "w-100 sdoc-rebase-incoming-changes-end",
352
- contentEditable: false
353
- }, '>>>>>>>'));
354
- }
355
143
  return /*#__PURE__*/React.createElement(CustomElement, props);
356
144
 
357
145
  // const { element } = props;
@@ -5,7 +5,7 @@ import { Transforms } from '@seafile/slate';
5
5
  import { insertTable } from '../../plugins/table/helpers';
6
6
  import TableSizePopover from '../../plugins/table/popover/table-size-popover';
7
7
  import { changeToCodeBlock } from '../../plugins/code-block/helpers';
8
- import { ELEMENT_TYPE, INSERT_POSITION, INSERT_IMAGE_TYPE, MENUS_CONFIG_MAP, LIST_ITEM } from '../../constants';
8
+ import { ELEMENT_TYPE, INSERT_POSITION, LOCAL_IMAGE, MENUS_CONFIG_MAP, LIST_ITEM } from '../../constants';
9
9
  import EventBus from '../../../utils/event-bus';
10
10
  import { INTERNAL_EVENT } from '../../../constants';
11
11
  import DropdownMenuItem from '../../commons/dropdown-menu-item';
@@ -19,7 +19,7 @@ var InsertBlockMenu = function InsertBlockMenu(_ref) {
19
19
  Transforms.select(editor, editor.selection.focus);
20
20
  }
21
21
  eventBus.dispatch(INTERNAL_EVENT.INSERT_ELEMENT, {
22
- type: INSERT_IMAGE_TYPE.LOCAL_IMAGE,
22
+ type: LOCAL_IMAGE,
23
23
  insertPosition: insertPosition,
24
24
  slateNode: slateNode
25
25
  });
@@ -1,7 +1,10 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { INTERNAL_EVENT } from '../constants';
4
5
  import { useScrollContext } from '../hooks/use-scroll-context';
6
+ import EventBus from '../utils/event-bus';
7
+ import { getOutlineSetting } from '../outline';
5
8
  export default function ArticleContainer(_ref) {
6
9
  var editor = _ref.editor,
7
10
  children = _ref.children;
@@ -18,15 +21,21 @@ export default function ArticleContainer(_ref) {
18
21
  var handleWindowResize = useCallback(function () {
19
22
  var rect = scrollRef.current.getBoundingClientRect();
20
23
  var articleRect = articleRef.current.getBoundingClientRect();
21
- if ((rect.width - articleRect.width) / 2 < 280) {
24
+ // get state from local storage
25
+ var isShowOutline = getOutlineSetting();
26
+ if (isShowOutline && (rect.width - articleRect.width) / 2 < 280) {
22
27
  setContainerStyle({
23
28
  marginLeft: '280px'
24
29
  });
25
30
  } else {
26
31
  setContainerStyle({});
27
32
  }
28
- // eslint-disable-next-line react-hooks/exhaustive-deps
29
- }, []);
33
+ }, [scrollRef]);
34
+ useEffect(function () {
35
+ var eventBus = EventBus.getInstance();
36
+ var unsubscribeOutline = eventBus.subscribe(INTERNAL_EVENT.OUTLINE_STATE_CHANGED, handleWindowResize);
37
+ return unsubscribeOutline;
38
+ }, [handleWindowResize]);
30
39
  useEffect(function () {
31
40
  handleWindowResize();
32
41
  window.addEventListener('resize', handleWindowResize);
@@ -2,9 +2,11 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
3
3
  import { withTranslation } from 'react-i18next';
4
4
  import { UncontrolledTooltip } from 'reactstrap';
5
+ import { INTERNAL_EVENT } from '../constants';
6
+ import EventBus from '../utils/event-bus';
5
7
  import OutlineItem from './outline-item';
6
8
  import './style.css';
7
- var getOutlineSetting = function getOutlineSetting() {
9
+ export var getOutlineSetting = function getOutlineSetting() {
8
10
  var currentValue = localStorage.getItem('sdoc');
9
11
  var config = currentValue ? JSON.parse(currentValue) : {};
10
12
  var _config$outlineOpen = config.outlineOpen,
@@ -25,15 +27,19 @@ var SDocOutline = function SDocOutline(_ref) {
25
27
  _useState2 = _slicedToArray(_useState, 2),
26
28
  isShown = _useState2[0],
27
29
  setIsShown = _useState2[1];
28
- useEffect(function () {
29
- var outlineOpen = getOutlineSetting();
30
- setIsShown(outlineOpen);
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ var updateOutlineState = useCallback(function (state) {
31
+ setIsShown(state);
32
+ setOutlineSetting(state);
33
+ var eventBus = EventBus.getInstance();
34
+ eventBus.dispatch(INTERNAL_EVENT.OUTLINE_STATE_CHANGED, state);
32
35
  }, []);
36
+ useEffect(function () {
37
+ var outlineState = getOutlineSetting();
38
+ updateOutlineState(outlineState);
39
+ }, [updateOutlineState]);
33
40
  var toggleShow = useCallback(function () {
34
- setIsShown(!isShown);
35
- setOutlineSetting(!isShown);
36
- }, [isShown]);
41
+ updateOutlineState(!isShown);
42
+ }, [isShown, updateOutlineState]);
37
43
  var list = useMemo(function () {
38
44
  return doc.filter(function (item) {
39
45
  return ['header1', 'header2', 'header3'].includes(item.type);
@@ -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,45 +119,6 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
119
119
  this.disconnectWithServer = function () {
120
120
  _this.socket.disconnect();
121
121
  };
122
- this.sendPublishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc, callback) {
123
- _this.socket.emit('publish-document', _this.getParams({
124
- origin_doc_uuid: originDocUuid,
125
- origin_doc_name: originDocName,
126
- update_origin_doc: isNeedUpdateOriginDoc
127
- }), function (success) {
128
- callback && callback(success);
129
- });
130
- };
131
- this.receivePublishDocument = function () {
132
- var socketManager = SocketManager.getInstance();
133
- socketManager.receivePublishDocument();
134
- };
135
- this.receivePublishDocumentError = function () {
136
- var socketManager = SocketManager.getInstance();
137
- socketManager.receivePublishDocumentError();
138
- };
139
- this.sendReplaceDocument = function (document, callback) {
140
- _this.socket.emit('replace-document', _this.getParams({
141
- document: document
142
- }), function (result) {
143
- callback && callback(result);
144
- });
145
- };
146
- this.receiveDocumentReplaced = function () {
147
- var socketManager = SocketManager.getInstance();
148
- socketManager.receiveDocumentReplaced();
149
- };
150
- this.receiveDocumentReplacedError = function () {
151
- var socketManager = SocketManager.getInstance();
152
- socketManager.receiveDocumentReplacedError();
153
- };
154
- this.sendSaveDocument = function (callback) {
155
- _this.socket.emit('save-document', _this.getParams({
156
- document: document
157
- }), function (saveFlag) {
158
- callback && callback(saveFlag);
159
- });
160
- };
161
122
  this.config = config;
162
123
  this.isReconnect = false;
163
124
  this.socket = io(config.sdocServer, {
@@ -172,12 +133,6 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
172
133
  this.socket.on('join-room', this.onJoinRoom);
173
134
  this.socket.on('leave-room', this.onLeaveRoom);
174
135
  this.socket.on('update-document', this.onReceiveRemoteOperations);
175
-
176
- // doc-replaced
177
- this.socket.on('doc-replaced', this.receiveDocumentReplaced);
178
- this.socket.on('doc-replaced-error', this.receiveDocumentReplacedError);
179
- this.socket.on('publish-document', this.receivePublishDocument);
180
- this.socket.on('publish-document-error', this.receivePublishDocumentError);
181
136
  this.socket.on('update-cursor', this.receiveCursorLocation);
182
137
  this.socket.io.on('reconnect', this.onReconnect);
183
138
  this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
@@ -7,7 +7,6 @@ import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, s
7
7
  import SocketClient from './socket-client';
8
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,37 +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 (originDocUuid, originDocName, isNeedUpdateOriginDoc, callback) {
31
- _this.socketClient.sendPublishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc, callback);
32
- };
33
- this.receivePublishDocument = function () {
34
- _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT);
35
- };
36
- this.receivePublishDocumentError = function () {
37
- _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR);
38
- };
39
- this.sendReplaceDocument = function (document) {
40
- _this.socketClient.sendReplaceDocument(document, function (result) {
41
- var serverVersion = result.version;
42
- _this.document['version'] = serverVersion;
43
- });
44
- };
45
- this.receiveDocumentReplaced = function () {
46
- _this.eventBus.dispatch(EXTERNAL_EVENT.DOCUMENT_REPLACED);
47
- };
48
- this.receiveDocumentReplacedError = function () {
49
- _this.eventBus.dispatch(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR);
50
- };
51
- this.sendSaveDocument = function (callback) {
52
- _this.socketClient.sendSaveDocument(callback);
53
- };
54
29
  this.onReceiveLocalOperations = function (operations) {
55
30
  _this.pendingOperationList.push(operations);
56
31
  if (_this.pendingOperationList.length > 5) {
@@ -59,7 +34,6 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
59
34
  _this.sendOperations();
60
35
  };
61
36
  this.sendOperations = function () {
62
- if (_this.editor.mode !== MODE.EDITOR) return;
63
37
  if (_this.state !== STATE.IDLE) return;
64
38
  stateDebug("State changed: ".concat(_this.state, " -> ").concat(STATE.SENDING));
65
39
  _this.state = STATE.SENDING;
@@ -318,7 +292,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _do
318
292
  _this.socketClient.disconnectWithServer();
319
293
  };
320
294
  this.editor = editor;
321
- this.document = _document;
295
+ this.document = document;
322
296
  this.socketClient = new SocketClient(config);
323
297
  this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
324
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 (originDocUuid, originDocName, isNeedUpdateOriginDoc, callback) {
58
- var config = options.config;
59
- var socketManager = SocketManager.getInstance(newEditor, document, config);
60
- socketManager.sendPublishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc, callback);
61
- };
62
- newEditor.replaceDocument = function (document) {
63
- var config = options.config;
64
- var socketManager = SocketManager.getInstance(newEditor, document, config);
65
- socketManager.sendReplaceDocument(document);
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: {