@zhenliang/sheet 0.1.18 → 0.1.20

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.
@@ -136,6 +136,7 @@ export var sideEffectReducer = {
136
136
  }
137
137
  var cellIndex = flatRowColIndex(start, end);
138
138
  var groupMap = groupConfigToGroupMap(groupConfig);
139
+ var count = 0;
139
140
  var copyData = cellIndex.reduce(function (left, _ref3) {
140
141
  var _ref3$row = _ref3.row,
141
142
  row = _ref3$row === void 0 ? 0 : _ref3$row,
@@ -153,6 +154,7 @@ export var sideEffectReducer = {
153
154
  };
154
155
  }
155
156
  }
157
+ count++;
156
158
 
157
159
  // 复制到剪贴板的时候执行 formatter
158
160
  var _data$row$col = data[row][col],
@@ -181,7 +183,7 @@ export var sideEffectReducer = {
181
183
  value: ''
182
184
  });
183
185
  var text = copyData.value;
184
- stringToClipboardData(text, cellIndex.length);
186
+ stringToClipboardData(text, count);
185
187
  },
186
188
  paste: function paste(dispatch, getState) {
187
189
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
@@ -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 = (actual - 1) * rowHeight;
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
- // to do 最后一行的有bug
97
- if (isNil(row) && start.row === data.length - 1) {
98
- setTimeout(function () {
99
- var _sheetWrapperRef$curr2, _sheetWrapperRef$curr3, _sheetWrapperRef$curr4;
100
- console.log(scrollHeight, (_sheetWrapperRef$curr2 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr2 === void 0 ? void 0 : _sheetWrapperRef$curr2.scrollHeight);
101
- (_sheetWrapperRef$curr3 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr3 === void 0 ? void 0 : _sheetWrapperRef$curr3.scrollTo(isNumber(row) ? 0 : colPosition, ((_sheetWrapperRef$curr4 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr4 === void 0 ? void 0 : _sheetWrapperRef$curr4.scrollHeight) || scrollHeight);
102
- }, 500);
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$curr5;
161
+ var _sheetWrapperRef$curr4;
161
162
  // 表格获取焦点 + 接收keyboard event
162
- (_sheetWrapperRef$curr5 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr5 === void 0 ? void 0 : _sheetWrapperRef$curr5.focus({
163
+ (_sheetWrapperRef$curr4 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr4 === void 0 ? void 0 : _sheetWrapperRef$curr4.focus({
163
164
  preventScroll: true
164
165
  });
165
166
  }, 1);
@@ -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) return false;
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$current;
82
- (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.removeEventListener('scroll', handleScroll);
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) {
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] : 1000;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",