@seafile/sdoc-editor 0.1.74 → 0.1.76

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/basic-sdk/editor.js +7 -3
  2. package/dist/basic-sdk/extension/constants/element-type.js +3 -0
  3. package/dist/basic-sdk/extension/constants/index.js +14 -15
  4. package/dist/basic-sdk/extension/plugins/code-block/helpers.js +17 -0
  5. package/dist/basic-sdk/extension/plugins/code-block/plugin.js +25 -5
  6. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +6 -0
  7. package/dist/basic-sdk/extension/plugins/table/constants/index.js +14 -1
  8. package/dist/basic-sdk/extension/plugins/table/helpers.js +35 -2
  9. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +2 -1
  10. package/dist/basic-sdk/extension/plugins/table/menu/context-menu/index.js +2 -2
  11. package/dist/basic-sdk/extension/plugins/table/menu/context-menu/insert-table-element.js +1 -2
  12. package/dist/basic-sdk/extension/plugins/table/plugin.js +2 -2
  13. package/dist/basic-sdk/extension/plugins/table/render/hooks.js +7 -3
  14. package/dist/basic-sdk/extension/plugins/table/render/index.css +12 -3
  15. package/dist/basic-sdk/extension/plugins/table/render/index.js +14 -3
  16. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -2
  17. package/dist/basic-sdk/extension/plugins/table/render/render-row.js +0 -2
  18. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/first-column-left-resize-handler.js +0 -2
  19. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/index.js +2 -2
  20. package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/resize-handler.js +0 -2
  21. package/dist/basic-sdk/extension/plugins/table/render/table-header/columns-header/column-header.js +71 -0
  22. package/dist/basic-sdk/extension/plugins/table/render/table-header/columns-header/index.js +92 -0
  23. package/dist/basic-sdk/extension/plugins/table/render/table-header/index.css +70 -0
  24. package/dist/basic-sdk/extension/plugins/table/render/table-header/index.js +62 -0
  25. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-columns-header.js +23 -0
  26. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/index.js +89 -0
  27. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +90 -0
  28. package/dist/basic-sdk/extension/plugins/table/render/table-root.js +6 -4
  29. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +20 -17
  30. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +6 -0
  31. package/dist/basic-sdk/extension/render/render-element.js +14 -8
  32. package/dist/basic-sdk/extension/toolbar/index.js +2 -2
  33. package/dist/basic-sdk/utils/dom-utils.js +5 -0
  34. package/dist/basic-sdk/views/viewer.js +6 -2
  35. package/dist/components/code-block-hover-menu/index.css +5 -1
  36. package/dist/components/code-block-hover-menu/index.js +5 -0
  37. package/dist/components/more-dropdown/index.js +69 -0
  38. package/dist/components/more-dropdown/style.css +64 -0
  39. package/package.json +2 -1
  40. package/public/locales/en/sdoc-editor.json +2 -0
  41. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  42. package/public/media/sdoc-editor-font/iconfont.svg +6 -4
  43. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  44. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  45. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  46. package/public/media/sdoc-editor-font.css +18 -14
@@ -2,7 +2,7 @@ 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
4
  import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextMenu } from './extension';
5
- import { focusEditor, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
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';
@@ -16,7 +16,7 @@ import { ScrollContext } from './hooks/use-scroll-context';
16
16
  import CommentContextProvider from './comment/comment-context-provider';
17
17
  import CommentWrapper from './comment';
18
18
  import { usePipDecorate } from './decorates';
19
- import { getCursorPosition, getDomHeight } from './utils/dom-utils';
19
+ import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
20
20
  import './assets/css/layout.css';
21
21
  import './assets/css/sdoc-editor-plugins.css';
22
22
  var SDocEditor = function SDocEditor(_ref) {
@@ -148,7 +148,11 @@ var SDocEditor = function SDocEditor(_ref) {
148
148
  if (!_prevNode) return;
149
149
  var _domNode2 = ReactEditor.toDOMNode(editor, _prevNode[0]);
150
150
  var _domHeight2 = getDomHeight(_domNode2);
151
- scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2)));
151
+ var node = getAboveBlockNode(editor);
152
+ if (!node) return;
153
+ var currentDomNode = ReactEditor.toDOMNode(editor, node[0]);
154
+ var marginTop = getDomMarginTop(currentDomNode);
155
+ scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2 + marginTop)));
152
156
  } else {
153
157
  scrollRef.current.scroll(0, Math.max(0, scrollTop - newY));
154
158
  }
@@ -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,17 +112,6 @@ 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
116
  computed_bg_color: '#ffeef0',
118
117
  color: 'rgb(165, 32, 21)'
