@zhenliang/sheet 0.1.15 → 0.1.16

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.
@@ -15,7 +15,7 @@ import { useEffect, useMemo, useRef } from 'react';
15
15
  import ReduxThunk from 'redux-thunk';
16
16
  import DefaultRow from "./DefaultRow";
17
17
  import DefaultShell from "./DefaultShell";
18
- import { Button } from 'antd';
18
+ import { ArrowDownOutlined, ArrowUpOutlined } from '@ant-design/icons';
19
19
  import { isNil, isNumber } from 'lodash';
20
20
  import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
21
21
  import sheetReducer from "../reducers";
@@ -186,7 +186,10 @@ var Sheet = function Sheet(props) {
186
186
  });
187
187
  }, [state.data, groupConfig, virtualStart, virtualEnd, rowClassName]);
188
188
  var memoHeight = Math.min(((_state$data$length = state === null || state === void 0 ? void 0 : (_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.length) !== null && _state$data$length !== void 0 ? _state$data$length : 0) + 1, 10) * 42 + 43;
189
- var startRowVisible = useSelectVisible(sheetWrapperRef, state.start);
189
+ var _useSelectVisible = useSelectVisible(sheetWrapperRef, state.start),
190
+ _useSelectVisible2 = _slicedToArray(_useSelectVisible, 2),
191
+ startRowVisible = _useSelectVisible2[0],
192
+ direction = _useSelectVisible2[1];
190
193
  return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
191
194
  value: eventBus,
192
195
  children: /*#__PURE__*/_jsxs("span", {
@@ -199,7 +202,7 @@ var Sheet = function Sheet(props) {
199
202
  },
200
203
  children: [/*#__PURE__*/_jsxs(SheetShell, {
201
204
  className: classNames('harvest-sheet', className),
202
- children: [virtualized && /*#__PURE__*/_jsx("tr", {
205
+ children: [virtualized && paddingTop > 0 && /*#__PURE__*/_jsx("tr", {
203
206
  style: {
204
207
  height: 0,
205
208
  paddingBottom: paddingTop,
@@ -224,20 +227,22 @@ var Sheet = function Sheet(props) {
224
227
  })
225
228
  }) : null, /*#__PURE__*/_jsxs("div", {
226
229
  className: "harvest-sheet-control",
227
- children: [children, showBackEdit && !startRowVisible ? /*#__PURE__*/_jsx(Button, {
228
- type: "dashed",
230
+ children: [children, showBackEdit && !startRowVisible ? /*#__PURE__*/_jsxs("div", {
231
+ className: "back-edit",
229
232
  onClick: function onClick() {
230
233
  var _sheetInstance$curren;
231
234
  return sheetInstance === null || sheetInstance === void 0 ? void 0 : (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
232
235
  },
233
- style: _objectSpread({
234
- position: 'absolute',
235
- zIndex: 4
236
- }, !backEditStyle ? {
236
+ style: _objectSpread({}, !backEditStyle ? {
237
237
  top: 0,
238
238
  right: 0
239
239
  } : backEditStyle),
240
- children: "\u56DE\u5230\u7F16\u8F91\u884C"
240
+ children: [direction === 'up' ? /*#__PURE__*/_jsx(ArrowUpOutlined, {}) : /*#__PURE__*/_jsx(ArrowDownOutlined, {}), /*#__PURE__*/_jsx("span", {
241
+ style: {
242
+ marginLeft: 0
243
+ },
244
+ children: "\u8FD4\u56DE\u7F16\u8F91\u884C"
245
+ })]
241
246
  }) : null]
242
247
  })]
243
248
  })
@@ -172,6 +172,7 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
172
172
  background: var(--cell-read-only-background-color);
173
173
  color: var(--read-color);
174
174
  text-align: center;
175
+ cursor: not-allowed;
175
176
  }
176
177
 
177
178
 
@@ -288,4 +289,15 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
288
289
  bottom: 0;
289
290
  left: 0;
290
291
  background-color: white;
292
+ }
293
+
294
+ .harvest-sheet-container .harvest-sheet-control .back-edit{
295
+ padding: 5px 8px;
296
+ display: flex;
297
+ width: 105px;
298
+ cursor: pointer;
299
+ align-items: center;
300
+ justify-content: center;
301
+ position: absolute;
302
+ z-index: 4,
291
303
  }
@@ -1,2 +1,2 @@
1
1
  import { SheetType } from "../../type";
2
- export declare const useSelectVisible: (sheetWrapper: React.RefObject<SheetType.refAssertion>, start?: SheetType.CellPosition) => boolean;
2
+ export declare const useSelectVisible: (sheetWrapper: React.RefObject<SheetType.refAssertion>, start?: SheetType.CellPosition) => [boolean, 'up' | 'down'];
@@ -11,6 +11,10 @@ export var useSelectVisible = function useSelectVisible(sheetWrapper, start) {
11
11
  _useState2 = _slicedToArray(_useState, 2),
12
12
  startVisible = _useState2[0],
13
13
  setStartVisible = _useState2[1];
14
+ var _useState3 = useState('up'),
15
+ _useState4 = _slicedToArray(_useState3, 2),
16
+ backDirection = _useState4[0],
17
+ setBackDirection = _useState4[1];
14
18
  useEffect(function () {
15
19
  var _sheetWrapper$current3;
16
20
  var handleScroll = throttle(function () {
@@ -32,6 +36,7 @@ export var useSelectVisible = function useSelectVisible(sheetWrapper, start) {
32
36
  setStartVisible(true);
33
37
  } else {
34
38
  setStartVisible(false);
39
+ setBackDirection(top < cellTop ? 'down' : 'up');
35
40
  }
36
41
  }, 100);
37
42
  handleScroll();
@@ -42,7 +47,7 @@ export var useSelectVisible = function useSelectVisible(sheetWrapper, start) {
42
47
  };
43
48
  }, [sheetWrapper.current, start]);
44
49
  if (!start) {
45
- return true;
50
+ return [true, 'up'];
46
51
  }
47
- return startVisible;
52
+ return [startVisible, backDirection];
48
53
  };
@@ -6,7 +6,7 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { isEqual, throttle } from 'lodash';
8
8
  import { useEffect, useRef, useState } from 'react';
9
- import { getRowHeight, rowToActualRow } from "../util";
9
+ import { getRowHeight, rowToActualRow, rowToCountRow } from "../util";
10
10
  var extra = 20;
11
11
  // 虚拟列表
12
12
  export var useVirtualList = function useVirtualList(elementRef) {
@@ -43,18 +43,39 @@ export var useVirtualList = function useVirtualList(elementRef) {
43
43
  clientHeight = _ref.clientHeight;
44
44
  var start = Math.floor(scrollTop / itemHeight) - extra;
45
45
  var end = Math.ceil((scrollTop + clientHeight) / itemHeight) + extra;
46
+ if (!groupConfigRef.current) {
47
+ var newConfig = {
48
+ virtualStart: start,
49
+ virtualEnd: end,
50
+ paddingTop: start * itemHeight,
51
+ paddingBottom: (data.length - end) * itemHeight
52
+ };
53
+ if (isEqual(newConfig, virtualRef.current)) {
54
+ return;
55
+ }
56
+ virtualRef.current = newConfig;
57
+ setState(newConfig);
58
+ return;
59
+ }
46
60
 
47
61
  // todo 加入分组之后的 虚拟列表计算
48
- var actualStart = groupConfigRef.current ? rowToActualRow(start, groupConfigRef.current) : start;
49
- var actualEnd = groupConfigRef.current ? rowToActualRow(end, groupConfigRef.current) : end;
62
+ var actualStart = rowToCountRow(start, groupConfigRef.current, data.length);
63
+ var actualEnd = rowToCountRow(end, groupConfigRef.current, data.length);
64
+ var maxEnd = rowToActualRow(data.length, groupConfigRef.current);
65
+ var invisibleTop = rowToActualRow(actualStart, groupConfigRef.current);
66
+ var invisibleBottom = maxEnd > end ? maxEnd - end : 0;
67
+ console.log('visiable-count', start, end, maxEnd);
68
+ console.log('visible-toactual-count', actualStart, actualEnd);
69
+ console.log('invisible', invisibleTop, invisibleBottom);
50
70
 
51
71
  // const minStart = start - (actualStart - start)
52
- var maxEnd = end - (actualEnd - end);
72
+ // const maxEnd = end - (actualEnd - end);
73
+
53
74
  var updateVirtualConfig = {
54
75
  virtualStart: actualStart,
55
- virtualEnd: maxEnd,
56
- paddingTop: actualStart * itemHeight,
57
- paddingBottom: (data.length - maxEnd) * itemHeight
76
+ virtualEnd: actualEnd,
77
+ paddingTop: invisibleTop * itemHeight,
78
+ paddingBottom: invisibleBottom * itemHeight
58
79
  };
59
80
  if (isEqual(updateVirtualConfig, virtualRef.current)) {
60
81
  return;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { SheetType } from "../../../type";
3
2
  import './index.less';
4
3
  export declare const DraggableShell: ({ columns, className, showGroup, showSelect, controlProps, controlWidth, }: SheetType.SheetShell) => import("react").FC<{
@@ -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<{
@@ -41,7 +41,8 @@ export declare const changeGroupConfig: (rowGroupConfig: SheetType.RowGroupConfi
41
41
  add?: number | undefined;
42
42
  remove?: number | undefined;
43
43
  }) => SheetType.RowGroupConfig;
44
- export declare const rowToActualRow: (row: number, groupConfig?: SheetType.RowGroupConfig) => number;
44
+ export declare const rowToActualRow: (row: number, groupConfig?: SheetType.RowGroupConfig, max?: number) => number;
45
+ export declare const rowToCountRow: (row: number, groupConfig: SheetType.RowGroupConfig, max: number) => number;
45
46
  export declare const getRowHeight: (container: HTMLSpanElement) => number;
46
47
  export declare const getNextVisibleRow: (row: number, maxRow: number, groupMap?: Map<number, SheetType.RowGroup & {
47
48
  isStart: boolean;
package/dist/core/util.js CHANGED
@@ -387,8 +387,23 @@ 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
391
  var groupMap = groupConfigToGroupMap(groupConfig);
391
- if (!groupMap.size) return row;
392
+ if (!groupMap.size || row < 0) return row;
393
+ var openCount = 0;
394
+ for (var i = 0; i < max; i++) {
395
+ var _groupMap$get9, _groupMap$get10;
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
+ continue;
398
+ } else {
399
+ openCount++;
400
+ if (i >= row) {
401
+ break;
402
+ }
403
+ }
404
+ }
405
+ return openCount;
406
+ // 减法的做法 有bug
392
407
  groupMap.forEach(function (item, index) {
393
408
  if (index <= row && !(item !== null && item !== void 0 && item.isOpen) && !(item !== null && item !== void 0 && item.isStart)) {
394
409
  row--;
@@ -396,13 +411,47 @@ export var rowToActualRow = function rowToActualRow(row, groupConfig) {
396
411
  });
397
412
  return row;
398
413
  };
414
+ export var rowToCountRow = function rowToCountRow(row, groupConfig, max) {
415
+ var groupMap = groupConfigToGroupMap(groupConfig);
416
+ if (!groupMap.size || row < 0) return row;
417
+
418
+ // 加法的做法
419
+ var maxCount = 0;
420
+ var maxIndex = max;
421
+ for (var i = 0; i < max; i++) {
422
+ var _groupMap$get11, _groupMap$get12;
423
+ if (groupMap.has(i) && !((_groupMap$get11 = groupMap.get(i)) !== null && _groupMap$get11 !== void 0 && _groupMap$get11.isOpen) && !((_groupMap$get12 = groupMap.get(i)) !== null && _groupMap$get12 !== void 0 && _groupMap$get12.isStart)) {
424
+ continue;
425
+ } else {
426
+ maxCount++;
427
+ }
428
+ }
429
+ if (row >= maxCount) {
430
+ return maxIndex;
431
+ }
432
+ maxIndex = 0;
433
+ var openCount = 0;
434
+ for (var _i2 = 0; _i2 < max; _i2++) {
435
+ var _groupMap$get13, _groupMap$get14;
436
+ if (groupMap.has(_i2) && !((_groupMap$get13 = groupMap.get(_i2)) !== null && _groupMap$get13 !== void 0 && _groupMap$get13.isOpen) && !((_groupMap$get14 = groupMap.get(_i2)) !== null && _groupMap$get14 !== void 0 && _groupMap$get14.isStart)) {
437
+ continue;
438
+ } else {
439
+ openCount++;
440
+ if (openCount >= row) {
441
+ maxIndex = _i2;
442
+ break;
443
+ }
444
+ }
445
+ }
446
+ return maxIndex;
447
+ };
399
448
  export var getRowHeight = function getRowHeight(container) {
400
449
  var _container$getElement, _container$getElement2;
401
450
  var h = ((_container$getElement = container.getElementsByTagName('td')[0]) === null || _container$getElement === void 0 ? void 0 : (_container$getElement2 = _container$getElement.parentNode) === null || _container$getElement2 === void 0 ? void 0 : _container$getElement2.clientHeight) || 30;
402
451
  return h;
403
452
  };
404
453
  export var getNextVisibleRow = function getNextVisibleRow(row, maxRow, groupMap) {
405
- var _groupMap$get9, _groupMap$get10;
454
+ var _groupMap$get15, _groupMap$get16;
406
455
  var up = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
407
456
  if (!(groupMap !== null && groupMap !== void 0 && groupMap.size)) {
408
457
  return row;
@@ -410,7 +459,7 @@ export var getNextVisibleRow = function getNextVisibleRow(row, maxRow, groupMap)
410
459
  if (row > maxRow) {
411
460
  return null;
412
461
  }
413
- if (groupMap.get(row) && !((_groupMap$get9 = groupMap.get(row)) !== null && _groupMap$get9 !== void 0 && _groupMap$get9.isOpen) && !((_groupMap$get10 = groupMap.get(row)) !== null && _groupMap$get10 !== void 0 && _groupMap$get10.isStart)) {
462
+ if (groupMap.get(row) && !((_groupMap$get15 = groupMap.get(row)) !== null && _groupMap$get15 !== void 0 && _groupMap$get15.isOpen) && !((_groupMap$get16 = groupMap.get(row)) !== null && _groupMap$get16 !== void 0 && _groupMap$get16.isStart)) {
414
463
  return getNextVisibleRow(row + up, maxRow, groupMap);
415
464
  }
416
465
  return row;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",