@zhenliang/sheet 0.0.8 → 0.1.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 (147) hide show
  1. package/README.md +3 -2
  2. package/dist/core/config.js +1 -2
  3. package/dist/core/editor/cascaderEditor/index.js +14 -7
  4. package/dist/core/editor/dateEditor/index.d.ts +1 -1
  5. package/dist/core/editor/dateEditor/index.js +2 -3
  6. package/dist/core/editor/index.d.ts +1 -1
  7. package/dist/core/editor/index.js +2 -3
  8. package/dist/core/editor/numberEditor/index.js +50 -6
  9. package/dist/core/editor/numberEditor/index.less +1 -0
  10. package/dist/core/editor/selectEditor/index.d.ts +1 -1
  11. package/dist/core/editor/selectEditor/index.js +23 -5
  12. package/dist/core/reducers/index.d.ts +1 -1
  13. package/dist/core/reducers/index.js +3 -2
  14. package/dist/core/reducers/keyboardReducer.js +2 -3
  15. package/dist/core/reducers/mouseReducer.js +1 -2
  16. package/dist/core/reducers/sideEffectReducer.js +49 -25
  17. package/dist/core/reducers/stateReducer.js +35 -10
  18. package/dist/core/sheet/Cell.js +37 -16
  19. package/dist/core/sheet/DataEditor.js +4 -2
  20. package/dist/core/sheet/DefaultCell.js +1 -2
  21. package/dist/core/sheet/DefaultRow.d.ts +1 -0
  22. package/dist/core/sheet/DefaultRow.js +5 -3
  23. package/dist/core/sheet/DefaultRowMapper.js +1 -2
  24. package/dist/core/sheet/DefaultShell.js +1 -2
  25. package/dist/core/sheet/Event.js +2 -3
  26. package/dist/core/sheet/ValueViewer.js +1 -2
  27. package/dist/core/sheet/index.js +54 -15
  28. package/dist/core/sheet/index.less +20 -11
  29. package/dist/core/sheet/useCellEvent.js +1 -2
  30. package/dist/core/sheet/useContextMenu.d.ts +1 -1
  31. package/dist/core/sheet/useContextMenu.js +2 -3
  32. package/dist/core/sheet/useKeyBoardEvent.js +15 -3
  33. package/dist/core/sheet/useMouseEvent.js +3 -4
  34. package/dist/core/sheet/useSelectVisible.d.ts +2 -0
  35. package/dist/core/sheet/useSelectVisible.js +48 -0
  36. package/dist/core/sheet/useVirtualList.d.ts +1 -1
  37. package/dist/core/sheet/useVirtualList.js +24 -20
  38. package/dist/core/shell/draggableShell/index.d.ts +0 -1
  39. package/dist/core/shell/draggableShell/index.js +21 -13
  40. package/dist/core/shell/tableShell.d.ts +0 -1
  41. package/dist/core/shell/tableShell.js +9 -6
  42. package/dist/core/table/events.d.ts +15 -0
  43. package/dist/core/table/events.js +94 -0
  44. package/dist/core/table/index.js +91 -112
  45. package/dist/core/table/useGroupConfig.js +24 -7
  46. package/dist/core/table/useRowSelection.d.ts +2 -1
  47. package/dist/core/table/useRowSelection.js +1 -2
  48. package/dist/core/table/util.js +2 -3
  49. package/dist/core/util.d.ts +5 -2
  50. package/dist/core/util.js +97 -16
  51. package/dist/core/viewer/btnViewer/index.js +2 -3
  52. package/dist/core/viewer/cascaderViewer/index.d.ts +2 -0
  53. package/dist/core/viewer/cascaderViewer/index.js +11 -0
  54. package/dist/core/viewer/checkViewer/index.js +2 -3
  55. package/dist/core/viewer/editViewer/index.js +2 -3
  56. package/dist/core/viewer/groupViewer/index.js +5 -3
  57. package/dist/core/viewer/index.d.ts +1 -0
  58. package/dist/core/viewer/index.js +2 -2
  59. package/dist/core/viewer/selectorViewer/index.d.ts +2 -0
  60. package/dist/core/viewer/selectorViewer/index.js +12 -0
  61. package/dist/core/viewer/switchViewer/index.js +2 -3
  62. package/dist/example/antComponent.js +60 -14
  63. package/dist/example/basic.js +2 -3
  64. package/dist/example/ellipsis.js +1 -2
  65. package/dist/example/fixed.js +1 -2
  66. package/dist/example/group.js +42 -4
  67. package/dist/example/selection.js +2 -3
  68. package/dist/example/sheet.js +52 -16
  69. package/dist/example/valuationAnalyze.js +20 -18
  70. package/dist/hooks/index.d.ts +1 -0
  71. package/dist/hooks/index.js +1 -1
  72. package/dist/hooks/useEventBus.d.ts +0 -1
  73. package/dist/hooks/useEventBus.js +1 -2
  74. package/dist/hooks/useKeyboard.js +1 -2
  75. package/dist/hooks/useMiddlewareReducer.js +1 -2
  76. package/dist/hooks/useMouse.js +1 -2
  77. package/dist/hooks/useSetState.js +1 -2
  78. package/dist/hooks/useSheetEvent.js +1 -2
  79. package/dist/hooks/useWidthConfig.d.ts +4 -0
  80. package/dist/hooks/useWidthConfig.js +5 -0
  81. package/dist/index.d.ts +4 -0
  82. package/dist/index.js +4 -1
  83. package/dist/standardUtils/index.js +2 -3
  84. package/dist/type/index.js +1 -2
  85. package/dist/type/sheet.d.ts +14 -3
  86. package/dist/type/sheet.js +1 -2
  87. package/dist/type/sheetTable.d.ts +43 -14
  88. package/dist/type/sheetTable.js +1 -2
  89. package/package.json +1 -1
  90. package/dist/core/config.js.map +0 -1
  91. package/dist/core/editor/cascaderEditor/index.js.map +0 -1
  92. package/dist/core/editor/dateEditor/index.js.map +0 -1
  93. package/dist/core/editor/index.js.map +0 -1
  94. package/dist/core/editor/numberEditor/index.js.map +0 -1
  95. package/dist/core/editor/selectEditor/index.js.map +0 -1
  96. package/dist/core/reducers/index.js.map +0 -1
  97. package/dist/core/reducers/keyboardReducer.js.map +0 -1
  98. package/dist/core/reducers/mouseReducer.js.map +0 -1
  99. package/dist/core/reducers/sideEffectReducer.js.map +0 -1
  100. package/dist/core/reducers/stateReducer.js.map +0 -1
  101. package/dist/core/sheet/Cell.js.map +0 -1
  102. package/dist/core/sheet/DataEditor.js.map +0 -1
  103. package/dist/core/sheet/DefaultCell.js.map +0 -1
  104. package/dist/core/sheet/DefaultRow.js.map +0 -1
  105. package/dist/core/sheet/DefaultRowMapper.js.map +0 -1
  106. package/dist/core/sheet/DefaultShell.js.map +0 -1
  107. package/dist/core/sheet/Event.js.map +0 -1
  108. package/dist/core/sheet/ValueViewer.js.map +0 -1
  109. package/dist/core/sheet/index.js.map +0 -1
  110. package/dist/core/sheet/useCellEvent.js.map +0 -1
  111. package/dist/core/sheet/useContextMenu.js.map +0 -1
  112. package/dist/core/sheet/useKeyBoardEvent.js.map +0 -1
  113. package/dist/core/sheet/useMouseEvent.js.map +0 -1
  114. package/dist/core/sheet/useVirtualList.js.map +0 -1
  115. package/dist/core/shell/draggableShell/index.js.map +0 -1
  116. package/dist/core/shell/tableShell.js.map +0 -1
  117. package/dist/core/table/index.js.map +0 -1
  118. package/dist/core/table/useGroupConfig.js.map +0 -1
  119. package/dist/core/table/useRowSelection.js.map +0 -1
  120. package/dist/core/table/util.js.map +0 -1
  121. package/dist/core/util.js.map +0 -1
  122. package/dist/core/viewer/btnViewer/index.js.map +0 -1
  123. package/dist/core/viewer/checkViewer/index.js.map +0 -1
  124. package/dist/core/viewer/editViewer/index.js.map +0 -1
  125. package/dist/core/viewer/groupViewer/index.js.map +0 -1
  126. package/dist/core/viewer/index.js.map +0 -1
  127. package/dist/core/viewer/switchViewer/index.js.map +0 -1
  128. package/dist/example/antComponent.js.map +0 -1
  129. package/dist/example/basic.js.map +0 -1
  130. package/dist/example/ellipsis.js.map +0 -1
  131. package/dist/example/fixed.js.map +0 -1
  132. package/dist/example/group.js.map +0 -1
  133. package/dist/example/selection.js.map +0 -1
  134. package/dist/example/sheet.js.map +0 -1
  135. package/dist/example/valuationAnalyze.js.map +0 -1
  136. package/dist/hooks/index.js.map +0 -1
  137. package/dist/hooks/useEventBus.js.map +0 -1
  138. package/dist/hooks/useKeyboard.js.map +0 -1
  139. package/dist/hooks/useMiddlewareReducer.js.map +0 -1
  140. package/dist/hooks/useMouse.js.map +0 -1
  141. package/dist/hooks/useSetState.js.map +0 -1
  142. package/dist/hooks/useSheetEvent.js.map +0 -1
  143. package/dist/index.js.map +0 -1
  144. package/dist/standardUtils/index.js.map +0 -1
  145. package/dist/type/index.js.map +0 -1
  146. package/dist/type/sheet.js.map +0 -1
  147. package/dist/type/sheetTable.js.map +0 -1
