@seafile/sdoc-editor 0.1.153 → 0.1.154-beta1

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 (37) hide show
  1. package/dist/api/seafile-api.js +23 -10
  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 +129 -0
  6. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  7. package/dist/basic-sdk/extension/constants/diff-view.js +14 -0
  8. package/dist/basic-sdk/extension/constants/element-type.js +2 -21
  9. package/dist/basic-sdk/extension/constants/index.js +8 -229
  10. package/dist/basic-sdk/extension/constants/menus-config.js +234 -0
  11. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  12. package/dist/basic-sdk/extension/plugins/markdown/plugin.js +7 -7
  13. package/dist/basic-sdk/extension/plugins/table/constants/index.js +5 -1
  14. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -3
  15. package/dist/basic-sdk/extension/plugins/text-align/helpers.js +3 -3
  16. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +4 -4
  17. package/dist/basic-sdk/extension/render/render-element.js +221 -1
  18. package/dist/basic-sdk/socket/helpers.js +2 -0
  19. package/dist/basic-sdk/socket/socket-client.js +58 -0
  20. package/dist/basic-sdk/socket/socket-manager.js +34 -2
  21. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  22. package/dist/basic-sdk/utils/diff.js +4 -3
  23. package/dist/basic-sdk/utils/rebase.js +193 -0
  24. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  25. package/dist/basic-sdk/views/viewer.js +9 -12
  26. package/dist/components/doc-operations/index.js +4 -2
  27. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  28. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  29. package/dist/components/tip-dialog/index.js +48 -0
  30. package/dist/components/tip-dialog/tip-content.js +47 -0
  31. package/dist/constants/index.js +26 -2
  32. package/dist/context.js +37 -9
  33. package/dist/pages/simple-editor.js +253 -84
  34. package/package.json +1 -1
  35. package/public/locales/en/sdoc-editor.json +11 -1
  36. package/public/locales/zh_CN/sdoc-editor.json +10 -1
  37. package/dist/basic-sdk/editor.js +0 -105
