@zhenliang/sheet 0.1.27 → 0.1.29
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/core/reducers/keyboardReducer.js +2 -1
- package/dist/core/sheet/Control.d.ts +10 -0
- package/dist/core/sheet/Control.js +32 -0
- package/dist/core/sheet/DefaultRow.js +1 -7
- package/dist/core/sheet/Menu.d.ts +6 -0
- package/dist/core/sheet/Menu.js +21 -0
- package/dist/core/sheet/index.js +66 -65
- package/dist/core/sheet/useSelectVisible.js +1 -0
- package/dist/core/sheet/useVirtualList.d.ts +10 -1
- package/dist/core/sheet/useVirtualList.js +38 -38
- package/dist/core/shell/draggableShell/index.js +9 -2
- package/dist/core/table/events.d.ts +0 -2
- package/dist/core/table/events.js +15 -24
- package/dist/core/table/index.js +60 -168
- package/dist/core/table/useGroupConfig.d.ts +4 -1
- package/dist/core/table/useGroupConfig.js +78 -1
- package/dist/core/table/useRowSelection.d.ts +13 -1
- package/dist/core/table/useRowSelection.js +50 -0
- package/dist/core/util.d.ts +1 -1
- package/dist/core/util.js +5 -4
- package/dist/core/viewer/groupViewer/index.js +22 -9
- package/dist/example/sheet.js +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useGroupConfig.d.ts +4 -0
- package/dist/hooks/useGroupConfig.js +5 -0
- package/dist/hooks/useWidthConfig.d.ts +3 -3
- package/dist/type/sheet.d.ts +15 -3
- package/dist/type/sheetTable.d.ts +2 -2
- package/package.json +1 -1
|
@@ -17,7 +17,8 @@ export var keyboardReducer = {
|
|
|
17
17
|
data = _state$data === void 0 ? [] : _state$data;
|
|
18
18
|
var newRow = (((_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.row) || 0) + row;
|
|
19
19
|
if (groupConfig) {
|
|
20
|
-
|
|
20
|
+
var _data;
|
|
21
|
+
newRow = getNextVisibleRow(newRow, (data === null || data === void 0 || (_data = data[data.length - 1]) === null || _data === void 0 ? void 0 : _data[0].row) || data.length, groupConfigToGroupMap(groupConfig), row < 0 ? -1 : 1);
|
|
21
22
|
}
|
|
22
23
|
var currentPos = {
|
|
23
24
|
row: newRow,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
interface ControlProps {
|
|
3
|
+
showBackEdit?: boolean;
|
|
4
|
+
startRowVisible: boolean;
|
|
5
|
+
handelClick: () => void;
|
|
6
|
+
backEditStyle?: Partial<CSSProperties>;
|
|
7
|
+
direction: 'up' | 'down';
|
|
8
|
+
}
|
|
9
|
+
export declare const Control: React.FC<ControlProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ArrowDownOutlined, ArrowUpOutlined } from '@ant-design/icons';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
export var Control = function Control(props) {
|
|
6
|
+
var showBackEdit = props.showBackEdit,
|
|
7
|
+
startRowVisible = props.startRowVisible,
|
|
8
|
+
handelClick = props.handelClick,
|
|
9
|
+
backEditStyle = props.backEditStyle,
|
|
10
|
+
direction = props.direction;
|
|
11
|
+
if (!showBackEdit || startRowVisible) return null;
|
|
12
|
+
var styles = backEditStyle || {
|
|
13
|
+
top: 0,
|
|
14
|
+
right: 0
|
|
15
|
+
};
|
|
16
|
+
var backIcon = direction === 'up' ? /*#__PURE__*/_jsx(ArrowUpOutlined, {
|
|
17
|
+
rev: undefined
|
|
18
|
+
}) : /*#__PURE__*/_jsx(ArrowDownOutlined, {
|
|
19
|
+
rev: undefined
|
|
20
|
+
});
|
|
21
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
22
|
+
className: "back-edit",
|
|
23
|
+
onClick: handelClick,
|
|
24
|
+
style: styles,
|
|
25
|
+
children: [backIcon, /*#__PURE__*/_jsx("span", {
|
|
26
|
+
style: {
|
|
27
|
+
marginLeft: 0
|
|
28
|
+
},
|
|
29
|
+
children: "\u8FD4\u56DE\u7F16\u8F91\u884C"
|
|
30
|
+
})]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -12,13 +12,7 @@ var DefaultRow = function DefaultRow(_ref) {
|
|
|
12
12
|
return groupConfigToGroupMap(groupConfig);
|
|
13
13
|
}, [groupConfig]);
|
|
14
14
|
if (groupMap.get(row) && !((_groupMap$get = groupMap.get(row)) !== null && _groupMap$get !== void 0 && _groupMap$get.isStart) && !((_groupMap$get2 = groupMap.get(row)) !== null && _groupMap$get2 !== void 0 && _groupMap$get2.isOpen)) {
|
|
15
|
-
return
|
|
16
|
-
className: rowClassName,
|
|
17
|
-
style: {
|
|
18
|
-
display: 'none'
|
|
19
|
-
},
|
|
20
|
-
children: children
|
|
21
|
-
});
|
|
15
|
+
return null;
|
|
22
16
|
}
|
|
23
17
|
return /*#__PURE__*/_jsx("tr", {
|
|
24
18
|
className: rowClassName,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MenuRenderProps } from "../../type/sheet";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const Menu: React.ForwardRefExoticComponent<MenuRenderProps & {
|
|
4
|
+
contextMenu?: React.FC<MenuRenderProps> | undefined;
|
|
5
|
+
showMenu: boolean;
|
|
6
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
4
|
+
var showMenu = props.showMenu,
|
|
5
|
+
position = props.position,
|
|
6
|
+
cell = props.cell,
|
|
7
|
+
onContextMenu = props.onContextMenu,
|
|
8
|
+
ContextMenu = props.contextMenu;
|
|
9
|
+
var isMenuShow = !!ContextMenu && showMenu;
|
|
10
|
+
return /*#__PURE__*/_jsx("div", {
|
|
11
|
+
ref: ref,
|
|
12
|
+
style: {
|
|
13
|
+
display: isMenuShow ? '' : 'none'
|
|
14
|
+
},
|
|
15
|
+
children: isMenuShow && /*#__PURE__*/_jsx(ContextMenu, {
|
|
16
|
+
position: position,
|
|
17
|
+
cell: cell,
|
|
18
|
+
onContextMenu: onContextMenu
|
|
19
|
+
})
|
|
20
|
+
});
|
|
21
|
+
});
|
package/dist/core/sheet/index.js
CHANGED
|
@@ -4,29 +4,31 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
7
|
+
import { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
8
8
|
// import ReduxLogger from 'redux-logger';
|
|
9
9
|
import ReduxThunk from 'redux-thunk';
|
|
10
10
|
import DefaultRow from "./DefaultRow";
|
|
11
11
|
import DefaultShell from "./DefaultShell";
|
|
12
|
-
import {
|
|
12
|
+
import { useGroup } from "../../hooks/useGroupConfig";
|
|
13
13
|
import { Empty } from 'antd';
|
|
14
14
|
import { isEmpty, isNil, isNumber } from 'lodash';
|
|
15
15
|
import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
|
|
16
16
|
import sheetReducer from "../reducers";
|
|
17
17
|
import { classNames, getRowHeight, rowToActualRow } from "../util";
|
|
18
|
+
import { Control } from "./Control";
|
|
18
19
|
import { DefaultRowMapper } from "./DefaultRowMapper";
|
|
20
|
+
import { Menu } from "./Menu";
|
|
19
21
|
import "./index.less";
|
|
20
22
|
import { useCellEvent } from "./useCellEvent";
|
|
21
23
|
import { useContextMenu } from "./useContextMenu";
|
|
22
24
|
import { useKeyBoardEvent } from "./useKeyBoardEvent";
|
|
23
25
|
import { useMouseEvent } from "./useMouseEvent";
|
|
24
26
|
import { useSelectVisible } from "./useSelectVisible";
|
|
25
|
-
import { useVirtualList } from "./useVirtualList";
|
|
27
|
+
import { VirtualizeEnd, VirtualizeStart, useVirtualList } from "./useVirtualList";
|
|
26
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
29
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
30
|
var Sheet = function Sheet(props) {
|
|
29
|
-
var
|
|
31
|
+
var _visibleData$length, _scroll$y, _scroll$x;
|
|
30
32
|
var _props$sheetInstance = props.sheetInstance,
|
|
31
33
|
sheetInstance = _props$sheetInstance === void 0 ? {
|
|
32
34
|
current: null
|
|
@@ -46,8 +48,6 @@ var Sheet = function Sheet(props) {
|
|
|
46
48
|
data = props.data,
|
|
47
49
|
_props$freePaste = props.freePaste,
|
|
48
50
|
freePaste = _props$freePaste === void 0 ? false : _props$freePaste,
|
|
49
|
-
_props$groupConfig = props.groupConfig,
|
|
50
|
-
groupConfig = _props$groupConfig === void 0 ? undefined : _props$groupConfig,
|
|
51
51
|
onCellsChanged = props.onCellsChanged,
|
|
52
52
|
onContextMenu = props.onContextMenu,
|
|
53
53
|
rowClassName = props.rowClassName,
|
|
@@ -58,6 +58,8 @@ var Sheet = function Sheet(props) {
|
|
|
58
58
|
var sheetWrapperRef = useRef(null);
|
|
59
59
|
var contextMenuRef = useRef(null);
|
|
60
60
|
var eventBus = useEventBus();
|
|
61
|
+
var _useGroup = useGroup(),
|
|
62
|
+
groupConfig = _useGroup.config;
|
|
61
63
|
var _useMiddlewareReducer = useMiddlewareReducer(sheetReducer, {
|
|
62
64
|
data: data,
|
|
63
65
|
mouseDown: false,
|
|
@@ -71,8 +73,8 @@ var Sheet = function Sheet(props) {
|
|
|
71
73
|
_useMiddlewareReducer2 = _slicedToArray(_useMiddlewareReducer, 2),
|
|
72
74
|
state = _useMiddlewareReducer2[0],
|
|
73
75
|
dispatch = _useMiddlewareReducer2[1];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
useImperativeHandle(sheetInstance, function () {
|
|
77
|
+
return {
|
|
76
78
|
zoomTo: function zoomTo(row) {
|
|
77
79
|
// 给定 row 回到行
|
|
78
80
|
// 不给定 row 默认回到编辑行和列
|
|
@@ -84,7 +86,7 @@ var Sheet = function Sheet(props) {
|
|
|
84
86
|
data = _getState.data;
|
|
85
87
|
var container = sheetWrapperRef.current;
|
|
86
88
|
if (!start && isNil(row)) return;
|
|
87
|
-
var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig);
|
|
89
|
+
var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig, data.length);
|
|
88
90
|
var rowHeight = getRowHeight(container);
|
|
89
91
|
var firstRowCell = container.querySelector("td.cell[data-col='".concat(start === null || start === void 0 ? void 0 : start.col, "']"));
|
|
90
92
|
var colPosition = firstRowCell ? firstRowCell.offsetLeft - firstRowCell.clientWidth : 0;
|
|
@@ -134,7 +136,7 @@ var Sheet = function Sheet(props) {
|
|
|
134
136
|
return history !== null && history !== void 0 && history.length ? history === null || history === void 0 ? void 0 : history[history.length - 1] : {};
|
|
135
137
|
}
|
|
136
138
|
};
|
|
137
|
-
}, [
|
|
139
|
+
}, [state.history]);
|
|
138
140
|
useEffect(function () {
|
|
139
141
|
// 同步必要的状态
|
|
140
142
|
dispatch({
|
|
@@ -164,7 +166,20 @@ var Sheet = function Sheet(props) {
|
|
|
164
166
|
}, 1);
|
|
165
167
|
}
|
|
166
168
|
}, [state.editing, state.start]);
|
|
167
|
-
var
|
|
169
|
+
var visibleData = useMemo(function () {
|
|
170
|
+
var _groupConfig$groups, _state$data;
|
|
171
|
+
if (!(groupConfig !== null && groupConfig !== void 0 && (_groupConfig$groups = groupConfig.groups) !== null && _groupConfig$groups !== void 0 && _groupConfig$groups.length)) {
|
|
172
|
+
return state.data;
|
|
173
|
+
}
|
|
174
|
+
return (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.filter(function (item, index) {
|
|
175
|
+
if (!(groupConfig !== null && groupConfig !== void 0 && groupConfig.configMap.has(index))) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
var rowConfig = groupConfig.configMap.get(index);
|
|
179
|
+
return (rowConfig === null || rowConfig === void 0 ? void 0 : rowConfig.isOpen) || (rowConfig === null || rowConfig === void 0 ? void 0 : rowConfig.isStart);
|
|
180
|
+
});
|
|
181
|
+
}, [state.data, groupConfig]);
|
|
182
|
+
var _useVirtualList = useVirtualList(sheetWrapperRef, visibleData, virtualized),
|
|
168
183
|
virtualStart = _useVirtualList.virtualStart,
|
|
169
184
|
virtualEnd = _useVirtualList.virtualEnd,
|
|
170
185
|
paddingTop = _useVirtualList.paddingTop,
|
|
@@ -178,15 +193,14 @@ var Sheet = function Sheet(props) {
|
|
|
178
193
|
});
|
|
179
194
|
}, [groupConfig]);
|
|
180
195
|
var rowElements = useMemo(function () {
|
|
181
|
-
var
|
|
182
|
-
return
|
|
183
|
-
var
|
|
184
|
-
var row = (
|
|
196
|
+
var _visibleData$slice;
|
|
197
|
+
return visibleData === null || visibleData === void 0 || (_visibleData$slice = visibleData.slice(virtualStart, virtualEnd)) === null || _visibleData$slice === void 0 ? void 0 : _visibleData$slice.map(function (rowData) {
|
|
198
|
+
var _rowData$, _rowData;
|
|
199
|
+
var row = ((_rowData$ = rowData[0]) === null || _rowData$ === void 0 ? void 0 : _rowData$.row) || 0;
|
|
185
200
|
var rowCN = rowClassName instanceof Function ? rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(rowData === null || rowData === void 0 || (_rowData = rowData[rowData.length - 1]) === null || _rowData === void 0 ? void 0 : _rowData.record, row) : rowClassName;
|
|
186
201
|
return /*#__PURE__*/_jsx(Row, {
|
|
187
202
|
row: row,
|
|
188
203
|
cells: rowData,
|
|
189
|
-
groupConfig: groupConfig,
|
|
190
204
|
rowClassName: rowCN,
|
|
191
205
|
children: /*#__PURE__*/_jsx(DefaultRowMapper, {
|
|
192
206
|
rowData: rowData,
|
|
@@ -194,12 +208,25 @@ var Sheet = function Sheet(props) {
|
|
|
194
208
|
})
|
|
195
209
|
}, row);
|
|
196
210
|
});
|
|
197
|
-
}, [
|
|
198
|
-
var memoHeight = Math.min(((
|
|
211
|
+
}, [visibleData, groupConfig, virtualStart, virtualEnd, rowClassName]);
|
|
212
|
+
var memoHeight = Math.min(((_visibleData$length = visibleData === null || visibleData === void 0 ? void 0 : visibleData.length) !== null && _visibleData$length !== void 0 ? _visibleData$length : 0) + 1, 10) * 42 + 43;
|
|
199
213
|
var _useSelectVisible = useSelectVisible(sheetWrapperRef, state.start),
|
|
200
214
|
_useSelectVisible2 = _slicedToArray(_useSelectVisible, 2),
|
|
201
215
|
startRowVisible = _useSelectVisible2[0],
|
|
202
216
|
direction = _useSelectVisible2[1];
|
|
217
|
+
var isEmptyData = isEmpty(state.data);
|
|
218
|
+
var EmptyElement = useMemo(function () {
|
|
219
|
+
if (isEmptyData) {
|
|
220
|
+
return /*#__PURE__*/_jsx("div", {
|
|
221
|
+
style: {
|
|
222
|
+
marginTop: 16,
|
|
223
|
+
marginBottom: 16
|
|
224
|
+
},
|
|
225
|
+
children: emptyRenderer
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}, [isEmptyData, emptyRenderer]);
|
|
203
230
|
return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
|
|
204
231
|
value: eventBus,
|
|
205
232
|
children: /*#__PURE__*/_jsxs("span", {
|
|
@@ -213,59 +240,33 @@ var Sheet = function Sheet(props) {
|
|
|
213
240
|
},
|
|
214
241
|
children: [/*#__PURE__*/_jsxs(SheetShell, {
|
|
215
242
|
className: classNames('harvest-sheet', className),
|
|
216
|
-
children: [
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}), rowElements, virtualized && paddingBottom > 0 && /*#__PURE__*/_jsx("tr", {
|
|
223
|
-
style: {
|
|
224
|
-
height: 0,
|
|
225
|
-
paddingBottom: paddingBottom,
|
|
226
|
-
display: 'block'
|
|
227
|
-
}
|
|
243
|
+
children: [/*#__PURE__*/_jsx(VirtualizeStart, {
|
|
244
|
+
virtualized: virtualized,
|
|
245
|
+
paddingTop: paddingTop
|
|
246
|
+
}), rowElements, /*#__PURE__*/_jsx(VirtualizeEnd, {
|
|
247
|
+
virtualized: virtualized,
|
|
248
|
+
paddingBottom: paddingBottom
|
|
228
249
|
})]
|
|
229
|
-
}, "sheet"),
|
|
250
|
+
}, "sheet"), /*#__PURE__*/_jsx(Menu, {
|
|
230
251
|
ref: contextMenuRef,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
})
|
|
239
|
-
}) : null]
|
|
240
|
-
}), isEmpty(state.data) || isNil(state.data) ? /*#__PURE__*/_jsx("div", {
|
|
241
|
-
style: {
|
|
242
|
-
marginTop: 16,
|
|
243
|
-
marginBottom: 16
|
|
244
|
-
},
|
|
245
|
-
children: emptyRenderer
|
|
246
|
-
}) : null, /*#__PURE__*/_jsxs("div", {
|
|
252
|
+
position: menu.position,
|
|
253
|
+
cell: menu.cellPosition,
|
|
254
|
+
showMenu: menu.showMenu,
|
|
255
|
+
contextMenu: ContextMenu,
|
|
256
|
+
onContextMenu: onContextMenu
|
|
257
|
+
})]
|
|
258
|
+
}), EmptyElement, /*#__PURE__*/_jsxs("div", {
|
|
247
259
|
className: "harvest-sheet-control",
|
|
248
|
-
children: [children,
|
|
249
|
-
|
|
250
|
-
|
|
260
|
+
children: [children, /*#__PURE__*/_jsx(Control, {
|
|
261
|
+
showBackEdit: showBackEdit,
|
|
262
|
+
startRowVisible: startRowVisible,
|
|
263
|
+
handelClick: function handelClick() {
|
|
251
264
|
var _sheetInstance$curren;
|
|
252
265
|
return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
|
|
253
266
|
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
} : backEditStyle,
|
|
258
|
-
children: [direction === 'up' ? /*#__PURE__*/_jsx(ArrowUpOutlined, {
|
|
259
|
-
rev: undefined
|
|
260
|
-
}) : /*#__PURE__*/_jsx(ArrowDownOutlined, {
|
|
261
|
-
rev: undefined
|
|
262
|
-
}), /*#__PURE__*/_jsx("span", {
|
|
263
|
-
style: {
|
|
264
|
-
marginLeft: 0
|
|
265
|
-
},
|
|
266
|
-
children: "\u8FD4\u56DE\u7F16\u8F91\u884C"
|
|
267
|
-
})]
|
|
268
|
-
}) : null]
|
|
267
|
+
direction: direction,
|
|
268
|
+
backEditStyle: backEditStyle
|
|
269
|
+
})]
|
|
269
270
|
})]
|
|
270
271
|
})
|
|
271
272
|
});
|
|
@@ -20,6 +20,7 @@ export var useSelectVisible = function useSelectVisible(sheetWrapper, start) {
|
|
|
20
20
|
var handleScroll = throttle(function () {
|
|
21
21
|
var _sheetWrapper$current, _sheetWrapper$current2;
|
|
22
22
|
if (!start) {
|
|
23
|
+
setStartVisible(true);
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
var startCell = (_sheetWrapper$current = sheetWrapper.current) === null || _sheetWrapper$current === void 0 ? void 0 : _sheetWrapper$current.querySelector("td.cell[data-row='".concat(start.row, "']"));
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { SheetType } from "../../type";
|
|
2
|
-
export declare const useVirtualList: (elementRef: React.RefObject<SheetType.refAssertion>, data?: SheetType.Cell[][],
|
|
3
|
+
export declare const useVirtualList: (elementRef: React.RefObject<SheetType.refAssertion>, data?: SheetType.Cell[][], virtualized?: boolean) => {
|
|
3
4
|
virtualStart: number;
|
|
4
5
|
virtualEnd: number;
|
|
5
6
|
paddingTop: number;
|
|
6
7
|
paddingBottom: number;
|
|
7
8
|
};
|
|
9
|
+
export declare const VirtualizeStart: React.FC<{
|
|
10
|
+
virtualized: boolean;
|
|
11
|
+
paddingTop: number;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const VirtualizeEnd: React.FC<{
|
|
14
|
+
virtualized: boolean;
|
|
15
|
+
paddingBottom: number;
|
|
16
|
+
}>;
|
|
@@ -4,15 +4,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
|
+
import { useGroup } from "../../hooks/useGroupConfig";
|
|
9
|
+
import { throttle } from 'lodash';
|
|
10
|
+
import { useEffect, useState } from 'react';
|
|
11
|
+
import { getRowHeight } from "../util";
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
13
|
var extra = 20;
|
|
11
14
|
// 虚拟列表
|
|
12
15
|
export var useVirtualList = function useVirtualList(elementRef) {
|
|
13
16
|
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
14
|
-
var
|
|
15
|
-
var virtualized = arguments.length > 3 ? arguments[3] : undefined;
|
|
17
|
+
var virtualized = arguments.length > 2 ? arguments[2] : undefined;
|
|
16
18
|
var _useState = useState({
|
|
17
19
|
virtualStart: 0,
|
|
18
20
|
virtualEnd: virtualized ? Math.min(data.length - 1, 2 * extra) : data.length - 1,
|
|
@@ -22,17 +24,17 @@ export var useVirtualList = function useVirtualList(elementRef) {
|
|
|
22
24
|
_useState2 = _slicedToArray(_useState, 2),
|
|
23
25
|
state = _useState2[0],
|
|
24
26
|
setState = _useState2[1];
|
|
27
|
+
var _useGroup = useGroup(),
|
|
28
|
+
groupConfig = _useGroup.config;
|
|
25
29
|
var virtualStart = state.virtualStart,
|
|
26
30
|
virtualEnd = state.virtualEnd,
|
|
27
31
|
paddingTop = state.paddingTop,
|
|
28
32
|
paddingBottom = state.paddingBottom;
|
|
29
|
-
|
|
30
|
-
var groupConfigRef = useRef(groupConfig);
|
|
33
|
+
// const virtualRef = useRef<VirtualConfig | null>();
|
|
31
34
|
useEffect(function () {
|
|
32
35
|
var _elementRef$current;
|
|
33
|
-
groupConfigRef.current = groupConfig;
|
|
34
36
|
(_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 || _elementRef$current.scrollBy({
|
|
35
|
-
top:
|
|
37
|
+
top: 0
|
|
36
38
|
});
|
|
37
39
|
}, [groupConfig]);
|
|
38
40
|
useEffect(function () {
|
|
@@ -47,36 +49,15 @@ export var useVirtualList = function useVirtualList(elementRef) {
|
|
|
47
49
|
clientHeight = _ref.clientHeight;
|
|
48
50
|
var start = Math.floor(scrollTop / itemHeight) - extra;
|
|
49
51
|
var end = Math.ceil((scrollTop + clientHeight) / itemHeight) + extra;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
paddingBottom: (data.length - end) * itemHeight
|
|
56
|
-
};
|
|
57
|
-
if (isEqual(newConfig, virtualRef.current)) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
virtualRef.current = newConfig;
|
|
61
|
-
setState(newConfig);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
var actualStart = rowToCountRow(start, groupConfigRef.current, data.length);
|
|
65
|
-
var actualEnd = rowToCountRow(end, groupConfigRef.current, data.length);
|
|
66
|
-
var maxEnd = rowToActualRow(data.length, groupConfigRef.current, data.length);
|
|
67
|
-
var invisibleTop = rowToActualRow(actualStart, groupConfigRef.current, data.length);
|
|
68
|
-
var invisibleBottom = maxEnd > end ? maxEnd - end : 0;
|
|
69
|
-
var updateVirtualConfig = {
|
|
70
|
-
virtualStart: actualStart,
|
|
71
|
-
virtualEnd: actualEnd,
|
|
72
|
-
paddingTop: invisibleTop * itemHeight,
|
|
73
|
-
paddingBottom: invisibleBottom * itemHeight
|
|
52
|
+
var newConfig = {
|
|
53
|
+
virtualStart: start,
|
|
54
|
+
virtualEnd: end,
|
|
55
|
+
paddingTop: start * itemHeight,
|
|
56
|
+
paddingBottom: (data.length - end) * itemHeight
|
|
74
57
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
setState(updateVirtualConfig);
|
|
79
|
-
virtualRef.current = updateVirtualConfig;
|
|
58
|
+
// virtualRef.current = newConfig;
|
|
59
|
+
setState(newConfig);
|
|
60
|
+
return;
|
|
80
61
|
}, 50);
|
|
81
62
|
// data.length change 的时候用 handleScroll 重设 virtual params
|
|
82
63
|
handleScroll();
|
|
@@ -100,4 +81,23 @@ export var useVirtualList = function useVirtualList(elementRef) {
|
|
|
100
81
|
paddingTop: Math.max(0, paddingTop),
|
|
101
82
|
paddingBottom: data.length - 1 <= virtualEnd ? 0 : paddingBottom
|
|
102
83
|
};
|
|
84
|
+
};
|
|
85
|
+
export var VirtualizeStart = function VirtualizeStart(_ref2) {
|
|
86
|
+
var virtualized = _ref2.virtualized,
|
|
87
|
+
paddingTop = _ref2.paddingTop;
|
|
88
|
+
return virtualized && paddingTop > 0 ? /*#__PURE__*/_jsx("tr", {
|
|
89
|
+
style: {
|
|
90
|
+
height: 0,
|
|
91
|
+
paddingBottom: paddingTop,
|
|
92
|
+
display: 'block'
|
|
93
|
+
}
|
|
94
|
+
}) : null;
|
|
95
|
+
};
|
|
96
|
+
export var VirtualizeEnd = function VirtualizeEnd(_ref3) {
|
|
97
|
+
var virtualized = _ref3.virtualized,
|
|
98
|
+
paddingBottom = _ref3.paddingBottom;
|
|
99
|
+
return /*#__PURE__*/_jsx(VirtualizeStart, {
|
|
100
|
+
virtualized: virtualized,
|
|
101
|
+
paddingTop: paddingBottom
|
|
102
|
+
});
|
|
103
103
|
};
|
|
@@ -147,14 +147,18 @@ export var DraggableShell = function DraggableShell(_ref) {
|
|
|
147
147
|
var _downRef$current$oldW, _downRef$current$oldX;
|
|
148
148
|
downRef.current.style.cursor = 'default';
|
|
149
149
|
if (((_downRef$current$oldW = downRef.current.oldWidth) !== null && _downRef$current$oldW !== void 0 ? _downRef$current$oldW : 0) + (e.x - ((_downRef$current$oldX = downRef.current.oldX) !== null && _downRef$current$oldX !== void 0 ? _downRef$current$oldX : 0)) > 0) {
|
|
150
|
-
var _downRef$current$oldW2, _downRef$current$oldX2, _headRef$current
|
|
150
|
+
var _downRef$current$oldW2, _downRef$current$oldX2, _headRef$current, _columns$actualIndex$;
|
|
151
151
|
var newWidth = Math.max(Number(((_downRef$current$oldW2 = downRef.current.oldWidth) !== null && _downRef$current$oldW2 !== void 0 ? _downRef$current$oldW2 : 0) + (e.x - ((_downRef$current$oldX2 = downRef.current.oldX) !== null && _downRef$current$oldX2 !== void 0 ? _downRef$current$oldX2 : 0))), 50);
|
|
152
152
|
var cellList = [].slice.call((_headRef$current = headRef.current) === null || _headRef$current === void 0 ? void 0 : _headRef$current.cells);
|
|
153
153
|
var changeIndex = cellList.indexOf(downRef.current);
|
|
154
|
+
var actualIndex = hasControl ? changeIndex - 1 : changeIndex;
|
|
155
|
+
var isDoubleSpan = (((_columns$actualIndex$ = columns[actualIndex].titleConfig) === null || _columns$actualIndex$ === void 0 ? void 0 : _columns$actualIndex$.colSpan) || 0) > 1;
|
|
156
|
+
var nextColumn = columns[actualIndex + 1] || {};
|
|
157
|
+
var nextWidth = +String(nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.width).replace('px', '');
|
|
154
158
|
//调整该列中的每个Cell
|
|
155
159
|
var _widths2 = _defineProperty({
|
|
156
160
|
length: columns.length
|
|
157
|
-
},
|
|
161
|
+
}, actualIndex, isDoubleSpan ? newWidth - nextWidth : newWidth);
|
|
158
162
|
setWidth(_widths2);
|
|
159
163
|
}
|
|
160
164
|
}
|
|
@@ -177,6 +181,9 @@ export var DraggableShell = function DraggableShell(_ref) {
|
|
|
177
181
|
children: [/*#__PURE__*/_jsx("colgroup", {
|
|
178
182
|
children: colItems
|
|
179
183
|
}), /*#__PURE__*/_jsx("thead", {
|
|
184
|
+
style: {
|
|
185
|
+
pointerEvents: 'all'
|
|
186
|
+
},
|
|
180
187
|
children: /*#__PURE__*/_jsx("tr", {
|
|
181
188
|
ref: headRef,
|
|
182
189
|
children: thItems
|
|
@@ -7,9 +7,7 @@ export declare const SelectionEvent: FC<{
|
|
|
7
7
|
}>;
|
|
8
8
|
export declare const GroupEvent: FC<{
|
|
9
9
|
hasChildren: boolean;
|
|
10
|
-
rowGroupConfig: SheetType.RowGroupConfig;
|
|
11
10
|
data: SheetType.Cell[][];
|
|
12
11
|
sheetInstance: SheetType.SheetInstance | null;
|
|
13
|
-
onGroupChange: (value: SheetType.RowGroupConfig) => void;
|
|
14
12
|
onGridChange: (value: SheetType.Cell[][]) => void;
|
|
15
13
|
}>;
|
|
@@ -10,6 +10,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
11
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
12
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14
|
+
import { useGroup } from "../../hooks/useGroupConfig";
|
|
13
15
|
import { SheetEvent } from "../sheet/Event";
|
|
14
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
17
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -31,44 +33,34 @@ export var SelectionEvent = function SelectionEvent(props) {
|
|
|
31
33
|
};
|
|
32
34
|
export var GroupEvent = function GroupEvent(props) {
|
|
33
35
|
var hasChildren = props.hasChildren,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
sheetInstance = props.sheetInstance;
|
|
37
|
+
var _useGroup = useGroup(),
|
|
38
|
+
_useGroup$config = _useGroup.config,
|
|
39
|
+
rowGroupConfig = _useGroup$config === void 0 ? {} : _useGroup$config,
|
|
40
|
+
onGroupChange = _useGroup.onChange;
|
|
39
41
|
if (!hasChildren) return null;
|
|
40
|
-
var
|
|
41
|
-
groups = _ref.groups;
|
|
42
|
+
var groups = rowGroupConfig.groups;
|
|
42
43
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
43
44
|
children: [/*#__PURE__*/_jsx(SheetEvent, {
|
|
44
45
|
name: "group-open",
|
|
45
46
|
handler: function handler(e) {
|
|
46
|
-
var
|
|
47
|
-
row =
|
|
48
|
-
var index = groups.findIndex(function (item) {
|
|
47
|
+
var _ref = e,
|
|
48
|
+
row = _ref.row;
|
|
49
|
+
var index = groups === null || groups === void 0 ? void 0 : groups.findIndex(function (item) {
|
|
49
50
|
return item.groupStart === row;
|
|
50
51
|
});
|
|
51
52
|
if (index >= 0) {
|
|
52
|
-
var groupOpen = _toConsumableArray(rowGroupConfig.groupOpen);
|
|
53
|
-
groupOpen[index] = !rowGroupConfig.groupOpen[index];
|
|
53
|
+
var groupOpen = _toConsumableArray(rowGroupConfig === null || rowGroupConfig === void 0 ? void 0 : rowGroupConfig.groupOpen);
|
|
54
|
+
groupOpen[index] = !(rowGroupConfig !== null && rowGroupConfig !== void 0 && rowGroupConfig.groupOpen[index]);
|
|
54
55
|
onGroupChange && onGroupChange(_objectSpread(_objectSpread({}, rowGroupConfig), {}, {
|
|
55
56
|
groupOpen: groupOpen
|
|
56
57
|
}));
|
|
57
|
-
var newGrid = _toConsumableArray(data);
|
|
58
|
-
newGrid[row] = _toConsumableArray(newGrid[row]);
|
|
59
|
-
newGrid[row][0] = _objectSpread(_objectSpread({}, newGrid[row][0]), {}, {
|
|
60
|
-
record: {
|
|
61
|
-
open: !!groupOpen[index]
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
onGridChange && onGridChange(newGrid);
|
|
65
58
|
sheetInstance === null || sheetInstance === void 0 || sheetInstance.pushToHistory({
|
|
66
59
|
type: 'Custom',
|
|
67
60
|
changes: [],
|
|
68
61
|
extraInfo: {
|
|
69
62
|
extraType: 'group',
|
|
70
|
-
groupConfig: rowGroupConfig
|
|
71
|
-
data: data
|
|
63
|
+
groupConfig: rowGroupConfig
|
|
72
64
|
}
|
|
73
65
|
});
|
|
74
66
|
}
|
|
@@ -85,8 +77,7 @@ export var GroupEvent = function GroupEvent(props) {
|
|
|
85
77
|
changes: [],
|
|
86
78
|
extraInfo: {
|
|
87
79
|
extraType: 'group',
|
|
88
|
-
groupConfig: rowGroupConfig
|
|
89
|
-
data: data
|
|
80
|
+
groupConfig: rowGroupConfig
|
|
90
81
|
}
|
|
91
82
|
});
|
|
92
83
|
}
|