@seafile/sdoc-editor 0.1.73 → 0.1.75

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 (43) hide show
  1. package/dist/basic-sdk/comment/comment-decorate.js +1 -1
  2. package/dist/basic-sdk/editor.js +48 -0
  3. package/dist/basic-sdk/extension/constants/element-type.js +3 -0
  4. package/dist/basic-sdk/extension/constants/index.js +16 -17
  5. package/dist/basic-sdk/extension/plugins/code-block/plugin.js +8 -0
  6. package/dist/basic-sdk/extension/plugins/table/constants/index.js +14 -1
  7. package/dist/basic-sdk/extension/plugins/table/helpers.js +35 -2
  8. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +2 -1
  9. package/dist/basic-sdk/extension/plugins/table/menu/context-menu/index.js +2 -2
  10. package/dist/basic-sdk/extension/plugins/table/menu/context-menu/insert-table-element.js +1 -2
  11. package/dist/basic-sdk/extension/plugins/table/plugin.js +2 -2
  12. package/dist/basic-sdk/extension/plugins/table/render/hooks.js +7 -3
  13. package/dist/basic-sdk/extension/plugins/table/render/index.css +12 -3
  14. package/dist/basic-sdk/extension/plugins/table/render/index.js +14 -3
  15. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -2
  16. package/dist/basic-sdk/extension/plugins/table/render/render-row.js +0 -2
  17. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/first-column-left-resize-handler.js +0 -2
  18. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/index.js +2 -2
  19. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/resize-handler.js +0 -2
  20. package/dist/basic-sdk/extension/plugins/table/render/table-header/columns-header/column-header.js +71 -0
  21. package/dist/basic-sdk/extension/plugins/table/render/table-header/columns-header/index.js +92 -0
  22. package/dist/basic-sdk/extension/plugins/table/render/table-header/index.css +70 -0
  23. package/dist/basic-sdk/extension/plugins/table/render/table-header/index.js +62 -0
  24. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-columns-header.js +23 -0
  25. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/index.js +89 -0
  26. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +90 -0
  27. package/dist/basic-sdk/extension/plugins/table/render/table-root.js +6 -4
  28. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +20 -17
  29. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +8 -5
  30. package/dist/basic-sdk/extension/render/render-element.js +14 -8
  31. package/dist/basic-sdk/extension/toolbar/index.js +2 -2
  32. package/dist/basic-sdk/views/diff-viewer.js +1 -1
  33. package/dist/basic-sdk/views/viewer.js +6 -2
  34. package/dist/components/more-dropdown/index.js +69 -0
  35. package/dist/components/more-dropdown/style.css +64 -0
  36. package/package.json +1 -1
  37. package/public/locales/en/sdoc-editor.json +2 -0
  38. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  39. package/public/media/sdoc-editor-font/iconfont.svg +6 -4
  40. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  41. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  42. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  43. package/public/media/sdoc-editor-font.css +18 -14
@@ -20,7 +20,7 @@ export var commentDecorate = function commentDecorate(editor) {
20
20
  }
21
21
  };
22
22
  // rgba prevents occlusion of the cursor
23
- decoration['bg_color'] = 'rgba(129, 237, 247, 0.5)';
23
+ decoration['computed_bg_color'] = 'rgba(129, 237, 247, 0.5)';
24
24
  decoration['comment_count'] = editor.comments_map[node.id].length;
25
25
  decorations.push(decoration);
26
26
  }
@@ -136,6 +136,54 @@ var SDocEditor = function SDocEditor(_ref) {
136
136
  scrollRef.current.scroll(0, Math.max(0, scrollTop + _domHeight));
137
137
  return;
138
138
  }