@@ -64,8 +64,13 @@ var Cell = function Cell(props) {
64
64
  return;
65
65
  }
66
66
  var onCellState = function onCellState(eventInfo) {
67
- if (eventInfo.value && eventInfo.editing) {
68
- setValue(eventInfo.value);
67
+ if (eventInfo.editing === false && !eventInfo.confirm) {
68
+ // 退出编辑,重设数据
69
+ setValue(valueRef.current);
70
+ } else if (eventInfo.value && eventInfo.editing) {
71
+ var _cell$dataEditor, _cell$dataEditor2, _cell$dataEditor2$par;
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) : value);
69
74
  }
70
75
  setEventState(eventInfo);
71
76
  };
@@ -87,29 +92,42 @@ var Cell = function Cell(props) {
87
92
  confirm: false
88
93
  });
89
94
  if (value !== valueRef.current) {
90
- var _cell$dataEditor, _cell$dataEditor$form, _cell$dataEditor2;
91
- console.log('confirm omit');
95
+ var _cell$dataEditor3, _cell$dataEditor4, _cell$dataEditor4$che;
96
+ if (cell !== null && cell !== void 0 && (_cell$dataEditor3 = cell.dataEditor) !== null && _cell$dataEditor3 !== void 0 && _cell$dataEditor3.checker && !((_cell$dataEditor4 = cell.dataEditor) !== null && _cell$dataEditor4 !== void 0 && (_cell$dataEditor4$che = _cell$dataEditor4.checker) !== null && _cell$dataEditor4$che !== void 0 && _cell$dataEditor4$che.call(_cell$dataEditor4, value, cell.record))) {
97
+ setValue(valueRef.current);
98
+ return;
99
+ }
92
100
  eventBus.emit('cell-change', {
93
101
  row: row,
94
102
  col: col,
95
- value: (_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.formatter ? (_cell$dataEditor$form = (_cell$dataEditor2 = cell.dataEditor).formatter) === null || _cell$dataEditor$form === void 0 ? void 0 : _cell$dataEditor$form.call(_cell$dataEditor2, value) : value
103
+ id: cell.id,
104
+ value: value
105
+ // 没必要format value 已经是legal 的值了
106
+ // value: cell.dataEditor?.formatter
107
+ // ? cell.dataEditor.formatter?.(value)
108
+ // : value,
96
109
  });
97
110
  }
98
111
  }
