@seafile/sdoc-editor 0.1.152 → 0.1.154-beta

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 (39) hide show
  1. package/dist/api/sdoc-server-api.js +10 -0
  2. package/dist/api/seafile-api.js +17 -9
  3. package/dist/basic-sdk/constants/index.js +25 -1
  4. package/dist/basic-sdk/editor/common-editor.js +50 -0
  5. package/dist/basic-sdk/editor/index.css +29 -0
  6. package/dist/basic-sdk/editor/index.js +129 -0
  7. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  8. package/dist/basic-sdk/extension/constants/diff-view.js +14 -0
  9. package/dist/basic-sdk/extension/constants/element-type.js +3 -23
  10. package/dist/basic-sdk/extension/constants/index.js +8 -229
  11. package/dist/basic-sdk/extension/constants/menus-config.js +234 -0
  12. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  13. package/dist/basic-sdk/extension/plugins/check-list/menu/index.js +2 -2
  14. package/dist/basic-sdk/extension/plugins/markdown/plugin.js +7 -7
  15. package/dist/basic-sdk/extension/plugins/table/constants/index.js +5 -1
  16. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -3
  17. package/dist/basic-sdk/extension/plugins/text-align/helpers.js +3 -3
  18. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +4 -4
  19. package/dist/basic-sdk/extension/render/render-element.js +247 -1
  20. package/dist/basic-sdk/socket/helpers.js +2 -0
  21. package/dist/basic-sdk/socket/socket-client.js +45 -0
  22. package/dist/basic-sdk/socket/socket-manager.js +28 -2
  23. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  24. package/dist/basic-sdk/utils/diff.js +4 -3
  25. package/dist/basic-sdk/utils/rebase.js +228 -0
  26. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  27. package/dist/basic-sdk/views/viewer.js +9 -12
  28. package/dist/components/doc-operations/index.js +4 -2
  29. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  30. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  31. package/dist/components/tip-dialog/index.js +48 -0
  32. package/dist/components/tip-dialog/tip-content.js +47 -0
  33. package/dist/constants/index.js +23 -2
  34. package/dist/context.js +34 -9
  35. package/dist/pages/simple-editor.js +250 -83
  36. package/package.json +1 -1
  37. package/public/locales/en/sdoc-editor.json +11 -1
  38. package/public/locales/zh_CN/sdoc-editor.json +10 -1
  39. 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
  };
@@ -4,7 +4,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
- import { CHECK_LIST, CHECK_LIST_ITEM, MENUS_CONFIG_MAP, PARAGRAPH } from '../../../constants';
7
+ import { CHECK_LIST_ITEM, MENUS_CONFIG_MAP, PARAGRAPH } from '../../../constants';
8
8
  import { MenuItem } from '../../../commons';
9
9
  import { isMenuDisabled, setCheckListItemType, getCheckListItemType } from '../helpers';