@@ -0,0 +1,234 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ var _MENUS_CONFIG_MAP;
3
+ import { RECENT_USED_HIGHLIGHT_COLORS_KEY, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, RECENT_USED_FONT_COLORS_KEY, DEFAULT_FONT_COLOR, DEFAULT_LAST_USED_FONT_COLOR } from './color';
4
+ import { BLOCKQUOTE, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST_ITEM, CODE_BLOCK, LINK, IMAGE, TABLE, SDOC_LINK, FILE_LINK, PARAGRAPH } from './element-type';
5
+ export var UNDO = 'undo';
6
+ export var REDO = 'redo';
7
+ export var CLEAR_FORMAT = 'clear_format';
8
+ export var REMOVE_TABLE = 'remove_table';
9
+ export var BG_COLOR = 'bg_color';
10
+
11
+ // text style
12
+ var ITALIC = 'italic';
13
+ var BOLD = 'bold';
14
+ var UNDERLINE = 'underline';
15
+ var HIGHLIGHT_COLOR = 'highlight-color';
16
+ var COLOR = 'color';
17
+ export var TEXT_STYLE = 'text_style';
18
+ export var TEXT_STYLE_MAP = {
19
+ ITALIC: ITALIC,
20
+ BOLD: BOLD,
21
+ BOLD_ITALIC: "".concat(BOLD, "-").concat(ITALIC),
22
+ COLOR: COLOR
23
+ };
24
+
25
+ // text-align
26
+ export var TEXT_ALIGN = 'text_align';
27
+ var ALIGN_LEFT = 'align_left';
28
+ var ALIGN_RIGHT = 'align_right';
29
+ var ALIGN_CENTER = 'align_center';
30
+ export var TEXT_STYLE_MORE = 'text_style_more';
31
+ var STRIKETHROUGH = 'strikethrough';
32
+ var SUPERSCRIPT = 'superscript';
33
+ var SUBSCRIPT = 'subscript';
34
+ // const FONT_SIZE_INCREASE = 'font-size-increase';
35
+ // const FONT_SIZE_REDUCE = 'font-size-reduce';
36
+
37
+ // header menu config
38
+ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CONFIG_MAP, BLOCKQUOTE, {
39
+ id: "sdoc_".concat(BLOCKQUOTE),
40
+ iconClass: 'sdocfont sdoc-quote-left',
41
+ text: 'Quote'
42
+ }), _defineProperty(_MENUS_CONFIG_MAP, ORDERED_LIST, {
43
+ id: ORDERED_LIST,
44
+ iconClass: 'sdocfont sdoc-list-ol',
45
+ text: 'Ordered_list'
46
+ }), _defineProperty(_MENUS_CONFIG_MAP, UNORDERED_LIST, {
47
+ id: UNORDERED_LIST,
48
+ iconClass: 'sdocfont sdoc-list-ul',
49
+ text: 'Unordered_list'
50
+ }), _defineProperty(_MENUS_CONFIG_MAP, CHECK_LIST_ITEM, {
51
+ id: CHECK_LIST_ITEM,
52
+ iconClass: 'sdocfont sdoc-check-square',
53
+ text: 'Check_list_item'
54
+ }), _defineProperty(_MENUS_CONFIG_MAP, CODE_BLOCK, {
55
+ id: CODE_BLOCK,
56
+ iconClass: 'sdocfont sdoc-code-block',
57
+ text: 'Code_block'
58
+ }), _defineProperty(_MENUS_CONFIG_MAP, LINK, {
59
+ id: "sdoc_".concat(LINK),
60
+ iconClass: 'sdocfont sdoc-link',
61
+ text: 'Insert_link'
62
+ }), _defineProperty(_MENUS_CONFIG_MAP, IMAGE, {
63
+ id: "sdoc_".concat(IMAGE),
64
+ iconClass: 'sdocfont sdoc-image',
65
+ text: 'Insert_image'
66
+ }), _defineProperty(_MENUS_CONFIG_MAP, TABLE, {
67
+ id: "sdoc_".concat(TABLE),
68
+ iconClass: 'sdocfont sdoc-table',
69
+ text: 'Insert_table'
70
+ }), _defineProperty(_MENUS_CONFIG_MAP, REMOVE_TABLE, {
71
+ id: "sdoc_".concat(REMOVE_TABLE),
72
+ iconClass: 'sdocfont sdoc-delete-table',
73
+ text: 'Delete_table'
74
+ }), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE, [{
75
+ id: ITALIC,
76
+ iconClass: 'sdocfont sdoc-italic',
77
+ text: 'Italic',
78
+ type: 'ITALIC'
79
+ }, {
80
+ id: BOLD,
81
+ iconClass: 'sdocfont sdoc-bold',
82
+ text: 'Bold',
83
+ type: 'BOLD'
84
+ }, {
85
+ id: UNDERLINE,
86
+ iconClass: 'sdocfont sdoc-underline',
87
+ text: 'Underline',
88
+ type: 'UNDERLINE'
89
+ }, {
90
+ id: "sdoc-".concat(HIGHLIGHT_COLOR),
91
+ iconClass: 'sdocfont sdoc-highlight-color',
92
+ text: 'Highlight_color',
93
+ type: HIGHLIGHT_COLOR,
94
+ isColor: true,
95
+ recentUsedColorsKey: RECENT_USED_HIGHLIGHT_COLORS_KEY,
96
+ defaultLastUsedColor: DEFAULT_LAST_USED_HIGHLIGHT_COLOR
97
+ }, {
98
+ id: "sdoc-font-".concat(COLOR),
99
+ iconClass: 'sdocfont sdoc-font-color',
100
+ text: 'Font_color',
101
+ type: COLOR,
102
+ defaultColor: DEFAULT_FONT_COLOR,
103
+ isColor: true,
104
+ recentUsedColorsKey: RECENT_USED_FONT_COLORS_KEY,
105
+ defaultLastUsedColor: DEFAULT_LAST_USED_FONT_COLOR
106
+ }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE_MORE, [
107
+ //
108
+ {
109
+ id: STRIKETHROUGH,
110
+ iconClass: 'sdocfont sdoc-strikethrough',
111
+ text: 'Strikethrough',
112
+ type: 'STRIKETHROUGH'
113
+ }, {
114
+ id: SUPERSCRIPT,
115
+ iconClass: 'sdocfont sdoc-subscripts',
116
+ text: 'Superscript',
117
+ type: 'SUPERSCRIPT'
118
+ }, {
119
+ id: SUBSCRIPT,
120
+ iconClass: 'sdocfont sdoc-subscripts',
121
+ text: 'Subscript',
122
+ type: 'SUBSCRIPT'
123
+ }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_ALIGN, [{
124
+ id: ALIGN_LEFT,
125
+ iconClass: 'sdocfont sdoc-align-left',
126
+ type: 'left'
127
+ }, {
128
+ id: ALIGN_CENTER,
129
+ iconClass: 'sdocfont sdoc-align-center',
130
+ type: 'center'
131
+ }, {
132
+ id: ALIGN_RIGHT,
133
+ iconClass: 'sdocfont sdoc-align-right',
134
+ type: 'right'
135
+ }]), _defineProperty(_MENUS_CONFIG_MAP, UNDO, {
136
+ id: UNDO,
137
+ iconClass: 'sdocfont sdoc-revoke',
138
+ text: 'Undo',
139
+ type: 'undo'
140
+ }), _defineProperty(_MENUS_CONFIG_MAP, REDO, {
141
+ id: REDO,
142
+ iconClass: 'sdocfont sdoc-redo',
143
+ text: 'Redo',
144
+ type: 'redo'
145
+ }), _defineProperty(_MENUS_CONFIG_MAP, BG_COLOR, {
146
+ id: "sdoc_".concat(BG_COLOR),
147
+ iconClass: 'sdocfont sdoc-bg-color',
148
+ text: 'Background_color'
149
+ }), _defineProperty(_MENUS_CONFIG_MAP, CLEAR_FORMAT, {
150
+ id: "sdoc_".concat(CLEAR_FORMAT),
151
+ iconClass: 'sdocfont sdoc-format-clear',
152
+ text: 'Clear_format'
153
+ }), _defineProperty(_MENUS_CONFIG_MAP, SDOC_LINK, {
154
+ id: "sdoc_".concat(SDOC_LINK),
155
+ iconClass: 'sdocfont sdoc-document',
156
+ text: 'Link_sdoc'
157
+ }), _defineProperty(_MENUS_CONFIG_MAP, FILE_LINK, {
158
+ id: "sdoc_".concat(FILE_LINK),
159
+ iconClass: 'sdocfont sdoc-link-file',
160
+ text: 'Link_file'
161
+ }), _MENUS_CONFIG_MAP);
162
+
163
+ // side menu config
164
+ export var SIDE_MENUS_CONFIG = [{
165
+ id: PARAGRAPH,
166
+ iconClass: 'sdocfont sdoc-text',
167
+ type: PARAGRAPH,
168
+ text: 'Paragraph'
169
+ }, {
170
+ id: HEADER1,
171
+ iconClass: 'sdocfont sdoc-header1',
172
+ type: HEADER1,
173
+ text: 'Header_one'
174
+ }, {
175
+ id: HEADER2,
176
+ iconClass: 'sdocfont sdoc-header2',
177
+ type: HEADER2,
178
+ text: 'Header_two'
179
+ }, {
180
+ id: HEADER3,
181
+ iconClass: 'sdocfont sdoc-header3',
182
+ type: HEADER3,
183
+ text: 'Header_three'
184
+ }, {
185
+ id: HEADER4,
186
+ iconClass: 'sdocfont sdoc-header4',
187
+ type: HEADER4,
188
+ text: 'Header_four'
189
+ }, {
190
+ id: HEADER5,
191
+ iconClass: 'sdocfont sdoc-header5',
192
+ type: HEADER5,
193
+ text: 'Header_five'
194
+ }, {
195
+ id: HEADER6,
196
+ iconClass: 'sdocfont sdoc-header6',
197
+ type: HEADER6,
198
+ text: 'Header_six'
199
+ }, {
200
+ id: UNORDERED_LIST,
201
+ iconClass: 'sdocfont sdoc-list-ul',
202
+ type: UNORDERED_LIST,
203
+ text: 'Unordered_list'
204
+ }, {
205
+ id: ORDERED_LIST,
206
+ iconClass: 'sdocfont sdoc-list-ol',
207
+ type: ORDERED_LIST,
208
+ text: 'Ordered_list'
209
+ }, {
210
+ id: CHECK_LIST_ITEM,
211
+ iconClass: 'sdocfont sdoc-check-square',
212
+ type: CHECK_LIST_ITEM,
213
+ text: 'Check_list_item'
214
+ }, {
215
+ id: ALIGN_LEFT,
216
+ iconClass: 'sdocfont sdoc-align-left',
217
+ type: 'left',
218
+ text: 'Left'
219
+ }, {
220
+ id: ALIGN_CENTER,
221
+ iconClass: 'sdocfont sdoc-align-center',
222
+ type: 'center',
223
+ text: 'Center'
224
+ }, {
225
+ id: ALIGN_RIGHT,
226
+ iconClass: 'sdocfont sdoc-align-right',
227
+ type: 'right',
228
+ text: 'Right'
229
+ }, {
230
+ id: BLOCKQUOTE,
231
+ iconClass: 'sdocfont sdoc-quote1',
232
+ type: BLOCKQUOTE,
233
+ text: 'Quote'
234
+ }];
@@ -12,4 +12,30 @@ 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
+ });
15
41
  };
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { Editor, Transforms, Range } from '@seafile/slate';
3
3
  import { toggleList } from '../list/transforms';