99
112
  }, [confirm, eventBus, value, cell]);
100
113
  var handleCommit = useCallback(function (value) {
114
+ var _cell$dataEditor5, _cell$dataEditor6, _cell$dataEditor6$che;
101
115
  if (valueRef.current === value) {
102
116
  return;
103
117
  }
118
+ if (cell !== null && cell !== void 0 && (_cell$dataEditor5 = cell.dataEditor) !== null && _cell$dataEditor5 !== void 0 && _cell$dataEditor5.checker && !((_cell$dataEditor6 = cell.dataEditor) !== null && _cell$dataEditor6 !== void 0 && (_cell$dataEditor6$che = _cell$dataEditor6.checker) !== null && _cell$dataEditor6$che !== void 0 && _cell$dataEditor6$che.call(_cell$dataEditor6, value, cell.record))) {
119
+ setValue(valueRef.current);
120
+ return;
121
+ }
104
122
  setValue(value);
105
- console.log('handle omit');
106
123
  eventBus.emit('cell-change', {
107
124
  row: row,
108
125
  col: col,
126
+ id: cell.id,
109
127
  value: value,
110
128
  confirm: true
111
129
  });
112
- }, [eventBus, valueRef]);
130
+ }, [eventBus, valueRef, cell]);
113
131
  var renderEditor = function renderEditor(cel, r, col, editor, isEditing) {
114
132
  if (isEditing) {
115
133
  var Editor = cel.dataEditor || editor || DataEditor;
@@ -118,6 +136,7 @@ var Cell = function Cell(props) {
118
136
  row: r,
119
137
  col: col,
120
138
  value: value,
139
+ record: cel.record,
121
140
  onConfirm: handleCommit,
122
141
  onChange: setValue
123
142
  });
@@ -127,12 +146,15 @@ var Cell = function Cell(props) {
127
146
  var renderViewer = function renderViewer(cel, r, col, valViewer) {
128
147
  var Viewer = cell.valueViewer || valViewer || ValueViewer;
129
148
  var val = renderValue(cell);
130
- return /*#__PURE__*/_jsx(Viewer, {
131
- record: cell.record,
132
- cell: cell,
133
- row: row,
134
- col: col,
135
- value: val
149
+ return /*#__PURE__*/_jsx("span", {
150
+ className: "value-viewer",
151
+ children: /*#__PURE__*/_jsx(Viewer, {
152
+ record: cell.record,
153
+ cell: cell,
154
+ row: row,
155
+ col: col,
156
+ value: val
157
+ })
136
158
  });
137
159
  };
138
160
  var content = ((_cell$editable = cell.editable) !== null && _cell$editable !== void 0 ? _cell$editable : true) && editing ? renderEditor(cell, row, col, dataEditor, editing) : renderViewer(cell, row, col, valueViewer);
@@ -154,7 +176,6 @@ var Cell = function Cell(props) {
154
176
  });
155
177
  };
156
178
  export default /*#__PURE__*/memo(Cell, function (pre, next) {
157
- var shouldUpdate = pre.col === next.col && pre.row === next.row && pre.cell.value === next.cell.value && pre.cell.record === next.cell.record;
179
+ var shouldUpdate = pre.col === next.col && pre.row === next.row && pre.cell.value === next.cell.value && pre.cell.dataEditor === next.cell.dataEditor && pre.cell.record === next.cell.record;
158
180
  return shouldUpdate;
159
- });
160
- //# sourceMappingURL=Cell.js.map
181
+ });
@@ -13,10 +13,12 @@ var DataEditor = function DataEditor(_ref) {
13
13
  };