10
10
  var CheckListMenu = /*#__PURE__*/function (_React$Component) {
@@ -41,7 +41,7 @@ var CheckListMenu = /*#__PURE__*/function (_React$Component) {
41
41
  var _this$props2 = this.props,
42
42
  isRichEditor = _this$props2.isRichEditor,
43
43
  className = _this$props2.className;
44
- var menuConfig = MENUS_CONFIG_MAP[CHECK_LIST];
44
+ var menuConfig = MENUS_CONFIG_MAP[CHECK_LIST_ITEM];
45
45
  var props = _objectSpread(_objectSpread({
46
46
  isRichEditor: isRichEditor,
47
47
  className: className
@@ -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, generateEmptyElement, 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,246 @@ 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
+
203
+ // const addDeletedElement = useCallback((element) => {
204
+ // const path = findPath(editor, element);
205
+ // deleteNodeMark(editor, path, element, REBASE_MARKS);
206
+
207
+ // if (element.type !== ELEMENT_TYPE.LIST_ITEM) {
208
+ // const emptyNode = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
209
+ // Transforms.insertNodes(editor, emptyNode, { at: [ path[0] ] });
210
+ // } else {
211
+ // const emptyNode = generateEmptyElement(ELEMENT_TYPE.LIST_ITEM);
212
+ // emptyNode.children[0] = generateEmptyElement(ELEMENT_TYPE.LIST_LIC);
213
+ // const parentPath = path.slice(0, -1);
214
+ // const parentNode = getNode(editor, parentPath);
215
+ // const newChildren = [ ...parentNode.children ];
216
+ // const index = path[path.length - 1];
217
+ // newChildren.splice(index, 0, emptyNode);
218
+ // replaceNode(editor, { at: parentPath, nodes: { ...parentNode, children: newChildren} });
219
+ // }
220
+
221
+ // if (element.type === ELEMENT_TYPE.LIST_ITEM) {
222
+ // updateParentNodeByPath(path);
223
+ // }
224
+
225
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
226
+ // }, [ editor]);
227
+
228
+ var useMasterChanges = useCallback(function (element) {
229
+ var path = findPath(editor, element);
230
+ deleteNodeMark(editor, path, element[REBASE_MARK_KEY.OLD_ELEMENT], REBASE_MARKS);
231
+ var nextElementPath = _toConsumableArray(path);
232
+ nextElementPath[path.length - 1] = path[path.length - 1] + 1;
233
+ Transforms.removeNodes(editor, {
234
+ at: nextElementPath
235
+ });
236
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
237
+ updateParentNodeByPath(path);
238
+ }
239
+
240
+ // eslint-disable-next-line react-hooks/exhaustive-deps
241
+ }, [editor]);
242
+ var useCurrentChanges = useCallback(function (element) {
243
+ var path = findPath(editor, element);
244
+ var currentElementPath = _toConsumableArray(path);
245
+ currentElementPath[path.length - 1] = path[path.length - 1] + 1;
246
+ var currentElement = getNode(editor, currentElementPath);
247
+ var newCurrentElement = deepCopy(currentElement);
248
+ deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
249
+ Transforms.removeNodes(editor, {
250
+ at: path
251
+ });
252
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
253
+ updateParentNodeByPath(path);
254
+ }
255
+
256
+ // eslint-disable-next-line react-hooks/exhaustive-deps
257
+ }, [editor]);
258
+ var useBothChanges = useCallback(function (element) {
259
+ // delete element marks
260
+ var path = findPath(editor, element);
261
+ deleteNodeMark(editor, path, element, REBASE_MARKS);
262
+
263
+ // delete next element marks
264
+ var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
265
+ var nextElement = getNode(editor, nextElementPath);
266
+ deleteNodeMark(editor, nextElementPath, nextElement, REBASE_MARKS);
267
+ if (element.type === ELEMENT_TYPE.LIST_ITEM) {
268
+ updateParentNodeByPath(path);
269
+ }
270
+
271
+ // eslint-disable-next-line react-hooks/exhaustive-deps
272
+ }, [editor]);
273
+ var element = props.element;
274
+ var rebaseType = element[REBASE_MARK_KEY.REBASE_TYPE];
275
+ if (!rebaseType) {
276
+ return /*#__PURE__*/React.createElement(CustomElement, props);
277
+ }
278
+ if (rebaseType === REBASE_TYPE.MODIFY_DELETE) {
279
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
280
+ className: "w-100 d-flex sdoc-rebase-btn-group",
281
+ contentEditable: false
282
+ }, /*#__PURE__*/React.createElement("div", {
283
+ className: "sdoc-rebase-btn",
284
+ onClick: function onClick() {
285
+ return deleteMark(element);
286
+ }
287
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
288
+ className: "mr-2 ml-2"
289
+ }, '|'), /*#__PURE__*/React.createElement("div", {
290
+ className: "sdoc-rebase-btn",
291
+ onClick: function onClick() {
292
+ return deleteElement(element);
293
+ }
294
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
295
+ className: "mr-2 ml-2"
296
+ }, '|'), /*#__PURE__*/React.createElement("div", {
297
+ className: "sdoc-rebase-btn",
298
+ onClick: function onClick() {
299
+ return deleteMark(element);
300
+ }
301
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
302
+ className: "w-100 sdoc-rebase-current-changes-start",
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",
309
+ contentEditable: false
310
+ }, '======='), /*#__PURE__*/React.createElement("div", {
311
+ className: "w-100 sdoc-rebase-incoming-changes-end",
312
+ contentEditable: false
313
+ }, '>>>>>>>'));
314
+ }
315
+ if (rebaseType === REBASE_TYPE.DELETE_MODIFY) {
316
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
317
+ className: "w-100 d-flex sdoc-rebase-btn-group",
318
+ contentEditable: false
319
+ }, /*#__PURE__*/React.createElement("div", {
320
+ className: "sdoc-rebase-btn",
321
+ onClick: function onClick() {
322
+ return deleteElement(element);
323
+ }
324
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
325
+ className: "mr-2 ml-2"
326
+ }, '|'), /*#__PURE__*/React.createElement("div", {
327
+ className: "sdoc-rebase-btn",
328
+ onClick: function onClick() {
329
+ return deleteMark(element);
330
+ }
331
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
332
+ className: "mr-2 ml-2"
333
+ }, '|'), /*#__PURE__*/React.createElement("div", {
334
+ className: "sdoc-rebase-btn",
335
+ onClick: function onClick() {
336
+ return deleteMark(element);
337
+ }
338
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
339
+ className: "w-100 sdoc-rebase-current-changes-start",
340
+ contentEditable: false
341
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
342
+ className: "w-100",
343
+ contentEditable: false
344
+ }, '======='), /*#__PURE__*/React.createElement("div", {
345
+ className: "w-100 sdoc-rebase-incoming-changes",
346
+ contentEditable: false
347
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
348
+ className: "w-100 sdoc-rebase-incoming-changes-end",
349
+ contentEditable: false
350
+ }, '>>>>>>>'));
351
+ }
352
+ if (rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
353
+ if (element[REBASE_MARK_KEY.ORIGIN] === REBASE_ORIGIN.OTHER) {
354
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
355
+ className: "w-100 d-flex sdoc-rebase-btn-group",
356
+ contentEditable: false
357
+ }, /*#__PURE__*/React.createElement("div", {
358
+ className: "sdoc-rebase-btn",
359
+ onClick: function onClick() {
360
+ return useMasterChanges(element);
361
+ }
362
+ }, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
363
+ className: "mr-2 ml-2"
364
+ }, '|'), /*#__PURE__*/React.createElement("div", {
365
+ className: "sdoc-rebase-btn",
366
+ onClick: function onClick() {
367
+ return useCurrentChanges(element);
368
+ }
369
+ }, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
370
+ className: "mr-2 ml-2"
371
+ }, '|'), /*#__PURE__*/React.createElement("div", {
372
+ className: "sdoc-rebase-btn",
373
+ onClick: function onClick() {
374
+ return useBothChanges(element);
375
+ }
376
+ }, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
377
+ className: "w-100 sdoc-rebase-current-changes-start",
378
+ contentEditable: false
379
+ }, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
380
+ className: "w-100 sdoc-rebase-current-changes",
381
+ contentEditable: false
382
+ }, /*#__PURE__*/React.createElement(CustomElement, props)));
383
+ }
384
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
385
+ className: "w-100",
386
+ contentEditable: false
387
+ }, '======='), /*#__PURE__*/React.createElement("div", {
388
+ className: "w-100 sdoc-rebase-incoming-changes",
389
+ contentEditable: false
390
+ }, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
391
+ className: "w-100 sdoc-rebase-incoming-changes-end",
392
+ contentEditable: false
393
+ }, '>>>>>>>'));
394
+ }
149
395
  return /*#__PURE__*/React.createElement(CustomElement, props);
150
396
 
151
397
  // const { element } = props;