4
4
  import { getSelectedNodeByType } from '../../core';
5
- import { HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, UNORDERED_LIST, BLOCKQUOTE, BOLD, ITALIC, BOLD_ITALIC } from '../../constants';
5
+ import { HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, UNORDERED_LIST, BLOCKQUOTE, TEXT_STYLE_MAP } from '../../constants';
6
6
  var KEY_TO_TYPE_FOR_SPACE = {
7
7
  // Title shortcut
8
8
  '#': HEADER1,
@@ -19,9 +19,9 @@ var KEY_TO_TYPE_FOR_SPACE = {
19
19
  };
20
20
  var KEY_TO_INLINE_TYPE_FOR_SPACE = {
21
21
  // Inline shortcut keys
22
- '**': BOLD,
23
- '*': ITALIC,
24
- '***': BOLD_ITALIC
22
+ '**': TEXT_STYLE_MAP.BOLD,
23
+ '*': TEXT_STYLE_MAP.ITALIC,
24
+ '***': TEXT_STYLE_MAP.BOLD_ITALIC
25
25
  };
26
26
  var getBeforeText = function getBeforeText(editor) {
27
27
  var selection = editor.selection;
@@ -76,7 +76,7 @@ var withMarkDown = function withMarkDown(editor) {
76
76
  var italicType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-1)];
77
77
  var italicAndBoldType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-3)];