@@ -121,4 +120,4 @@ export var ADDED_STYLE = {
121
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 };
@@ -1,5 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import copy from 'copy-to-clipboard';
3
4
  import { Transforms, Editor, Node } from '@seafile/slate';
4
5
  import slugid from 'slugid';
5
6
  import { CODE_BLOCK, CODE_LINE, PARAGRAPH } from '../../constants';
@@ -106,4 +107,20 @@ export var changeToPlainText = function changeToPlainText(editor) {
106
107
  Transforms.insertNodes(editor, pList, {
107
108
  mode: 'highest'
108
109
  });
110
+ };
111
+ export var setClipboardData = function setClipboardData(value) {
112
+ // Insert text into the clipboard for use on other pages
113
+ var text = value.children.map(function (line) {
114
+ return Node.string(line);
115
+ }).join('\n');
116
+ copy(text, {
117
+ format: 'text/plain'
118
+ });
119
+
120
+ // Store the code block data
121
+ var clipboardData = {
122
+ text: text,
123
+ codeBlockNode: value
124
+ };
125
+ sessionStorage.setItem('clipboardData', JSON.stringify(clipboardData));
109
126
  };
@@ -9,8 +9,28 @@ var withCodeBlock = function withCodeBlock(editor) {
9
9
  var normalizeNode = editor.normalizeNode,
10
10
  insertFragment = editor.insertFragment,
11
11
  insertText = editor.insertText,
12
- insertBreak = editor.insertBreak;
12
+ insertBreak = editor.insertBreak,
13
+ insertData = editor.insertData,
14
+ insertNode = editor.insertNode;
13
15
  var newEditor = editor;
16
+
17
+ // If you enter two Spaces in quick succession, a period and a space appear (Default Settings for mac)
18
+ newEditor.insertText = function (data) {
19
+ if (data === '. ') {
20
+ return insertText(' ');
21
+ }
22
+ return insertText(data);
23
+ };
24
+ newEditor.insertData = function (data) {
25
+ var text = data.getData('text/plain');
26
+ var _ref = JSON.parse(sessionStorage.getItem('clipboardData')) || {},
27
+ storageText = _ref.text,
28
+ codeBlockNode = _ref.codeBlockNode;
29
+ if (codeBlockNode && text === storageText && !getSelectedNodeByType(editor, CODE_BLOCK)) {
30
+ return insertNode(codeBlockNode);
31
+ }
32
+ return insertData(data);
33
+ };
14
34
  newEditor.insertFragment = function (data) {
15
35
  // only selected code block content
16
36
  if (data.length === 1 && data[0].type === CODE_BLOCK && !getSelectedNodeByType(editor, CODE_BLOCK)) {
@@ -75,10 +95,10 @@ var withCodeBlock = function withCodeBlock(editor) {
75
95
  };
76
96
 
77
97
  // Rewrite normalizeNode
78
- newEditor.normalizeNode = function (_ref) {
79
- var _ref2 = _slicedToArray(_ref, 2),
80
- node = _ref2[0],
81
- path = _ref2[1];
98
+ newEditor.normalizeNode = function (_ref2) {
99
+ var _ref3 = _slicedToArray(_ref2, 2),
100
+ node = _ref3[0],
101
+ path = _ref3[1];
82
102
  var type = getNodeType(node);
83
103
  if (type === CODE_BLOCK) {
84
104
  // code-block is the last node in the editor and needs to be followed by a p node
@@ -5,6 +5,7 @@ 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
7
  import CodeBlockHoverMenu from '../../../../components/code-block-hover-menu';
8
+ import { setClipboardData } from './helpers';
8
9
  import '../../../assets/css/code-block.css';
9
10
  var CodeBlock = function CodeBlock(_ref) {
10
11
  var codeBlockProps = _ref.codeBlockProps;
@@ -53,6 +54,10 @@ var CodeBlock = function CodeBlock(_ref) {
53
54
  });
54
55
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
56
  }, []);
57
+ var onCopyCodeBlock = useCallback(function () {
58
+ setClipboardData(element);
59
+ // eslint-disable-next-line react-hooks/exhaustive-deps
60
+ }, [element]);
56
61
  var onDeleteCodeBlock = useCallback(function () {
57
62
  var path = ReactEditor.findPath(editor, element);
58
63
  Transforms.removeNodes(editor, {
@@ -124,6 +129,7 @@ var CodeBlock = function CodeBlock(_ref) {
124
129
  white_space: 'nowrap'
125
130
  },
126
131
  onChangeAutoLineWrap: onChangeAutoLineWrap,
132
+ onCopyCodeBlock: onCopyCodeBlock,
127
133
  onDeleteCodeBlock: onDeleteCodeBlock
128
134
  }));
129
135
  };
@@ -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;