@seafile/sdoc-editor 0.1.157 → 0.1.159-beta10

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 (47) hide show
  1. package/dist/api/seafile-api.js +28 -9
  2. package/dist/basic-sdk/constants/index.js +25 -1
  3. package/dist/basic-sdk/editor/common-editor.js +50 -0
  4. package/dist/basic-sdk/editor/index.css +29 -0
  5. package/dist/basic-sdk/editor/index.js +132 -0
  6. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  7. package/dist/basic-sdk/extension/constants/element-type.js +14 -9
  8. package/dist/basic-sdk/extension/constants/menus-config.js +27 -16
  9. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  10. package/dist/basic-sdk/extension/plugins/file-link/render-elem.css +4 -0
  11. package/dist/basic-sdk/extension/plugins/file-link/render-elem.js +1 -4
  12. package/dist/basic-sdk/extension/plugins/font/helpers.js +16 -12
  13. package/dist/basic-sdk/extension/plugins/html/rules/text.js +5 -5
  14. package/dist/basic-sdk/extension/plugins/markdown/plugin.js +4 -4
  15. package/dist/basic-sdk/extension/plugins/table/constants/index.js +5 -2
  16. package/dist/basic-sdk/extension/plugins/table/helpers.js +13 -8
  17. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-bg-color-menu.js +1 -1
  18. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-text-align-menu.js +3 -3
  19. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -2
  20. package/dist/basic-sdk/extension/plugins/table/render/render-row.js +7 -9
  21. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +3 -3
  22. package/dist/basic-sdk/extension/plugins/text-style/plugin.js +3 -2
  23. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +20 -19
  24. package/dist/basic-sdk/extension/render/render-element.js +221 -1
  25. package/dist/basic-sdk/socket/helpers.js +2 -0
  26. package/dist/basic-sdk/socket/socket-client.js +58 -0
  27. package/dist/basic-sdk/socket/socket-manager.js +34 -2
  28. package/dist/basic-sdk/socket/with-socket-io.js +40 -12
  29. package/dist/basic-sdk/utils/diff.js +20 -19
  30. package/dist/basic-sdk/utils/rebase.js +193 -0
  31. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  32. package/dist/basic-sdk/views/viewer.js +9 -12
  33. package/dist/components/doc-operations/index.js +4 -2
  34. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  35. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  36. package/dist/components/tip-dialog/index.js +48 -0
  37. package/dist/components/tip-dialog/tip-content.js +47 -0
  38. package/dist/constants/index.js +26 -2
  39. package/dist/context.js +43 -9
  40. package/dist/pages/simple-editor.js +245 -88
  41. package/package.json +1 -1
  42. package/public/locales/en/sdoc-editor.json +12 -1
  43. package/public/locales/fr/sdoc-editor.json +154 -152
  44. package/public/locales/ru/sdoc-editor.json +50 -48
  45. package/public/locales/zh_CN/sdoc-editor.json +11 -1
  46. package/dist/basic-sdk/editor.js +0 -105
  47. package/dist/basic-sdk/extension/plugins/text-style/model.js +0 -11
@@ -13,7 +13,7 @@ var textRule = function textRule(element, parseChild) {
13
13
  return {
14
14
  level: 'level3',
15
15
  id: slugid.nice(),
16
- BOLD: true,
16
+ bold: true,
17
17
  text: element.textContent
18
18
  };
19
19
  }
@@ -21,7 +21,7 @@ var textRule = function textRule(element, parseChild) {
21
21
  return {
22
22
  level: 'level3',
23
23
  id: slugid.nice(),
24
- CODE: true,
24
+ code: true,
25
25
  text: element.textContent
26
26
  };
27
27
  }
@@ -29,7 +29,7 @@ var textRule = function textRule(element, parseChild) {
29
29
  return {
30
30
  level: 'level3',
31
31
  id: slugid.nice(),
32
- DELETE: true,
32
+ delete: true,
33
33
  text: element.textContent
34
34
  };
35
35
  }
@@ -37,7 +37,7 @@ var textRule = function textRule(element, parseChild) {
37
37
  return {
38
38
  level: 'level3',
39
39
  id: slugid.nice(),
40
- ITALIC: true,
40
+ italic: true,
41
41
  text: element.textContent
42
42
  };
43
43
  }
