@seafile/sdoc-editor 1.0.202-test-0.0.5 → 1.0.202-test-0.0.6
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.
|
@@ -158,7 +158,7 @@ const updateColumnWidthOnDeletion = (editor, selection, column, deletionDirectio
|
|
|
158
158
|
exports.updateColumnWidthOnDeletion = updateColumnWidthOnDeletion;
|
|
159
159
|
const getCurrentPageWidth = () => {
|
|
160
160
|
const sdocEditorPage = document.getElementById('sdoc-editor');
|
|
161
|
-
const pageWidth = sdocEditorPage.getBoundingClientRect().width;
|
|
161
|
+
const pageWidth = sdocEditorPage === null || sdocEditorPage === void 0 ? void 0 : sdocEditorPage.getBoundingClientRect().width;
|
|
162
162
|
return pageWidth;
|
|
163
163
|
};
|
|
164
164
|
exports.getCurrentPageWidth = getCurrentPageWidth;
|
|
@@ -12,8 +12,6 @@ var _slateReact = require("@seafile/slate-react");
|
|
|
12
12
|
var _multiColumnRoot = _interopRequireDefault(require("./multi-column-root"));
|
|
13
13
|
var _resizeHandlers = _interopRequireDefault(require("../resize-handlers"));
|
|
14
14
|
var _helper = require("../helper");
|
|
15
|
-
var _localStorageUtils = _interopRequireDefault(require("../../../../../utils/local-storage-utils"));
|
|
16
|
-
var _constants = require("../../../../constants");
|
|
17
15
|
require("./index.css");
|
|
18
16
|
const MultiColumn = _ref => {
|
|
19
17
|
let {
|
|
@@ -24,42 +22,15 @@ const MultiColumn = _ref => {
|
|
|
24
22
|
} = _ref;
|
|
25
23
|
const editor = (0, _slateReact.useSlateStatic)();
|
|
26
24
|
const multiColumn = (0, _react.useRef)(null);
|
|
27
|
-
const [column, setColumn] = (0, _react.useState)(element.column || []);
|
|
28
25
|
const [style, setStyle] = (0, _react.useState)(element.style ? {
|
|
29
26
|
...element.style
|
|
30
27
|
} : {});
|
|
31
28
|
const multiColumnContainerClassName = (0, _classnames.default)('sdoc-multicolumn-container', className);
|
|
32
29
|
const [pageWidth, setPageWidth] = (0, _react.useState)((0, _helper.getCurrentPageWidth)());
|
|
33
|
-
// const [isChangedPageWidth, setIsChangedPageWidth] = useState(false);
|
|
34
|
-
// const [fullPageWidthState, setFullPageWidthState] = useState(null);
|
|
35
|
-
|
|
36
30
|
const handleResizeColumn = newColumn => {
|
|
37
|
-
|
|
31
|
+
(0, _helper.updateColumnWidth)(editor, element, newColumn);
|
|
38
32
|
};
|
|
39
|
-
|
|
40
|
-
// useEffect(() => {
|
|
41
|
-
// const fullPageWidthStorage = LocalStorage.getItem(FULL_WIDTH_MODE);
|
|
42
|
-
// setFullPageWidthState(fullPageWidthStorage);
|
|
43
|
-
// console.log(666)
|
|
44
|
-
// }, []);
|
|
45
|
-
|
|
46
|
-
// useEffect(() => {
|
|
47
|
-
// const handleStorageChange = (event) => {
|
|
48
|
-
// if (event.key === FULL_WIDTH_MODE && LocalStorage.getItem(FULL_WIDTH_MODE) !== fullPageWidthState) {
|
|
49
|
-
// setIsChangedPageWidth(true);
|
|
50
|
-
// console.log(555)
|
|
51
|
-
// }
|
|
52
|
-
// };
|
|
53
|
-
|
|
54
|
-
// window.addEventListener('storage', handleStorageChange);
|
|
55
|
-
|
|
56
|
-
// return () => {
|
|
57
|
-
// window.removeEventListener('storage', handleStorageChange);
|
|
58
|
-
// };
|
|
59
|
-
// }, [fullPageWidthState]);
|
|
60
|
-
|
|
61
33
|
(0, _react.useEffect)(() => {
|
|
62
|
-
console.log(3, column, element.column);
|
|
63
34
|
const sdocEditorPage = document.getElementById('sdoc-editor');
|
|
64
35
|
if (!sdocEditorPage) return;
|
|
65
36
|
const resizeObserver = new ResizeObserver(entries => {
|
|
@@ -67,7 +38,6 @@ const MultiColumn = _ref => {
|
|
|
67
38
|
const newPageWidth = (_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : _entries$.contentRect.width;
|
|
68
39
|
// Check if sdocPageWidth changes
|
|
69
40
|
if (newPageWidth !== pageWidth) {
|
|
70
|
-
console.log('change');
|
|
71
41
|
const scaleFactor = newPageWidth / pageWidth;
|
|
72
42
|
const updatedColumns = element.column.map(item => ({
|
|
73
43
|
...item,
|
|
@@ -79,24 +49,23 @@ const MultiColumn = _ref => {
|
|
|
79
49
|
gridTemplateColumns: columnWidthList.join(' ')
|
|
80
50
|
};
|
|
81
51
|
setStyle(newStyle);
|
|
82
|
-
// setColumn(updatedColumns);
|
|
83
52
|
setPageWidth(newPageWidth);
|
|
84
53
|
(0, _helper.updateColumnWidth)(editor, element, updatedColumns);
|
|
85
54
|
} else {
|
|
86
|
-
console.log(0);
|
|
87
55
|
const columnWidthList = element.column.map(item => `${item.width}px`);
|
|
88
56
|
const newStyle = {
|
|
89
57
|
...element.style,
|
|
90
58
|
gridTemplateColumns: columnWidthList.join(' ')
|
|
91
59
|
};
|
|
92
60
|
setStyle(newStyle);
|
|
93
|
-
// setColumn(element.column);
|
|
94
61
|
}
|
|
95
62
|
});
|
|
96
63
|
resizeObserver.observe(sdocEditorPage);
|
|
97
64
|
return () => {
|
|
98
65
|
resizeObserver.disconnect();
|
|
99
66
|
};
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
69
|
}, [pageWidth, element.style, element.column]);
|
|
101
70
|
return /*#__PURE__*/_react.default.createElement(_multiColumnRoot.default, {
|
|
102
71
|
attributes: attributes
|
|
@@ -107,8 +76,7 @@ const MultiColumn = _ref => {
|
|
|
107
76
|
"data-id": element.id
|
|
108
77
|
}, children, /*#__PURE__*/_react.default.createElement(_resizeHandlers.default, {
|
|
109
78
|
element: element,
|
|
110
|
-
handleResizeColumn: handleResizeColumn
|
|
111
|
-
newColumnWidthList: element.column
|
|
79
|
+
handleResizeColumn: handleResizeColumn
|
|
112
80
|
})));
|
|
113
81
|
};
|
|
114
82
|
function renderMultiColumn(props) {
|
|
@@ -16,21 +16,20 @@ var _mouseEvent = require("../../../../utils/mouse-event");
|
|
|
16
16
|
const ResizeHandlers = _ref => {
|
|
17
17
|
let {
|
|
18
18
|
element,
|
|
19
|
-
handleResizeColumn
|
|
20
|
-
newColumnWidthList
|
|
19
|
+
handleResizeColumn
|
|
21
20
|
} = _ref;
|
|
22
21
|
const editor = (0, _slateReact.useSlateStatic)();
|
|
23
|
-
const [
|
|
22
|
+
const [column, setColumn] = (0, _react.useState)(element.column);
|
|
24
23
|
const [isDraggingResizeHandler, setIsDraggingResizeHandler] = (0, _react.useState)(false);
|
|
25
24
|
const [adjustingCell, setAdjustingCell] = (0, _react.useState)(null);
|
|
26
25
|
const [resizeInfo, setResizeInfo] = (0, _react.useState)({
|
|
27
26
|
initialX: 0,
|
|
28
27
|
cellWidths: []
|
|
29
28
|
});
|
|
30
|
-
const [isMouseNearBorder, setIsMouseNearBorder] = (0, _react.useState)(
|
|
29
|
+
const [isMouseNearBorder, setIsMouseNearBorder] = (0, _react.useState)(column.map(() => false));
|
|
31
30
|
const handleMouseDown = (index, event) => {
|
|
32
31
|
event.preventDefault();
|
|
33
|
-
const cellWidths =
|
|
32
|
+
const cellWidths = column.map(col => col.width);
|
|
34
33
|
setResizeInfo({
|
|
35
34
|
initialX: event.clientX,
|
|
36
35
|
cellWidths,
|
|
@@ -42,8 +41,8 @@ const ResizeHandlers = _ref => {
|
|
|
42
41
|
|
|
43
42
|
// Render when column element of multi_column node changes
|
|
44
43
|
(0, _react.useEffect)(() => {
|
|
45
|
-
|
|
46
|
-
}, [
|
|
44
|
+
setColumn(element.column);
|
|
45
|
+
}, [element.column]);
|
|
47
46
|
(0, _react.useEffect)(() => {
|
|
48
47
|
const path = _slateReact.ReactEditor.findPath(editor, element);
|
|
49
48
|
const [node] = _slate.Editor.node(editor, path);
|
|
@@ -53,7 +52,7 @@ const ResizeHandlers = _ref => {
|
|
|
53
52
|
const onMouseMove = event => {
|
|
54
53
|
event.preventDefault();
|
|
55
54
|
// Let resize handler show when mouse is close to right edge of column at range of 20 px
|
|
56
|
-
const nearBorder =
|
|
55
|
+
const nearBorder = column.map((col, colIndex) => {
|
|
57
56
|
const child = childNodes[colIndex];
|
|
58
57
|
if (!child) return false;
|
|
59
58
|
const childRect = child.getBoundingClientRect();
|
|
@@ -77,7 +76,7 @@ const ResizeHandlers = _ref => {
|
|
|
77
76
|
const deltaX = Math.min(event.clientX - initialX, cellWidths[index + 1] - _constants.COLUMN_MIN_WIDTH);
|
|
78
77
|
const newWidth = Math.max(cellWidths[index] + deltaX, _constants.COLUMN_MIN_WIDTH);
|
|
79
78
|
if (cellWidths[index] === _constants.COLUMN_MIN_WIDTH && deltaX < 0) return;
|
|
80
|
-
const
|
|
79
|
+
const updatedColumn = column.map((column, colIndex) => {
|
|
81
80
|
if (colIndex === index) {
|
|
82
81
|
return {
|
|
83
82
|
...column,
|
|
@@ -91,12 +90,12 @@ const ResizeHandlers = _ref => {
|
|
|
91
90
|
}
|
|
92
91
|
return column;
|
|
93
92
|
});
|
|
94
|
-
|
|
93
|
+
setColumn(updatedColumn);
|
|
95
94
|
};
|
|
96
95
|
const onMouseUp = event => {
|
|
97
96
|
event.preventDefault();
|
|
98
97
|
if (adjustingCell === null) return;
|
|
99
|
-
const newColumn =
|
|
98
|
+
const newColumn = column.map(column => ({
|
|
100
99
|
...column,
|
|
101
100
|
left: column.width
|
|
102
101
|
}));
|
|
@@ -117,12 +116,12 @@ const ResizeHandlers = _ref => {
|
|
|
117
116
|
'mouseleave': onMouseUp
|
|
118
117
|
});
|
|
119
118
|
};
|
|
120
|
-
}, [handleResizeColumn,
|
|
119
|
+
}, [handleResizeColumn, column, isDraggingResizeHandler, isMouseNearBorder]);
|
|
121
120
|
let leftAccumulator = 0;
|
|
122
121
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
123
122
|
className: "column-resize-handler",
|
|
124
123
|
contentEditable: false
|
|
125
|
-
},
|
|
124
|
+
}, column.map((column, index) => {
|
|
126
125
|
leftAccumulator += column.width;
|
|
127
126
|
const left = leftAccumulator;
|
|
128
127
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|