78
78
  if (!type && !boldType && !italicType && !italicAndBoldType) return insertText(text);
79
- if (italicAndBoldType === BOLD_ITALIC) {
79
+ if (italicAndBoldType === TEXT_STYLE_MAP.BOLD_ITALIC) {
80
80
  var restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 3);
81
81
  var startOffset = restStr === null || restStr === void 0 ? void 0 : restStr.lastIndexOf('***');
82
82
  var endOffset = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf('***')) + 3;
@@ -97,7 +97,7 @@ var withMarkDown = function withMarkDown(editor) {
97
97
  return insertText(newText);
98
98
  }
99
99
  }
100
- if (boldType === BOLD) {
100
+ if (boldType === TEXT_STYLE_MAP.BOLD) {
101
101
  var _restStr = beforeText.slice(0, beforeText.length - 2);
102
102
  var _startOffset = _restStr.lastIndexOf('**');
103
103
  var _endOffset = beforeText.lastIndexOf('**') + 2;
@@ -119,7 +119,7 @@ var withMarkDown = function withMarkDown(editor) {
119
119
  Editor.addMark(editor, newType, true);
120
120
  return insertText(_newText);
121
121
  }
122
- if (italicType === ITALIC) {
122
+ if (italicType === TEXT_STYLE_MAP.ITALIC) {
123
123
  var _restStr2 = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 1);
124
124
  var _startOffset2 = _restStr2 === null || _restStr2 === void 0 ? void 0 : _restStr2.lastIndexOf('*');
125
125
  var _endOffset2 = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf('*')) + 1;
@@ -21,4 +21,8 @@ export var TABLE_ELEMENT_POSITION = {
21
21
  AFTER: 'after',
22
22
  BEFORE: 'before'
23
23
  };
24
- export var SELECTED_TABLE_CELL_BG_COLOR = '#dee8fe';
24
+ export var SELECTED_TABLE_CELL_BG_COLOR = '#dee8fe';
25
+ export var STYLE_KEY = {
26
+ TEXT_ALIGN: 'textAlign',
27
+ BG_COLOR: 'bg_color'
28
+ };
@@ -4,10 +4,9 @@ import classnames from 'classnames';
4
4
  import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
5
  import { Transforms } from '@seafile/slate';
6
6
  import ObjectUtils from '../../../../utils/object-utils';
7
- import { STYLE_KEY } from '../../../constants';
8
7
  import { findPath, focusEditor } from '../../../core';
9
8
  import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
10
- import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BG_COLOR } from '../constants';
9
+ import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BG_COLOR, STYLE_KEY } from '../constants';
11
10
  import { getTableColumns, getCellColumn, colorBlend } from '../helpers';