@@ -45,7 +45,7 @@ var textRule = function textRule(element, parseChild) {
45
45
  return {
46
46
  level: 'level3',
47
47
  id: slugid.nice(),
48
- ADD: true,
48
+ add: true,
49
49
  text: element.textContent
50
50
  };
51
51
  }
@@ -92,8 +92,8 @@ var withMarkDown = function withMarkDown(editor) {
92
92
  voids: true
93
93
  });
94
94
  var newText = beforeText.slice(startOffset + 3, endOffset - 3);
95
- Editor.addMark(editor, 'BOLD', true);
96
- Editor.addMark(editor, 'ITALIC', true);
95
+ Editor.addMark(editor, TEXT_STYLE_MAP.BOLD, true);
96
+ Editor.addMark(editor, TEXT_STYLE_MAP.ITALIC, true);
97
97
  return insertText(newText);
98
98
  }
99
99
  }
@@ -114,7 +114,7 @@ var withMarkDown = function withMarkDown(editor) {
114
114
  },
115
115
  voids: true
116
116
  });
117
- var newType = boldType.toUpperCase();
117
+ var newType = boldType.toLowerCase();
118
118
  var _newText = beforeText.slice(_startOffset + 2, _endOffset - 2);
119
119
  Editor.addMark(editor, newType, true);
120
120
  return insertText(_newText);
@@ -134,7 +134,7 @@ var withMarkDown = function withMarkDown(editor) {
134
134
  },
135
135
  voids: true
136
136
  });
137
- var _newType = italicType.toUpperCase();
137
+ var _newType = italicType.toLowerCase();
138
138
  var _newText2 = beforeText.slice(_startOffset2 + 1, _endOffset2 - 1);
139
139
  Editor.addMark(editor, _newType, true);
140
140
  return insertText(_newText2);
@@ -23,6 +23,9 @@ export var TABLE_ELEMENT_POSITION = {
23
23
  };
24
24
  export var SELECTED_TABLE_CELL_BACKGROUND_COLOR = '#dee8fe';
25
25
  export var TABLE_CELL_STYLE = {
26
- TEXT_ALIGN: 'textAlign',
27
- BACKGROUND_COLOR: 'bg_color'
26
+ TEXT_ALIGN: 'text_align',
27
+ BACKGROUND_COLOR: 'background_color'
28
+ };
29
+ export var TABLE_ROW_STYLE = {
30
+ MIN_HEIGHT: 'min_height'
28
31
  };
@@ -1,13 +1,14 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
5
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
6
  import slugid from 'slugid';
6
7
  import { Editor, Range, Transforms, Point, Node } from '@seafile/slate';
7
8
  import { ReactEditor } from '@seafile/slate-react';
8
9
  import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, focusEditor, getNode, findPath, replaceNodeChildren } from '../../core';
9
10
  import { ELEMENT_TYPE, KEYBOARD, CLIPBOARD_FORMAT_KEY, INSERT_POSITION } from '../../constants';
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
+ import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, TABLE_ROW_STYLE } from './constants';
11
12
  import EventBus from '../../../utils/event-bus';
12
13
  import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../constants';
13
14
  import ObjectUtils from '../../../utils/object-utils';
@@ -64,9 +65,7 @@ export var generateTableRow = function generateTableRow(colsCount) {
64
65
  id: slugid.nice(),
65
66
  type: ELEMENT_TYPE.TABLE_ROW,
66
67
  children: children,
67
- style: {
68
- minHeight: TABLE_ROW_MIN_HEIGHT
69
- }
68
+ style: _defineProperty({}, TABLE_ROW_STYLE.MIN_HEIGHT, TABLE_ROW_MIN_HEIGHT)
70
69
  };
71
70
  };