139
+ if (event.key === 'Backspace') {
140
+ var _getCursorPosition3 = getCursorPosition(),
141
+ _y2 = _getCursorPosition3.y;
142
+
143
+ // above viewport
144
+ if (_y2 < 0) {
145
+ var newY = Math.abs(_y2);
146
+ if (isSelectionAtBlockStart(editor)) {
147
+ var _prevNode = getPrevNode(editor);
148
+ if (!_prevNode) return;
149
+ var _domNode2 = ReactEditor.toDOMNode(editor, _prevNode[0]);
150
+ var _domHeight2 = getDomHeight(_domNode2);
151
+ scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2)));
152
+ } else {
153
+ scrollRef.current.scroll(0, Math.max(0, scrollTop - newY));
154
+ }
155
+ return;
156
+ }
157
+
158
+ // insider viewport
159
+ if (_y2 >= 0 && _y2 <= clientHeight) {
160
+ if (isSelectionAtBlockStart(editor)) {
161
+ var _prevNode2 = getPrevNode(editor);
162
+ if (!_prevNode2) return;
163
+ var _domNode3 = ReactEditor.toDOMNode(editor, _prevNode2[0]);
164
+ var _domHeight3 = getDomHeight(_domNode3);
165
+ if (_y2 >= _domHeight3) return;
166
+ // Scroll up the height of the previous block
167
+ scrollRef.current.scroll(0, Math.max(0, scrollTop - _domHeight3));
168
+ return;
169
+ }
170
+ }
171
+
172
+ // below viewport
173
+ if (_y2 > clientHeight) {
174
+ if (isSelectionAtBlockStart(editor)) {
175
+ // y: text top border
176
+ scrollRef.current.scroll(0, Math.max(0, scrollTop + (_y2 - clientHeight)));
177
+ } else {
178
+ var marginBottom = 11.2;
179
+ var _getCursorPosition4 = getCursorPosition(false),
180
+ _newY = _getCursorPosition4.y;
181
+ var rectBottom = _newY + marginBottom; // text bottom border
182
+ scrollRef.current.scroll(0, Math.max(0, scrollTop + (rectBottom - clientHeight)));
183
+ }
184
+ return;
185
+ }
186
+ }
139
187
  eventProxy.onKeyDown(event);
140
188
  // eslint-disable-next-line react-hooks/exhaustive-deps
141
189
  }, []);
@@ -3,6 +3,8 @@ export var BOLD = 'bold';
3
3
  export var ITALIC = 'italic';
4
4
  export var UNDERLINE = 'underline';
5
5
  export var STRIKETHROUGH = 'strikethrough';
6
+ export var SUPERSCRIPT = 'superscript';
7
+ export var SUBSCRIPT = 'subscript';
6
8
  export var HEADER = 'header';
7
9
  export var HEADER1 = 'header1';
8
10
  export var HEADER2 = 'header2';
@@ -28,6 +30,7 @@ export var TABLE_CELL = 'table-cell';
28
30
  export var FORMULA = 'formula';
29
31
  export var COLUMN = 'column';
30
32
  export var TEXT_STYLE = 'text-style';
33
+ export var TEXT_STYLE_MORE = 'text-style-more';
31
34
  export var BOLD_ITALIC = 'bold-italic';
32
35
  export var TEXT_ALIGN = 'text-align';
33
36
  export var ALIGN_LEFT = 'align-left';
@@ -1,8 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP, _TABLE_ELEMENT_SPAN;
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, 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, 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 } from './element-type';
6
6
  import KEYBOARD from './keyboard';
7
7
 
8
8
  // history
@@ -64,11 +64,21 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
64
64
  iconClass: 'sdocfont sdoc-underline',
65
65
  text: 'Underline',
66
66
  type: 'UNDERLINE'
