@zhenliang/sheet 0.1.4 → 0.1.7-3.beta.0

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.
Files changed (117) hide show
  1. package/dist/assets/arrow-mac-down.svg +19 -0
  2. package/dist/assets/arrow-mac-right.svg +17 -0
  3. package/dist/assets/arrow-windows-down.svg +17 -0
  4. package/dist/assets/arrow-windows-right.svg +17 -0
  5. package/dist/core/config.d.ts +3 -0
  6. package/dist/core/config.js +4 -1
  7. package/dist/core/editor/cascaderEditor/index.d.ts +1 -1
  8. package/dist/core/editor/cascaderEditor/index.js +12 -11
  9. package/dist/core/editor/cascaderEditor/index.less +15 -7
  10. package/dist/core/editor/dateEditor/index.js +31 -8
  11. package/dist/core/editor/dateEditor/index.less +9 -2
  12. package/dist/core/editor/numberEditor/index.d.ts +3 -1
  13. package/dist/core/editor/numberEditor/index.js +62 -27
  14. package/dist/core/editor/numberEditor/index.less +3 -2
  15. package/dist/core/editor/selectEditor/index.d.ts +1 -1
  16. package/dist/core/editor/selectEditor/index.js +34 -19
  17. package/dist/core/editor/selectEditor/index.less +16 -5
  18. package/dist/core/reducers/index.d.ts +2 -2
  19. package/dist/core/reducers/index.js +8 -1
  20. package/dist/core/reducers/keyboardReducer.js +39 -9
  21. package/dist/core/reducers/mouseReducer.js +115 -11
  22. package/dist/core/reducers/sideEffectReducer.d.ts +1 -1
  23. package/dist/core/reducers/sideEffectReducer.js +146 -41
  24. package/dist/core/reducers/stateReducer.d.ts +1 -0
  25. package/dist/core/reducers/stateReducer.js +96 -27
  26. package/dist/core/sheet/Cell.d.ts +1 -1
  27. package/dist/core/sheet/Cell.js +33 -24
  28. package/dist/core/sheet/Control.d.ts +21 -0
  29. package/dist/core/sheet/Control.js +83 -0
  30. package/dist/core/sheet/DataEditor.js +3 -3
  31. package/dist/core/sheet/DefaultCell.d.ts +8 -3
  32. package/dist/core/sheet/DefaultCell.js +12 -8
  33. package/dist/core/sheet/DefaultRow.js +3 -9
  34. package/dist/core/sheet/DefaultRowMapper.d.ts +3 -0
  35. package/dist/core/sheet/DefaultRowMapper.js +22 -6
  36. package/dist/core/sheet/DefaultShell.js +1 -1
  37. package/dist/core/sheet/Event.d.ts +1 -1
  38. package/dist/core/sheet/Event.js +1 -1
  39. package/dist/core/sheet/Menu.d.ts +6 -0
  40. package/dist/core/sheet/Menu.js +21 -0
  41. package/dist/core/sheet/ValueViewer.js +1 -1
  42. package/dist/core/sheet/index.js +249 -88
  43. package/dist/core/sheet/index.less +199 -107
  44. package/dist/core/sheet/searchInput.d.ts +15 -0
  45. package/dist/core/sheet/searchInput.js +78 -0
  46. package/dist/core/sheet/useCellEvent.js +1 -1
  47. package/dist/core/sheet/useContextMenu.d.ts +1 -1
  48. package/dist/core/sheet/useContextMenu.js +13 -10
  49. package/dist/core/sheet/useKeyBoardEvent.js +19 -2
  50. package/dist/core/sheet/useMouseEvent.js +19 -12
  51. package/dist/core/sheet/useSearchInput.d.ts +11 -0
  52. package/dist/core/sheet/useSearchInput.js +65 -0
  53. package/dist/core/sheet/useSelectVisible.d.ts +1 -1
  54. package/dist/core/sheet/useSelectVisible.js +17 -7
  55. package/dist/core/sheet/useVirtualList.d.ts +10 -1
  56. package/dist/core/sheet/useVirtualList.js +44 -28
  57. package/dist/core/sheet/var.less +41 -34
  58. package/dist/core/shell/draggableShell/index.d.ts +4 -1
  59. package/dist/core/shell/draggableShell/index.js +133 -50
  60. package/dist/core/shell/tableShell.d.ts +4 -1
  61. package/dist/core/shell/tableShell.js +82 -34
  62. package/dist/core/table/addButton.d.ts +6 -0
  63. package/dist/core/table/addButton.js +103 -0
  64. package/dist/core/table/events.d.ts +1 -3
  65. package/dist/core/table/events.js +30 -35
  66. package/dist/core/table/index.js +97 -189
  67. package/dist/core/table/index.less +12 -0
  68. package/dist/core/table/useGroupConfig.d.ts +4 -1
  69. package/dist/core/table/useGroupConfig.js +139 -14
  70. package/dist/core/table/useRowSelection.d.ts +3 -0
  71. package/dist/core/table/useRowSelection.js +68 -2
  72. package/dist/core/util.d.ts +10 -4
  73. package/dist/core/util.js +121 -69
  74. package/dist/core/viewer/btnViewer/index.js +3 -3
  75. package/dist/core/viewer/cascaderViewer/index.js +6 -1
  76. package/dist/core/viewer/checkViewer/index.js +2 -2
  77. package/dist/core/viewer/editViewer/index.js +3 -3
  78. package/dist/core/viewer/groupViewer/index.js +26 -10
  79. package/dist/core/viewer/selectorViewer/index.js +7 -3
  80. package/dist/core/viewer/switchViewer/index.js +10 -4
  81. package/dist/example/antComponent.d.ts +1 -1
  82. package/dist/example/antComponent.js +63 -37
  83. package/dist/example/basic.d.ts +1 -1
  84. package/dist/example/basic.js +20 -14
  85. package/dist/example/ellipsis.d.ts +1 -1
  86. package/dist/example/ellipsis.js +3 -2
  87. package/dist/example/fixed.d.ts +1 -1
  88. package/dist/example/fixed.js +3 -2
  89. package/dist/example/group.js +40 -17
  90. package/dist/example/selection.d.ts +1 -1
  91. package/dist/example/selection.js +9 -8
  92. package/dist/example/sheet.d.ts +1 -1
  93. package/dist/example/sheet.js +21 -22
  94. package/dist/example/valuationAnalyze.d.ts +1 -0
  95. package/dist/example/valuationAnalyze.js +3 -4
  96. package/dist/hooks/index.d.ts +1 -1
  97. package/dist/hooks/index.js +1 -1
  98. package/dist/hooks/useEventBus.d.ts +1 -0
  99. package/dist/hooks/useEventBus.js +2 -2
  100. package/dist/hooks/useGroupConfig.d.ts +4 -0
  101. package/dist/hooks/useGroupConfig.js +5 -0
  102. package/dist/hooks/useKeyboard.d.ts +5 -2
  103. package/dist/hooks/useKeyboard.js +17 -3
  104. package/dist/hooks/useMiddlewareReducer.d.ts +5 -5
  105. package/dist/hooks/useMiddlewareReducer.js +3 -3
  106. package/dist/hooks/useMouse.d.ts +1 -1
  107. package/dist/hooks/useMouse.js +7 -7
  108. package/dist/hooks/useSetState.js +7 -7
  109. package/dist/hooks/useSheetEvent.d.ts +1 -1
  110. package/dist/hooks/useSheetEvent.js +2 -2
  111. package/dist/hooks/useWidthConfig.d.ts +3 -3
  112. package/dist/hooks/useWidthConfig.js +2 -2
  113. package/dist/standardUtils/index.d.ts +1 -1
  114. package/dist/standardUtils/index.js +1 -1
  115. package/dist/type/sheet.d.ts +77 -31
  116. package/dist/type/sheetTable.d.ts +21 -12
  117. package/package.json +7 -4
