@seafile/sdoc-editor 0.1.87 → 0.1.88

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 (46) hide show
  1. package/dist/assets/css/simple-editor.css +11 -0
  2. package/dist/basic-sdk/editor.js +12 -38
  3. package/dist/basic-sdk/extension/constants/color.js +2 -1
  4. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  5. package/dist/basic-sdk/extension/constants/index.js +23 -3
  6. package/dist/basic-sdk/extension/index.js +1 -2
  7. package/dist/basic-sdk/{comment → extension/menu}/color-menu/index.css +25 -1
  8. package/dist/basic-sdk/{comment → extension/menu}/color-menu/index.js +28 -14
  9. package/dist/basic-sdk/extension/menu/index.js +1 -2
  10. package/dist/basic-sdk/extension/menu/menu-item.js +1 -0
  11. package/dist/basic-sdk/extension/plugins/clear-format/helpers.js +56 -0
  12. package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +25 -0
  13. package/dist/{components/code-block-hover-menu → basic-sdk/extension/plugins/code-block/hover-menu}/index.js +1 -1
  14. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +1 -1
  15. package/dist/basic-sdk/extension/plugins/html/rules/code-block.js +1 -1
  16. package/dist/basic-sdk/extension/plugins/table/constants/index.js +2 -1
  17. package/dist/basic-sdk/extension/plugins/table/index.js +2 -3
  18. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.css +7 -0
  19. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +3 -2
  20. package/dist/basic-sdk/extension/plugins/table/menu/index.js +2 -2
  21. package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.js +14 -10
  22. package/dist/basic-sdk/extension/plugins/table/render/hooks.js +51 -1
  23. package/dist/basic-sdk/extension/plugins/table/render/index.css +0 -34
  24. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +17 -5
  25. package/dist/basic-sdk/extension/plugins/table/render/table-root.js +12 -3
  26. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +73 -73
  27. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +3 -0
  28. package/dist/basic-sdk/extension/toolbar/index.js +3 -0
  29. package/dist/basic-sdk/highlight-decorate/setNodeToDecorations.js +1 -1
  30. package/package.json +1 -1
  31. package/public/locales/en/sdoc-editor.json +4 -1
  32. package/public/locales/zh-CN/sdoc-editor.json +4 -1
  33. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  34. package/public/media/sdoc-editor-font/iconfont.svg +6 -0
  35. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  36. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  37. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  38. package/public/media/sdoc-editor-font.css +18 -6
  39. package/dist/basic-sdk/extension/menu/context-menu/index.css +0 -1
  40. package/dist/basic-sdk/extension/menu/context-menu/index.js +0 -38
  41. /package/dist/{components/modal-portal.js → basic-sdk/extension/commons/modal-portal/index.js} +0 -0
  42. /package/dist/basic-sdk/{comment → extension/menu}/color-menu/color-item.js +0 -0
  43. /package/dist/{components/code-block-hover-menu → basic-sdk/extension/plugins/code-block/hover-menu}/index.css +0 -0
  44. /package/dist/basic-sdk/{utils → extension/plugins/code-block}/prismjs.js +0 -0
  45. /package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/index.css +0 -0
  46. /package/dist/basic-sdk/extension/plugins/table/menu/{context-menu → table-context-menu}/insert-table-element.js +0 -0
@@ -29,3 +29,14 @@
29
29
  .sdoc-editor-page-header .doc-state {
30
30
  font-size: 0.8125rem;
31
31
  }
32
+
33
+ /* reset common css */
34
+ .sdoc-editor-page-wrapper .dropdown-item,
35
+ .sdoc-context-menu .dropdown-item {
36
+ color: #212529;
37
+ }
38
+
39
+ .sdoc-editor-page-wrapper .dropdown-item:hover,
40
+ .sdoc-context-menu .dropdown-item:hover {
41
+ color: #fff;
42
+ }
@@ -1,22 +1,21 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
4
- import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextMenu } from './extension';
4
+ import defaultEditor, { renderLeaf, renderElement, Toolbar } from './extension';
5
5
  import { focusEditor, getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
6
6
  import { withSocketIO } from './socket';
7
7
  import withNodeId from './node-id';
8
8
  import SDocOutline from './outline';
9
9
  import EventProxy from './utils/event-handler';
10
10
  import { useCursors } from './cursor/use-cursors';
11
- import EventBus from './utils/event-bus';
12
11
  import { EXTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../constants';
13
- import { isAllInTable } from './extension/plugins/table/helpers';
14
12
  import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
15
13
  import { ScrollContext } from './hooks/use-scroll-context';
16
14
  import CommentContextProvider from './comment/comment-context-provider';
17
15
  import CommentWrapper from './comment';
18
16
  import { usePipDecorate } from './decorates';
19
17
  import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
18
+ import EventBus from './utils/event-bus';
20
19
  import './assets/css/layout.css';
21
20
  import './assets/css/sdoc-editor-plugins.css';
22
21
  import './assets/css/dropdown-menu.css';
@@ -39,14 +38,6 @@ var SDocEditor = function SDocEditor(_ref) {
39
38
  _useState2 = _slicedToArray(_useState, 2),
40
39
  slateValue = _useState2[0],
41
40
  setSlateValue = _useState2[1];
42
- var _useState3 = useState(false),
43
- _useState4 = _slicedToArray(_useState3, 2),
44
- isShowContextMenu = _useState4[0],
45
- setContextMenu = _useState4[1];
46
- var _useState5 = useState({}),
47
- _useState6 = _slicedToArray(_useState5, 2),
48
- menuPosition = _useState6[0],
49
- setMenuPosition = _useState6[1];
50
41
  var _useCursors = useCursors(editor),
51
42
  cursors = _useCursors.cursors;
52
43
  var scrollRef = useRef(null);
@@ -58,7 +49,6 @@ var SDocEditor = function SDocEditor(_ref) {
58
49
  var eventProxy = useMemo(function () {
59
50
  return new EventProxy(editor);
60
51
  }, []);
61
- var eventBus = EventBus.getInstance();
62
52
 
63
53
  // useMount: init socket connection
64
54
  useEffect(function () {
@@ -81,26 +71,14 @@ var SDocEditor = function SDocEditor(_ref) {
81
71
  };
82
72
  // eslint-disable-next-line react-hooks/exhaustive-deps
83
73
  }, []);
84
- var onContextMenu = useCallback(function (event) {
85
- if (isAllInTable(editor)) {
86
- event.preventDefault();
87
- var contextMenuPosition = {
88
- left: event.clientX,
89
- top: event.clientY
90
- };
91
- setContextMenu(true);
92
- setMenuPosition(contextMenuPosition);
93
- }
94
- // eslint-disable-next-line react-hooks/exhaustive-deps
95
- }, []);
96
74
  var onChange = useCallback(function (slateValue) {
97
75
  setSlateValue(slateValue);
98
- setContextMenu(false);
99
76
  // eslint-disable-next-line react-hooks/exhaustive-deps
100
77
  }, []);
101
78
  var onMouseDown = useCallback(function (event) {
102
79
  if (event.button === 0) {
103
80
  editor.reSetTableSelectedRange();
81
+ var eventBus = EventBus.getInstance();
104
82
  eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
105
83
  }
106
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -195,10 +173,10 @@ var SDocEditor = function SDocEditor(_ref) {
195
173
  eventProxy.onKeyDown(event);
196
174
  // eslint-disable-next-line react-hooks/exhaustive-deps
197
175
  }, []);
198
- var _useState7 = useState({}),
199
- _useState8 = _slicedToArray(_useState7, 2),
200
- containerStyle = _useState8[0],
201
- setContainerStyle = _useState8[1];
176
+ var _useState3 = useState({}),
177
+ _useState4 = _slicedToArray(_useState3, 2),
178
+ containerStyle = _useState4[0],
179
+ setContainerStyle = _useState4[1];
202
180
  var handleWindowResize = useCallback(function () {
203
181
  var rect = scrollRef.current.getBoundingClientRect();
204
182
  var articleRect = articleRef.current.getBoundingClientRect();
@@ -217,10 +195,10 @@ var SDocEditor = function SDocEditor(_ref) {
217
195
  window.removeEventListener('resize', handleWindowResize);
218
196
  };
219
197
  }, [handleWindowResize]);
220
- var _useState9 = useState(0),
221
- _useState10 = _slicedToArray(_useState9, 2),
222
- scrollLeft = _useState10[0],
223
- setScrollLeft = _useState10[1];
198
+ var _useState5 = useState(0),
199
+ _useState6 = _slicedToArray(_useState5, 2),
200
+ scrollLeft = _useState6[0],
201
+ setScrollLeft = _useState6[1];
224
202
  var onWrapperScroll = useCallback(function (event) {
225
203
  var scrollLeft = event.target.scrollLeft;
226
204
  setScrollLeft(scrollLeft);
@@ -262,13 +240,9 @@ var SDocEditor = function SDocEditor(_ref) {
262
240
  renderElement: renderElement,
263
241
  renderLeaf: renderLeaf,
264
242
  onKeyDown: onKeyDown,
265
- onContextMenu: onContextMenu,
266
243
  onMouseDown: onMouseDown,
267
244
  decorate: decorate,
268
245
  onCut: eventProxy.onCut
269
- })), /*#__PURE__*/React.createElement(CommentWrapper, null))))))))), isShowContextMenu && /*#__PURE__*/React.createElement(ContextMenu, {
270
- editor: editor,
271
- contextMenuPosition: menuPosition
272
- }));
246
+ })), /*#__PURE__*/React.createElement(CommentWrapper, null))))))))));
273
247
  };
