@zhenliang/sheet 0.1.17 → 0.1.19
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/sideEffectReducer.js +4 -3
- package/dist/core/sheet/Cell.js +1 -1
- package/dist/core/sheet/index.js +11 -10
- package/dist/core/sheet/index.less +1 -1
- package/dist/core/sheet/useMouseEvent.js +1 -1
- package/dist/core/sheet/useSelectVisible.js +5 -1
- package/dist/core/sheet/useVirtualList.js +8 -4
- package/dist/core/shell/draggableShell/index.d.ts +0 -1
- package/dist/core/shell/tableShell.d.ts +0 -1
- package/dist/core/util.js +2 -9
- package/dist/hooks/useEventBus.d.ts +0 -1
- package/package.json +1 -1
|
@@ -157,10 +157,11 @@ export var sideEffectReducer = {
|
|
|
157
157
|
// 复制到剪贴板的时候执行 formatter
|
|
158
158
|
var _data$row$col = data[row][col],
|
|
159
159
|
dataValue = _data$row$col.value,
|
|
160
|
-
dataEditor = _data$row$col.dataEditor
|
|
160
|
+
dataEditor = _data$row$col.dataEditor,
|
|
161
|
+
record = _data$row$col.record;
|
|
161
162
|
var _ref4 = dataEditor || {},
|
|
162
163
|
dataFormatter = _ref4.formatter;
|
|
163
|
-
var formattedValue = dataFormatter ? dataFormatter(dataValue) : dataValue;
|
|
164
|
+
var formattedValue = dataFormatter ? dataFormatter(dataValue, record) : dataValue;
|
|
164
165
|
if (isNil(dataValue)) {
|
|
165
166
|
formattedValue = ' ';
|
|
166
167
|
}
|
|
@@ -231,7 +232,7 @@ export var sideEffectReducer = {
|
|
|
231
232
|
row: row,
|
|
232
233
|
col: col,
|
|
233
234
|
id: (_data$row$col2 = data[row][col]) === null || _data$row$col2 === void 0 ? void 0 : _data$row$col2.id,
|
|
234
|
-
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 ? void 0 : (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value) : value
|
|
235
|
+
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 ? void 0 : (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value, data[row][col].record) : value
|
|
235
236
|
};
|
|
236
237
|
});
|
|
237
238
|
lastRow = extChanges === null || extChanges === void 0 ? void 0 : (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
|
package/dist/core/sheet/Cell.js
CHANGED
|
@@ -70,7 +70,7 @@ var Cell = function Cell(props) {
|
|
|
70
70
|
} else if (eventInfo.value && eventInfo.editing) {
|
|
71
71
|
var _cell$dataEditor, _cell$dataEditor2, _cell$dataEditor2$par;
|
|
72
72
|
// 单元格直接键盘编辑,设置为输入值
|
|
73
|
-
setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 ? void 0 : (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 ? void 0 : (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value) : eventInfo.value);
|
|
73
|
+
setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 ? void 0 : (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 ? void 0 : (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value, cell.record) : eventInfo.value);
|
|
74
74
|
}
|
|
75
75
|
setEventState(eventInfo);
|
|
76
76
|
};
|
package/dist/core/sheet/index.js
CHANGED
|
@@ -90,16 +90,17 @@ var Sheet = function Sheet(props) {
|
|
|
90
90
|
var rowHeight = getRowHeight(container);
|
|
91
91
|
var firstRowCell = container.querySelector("td.cell[data-col='".concat(start === null || start === void 0 ? void 0 : start.col, "']"));
|
|
92
92
|
var colPosition = firstRowCell ? firstRowCell.offsetLeft - firstRowCell.clientWidth : 0;
|
|
93
|
-
var scrollHeight =
|
|
93
|
+
var scrollHeight = actual * rowHeight;
|
|
94
94
|
(_sheetWrapperRef$curr = sheetWrapperRef.current) === null || _sheetWrapperRef$curr === void 0 ? void 0 : _sheetWrapperRef$curr.scrollTo(isNumber(row) ? 0 : colPosition, scrollHeight);
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
if (isNil(row) && start.row === data.length - 1) {
|
|
98
|
-
|
|
99
|
-
var _sheetWrapperRef$curr2, _sheetWrapperRef$curr3
|
|
100
|
-
|
|
101
|
-
(_sheetWrapperRef$curr3 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr3 === void 0 ? void 0 : _sheetWrapperRef$curr3.
|
|
102
|
-
}
|
|
96
|
+
// 最后一行的bug暂时用 scroll end 事件来处理
|
|
97
|
+
if (isNil(row) && start.row === data.length - 1 && sheetWrapperRef.current) {
|
|
98
|
+
var handleScrollEnd = function handleScrollEnd() {
|
|
99
|
+
var _sheetWrapperRef$curr2, _sheetWrapperRef$curr3;
|
|
100
|
+
(_sheetWrapperRef$curr2 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr2 === void 0 ? void 0 : _sheetWrapperRef$curr2.scrollTo(isNumber(row) ? 0 : colPosition, scrollHeight);
|
|
101
|
+
(_sheetWrapperRef$curr3 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr3 === void 0 ? void 0 : _sheetWrapperRef$curr3.removeEventListener('scrollend', handleScrollEnd);
|
|
102
|
+
};
|
|
103
|
+
sheetWrapperRef.current.addEventListener('scrollend', handleScrollEnd);
|
|
103
104
|
}
|
|
104
105
|
});
|
|
105
106
|
},
|
|
@@ -157,9 +158,9 @@ var Sheet = function Sheet(props) {
|
|
|
157
158
|
useEffect(function () {
|
|
158
159
|
if (!state.editing && state.start) {
|
|
159
160
|
setTimeout(function () {
|
|
160
|
-
var _sheetWrapperRef$
|
|
161
|
+
var _sheetWrapperRef$curr4;
|
|
161
162
|
// 表格获取焦点 + 接收keyboard event
|
|
162
|
-
(_sheetWrapperRef$
|
|
163
|
+
(_sheetWrapperRef$curr4 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr4 === void 0 ? void 0 : _sheetWrapperRef$curr4.focus({
|
|
163
164
|
preventScroll: true
|
|
164
165
|
});
|
|
165
166
|
}, 1);
|
|
@@ -57,7 +57,7 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
|
|
|
57
57
|
background-color: var(--cell-background-color);
|
|
58
58
|
cursor: cell;
|
|
59
59
|
text-align: right;
|
|
60
|
-
transition: box-shadow 100ms ease-out;
|
|
60
|
+
// transition: box-shadow 100ms ease-out;
|
|
61
61
|
user-select: none;
|
|
62
62
|
vertical-align: bottom;
|
|
63
63
|
position: relative;
|
|
@@ -276,7 +276,7 @@ export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
|
|
|
276
276
|
}
|
|
277
277
|
e.preventDefault();
|
|
278
278
|
var currentCell = findParentTd(e.target);
|
|
279
|
-
if (currentCell.classList.contains('read-only')) {
|
|
279
|
+
if (!(currentCell !== null && currentCell !== void 0 && currentCell.classList) || currentCell.classList.contains('read-only')) {
|
|
280
280
|
// 只读
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
@@ -23,7 +23,11 @@ export var useSelectVisible = function useSelectVisible(sheetWrapper, start) {
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
var startCell = (_sheetWrapper$current = sheetWrapper.current) === null || _sheetWrapper$current === void 0 ? void 0 : _sheetWrapper$current.querySelector("td.cell[data-row='".concat(start.row, "']"));
|
|
26
|
-
if (!startCell)
|
|
26
|
+
if (!startCell) {
|
|
27
|
+
// 找不到说明已经不在可视区域了
|
|
28
|
+
setStartVisible(false);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
27
31
|
var _ref = ((_sheetWrapper$current2 = sheetWrapper.current) === null || _sheetWrapper$current2 === void 0 ? void 0 : _sheetWrapper$current2.getBoundingClientRect()) || {},
|
|
28
32
|
_ref$top = _ref.top,
|
|
29
33
|
top = _ref$top === void 0 ? 0 : _ref$top,
|
|
@@ -29,7 +29,11 @@ export var useVirtualList = function useVirtualList(elementRef) {
|
|
|
29
29
|
var virtualRef = useRef();
|
|
30
30
|
var groupConfigRef = useRef(groupConfig);
|
|
31
31
|
useEffect(function () {
|
|
32
|
+
var _elementRef$current;
|
|
32
33
|
groupConfigRef.current = groupConfig;
|
|
34
|
+
(_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.scrollBy({
|
|
35
|
+
top: 1
|
|
36
|
+
});
|
|
33
37
|
}, [groupConfig]);
|
|
34
38
|
useEffect(function () {
|
|
35
39
|
if (!elementRef.current) return;
|
|
@@ -59,8 +63,8 @@ export var useVirtualList = function useVirtualList(elementRef) {
|
|
|
59
63
|
}
|
|
60
64
|
var actualStart = rowToCountRow(start, groupConfigRef.current, data.length);
|
|
61
65
|
var actualEnd = rowToCountRow(end, groupConfigRef.current, data.length);
|
|
62
|
-
var maxEnd = rowToActualRow(data.length, groupConfigRef.current);
|
|
63
|
-
var invisibleTop = rowToActualRow(actualStart, groupConfigRef.current);
|
|
66
|
+
var maxEnd = rowToActualRow(data.length, groupConfigRef.current, data.length);
|
|
67
|
+
var invisibleTop = rowToActualRow(actualStart, groupConfigRef.current, data.length);
|
|
64
68
|
var invisibleBottom = maxEnd > end ? maxEnd - end : 0;
|
|
65
69
|
var updateVirtualConfig = {
|
|
66
70
|
virtualStart: actualStart,
|
|
@@ -78,8 +82,8 @@ export var useVirtualList = function useVirtualList(elementRef) {
|
|
|
78
82
|
handleScroll();
|
|
79
83
|
elementRef.current.addEventListener('scroll', handleScroll);
|
|
80
84
|
return function () {
|
|
81
|
-
var _elementRef$
|
|
82
|
-
(_elementRef$
|
|
85
|
+
var _elementRef$current2;
|
|
86
|
+
(_elementRef$current2 = elementRef.current) === null || _elementRef$current2 === void 0 ? void 0 : _elementRef$current2.removeEventListener('scroll', handleScroll);
|
|
83
87
|
};
|
|
84
88
|
}, [elementRef.current, data.length]);
|
|
85
89
|
if (!virtualized) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { SheetType } from "../../type";
|
|
3
2
|
import './draggableShell/index.less';
|
|
4
3
|
export declare const TableShell: ({ columns, className, showGroup, showSelect, controlProps, controlWidth, }: SheetType.SheetShell) => import("react").FC<{
|
package/dist/core/util.js
CHANGED
|
@@ -387,7 +387,7 @@ export var changeGroupConfig = function changeGroupConfig(rowGroupConfig, change
|
|
|
387
387
|
});
|
|
388
388
|
};
|
|
389
389
|
export var rowToActualRow = function rowToActualRow(row, groupConfig) {
|
|
390
|
-
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] :
|
|
390
|
+
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10000;
|
|
391
391
|
var groupMap = groupConfigToGroupMap(groupConfig);
|
|
392
392
|
if (!groupMap.size || row < 0) return row;
|
|
393
393
|
var openCount = 0;
|
|
@@ -396,20 +396,13 @@ export var rowToActualRow = function rowToActualRow(row, groupConfig) {
|
|
|
396
396
|
if (groupMap.has(i) && !((_groupMap$get9 = groupMap.get(i)) !== null && _groupMap$get9 !== void 0 && _groupMap$get9.isOpen) && !((_groupMap$get10 = groupMap.get(i)) !== null && _groupMap$get10 !== void 0 && _groupMap$get10.isStart)) {
|
|
397
397
|
continue;
|
|
398
398
|
} else {
|
|
399
|
-
openCount++;
|
|
400
399
|
if (i >= row) {
|
|
401
400
|
break;
|
|
402
401
|
}
|
|
402
|
+
openCount++;
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
return openCount;
|
|
406
|
-
// 减法的做法 有bug
|
|
407
|
-
groupMap.forEach(function (item, index) {
|
|
408
|
-
if (index <= row && !(item !== null && item !== void 0 && item.isOpen) && !(item !== null && item !== void 0 && item.isStart)) {
|
|
409
|
-
row--;
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
return row;
|
|
413
406
|
};
|
|
414
407
|
export var rowToCountRow = function rowToCountRow(row, groupConfig, max) {
|
|
415
408
|
var groupMap = groupConfigToGroupMap(groupConfig);
|