72
71
  export var generateEmptyTable = function generateEmptyTable(editor) {
@@ -389,11 +388,11 @@ export var setTableSelectedRange = function setTableSelectedRange(editor, range)
389
388
  export var updateTableRowHeight = function updateTableRowHeight(editor, element, rowHeight) {
390
389
  var path = findPath(editor, element);
391
390
  var targetNode = getNode(editor, path);
392
- if (targetNode.style && targetNode.style.minHeight === rowHeight) return;
391
+ var _targetNode$style = targetNode.style,
392
+ style = _targetNode$style === void 0 ? {} : _targetNode$style;
393
+ if (style[TABLE_ROW_STYLE.MIN_HEIGHT] === rowHeight) return;
393
394
  Transforms.setNodes(editor, {
394
- style: _objectSpread(_objectSpread({}, targetNode.style), {}, {
395
- minHeight: rowHeight
396
- })
395
+ style: _objectSpread(_objectSpread({}, style), {}, _defineProperty({}, TABLE_ROW_STYLE.MIN_HEIGHT, rowHeight))
397
396
  }, {
398
397
  at: path
399
398
  });
@@ -878,4 +877,10 @@ export var colorBlend = function colorBlend(c1, c2, ratio) {
878
877
  g = ('0' + (g || 0).toString(16)).slice(-2);
879
878
  b = ('0' + (b || 0).toString(16)).slice(-2);
880
879
  return '#' + r + g + b;
880
+ };
881
+ export var getRowHeight = function getRowHeight(element, rowIndex) {
882
+ var _element$style = element.style,
883
+ style = _element$style === void 0 ? {} : _element$style;
884
+ var rowHeight = style[TABLE_ROW_STYLE.MIN_HEIGHT] || TABLE_ROW_MIN_HEIGHT;
885
+ return rowIndex === 0 ? rowHeight + 1 : rowHeight;
881
886
  };
@@ -18,7 +18,7 @@ var CellBackgroundColorMenu = function CellBackgroundColorMenu(_ref) {
18
18
  updateLastUsedTableCellBackgroundColor = _useColorContext.updateLastUsedTableCellBackgroundColor;
19
19
  var setColor = useCallback(function (color) {
20
20
  setCellStyle(editor, {
21
- bg_color: color
21
+ background_color: color
22
22
  });
23
23
  }, [editor]);
24
24
  var props = _objectSpread(_objectSpread({
@@ -1,7 +1,9 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import React, { useCallback, useRef } from 'react';
2
3
  import { useTranslation } from 'react-i18next';
3
4
  import CommonMenu from './common-menu';
4
5
  import { setCellStyle } from '../../helpers';
6
+ import { TABLE_CELL_STYLE } from '../../constants';
5
7
  var CellTextAlignMenu = function CellTextAlignMenu(_ref) {
6
8
  var editor = _ref.editor,
7
9
  readonly = _ref.readonly;
@@ -10,9 +12,7 @@ var CellTextAlignMenu = function CellTextAlignMenu(_ref) {
10
12
  t = _useTranslation.t;
11
13
  var setTextAlignStyle = useCallback(function (textAlign) {
12
14
  if (readonly) return;
13
- setCellStyle(editor, {
14
- textAlign: textAlign
15
- });
15
+ setCellStyle(editor, _defineProperty({}, TABLE_CELL_STYLE.TEXT_ALIGN, textAlign));
16
16
  textAlignRef.current && textAlignRef.current.hidePopover();
17
17
  }, [editor, readonly]);
18
18
  return /*#__PURE__*/React.createElement(CommonMenu, {
@@ -40,7 +40,7 @@ var TableCell = function TableCell(_ref) {
40
40
  }, [editor, element]);
41
41
  var style = attributes.style || {};
42
42
  if (ObjectUtils.hasProperty(element.style, TABLE_CELL_STYLE.TEXT_ALIGN)) {
43
- style[TABLE_CELL_STYLE.TEXT_ALIGN] = element.style[TABLE_CELL_STYLE.TEXT_ALIGN];
43
+ style['textAlign'] = element.style[TABLE_CELL_STYLE.TEXT_ALIGN];
44
44
  }
45
45
  if (isSelected) {
46
46
  style['backgroundColor'] = SELECTED_TABLE_CELL_BACKGROUND_COLOR;
@@ -86,7 +86,7 @@ function renderTableCell(props) {
86
86
  // const cellValue = element;
87
87
  var style = attributes.style || {};
88
88
  if (ObjectUtils.hasProperty(element.style, TABLE_CELL_STYLE.TEXT_ALIGN)) {
89
- style[TABLE_CELL_STYLE.TEXT_ALIGN] = element[TABLE_CELL_STYLE.TEXT_ALIGN];
89
+ style['textAlign'] = element.style[TABLE_CELL_STYLE.TEXT_ALIGN];
90
90
  }
91
91
  if (ObjectUtils.hasProperty(element.style, TABLE_CELL_STYLE.BACKGROUND_COLOR) && element.style[TABLE_CELL_STYLE.BACKGROUND_COLOR]) {
92
92
  style['backgroundColor'] = element.style[TABLE_CELL_STYLE.BACKGROUND_COLOR];
@@ -6,12 +6,11 @@ import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
6
6
  import { ReactEditor } from '@seafile/slate-react';
7
7
  import { findPath } from '../../../core';
8
8
  import { TABLE_ROW_MIN_HEIGHT } from '../constants';
9
- import { updateTableRowHeight } from '../helpers';
9
+ import { getRowHeight, updateTableRowHeight } from '../helpers';
10
10
  import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
11
11
  import { useSettingSelectRangeContext, useResizeHandlersContext } from './hooks';
12
12
  import { useScrollContext } from '../../../../hooks/use-scroll-context';
13
13
  var TableRow = function TableRow(_ref) {
14
- var _element$style;
15
14
  var element = _ref.element,
16
15
  attributes = _ref.attributes,
17
16
  children = _ref.children;
@@ -29,10 +28,9 @@ var TableRow = function TableRow(_ref) {
29
28
  var rowPath = findPath(editor, element);
30
29
  var pathLength = rowPath ? rowPath.length : 0;
31
30
  var rowIndex = rowPath ? rowPath[pathLength - 1] : -1;
32
- var minHeight = ((_element$style = element.style) === null || _element$style === void 0 ? void 0 : _element$style.minHeight) || TABLE_ROW_MIN_HEIGHT;
33
- var initHeight = rowIndex === 0 ? minHeight + 1 : minHeight;
34
- var tableRow = useRef(initHeight);
35
- var _useState5 = useState(initHeight),
31
+ var rowHeight = getRowHeight(element, rowIndex);
32
+ var tableRow = useRef(rowHeight);
33
+ var _useState5 = useState(rowHeight),
36
34
  _useState6 = _slicedToArray(_useState5, 2),
37
35
  height = _useState6[0],
38
36
  setHeight = _useState6[1];
@@ -107,13 +105,13 @@ function renderTableRow(props) {
107
105
 
108
106
  // eslint-disable-next-line react-hooks/rules-of-hooks
109
107
  var editor = useSlateStatic();
110
- var style = element.style;
111
108
  var rowPath = findPath(editor, element);
112
109
  if (!rowPath) return null;
113
110
  var pathLength = rowPath.length;
114
111
  var rowIndex = rowPath[pathLength - 1];
115
- var minHeight = (style === null || style === void 0 ? void 0 : style.minHeight) || TABLE_ROW_MIN_HEIGHT;
116
- var height = rowIndex === 0 ? minHeight + 1 : minHeight;
112
+ var _element$style = element.style,
113
+ style = _element$style === void 0 ? {} : _element$style;
114
+ var height = getRowHeight(element, rowIndex);
117
115
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
118
116
  className: classnames('table-row', attributes.className),
119
117
  style: _objectSpread(_objectSpread(_objectSpread({}, attributes.style), style), {}, {
@@ -8,9 +8,8 @@ import { useResizeHandlersContext, useTableSelectedRangeContext } from '../../ho
8
8
  import { useScrollContext } from '../../../../../../hooks/use-scroll-context';
9
9
  import { ELEMENT_TYPE } from '../../../../../constants';
10
10
  import { findPath, getSelectedNodeByType } from '../../../../../core';
11
- import { elementHasImage } from '../../../helpers';
11
+ import { elementHasImage, getRowHeight } from '../../../helpers';
12
12
  var RowHeader = function RowHeader(_ref) {
13
- var _row$style;
14
13
  var row = _ref.row,
15
14
  index = _ref.index,
16
15
  addIconPosition = _ref.addIconPosition,
@@ -18,8 +17,9 @@ var RowHeader = function RowHeader(_ref) {
18
17
  setInsertRowIndex = _ref.setInsertRowIndex,
19
18
  selectRange = _ref.selectRange,
20
19
  tableSize = _ref.tableSize;
20
+ var oldRowHeight = getRowHeight(row);
21
21
  var editor = useSlateStatic();
22
- var _useState = useState(row === null || row === void 0 ? void 0 : (_row$style = row.style) === null || _row$style === void 0 ? void 0 : _row$style.minHeight),
22
+ var _useState = useState(oldRowHeight),
23
23
  _useState2 = _slicedToArray(_useState, 2),
24
24
  rowHeight = _useState2[0],
25
25
  setRowHeight = _useState2[1];
@@ -1,3 +1,4 @@
1
+ import { TEXT_STYLE_MAP } from '../../constants';
1
2
  import { getValue, isMenuDisabled, addMark, removeMark } from './helpers';
2
3
  var withTextStyle = function withTextStyle(editor) {
3
4
  var toggleTextStyle = function toggleTextStyle(type) {
@@ -13,10 +14,10 @@ var withTextStyle = function withTextStyle(editor) {
13
14
  }
14
15
  };
15
16
  editor.toggleTextBold = function () {
16
- toggleTextStyle('BOLD');
17
+ toggleTextStyle(TEXT_STYLE_MAP.BOLD);
17
18
  };
18
19
  editor.toggleTextItalic = function () {
19
- toggleTextStyle('ITALIC');
20
+ toggleTextStyle(TEXT_STYLE_MAP.ITALIC);
20
21
  };
21
22
  return editor;
22
23
  };
@@ -2,7 +2,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
2
2
  var _excluded = ["text"];
3
3
  import React from 'react';
4
4
  import Caret from './caret';
5
- import { DEFAULT_FONT } from '../../constants';
5
+ import { DEFAULT_FONT, TEXT_STYLE_MAP } from '../../constants';
6
6
  import { generatorFontFamily } from '../font/helpers';
7
7
  var renderText = function renderText(props, editor) {
8
8
  var attributes = props.attributes,
@@ -20,54 +20,55 @@ var renderText = function renderText(props, editor) {
20
20
  if (leaf.computed_background_color) {
21
21
  style['backgroundColor'] = leaf.computed_background_color;
22
22
  }
23
- if (leaf.color) {
24
- style['color'] = leaf.color;
23
+ if (leaf[TEXT_STYLE_MAP.COLOR]) {
24
+ style['color'] = leaf[TEXT_STYLE_MAP.COLOR];
25
25
  }
26
- if (leaf['highlight-color']) {
27
- style['backgroundColor'] = leaf['highlight-color'];
26
+ if (leaf[TEXT_STYLE_MAP.HIGHLIGHT_COLOR]) {
27
+ style['backgroundColor'] = leaf[TEXT_STYLE_MAP.HIGHLIGHT_COLOR];
28
28
  }
29
- if (leaf['font-size']) {
30
- var fontSize = leaf['font-size'];
29
+ if (leaf[TEXT_STYLE_MAP.FONT_SIZE]) {
30
+ var fontSize = leaf[TEXT_STYLE_MAP.FONT_SIZE];
31
31
  if (typeof fontSize === 'number') {
32
32
  style['fontSize'] = "".concat(fontSize, "pt");
33
33
  }
34
34
  }
35
- var font = leaf['font'] || DEFAULT_FONT;
36
- var fontWeight = leaf.BOLD ? 600 : 400;
37
- style['fontFamily'] = generatorFontFamily(font, fontWeight, leaf);
38
- if (leaf.BOLD) {
35
+ if (leaf[TEXT_STYLE_MAP.FONT]) {
36
+ var fontWeight = leaf[TEXT_STYLE_MAP.BOLD] ? 600 : 400;
37
+ style['fontFamily'] = generatorFontFamily(leaf[TEXT_STYLE_MAP.FONT], fontWeight);
38
+ }
39
+ if (leaf[TEXT_STYLE_MAP.BOLD]) {
39
40
  markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
40
41
  }
41
- if (leaf.ITALIC) {
42
+ if (leaf[TEXT_STYLE_MAP.ITALIC]) {
42
43
  markedChildren = /*#__PURE__*/React.createElement("i", null, markedChildren);
43
44
  }
44
- if (leaf.UNDERLINE) {
45
+ if (leaf[TEXT_STYLE_MAP.UNDERLINE]) {
45
46
  markedChildren = /*#__PURE__*/React.createElement("span", {
46
47
  style: {
47
48
  textDecoration: 'underline'
48
49
  }
49
50
  }, markedChildren);
50
51
  }
51
- if (leaf.STRIKETHROUGH) {
52
+ if (leaf[TEXT_STYLE_MAP.STRIKETHROUGH]) {
52
53
  markedChildren = /*#__PURE__*/React.createElement("span", {
53
54
  style: {
54
55
  textDecoration: 'line-through'
55
56
  }
56
57
  }, markedChildren);
57
58
  }
58
- if (leaf.SUPERSCRIPT) {
59
+ if (leaf[TEXT_STYLE_MAP.SUPERSCRIPT]) {
59
60
  markedChildren = /*#__PURE__*/React.createElement("sup", null, markedChildren);
60
61
  }
61
- if (leaf.SUBSCRIPT) {
62
+ if (leaf[TEXT_STYLE_MAP.SUBSCRIPT]) {
62
63
  markedChildren = /*#__PURE__*/React.createElement("sub", null, markedChildren);
63
64
  }
64
- if (leaf.CODE) {
65
+ if (leaf[TEXT_STYLE_MAP.CODE]) {
65
66
  markedChildren = /*#__PURE__*/React.createElement("code", null, markedChildren);
66
67
  }
67
- if (leaf.DELETE) {
68
+ if (leaf[TEXT_STYLE_MAP.DELETE]) {
68
69
  markedChildren = /*#__PURE__*/React.createElement("del", null, markedChildren);
69
70
  }
70
- if (leaf.ADD) {
71
+ if (leaf[TEXT_STYLE_MAP.ADD]) {
71
72
  markedChildren = /*#__PURE__*/React.createElement("span", null, markedChildren);
72
73
  }
73
74
  if (leaf.decoration) {
@@ -1,10 +1,16 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
4
  import React, { useCallback } from 'react';
3
5
  import { useSlateStatic } from '@seafile/slate-react';
6
+ import { Transforms } from '@seafile/slate';
7
+ import deepCopy from 'deep-copy';
8
+ import { useTranslation } from 'react-i18next';
4
9
  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, FILE_LINK, TITLE, SUBTITLE } from '../constants';
5
10
  import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin } from '../plugins';
6
11
  import EventBus from '../../utils/event-bus';
7
- import { INTERNAL_EVENT } from '../../constants';
12
+ import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY, REBASE_ORIGIN } from '../../constants';
13
+ import { findPath, getNode, replaceNode, deleteNodeMark } from '../../extension/core';
8
14
  var CustomElement = function CustomElement(props) {
9
15
  var editor = useSlateStatic();
10
16
  var element = props.element,
@@ -146,6 +152,220 @@ var CustomElement = function CustomElement(props) {
146
152
  }
147
153
  };
148
154
  var RenderElement = function RenderElement(props) {
155
+ var editor = useSlateStatic();
156
+ var _useTranslation = useTranslation(),
157
+ t = _useTranslation.t;
158
+ var updateParentNodeByPath = useCallback(function (path) {
159
+ var parentPath = path.slice(0, -1);
160
+ var parentNode = getNode(editor, parentPath);
161
+ if (parentNode.children.filter(function (item) {
162
+ return item[REBASE_MARK_KEY.REBASE_TYPE];
163
+ }).length === 0) {
164
+ var newParentElement = _objectSpread({}, parentNode);
165
+ newParentElement[REBASE_MARK_KEY.REBASE_TYPE] && delete newParentElement[REBASE_MARK_KEY.REBASE_TYPE];
166
+ newParentElement[REBASE_MARK_KEY.OLD_ELEMENT] && delete newParentElement[REBASE_MARK_KEY.OLD_ELEMENT];
167
+ newParentElement[REBASE_MARK_KEY.ORIGIN] && delete newParentElement[REBASE_MARK_KEY.ORIGIN];
168
+ newParentElement['children'] = newParentElement['children'].map(function (item) {
169
+ item[REBASE_MARK_KEY.REBASE_TYPE] && delete item[REBASE_MARK_KEY.REBASE_TYPE];
170
+ item[REBASE_MARK_KEY.OLD_ELEMENT] && delete item[REBASE_MARK_KEY.OLD_ELEMENT];
171
+ item[REBASE_MARK_KEY.ORIGIN] && delete item[REBASE_MARK_KEY.ORIGIN];
172
+ return item;
173
+ });
174
+ replaceNode(editor, {
175
+ at: parentPath,
176
+ nodes: newParentElement
177
+ });
178
+ }
179
+
180
+ // eslint-disable-next-line react-hooks/exhaustive-deps
181
+ }, [editor]);
182
+ var deleteElement = useCallback(function (element) {
183
+ var path = findPath(editor, element);
184
+ Transforms.removeNodes(editor, {
185
+ at: path
186
+ });
187
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
188
+ updateParentNodeByPath(path);
189
+ }
190
+
191
+ // eslint-disable-next-line react-hooks/exhaustive-deps
192
+ }, [editor]);
193
+ var deleteMark = useCallback(function (element) {
194
+ var path = findPath(editor, element);
195
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
196
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
197
+ updateParentNodeByPath(path);
198
+ }
199
+
200
+ // eslint-disable-next-line react-hooks/exhaustive-deps
201
+ }, [editor]);
202
+ var useMasterChanges = useCallback(function (element) {
203
+ var path = findPath(editor, element);
204
+ deleteNodeMark(editor, path, element[REBASE_MARK_KEY.OLD_ELEMENT], REBASE_MARKS);
205
+ var nextElementPath = _toConsumableArray(path);
206
+ nextElementPath[path.length - 1] = path[path.length - 1] + 1;
207
+ Transforms.removeNodes(editor, {
208
+ at: nextElementPath
209
+ });
210
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
211
+ updateParentNodeByPath(path);
212
+ }
213
+
214
+ // eslint-disable-next-line react-hooks/exhaustive-deps
215
+ }, [editor]);
216
+ var useCurrentChanges = useCallback(function (element) {
217
+ var path = findPath(editor, element);
218
+ var currentElementPath = _toConsumableArray(path);
219
+ currentElementPath[path.length - 1] = path[path.length - 1] + 1;
220
+ var currentElement = getNode(editor, currentElementPath);
221
+ var newCurrentElement = deepCopy(currentElement);
222
+ deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
223
+ Transforms.removeNodes(editor, {
224
+ at: path
225
+ });
226
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
227
+ updateParentNodeByPath(path);
228
+ }
229
+
230
+ // eslint-disable-next-line react-hooks/exhaustive-deps
231
+ }, [editor]);
232
+ var useBothChanges = useCallback(function (element) {
233
+ // delete element marks
234
+ var path = findPath(editor, element);
235
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
236
+
237
+ // delete next element marks
238
+ var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
239
+ var nextElement = getNode(editor, nextElementPath);
240
+ deleteNodeMark(editor, nextElementPath, nextElement, REBASE_MARKS);
241
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
242
+ updateParentNodeByPath(path);
243
+ }
244
+
245
+ // eslint-disable-next-line react-hooks/exhaustive-deps
246
+ }, [editor]);
247
+ var element = props.element;
248
+ var rebaseType = element[REBASE_MARK_KEY.REBASE_TYPE];
249
+ if (!rebaseType) {
250
+ return /*#__PURE__*/React.createElement(CustomElement, props);
251
+ }
252
+ if (rebaseType === REBASE_TYPE.MODIFY_DELETE) {
253
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
254
+ className: "w-100 d-flex sdoc-rebase-btn-group",
255
+ contentEditable: false
256
+ }, /*#__PURE__*/React.createElement("div", {
257
+ className: "sdoc-rebase-btn",
258
+ onClick: function onClick() {
259
+ return deleteMark(element);
260
+ }
261
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
262
+ className: "mr-2 ml-2"
263
+ }, '|'), /*#__PURE__*/React.createElement("div", {
264
+ className: "sdoc-rebase-btn",
265
+ onClick: function onClick() {
266
+ return deleteElement(element);
267
+ }
268
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
269
+ className: "mr-2 ml-2"
270
+ }, '|'), /*#__PURE__*/React.createElement("div", {
271
+ className: "sdoc-rebase-btn",
272
+ onClick: function onClick() {
273
+ return deleteMark(element);
274
+ }
275
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
276
+ className: "w-100 sdoc-rebase-current-changes-start",
277
+ contentEditable: false
278
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
279
+ className: "w-100 sdoc-rebase-incoming-changes",
280
+ contentEditable: false
281
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
282
+ className: "w-100",
283
+ contentEditable: false
284
+ }, '======='), /*#__PURE__*/React.createElement("div", {
285
+ className: "w-100 sdoc-rebase-incoming-changes-end",
286
+ contentEditable: false
287
+ }, '>>>>>>>'));
288
+ }
289
+ if (rebaseType === REBASE_TYPE.DELETE_MODIFY) {
290
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
291
+ className: "w-100 d-flex sdoc-rebase-btn-group",
292
+ contentEditable: false
293
+ }, /*#__PURE__*/React.createElement("div", {
294
+ className: "sdoc-rebase-btn",
295
+ onClick: function onClick() {
296
+ return deleteElement(element);
297
+ }
298
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
299
+ className: "mr-2 ml-2"
300
+ }, '|'), /*#__PURE__*/React.createElement("div", {
301
+ className: "sdoc-rebase-btn",
302
+ onClick: function onClick() {
303
+ return deleteMark(element);
304
+ }
305
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
306
+ className: "mr-2 ml-2"
307
+ }, '|'), /*#__PURE__*/React.createElement("div", {
308
+ className: "sdoc-rebase-btn",
309
+ onClick: function onClick() {
310
+ return deleteMark(element);
311
+ }
312
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
313
+ className: "w-100 sdoc-rebase-current-changes-start",
314
+ contentEditable: false
315
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
316
+ className: "w-100",
317
+ contentEditable: false
318
+ }, '======='), /*#__PURE__*/React.createElement("div", {
319
+ className: "w-100 sdoc-rebase-incoming-changes",
320
+ contentEditable: false
321
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
322
+ className: "w-100 sdoc-rebase-incoming-changes-end",
323
+ contentEditable: false
324
+ }, '>>>>>>>'));
325
+ }
326
+ if (rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
327
+ if (element[REBASE_MARK_KEY.ORIGIN] === REBASE_ORIGIN.OTHER) {
328
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
329
+ className: "w-100 d-flex sdoc-rebase-btn-group",
330
+ contentEditable: false
331
+ }, /*#__PURE__*/React.createElement("div", {
332
+ className: "sdoc-rebase-btn",
333
+ onClick: function onClick() {
334
+ return useMasterChanges(element);
335
+ }
336
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
337
+ className: "mr-2 ml-2"
338
+ }, '|'), /*#__PURE__*/React.createElement("div", {
339
+ className: "sdoc-rebase-btn",
340
+ onClick: function onClick() {
341
+ return useCurrentChanges(element);
342
+ }
343
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
344
+ className: "mr-2 ml-2"
345
+ }, '|'), /*#__PURE__*/React.createElement("div", {
346
+ className: "sdoc-rebase-btn",
347
+ onClick: function onClick() {
348
+ return useBothChanges(element);
349
+ }
350
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
351
+ className: "w-100 sdoc-rebase-current-changes-start",
352
+ contentEditable: false
353
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
354
+ className: "w-100 sdoc-rebase-current-changes",
355
+ contentEditable: false
356
+ }, /*#__PURE__*/React.createElement(CustomElement, props)));
357
+ }
358
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
359
+ className: "w-100",
360
+ contentEditable: false
361
+ }, '======='), /*#__PURE__*/React.createElement("div", {
362
+ className: "w-100 sdoc-rebase-incoming-changes",
363
+ contentEditable: false
364
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
365
+ className: "w-100 sdoc-rebase-incoming-changes-end",
366
+ contentEditable: false
367
+ }, '>>>>>>>'));
368
+ }
149
369
  return /*#__PURE__*/React.createElement(CustomElement, props);
150
370
 
151
371
  // const { element } = props;
@@ -4,6 +4,7 @@ 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';
7
8
  export var getNodePathById = function getNodePathById(rootNode, nodeId) {
8
9
  var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
9
10
  if (rootNode.id === nodeId) return path;
@@ -252,6 +253,7 @@ export var reExecRevertOperationList = function reExecRevertOperationList(editor
252
253
  }
253
254
  };
254
255
  export var syncRemoteOperations = function syncRemoteOperations(editor, remoteOperations) {
256
+ if (editor.mode !== MODE.EDITOR) return;
255
257
  if (remoteOperations.length === 0) return;
256
258
  Editor.withoutNormalizing(editor, function () {
257
259
  for (var i = 0; i < remoteOperations.length; i++) {