274
248
  export default SDocEditor;
@@ -262,4 +262,5 @@ export var STANDARD_COLORS = [{
262
262
  }];
263
263
 
264
264
  // Initialize the most recently used colors
265
- export var DEFAULT_RECENT_USED_COLORS = new Array(10).fill('');
265
+ export var DEFAULT_RECENT_USED_COLORS = new Array(10).fill('');
266
+ export var DEFAULT_FONT_COLOR = '#333333';
@@ -5,6 +5,8 @@ export var UNDERLINE = 'underline';
5
5
  export var STRIKETHROUGH = 'strikethrough';
6
6
  export var SUPERSCRIPT = 'superscript';
7
7
  export var SUBSCRIPT = 'subscript';
8
+ export var COLOR = 'color';
9
+ export var HIGHLIGHT_COLOR = 'highlight-color';
8
10
  export var HEADER = 'header';
9
11
  export var HEADER1 = 'header1';
10
12
  export var HEADER2 = 'header2';
@@ -35,4 +37,5 @@ export var BOLD_ITALIC = 'bold-italic';
35
37
  export var TEXT_ALIGN = 'text-align';
36
38
  export var ALIGN_LEFT = 'align-left';
37
39
  export var ALIGN_RIGHT = 'align-right';
38
- export var ALIGN_CENTER = 'align-center';
40
+ export var ALIGN_CENTER = 'align-center';
41
+ export var CLEAR_FORMAT = 'clear-format';
@@ -2,9 +2,9 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
3
3
  // extension plugin
4
4
  import * as ELEMENT_TYPE from './element-type';
5
- import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER } from './element-type';
5
+ import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, CLEAR_FORMAT, COLOR, HIGHLIGHT_COLOR } from './element-type';
6
6
  import KEYBOARD from './keyboard';
7
- import { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_COLORS } from './color';
7
+ import { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_COLORS, DEFAULT_FONT_COLOR } from './color';
8
8
 
9
9
  // history
10
10
  export var UNDO = 'undo';
@@ -66,6 +66,21 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
66
66
  iconClass: 'sdocfont sdoc-underline',
67
67
  text: 'Underline',
68
68
  type: 'UNDERLINE'
69
+ }, {
70
+ id: "sdoc-".concat(HIGHLIGHT_COLOR),
71
+ iconClass: 'sdocfont sdoc-highlight-color',
72
+ text: 'Highlight_color',
73
+ type: HIGHLIGHT_COLOR,
74
+ isColor: true,
75
+ localStorageKey: 'sdoc-recent-used-highlight-colors'
76
+ }, {
77
+ id: "sdoc-font-".concat(COLOR),
78
+ iconClass: 'sdocfont sdoc-font-color',
79
+ text: 'Font_color',
80
+ type: COLOR,
81
+ defaultColor: DEFAULT_FONT_COLOR,
82
+ isColor: true,
83
+ localStorageKey: 'sdoc-recent-used-font-colors'
69
84
  }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE_MORE, [{
70
85
  id: STRIKETHROUGH,
71
86
  iconClass: 'sdocfont sdoc-strikethrough',
@@ -107,6 +122,10 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
107
122
  id: "sdoc_".concat(BG_COLOR),
108
123
  iconClass: 'sdocfont sdoc-bg-color',
109
124
  text: 'Background_color'
125
+ }), _defineProperty(_MENUS_CONFIG_MAP, CLEAR_FORMAT, {
126
+ id: "sdoc_".concat(CLEAR_FORMAT),
127
+ iconClass: 'sdocfont sdoc-format-clear',
128
+ text: 'Clear_format'
110
129
  }), _MENUS_CONFIG_MAP);
111
130
  export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'Header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'Header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'Header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'Header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'Header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'Header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'Paragraph'), _HEADER_TITLE_MAP);