@@ -1,43 +1,47 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
3
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
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; }
11
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
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; } }
12
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- import { useEffect, useMemo, useRef } from 'react';
14
- import ReduxLogger from 'redux-logger';
7
+ import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "../../../node_modules/@types/react";
8
+ // import ReduxLogger from 'redux-logger';
15
9
  import ReduxThunk from 'redux-thunk';
16
10
  import DefaultRow from "./DefaultRow";
17
11
  import DefaultShell from "./DefaultShell";
18
- import { Button } from 'antd';
19
- import { isNil, isNumber } from 'lodash';
12
+ import { useGroup } from "../../hooks/useGroupConfig";
13
+ import { Empty } from 'antd';
14
+ import { isEmpty, isNil, isNumber } from 'lodash';
20
15
  import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
21
16
  import sheetReducer from "../reducers";
22
17
  import { classNames, getRowHeight, rowToActualRow } from "../util";
18
+ import { Control } from "./Control";
23
19
  import { DefaultRowMapper } from "./DefaultRowMapper";
20
+ import { Menu } from "./Menu";
24
21
  import "./index.less";
22
+ import { SearchInput } from "./searchInput";
25
23
  import { useCellEvent } from "./useCellEvent";
26
24
  import { useContextMenu } from "./useContextMenu";