14
14
  return /*#__PURE__*/_jsx("input", {
15
15
  ref: inputRef,
16
+ onMouseDown: function onMouseDown(e) {
17
+ return e.stopPropagation();
18
+ },
16
19
  className: "data-editor",
17
20
  value: value,
18
21
  onChange: handleChange
19
22
  });
20
23
  };
21
- export default DataEditor;
22
- //# sourceMappingURL=DataEditor.js.map
24
+ export default DataEditor;
@@ -28,5 +28,4 @@ var DefaultCell = function DefaultCell(props) {
28
28
  children: children
29
29
  }));
30
30
  };
31
- export default DefaultCell;
32
- //# sourceMappingURL=DefaultCell.js.map
31
+ export default DefaultCell;
@@ -2,6 +2,7 @@
2
2
  import type { SheetType } from "../../type";
3
3
  declare const DefaultRow: React.FC<{
4
4
  children: React.ReactElement;
5
+ rowClassName?: string;
5
6
  row: number;
6
7
  groupConfig?: {
7
8
  groups: SheetType.RowGroup[];
@@ -3,7 +3,8 @@ import { groupConfigToGroupMap } from "../util";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  var DefaultRow = function DefaultRow(_ref) {
5
5
  var _groupMap$get, _groupMap$get2;
6
- var children = _ref.children,
6
+ var rowClassName = _ref.rowClassName,
7
+ children = _ref.children,
7
8
  row = _ref.row,
8
9
  groupConfig = _ref.groupConfig;
9
10
  var groupMap = useMemo(function () {
@@ -12,6 +13,7 @@ var DefaultRow = function DefaultRow(_ref) {
12
13
  }, [groupConfig]);
13
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)) {
14
15
  return /*#__PURE__*/_jsx("tr", {
16
+ className: rowClassName,
15
17
  style: {
16
18
  display: 'none'
17
19
  },
@@ -19,8 +21,8 @@ var DefaultRow = function DefaultRow(_ref) {
19
21
  });
20
22
  }
21
23
  return /*#__PURE__*/_jsx("tr", {
24
+ className: rowClassName,
22
25
  children: children
23
26
  });
24
27
  };
25
- export default DefaultRow;
26
- //# sourceMappingURL=DefaultRow.js.map
28
+ export default DefaultRow;
@@ -12,5 +12,4 @@ export var DefaultRowMapper = /*#__PURE__*/memo(function (_ref) {
12
12
  }, col);
13
13
  });