112
131
  export var DIFF_TYPE = {
@@ -129,4 +148,5 @@ export var ADDED_STYLE = {
129
148
  };
130
149
  export var HEADER_TYPE_ARRAY = ['header1', 'header2', 'header3', 'header4', 'header5', 'header6'];
131
150
  export var LIST_TYPE_ARRAY = ['unordered_list', 'ordered_list'];
132
- export { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD, DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_COLORS };
151
+ export var TRANSPARENT = 'transparent';
152
+ export { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD, DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_COLORS, CLEAR_FORMAT, DEFAULT_FONT_COLOR };
@@ -5,7 +5,6 @@ import Plugins from './plugins';
5
5
  import renderElement from './render/render-element';
6
6
  import renderLeaf from './render/render-leaf';
7
7
  import Toolbar from './toolbar';
8
- import { ContextMenu } from './menu';
9
8
  var baseEditor = withHistory(withReact(createEditor()));
10
9
  var defaultEditor = Plugins.reduce(function (editor, pluginItem) {
11
10
  var withPlugin = pluginItem.editorPlugin;
@@ -15,4 +14,4 @@ var defaultEditor = Plugins.reduce(function (editor, pluginItem) {
15
14
  return editor;
16
15
  }, baseEditor);
17
16
  export default defaultEditor;
18
- export { renderLeaf, renderElement, Toolbar, ContextMenu };
17
+ export { renderLeaf, renderElement, Toolbar };
@@ -1,3 +1,23 @@
1
+ .menu-group .sdoc-color-menu {
2
+ width: 48px;
3
+ display: flex;
4
+ align-items: center;
5
+ justify-content: center;
6
+ }
7
+
8
+ .menu-group .sdoc-color-menu.disabled {
9
+ width: 30px;
10
+ }
11
+
12
+ .menu-group .sdoc-color-menu.disabled .sdoc-color-toggle-icon {
13
+ display: none;
14
+ }
15
+
16
+ .sdoc-color-menu .sdoc-color-toggle-icon {
17
+ font-size: 14px;
18
+ transform: scale(.8);
19
+ }
20
+
1
21
  .sdoc-color-menu .sdoc-color-icon {
2
22
  font-size: 12px !important;
3
23
  height: 12px;
@@ -12,6 +32,10 @@
12
32
  border: 1px solid rgba(0, 0, 0, .08);
13
33
  }
14
34
 
35
+ .sdoc-color-menu-popover .popover {
36
+ left: -26px !important;
37
+ }
38
+
15
39
  .sdoc-color-menu-popover .sdoc-color-dropdown-menu {
16
40
  width: 251px;
17
41
  padding: 0 0 12px 0;
@@ -87,7 +111,7 @@
87
111
  .sdoc-color-menu-popover .sdoc-more-colors {
88
112
  display: flex;
89
113
  align-items: center;
90
- justify-content: baseline;
114
+ justify-content: space-between;
91
115
  height: 30px;
92
116
  font-size: 12px;
93
117
  padding: 0 12px;
@@ -2,11 +2,11 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useRef, useState } from 'react';
3
3
  import { withTranslation } from 'react-i18next';
4
4
  import classnames from 'classnames';
5
- import { UncontrolledPopover } from 'reactstrap';
5
+ import { UncontrolledPopover, UncontrolledTooltip } from 'reactstrap';
6
6
  import { ChromePicker } from 'react-color';
7
- import { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_COLORS } from '../../extension/constants';
8
- import { LocalStorage } from '../../../utils';
9
- import { eventStopPropagation } from '../../utils/mouse-event';
7
+ import { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_COLORS, TRANSPARENT } from '../../constants';
8
+ import { LocalStorage } from '../../../../utils';
9
+ import { eventStopPropagation } from '../../../utils/mouse-event';
10
10
  import ColorItem from './color-item';
11
11
  import './index.css';
12
12
  var ColorMenu = function ColorMenu(_ref) {
@@ -17,7 +17,10 @@ var ColorMenu = function ColorMenu(_ref) {
17
17
  disabled = _ref.disabled,
18
18
  t = _ref.t,
19
19
  setColor = _ref.setColor,
20
- localStorageKey = _ref.localStorageKey;
20
+ localStorageKey = _ref.localStorageKey,
21
+ text = _ref.text,
22
+ defaultColorTip = _ref.defaultColorTip,
23
+ defaultColor = _ref.defaultColor;
21
24
  var popoverRef = useRef(null);
22
25
  var moreColorsPopoverRef = useRef(null);
23
26
  var _useState = useState(LocalStorage.getItem(localStorageKey, DEFAULT_RECENT_USED_COLORS)),
@@ -34,9 +37,9 @@ var ColorMenu = function ColorMenu(_ref) {
34
37
  setPickerShow = _useState6[1];
35
38
  var onSetColor = useCallback(function (color) {
36
39
  var shouldClose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
37
- var validColor = color || 'transparent';
40
+ var validColor = color || TRANSPARENT;
38
41
  setColor(validColor);
39
- if (validColor !== 'transparent' && recentUsedColors[0] !== validColor) {
42
+ if (validColor !== TRANSPARENT && recentUsedColors[0] !== validColor) {
40
43
  var newRecentUsedColors = recentUsedColors.slice(0, 9);
41
44
  newRecentUsedColors.unshift(validColor);
42
45
  LocalStorage.setItem(localStorageKey, newRecentUsedColors);
@@ -82,6 +85,7 @@ var ColorMenu = function ColorMenu(_ref) {
82
85
  // eslint-disable-next-line react-hooks/exhaustive-deps
83
86
  }, []);
84
87
  var validClassName = classnames(className, 'sdoc-color-menu', {
88
+ 'disabled': disabled,
85
89
  'rich-icon-btn d-flex': isRichEditor,
86
90
  'rich-icon-btn-disabled': isRichEditor && disabled,
87
91
  'rich-icon-btn-hover': isRichEditor && !disabled,
@@ -93,23 +97,33 @@ var ColorMenu = function ColorMenu(_ref) {
93
97
 
94
98
  // eslint-disable-next-line react-hooks/exhaustive-deps
95
99
  }, [recentUsedColors]);
100
+ var buttonId = "button-".concat(id);
96
101
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
97
102
  type: "button",
98
- className: validClassName
103
+ className: validClassName,
104
+ id: buttonId,
105
+ disabled: disabled
99
106
  }, /*#__PURE__*/React.createElement("div", {
100
- className: "d-flex flex-column justify-content-center h-100 mr-1 pt-1",
107
+ className: classnames('d-flex flex-column justify-content-center h-100 pt-1', {
108
+ 'mr-1': !disabled
109
+ }),
101
110
  onClick: setRecentUsedColor
102
111
  }, /*#__PURE__*/React.createElement("i", {
103
112
  className: classnames(iconClass, 'sdoc-color-icon')
104
113
  }), /*#__PURE__*/React.createElement("div", {
105
114
  className: "recent-used-color",
106
115
  style: {
107
- backgroundColor: recentUsedColors[0] || 'transparent'
116
+ backgroundColor: recentUsedColors[0] || TRANSPARENT
108
117
  }
109
118
  })), /*#__PURE__*/React.createElement("i", {
110
119
  id: id,
111
- className: "sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down')
112
- })), /*#__PURE__*/React.createElement(UncontrolledPopover, {
120
+ className: "sdoc-color-toggle-icon sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down')
121
+ })), text && /*#__PURE__*/React.createElement(UncontrolledTooltip, {
122
+ target: buttonId,
123
+ fade: false,
124
+ placement: "bottom",
125
+ delay: 0
126
+ }, t(text)), !disabled && /*#__PURE__*/React.createElement(UncontrolledPopover, {
113
127
  target: id,
114
128
  className: "sdoc-color-menu-popover",
115
129
  trigger: "legacy",
@@ -127,9 +141,9 @@ var ColorMenu = function ColorMenu(_ref) {
127
141
  }, /*#__PURE__*/React.createElement("div", {
128
142
  className: "sdoc-color-no-color-content",
129
143
  onClick: function onClick() {
130
- return onSetColor();
144
+ return onSetColor(defaultColor);
131
145
  }
132
- }, t('No_color'))), /*#__PURE__*/React.createElement("div", {
146
+ }, defaultColorTip || t('No_color'))), /*#__PURE__*/React.createElement("div", {
133
147
  className: "sdoc-color-default-colors-container",
134
148
  onClick: setColorProxy
135
149
  }, DEFAULT_COLORS.map(function (color, index) {
@@ -1,5 +1,4 @@
1
1
  import MenuGroup from './menu-group';
2
2
  import MenuItem from './menu-item';
3
- import ContextMenu from './context-menu';
4
3
  import './menu.css';
5
- export { MenuGroup, MenuItem, ContextMenu };
4
+ export { MenuGroup, MenuItem };
@@ -68,6 +68,7 @@ var MenuItem = /*#__PURE__*/function (_React$Component) {
68
68
  target: id,
69
69
  isOpen: isShowToolTip,
70
70
  delay: delay,
71
+ fade: false,
71
72
  placement: "bottom",
72
73
  toggle: this.toggle
73
74
  }, t(text)));
@@ -0,0 +1,56 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import { Editor, Text } from '@seafile/slate';
4
+ import { CODE_BLOCK, CODE_LINE } from '../../constants';
5
+ import { getNodeType } from '../../core';
6
+ export var isMenuDisabled = function isMenuDisabled(editor) {
7
+ if (editor.selection == null) return true;
8
+ var _Editor$nodes = Editor.nodes(editor, {
9
+ match: function match(n) {
10
+ var type = getNodeType(n);
11
+ if ([CODE_BLOCK, CODE_LINE].includes(type)) return true; // code-block
12
+ if (Editor.isVoid(editor, n)) return true; // void node
13
+
14
+ return false;
15
+ },
16
+ universal: true
17
+ }),
18
+ _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
19
+ match = _Editor$nodes2[0];
20
+ if (match) return true;
21
+ return false;
22
+ };
23
+ var removeMarks = function removeMarks(editor, textNode) {
24
+ // Iterate text node properties, clearing styles
25
+ var keys = Object.keys(textNode);
26
+ keys.forEach(function (key) {
27
+ if (key === 'text') {
28
+ // Keep only the text attribute (Text attributes are necessary)
29
+ return;
30
+ }
31
+ // All other attributes are deleted
32
+ Editor.removeMark(editor, key);
33
+ });
34
+ };
35
+ export var clearStyles = function clearStyles(editor) {
36
+ var nodeEntries = Editor.nodes(editor, {
37
+ match: function match(n) {
38
+ return Text.isText(n);
39
+ },
40
+ universal: true
41
+ });
42
+ var _iterator = _createForOfIteratorHelper(nodeEntries),
43
+ _step;
44
+ try {
45
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
46
+ var nodeEntry = _step.value;
47
+ // single text node
48
+ var n = nodeEntry[0];
49
+ removeMarks(editor, n);
50
+ }
51
+ } catch (err) {
52
+ _iterator.e(err);
53
+ } finally {
54
+ _iterator.f();
55
+ }
56
+ };
@@ -0,0 +1,25 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import React, { useCallback } from 'react';
3
+ import { CLEAR_FORMAT, MENUS_CONFIG_MAP } from '../../../constants';
4
+ import { MenuItem } from '../../../menu';
5
+ import { isMenuDisabled, clearStyles } from '../helpers';
6
+ var menuConfig = MENUS_CONFIG_MAP[CLEAR_FORMAT];
7
+ var ClearFormatMenu = function ClearFormatMenu(_ref) {
8
+ var isRichEditor = _ref.isRichEditor,
9
+ className = _ref.className,
10
+ editor = _ref.editor;
11
+ var onMouseDown = useCallback(function () {
12
+ clearStyles(editor);
13
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14
+ }, []);
15
+ var props = _objectSpread(_objectSpread({
16
+ isRichEditor: isRichEditor,
17
+ className: className
18
+ }, menuConfig), {}, {
19
+ disabled: isMenuDisabled(editor),
20
+ isActive: false,
21
+ 'onMouseDown': onMouseDown
22
+ });
23
+ return /*#__PURE__*/React.createElement(MenuItem, props);
24
+ };
25
+ export default ClearFormatMenu;
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useState } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import { withTranslation } from 'react-i18next';
5
- import { genCodeLangs } from '../../basic-sdk/utils/prismjs';
5
+ import { genCodeLangs } from '../prismjs';
6
6
  import './index.css';
7
7
  var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
8
8
  var style = _ref.style,
@@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useState, useRef } from 'react';
4
4
  import { ReactEditor, useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
5
  import { Transforms } from '@seafile/slate';
6
6
  import { useScrollContext } from '../../../hooks/use-scroll-context';
7
- import CodeBlockHoverMenu from '../../../../components/code-block-hover-menu';
7
+ import CodeBlockHoverMenu from './hover-menu';
8
8
  import { setClipboardData } from './helpers';
9
9
  import '../../../assets/css/code-block.css';
10
10
  var CodeBlock = function CodeBlock(_ref) {
@@ -1,6 +1,6 @@
1
1
  import slugid from 'slugid';
2
2
  import { CODE_BLOCK, CODE_LINE } from '../../../constants';
3
- import { genCodeLangs } from '../../../../utils/prismjs';
3
+ import { genCodeLangs } from '../../code-block/prismjs';
4
4
  var codeBlockRule = function codeBlockRule(element, parseChild) {
5
5
  var nodeName = element.nodeName,
6
6
  childNodes = element.childNodes;
@@ -20,4 +20,5 @@ export var TABLE_ELEMENT_SPAN = (_TABLE_ELEMENT_SPAN = {}, _defineProperty(_TABL
20
20
  export var TABLE_ELEMENT_POSITION = {
21
21
  AFTER: 'after',
22
22
  BEFORE: 'before'
23
- };
23
+ };
24
+ export var SELECTED_TABLE_CELL_BG_COLOR = '#dee8fe';
@@ -1,5 +1,5 @@
1
1
  import { TABLE } from '../../constants';
2
- import { TableMenu, ContextMenu } from './menu';
2
+ import { TableMenu } from './menu';
3
3
  import Table from './model';
4
4
  import withTable from './plugin';
5
5
  import { renderTable, renderTableRow, renderTableCell } from './render-elem';
@@ -9,7 +9,6 @@ var TablePlugin = {
9
9
  model: Table,
10
10
  editorMenus: [TableMenu],
11
11
  editorPlugin: withTable,
12
- renderElements: [renderTable, renderTableRow, renderTableCell],
13
- contextMenu: ContextMenu
12
+ renderElements: [renderTable, renderTableRow, renderTableCell]
14
13
  };
15
14
  export default TablePlugin;
@@ -1,3 +1,10 @@
1
+ .sdoc-table-menu-group.menu-group .menu-group-item:not(.sdoc-remove-table) {
2
+ width: 48px;
3
+ display: flex;
4
+ align-items: center;
5
+ justify-content: center;
6
+ }
7
+
1
8
  .sdoc-table-menu-group .sdoc-drop-down,
2
9
  .sdoc-table-menu-group .sdoc-caret-up {
3
10
  transform: scale(.8);
@@ -6,12 +6,13 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
6
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
7
7
  import React, { Component } from 'react';
8
8
  import { withTranslation } from 'react-i18next';
9
+ import classnames from 'classnames';
9
10
  import { MenuGroup, MenuItem } from '../../../../menu';
10
11
  import CommonMenu from './common-menu';
11
12
  import { MENUS_CONFIG_MAP, REMOVE_TABLE, BG_COLOR } from '../../../../constants';
12
13
  import { setCellStyle, insertTableElement, removeTableElement, isAllInTable } from '../../helpers';
13
14
  import { TABLE_ELEMENT } from '../../constants';
14
- import ColorMenu from '../../../../../comment/color-menu';
15
+ import ColorMenu from '../../../../menu/color-menu';
15
16
  import './index.css';
16
17
  var ActiveTableMenu = /*#__PURE__*/function (_Component) {
17
18
  _inherits(ActiveTableMenu, _Component);
@@ -116,7 +117,7 @@ var ActiveTableMenu = /*#__PURE__*/function (_Component) {
116
117
  var menuConfig = MENUS_CONFIG_MAP[REMOVE_TABLE];
117
118
  var props = _objectSpread(_objectSpread({
118
119
  isRichEditor: isRichEditor,
119
- className: className,
120
+ className: classnames(className, 'sdoc-remove-table menu-group-item'),
120
121
  disabled: false,
121
122
  isActive: false
122
123
  }, menuConfig), {}, {
@@ -1,4 +1,4 @@
1
1
  import TableMenu from './table-menu';
2
2
  import ActiveTableMenu from './active-table-menu';
3
- import ContextMenu from './context-menu';
4
- export { TableMenu, ActiveTableMenu, ContextMenu };
3
+ import TableContextMenu from './table-context-menu';
4
+ export { TableMenu, ActiveTableMenu, TableContextMenu };
@@ -11,13 +11,14 @@ import InsertTableElement from './insert-table-element';
11
11
  import { getSelectedNodeByType } from '../../../../core';
12
12
  import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../constants';
13
13
  import { insertTableElement, removeTableElement } from '../../helpers';
14
+ import ModalPortal from '../../../../commons/modal-portal';
14
15
  import './index.css';
15
- var ContextMenu = /*#__PURE__*/function (_React$Component) {
16
- _inherits(ContextMenu, _React$Component);
17
- var _super = _createSuper(ContextMenu);
18
- function ContextMenu(props) {
16
+ var TableContextMenu = /*#__PURE__*/function (_React$Component) {
17
+ _inherits(TableContextMenu, _React$Component);
18
+ var _super = _createSuper(TableContextMenu);
19
+ function TableContextMenu(props) {
19
20
  var _this;
20
- _classCallCheck(this, ContextMenu);
21
+ _classCallCheck(this, TableContextMenu);
21
22
  _this = _super.call(this, props);
22
23
  _this.updateMenuPosition = function () {
23
24
  var menuHeight = _this.menu.offsetHeight;
@@ -61,7 +62,7 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
61
62
  _this.position = null;
62
63
  return _this;
63
64
  }
64
- _createClass(ContextMenu, [{
65
+ _createClass(TableContextMenu, [{
65
66
  key: "componentDidMount",
66
67
  value: function componentDidMount() {
67
68
  this.position = this.props.contextMenuPosition;
@@ -88,6 +89,7 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
88
89
  var contextStyle = this.state.contextStyle;
89
90
  var editor = this.props.editor;
90
91
  var currentTable = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE);
92
+ if (!currentTable) return null;
91
93
  var currentRow = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_ROW);
92
94
  var currentRowsCount = currentTable.children.length;
93
95
  var currentColumnsCount = currentRow.children.length;
@@ -96,7 +98,9 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
96
98
  var selectedCols = tableSelectedRange.maxColIndex - tableSelectedRange.minColIndex + 1;
97
99
  var canAddRowsCount = currentRowsCount + selectedRows > TABLE_MAX_ROWS ? TABLE_MAX_ROWS - currentRowsCount : selectedRows;
98
100
  var canAddColsCount = currentColumnsCount + selectedCols > TABLE_MAX_COLUMNS ? TABLE_MAX_COLUMNS - currentColumnsCount : selectedCols;
99
- return /*#__PURE__*/React.createElement("div", {
101
+ return /*#__PURE__*/React.createElement(ModalPortal, {
102
+ className: "sdoc-context-menu"
103
+ }, /*#__PURE__*/React.createElement("div", {
100
104
  style: contextStyle,
101
105
  ref: function ref(_ref) {
102
106
  return _this2.menu = _ref;
@@ -128,9 +132,9 @@ var ContextMenu = /*#__PURE__*/function (_React$Component) {
128
132
  insertTableElement: this.insertTableElement
129
133
  }), /*#__PURE__*/React.createElement("div", {
130
134
  className: 'seafile-divider dropdown-divider'
131
- }), this.renderRemoveBtn(TABLE_ELEMENT.ROW, 'Delete_row'), this.renderRemoveBtn(TABLE_ELEMENT.COLUMN, 'Delete_column'), this.renderRemoveBtn(TABLE_ELEMENT.TABLE, 'Delete_table'));
135
+ }), this.renderRemoveBtn(TABLE_ELEMENT.ROW, 'Delete_row'), this.renderRemoveBtn(TABLE_ELEMENT.COLUMN, 'Delete_column'), this.renderRemoveBtn(TABLE_ELEMENT.TABLE, 'Delete_table')));
132
136
  }
133
137
  }]);
134
- return ContextMenu;
138
+ return TableContextMenu;
135
139
  }(React.Component);
136
- export default withTranslation('sdoc-editor')(ContextMenu);
140
+ export default withTranslation('sdoc-editor')(TableContextMenu);
@@ -1,4 +1,6 @@
1
- import { createContext, useContext } from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { createContext, useCallback, useContext, useEffect, useState } from 'react';
3
+ import { useScrollContext } from '../../../../hooks/use-scroll-context';
2
4
  export var TableRootContext = createContext();
3
5
  export var useTableRootContext = function useTableRootContext() {
4
6
  return useContext(TableRootContext);
@@ -18,4 +20,52 @@ export var useSettingSelectRangeContext = function useSettingSelectRangeContext(
18
20
  export var TableRootScrollLeftContext = createContext();
19
21
  export var useTableRootScrollLeftContext = function useTableRootScrollLeftContext() {
20
22
  return useContext(TableRootScrollLeftContext);
23
+ };
24
+ export var useContextMenu = function useContextMenu(tableScrollWrapper) {
25
+ var scrollRef = useScrollContext();
26
+ var _useState = useState(),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ isShowContextMenu = _useState2[0],
29
+ setShowContextMenu = _useState2[1];
30
+ var _useState3 = useState({}),
31
+ _useState4 = _slicedToArray(_useState3, 2),
32
+ menuPosition = _useState4[0],
33
+ setMenuPosition = _useState4[1];
34
+ var onContextMenu = useCallback(function (event) {
35
+ event.preventDefault();
36
+ var menuPosition = {
37
+ left: event.clientX,
38
+ top: event.clientY
39
+ };
40
+ setShowContextMenu(true);
41
+ setMenuPosition(menuPosition);
42
+ }, []);
43
+ var hideContextMenu = useCallback(function (e) {
44
+ if (isShowContextMenu) {
45
+ setShowContextMenu(false);
46
+ }
47
+ }, [isShowContextMenu]);
48
+ var hideByContextmenuEvent = useCallback(function (e) {
49
+ var table = tableScrollWrapper.current;
50
+ var clickIsInCurrentTable = table && table.contains(e.target) && table !== e.target;
51
+ if (!clickIsInCurrentTable) {
52
+ setShowContextMenu(false);
53
+ }
54
+ }, [tableScrollWrapper]);
55
+ useEffect(function () {
56
+ document.addEventListener('mousedown', hideContextMenu);
57
+ document.addEventListener('contextmenu', hideByContextmenuEvent, true);
58
+ scrollRef.current && scrollRef.current.addEventListener('scroll', hideContextMenu);
59
+ return function () {
60
+ document.removeEventListener('mousedown', hideContextMenu);
61
+ document.removeEventListener('contextmenu', hideByContextmenuEvent, true);
62
+ // eslint-disable-next-line react-hooks/exhaustive-deps
63
+ scrollRef.current && scrollRef.current.removeEventListener('scroll', hideContextMenu);
64
+ };
65
+ }, [hideContextMenu, hideByContextmenuEvent, scrollRef]);
66
+ return {
67
+ isShowContextMenu: isShowContextMenu,
68
+ menuPosition: menuPosition,
69
+ onContextMenu: onContextMenu
70
+ };
21
71
  };
@@ -65,43 +65,9 @@
65
65
 
66
66
  .sdoc-table-wrapper .cell-selected {
67
67
  caret-color: transparent;
68
- background-color: #fff4e6;
69
68
  position: relative;
70
69
  }
71
70
 
72
- .sdoc-table-wrapper .cell-light-height-top-border::before {
73
- content: '';
74
- position: absolute;
75
- top: -1px;
76
- left: 0;
77
- width: calc(100% + 1px);
78
- height: 2px;
79
- border-top: 1px double #ffa94d !important;
80
- }
81
-
82
- .sdoc-table-wrapper .cell-light-height-top-border:first-child:before {
83
- left: -1px;
84
- width: calc(100% + 2px);
85
- }
86
-
87
- .sdoc-table-wrapper .cell-light-height-bottom-border {
88
- border-bottom: 1px double #ffa94d !important;
89
- }
90
-
91
- .sdoc-table-wrapper .cell-light-height-left-border::after {
92
- content: '';
93
- position: absolute;
94
- top: 0px;
95
- left: -1px;
96
- width: 2px;
97
- height: calc(100% + 1px);
98
- border-left: 1px double #ffa94d !important;
99
- }
100
-
101
- .sdoc-table-wrapper .cell-light-height-right-border {
102
- border-right: 1px double #ffa94d !important;
103
- }
104
-
105
71
  .sdoc-table-wrapper .table-row-height-just {
106
72
  width: 100%;
107
73
  height: 5px;
@@ -1,12 +1,13 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import React from 'react';
2
+ import React, { useCallback } from 'react';
3
3
  import classnames from 'classnames';
4
4
  import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
+ import { Transforms } from '@seafile/slate';
5
6
  import ObjectUtils from '../../../../utils/object-utils';
6
7
  import { STYLE_KEY } from '../../../constants';
7
- import { findPath } from '../../../core';
8
+ import { findPath, focusEditor } from '../../../core';
8
9
  import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
9
- import { EMPTY_SELECTED_RANGE } from '../constants';
10
+ import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BG_COLOR } from '../constants';
10
11
  import { getTableColumns, getCellColumn, colorBlend } from '../helpers';
11
12
  var TableCell = function TableCell(_ref) {
12
13
  var attributes = _ref.attributes,
@@ -31,14 +32,24 @@ var TableCell = function TableCell(_ref) {
31
32
  var isSelectedLastCell = isSelected && cellIndex === maxColIndex;
32
33
  var isSelectedFirstRow = isSelected && rowIndex === minRowIndex;
33
34
  var isSelectedLastRow = isSelected && rowIndex === maxRowIndex;
35
+ var onContextMenu = useCallback(function (event) {
36
+ var path = findPath(editor, element);
37
+ focusEditor(editor, path);
38
+ Transforms.collapse(editor, {
39
+ edge: 'end'
40
+ });
41
+ }, [editor, element]);
34
42
  var style = attributes.style || {};
35
43
  if (ObjectUtils.hasProperty(element.style, STYLE_KEY.TEXT_ALIGN)) {
36
44
  style[STYLE_KEY.TEXT_ALIGN] = element.style[STYLE_KEY.TEXT_ALIGN];
37
45
  }
46
+ if (isSelected) {
47
+ style['backgroundColor'] = SELECTED_TABLE_CELL_BG_COLOR;
48
+ }
38
49
  if (ObjectUtils.hasProperty(element.style, STYLE_KEY.BG_COLOR)) {
39
50
  var color = element.style[STYLE_KEY.BG_COLOR];
40
51
  if (color && (color !== 'transparent' || color !== 'unset')) {
41
- style['backgroundColor'] = isSelected ? colorBlend('#fff4e6', color, 0.9) : color;
52
+ style['backgroundColor'] = isSelected ? colorBlend(SELECTED_TABLE_CELL_BG_COLOR, color, 0.9) : color;
42
53
  }
43
54
  }
44
55
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
@@ -55,7 +66,8 @@ var TableCell = function TableCell(_ref) {
55
66
  }),
56
67
  "data-id": element.id,
57
68
  "row-index": rowIndex,
58
- "cell-index": cellIndex
69
+ "cell-index": cellIndex,
70
+ onContextMenu: onContextMenu
59
71
  }), children);
60
72
  };
61
73
  function renderTableCell(props) {
@@ -3,7 +3,8 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useState, useRef, useCallback } from 'react';
4
4
  import classnames from 'classnames';
5
5
  import { useSlateStatic } from '@seafile/slate-react';
6
- import { TableRootContext, TableRootScrollLeftContext } from './hooks';
6
+ import { TableRootContext, TableRootScrollLeftContext, useContextMenu } from './hooks';
7
+ import { TableContextMenu } from '../menu';
7
8
  var TableRoot = function TableRoot(_ref) {
8
9
  var attributes = _ref.attributes,
9
10
  _ref$columns = _ref.columns,
@@ -21,6 +22,10 @@ var TableRoot = function TableRoot(_ref) {
21
22
  var onScroll = useCallback(function (event) {
22
23
  setScrollLeft(event.target.scrollLeft);
23
24
  }, []);
25
+ var _useContextMenu = useContextMenu(tableScrollWrapper),
26
+ isShowContextMenu = _useContextMenu.isShowContextMenu,
27
+ menuPosition = _useContextMenu.menuPosition,
28
+ onContextMenu = _useContextMenu.onContextMenu;
24
29
  return /*#__PURE__*/React.createElement(TableRootContext.Provider, {
25
30
  value: tableScrollWrapper.current
26
31
  }, /*#__PURE__*/React.createElement(TableRootScrollLeftContext.Provider, {
@@ -39,7 +44,11 @@ var TableRoot = function TableRoot(_ref) {
39
44
  'scroll-at-left': scrollLeft === 0
40
45
  }),
41
46
  ref: tableScrollWrapper,
42
- onScroll: onScroll
43
- }, children))));
47
+ onScroll: onScroll,
48
+ onContextMenu: onContextMenu
49
+ }, children)), isShowContextMenu && /*#__PURE__*/React.createElement(TableContextMenu, {
50
+ editor: editor,
51
+ contextMenuPosition: menuPosition
52
+ })));
44
53
  };
45
54
  export default TableRoot;
@@ -1,80 +1,80 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
- import React from 'react';
7
- import { TEXT_STYLE, TEXT_STYLE_MORE, MENUS_CONFIG_MAP } from '../../../constants';
2
+ import React, { useCallback } from 'react';
3
+ import { withTranslation } from 'react-i18next';
4
+ import { Editor } from '@seafile/slate';
5
+ import { TEXT_STYLE, TEXT_STYLE_MORE, MENUS_CONFIG_MAP, ELEMENT_TYPE } from '../../../constants';
8
6
  import { focusEditor } from '../../../core';
9
7
  import { MenuItem } from '../../../menu';
10
8
  import { getValue, isMenuDisabled, addMark, removeMark } from '../helpers';
11
9
  import MoreDropdown from '../../../../../components/more-dropdown';
12
- var TextStyleMenuList = /*#__PURE__*/function (_React$Component) {
13
- _inherits(TextStyleMenuList, _React$Component);
14
- var _super = _createSuper(TextStyleMenuList);
15
- function TextStyleMenuList() {
16
- var _this;
17
- _classCallCheck(this, TextStyleMenuList);
18
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
19
- args[_key] = arguments[_key];
10
+ import ColorMenu from '../../../menu/color-menu';
11
+ var TextStyleMenuList = function TextStyleMenuList(_ref) {
12
+ var editor = _ref.editor,
13
+ t = _ref.t,
14
+ isRichEditor = _ref.isRichEditor,
15
+ className = _ref.className;
16
+ var isActive = useCallback(function (type) {
17
+ var isMark = getValue(editor, type);
18
+ return !!isMark;
19
+
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ }, [editor]);
22
+ var isDisabled = useCallback(function () {
23
+ return isMenuDisabled(editor);
24
+
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, [editor]);
27
+ var onMouseDown = useCallback(function (event, type) {
28
+ event.preventDefault();
29
+ event.stopPropagation();
30
+ if (isDisabled()) return;
31
+ var active = isActive(type);
32
+ if (active) {
33
+ removeMark(editor, type);
34
+ } else {
35
+ addMark(editor, type);
20
36
  }
21
- _this = _super.call.apply(_super, [this].concat(args));
22
- _this.isActive = function (editor, type) {
23
- var isMark = getValue(editor, type);
24
- return !!isMark;
25
- };
26
- _this.isDisabled = function () {
27
- var editor = _this.props.editor;
28
- return isMenuDisabled(editor);
29
- };
30
- _this.onMouseDown = function (e, type) {
31
- e.preventDefault();
32
- e.stopPropagation();
33
- if (_this.isDisabled()) return;
34
- var editor = _this.props.editor;
35
- var active = _this.isActive(editor, type);
36
- if (active) {
37
- removeMark(editor, type);
38
- } else {
39
- addMark(editor, type);
40
- }
41
- focusEditor(editor);
42
- };
43
- _this.getTextStyleList = function (key) {
44
- var _this$props = _this.props,
45
- isRichEditor = _this$props.isRichEditor,
46
- className = _this$props.className,
47
- editor = _this$props.editor;
48
- var list = MENUS_CONFIG_MAP[key].map(function (item) {
49
- var itemProps = {
50
- isRichEditor: isRichEditor,
51
- className: className,
52
- disabled: _this.isDisabled(),
53
- isActive: _this.isActive(editor, item.type),
54
- onMouseDown: _this.onMouseDown
37
+ focusEditor(editor);
38
+
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [editor]);
41
+ var setColor = useCallback(function (type, color) {
42
+ Editor.addMark(editor, type, color);
43
+ focusEditor(editor);
44
+
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ }, [editor]);
47
+ var getTextStyleList = useCallback(function (key) {
48
+ return MENUS_CONFIG_MAP[key].map(function (item) {
49
+ var itemProps = {
50
+ isRichEditor: isRichEditor,
51
+ className: className,
52
+ disabled: isDisabled(),
53
+ isActive: isActive(item.type),
54
+ onMouseDown: item.isColor ? function () {} : onMouseDown
55
+ };
56
+ if (item.isColor) {
57
+ itemProps['setColor'] = function (color) {
58
+ return setColor(item.type, color);
55
59
  };
56
- return _objectSpread(_objectSpread({}, itemProps), item);
57
- });
58
- return list;
59
- };
60
- return _this;
61
- }
62
- _createClass(TextStyleMenuList, [{
63
- key: "render",
64
- value: function render() {
65
- var list = this.getTextStyleList(TEXT_STYLE);
66
- var dropdownList = this.getTextStyleList(TEXT_STYLE_MORE);
67
- return /*#__PURE__*/React.createElement(React.Fragment, null, list.map(function (itemProps, index) {
68
- return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
69
- key: index
70
- }, itemProps));
71
- }), /*#__PURE__*/React.createElement(MoreDropdown, null, dropdownList.map(function (itemProps, index) {
72
- return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
73
- key: index
74
- }, itemProps));
75
- })));
76
- }
77
- }]);
78
- return TextStyleMenuList;
79
- }(React.Component);
80
- export default TextStyleMenuList;
60
+ itemProps['defaultColorTip'] = item.type === ELEMENT_TYPE.COLOR ? t('Default') : '';
61
+ }
62
+ return _objectSpread(_objectSpread({}, itemProps), item);
63
+ });
64
+
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, [editor]);
67
+ var list = getTextStyleList(TEXT_STYLE);
68
+ var dropdownList = getTextStyleList(TEXT_STYLE_MORE);
69
+ return /*#__PURE__*/React.createElement(React.Fragment, null, list.map(function (itemProps, index) {
70
+ var Component = itemProps.isColor ? ColorMenu : MenuItem;
71
+ return /*#__PURE__*/React.createElement(Component, Object.assign({
72
+ key: index
73
+ }, itemProps));
74
+ }), /*#__PURE__*/React.createElement(MoreDropdown, null, dropdownList.map(function (itemProps, index) {
75
+ return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
76
+ key: index
77
+ }, itemProps));
78
+ })));
79
+ };
80
+ export default withTranslation('sdoc-editor')(TextStyleMenuList);
@@ -21,6 +21,9 @@ var renderText = function renderText(props, editor) {
21
21
  if (leaf.color) {
22
22
  style['color'] = leaf.color;
23
23
  }
24
+ if (leaf['highlight-color']) {
25
+ style['backgroundColor'] = leaf['highlight-color'];
26
+ }
24
27
  if (leaf.BOLD) {
25
28
  markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
26
29
  }
@@ -13,6 +13,7 @@ import CodeBlockMenu from '../plugins/code-block/menu';
13
13
  import TextAlignMenu from '../plugins/text-align/menu';
14
14
  import HistoryMenu from './redo-undo';
15
15
  import { TableMenu, ActiveTableMenu } from '../plugins/table/menu';
16
+ import ClearFormatMenu from '../plugins/clear-format/menu';
16
17
  var Toolbar = function Toolbar(_ref) {
17
18
  var editor = _ref.editor;
18
19
  useSelectionUpdate();
@@ -20,6 +21,8 @@ var Toolbar = function Toolbar(_ref) {
20
21
  className: "sdoc-editor-toolbar"
21
22
  }, /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(HistoryMenu, {
22
23
  editor: editor
24
+ })), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(ClearFormatMenu, {
25
+ editor: editor
23
26
  })), /*#__PURE__*/React.createElement(HeaderMenu, {
24
27
  editor: editor
25
28
  }), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenuList, {
@@ -4,7 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
5
  import { Node, Element, Editor } from '@seafile/slate';
6
6
  import { useSlateStatic } from '@seafile/slate-react';
7
- import Prism, { normalizeTokens, normalizeTokensByLanguageType } from '../utils/prismjs';
7
+ import Prism, { normalizeTokens, normalizeTokensByLanguageType } from '../extension/plugins/code-block/prismjs';
8
8
  import { CODE_BLOCK } from '../extension/constants';
9
9
  var mergeMaps = function mergeMaps() {
10
10
  var map = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.87",
3
+ "version": "0.1.88",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -305,5 +305,8 @@
305
305
  "Standard_light_blue": "Standard light blue",
306
306
  "Standard_blue": "Standard blue",
307
307
  "Standard_dark_blue": "Standard dark blue",
308
- "Standard_purple": "Standard purple"
308
+ "Standard_purple": "Standard purple",
309
+ "Highlight_color": "Highlight",
310
+ "Font_color": "Font color",
311
+ "Default": "Default"
309
312
  }
@@ -305,5 +305,8 @@
305
305
  "Standard_light_blue": "标准浅蓝",
306
306
  "Standard_blue": "标准蓝",
307
307
  "Standard_dark_blue": "标准深蓝",
308
- "Standard_purple": "标准紫"
308
+ "Standard_purple": "标准紫",
309
+ "Highlight_color": "突出显示",
310
+ "Font_color": "字体颜色",
311
+ "Default": "默认"
309
312
  }
@@ -14,6 +14,12 @@
14
14
  />
15
15
  <missing-glyph />
16
16
 
17
+ <glyph glyph-name="sdoc-font-color" unicode="&#58886;" d="M960-96h-160l-80 224h-416L224-96H64L403.2 864h211.2L960-96zM512 704l-160-448h320L512 704z" horiz-adv-x="1024" />
18
+
19
+ <glyph glyph-name="sdoc-highlight-color" unicode="&#58885;" d="M992 528L640-67.2l-144 80-64-108.8H32l163.2 278.4L32 275.2 380.8 896 992 528zM198.4 320l406.4-224 233.6 390.4L428.8 736 198.4 320z" horiz-adv-x="1024" />
20
+
21
+ <glyph glyph-name="sdoc-format-clear" unicode="&#58883;" d="M519.488 64H279.552L64 279.552 584.448 800l384.64-384.64L617.728 64h-98.176z m64 64l92.608 92.608-288.64 288.64L161.28 282.88 316.16 128h267.328zM128 0h832v-64H128v64z" horiz-adv-x="1024" />
22
+
17
23
  <glyph glyph-name="sdoc-bg-color" unicode="&#58884;" d="M906.4-64c60.8 0 105.6 48 105.6 105.6 0 38.4-35.2 124.8-105.6 246.4C836 160 800.8 80 800.8 41.6c0-60.8 48-105.6 105.6-105.6zM512.8 761.6l358.4-352c35.2-35.2 35.2-92.8 0-128l-358.4-352c-35.2-35.2-92.8-35.2-131.2 0l-355.2 352c-35.2 35.2-35.2 92.8 0 128L356 736l-19.2 19.2c-25.6 22.4-25.6 64 0 89.6s64 22.4 89.6 0l86.4-83.2z m-368-400h614.4L452 649.6c0-3.2-307.2-288-307.2-288z" horiz-adv-x="1024" />
18
24
 
19
25
  <glyph glyph-name="sdoc-right-slide" unicode="&#58882;" d="M806.4 438.4L336 812.8c-54.4 44.8-144 9.6-144-54.4v-748.8c0-64 86.4-99.2 144-54.4l470.4 374.4c35.2 28.8 35.2 80 0 108.8z" horiz-adv-x="1024" />
@@ -1,11 +1,11 @@
1
1
  @font-face {
2
2
  font-family: "sdocfont"; /* Project id 4097705 */
3
- src: url('./sdoc-editor-font/iconfont.eot?t=1689838000925'); /* IE9 */
4
- src: url('./sdoc-editor-font/iconfont.eot?t=1689838000925#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
- url('./sdoc-editor-font/iconfont.woff2?t=1689838000925') format('woff2'),
6
- url('./sdoc-editor-font/iconfont.woff?t=1689838000925') format('woff'),
7
- url('./sdoc-editor-font/iconfont.ttf?t=1689838000925') format('truetype'),
8
- url('./sdoc-editor-font/iconfont.svg?t=1689838000925#sdocfont') format('svg');
3
+ src: url('./sdoc-editor-font/iconfont.eot?t=1690191058909'); /* IE9 */
4
+ src: url('./sdoc-editor-font/iconfont.eot?t=1690191058909#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
+ url('./sdoc-editor-font/iconfont.woff2?t=1690191058909') format('woff2'),
6
+ url('./sdoc-editor-font/iconfont.woff?t=1690191058909') format('woff'),
7
+ url('./sdoc-editor-font/iconfont.ttf?t=1690191058909') format('truetype'),
8
+ url('./sdoc-editor-font/iconfont.svg?t=1690191058909#sdocfont') format('svg');
9
9
  }
10
10
 
11
11
  .sdocfont {
@@ -16,6 +16,18 @@
16
16
  -moz-osx-font-smoothing: grayscale;
17
17
  }
18
18
 
19
+ .sdoc-font-color:before {
20
+ content: "\e606";
21
+ }
22
+
23
+ .sdoc-highlight-color:before {
24
+ content: "\e605";
25
+ }
26
+
27
+ .sdoc-format-clear:before {
28
+ content: "\e603";
29
+ }
30
+
19
31
  .sdoc-bg-color:before {
20
32
  content: "\e604";
21
33
  }
@@ -1,38 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React, { Component } from 'react';
6
- import ModalPortal from '../../../../components/modal-portal';
7
- import { TablePlugin } from '../../plugins';
8
- import { isAllInTable } from '../../plugins/table/helpers';
9
- var ContextMenu = /*#__PURE__*/function (_Component) {
10
- _inherits(ContextMenu, _Component);
11
- var _super = _createSuper(ContextMenu);
12
- function ContextMenu() {
13
- var _this;
14
- _classCallCheck(this, ContextMenu);
15
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
- args[_key] = arguments[_key];
17
- }
18
- _this = _super.call.apply(_super, [this].concat(args));
19
- _this.renderContextMenu = function () {
20
- var editor = _this.props.editor;
21
- if (isAllInTable(editor)) {
22
- var ContextMenuComponent = TablePlugin.contextMenu;
23
- return /*#__PURE__*/React.createElement(ContextMenuComponent, _this.props);
24
- }
25
- };
26
- return _this;
27
- }
28
- _createClass(ContextMenu, [{
29
- key: "render",
30
- value: function render() {
31
- return /*#__PURE__*/React.createElement(ModalPortal, {
32
- className: "sdoc-context-menu"
33
- }, this.renderContextMenu());
34
- }
35
- }]);
36
- return ContextMenu;
37
- }(Component);
38
- export default ContextMenu;