12
11
  var TableCell = function TableCell(_ref) {
13
12
  var attributes = _ref.attributes,
@@ -86,7 +85,7 @@ function renderTableCell(props) {
86
85
 
87
86
  // const cellValue = element;
88
87
  var style = attributes.style || {};
89
- if (ObjectUtils.hasProperty(element, STYLE_KEY.TEXT_ALIGN)) {
88
+ if (ObjectUtils.hasProperty(element.style, STYLE_KEY.TEXT_ALIGN)) {
90
89
  style[STYLE_KEY.TEXT_ALIGN] = element[STYLE_KEY.TEXT_ALIGN];
91
90
  }
92
91
  if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR) && element.style[STYLE_KEY.BG_COLOR]) {
@@ -1,6 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import { Editor, Transforms, Element } from '@seafile/slate';
3
- import { TEXT_ALIGN, MENUS_CONFIG_MAP, CODE_BLOCK, TABLE } from '../../constants';
3
+ import { CODE_BLOCK, TABLE } from '../../constants';
4
4
  export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
5
5
  if (readonly) return true;
6
6
  if (!editor.selection) return true;
@@ -15,13 +15,13 @@ export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
15
15
  match = _Editor$nodes2[0];
16
16
  var elementType = match[0].type;
17
17
  // at present, TABLE got its own 'text align'
18
- if (elementType == CODE_BLOCK || elementType == TABLE) {
18
+ if (elementType === CODE_BLOCK || elementType === TABLE) {
19
19
  return true;
20
20
  }
21
21
  return false;
22
22
  };
23
23
  export var getAlignType = function getAlignType(editor) {
24
- var defaultType = MENUS_CONFIG_MAP[TEXT_ALIGN][0].type;
24
+ var defaultType = 'left';
25
25
  var selection = editor.selection;
26
26
  if (!selection) {
27
27
  return defaultType;
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useCallback } from 'react';
3
3
  import { withTranslation } from 'react-i18next';
4
4
  import { Editor } from '@seafile/slate';
5
- import { TEXT_STYLE, TEXT_STYLE_MORE, MENUS_CONFIG_MAP, ELEMENT_TYPE } from '../../../constants';
5
+ import { TEXT_STYLE, TEXT_STYLE_MAP, TEXT_STYLE_MORE, MENUS_CONFIG_MAP } from '../../../constants';
6
6
  import { focusEditor } from '../../../core';
7
7
  import { MenuItem, ColorMenu, MoreDropdown } from '../../../commons';
8
8
  import { getFontSize, setFontSize } from '../../font/helpers';
@@ -82,9 +82,9 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
82
82
  itemProps['setColor'] = function (color) {
83
83
  return setColor(item.type, color);
84
84
  };
85
- itemProps['defaultColorTip'] = item.type === ELEMENT_TYPE.COLOR ? t('Default') : '';
86
- itemProps['lastUsedColor'] = item.type === ELEMENT_TYPE.COLOR ? lastUsedFontColor : lastUsedHighlightColor;
87
- itemProps['updateLastUsedColor'] = item.type === ELEMENT_TYPE.COLOR ? updateLastUsedFontColor : updateLastUsedHighlightColor;
85
+ itemProps['defaultColorTip'] = item.type === TEXT_STYLE_MAP.COLOR ? t('Default') : '';
86
+ itemProps['lastUsedColor'] = item.type === TEXT_STYLE_MAP.COLOR ? lastUsedFontColor : lastUsedHighlightColor;
87
+ itemProps['updateLastUsedColor'] = item.type === TEXT_STYLE_MAP.COLOR ? updateLastUsedFontColor : updateLastUsedHighlightColor;
88
88
  }
89
89
  return _objectSpread(_objectSpread(_objectSpread({}, itemProps), item), {}, {
90
90
  id: idPrefix ? "".concat(idPrefix, "_").concat(item.id) : item.id
@@ -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++) {