27
25
  import { useKeyBoardEvent } from "./useKeyBoardEvent";
28
26
  import { useMouseEvent } from "./useMouseEvent";
27
+ import { useSearchInput } from "./useSearchInput";
29
28
  import { useSelectVisible } from "./useSelectVisible";
30
- import { useVirtualList } from "./useVirtualList";
31
- import { jsx as _jsx } from "react/jsx-runtime";
32
- import { jsxs as _jsxs } from "react/jsx-runtime";
29
+ import { VirtualizeEnd, VirtualizeStart, useVirtualList } from "./useVirtualList";
30
+ import { jsx as _jsx } from "../../../node_modules/@types/react/jsx-runtime";
31
+ import { jsxs as _jsxs } from "../../../node_modules/@types/react/jsx-runtime";
32
+ import { Fragment as _Fragment } from "../../../node_modules/@types/react/jsx-runtime";
33
33
  var Sheet = function Sheet(props) {
34
- var _state$data$length, _state$data3, _scroll$y, _scroll$x;
34
+ var _visibleData$length, _scroll$y, _scroll$x;
35
35
  var _props$sheetInstance = props.sheetInstance,
36
36
  sheetInstance = _props$sheetInstance === void 0 ? {
37
37
  current: null
38
38
  } : _props$sheetInstance,
39
39
  _props$sheetRenderer = props.sheetRenderer,
40
40
  SheetShell = _props$sheetRenderer === void 0 ? DefaultShell : _props$sheetRenderer,
41
+ _props$emptyRenderer = props.emptyRenderer,
42
+ emptyRenderer = _props$emptyRenderer === void 0 ? /*#__PURE__*/_jsx(Empty, {
43
+ description: "\u6682\u65E0\u6570\u636E"
44
+ }) : _props$emptyRenderer,
41
45
  _props$rowRenderer = props.rowRenderer,
42
46
  Row = _props$rowRenderer === void 0 ? DefaultRow : _props$rowRenderer,
43
47
  ContextMenu = props.menuRenderer,
@@ -47,31 +51,50 @@ var Sheet = function Sheet(props) {
47
51
  data = props.data,
48
52
  _props$freePaste = props.freePaste,
49
53
  freePaste = _props$freePaste === void 0 ? false : _props$freePaste,
50
- _props$groupConfig = props.groupConfig,
51
- groupConfig = _props$groupConfig === void 0 ? undefined : _props$groupConfig,
52
54
  onCellsChanged = props.onCellsChanged,
53
55
  onContextMenu = props.onContextMenu,
54
56
  rowClassName = props.rowClassName,
55
57
  scroll = props.scroll,
56
58
  children = props.children,
57
- showBackEdit = props.showBackEdit,
58
- backEditStyle = props.backEditStyle;
59
+ _props$showBackEdit = props.showBackEdit,
60
+ showBackEdit = _props$showBackEdit === void 0 ? true : _props$showBackEdit,
61
+ backEditStyle = props.backEditStyle,
62
+ _props$boldScroll = props.boldScroll,
63
+ boldScroll = _props$boldScroll === void 0 ? true : _props$boldScroll,
64
+ _props$hideColBar = props.hideColBar,
65
+ hideColBar = _props$hideColBar === void 0 ? true : _props$hideColBar,
66
+ _props$showQuickLocat = props.showQuickLocationBtn,
67
+ showQuickLocationBtn = _props$showQuickLocat === void 0 ? false : _props$showQuickLocat,
68
+ ControlContainer = props.ControlContainer;
69
+ var _useState = useState(false),
70
+ _useState2 = _slicedToArray(_useState, 2),
71
+ isScrolledOver = _useState2[0],
72
+ setIsScrolledOver = _useState2[1];
73
+ var _useState3 = useState(false),
74
+ _useState4 = _slicedToArray(_useState3, 2),
75
+ isScrolledToEnd = _useState4[0],
76
+ setIsScrolledToEnd = _useState4[1];
59
77
  var sheetWrapperRef = useRef(null);
60
78
  var contextMenuRef = useRef(null);
61
79
  var eventBus = useEventBus();
80
+ var _useGroup = useGroup(),
81
+ groupConfig = _useGroup.config;
62
82
  var _useMiddlewareReducer = useMiddlewareReducer(sheetReducer, {
63
83
  data: data,
64
84
  mouseDown: false,
65
85
  editing: undefined,
66
86
  lastFocus: [],
67
87
  groupConfig: groupConfig,
68
- eventBus: eventBus
69
- }, [ReduxThunk, ReduxLogger]),
88
+ eventBus: eventBus,
89
+ fixedInfo: []
90
+ },
91
+ // [ReduxThunk, ReduxLogger],
92
+ [ReduxThunk]),
70
93
  _useMiddlewareReducer2 = _slicedToArray(_useMiddlewareReducer, 2),