67
- }, {
67
+ }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE_MORE, [{
68
68
  id: STRIKETHROUGH,
69
69
  iconClass: 'sdocfont sdoc-strikethrough',
70
70
  text: 'Strikethrough',
71
71
  type: 'STRIKETHROUGH'
72
+ }, {
73
+ id: SUPERSCRIPT,
74
+ iconClass: 'sdocfont sdoc-superscript',
75
+ text: 'Superscript',
76
+ type: 'SUPERSCRIPT'
77
+ }, {
78
+ id: SUBSCRIPT,
79
+ iconClass: 'sdocfont sdoc-subscript',
80
+ text: 'Subscript',
81
+ type: 'SUBSCRIPT'
72
82
  }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_ALIGN, [{
73
83
  id: ALIGN_LEFT,
74
84
  iconClass: 'sdocfont sdoc-align-left',
@@ -102,23 +112,12 @@ export var DIFF_TYPE = {
102
112
  export var STYLE_KEY = {
103
113
  TEXT_ALIGN: 'textAlign'
104
114
  };
105
- export var TABLE_ELEMENT = {
106
- TABLE: 'table',
107
- ROW: 'row',
108
- COLUMN: 'column',
109
- CELL: 'cell'
110
- };
111
- export var TABLE_ELEMENT_SPAN = (_TABLE_ELEMENT_SPAN = {}, _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.TABLE, 'table'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.ROW, 'tr'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.CELL, 'td'), _TABLE_ELEMENT_SPAN);
112
- export var TABLE_ELEMENT_POSITION = {
113
- AFTER: 'after',
114
- BEFORE: 'before'
115
- };
116
115
  export var DELETED_STYLE = {
117
- background_color: '#ffeef0',
116
+ computed_bg_color: '#ffeef0',
118
117
  color: 'rgb(165, 32, 21)'
119
118
  };
120
119
  export var ADDED_STYLE = {
121
- background_color: '#e6ffed',
120
+ computed_bg_color: '#e6ffed',
122
121
  color: 'rgb(137, 181, 66)'
123
122
  };
124
- export { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, 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, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD };
123
+ 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 };
@@ -11,6 +11,14 @@ var withCodeBlock = function withCodeBlock(editor) {
11
11
  insertText = editor.insertText,
12
12
  insertBreak = editor.insertBreak;
13
13
  var newEditor = editor;
14
+
15
+ // If you enter two Spaces in quick succession, a period and a space appear (Default Settings for mac)
16
+ newEditor.insertText = function (data) {
17
+ if (data === '. ') {
18
+ return insertText(' ');
19
+ }
20
+ return insertText(data);
21
+ };
14
22
  newEditor.insertFragment = function (data) {
15
23
  // only selected code block content
16
24
  if (data.length === 1 && data[0].type === CODE_BLOCK && !getSelectedNodeByType(editor, CODE_BLOCK)) {
@@ -1,3 +1,5 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ var _TABLE_ELEMENT_SPAN;
1
3
  export var TABLE_MAX_ROWS = 50;
2
4
  export var TABLE_MAX_COLUMNS = 50;
3
5
  export var EMPTY_SELECTED_RANGE = {
@@ -7,4 +9,15 @@ export var EMPTY_SELECTED_RANGE = {
7
9
  maxColIndex: -1
8
10
  };
9
11
  export var TABLE_ROW_MIN_HEIGHT = 42;
10
- export var TABLE_CELL_MIN_WIDTH = 35;
12
+ export var TABLE_CELL_MIN_WIDTH = 35;
13
+ export var TABLE_ELEMENT = {
14
+ TABLE: 'table',
15
+ ROW: 'row',
16
+ COLUMN: 'column',
17
+ CELL: 'cell'
18
+ };
19
+ export var TABLE_ELEMENT_SPAN = (_TABLE_ELEMENT_SPAN = {}, _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.TABLE, 'table'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.ROW, 'tr'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.CELL, 'td'), _TABLE_ELEMENT_SPAN);
20
+ export var TABLE_ELEMENT_POSITION = {
21
+ AFTER: 'after',
22
+ BEFORE: 'before'
23
+ };
@@ -4,8 +4,8 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import slugid from 'slugid';
5
5
  import { Editor, Range, Transforms } from '@seafile/slate';
6
6
  import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, getSelectedElems, focusEditor, getNode, findPath } from '../../core';
7
- import { ELEMENT_TYPE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../constants';
8
- import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH } from './constants';
7
+ import { ELEMENT_TYPE } from '../../constants';
8
+ import { TABLE_MAX_ROWS, TABLE_MAX_COLUMNS, EMPTY_SELECTED_RANGE, TABLE_ROW_MIN_HEIGHT, TABLE_CELL_MIN_WIDTH, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
9
9
  import EventBus from '../../../utils/event-bus';
10
10
  import { EXTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../../constants';
11
11
  import ObjectUtils from '../../../utils/object-utils';
@@ -159,6 +159,39 @@ export var setTextStyle = function setTextStyle(editor, style) {
159
159
  Transforms.select(editor, newSelection);
160
160
  }
161
161
  };
162
+ export var insertTableRow = function insertTableRow(editor, table, rowIndex) {
163
+ var position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : TABLE_ELEMENT_POSITION.AFTER;
164
+ var tableRowCount = table.children.length;
165
+ if (tableRowCount >= TABLE_MAX_ROWS) return;
166
+ var tableColumnCount = table.children[0].children.length;
167
+ var row = generateTableRow(tableColumnCount);
168
+ var tablePath = findPath(editor, table);
169
+ var targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [].concat(_toConsumableArray(tablePath), [rowIndex + 1]) : [].concat(_toConsumableArray(tablePath), [rowIndex]);
170
+ Transforms.insertNodes(editor, row, {
171
+ at: targetPath
172
+ });
173
+ var focusPath = [].concat(_toConsumableArray(targetPath), [0]);
174
+ focusEditor(editor, focusPath);
175
+ };
176
+ export var insertTableColumn = function insertTableColumn(editor, table, columnIndex) {
177
+ var position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : TABLE_ELEMENT_POSITION.AFTER;
178
+ var tableColumnCount = table.children[0].children.length;
179
+ if (tableColumnCount >= TABLE_MAX_COLUMNS) return;
180
+ var newCellIndex = position === TABLE_ELEMENT_POSITION.AFTER ? columnIndex + 1 : columnIndex;
181
+ var newColumns = getTableColumnsAfterInsertColumn(editor, table, newCellIndex, 1);
182
+ updateColumnWidth(editor, table, newColumns);
183
+ var tablePath = findPath(editor, table);
184
+ var tableRowCount = table.children.length;
185
+ for (var i = 0; i < tableRowCount; i++) {
186
+ var newCellPath = [].concat(_toConsumableArray(tablePath), [i, newCellIndex]);
187
+ var newCell = generateTableCell();
188
+ Transforms.insertNodes(editor, newCell, {
189
+ at: newCellPath
190
+ });
191
+ }
192
+ var focusPath = [].concat(_toConsumableArray(tablePath), [0, newCellIndex, 0]);
193
+ focusEditor(editor, focusPath);
194
+ };
162
195
  export var insertTableElement = function insertTableElement(editor, type) {
163
196
  var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TABLE_ELEMENT_POSITION.AFTER;
164
197
  var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
@@ -8,8 +8,9 @@ import React, { Component } from 'react';
8
8
  import { withTranslation } from 'react-i18next';
9
9
  import { MenuGroup, MenuItem } from '../../../../menu';
10
10
  import CommonMenu from './common-menu';
11
- import { TABLE_ELEMENT, MENUS_CONFIG_MAP, REMOVE_TABLE } from '../../../../constants';
11
+ import { MENUS_CONFIG_MAP, REMOVE_TABLE } from '../../../../constants';
12
12
  import { setTextStyle, insertTableElement, removeTableElement, isAllInTable } from '../../helpers';
13
+ import { TABLE_ELEMENT } from '../../constants';
13
14
  import './index.css';
14
15
  var ActiveTableMenu = /*#__PURE__*/function (_Component) {
15
16
  _inherits(ActiveTableMenu, _Component);
@@ -6,10 +6,10 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
7
  import { withTranslation } from 'react-i18next';
8
8
  import ObjectUtils from '../../../../../utils/object-utils';
9
- import { TABLE_ELEMENT, TABLE_ELEMENT_POSITION, ELEMENT_TYPE } from '../../../../constants';
9
+ import { ELEMENT_TYPE } from '../../../../constants';
10
10
  import InsertTableElement from './insert-table-element';
11
11
  import { getSelectedNodeByType } from '../../../../core';
12
- import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS } from '../../constants';
12
+ import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../constants';
13
13
  import { insertTableElement, removeTableElement } from '../../helpers';
14
14
  import './index.css';
15
15
  var ContextMenu = /*#__PURE__*/function (_React$Component) {
@@ -6,8 +6,7 @@ import React, { Component } from 'react';
6
6
  import { withTranslation } from 'react-i18next';
7
7
  import { Input } from 'reactstrap';
8
8
  import isHotkey from 'is-hotkey';
9
- import { TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../../../constants';
10
- import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS } from '../../constants';
9
+ import { TABLE_MAX_COLUMNS, TABLE_MAX_ROWS, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from '../../constants';
11
10
  var InsertTableElement = /*#__PURE__*/function (_Component) {
12
11
  _inherits(InsertTableElement, _Component);
13
12
  var _super = _createSuper(InsertTableElement);
@@ -6,8 +6,8 @@ import isHotkey from 'is-hotkey';
6
6
  import { Editor, Transforms, Point, Path, Node } from '@seafile/slate';
7
7
  import { ReactEditor } from '@seafile/slate-react';
8
8
  import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, isLastNode, replaceNodeChildren, focusEditor, getNode, generateEmptyElement } from '../../core';
9
- import { ELEMENT_TYPE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, KEYBOARD, PARAGRAPH } from '../../constants';
10
- import { TABLE_MAX_ROWS, EMPTY_SELECTED_RANGE } from './constants';
9
+ import { ELEMENT_TYPE, KEYBOARD, PARAGRAPH } from '../../constants';
10
+ import { TABLE_MAX_ROWS, EMPTY_SELECTED_RANGE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION } from './constants';
11
11
  import ObjectUtils from '../../../utils/object-utils';
12
12
  import { getSelectedInfo, insertTableElement } from './helpers';
13
13
  var deleteHandler = function deleteHandler(editor) {
@@ -3,9 +3,9 @@ export var TableRootContext = createContext();
3
3
  export var useTableRootContext = function useTableRootContext() {
4
4
  return useContext(TableRootContext);
5
5
  };
6
- export var TableContext = createContext();
7
- export var useTableContext = function useTableContext() {
8
- return useContext(TableContext);
6
+ export var TableSelectedRangeContext = createContext();
7
+ export var useTableSelectedRangeContext = function useTableSelectedRangeContext() {
8
+ return useContext(TableSelectedRangeContext);
9
9
  };
10
10
  export var ResizeHandlersContext = createContext();
11
11
  export var useResizeHandlersContext = function useResizeHandlersContext() {
@@ -14,4 +14,8 @@ export var useResizeHandlersContext = function useResizeHandlersContext() {
14
14
  export var SettingSelectRangeContext = createContext();
15
15
  export var useSettingSelectRangeContext = function useSettingSelectRangeContext() {
16
16
  return useContext(SettingSelectRangeContext);
17
+ };
18
+ export var TableRootScrollLeftContext = createContext();
19
+ export var useTableRootScrollLeftContext = function useTableRootScrollLeftContext() {
20
+ return useContext(TableRootScrollLeftContext);
17
21
  };
@@ -1,6 +1,6 @@
1
1
  .sdoc-table-wrapper {
2
2
  width: 100%;
3
- overflow: hidden;
3
+ /* overflow: hidden; */
4
4
  }
5
5
 
6
6
  .sdoc-table-wrapper .sdoc-table-scroll-wrapper {
@@ -72,11 +72,16 @@
72
72
  position: absolute;
73
73
  top: -1px;
74
74
  left: 0;
75
- width: 100%;
75
+ width: calc(100% + 1px);
76
76
  height: 2px;
77
77
  border-top: 1px double #ffa94d !important;
78
78
  }
79
79
 
80
+ .sdoc-table-wrapper .cell-light-height-top-border:first-child:before {
81
+ left: -1px;
82
+ width: calc(100% + 2px);
83
+ }
84
+
80
85
  .sdoc-table-wrapper .cell-light-height-bottom-border {
81
86
  border-bottom: 1px double #ffa94d !important;
82
87
  }
@@ -87,7 +92,7 @@
87
92
  top: 0px;
88
93
  left: -1px;
89
94
  width: 2px;
90
- height: 100%;
95
+ height: calc(100% + 1px);
91
96
  border-left: 1px double #ffa94d !important;
92
97
  }
93
98
 
@@ -135,3 +140,7 @@
135
140
  background-color: #2d7ff9;
136
141
  border-radius: 1px;
137
142
  }
143
+
144
+ .sdoc-table-wrapper .background-color-tip-blue {
145
+ background-color: #2d7ff9 !important;
146
+ }
@@ -4,7 +4,7 @@ import classnames from 'classnames';
4
4
  import throttle from 'lodash.throttle';
5
5
  import { useSelected, useSlateStatic, useReadOnly } from '@seafile/slate-react';
6
6
  import { EMPTY_SELECTED_RANGE } from '../constants';
7
- import { ResizeHandlersContext, TableContext, SettingSelectRangeContext } from './hooks';
7
+ import { ResizeHandlersContext, TableSelectedRangeContext, SettingSelectRangeContext } from './hooks';
8
8
  import EventBus from '../../../../utils/event-bus';
9
9
  import { EXTERNAL_EVENT } from '../../../../../constants';
10
10
  import { getTableColumns, setTableSelectedRange, getFirstTableCell } from '../helpers';
@@ -12,6 +12,7 @@ import ObjectUtils from '../../../../utils/object-utils';
12
12
  import ResizeHandlers from './resize-handlers';
13
13
  import { registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
14
14
  import TableRoot from './table-root';
15
+ import TableHeader from './table-header';
15
16
  import './index.css';
16
17
  var Table = function Table(_ref) {
17
18
  var className = _ref.className,
@@ -108,6 +109,7 @@ var Table = function Table(_ref) {
108
109
  }
109
110
  return function () {
110
111
  cancelTableSelectRangeSubscribe();
112
+ setTableSelectedRange(editor, selectedRange);
111
113
  };
112
114
 
113
115
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -117,7 +119,13 @@ var Table = function Table(_ref) {
117
119
 
118
120
  // eslint-disable-next-line react-hooks/exhaustive-deps
119
121
  }, []);
120
- return /*#__PURE__*/React.createElement(TableContext.Provider, {
122
+ var setSelectedRangeByClick = useCallback(function (range) {
123
+ setSelectedRange(range);
124
+ setTableSelectedRange(editor, range);
125
+
126
+ // eslint-disable-next-line react-hooks/exhaustive-deps
127
+ }, []);
128
+ return /*#__PURE__*/React.createElement(TableSelectedRangeContext.Provider, {
121
129
  value: selectedRange
122
130
  }, /*#__PURE__*/React.createElement(ResizeHandlersContext.Provider, {
123
131
  value: columns
@@ -126,7 +134,10 @@ var Table = function Table(_ref) {
126
134
  }, /*#__PURE__*/React.createElement(TableRoot, {
127
135
  columns: columns,
128
136
  attributes: attributes
129
- }, /*#__PURE__*/React.createElement("div", {
137
+ }, isSelected && /*#__PURE__*/React.createElement(TableHeader, {
138
+ table: element,
139
+ setSelectedRange: setSelectedRangeByClick
140
+ }), /*#__PURE__*/React.createElement("div", {
130
141
  className: classnames('sdoc-table-container position-relative', attributes.className, className, {
131
142
  'sdoc-table-selected': isSelected
132
143
  }),
@@ -5,7 +5,7 @@ import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
5
5
  import ObjectUtils from '../../../../utils/object-utils';
6
6
  import { STYLE_KEY } from '../../../constants';
7
7
  import { findPath } from '../../../core';
8
- import { useResizeHandlersContext, useTableContext } from './hooks';
8
+ import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks';
9
9
  import { EMPTY_SELECTED_RANGE } from '../constants';
10
10
  import { getTableColumns, getCellColumn } from '../helpers';
11
11
  var TableCell = function TableCell(_ref) {
@@ -13,7 +13,7 @@ var TableCell = function TableCell(_ref) {
13
13
  element = _ref.element,
14
14
  children = _ref.children;
15
15
  var editor = useSlateStatic();
16
- var selectedRange = useTableContext() || EMPTY_SELECTED_RANGE;
16
+ var selectedRange = useTableSelectedRangeContext() || EMPTY_SELECTED_RANGE;
17
17
  var cellPath = findPath(editor, element, [0, 0]);
18
18
  var columns = useResizeHandlersContext() || getTableColumns(editor, element);
19
19
  var pathLength = cellPath.length;
@@ -4,7 +4,6 @@ import React, { useEffect, useState, useRef, useCallback } from 'react';
4
4
  import classnames from 'classnames';
5
5
  import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
6
6
  import { ReactEditor } from '@seafile/slate-react';
7
- import { Transforms } from '@seafile/slate';
8
7
  import { findPath } from '../../../core';
9
8
  import { TABLE_ROW_MIN_HEIGHT } from '../constants';
10
9
  import { updateTableRowHeight } from '../helpers';
@@ -40,7 +39,6 @@ var TableRow = function TableRow(_ref) {
40
39
  var scrollContent = useScrollContext();
41
40
  var onMouseDown = useCallback(function (event) {
42
41
  eventStopPropagation(event);
43
- Transforms.deselect(editor);
44
42
  var mouseDownInfo = getMouseDownInfo(event, scrollContent.current);
45
43
  setMouseDownInfo(mouseDownInfo);
46
44
  setIsResizing(true);
@@ -1,7 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useRef, useState, useEffect, useCallback } from 'react';
4
- import { Transforms } from '@seafile/slate';
5
4
  import { useSlateStatic } from '@seafile/slate-react';
6
5
  import classnames from 'classnames';
7
6
  import { useTableRootContext } from '../hooks';
@@ -35,7 +34,6 @@ var FirstColumnResizeHandler = function FirstColumnResizeHandler(_ref) {
35
34
  var tableRootScrollContainer = useTableRootContext();
36
35
  var onMouseDown = useCallback(function (event) {
37
36
  eventStopPropagation(event);
38
- Transforms.deselect(editor);
39
37
  var mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
40
38
  var _tableRootScrollConta = tableRootScrollContainer.getBoundingClientRect(),
41
39
  top = _tableRootScrollConta.top;
@@ -5,8 +5,8 @@ import ResizeHandler from './resize-handler';
5
5
  import { getNode, findPath } from '../../../../core';
6
6
  import { useResizeHandlersContext } from '../hooks';
7
7
  import { getTableColumns } from '../../helpers';
8
- var ResizeHandlers = function ResizeHandlers(props) {
9
- var element = props.element;
8
+ var ResizeHandlers = function ResizeHandlers(_ref) {
9
+ var element = _ref.element;
10
10
  var editor = useSlateStatic();
11
11
  var tablePath = findPath(editor, element);
12
12
  var columns = useResizeHandlersContext() || getTableColumns(editor, element);
@@ -1,7 +1,6 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useRef, useState, useEffect, useCallback } from 'react';
4
- import { Transforms } from '@seafile/slate';
5
4
  import { useSlateStatic } from '@seafile/slate-react';
6
5
  import classnames from 'classnames';
7
6
  import { useTableRootContext } from '../hooks';
@@ -35,7 +34,6 @@ var ResizeHandler = function ResizeHandler(_ref) {
35
34
  var tableRootScrollContainer = useTableRootContext();
36
35
  var onMouseDown = useCallback(function (event) {
37
36
  eventStopPropagation(event);
38
- Transforms.deselect(editor);
39
37
  var mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
40
38
  var _tableRootScrollConta = tableRootScrollContainer.getBoundingClientRect(),
41
39
  top = _tableRootScrollConta.top;
@@ -0,0 +1,71 @@
1
+ import React, { useRef, useCallback } from 'react';
2
+ import classnames from 'classnames';
3
+ import { useSlateStatic } from '@seafile/slate-react';
4
+ import ObjectUtils from '../../../../../../utils/object-utils';
5
+ import { useTableRootContext, useTableSelectedRangeContext } from '../../hooks';
6
+ import { ELEMENT_TYPE } from '../../../../../constants';
7
+ import { findPath, getSelectedNodeByType } from '../../../../../core';
8
+ var ColumnHeader = function ColumnHeader(_ref) {
9
+ var index = _ref.index,
10
+ column = _ref.column,
11
+ addIconPosition = _ref.addIconPosition,
12
+ setAddIconPosition = _ref.setAddIconPosition,
13
+ setInsertColumnIndex = _ref.setInsertColumnIndex,
14
+ selectRange = _ref.selectRange,
15
+ tableSize = _ref.tableSize;
16
+ var editor = useSlateStatic();
17
+ var columnHeaderRef = useRef(null);
18
+ var tableRoot = useTableRootContext();
19
+ var selectedRange = useTableSelectedRangeContext();
20
+ var currentCell = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_CELL);
21
+ var currentCellPath = currentCell ? findPath(editor, currentCell, [-1, -1]) : [-1, -1];
22
+ var pathLength = currentCellPath.length;
23
+ var onMouseMove = useCallback(function (event) {
24
+ var _columnHeaderRef$curr = columnHeaderRef.current.getBoundingClientRect(),
25
+ left = _columnHeaderRef$curr.left,
26
+ width = _columnHeaderRef$curr.width,
27
+ top = _columnHeaderRef$curr.top;
28
+ var tableRootPosition = tableRoot.getBoundingClientRect();
29
+ var halfElementX = left + width / 2;
30
+ var nextAddIconPosition = {
31
+ left: event.clientX > halfElementX ? left + width - 6 : left - 6,
32
+ top: top
33
+ };
34
+ if (tableRootPosition.right < nextAddIconPosition.left) {
35
+ setAddIconPosition(undefined);
36
+ return;
37
+ }
38
+ if (tableRootPosition.left - 6 > nextAddIconPosition.left) {
39
+ setAddIconPosition(undefined);
40
+ return;
41
+ }
42
+ if (ObjectUtils.isSameObject(nextAddIconPosition, addIconPosition)) return;
43
+ setInsertColumnIndex(event.clientX > halfElementX ? index : index - 1);
44
+ setAddIconPosition(nextAddIconPosition);
45
+
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, [index, addIconPosition, column, tableSize]);
48
+ var onMouseLeave = useCallback(function (event) {
49
+ setAddIconPosition(undefined);
50
+
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [index, addIconPosition, column, tableSize]);
53
+ var isSelectedAColumn = selectedRange.minRowIndex === 0 && selectedRange.maxRowIndex === tableSize[0] - 1;
54
+ var isSelectedRangeColumn = selectedRange.minColIndex <= index && index <= selectedRange.maxColIndex;
55
+ return /*#__PURE__*/React.createElement("div", {
56
+ className: classnames('sdoc-table-column-header h-100', {
57
+ 'range-selected': isSelectedAColumn && isSelectedRangeColumn,
58
+ 'range-selected-tip': !isSelectedAColumn && isSelectedRangeColumn || currentCellPath[pathLength - 1] === index
59
+ }),
60
+ ref: columnHeaderRef,
61
+ onMouseMove: onMouseMove,
62
+ onMouseLeave: onMouseLeave,
63
+ onClick: function onClick() {
64
+ return selectRange(index);
65
+ },
66
+ style: {
67
+ width: column.width
68
+ }
69
+ });
70
+ };
71
+ export default ColumnHeader;
@@ -0,0 +1,92 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useCallback, useState } from 'react';
3
+ import { useSlateStatic } from '@seafile/slate-react';
4
+ import classnames from 'classnames';
5
+ import { useResizeHandlersContext, useTableRootScrollLeftContext, useTableRootContext } from '../../hooks';
6
+ import ColumnHeader from './column-header';
7
+ import { insertTableColumn } from '../../../helpers';
8
+ import { TABLE_ELEMENT_POSITION } from '../../../constants';
9
+ var ColumnsHeader = function ColumnsHeader(_ref) {
10
+ var table = _ref.table,
11
+ selectRange = _ref.selectRange,
12
+ tableSize = _ref.tableSize;
13
+ var editor = useSlateStatic();
14
+ var _useState = useState(0),
15
+ _useState2 = _slicedToArray(_useState, 2),
16
+ insertColumnIndex = _useState2[0],
17
+ setInsertColumnIndex = _useState2[1];
18
+ var _useState3 = useState(),
19
+ _useState4 = _slicedToArray(_useState3, 2),
20
+ addIconPosition = _useState4[0],
21
+ setAddIconPosition = _useState4[1];
22
+ var columns = useResizeHandlersContext();
23
+ var tableRootScrollLeft = useTableRootScrollLeftContext();
24
+ var _useState5 = useState(false),
25
+ _useState6 = _slicedToArray(_useState5, 2),
26
+ isHoverInAddIcon = _useState6[0],
27
+ setIsHoverInAddIcon = _useState6[1];
28
+ var tableRootContent = useTableRootContext();
29
+ var onMouseLeave = useCallback(function () {
30
+ setAddIconPosition();
31
+ setInsertColumnIndex(0);
32
+ setIsHoverInAddIcon(false);
33
+
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, [table, columns, tableSize]);
36
+ var _onMouseEnter = useCallback(function (addIconPosition) {
37
+ setAddIconPosition(addIconPosition);
38
+ setIsHoverInAddIcon(true);
39
+
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, [table, columns, tableSize]);
42
+ var insertColumn = useCallback(function (insertColumnIndex) {
43
+ var validInsertColumnIndex = insertColumnIndex === -1 ? 0 : insertColumnIndex;
44
+ var insertColumnPosition = insertColumnIndex === -1 ? TABLE_ELEMENT_POSITION.BEFORE : TABLE_ELEMENT_POSITION.AFTER;
45
+ insertTableColumn(editor, table, validInsertColumnIndex, insertColumnPosition, 1);
46
+
47
+ // eslint-disable-next-line react-hooks/exhaustive-deps
48
+ }, [table, columns, tableSize]);
49
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
50
+ className: "sdoc-table-columns-header position-absolute",
51
+ contentEditable: false
52
+ }, /*#__PURE__*/React.createElement("div", {
53
+ className: "sdoc-table-columns-header-container h-100 d-flex position-absolute",
54
+ style: {
55
+ left: -1 * tableRootScrollLeft
56
+ }
57
+ }, columns.map(function (column, index) {
58
+ return /*#__PURE__*/React.createElement(ColumnHeader, {
59
+ key: index,
60
+ column: column,
61
+ index: index,
62
+ addIconPosition: addIconPosition,
63
+ tableSize: tableSize,
64
+ setAddIconPosition: setAddIconPosition,
65
+ setInsertColumnIndex: setInsertColumnIndex,
66
+ selectRange: selectRange
67
+ });
68
+ }))), addIconPosition && /*#__PURE__*/React.createElement("div", {
69
+ className: classnames('position-fixed sdoc-table-add-element-icon-content', {
70
+ 'background-color-tip-blue': isHoverInAddIcon
71
+ }),
72
+ contentEditable: false,
73
+ style: addIconPosition,
74
+ onMouseEnter: function onMouseEnter() {
75
+ return _onMouseEnter(addIconPosition);
76
+ },
77
+ onMouseLeave: onMouseLeave,
78
+ onClick: function onClick() {
79
+ return insertColumn(insertColumnIndex);
80
+ }
81
+ }, '+'), addIconPosition && isHoverInAddIcon && /*#__PURE__*/React.createElement("div", {
82
+ className: "position-fixed sdoc-table-add-element-tip background-color-tip-blue",
83
+ style: {
84
+ left: (addIconPosition === null || addIconPosition === void 0 ? void 0 : addIconPosition.left) + 5,
85
+ top: (addIconPosition === null || addIconPosition === void 0 ? void 0 : addIconPosition.top) + 12,
86
+ width: 2,
87
+ height: tableRootContent.clientHeight,
88
+ zIndex: 1
89
+ }
90
+ }));
91
+ };
92
+ export default ColumnsHeader;