14
14
  return cls;
15
- });
16
- //# sourceMappingURL=DefaultRowMapper.js.map
15
+ });
@@ -9,5 +9,4 @@ var DefaultShell = function DefaultShell(_ref) {
9
9
  })
10
10
  });
11
11
  };
12
- export default DefaultShell;
13
- //# sourceMappingURL=DefaultShell.js.map
12
+ export default DefaultShell;
@@ -1,4 +1,4 @@
1
- import { useSheetEvent } from "../../hooks";
1
+ import { useSheetEvent } from "../..";
2
2
  import { useEffect } from 'react';
3
3
  export var SheetEvent = function SheetEvent(_ref) {
4
4
  var handler = _ref.handler,
@@ -14,5 +14,4 @@ export var SheetEvent = function SheetEvent(_ref) {
14
14
  };
15
15
  }, [eventBus, handler, name]);
16
16
  return null;
17
- };
18
- //# sourceMappingURL=Event.js.map
17
+ };
@@ -6,5 +6,4 @@ var ValueViewer = function ValueViewer(_ref) {
6
6
  children: value
7
7
  });
8
8
  };
9
- export default ValueViewer;
10
- //# sourceMappingURL=ValueViewer.js.map
9
+ export default ValueViewer;
@@ -1,3 +1,9 @@
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); }
1
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
8
  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."); }
3
9
  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); }
@@ -9,7 +15,8 @@ import ReduxLogger from 'redux-logger';
9
15
  import ReduxThunk from 'redux-thunk';
10
16
  import DefaultRow from "./DefaultRow";
11
17
  import DefaultShell from "./DefaultShell";
12
- import { isNil } from 'lodash';
18
+ import { Button } from 'antd';
19
+ import { isNil, isNumber } from 'lodash';
13
20
  import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
14
21
  import sheetReducer from "../reducers";
15
22
  import { classNames, getRowHeight, rowToActualRow } from "../util";
@@ -19,6 +26,7 @@ import { useCellEvent } from "./useCellEvent";
19
26
  import { useContextMenu } from "./useContextMenu";
20
27
  import { useKeyBoardEvent } from "./useKeyBoardEvent";
21
28
  import { useMouseEvent } from "./useMouseEvent";
29
+ import { useSelectVisible } from "./useSelectVisible";
22
30
  import { useVirtualList } from "./useVirtualList";
23
31
  import { jsx as _jsx } from "react/jsx-runtime";
