@seafile/sdoc-editor 0.4.21 → 0.4.23
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.
- package/dist/basic-sdk/constants/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/callout/helper.js +1 -10
- package/dist/basic-sdk/extension/plugins/callout/render-elem/color-selector.js +18 -21
- package/dist/basic-sdk/extension/plugins/callout/render-elem/index.js +33 -32
- package/dist/basic-sdk/extension/plugins/image/plugin.js +1 -1
- package/dist/basic-sdk/extension/plugins/search-replace/menu/index.js +4 -2
- package/dist/basic-sdk/extension/plugins/search-replace/popover/index.css +7 -0
- package/dist/basic-sdk/extension/plugins/search-replace/popover/index.js +16 -3
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +8 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +87 -86
- package/dist/basic-sdk/extension/plugins/table/render/index.css +47 -1
- package/dist/basic-sdk/extension/plugins/table/render/index.js +27 -3
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +17 -5
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/column-resize-handler.js +25 -45
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/first-column-left-resize-handler.js +21 -41
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/index.js +44 -35
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/row-resize-handler.js +22 -32
- package/dist/basic-sdk/extension/plugins/table/render/resize-mask/index.js +133 -0
- package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +9 -15
- package/package.json +1 -1
- package/public/locales/zh_CN/sdoc-editor.json +1 -1
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +16 -2
- package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
- package/public/media/sdoc-editor-font.css +38 -10
|
@@ -9,6 +9,8 @@ import { useResizeHandlersContext, useTableSelectedRangeContext } from './hooks'
|
|
|
9
9
|
import { EMPTY_SELECTED_RANGE, SELECTED_TABLE_CELL_BACKGROUND_COLOR, TABLE_CELL_STYLE } from '../constants';
|
|
10
10
|
import { getTableColumns, colorBlend, getCellHighlightClassName } from '../helpers';
|
|
11
11
|
import { ELEMENT_TYPE } from '../../../constants';
|
|
12
|
+
import EventBus from '../../../../utils/event-bus';
|
|
13
|
+
import { INTERNAL_EVENT } from '../../../../constants';
|
|
12
14
|
const TableCell = _ref => {
|
|
13
15
|
let {
|
|
14
16
|
attributes,
|
|
@@ -22,6 +24,8 @@ const TableCell = _ref => {
|
|
|
22
24
|
const pathLength = cellPath.length;
|
|
23
25
|
const rowIndex = cellPath[pathLength - 2];
|
|
24
26
|
const cellIndex = cellPath[pathLength - 1];
|
|
27
|
+
const rowEntry = Editor.parent(editor, cellPath);
|
|
28
|
+
const tableEntry = Editor.parent(editor, rowEntry[1]);
|
|
25
29
|
const {
|
|
26
30
|
minColIndex,
|
|
27
31
|
maxColIndex,
|
|
@@ -75,10 +79,6 @@ const TableCell = _ref => {
|
|
|
75
79
|
// Table alternate highlight
|
|
76
80
|
const highlightClass = useMemo(() => {
|
|
77
81
|
var _tableEntry$;
|
|
78
|
-
const [tableEntry] = Editor.nodes(editor, {
|
|
79
|
-
at: cellPath,
|
|
80
|
-
match: n => n.type === ELEMENT_TYPE.TABLE
|
|
81
|
-
});
|
|
82
82
|
const {
|
|
83
83
|
alternate_highlight,
|
|
84
84
|
alternate_highlight_color
|
|
@@ -88,6 +88,17 @@ const TableCell = _ref => {
|
|
|
88
88
|
return className;
|
|
89
89
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
90
|
}, [editor, rowIndex]);
|
|
91
|
+
const onMouseMove = mouseDownEvent => {
|
|
92
|
+
const eventBus = EventBus.getInstance();
|
|
93
|
+
const tableId = tableEntry[0].id;
|
|
94
|
+
eventBus.dispatch(INTERNAL_EVENT.TABLE_CELL_MOUSE_ENTER, {
|
|
95
|
+
mouseDownEvent,
|
|
96
|
+
cell: element,
|
|
97
|
+
rowIndex,
|
|
98
|
+
cellIndex,
|
|
99
|
+
tableId
|
|
100
|
+
});
|
|
101
|
+
};
|
|
91
102
|
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
92
103
|
style: _objectSpread(_objectSpread({}, element.style), style),
|
|
93
104
|
className: classnames('table-cell', attributes.className, highlightClass, {
|
|
@@ -100,7 +111,8 @@ const TableCell = _ref => {
|
|
|
100
111
|
"data-id": element.id,
|
|
101
112
|
"row-index": rowIndex,
|
|
102
113
|
"cell-index": cellIndex,
|
|
103
|
-
onContextMenu: onContextMenu
|
|
114
|
+
onContextMenu: onContextMenu,
|
|
115
|
+
onMouseMove: onMouseMove
|
|
104
116
|
}), children);
|
|
105
117
|
};
|
|
106
118
|
function renderTableCell(props) {
|
package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/column-resize-handler.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import React, { useRef, useState, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
3
3
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
|
-
import classnames from 'classnames';
|
|
5
4
|
import { useTableRootContext } from '../hooks';
|
|
6
5
|
import { TABLE_CELL_MIN_WIDTH } from '../../constants';
|
|
7
6
|
import { getTableColumns, updateColumnWidth, focusClosestCellWhenJustifyCellSize } from '../../helpers';
|
|
@@ -10,21 +9,23 @@ const ColumnResizeHandler = _ref => {
|
|
|
10
9
|
let {
|
|
11
10
|
column,
|
|
12
11
|
left: initLeft,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
table,
|
|
13
|
+
cellIndex,
|
|
14
|
+
rowBottom,
|
|
15
|
+
hideResizeHandlers,
|
|
16
|
+
mouseDownEvent,
|
|
17
|
+
adjustingCell,
|
|
18
|
+
isDraggingResizeHandler
|
|
16
19
|
} = _ref;
|
|
17
20
|
const editor = useSlateStatic();
|
|
18
21
|
const resizeHandler = useRef(null);
|
|
19
22
|
const [left, setLeft] = useState(initLeft);
|
|
20
|
-
const [isResizing, setIsResizing] = useState(false);
|
|
21
23
|
const [mouseDownInfo, setMouseDownInfo] = useState({});
|
|
22
24
|
const [style, setStyle] = useState({});
|
|
23
25
|
const width = column.width;
|
|
24
26
|
const tableRootScrollContainer = useTableRootContext();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
const mouseDownInfo = getMouseDownInfo(mouseDownEvent, tableRootScrollContainer);
|
|
28
29
|
const {
|
|
29
30
|
top
|
|
30
31
|
} = tableRootScrollContainer.getBoundingClientRect();
|
|
@@ -34,24 +35,16 @@ const ColumnResizeHandler = _ref => {
|
|
|
34
35
|
top
|
|
35
36
|
});
|
|
36
37
|
setMouseDownInfo(mouseDownInfo);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
}, [tableRootScrollContainer]);
|
|
38
|
+
}, [mouseDownEvent, tableRootScrollContainer]);
|
|
41
39
|
useEffect(() => {
|
|
42
|
-
if (!
|
|
43
|
-
if (initLeft !== left) {
|
|
44
|
-
setLeft(initLeft);
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
40
|
+
if (!isDraggingResizeHandler) return;
|
|
48
41
|
const onMouseMove = event => {
|
|
49
42
|
eventStopPropagation(event);
|
|
50
43
|
const mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, tableRootScrollContainer);
|
|
51
44
|
const newWidth = width + mouseMoveInfo.displacementX;
|
|
52
|
-
const columns = getTableColumns(editor,
|
|
45
|
+
const columns = getTableColumns(editor, table);
|
|
53
46
|
if (newWidth < TABLE_CELL_MIN_WIDTH) return;
|
|
54
|
-
const nextColumn = columns[
|
|
47
|
+
const nextColumn = columns[cellIndex + 1];
|
|
55
48
|
if (nextColumn) {
|
|
56
49
|
const nextColumnWidth = nextColumn.width - mouseMoveInfo.displacementX;
|
|
57
50
|
if (nextColumnWidth < TABLE_CELL_MIN_WIDTH) return;
|
|
@@ -69,30 +62,24 @@ const ColumnResizeHandler = _ref => {
|
|
|
69
62
|
};
|
|
70
63
|
const onMouseUp = event => {
|
|
71
64
|
eventStopPropagation(event);
|
|
72
|
-
setIsResizing(false);
|
|
73
65
|
setStyle({});
|
|
74
|
-
const columns = getTableColumns(editor,
|
|
66
|
+
const columns = getTableColumns(editor, table);
|
|
75
67
|
const newColumns = columns.slice(0);
|
|
76
|
-
const column = newColumns[
|
|
68
|
+
const column = newColumns[cellIndex];
|
|
77
69
|
const newWidth = width + left - initLeft;
|
|
78
|
-
newColumns[
|
|
70
|
+
newColumns[cellIndex] = _objectSpread(_objectSpread({}, column), {}, {
|
|
79
71
|
width: newWidth
|
|
80
72
|
});
|
|
81
|
-
const nextColumn = columns[
|
|
73
|
+
const nextColumn = columns[cellIndex + 1];
|
|
82
74
|
if (nextColumn) {
|
|
83
75
|
const nextColumnWidth = nextColumn.width - left + initLeft;
|
|
84
|
-
newColumns[
|
|
76
|
+
newColumns[cellIndex + 1] = _objectSpread(_objectSpread({}, nextColumn), {}, {
|
|
85
77
|
width: nextColumnWidth
|
|
86
78
|
});
|
|
87
79
|
}
|
|
88
|
-
updateColumnWidth(editor,
|
|
89
|
-
focusClosestCellWhenJustifyCellSize(
|
|
90
|
-
|
|
91
|
-
columnIndex: index,
|
|
92
|
-
table: element,
|
|
93
|
-
mouseDownInfo,
|
|
94
|
-
rowBottoms
|
|
95
|
-
});
|
|
80
|
+
updateColumnWidth(editor, table, newColumns);
|
|
81
|
+
focusClosestCellWhenJustifyCellSize(editor, adjustingCell);
|
|
82
|
+
hideResizeHandlers();
|
|
96
83
|
};
|
|
97
84
|
registerResizeEvents({
|
|
98
85
|
'mousemove': onMouseMove,
|
|
@@ -106,18 +93,11 @@ const ColumnResizeHandler = _ref => {
|
|
|
106
93
|
};
|
|
107
94
|
|
|
108
95
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
-
}, [
|
|
96
|
+
}, [isDraggingResizeHandler, mouseDownInfo, left, width, column, editor, table, cellIndex, initLeft, rowBottom]);
|
|
110
97
|
return /*#__PURE__*/React.createElement("div", {
|
|
111
|
-
className:
|
|
112
|
-
'resizing position-fixed': isResizing,
|
|
113
|
-
'position-absolute': !isResizing
|
|
114
|
-
}),
|
|
98
|
+
className: "table-cell-width-just resizing position-fixed",
|
|
115
99
|
contentEditable: false,
|
|
116
|
-
style:
|
|
117
|
-
left: left - 3.5,
|
|
118
|
-
top: 0
|
|
119
|
-
},
|
|
120
|
-
onMouseDown: onMouseDown,
|
|
100
|
+
style: style,
|
|
121
101
|
ref: resizeHandler
|
|
122
102
|
}, /*#__PURE__*/React.createElement("div", {
|
|
123
103
|
className: "table-cell-width-just-color-tip"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import React, { useRef, useState, useEffect,
|
|
2
|
+
import React, { useRef, useState, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
|
-
import classnames from 'classnames';
|
|
5
4
|
import { useTableRootContext } from '../hooks';
|
|
6
5
|
import { TABLE_CELL_MIN_WIDTH } from '../../constants';
|
|
7
6
|
import { focusClosestCellWhenJustifyCellSize, getTableColumns, updateColumnWidth } from '../../helpers';
|
|
@@ -10,21 +9,23 @@ const FirstColumnResizeHandler = _ref => {
|
|
|
10
9
|
let {
|
|
11
10
|
column,
|
|
12
11
|
left: initLeft,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
rowBottoms
|
|
12
|
+
table,
|
|
13
|
+
cellIndex,
|
|
14
|
+
rowBottoms,
|
|
15
|
+
hideResizeHandlers,
|
|
16
|
+
mouseDownEvent,
|
|
17
|
+
adjustingCell,
|
|
18
|
+
isDraggingResizeHandler
|
|
16
19
|
} = _ref;
|
|
17
20
|
const editor = useSlateStatic();
|
|
18
21
|
const resizeHandler = useRef(null);
|
|
19
22
|
const [left, setLeft] = useState(initLeft);
|
|
20
|
-
const [isResizing, setIsResizing] = useState(false);
|
|
21
23
|
const [mouseDownInfo, setMouseDownInfo] = useState({});
|
|
22
24
|
const [style, setStyle] = useState({});
|
|
23
25
|
const width = column.width;
|
|
24
26
|
const tableRootScrollContainer = useTableRootContext();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
const mouseDownInfo = getMouseDownInfo(mouseDownEvent, tableRootScrollContainer);
|
|
28
29
|
const {
|
|
29
30
|
top
|
|
30
31
|
} = tableRootScrollContainer.getBoundingClientRect();
|
|
@@ -34,17 +35,9 @@ const FirstColumnResizeHandler = _ref => {
|
|
|
34
35
|
top
|
|
35
36
|
});
|
|
36
37
|
setMouseDownInfo(mouseDownInfo);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
}, [tableRootScrollContainer]);
|
|
38
|
+
}, [mouseDownEvent, tableRootScrollContainer]);
|
|
41
39
|
useEffect(() => {
|
|
42
|
-
if (!
|
|
43
|
-
if (initLeft !== left) {
|
|
44
|
-
setLeft(initLeft);
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
40
|
+
if (!isDraggingResizeHandler) return;
|
|
48
41
|
const onMouseMove = event => {
|
|
49
42
|
eventStopPropagation(event);
|
|
50
43
|
const mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, tableRootScrollContainer);
|
|
@@ -63,23 +56,17 @@ const FirstColumnResizeHandler = _ref => {
|
|
|
63
56
|
};
|
|
64
57
|
const onMouseUp = event => {
|
|
65
58
|
eventStopPropagation(event);
|
|
66
|
-
setIsResizing(false);
|
|
67
59
|
setStyle({});
|
|
68
|
-
const columns = getTableColumns(editor,
|
|
60
|
+
const columns = getTableColumns(editor, table);
|
|
69
61
|
const newColumns = columns.slice(0);
|
|
70
|
-
const column = newColumns[
|
|
62
|
+
const column = newColumns[cellIndex];
|
|
71
63
|
const newWidth = width + left - initLeft;
|
|
72
|
-
newColumns[
|
|
64
|
+
newColumns[cellIndex] = _objectSpread(_objectSpread({}, column), {}, {
|
|
73
65
|
width: newWidth
|
|
74
66
|
});
|
|
75
|
-
updateColumnWidth(editor,
|
|
76
|
-
focusClosestCellWhenJustifyCellSize(
|
|
77
|
-
|
|
78
|
-
columnIndex: index,
|
|
79
|
-
table: element,
|
|
80
|
-
mouseDownInfo,
|
|
81
|
-
rowBottoms
|
|
82
|
-
});
|
|
67
|
+
updateColumnWidth(editor, table, newColumns);
|
|
68
|
+
focusClosestCellWhenJustifyCellSize(editor, adjustingCell);
|
|
69
|
+
hideResizeHandlers();
|
|
83
70
|
};
|
|
84
71
|
registerResizeEvents({
|
|
85
72
|
'mousemove': onMouseMove,
|
|
@@ -93,18 +80,11 @@ const FirstColumnResizeHandler = _ref => {
|
|
|
93
80
|
};
|
|
94
81
|
|
|
95
82
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
-
}, [
|
|
83
|
+
}, [isDraggingResizeHandler, mouseDownInfo, left, width, column, editor, table, cellIndex, initLeft, rowBottoms]);
|
|
97
84
|
return /*#__PURE__*/React.createElement("div", {
|
|
98
|
-
className:
|
|
99
|
-
'resizing position-fixed': isResizing,
|
|
100
|
-
'position-absolute': !isResizing
|
|
101
|
-
}),
|
|
85
|
+
className: "table-cell-width-just resizing position-fixed",
|
|
102
86
|
contentEditable: false,
|
|
103
|
-
style:
|
|
104
|
-
left: -3.5,
|
|
105
|
-
top: 0
|
|
106
|
-
},
|
|
107
|
-
onMouseDown: onMouseDown,
|
|
87
|
+
style: style,
|
|
108
88
|
ref: resizeHandler
|
|
109
89
|
}, /*#__PURE__*/React.createElement("div", {
|
|
110
90
|
className: "table-cell-width-just-color-tip"
|
|
@@ -1,57 +1,66 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
import React
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
4
|
import FirstColumnResizeHandler from './first-column-left-resize-handler';
|
|
5
5
|
import ColumnResizeHandler from './column-resize-handler';
|
|
6
6
|
import RowResizeHandler from './row-resize-handler';
|
|
7
7
|
import { getNode, findPath } from '../../../../core';
|
|
8
8
|
import { useResizeHandlersContext } from '../hooks';
|
|
9
|
-
import {
|
|
9
|
+
import { getTableColumns } from '../../helpers';
|
|
10
|
+
import { RESIZE_HANDLER_COLUMN, RESIZE_HANDLER_ROW, RESIZE_HANDLER_FIRST_COLUMN } from '../../constants';
|
|
10
11
|
const ResizeHandlers = _ref => {
|
|
11
12
|
let {
|
|
12
|
-
element
|
|
13
|
+
element,
|
|
14
|
+
resizeCellMaskInfo,
|
|
15
|
+
hideResizeHandlers,
|
|
16
|
+
isDraggingResizeHandler
|
|
13
17
|
} = _ref;
|
|
18
|
+
const {
|
|
19
|
+
rowIndex,
|
|
20
|
+
cellIndex,
|
|
21
|
+
top,
|
|
22
|
+
height,
|
|
23
|
+
left,
|
|
24
|
+
mouseDownEvent,
|
|
25
|
+
displayType,
|
|
26
|
+
cell
|
|
27
|
+
} = resizeCellMaskInfo;
|
|
14
28
|
const editor = useSlateStatic();
|
|
15
29
|
const tablePath = findPath(editor, element);
|
|
16
30
|
if (!tablePath) return null;
|
|
17
31
|
const table = getNode(editor, tablePath);
|
|
18
32
|
if (!table) return null;
|
|
19
|
-
const [rowBottoms, setRowBottoms] = useState([]);
|
|
20
33
|
const columns = useResizeHandlersContext() || getTableColumns(editor, element);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return /*#__PURE__*/React.createElement(RowResizeHandler, {
|
|
32
|
-
key: index,
|
|
33
|
-
row: row,
|
|
34
|
-
rowBottoms: rowBottoms[index],
|
|
35
|
-
index: index,
|
|
36
|
-
element: element
|
|
37
|
-
});
|
|
38
|
-
}), /*#__PURE__*/React.createElement(FirstColumnResizeHandler, {
|
|
34
|
+
const rowBottom = top + height;
|
|
35
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, displayType === RESIZE_HANDLER_ROW && /*#__PURE__*/React.createElement(RowResizeHandler, {
|
|
36
|
+
initRowBottom: rowBottom,
|
|
37
|
+
rowIndex: rowIndex,
|
|
38
|
+
table: element,
|
|
39
|
+
hideResizeHandlers: hideResizeHandlers,
|
|
40
|
+
mouseDownEvent: mouseDownEvent,
|
|
41
|
+
adjustingCell: cell,
|
|
42
|
+
isDraggingResizeHandler: isDraggingResizeHandler
|
|
43
|
+
}), displayType === RESIZE_HANDLER_FIRST_COLUMN && /*#__PURE__*/React.createElement(FirstColumnResizeHandler, {
|
|
39
44
|
key: "column-0-left",
|
|
40
45
|
column: columns[0],
|
|
41
46
|
left: 0,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
rowBottoms:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
cellIndex: 0,
|
|
48
|
+
table: element,
|
|
49
|
+
rowBottoms: rowBottom,
|
|
50
|
+
hideResizeHandlers: hideResizeHandlers,
|
|
51
|
+
mouseDownEvent: mouseDownEvent,
|
|
52
|
+
adjustingCell: cell,
|
|
53
|
+
isDraggingResizeHandler: isDraggingResizeHandler
|
|
54
|
+
}), displayType === RESIZE_HANDLER_COLUMN && /*#__PURE__*/React.createElement(ColumnResizeHandler, {
|
|
55
|
+
rowBottom: rowBottom,
|
|
56
|
+
column: element.columns[cellIndex],
|
|
57
|
+
left: left,
|
|
58
|
+
cellIndex: cellIndex,
|
|
59
|
+
table: element,
|
|
60
|
+
hideResizeHandlers: hideResizeHandlers,
|
|
61
|
+
mouseDownEvent: mouseDownEvent,
|
|
62
|
+
adjustingCell: cell,
|
|
63
|
+
isDraggingResizeHandler: isDraggingResizeHandler
|
|
55
64
|
}));
|
|
56
65
|
};
|
|
57
66
|
export default ResizeHandlers;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState, useRef,
|
|
2
|
-
import classnames from 'classnames';
|
|
1
|
+
import React, { useEffect, useState, useRef, useLayoutEffect } from 'react';
|
|
3
2
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
3
|
import { ReactEditor } from '@seafile/slate-react';
|
|
5
4
|
import { TABLE_ROW_MIN_HEIGHT } from '../../constants';
|
|
@@ -8,32 +7,33 @@ import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResiz
|
|
|
8
7
|
import { useScrollContext } from '../../../../../hooks/use-scroll-context';
|
|
9
8
|
const RowResizeHandler = _ref => {
|
|
10
9
|
let {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
rowIndex,
|
|
11
|
+
initRowBottom = 0,
|
|
12
|
+
table,
|
|
13
|
+
hideResizeHandlers,
|
|
14
|
+
mouseDownEvent,
|
|
15
|
+
adjustingCell,
|
|
16
|
+
isDraggingResizeHandler
|
|
15
17
|
} = _ref;
|
|
16
18
|
const editor = useSlateStatic();
|
|
17
19
|
const [rowBottom, setRowBottom] = useState(initRowBottom);
|
|
18
|
-
const [isResizing, setIsResizing] = useState(false);
|
|
19
20
|
const [mouseDownInfo, setMouseDownInfo] = useState({});
|
|
20
21
|
const [style, setStyle] = useState({});
|
|
21
|
-
const
|
|
22
|
+
const row = table.children[rowIndex];
|
|
23
|
+
const rowHeight = getRowHeight(row, rowIndex);
|
|
22
24
|
const tableRow = useRef(rowHeight);
|
|
23
25
|
const [height, setHeight] = useState(rowHeight);
|
|
24
26
|
const scrollContent = useScrollContext();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const mouseDownInfo = getMouseDownInfo(event, scrollContent.current);
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
const mouseDownInfo = getMouseDownInfo(mouseDownEvent, scrollContent.current);
|
|
28
29
|
setMouseDownInfo(mouseDownInfo);
|
|
30
|
+
const lastRowOffset = rowIndex === table.children.length - 1 ? -2 : 0;
|
|
29
31
|
setStyle({
|
|
30
|
-
top: rowBottom
|
|
32
|
+
top: rowBottom + lastRowOffset
|
|
31
33
|
});
|
|
32
|
-
|
|
33
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
-
}, [rowBottom]);
|
|
34
|
+
}, [mouseDownEvent, rowBottom, rowIndex, scrollContent, table.children.length]);
|
|
35
35
|
useEffect(() => {
|
|
36
|
-
if (!
|
|
36
|
+
if (!isDraggingResizeHandler) return;
|
|
37
37
|
const onMouseMove = event => {
|
|
38
38
|
eventStopPropagation(event);
|
|
39
39
|
const mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, scrollContent.current);
|
|
@@ -41,20 +41,15 @@ const RowResizeHandler = _ref => {
|
|
|
41
41
|
const validHeight = Math.max(TABLE_ROW_MIN_HEIGHT, newHeight);
|
|
42
42
|
setHeight(validHeight);
|
|
43
43
|
setStyle({
|
|
44
|
-
top: rowBottom - tableRow.current + validHeight
|
|
44
|
+
top: rowBottom - tableRow.current + validHeight
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
const onMouseUp = event => {
|
|
48
48
|
eventStopPropagation(event);
|
|
49
|
-
setIsResizing(false);
|
|
50
49
|
tableRow.current = height;
|
|
51
50
|
updateTableRowHeight(editor, row, height);
|
|
52
|
-
focusClosestCellWhenJustifyCellSize(
|
|
53
|
-
|
|
54
|
-
rowIndex: index,
|
|
55
|
-
table: element,
|
|
56
|
-
mouseDownInfo
|
|
57
|
-
});
|
|
51
|
+
focusClosestCellWhenJustifyCellSize(editor, adjustingCell);
|
|
52
|
+
hideResizeHandlers();
|
|
58
53
|
};
|
|
59
54
|
registerResizeEvents({
|
|
60
55
|
'mousemove': onMouseMove,
|
|
@@ -68,7 +63,7 @@ const RowResizeHandler = _ref => {
|
|
|
68
63
|
};
|
|
69
64
|
|
|
70
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
-
}, [
|
|
66
|
+
}, [isDraggingResizeHandler, mouseDownInfo, rowBottom, table, height]);
|
|
72
67
|
useEffect(() => {
|
|
73
68
|
const cell = row.children.filter(cell => !cell.is_combined && (!cell.rowspan || cell.rowspan == 1))[0];
|
|
74
69
|
if (!cell) return;
|
|
@@ -79,14 +74,9 @@ const RowResizeHandler = _ref => {
|
|
|
79
74
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
75
|
}, [row, initRowBottom]);
|
|
81
76
|
return /*#__PURE__*/React.createElement("div", {
|
|
82
|
-
className:
|
|
83
|
-
'resizing': isResizing
|
|
84
|
-
}),
|
|
77
|
+
className: "table-row-height-just position-absolute resizing",
|
|
85
78
|
contentEditable: false,
|
|
86
|
-
style:
|
|
87
|
-
top: rowBottom - 2.5
|
|
88
|
-
},
|
|
89
|
-
onMouseDown: onMouseDown
|
|
79
|
+
style: style
|
|
90
80
|
}, /*#__PURE__*/React.createElement("div", {
|
|
91
81
|
className: "table-row-height-just-color-tip"
|
|
92
82
|
}));
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import EventBus from '../../../../../utils/event-bus';
|
|
4
|
+
import { INTERNAL_EVENT } from '../../../../../constants';
|
|
5
|
+
import { getResizeMaskCellInfo } from '../../helpers';
|
|
6
|
+
import { RESIZE_MASK_TOP, RESIZE_MASK_RIGHT, RESIZE_MASK_BOTTOM, RESIZE_MASK_LEFT, RESIZE_HANDLER_ROW, RESIZE_HANDLER_COLUMN, RESIZE_HANDLER_FIRST_COLUMN } from '../../constants';
|
|
7
|
+
import '../index.css';
|
|
8
|
+
const ResizeMask = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
editor,
|
|
11
|
+
table,
|
|
12
|
+
handleShowResizeHandler,
|
|
13
|
+
hideResizeHandlers,
|
|
14
|
+
handlerStartDragging,
|
|
15
|
+
isDraggingResizeHandler
|
|
16
|
+
} = _ref;
|
|
17
|
+
const [cellInfo, setCellInfo] = useState({});
|
|
18
|
+
const [maskStyle, setMaskStyle] = useState({});
|
|
19
|
+
const handleCellMouseMove = useCallback(cellInfo => {
|
|
20
|
+
const {
|
|
21
|
+
mouseDownEvent,
|
|
22
|
+
rowIndex,
|
|
23
|
+
cellIndex,
|
|
24
|
+
tableId
|
|
25
|
+
} = cellInfo;
|
|
26
|
+
if (table.id !== tableId) return;
|
|
27
|
+
const resizeMaskCellInfo = getResizeMaskCellInfo(editor, table, rowIndex, cellIndex);
|
|
28
|
+
const {
|
|
29
|
+
width,
|
|
30
|
+
height,
|
|
31
|
+
top,
|
|
32
|
+
left
|
|
33
|
+
} = resizeMaskCellInfo;
|
|
34
|
+
setMaskStyle({
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
top,
|
|
38
|
+
left
|
|
39
|
+
});
|
|
40
|
+
setCellInfo(_objectSpread(_objectSpread({}, resizeMaskCellInfo), {}, {
|
|
41
|
+
mouseDownEvent
|
|
42
|
+
}));
|
|
43
|
+
}, [editor, table]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const eventBus = EventBus.getInstance();
|
|
46
|
+
const unSubscribe = eventBus.subscribe(INTERNAL_EVENT.TABLE_CELL_MOUSE_ENTER, handleCellMouseMove);
|
|
47
|
+
return () => {
|
|
48
|
+
unSubscribe();
|
|
49
|
+
};
|
|
50
|
+
}, [handleCellMouseMove]);
|
|
51
|
+
const getHandlerDisplayInfo = useCallback(mode => {
|
|
52
|
+
let resizeHandlerInfo = {};
|
|
53
|
+
if (mode === RESIZE_MASK_BOTTOM) resizeHandlerInfo = _objectSpread(_objectSpread(_objectSpread({}, cellInfo), maskStyle), {}, {
|
|
54
|
+
displayType: RESIZE_HANDLER_ROW
|
|
55
|
+
});
|
|
56
|
+
if (mode === RESIZE_MASK_RIGHT) resizeHandlerInfo = _objectSpread(_objectSpread(_objectSpread({}, cellInfo), maskStyle), {}, {
|
|
57
|
+
displayType: RESIZE_HANDLER_COLUMN
|
|
58
|
+
});
|
|
59
|
+
if (mode === RESIZE_MASK_LEFT) {
|
|
60
|
+
const {
|
|
61
|
+
cellIndex,
|
|
62
|
+
rowIndex,
|
|
63
|
+
focusCellIndex,
|
|
64
|
+
mouseDownEvent
|
|
65
|
+
} = cellInfo;
|
|
66
|
+
const calculateCellIndex = cellIndex === 0 ? 0 : cellIndex - 1;
|
|
67
|
+
const resizeMaskCellInfo = getResizeMaskCellInfo(editor, table, rowIndex, calculateCellIndex);
|
|
68
|
+
const displayType = focusCellIndex === 0 ? RESIZE_HANDLER_FIRST_COLUMN : RESIZE_HANDLER_COLUMN;
|
|
69
|
+
resizeHandlerInfo = _objectSpread(_objectSpread({
|
|
70
|
+
displayType
|
|
71
|
+
}, resizeMaskCellInfo), {}, {
|
|
72
|
+
mouseDownEvent
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (mode === RESIZE_MASK_TOP) {
|
|
76
|
+
const {
|
|
77
|
+
rowIndex,
|
|
78
|
+
cellIndex,
|
|
79
|
+
mouseDownEvent
|
|
80
|
+
} = cellInfo;
|
|
81
|
+
const resizeMaskCellInfo = getResizeMaskCellInfo(editor, table, rowIndex - 1, cellIndex);
|
|
82
|
+
resizeHandlerInfo = _objectSpread(_objectSpread({
|
|
83
|
+
displayType: RESIZE_HANDLER_ROW
|
|
84
|
+
}, resizeMaskCellInfo), {}, {
|
|
85
|
+
mouseDownEvent: mouseDownEvent
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return resizeHandlerInfo;
|
|
89
|
+
}, [cellInfo, editor, maskStyle, table]);
|
|
90
|
+
const handleMouseOver = useCallback((event, mode) => {
|
|
91
|
+
event.stopPropagation();
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
if (isDraggingResizeHandler) return;
|
|
94
|
+
const handlerInfo = getHandlerDisplayInfo(mode);
|
|
95
|
+
handleShowResizeHandler(handlerInfo);
|
|
96
|
+
}, [getHandlerDisplayInfo, handleShowResizeHandler, isDraggingResizeHandler]);
|
|
97
|
+
const handleMouseDown = useCallback(event => {
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
handlerStartDragging();
|
|
101
|
+
}, [handlerStartDragging]);
|
|
102
|
+
const handleMouseOut = useCallback(event => {
|
|
103
|
+
event.stopPropagation();
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
if (isDraggingResizeHandler) return;
|
|
106
|
+
hideResizeHandlers();
|
|
107
|
+
}, [hideResizeHandlers, isDraggingResizeHandler]);
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: "sdoc-table-resize-mask",
|
|
110
|
+
style: maskStyle
|
|
111
|
+
}, cellInfo.rowIndex !== 0 && /*#__PURE__*/React.createElement("div", {
|
|
112
|
+
onMouseOut: handleMouseOut,
|
|
113
|
+
onMouseDown: handleMouseDown,
|
|
114
|
+
onMouseOver: e => handleMouseOver(e, RESIZE_MASK_TOP),
|
|
115
|
+
className: "sdoc-table-resize-top"
|
|
116
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
117
|
+
onMouseOut: handleMouseOut,
|
|
118
|
+
onMouseDown: handleMouseDown,
|
|
119
|
+
onMouseOver: e => handleMouseOver(e, RESIZE_MASK_RIGHT),
|
|
120
|
+
className: "sdoc-table-resize-right"
|
|
121
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
122
|
+
onMouseOut: handleMouseOut,
|
|
123
|
+
onMouseDown: handleMouseDown,
|
|
124
|
+
onMouseOver: e => handleMouseOver(e, RESIZE_MASK_BOTTOM),
|
|
125
|
+
className: "sdoc-table-resize-bottom"
|
|
126
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
onMouseOut: handleMouseOut,
|
|
128
|
+
onMouseDown: handleMouseDown,
|
|
129
|
+
onMouseOver: e => handleMouseOver(e, RESIZE_MASK_LEFT),
|
|
130
|
+
className: "sdoc-table-resize-left"
|
|
131
|
+
}));
|
|
132
|
+
};
|
|
133
|
+
export default ResizeMask;
|