@seafile/sdoc-editor 0.1.56 → 0.1.57
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/editor.js +1 -1
- package/dist/basic-sdk/extension/constants/element-type.js +5 -1
- package/dist/basic-sdk/extension/constants/index.js +14 -2
- package/dist/basic-sdk/extension/core/queries/index.js +8 -0
- package/dist/basic-sdk/extension/plugins/blockquote/render-elem.js +6 -1
- package/dist/basic-sdk/extension/plugins/check-list/render-elem.js +8 -4
- package/dist/basic-sdk/extension/plugins/header/render-elem.js +6 -2
- package/dist/basic-sdk/extension/plugins/html/plugin.js +8 -6
- package/dist/basic-sdk/extension/plugins/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/list/render-elem.js +16 -2
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +5 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +159 -22
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +3 -3
- package/dist/basic-sdk/extension/plugins/table/plugin.js +2 -2
- package/dist/basic-sdk/extension/plugins/table/render/hooks.js +17 -0
- package/dist/basic-sdk/extension/plugins/table/render/index.css +137 -0
- package/dist/basic-sdk/extension/plugins/table/render/index.js +161 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +48 -14
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +122 -7
- package/dist/basic-sdk/extension/plugins/table/render/resize-handler.js +109 -0
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers.js +27 -0
- package/dist/basic-sdk/extension/plugins/table/render/table-root.js +38 -0
- package/dist/basic-sdk/extension/plugins/table/render-elem.js +1 -1
- package/dist/basic-sdk/extension/plugins/text-align/helpers.js +43 -0
- package/dist/basic-sdk/extension/plugins/text-align/index.js +2 -0
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +105 -0
- package/dist/basic-sdk/extension/plugins/text-align/menu/style.css +61 -0
- package/dist/basic-sdk/extension/render/render-element.js +9 -3
- package/dist/basic-sdk/extension/toolbar/index.js +3 -0
- package/dist/basic-sdk/utils/mouse-event.js +59 -0
- package/dist/basic-sdk/utils/object-utils.js +1 -0
- package/package.json +1 -1
- package/public/media/sdoc-editor-font.css +2 -2
- package/dist/basic-sdk/extension/plugins/table/render/context.js +0 -5
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.css +0 -72
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.js +0 -94
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
.sdoc-table-wrapper {
|
|
2
|
+
width: 100%;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.sdoc-table-wrapper .sdoc-table-scroll-wrapper {
|
|
7
|
+
max-width: 100%;
|
|
8
|
+
width: fit-content;
|
|
9
|
+
overflow-x: auto;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.sdoc-table-wrapper.scroll .sdoc-table-scroll-wrapper.scroll-at-right::before,
|
|
13
|
+
.sdoc-table-wrapper.scroll .sdoc-table-scroll-wrapper.scroll-at-center::before {
|
|
14
|
+
content: '';
|
|
15
|
+
position: absolute;
|
|
16
|
+
pointer-events: none;
|
|
17
|
+
top: 0;
|
|
18
|
+
left: 0;
|
|
19
|
+
width: 8px;
|
|
20
|
+
height: 100%;
|
|
21
|
+
background: linear-gradient(to left, transparent, rgba(0, 0, 0, .1));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sdoc-table-wrapper.scroll .sdoc-table-scroll-wrapper.scroll-at-center::after,
|
|
25
|
+
.sdoc-table-wrapper.scroll .sdoc-table-scroll-wrapper.scroll-at-left::after {
|
|
26
|
+
content: '';
|
|
27
|
+
position: absolute;
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
top: 0;
|
|
30
|
+
right: 0;
|
|
31
|
+
width: 8px;
|
|
32
|
+
height: 100%;
|
|
33
|
+
background: linear-gradient(to right, transparent, rgba(0, 0, 0, .1));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.sdoc-table-wrapper .sdoc-table-container {
|
|
37
|
+
width: fit-content;
|
|
38
|
+
display: table;
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.sdoc-table-wrapper .table-row {
|
|
43
|
+
display: table-row ;
|
|
44
|
+
height: auto;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.sdoc-table-wrapper .table-cell {
|
|
48
|
+
display: table-cell;
|
|
49
|
+
padding: 10px 10px;
|
|
50
|
+
border-right: 1px solid #ccc;
|
|
51
|
+
border-bottom: 1px solid #ccc;
|
|
52
|
+
word-break: break-all;
|
|
53
|
+
line-height: 1.5;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.sdoc-table-wrapper .table-row:first-child .table-cell {
|
|
57
|
+
border-top: 1px solid #ddd;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.sdoc-table-wrapper .table-row .table-cell:first-child {
|
|
61
|
+
border-left: 1px solid #ddd;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.sdoc-table-wrapper .cell-selected {
|
|
65
|
+
caret-color: transparent;
|
|
66
|
+
background-color: #fff4e6;
|
|
67
|
+
position: relative;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.sdoc-table-wrapper .cell-light-height-top-border::before {
|
|
71
|
+
content: '';
|
|
72
|
+
position: absolute;
|
|
73
|
+
top: -1px;
|
|
74
|
+
left: 0;
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: 2px;
|
|
77
|
+
border-top: 1px double #ffa94d !important;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.sdoc-table-wrapper .cell-light-height-bottom-border {
|
|
81
|
+
border-bottom: 1px double #ffa94d !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.sdoc-table-wrapper .cell-light-height-left-border::after {
|
|
85
|
+
content: '';
|
|
86
|
+
position: absolute;
|
|
87
|
+
top: 0px;
|
|
88
|
+
left: -1px;
|
|
89
|
+
width: 2px;
|
|
90
|
+
height: 100%;
|
|
91
|
+
border-left: 1px double #ffa94d !important;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.sdoc-table-wrapper .cell-light-height-right-border {
|
|
95
|
+
border-right: 1px double #ffa94d !important;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.sdoc-table-wrapper .table-row-height-just {
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: 5px;
|
|
101
|
+
bottom: -2.5px;
|
|
102
|
+
left: 0;
|
|
103
|
+
z-index: 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.sdoc-table-wrapper .table-row-height-just:hover {
|
|
107
|
+
cursor: row-resize;
|
|
108
|
+
z-index: 2;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.sdoc-table-wrapper .table-row-height-just.resizing .table-row-height-just-color-tip {
|
|
112
|
+
margin-top: 1.5;
|
|
113
|
+
height: 2px;
|
|
114
|
+
width: 100%;
|
|
115
|
+
background-color: #2d7ff9;
|
|
116
|
+
border-radius: 1px;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.sdoc-table-wrapper .table-cell-width-just {
|
|
120
|
+
height: 100%;
|
|
121
|
+
width: 5px;
|
|
122
|
+
top: 0;
|
|
123
|
+
z-index: 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.sdoc-table-wrapper .table-cell-width-just:hover {
|
|
127
|
+
cursor: col-resize;
|
|
128
|
+
z-index: 2;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.sdoc-table-wrapper .table-cell-width-just.resizing .table-cell-width-just-color-tip {
|
|
132
|
+
margin-left: 1.5px;
|
|
133
|
+
height: 100%;
|
|
134
|
+
width: 2px;
|
|
135
|
+
background-color: #2d7ff9;
|
|
136
|
+
border-radius: 1px;
|
|
137
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import throttle from 'lodash.throttle';
|
|
5
|
+
import { useSelected, useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
6
|
+
import { EMPTY_SELECTED_RANGE } from '../constants';
|
|
7
|
+
import { ResizeHandlersContext, TableContext, SettingSelectRangeContext } from './hooks';
|
|
8
|
+
import EventBus from '../../../../utils/event-bus';
|
|
9
|
+
import { EXTERNAL_EVENT } from '../../../../../constants';
|
|
10
|
+
import { getTableColumns, setTableSelectedRange, getFirstTableCell } from '../helpers';
|
|
11
|
+
import ObjectUtils from '../../../../utils/object-utils';
|
|
12
|
+
import ResizeHandlers from './resize-handlers';
|
|
13
|
+
import { registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
|
|
14
|
+
import TableRoot from './table-root';
|
|
15
|
+
import './index.css';
|
|
16
|
+
var Table = function Table(_ref) {
|
|
17
|
+
var className = _ref.className,
|
|
18
|
+
attributes = _ref.attributes,
|
|
19
|
+
children = _ref.children,
|
|
20
|
+
element = _ref.element;
|
|
21
|
+
var isSelected = useSelected();
|
|
22
|
+
var editor = useSlateStatic();
|
|
23
|
+
var table = useRef(null);
|
|
24
|
+
var _useState = useState(0),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
startRowIndex = _useState2[0],
|
|
27
|
+
setStartRowIndex = _useState2[1];
|
|
28
|
+
var _useState3 = useState(0),
|
|
29
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
30
|
+
startColIndex = _useState4[0],
|
|
31
|
+
setStartColIndex = _useState4[1];
|
|
32
|
+
var _useState5 = useState(false),
|
|
33
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
34
|
+
isSettingSelectRange = _useState6[0],
|
|
35
|
+
setIsSettingSelectRange = _useState6[1];
|
|
36
|
+
var _useState7 = useState(EMPTY_SELECTED_RANGE),
|
|
37
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
38
|
+
selectedRange = _useState8[0],
|
|
39
|
+
setSelectedRange = _useState8[1];
|
|
40
|
+
var oldColumns = getTableColumns(editor, element);
|
|
41
|
+
var _useState9 = useState(oldColumns),
|
|
42
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
43
|
+
columns = _useState10[0],
|
|
44
|
+
setColumns = _useState10[1];
|
|
45
|
+
var onMouseDown = useCallback(function (event) {
|
|
46
|
+
if (event.button !== 0) return; // right click not deal
|
|
47
|
+
setIsSettingSelectRange(true);
|
|
48
|
+
var tableCell = getFirstTableCell(event.target);
|
|
49
|
+
setStartRowIndex(Number(tableCell.getAttribute('row-index')));
|
|
50
|
+
setStartColIndex(Number(tableCell.getAttribute('cell-index')));
|
|
51
|
+
setSelectedRange(EMPTY_SELECTED_RANGE);
|
|
52
|
+
setTableSelectedRange(editor, EMPTY_SELECTED_RANGE);
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
+
}, []);
|
|
56
|
+
var resetState = useCallback(function () {
|
|
57
|
+
setIsSettingSelectRange(false);
|
|
58
|
+
setStartColIndex(0);
|
|
59
|
+
setStartRowIndex(0);
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
+
}, []);
|
|
63
|
+
useEffect(function () {
|
|
64
|
+
setColumns(getTableColumns(editor, element));
|
|
65
|
+
var eventBus = EventBus.getInstance();
|
|
66
|
+
var cancelTableSelectRangeSubscribe = eventBus.subscribe(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE, clearRange);
|
|
67
|
+
if (isSettingSelectRange) {
|
|
68
|
+
var onMouseMove = throttle(function (event) {
|
|
69
|
+
// if event.target not in the table, clear the mouseMove event
|
|
70
|
+
if (!table.current.contains(event.target)) return;
|
|
71
|
+
var tableCell = getFirstTableCell(event.target);
|
|
72
|
+
var endRowIndex = Number(tableCell.getAttribute('row-index'));
|
|
73
|
+
var endColIndex = Number(tableCell.getAttribute('cell-index'));
|
|
74
|
+
var newSelectedRange = {
|
|
75
|
+
minRowIndex: Math.min(startRowIndex, endRowIndex),
|
|
76
|
+
maxRowIndex: Math.max(startRowIndex, endRowIndex),
|
|
77
|
+
minColIndex: Math.min(startColIndex, endColIndex),
|
|
78
|
+
maxColIndex: Math.max(startColIndex, endColIndex)
|
|
79
|
+
};
|
|
80
|
+
if (!ObjectUtils.isSameObject(selectedRange, EMPTY_SELECTED_RANGE)) {
|
|
81
|
+
window.getSelection().collapseToEnd();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// same cell
|
|
85
|
+
if (newSelectedRange.minRowIndex === newSelectedRange.maxRowIndex && newSelectedRange.minColIndex === newSelectedRange.maxColIndex) {
|
|
86
|
+
setSelectedRange(EMPTY_SELECTED_RANGE);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
setSelectedRange(newSelectedRange);
|
|
90
|
+
}, 200);
|
|
91
|
+
var onMouseUp = function onMouseUp(event) {
|
|
92
|
+
if (!ObjectUtils.isSameObject(selectedRange, EMPTY_SELECTED_RANGE)) {
|
|
93
|
+
setTableSelectedRange(editor, selectedRange);
|
|
94
|
+
}
|
|
95
|
+
resetState();
|
|
96
|
+
};
|
|
97
|
+
registerResizeEvents({
|
|
98
|
+
'mousemove': onMouseMove,
|
|
99
|
+
'mouseup': onMouseUp
|
|
100
|
+
});
|
|
101
|
+
return function () {
|
|
102
|
+
cancelTableSelectRangeSubscribe();
|
|
103
|
+
unregisterResizeEvents({
|
|
104
|
+
'mousemove': onMouseMove,
|
|
105
|
+
'mouseup': onMouseUp
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return function () {
|
|
110
|
+
cancelTableSelectRangeSubscribe();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
+
}, [element, isSettingSelectRange, selectedRange, element]);
|
|
115
|
+
var clearRange = useCallback(function () {
|
|
116
|
+
setSelectedRange(EMPTY_SELECTED_RANGE);
|
|
117
|
+
|
|
118
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
119
|
+
}, []);
|
|
120
|
+
return /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
121
|
+
value: selectedRange
|
|
122
|
+
}, /*#__PURE__*/React.createElement(ResizeHandlersContext.Provider, {
|
|
123
|
+
value: columns
|
|
124
|
+
}, /*#__PURE__*/React.createElement(SettingSelectRangeContext.Provider, {
|
|
125
|
+
value: isSettingSelectRange
|
|
126
|
+
}, /*#__PURE__*/React.createElement(TableRoot, {
|
|
127
|
+
columns: columns,
|
|
128
|
+
attributes: attributes
|
|
129
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
130
|
+
className: classnames('sdoc-table-container position-relative', attributes.className, className, {
|
|
131
|
+
'sdoc-table-selected': isSelected
|
|
132
|
+
}),
|
|
133
|
+
onMouseDown: onMouseDown,
|
|
134
|
+
ref: table,
|
|
135
|
+
"data-id": element.id
|
|
136
|
+
}, children, !isSettingSelectRange && /*#__PURE__*/React.createElement(ResizeHandlers, {
|
|
137
|
+
element: element
|
|
138
|
+
}))))));
|
|
139
|
+
};
|
|
140
|
+
function renderTable(props) {
|
|
141
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
142
|
+
var readOnly = useReadOnly();
|
|
143
|
+
if (readOnly) {
|
|
144
|
+
var className = props.className,
|
|
145
|
+
attributes = props.attributes,
|
|
146
|
+
children = props.children,
|
|
147
|
+
element = props.element;
|
|
148
|
+
|
|
149
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
150
|
+
var editor = useSlateStatic();
|
|
151
|
+
return /*#__PURE__*/React.createElement(TableRoot, {
|
|
152
|
+
columns: getTableColumns(editor, element),
|
|
153
|
+
attributes: attributes
|
|
154
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
155
|
+
className: classnames('sdoc-table-container', attributes.className, className),
|
|
156
|
+
"data-id": element.id
|
|
157
|
+
}, children));
|
|
158
|
+
}
|
|
159
|
+
return /*#__PURE__*/React.createElement(Table, props);
|
|
160
|
+
}
|
|
161
|
+
export default renderTable;
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import classnames from 'classnames';
|
|
3
|
-
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
|
+
import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
4
5
|
import ObjectUtils from '../../../../utils/object-utils';
|
|
5
6
|
import { STYLE_KEY } from '../../../constants';
|
|
6
|
-
import {
|
|
7
|
-
import { useTableContext } from './
|
|
7
|
+
import { findPath } from '../../../core';
|
|
8
|
+
import { useResizeHandlersContext, useTableContext } from './hooks';
|
|
9
|
+
import { EMPTY_SELECTED_RANGE } from '../constants';
|
|
10
|
+
import { getTableColumns, getCellColumn } from '../helpers';
|
|
8
11
|
var TableCell = function TableCell(_ref) {
|
|
9
12
|
var attributes = _ref.attributes,
|
|
10
13
|
element = _ref.element,
|
|
11
14
|
children = _ref.children;
|
|
12
15
|
var editor = useSlateStatic();
|
|
13
|
-
var selectedRange = useTableContext();
|
|
14
|
-
var cellPath =
|
|
15
|
-
|
|
16
|
-
var cellValue = element.children[0];
|
|
17
|
-
var style = attributes.style || {};
|
|
18
|
-
if (ObjectUtils.hasProperty(cellValue, STYLE_KEY.TEXT_ALIGN)) {
|
|
19
|
-
style[STYLE_KEY.TEXT_ALIGN] = cellValue[STYLE_KEY.TEXT_ALIGN];
|
|
20
|
-
}
|
|
16
|
+
var selectedRange = useTableContext() || EMPTY_SELECTED_RANGE;
|
|
17
|
+
var cellPath = findPath(editor, element, [0, 0]);
|
|
18
|
+
var columns = useResizeHandlersContext() || getTableColumns(editor, element);
|
|
21
19
|
var pathLength = cellPath.length;
|
|
22
20
|
var rowIndex = cellPath[pathLength - 2];
|
|
23
21
|
var cellIndex = cellPath[pathLength - 1];
|
|
22
|
+
var column = columns ? columns[cellIndex] : {};
|
|
23
|
+
var columnWidth = (column === null || column === void 0 ? void 0 : column.width) || 0;
|
|
24
|
+
var style = attributes.style || {};
|
|
25
|
+
if (ObjectUtils.hasProperty(element.style, STYLE_KEY.TEXT_ALIGN)) {
|
|
26
|
+
style[STYLE_KEY.TEXT_ALIGN] = element.style[STYLE_KEY.TEXT_ALIGN];
|
|
27
|
+
}
|
|
24
28
|
var minColIndex = selectedRange.minColIndex,
|
|
25
29
|
maxColIndex = selectedRange.maxColIndex,
|
|
26
30
|
minRowIndex = selectedRange.minRowIndex,
|
|
@@ -31,9 +35,12 @@ var TableCell = function TableCell(_ref) {
|
|
|
31
35
|
var isSelectedLastCell = isSelected && cellIndex === maxColIndex;
|
|
32
36
|
var isSelectedFirstRow = isSelected && rowIndex === minRowIndex;
|
|
33
37
|
var isSelectedLastRow = isSelected && rowIndex === maxRowIndex;
|
|
34
|
-
return /*#__PURE__*/React.createElement("
|
|
35
|
-
style: style,
|
|
36
|
-
|
|
38
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
39
|
+
style: _objectSpread(_objectSpread(_objectSpread({}, style), element.style), {}, {
|
|
40
|
+
minWidth: columnWidth,
|
|
41
|
+
width: columnWidth
|
|
42
|
+
}),
|
|
43
|
+
className: classnames('table-cell', attributes.className, {
|
|
37
44
|
'cell-selected': isSelected,
|
|
38
45
|
'cell-light-height-left-border': isSelectedFirstCell,
|
|
39
46
|
'cell-light-height-right-border': isSelectedLastCell,
|
|
@@ -46,6 +53,33 @@ var TableCell = function TableCell(_ref) {
|
|
|
46
53
|
}), children);
|
|
47
54
|
};
|
|
48
55
|
function renderTableCell(props) {
|
|
56
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
57
|
+
var readOnly = useReadOnly();
|
|
58
|
+
if (readOnly) {
|
|
59
|
+
var attributes = props.attributes,
|
|
60
|
+
children = props.children,
|
|
61
|
+
element = props.element;
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
64
|
+
var editor = useSlateStatic();
|
|
65
|
+
var cellPath = findPath(editor, element);
|
|
66
|
+
if (!cellPath) return null;
|
|
67
|
+
|
|
68
|
+
// const cellValue = element;
|
|
69
|
+
var style = attributes.style || {};
|
|
70
|
+
if (ObjectUtils.hasProperty(element, STYLE_KEY.TEXT_ALIGN)) {
|
|
71
|
+
style[STYLE_KEY.TEXT_ALIGN] = element[STYLE_KEY.TEXT_ALIGN];
|
|
72
|
+
}
|
|
73
|
+
var column = getCellColumn(editor, element);
|
|
74
|
+
var width = column.width;
|
|
75
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
76
|
+
style: _objectSpread(_objectSpread(_objectSpread({}, style), element.style), {}, {
|
|
77
|
+
width: width
|
|
78
|
+
}),
|
|
79
|
+
className: classnames('table-cell', attributes.className),
|
|
80
|
+
"data-id": element.id
|
|
81
|
+
}), children);
|
|
82
|
+
}
|
|
49
83
|
return /*#__PURE__*/React.createElement(TableCell, props);
|
|
50
84
|
}
|
|
51
85
|
export default renderTableCell;
|
|
@@ -1,15 +1,130 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import React, { useEffect, useState, useRef, useCallback } from 'react';
|
|
2
4
|
import classnames from 'classnames';
|
|
5
|
+
import { useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
6
|
+
import { ReactEditor } from '@seafile/slate-react';
|
|
7
|
+
import { Transforms } from '@seafile/slate';
|
|
8
|
+
import { findPath } from '../../../core';
|
|
9
|
+
import { TABLE_ROW_MIN_HEIGHT } from '../constants';
|
|
10
|
+
import { updateTableRowHeight } from '../helpers';
|
|
11
|
+
import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
|
|
12
|
+
import { useSettingSelectRangeContext, useResizeHandlersContext } from './hooks';
|
|
3
13
|
var TableRow = function TableRow(_ref) {
|
|
4
|
-
var
|
|
5
|
-
|
|
14
|
+
var _element$style;
|
|
15
|
+
var element = _ref.element,
|
|
16
|
+
attributes = _ref.attributes,
|
|
6
17
|
children = _ref.children;
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
var editor = useSlateStatic();
|
|
19
|
+
var isSettingSelectRange = useSettingSelectRangeContext();
|
|
20
|
+
var columns = useResizeHandlersContext();
|
|
21
|
+
var _useState = useState(false),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
isResizing = _useState2[0],
|
|
24
|
+
setIsResizing = _useState2[1];
|
|
25
|
+
var _useState3 = useState({}),
|
|
26
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
+
mouseDownInfo = _useState4[0],
|
|
28
|
+
setMouseDownInfo = _useState4[1];
|
|
29
|
+
var rowPath = findPath(editor, element);
|
|
30
|
+
var pathLength = rowPath ? rowPath.length : 0;
|
|
31
|
+
var rowIndex = rowPath ? rowPath[pathLength - 1] : -1;
|
|
32
|
+
var minHeight = ((_element$style = element.style) === null || _element$style === void 0 ? void 0 : _element$style.minHeight) || TABLE_ROW_MIN_HEIGHT;
|
|
33
|
+
var initHeight = rowIndex === 0 ? minHeight + 1 : minHeight;
|
|
34
|
+
var tableRow = useRef(initHeight);
|
|
35
|
+
var _useState5 = useState(initHeight),
|
|
36
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
37
|
+
height = _useState6[0],
|
|
38
|
+
setHeight = _useState6[1];
|
|
39
|
+
var onMouseDown = useCallback(function (event) {
|
|
40
|
+
eventStopPropagation(event);
|
|
41
|
+
Transforms.deselect(editor);
|
|
42
|
+
var pageElement = document.getElementsByClassName('sdoc-editor-article-container')[0];
|
|
43
|
+
var mouseDownInfo = getMouseDownInfo(event, pageElement);
|
|
44
|
+
setMouseDownInfo(mouseDownInfo);
|
|
45
|
+
setIsResizing(true);
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
|
+
}, []);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
if (!isResizing) return;
|
|
51
|
+
var onMouseMove = function onMouseMove(event) {
|
|
52
|
+
eventStopPropagation(event);
|
|
53
|
+
var pageElement = document.getElementsByClassName('sdoc-editor-article-container')[0];
|
|
54
|
+
var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, pageElement);
|
|
55
|
+
var newHeight = tableRow.current + mouseMoveInfo.displacementY;
|
|
56
|
+
var validHeight = Math.max(TABLE_ROW_MIN_HEIGHT, newHeight);
|
|
57
|
+
setHeight(validHeight);
|
|
58
|
+
};
|
|
59
|
+
var onMouseUp = function onMouseUp(event) {
|
|
60
|
+
eventStopPropagation(event);
|
|
61
|
+
setIsResizing(false);
|
|
62
|
+
tableRow.current = height;
|
|
63
|
+
updateTableRowHeight(editor, element, height);
|
|
64
|
+
};
|
|
65
|
+
registerResizeEvents({
|
|
66
|
+
'mousemove': onMouseMove,
|
|
67
|
+
'mouseup': onMouseUp
|
|
68
|
+
});
|
|
69
|
+
return function () {
|
|
70
|
+
unregisterResizeEvents({
|
|
71
|
+
'mousemove': onMouseMove,
|
|
72
|
+
'mouseup': onMouseUp
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, [isResizing, mouseDownInfo, element, attributes, height]);
|
|
78
|
+
useEffect(function () {
|
|
79
|
+
var rowDom = ReactEditor.toDOMNode(editor, element);
|
|
80
|
+
if (!rowDom) return;
|
|
81
|
+
tableRow.current = rowDom.clientHeight;
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
|
+
}, [columns, element]);
|
|
85
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
86
|
+
className: classnames('table-row position-relative', attributes.className),
|
|
87
|
+
style: _objectSpread(_objectSpread({}, attributes.style), {}, {
|
|
88
|
+
height: height,
|
|
89
|
+
maxHeight: 'fit-content'
|
|
90
|
+
}),
|
|
9
91
|
"data-id": element.id
|
|
10
|
-
}), children
|
|
92
|
+
}), children, !isSettingSelectRange && /*#__PURE__*/React.createElement("div", {
|
|
93
|
+
className: classnames('table-row-height-just position-absolute', {
|
|
94
|
+
'resizing': isResizing
|
|
95
|
+
}),
|
|
96
|
+
contentEditable: false,
|
|
97
|
+
onMouseDown: onMouseDown
|
|
98
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
99
|
+
className: "table-row-height-just-color-tip"
|
|
100
|
+
})));
|
|
11
101
|
};
|
|
12
|
-
function renderTableRow(props
|
|
102
|
+
function renderTableRow(props) {
|
|
103
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
104
|
+
var readOnly = useReadOnly();
|
|
105
|
+
if (readOnly) {
|
|
106
|
+
var attributes = props.attributes,
|
|
107
|
+
children = props.children,
|
|
108
|
+
element = props.element;
|
|
109
|
+
|
|
110
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
111
|
+
var editor = useSlateStatic();
|
|
112
|
+
var style = element.style;
|
|
113
|
+
var rowPath = findPath(editor, element);
|
|
114
|
+
if (!rowPath) return null;
|
|
115
|
+
var pathLength = rowPath.length;
|
|
116
|
+
var rowIndex = rowPath[pathLength - 1];
|
|
117
|
+
var minHeight = (style === null || style === void 0 ? void 0 : style.minHeight) || TABLE_ROW_MIN_HEIGHT;
|
|
118
|
+
var height = rowIndex === 0 ? minHeight + 1 : minHeight;
|
|
119
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
120
|
+
className: classnames('table-row', attributes.className),
|
|
121
|
+
style: _objectSpread(_objectSpread(_objectSpread({}, attributes.style), style), {}, {
|
|
122
|
+
height: height,
|
|
123
|
+
maxHeight: 'fit-content'
|
|
124
|
+
}),
|
|
125
|
+
"data-id": element.id
|
|
126
|
+
}), children);
|
|
127
|
+
}
|
|
13
128
|
return /*#__PURE__*/React.createElement(TableRow, props);
|
|
14
129
|
}
|
|
15
130
|
export default renderTableRow;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { Transforms } from '@seafile/slate';
|
|
5
|
+
import { useSlateStatic } from '@seafile/slate-react';
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
import { useTableRootContext } from './hooks';
|
|
8
|
+
import { TABLE_CELL_MIN_WIDTH } from '../constants';
|
|
9
|
+
import { getTableColumns, updateColumnWidth } from '../helpers';
|
|
10
|
+
import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
|
|
11
|
+
var ResizeHandler = function ResizeHandler(_ref) {
|
|
12
|
+
var column = _ref.column,
|
|
13
|
+
initLeft = _ref.left,
|
|
14
|
+
element = _ref.element,
|
|
15
|
+
index = _ref.index;
|
|
16
|
+
var editor = useSlateStatic();
|
|
17
|
+
var resizeHandler = useRef(null);
|
|
18
|
+
var _useState = useState(initLeft),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
left = _useState2[0],
|
|
21
|
+
setLeft = _useState2[1];
|
|
22
|
+
var _useState3 = useState(false),
|
|
23
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
24
|
+
isResizing = _useState4[0],
|
|
25
|
+
setIsResizing = _useState4[1];
|
|
26
|
+
var _useState5 = useState({}),
|
|
27
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
28
|
+
mouseDownInfo = _useState6[0],
|
|
29
|
+
setMouseDownInfo = _useState6[1];
|
|
30
|
+
var width = column.width;
|
|
31
|
+
var tableRootScrollContainer = useTableRootContext();
|
|
32
|
+
var onMouseDown = useCallback(function (event) {
|
|
33
|
+
eventStopPropagation(event);
|
|
34
|
+
Transforms.deselect(editor);
|
|
35
|
+
var mouseDownInfo = getMouseDownInfo(event, tableRootScrollContainer);
|
|
36
|
+
setMouseDownInfo(mouseDownInfo);
|
|
37
|
+
setIsResizing(true);
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, []);
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
if (!isResizing) {
|
|
43
|
+
if (initLeft !== left) {
|
|
44
|
+
setLeft(initLeft);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var onMouseMove = function onMouseMove(event) {
|
|
49
|
+
eventStopPropagation(event);
|
|
50
|
+
var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, tableRootScrollContainer);
|
|
51
|
+
var newWidth = width + mouseMoveInfo.displacementX;
|
|
52
|
+
if (newWidth < TABLE_CELL_MIN_WIDTH) return;
|
|
53
|
+
var columns = getTableColumns(editor, element);
|
|
54
|
+
var nextColumn = columns[index + 1];
|
|
55
|
+
if (nextColumn) {
|
|
56
|
+
var nextColumnWidth = nextColumn.width - mouseMoveInfo.displacementX;
|
|
57
|
+
if (nextColumnWidth < TABLE_CELL_MIN_WIDTH) return;
|
|
58
|
+
}
|
|
59
|
+
var left = initLeft + mouseMoveInfo.displacementX;
|
|
60
|
+
setLeft(left);
|
|
61
|
+
};
|
|
62
|
+
var onMouseUp = function onMouseUp(event) {
|
|
63
|
+
eventStopPropagation(event);
|
|
64
|
+
setIsResizing(false);
|
|
65
|
+
var columns = getTableColumns(editor, element);
|
|
66
|
+
var newColumns = columns.slice(0);
|
|
67
|
+
var column = newColumns[index];
|
|
68
|
+
var newWidth = width + left - initLeft;
|
|
69
|
+
newColumns[index] = _objectSpread(_objectSpread({}, column), {}, {
|
|
70
|
+
width: newWidth
|
|
71
|
+
});
|
|
72
|
+
var nextColumn = columns[index + 1];
|
|
73
|
+
if (nextColumn) {
|
|
74
|
+
var nextColumnWidth = nextColumn.width - left + initLeft;
|
|
75
|
+
newColumns[index + 1] = _objectSpread(_objectSpread({}, nextColumn), {}, {
|
|
76
|
+
width: nextColumnWidth
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
updateColumnWidth(editor, element, newColumns);
|
|
80
|
+
};
|
|
81
|
+
registerResizeEvents({
|
|
82
|
+
'mousemove': onMouseMove,
|
|
83
|
+
'mouseup': onMouseUp
|
|
84
|
+
});
|
|
85
|
+
return function () {
|
|
86
|
+
unregisterResizeEvents({
|
|
87
|
+
'mousemove': onMouseMove,
|
|
88
|
+
'mouseup': onMouseUp
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
}, [isResizing, mouseDownInfo, left, width, column, editor, element, index, initLeft]);
|
|
94
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: classnames('table-cell-width-just position-absolute', {
|
|
96
|
+
'resizing': isResizing
|
|
97
|
+
}),
|
|
98
|
+
contentEditable: false,
|
|
99
|
+
style: {
|
|
100
|
+
left: left - 3.5,
|
|
101
|
+
top: 0
|
|
102
|
+
},
|
|
103
|
+
onMouseDown: onMouseDown,
|
|
104
|
+
ref: resizeHandler
|
|
105
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
106
|
+
className: "table-cell-width-just-color-tip"
|
|
107
|
+
}));
|
|
108
|
+
};
|
|
109
|
+
export default ResizeHandler;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSlateStatic } from '@seafile/slate-react';
|
|
3
|
+
import ResizeHandler from './resize-handler';
|
|
4
|
+
import { getNode, findPath } from '../../../core';
|
|
5
|
+
import { useResizeHandlersContext } from './hooks';
|
|
6
|
+
import { getTableColumns } from '../helpers';
|
|
7
|
+
var ResizeHandlers = function ResizeHandlers(props) {
|
|
8
|
+
var element = props.element;
|
|
9
|
+
var editor = useSlateStatic();
|
|
10
|
+
var tablePath = findPath(editor, element);
|
|
11
|
+
var columns = useResizeHandlersContext() || getTableColumns(editor, element);
|
|
12
|
+
if (!tablePath) return null;
|
|
13
|
+
var table = getNode(editor, tablePath);
|
|
14
|
+
if (!table) return null;
|
|
15
|
+
var columnLeft = 0;
|
|
16
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, columns.map(function (column, columnIndex) {
|
|
17
|
+
columnLeft = columnLeft + column.width;
|
|
18
|
+
return /*#__PURE__*/React.createElement(ResizeHandler, {
|
|
19
|
+
key: columnIndex,
|
|
20
|
+
column: column,
|
|
21
|
+
left: columnLeft,
|
|
22
|
+
index: columnIndex,
|
|
23
|
+
element: element
|
|
24
|
+
});
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
export default ResizeHandlers;
|