24
32
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -45,7 +53,9 @@ var Sheet = function Sheet(props) {
45
53
  onContextMenu = props.onContextMenu,
46
54
  rowClassName = props.rowClassName,
47
55
  scroll = props.scroll,
48
- children = props.children;
56
+ children = props.children,
57
+ showBackEdit = props.showBackEdit,
58
+ backEditStyle = props.backEditStyle;
49
59
  var sheetWrapperRef = useRef(null);
50
60
  var contextMenuRef = useRef(null);
51
61
  var eventBus = useEventBus();
@@ -63,16 +73,20 @@ var Sheet = function Sheet(props) {
63
73
  useEffect(function () {
64
74
  sheetInstance.current = {
65
75
  zoomTo: function zoomTo(row) {
66
- // 默认回到编辑行
76
+ // 给定 row 回到行
77
+ // 不给定 row 默认回到编辑行和列
67
78
  dispatch(function (d, getState) {
68
79
  var _ref, _sheetWrapperRef$curr;
69
80
  var _getState = getState(),
70
81
  start = _getState.start,
71
82
  groupConfig = _getState.groupConfig;
83
+ var container = sheetWrapperRef.current;
72
84
  if (!start && isNil(row)) return;
73
85
  var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig);
74
- var rowHeight = getRowHeight(sheetWrapperRef.current);
75
- (_sheetWrapperRef$curr = sheetWrapperRef.current) === null || _sheetWrapperRef$curr === void 0 ? void 0 : _sheetWrapperRef$curr.scrollTo(0, rowHeight * actual);
86
+ var rowHeight = getRowHeight(container);
87
+ var firstRowCell = container.querySelector("td.cell[data-col='".concat(start === null || start === void 0 ? void 0 : start.col, "']"));
88
+ 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);
76
90
  });
77
91
  },
78
92
  pushToHistory: function pushToHistory(config) {
@@ -93,11 +107,21 @@ var Sheet = function Sheet(props) {
93
107
  });
94
108
  }
95
109
  },
110
+ select: function select(props) {
111
+ dispatch({
112
+ type: 'select',
113
+ payload: props
114
+ });
115
+ },
96
116
  popHistory: function popHistory() {
97
- return {};
117
+ var history = state.history;
118
+ dispatch({
119
+ type: 'popHistory'
120
+ });
121
+ return history !== null && history !== void 0 && history.length ? history === null || history === void 0 ? void 0 : history[history.length - 1] : {};
98
122
  }
99
123
  };
100
- }, [sheetWrapperRef.current]);
124
+ }, [sheetWrapperRef.current, state.history]);
101
125
  useEffect(function () {
102
126
  // 同步必要的状态
103
127
  dispatch({
@@ -127,7 +151,7 @@ var Sheet = function Sheet(props) {
127
151
  }, 1);
128
152
  }
129
153
  }, [state.editing, state.start]);
130
- var _useVirtualList = useVirtualList(sheetWrapperRef, state.data, virtualized),
154
+ var _useVirtualList = useVirtualList(sheetWrapperRef, state.data, groupConfig, virtualized),
131
155
  virtualStart = _useVirtualList.virtualStart,
132
156
  virtualEnd = _useVirtualList.virtualEnd,
133
157
  paddingTop = _useVirtualList.paddingTop,
@@ -143,21 +167,23 @@ var Sheet = function Sheet(props) {
143
167
  var rowElements = useMemo(function () {
144
168
  var _state$data, _state$data$slice;
145
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) {
146
- var _state$data2;
170
+ var _state$data2, _rowData;
147
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;
148
173
  return /*#__PURE__*/_jsx(Row, {
149
174
  row: row,
150
175
  cells: rowData,
151
176
  groupConfig: groupConfig,
152
- rowClassName: rowClassName,
177
+ rowClassName: rowCN,
153
178
  children: /*#__PURE__*/_jsx(DefaultRowMapper, {
154
179
  rowData: rowData,
155
180
  row: row
156
181
  })
157
182
  }, row);
158
183
  });
159
- }, [state.data, groupConfig, virtualStart, virtualEnd]);
184
+ }, [state.data, groupConfig, virtualStart, virtualEnd, rowClassName]);
160
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);
161
187
  return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
162
188
  value: eventBus,
163
189
  children: /*#__PURE__*/_jsxs("span", {
@@ -193,12 +219,25 @@ var Sheet = function Sheet(props) {
193
219
  cell: menu.cellPosition,
194
220
  onContextMenu: onContextMenu
195
221
  })
196
- }) : null, /*#__PURE__*/_jsx("div", {
222
+ }) : null, /*#__PURE__*/_jsxs("div", {
197
223
  className: "harvest-sheet-control",
198
- children: children
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();
229
+ },
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]
199
239
  })]
200
240
  })
201
241
  });
202
242
  };
203
- export default Sheet;
204
- //# sourceMappingURL=index.js.map
243
+ export default Sheet;
@@ -91,6 +91,12 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
91
91
  box-shadow: var(--cell-fixed-box-shadow-left);
92
92
  }
93
93
 
94
+
95
+ &.fixed-right{
96
+ // transform: translateX(1px);
97
+
98
+ }
99
+
94
100
  &.fixed-right::after{
95
101
  position: absolute;
96
102
  top: 0;
@@ -124,22 +130,32 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
124
130
  }
125
131
 
126
132
  .harvest-sheet-container .harvest-sheet .cell.selected-top{
127
- border-top-color: var(--resizer) !important;
133
+ border-top-color: var(--resizer);
128
134
  }