71
94
  state = _useMiddlewareReducer2[0],
72
95
  dispatch = _useMiddlewareReducer2[1];
73
- useEffect(function () {
74
- sheetInstance.current = {
96
+ useImperativeHandle(sheetInstance, function () {
97
+ return {
75
98
  zoomTo: function zoomTo(row) {
76
99
  // 给定 row 回到行
77
100
  // 不给定 row 默认回到编辑行和列
@@ -79,14 +102,42 @@ var Sheet = function Sheet(props) {
79
102
  var _ref, _sheetWrapperRef$curr;
80
103
  var _getState = getState(),
81
104
  start = _getState.start,
82
- groupConfig = _getState.groupConfig;
105
+ groupConfig = _getState.groupConfig,
106
+ data = _getState.data;
83
107
  var container = sheetWrapperRef.current;
84
108
  if (!start && isNil(row)) return;
85
- var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig);
109
+ var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig, data.length);
86
110
  var rowHeight = getRowHeight(container);
87
111
  var firstRowCell = container.querySelector("td.cell[data-col='".concat(start === null || start === void 0 ? void 0 : start.col, "']"));
88
112
  var colPosition = firstRowCell ? firstRowCell.offsetLeft - firstRowCell.clientWidth : 0;
89
- (_sheetWrapperRef$curr = sheetWrapperRef.current) === null || _sheetWrapperRef$curr === void 0 ? void 0 : _sheetWrapperRef$curr.scrollTo(isNumber(row) ? 0 : colPosition, rowHeight * actual);
113
+ var scrollHeight = actual * rowHeight;
114
+ (_sheetWrapperRef$curr = sheetWrapperRef.current) === null || _sheetWrapperRef$curr === void 0 || _sheetWrapperRef$curr.scrollTo(isNumber(row) ? 0 : colPosition, scrollHeight);
115
+
116
+ // 最后一行的bug暂时用 scroll end 事件来处理
117
+ if (isNil(row) && start.row === data.length - 1 && sheetWrapperRef.current) {
118
+ var handleScrollEnd = function handleScrollEnd() {
119
+ var _sheetWrapperRef$curr2, _sheetWrapperRef$curr3;
120
+ (_sheetWrapperRef$curr2 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr2 === void 0 || _sheetWrapperRef$curr2.scrollTo(isNumber(row) ? 0 : colPosition, scrollHeight);
121
+ (_sheetWrapperRef$curr3 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr3 === void 0 || _sheetWrapperRef$curr3.removeEventListener('scrollend', handleScrollEnd);
122
+ };
123
+ sheetWrapperRef.current.addEventListener('scrollend', handleScrollEnd);
124
+ }
125
+ });
126
+ },
127
+ goTo: function goTo(row, col) {
128
+ dispatch(function (d, getState) {
129
+ var _sheetWrapperRef$curr4;
130
+ var _getState2 = getState(),
131
+ groupConfig = _getState2.groupConfig,
132
+ data = _getState2.data;
133
+ var container = sheetWrapperRef.current;
134
+ if (isNil(row) || isNil(col)) return;
135
+ var actual = rowToActualRow(row, groupConfig, data.length);
136
+ var rowHeight = getRowHeight(container);
137
+ var firstRowCell = container.querySelector("td.cell[data-col='".concat(col, "']"));
138
+ var colPosition = firstRowCell ? firstRowCell.offsetLeft - firstRowCell.clientWidth : 0;
139
+ var scrollHeight = actual * rowHeight;
140
+ (_sheetWrapperRef$curr4 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr4 === void 0 || _sheetWrapperRef$curr4.scrollTo(colPosition, scrollHeight);
90
141
  });
91
142
  },
92
143
  pushToHistory: function pushToHistory(config) {
@@ -102,7 +153,7 @@ var Sheet = function Sheet(props) {
102
153
  });
103
154
  } else {
104
155
  dispatch({
105
- type: 'selectRow',
156
+ type: 'selectOneRow',
106
157
  payload: row
107
158
  });
108
159
  }
@@ -119,9 +170,19 @@ var Sheet = function Sheet(props) {
119
170
  type: 'popHistory'
120
171
  });
121
172
  return history !== null && history !== void 0 && history.length ? history === null || history === void 0 ? void 0 : history[history.length - 1] : {};
173
+ },
174
+ dropHistory: function dropHistory() {
175
+ var history = state.history;
176
+ dispatch({
177
+ type: 'changes',
178
+ payload: {
179
+ history: []
180
+ }
181
+ });
182
+ return history !== null && history !== void 0 ? history : [];
122
183
  }
123
184
  };
124
- }, [sheetWrapperRef.current, state.history]);
185
+ }, [state.history]);
125
186
  useEffect(function () {
126
187
  // 同步必要的状态
127
188
  dispatch({
@@ -143,19 +204,37 @@ var Sheet = function Sheet(props) {
143
204
  useEffect(function () {
144
205
  if (!state.editing && state.start) {
145
206
  setTimeout(function () {
146
- var _sheetWrapperRef$curr2;
207
+ var _sheetWrapperRef$curr5;
147
208
  // 表格获取焦点 + 接收keyboard event
148
- (_sheetWrapperRef$curr2 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr2 === void 0 ? void 0 : _sheetWrapperRef$curr2.focus({
209
+ (_sheetWrapperRef$curr5 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr5 === void 0 || _sheetWrapperRef$curr5.focus({
149
210
  preventScroll: true
150
211
  });
151
212
  }, 1);
152
213
  }
153
214
  }, [state.editing, state.start]);
154
- var _useVirtualList = useVirtualList(sheetWrapperRef, state.data, groupConfig, virtualized),
215
+ var visibleData = useMemo(function () {
216
+ var _groupConfig$groups, _state$data;
217
+ if (!(groupConfig !== null && groupConfig !== void 0 && (_groupConfig$groups = groupConfig.groups) !== null && _groupConfig$groups !== void 0 && _groupConfig$groups.length)) {
218
+ return state.data;
219
+ }
220
+ return (_state$data = state.data) === null || _state$data === void 0 ? void 0 : _state$data.filter(function (item, index) {
221
+ if (!(groupConfig !== null && groupConfig !== void 0 && groupConfig.configMap.has(index))) {
222
+ return true;
223
+ }
224
+ var rowConfig = groupConfig.configMap.get(index);
225
+ return (rowConfig === null || rowConfig === void 0 ? void 0 : rowConfig.isOpen) || (rowConfig === null || rowConfig === void 0 ? void 0 : rowConfig.isStart);
226
+ });
227
+ }, [state.data, groupConfig]);
228
+ var _useVirtualList = useVirtualList(sheetWrapperRef, visibleData, virtualized),
155
229
  virtualStart = _useVirtualList.virtualStart,
156
230
  virtualEnd = _useVirtualList.virtualEnd,
157
231
  paddingTop = _useVirtualList.paddingTop,
158
232
  paddingBottom = _useVirtualList.paddingBottom;
233
+ var _useSearchInput = useSearchInput(state, dispatch, sheetInstance),
234
+ closeSearch = _useSearchInput.closeSearch,
235
+ changeSearch = _useSearchInput.changeSearch,
236
+ goNext = _useSearchInput.goNext,
237
+ goLast = _useSearchInput.goLast;
159
238
  useEffect(function () {
160
239
  dispatch({
161
240
  type: 'clearEdit'
@@ -165,77 +244,159 @@ var Sheet = function Sheet(props) {
165
244
  });
166
245
  }, [groupConfig]);
167
246
  var rowElements = useMemo(function () {
168
- var _state$data, _state$data$slice;
169
- return state === null || state === void 0 ? void 0 : (_state$data = state.data) === null || _state$data === void 0 ? void 0 : (_state$data$slice = _state$data.slice(virtualStart, virtualEnd)) === null || _state$data$slice === void 0 ? void 0 : _state$data$slice.map(function (rowData) {
170
- var _state$data2, _rowData;
171
- var row = (state === null || state === void 0 ? void 0 : (_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : _state$data2.indexOf(rowData)) || 0;
172
- var rowCN = rowClassName instanceof Function ? rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(rowData === null || rowData === void 0 ? void 0 : (_rowData = rowData[rowData.length - 1]) === null || _rowData === void 0 ? void 0 : _rowData.record, row) : rowClassName;
247
+ var _visibleData$slice;
248
+ return visibleData === null || visibleData === void 0 || (_visibleData$slice = visibleData.slice(virtualStart, virtualEnd)) === null || _visibleData$slice === void 0 ? void 0 : _visibleData$slice.map(function (rowData) {
249
+ var _rowData$, _rowData;
250
+ var row = ((_rowData$ = rowData[0]) === null || _rowData$ === void 0 ? void 0 : _rowData$.row) || 0;
251
+ 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;
173
252
  return /*#__PURE__*/_jsx(Row, {
174
253
  row: row,
175
254
  cells: rowData,
176
- groupConfig: groupConfig,
177
255
  rowClassName: rowCN,
178
256
  children: /*#__PURE__*/_jsx(DefaultRowMapper, {
257
+ fixedInfo: state.fixedInfo,
179
258
  rowData: rowData,
180
- row: row
259
+ row: row,
260
+ isScrolledOver: isScrolledOver,
261
+ isScrolledToEnd: isScrolledToEnd
181
262
  })
182
263
  }, row);
183
264
  });
184
- }, [state.data, groupConfig, virtualStart, virtualEnd, rowClassName]);
185
- 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;
186
- var startRowVisible = useSelectVisible(sheetWrapperRef, state.start);
265
+ }, [visibleData, groupConfig, virtualStart, virtualEnd, rowClassName, state.fixedInfo]);
266
+ 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;
267
+ var _useSelectVisible = useSelectVisible(sheetWrapperRef, state.start),
268
+ _useSelectVisible2 = _slicedToArray(_useSelectVisible, 1),
269
+ startRowVisible = _useSelectVisible2[0];
270
+ var _useSelectVisible3 = useSelectVisible(sheetWrapperRef, {
271
+ col: 0,
272
+ row: 0
273
+ }),
274
+ _useSelectVisible4 = _slicedToArray(_useSelectVisible3, 1),
275
+ firstRowVisible = _useSelectVisible4[0];
276
+ var _useSelectVisible5 = useSelectVisible(sheetWrapperRef, {
277
+ col: 0,
278
+ row: ((data === null || data === void 0 ? void 0 : data.length) || 1) - 1
279
+ }),
280
+ _useSelectVisible6 = _slicedToArray(_useSelectVisible5, 1),
281
+ lastRowVisible = _useSelectVisible6[0];
282
+ var isEmptyData = isEmpty(state.data);
283
+ var EmptyElement = useMemo(function () {
284
+ if (isEmptyData) {
285
+ return /*#__PURE__*/_jsx("div", {
286
+ style: {
287
+ marginTop: 16,
288
+ marginBottom: 16
289
+ },
290
+ children: emptyRenderer
291
+ });
292
+ }
293
+ return null;
294
+ }, [isEmptyData, emptyRenderer]);
295
+ var hasHorizontalScrollbar = sheetWrapperRef.current && sheetWrapperRef.current.scrollWidth > sheetWrapperRef.current.clientWidth;
296
+ var handleScroll = useCallback(function () {
297
+ if (!sheetWrapperRef.current) {
298
+ return;
299
+ }
300
+ var div = sheetWrapperRef.current;
301
+
302
+ // 当前的滚动位置
303
+ var scrollLeft = div.scrollLeft;
304
+ // 整个内容的宽度
305
+ var scrollWidth = div.scrollWidth;
306
+ // 当前可视区域的宽度
307
+ var clientWidth = div.clientWidth;
308
+ setIsScrolledOver(scrollLeft > 0);
309
+ if (scrollWidth === clientWidth) {
310
+ setIsScrolledToEnd(true);
311
+ return;
312
+ }
313
+ // 判断是否滚动到底
314
+ if (scrollLeft + clientWidth + 1 >= scrollWidth) {
315
+ setIsScrolledToEnd(true);
316
+ } else {
317
+ setIsScrolledToEnd(false);
318
+ }
319
+ }, []);
320
+ useEffect(function () {
321
+ if (sheetWrapperRef.current) {
322
+ handleScroll();
323
+ }
324
+ }, []);
187
325
  return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
188
326
  value: eventBus,
189
- children: /*#__PURE__*/_jsxs("span", {
190
- ref: sheetWrapperRef,
191
- tabIndex: 0,
192
- className: classNames('harvest harvest-sheet-container', className),
193
- style: {
194
- maxHeight: (_scroll$y = scroll === null || scroll === void 0 ? void 0 : scroll.y) !== null && _scroll$y !== void 0 ? _scroll$y : memoHeight,
195
- width: (_scroll$x = scroll === null || scroll === void 0 ? void 0 : scroll.x) !== null && _scroll$x !== void 0 ? _scroll$x : '100%'
196
- },
197
- children: [/*#__PURE__*/_jsxs(SheetShell, {
198
- className: classNames('harvest-sheet', className),
199
- children: [virtualized && /*#__PURE__*/_jsx("tr", {
200
- style: {
201
- height: 0,
202
- paddingBottom: paddingTop,
203
- display: 'block'
204
- }
205
- }), rowElements, virtualized && paddingBottom > 0 && /*#__PURE__*/_jsx("tr", {
206
- style: {
207
- height: 0,
208
- paddingBottom: paddingBottom,
209
- display: 'block'
210
- }
211
- })]
212
- }, "sheet"), ContextMenu ? /*#__PURE__*/_jsx("div", {
213
- ref: contextMenuRef,
327
+ children: /*#__PURE__*/_jsxs(_Fragment, {
328
+ children: [/*#__PURE__*/_jsxs("span", {
214
329
  style: {
215
- display: menu.showMenu ? '' : 'none'
330
+ position: 'relative'
216
331
  },
217
- children: /*#__PURE__*/_jsx(ContextMenu, {
218
- position: menu.position,
219
- cell: menu.cellPosition,
220
- onContextMenu: onContextMenu
221
- })
222
- }) : null, /*#__PURE__*/_jsxs("div", {
223
- className: "harvest-sheet-control",
224
- children: [children, showBackEdit && !startRowVisible ? /*#__PURE__*/_jsx(Button, {
225
- type: "dashed",
226
- onClick: function onClick() {
227
- var _sheetInstance$curren;
228
- return sheetInstance === null || sheetInstance === void 0 ? void 0 : (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
332
+ children: [/*#__PURE__*/_jsxs("span", {
333
+ ref: sheetWrapperRef,
334
+ tabIndex: 0,
335
+ className: classNames('harvest harvest-sheet-container', className, hasHorizontalScrollbar && boldScroll ? 'tableWarpScroll' : null, hideColBar ? 'hideColBar' : null),
336
+ style: {
337
+ maxHeight: (_scroll$y = scroll === null || scroll === void 0 ? void 0 : scroll.y) !== null && _scroll$y !== void 0 ? _scroll$y : memoHeight,
338
+ width: (_scroll$x = scroll === null || scroll === void 0 ? void 0 : scroll.x) !== null && _scroll$x !== void 0 ? _scroll$x : '100%'
229
339
  },
230
- style: _objectSpread({
231
- position: 'absolute',
232
- zIndex: 4
233
- }, !backEditStyle ? {
234
- top: 0,
235
- right: 0
236
- } : backEditStyle),
237
- children: "\u56DE\u5230\u7F16\u8F91\u884C"
238
- }) : null]
340
+ onScroll: handleScroll,
341
+ children: [/*#__PURE__*/_jsxs(SheetShell, {
342
+ className: classNames('harvest-sheet', className),
343
+ isScrolledOver: isScrolledOver,
344
+ isScrolledToEnd: isScrolledToEnd,
345
+ children: [/*#__PURE__*/_jsx(VirtualizeStart, {
346
+ virtualized: virtualized,
347
+ paddingTop: paddingTop
348
+ }), rowElements, /*#__PURE__*/_jsx(VirtualizeEnd, {
349
+ virtualized: virtualized,
350
+ paddingBottom: paddingBottom
351
+ })]
352
+ }, "sheet"), /*#__PURE__*/_jsx(Menu, {
353
+ ref: contextMenuRef,
354
+ position: menu.position,
355
+ cell: menu.cellPosition,
356
+ showMenu: menu.showMenu,
357
+ contextMenu: ContextMenu,
358
+ onContextMenu: onContextMenu
359
+ }), EmptyElement]
360
+ }), /*#__PURE__*/_jsxs("div", {
361
+ className: "harvest-sheet-control",
362
+ children: [/*#__PURE__*/_jsx(Control, {
363
+ showBackEdit: showBackEdit,
364
+ startRowVisible: startRowVisible,
365
+ backToEditRow: function backToEditRow() {
366
+ var _sheetInstance$curren;
367
+ return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
368
+ },
369
+ firstRowVisible: firstRowVisible,
370
+ lastRowVisible: lastRowVisible,
371
+ backEditStyle: backEditStyle,
372
+ toTop: function toTop() {
373
+ var _sheetInstance$curren2;
374
+ return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren2 = sheetInstance.current) === null || _sheetInstance$curren2 === void 0 ? void 0 : _sheetInstance$curren2.zoomTo(0);
375
+ },
376
+ toBottom: function toBottom() {
377
+ var _sheetInstance$curren3, _data$length;
378
+ return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren3 = sheetInstance.current) === null || _sheetInstance$curren3 === void 0 ? void 0 : _sheetInstance$curren3.zoomTo(((_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 1) - 1);
379
+ },
380
+ showQuickLocationBtn: showQuickLocationBtn,
381
+ ControlContainer: ControlContainer,
382
+ selectInfo: {
383
+ start: state.start,
384
+ end: state.end,
385
+ selecting: state.selecting
386
+ }
387
+ }), children]
388
+ })]
389
+ }), /*#__PURE__*/_jsx(SearchInput, {
390
+ style: props.searchStyle,
391
+ value: state.searchText,
392
+ total: state.searchTotal,
393
+ current: state.searchCurrent,
394
+ calledCount: state.searchCalledCount,
395
+ open: state.showSearch,
396
+ goNext: goNext,
397
+ goLast: goLast,
398
+ onChange: changeSearch,
399
+ onClose: closeSearch
239
400
  })]
240
401
  })
241
402
  });