129
135
 
130
136
  .harvest-sheet-container .harvest-sheet .cell.selected-left{
131
- border-left-color: var(--resizer) !important;
137
+ border-left-color: var(--resizer);
132
138
  }
133
139
 
134
140
  .harvest-sheet-container .harvest-sheet .cell.selected-bottom{
135
- border-bottom-color: var(--resizer) !important;
141
+ border-bottom-color: var(--resizer);
136
142
  }
137
143
 
138
144
  .harvest-sheet-container .harvest-sheet .cell.selected-right{
139
- border-right-color: var(--resizer) !important;
145
+ border-right-color: var(--resizer);
140
146
  }
141
147
 
142
148
 
149
+ .harvest-sheet-container .harvest-sheet .cell.sheet-control{
150
+ border-right: 1px solid transparent;
151
+ background: var(--cell-background-color) ;
152
+ color:var(--read-color);
153
+
154
+ &.read-only{
155
+ border-right: 1px solid var(--cell-title-background-color);
156
+ }
157
+ // position: relative !important;
158
+ }
143
159
 
144
160
  .harvest-sheet-container .harvest-sheet .cell.read-only {
145
161
  background: var(--cell-read-only-background-color);
@@ -147,12 +163,6 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
147
163
  text-align: center;
148
164
  }
149
165
 
150
- .harvest-sheet-container .harvest-sheet .cell.sheet-control{
151
- border-right: 1px solid transparent;
152
- background: var(--cell-background-color) ;
153
- color:var(--read-color);
154
- // position: relative !important;
155
- }
156
166
 
157
167
  .harvest-sheet-container .harvest-sheet .cell-title.sheet-control{
158
168
  border-right: 1px solid var(--cell-title-background-color);
@@ -263,7 +273,6 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
263
273
  .harvest-sheet-container .harvest-sheet-control{
264
274
  position: sticky;
265
275
  z-index: 3;
266
- height: 32px;
267
276
  bottom: 0;
268
277
  left: 0;
269
278
  background-color: white;
@@ -19,5 +19,4 @@ export var useCellEvent = function useCellEvent(dispatch, listenerVar) {
19
19
  useEffect(function () {
20
20
  dispatch(sideEffectReducer.emitEditChange);
21
21
  }, [editing, lastEditing]);
22
- };
23
- //# sourceMappingURL=useCellEvent.js.map
22
+ };
@@ -1,4 +1,4 @@
1
- import { Dispatch } from "../../hooks";
1
+ import { Dispatch } from "../..";
2
2
  import type { SheetType } from "../../type";
3
3
  export declare type MenuEvent = {
4
4
  showMenu: boolean;
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
10
10
  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
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; } }
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- import { useSetState } from "../../hooks";
13
+ import { useSetState } from "../..";
14
14
  import { useEffect } from 'react';
15
15
  import { calcMenuPosition, extractDataRowAndCol, findParentTd } from "../util";
16
16
  export var useContextMenu = function useContextMenu(dispatch, elementRef) {
@@ -83,5 +83,4 @@ export var useContextMenu = function useContextMenu(dispatch, elementRef) {
83
83
  };
84
84
  }, [elementRef.current, enableContextMenu]);
85
85
  return _objectSpread({}, menuEvent);
86
- };
87
- //# sourceMappingURL=useContextMenu.js.map
86
+ };
@@ -1,12 +1,25 @@
1
- import { useKeyBoard } from "../../hooks";
1
+ import { useKeyBoard } from "../..";
2
2
  import { sideEffectReducer } from "../reducers/sideEffectReducer";
3
+ import { getRowHeight } from "../util";
3
4
  export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
4
5
  useKeyBoard({
5
6
  move: function move(e, value) {
7
+ e.preventDefault();
6
8
  dispatch({
7
9
  type: 'move',
8
10
  payload: value
9
11
  });
12
+ // todo 横向滚动的处理
13
+ var _ref = value,
14
+ row = _ref.row;
15
+ if (Math.abs(row) !== 0) {
16
+ var _elementRef$current;
17
+ var rowHeight = getRowHeight(elementRef.current);
18
+ var itemHeight = rowHeight || 30;
19
+ elementRef === null || elementRef === void 0 ? void 0 : (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.scrollBy({
20
+ top: itemHeight * row
21
+ });
22
+ }
10
23
  },
11
24
  escape: function escape() {
12
25
  dispatch({
@@ -50,5 +63,4 @@ export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
50
63
  dispatch(sideEffectReducer.delete);
51
64
  }
52
65
  }, elementRef.current);
53
- };
54
- //# sourceMappingURL=useKeyBoardEvent.js.map
66
+ };
@@ -1,8 +1,8 @@
1
- import { useMouse } from "../../hooks";
1
+ import { useMouse } from "../..";
2
2
  import { useCallback, useRef } from 'react';
3
3
  import { extractDataRowAndCol, findParentTd } from "../util";
4
4
  var rowCount = 10; //每秒10行
5
- var colCount = 5; //每秒3
5
+ var colCount = 5; //每秒5
6
6
 
7
7
  export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
8
8
  var animateRef = useRef(false);
@@ -295,5 +295,4 @@ export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
295
295
  doubleClick: doubleClick,
296
296
  loseFocus: loseFocus
297
297
  }, elementRef.current);
298
- };
299
- //# sourceMappingURL=useMouseEvent.js.map
298
+ };
@@ -0,0 +1,2 @@
1
+ import { SheetType } from "../../type";
2
+ export declare const useSelectVisible: (sheetWrapper: React.RefObject<SheetType.refAssertion>, start?: SheetType.CellPosition) => boolean;
@@ -0,0 +1,48 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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."); }
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); }
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
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { throttle } from 'lodash';
8
+ import { useEffect, useState } from 'react';
9
+ export var useSelectVisible = function useSelectVisible(sheetWrapper, start) {
10
+ var _useState = useState(true),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ startVisible = _useState2[0],
13
+ setStartVisible = _useState2[1];
14
+ useEffect(function () {
15
+ var _sheetWrapper$current3;
16
+ var handleScroll = throttle(function () {
17
+ var _sheetWrapper$current, _sheetWrapper$current2;
18
+ if (!start) {
19
+ return;
20
+ }
21
+ var startCell = (_sheetWrapper$current = sheetWrapper.current) === null || _sheetWrapper$current === void 0 ? void 0 : _sheetWrapper$current.querySelector("td.cell[data-row='".concat(start.row, "']"));
22
+ if (!startCell) return false;
23
+ var _ref = ((_sheetWrapper$current2 = sheetWrapper.current) === null || _sheetWrapper$current2 === void 0 ? void 0 : _sheetWrapper$current2.getBoundingClientRect()) || {},
24
+ _ref$top = _ref.top,
25
+ top = _ref$top === void 0 ? 0 : _ref$top,
26
+ _ref$bottom = _ref.bottom,
27
+ bottom = _ref$bottom === void 0 ? 0 : _ref$bottom;
28
+ var _ref2 = (startCell === null || startCell === void 0 ? void 0 : startCell.getBoundingClientRect()) || {},
29
+ cellTop = _ref2.top,
30
+ cellBottom = _ref2.bottom;
31
+ if (top < cellTop && bottom > cellBottom) {
32
+ setStartVisible(true);
33
+ } else {
34
+ setStartVisible(false);
35
+ }
36
+ }, 100);
37
+ handleScroll();
38
+ (_sheetWrapper$current3 = sheetWrapper.current) === null || _sheetWrapper$current3 === void 0 ? void 0 : _sheetWrapper$current3.addEventListener('scroll', handleScroll);
39
+ return function () {
40
+ var _sheetWrapper$current4;
41
+ (_sheetWrapper$current4 = sheetWrapper.current) === null || _sheetWrapper$current4 === void 0 ? void 0 : _sheetWrapper$current4.removeEventListener('scroll', handleScroll);
42
+ };
43
+ }, [sheetWrapper.current, start]);
44
+ if (!start) {
45
+ return true;
46
+ }
47
+ return startVisible;
48
+ };
@@ -1,5 +1,5 @@
1
1
  import type { SheetType } from "../../type";
2
- export declare const useVirtualList: (elementRef: React.RefObject<SheetType.refAssertion>, data?: SheetType.Cell[][], virtualized?: boolean) => {
2
+ export declare const useVirtualList: (elementRef: React.RefObject<SheetType.refAssertion>, data?: SheetType.Cell[][], groupConfig?: SheetType.RowGroupConfig, virtualized?: boolean) => {
3
3
  virtualStart: number;
4
4
  virtualEnd: number;
5
5
  paddingTop: number;