@zhenliang/sheet 0.1.6 → 0.1.7-3.beta.1

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 (99) 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 +10 -9
  9. package/dist/core/editor/cascaderEditor/index.less +15 -7
  10. package/dist/core/editor/dateEditor/index.js +29 -6
  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 +60 -25
  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 +31 -16
  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.js +30 -21
  27. package/dist/core/sheet/Control.d.ts +21 -0
  28. package/dist/core/sheet/Control.js +83 -0
  29. package/dist/core/sheet/DataEditor.js +1 -1
  30. package/dist/core/sheet/DefaultCell.d.ts +8 -3
  31. package/dist/core/sheet/DefaultCell.js +11 -7
  32. package/dist/core/sheet/DefaultRow.js +1 -7
  33. package/dist/core/sheet/DefaultRowMapper.d.ts +3 -0
  34. package/dist/core/sheet/DefaultRowMapper.js +19 -3
  35. package/dist/core/sheet/Menu.d.ts +6 -0
  36. package/dist/core/sheet/Menu.js +21 -0
  37. package/dist/core/sheet/index.js +247 -86
  38. package/dist/core/sheet/index.less +199 -107
  39. package/dist/core/sheet/searchInput.d.ts +15 -0
  40. package/dist/core/sheet/searchInput.js +78 -0
  41. package/dist/core/sheet/useContextMenu.d.ts +1 -1
  42. package/dist/core/sheet/useContextMenu.js +12 -9
  43. package/dist/core/sheet/useKeyBoardEvent.js +19 -2
  44. package/dist/core/sheet/useMouseEvent.js +19 -12
  45. package/dist/core/sheet/useSearchInput.d.ts +11 -0
  46. package/dist/core/sheet/useSearchInput.js +65 -0
  47. package/dist/core/sheet/useSelectVisible.d.ts +1 -1
  48. package/dist/core/sheet/useSelectVisible.js +16 -6
  49. package/dist/core/sheet/useVirtualList.d.ts +10 -1
  50. package/dist/core/sheet/useVirtualList.js +44 -28
  51. package/dist/core/sheet/var.less +41 -34
  52. package/dist/core/shell/draggableShell/index.d.ts +3 -0
  53. package/dist/core/shell/draggableShell/index.js +130 -47
  54. package/dist/core/shell/tableShell.d.ts +3 -0
  55. package/dist/core/shell/tableShell.js +78 -30
  56. package/dist/core/table/addButton.d.ts +6 -0
  57. package/dist/core/table/addButton.js +103 -0
  58. package/dist/core/table/events.d.ts +0 -2
  59. package/dist/core/table/events.js +25 -31
  60. package/dist/core/table/index.js +94 -187
  61. package/dist/core/table/index.less +12 -0
  62. package/dist/core/table/useGroupConfig.d.ts +4 -1
  63. package/dist/core/table/useGroupConfig.js +138 -13
  64. package/dist/core/table/useRowSelection.d.ts +3 -0
  65. package/dist/core/table/useRowSelection.js +67 -1
  66. package/dist/core/util.d.ts +10 -4
  67. package/dist/core/util.js +121 -69
  68. package/dist/core/viewer/cascaderViewer/index.js +6 -1
  69. package/dist/core/viewer/groupViewer/index.js +24 -8
  70. package/dist/core/viewer/selectorViewer/index.js +7 -3
  71. package/dist/core/viewer/switchViewer/index.js +8 -2
  72. package/dist/example/antComponent.js +61 -35
  73. package/dist/example/basic.js +16 -10
  74. package/dist/example/ellipsis.js +1 -0
  75. package/dist/example/fixed.js +1 -0
  76. package/dist/example/group.js +38 -15
  77. package/dist/example/selection.js +7 -6
  78. package/dist/example/sheet.js +18 -19
  79. package/dist/example/valuationAnalyze.d.ts +1 -0
  80. package/dist/example/valuationAnalyze.js +1 -2
  81. package/dist/hooks/index.d.ts +1 -1
  82. package/dist/hooks/index.js +1 -1
  83. package/dist/hooks/useEventBus.d.ts +1 -0
  84. package/dist/hooks/useEventBus.js +1 -1
  85. package/dist/hooks/useGroupConfig.d.ts +4 -0
  86. package/dist/hooks/useGroupConfig.js +5 -0
  87. package/dist/hooks/useKeyboard.d.ts +5 -2
  88. package/dist/hooks/useKeyboard.js +16 -2
  89. package/dist/hooks/useMiddlewareReducer.d.ts +5 -5
  90. package/dist/hooks/useMiddlewareReducer.js +2 -2
  91. package/dist/hooks/useMouse.d.ts +1 -1
  92. package/dist/hooks/useMouse.js +6 -6
  93. package/dist/hooks/useSetState.js +6 -6
  94. package/dist/hooks/useWidthConfig.d.ts +3 -3
  95. package/dist/standardUtils/index.d.ts +1 -1
  96. package/dist/standardUtils/index.js +1 -1
  97. package/dist/type/sheet.d.ts +76 -31
  98. package/dist/type/sheetTable.d.ts +21 -12
  99. package/package.json +11 -5
@@ -1,15 +1,15 @@
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); }
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  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; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
- 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); }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
6
  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."); }
7
7
  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); }
8
8
  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; }
9
- 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; } }
9
+ 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; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { useEffect, useMemo, useRef } from 'react';
12
- import { useSetState, useWidth } from "../../../hooks";
11
+ import { createElement, useEffect, useMemo, useRef } from 'react';
12
+ import { useSetState, useSheetEvent, useWidth } from "../../../hooks";
13
13
  import { classNames } from "../../util";
14
14
  import { CheckViewer } from "../../viewer/checkViewer";
15
15
  import { GroupViewer } from "../../viewer/groupViewer";
@@ -26,7 +26,9 @@ export var DraggableShell = function DraggableShell(_ref) {
26
26
  _ref$controlWidth = _ref.controlWidth,
27
27
  controlWidth = _ref$controlWidth === void 0 ? 30 : _ref$controlWidth;
28
28
  var TableShell = function TableShell(_ref2) {
29
- var children = _ref2.children;
29
+ var children = _ref2.children,
30
+ isScrolledOver = _ref2.isScrolledOver,
31
+ isScrolledToEnd = _ref2.isScrolledToEnd;
30
32
  var headRef = useRef(null);
31
33
  var downRef = useRef(null);
32
34
  var _useSetState = useSetState({}),
@@ -36,11 +38,54 @@ export var DraggableShell = function DraggableShell(_ref) {
36
38
  var _useWidth = useWidth(),
37
39
  contextWidths = _useWidth.widths,
38
40
  contextSetWidth = _useWidth.onChange;
41
+ var eventBus = useSheetEvent();
39
42
  var setWidth = contextSetWidth || _setWidth;
40
43
  var widths = contextWidths || _widths;
41
44
  var hasControl = showGroup || showSelect;
45
+ var offset = 1 + (hasControl ? 1 : 0);
46
+ var colItems = useMemo(function () {
47
+ var cols = [/*#__PURE__*/_jsx("col", {
48
+ className: classNames('sheet-control sheet-row-cursor'),
49
+ style: {
50
+ width: 0,
51
+ border: 'none'
52
+ }
53
+ }, "sheet-row-cursor")];
54
+ if (hasControl) {
55
+ cols.push( /*#__PURE__*/_jsx("col", {
56
+ className: classNames('sheet-control'),
57
+ style: {
58
+ width: controlWidth
59
+ }
60
+ }, "sheet-control"));
61
+ }
62
+ var i = 0;
63
+ columns.forEach(function (item, index) {
64
+ var _item$titleConfig, _item$dataIndex;
65
+ var currentWidth = item.width || 'unset';
66
+ if (((_item$titleConfig = item.titleConfig) === null || _item$titleConfig === void 0 ? void 0 : _item$titleConfig.colSpan) !== 0) {
67
+ currentWidth = widths[i] || item.width || 'unset';
68
+ i++;
69
+ }
70
+ cols.push( /*#__PURE__*/_jsx("col", {
71
+ className: classNames('cell'),
72
+ style: {
73
+ width: currentWidth,
74
+ border: 'none'
75
+ }
76
+ }, (_item$dataIndex = item.dataIndex) !== null && _item$dataIndex !== void 0 ? _item$dataIndex : index));
77
+ });
78
+ return cols;
79
+ }, [widths, hasControl, columns]);
42
80
  var thItems = useMemo(function () {
43
- var ths = [];
81
+ var ths = [/*#__PURE__*/_jsx("th", {
82
+ className: "cell cell-title read-only sheet-control sheet-row-cursor"
83
+ }, -2)];
84
+ var positionArr = [{
85
+ isLastFixedLeft: false,
86
+ isFirstFixedRight: false,
87
+ fixPosition: 0
88
+ }];
44
89
  if (hasControl) {
45
90
  var _controlProps$group, _controlProps$check, _controlProps$check2, _controlProps$check3;
46
91
  ths.push( /*#__PURE__*/_jsxs("th", {
@@ -50,30 +95,69 @@ export var DraggableShell = function DraggableShell(_ref) {
50
95
  col: -1,
51
96
  value: true,
52
97
  record: {
53
- open: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$group = controlProps.group) === null || _controlProps$group === void 0 ? void 0 : _controlProps$group.open,
98
+ open: controlProps === null || controlProps === void 0 || (_controlProps$group = controlProps.group) === null || _controlProps$group === void 0 ? void 0 : _controlProps$group.open,
54
99
  isHeader: true
55
100
  }
56
101
  }), showSelect && /*#__PURE__*/_jsx(CheckViewer, {
57
102
  row: -1,
58
103
  col: -1,
59
- value: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$check = controlProps.check) === null || _controlProps$check === void 0 ? void 0 : _controlProps$check.checked,
104
+ value: controlProps === null || controlProps === void 0 || (_controlProps$check = controlProps.check) === null || _controlProps$check === void 0 ? void 0 : _controlProps$check.checked,
60
105
  record: {
61
- open: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$check2 = controlProps.check) === null || _controlProps$check2 === void 0 ? void 0 : _controlProps$check2.checked,
106
+ open: controlProps === null || controlProps === void 0 || (_controlProps$check2 = controlProps.check) === null || _controlProps$check2 === void 0 ? void 0 : _controlProps$check2.checked,
62
107
  isHeader: true,
63
- indeterminate: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$check3 = controlProps.check) === null || _controlProps$check3 === void 0 ? void 0 : _controlProps$check3.indeterminate
108
+ indeterminate: controlProps === null || controlProps === void 0 || (_controlProps$check3 = controlProps.check) === null || _controlProps$check3 === void 0 ? void 0 : _controlProps$check3.indeterminate
64
109
  }
65
110
  })]
66
111
  }, "-1"));
112
+ positionArr.push({
113
+ isLastFixedLeft: false,
114
+ isFirstFixedRight: false,
115
+ fixPosition: 0
116
+ });
67
117
  }
118
+ var fixLeftPosition = 0;
119
+ var fixRightPosition = columns.reduce(function (pre, cur, index) {
120
+ if (cur.fixed === 'right') {
121
+ var positionIndex = hasControl ? index + 2 : index + 1;
122
+ return pre + colItems[positionIndex].props.style.width;
123
+ }
124
+ return pre + 0;
125
+ }, 0);
68
126
  columns.forEach(function (item, index) {
69
- var _item$titleConfig, _item$titleConfig2, _item$titleConfig3, _item$dataIndex, _ref3;
70
- ((_item$titleConfig = item.titleConfig) === null || _item$titleConfig === void 0 ? void 0 : _item$titleConfig.colSpan) !== 0 && ths.push( /*#__PURE__*/_jsx("th", {
71
- className: classNames('cell', 'cell-title', 'read-only', item.fixed && 'fixed', item.fixed && "fixed-".concat(item.fixed), (_item$titleConfig2 = item.titleConfig) === null || _item$titleConfig2 === void 0 ? void 0 : _item$titleConfig2.className),
72
- colSpan: (_item$titleConfig3 = item.titleConfig) === null || _item$titleConfig3 === void 0 ? void 0 : _item$titleConfig3.colSpan,
127
+ var _item$titleConfig2, _item$titleConfig3, _item$titleConfig4, _item$dataIndex2, _ref3;
128
+ var positionIndex = hasControl ? index + 2 : index + 1;
129
+ if (item.fixed === 'right') {
130
+ fixRightPosition -= colItems[positionIndex].props.style.width;
131
+ }
132
+ var isLastFixedLeft = item.fixed === 'left' && !columns.slice(index + 1).some(function (item) {
133
+ return item.fixed === 'left';
134
+ });
135
+ var isFirstFixedRight = item.fixed === 'right' && !columns.slice(0, index).some(function (item) {
136
+ return item.fixed === 'right';
137
+ });
138
+ positionArr.push({
139
+ isLastFixedLeft: isLastFixedLeft,
140
+ isFirstFixedRight: isFirstFixedRight,
141
+ fixPosition: item.fixed === 'right' ? fixRightPosition : fixLeftPosition
142
+ });
143
+ ((_item$titleConfig2 = item.titleConfig) === null || _item$titleConfig2 === void 0 ? void 0 : _item$titleConfig2.colSpan) !== 0 && ths.push( /*#__PURE__*/_jsx("th", {
144
+ className: classNames('cell', 'cell-title', 'read-only', item.fixed && 'fixed', item.fixed && "fixed-".concat(item.fixed), (_item$titleConfig3 = item.titleConfig) === null || _item$titleConfig3 === void 0 ? void 0 : _item$titleConfig3.className, isLastFixedLeft && isScrolledOver ? "last-fixed-left" : '', isFirstFixedRight && !isScrolledToEnd ? "first-fixed-right" : ''),
145
+ colSpan: (_item$titleConfig4 = item.titleConfig) === null || _item$titleConfig4 === void 0 ? void 0 : _item$titleConfig4.colSpan,
146
+ onClick: function onClick(e) {
147
+ if (item.fixed) return;
148
+ var target = e.target;
149
+ if (e.nativeEvent.offsetX <= target.offsetWidth - 8) {
150
+ var _item$titleConfig5;
151
+ eventBus.emit('col-select', {
152
+ col: positionIndex,
153
+ colSpan: (_item$titleConfig5 = item.titleConfig) === null || _item$titleConfig5 === void 0 ? void 0 : _item$titleConfig5.colSpan
154
+ });
155
+ }
156
+ },
73
157
  style: {
74
158
  textAlign: (_ref3 = item.align) !== null && _ref3 !== void 0 ? _ref3 : 'unset',
75
- left: item.fixed === 'left' ? 0 : 'unset',
76
- right: item.fixed === 'right' ? 0 : 'unset'
159
+ left: item.fixed === 'left' ? fixLeftPosition : 'unset',
160
+ right: item.fixed === 'right' ? fixRightPosition : 'unset'
77
161
  },
78
162
  onMouseDown: function onMouseDown(e) {
79
163
  var target = e.target;
@@ -82,16 +166,23 @@ export var DraggableShell = function DraggableShell(_ref) {
82
166
  downRef.current.mouseDown = true;
83
167
  downRef.current.oldX = e.nativeEvent.x;
84
168
  downRef.current.oldWidth = downRef.current.offsetWidth;
169
+ e.preventDefault();
85
170
  } else {
86
171
  downRef.current = null;
87
172
  }
88
173
  },
89
174
  onMouseMove: function onMouseMove(e) {
90
175
  var target = e.target;
91
- if (e.nativeEvent.offsetX > target.offsetWidth - 10) {
176
+ if (target instanceof HTMLSpanElement) {
177
+ if (target.parentElement instanceof HTMLTableCellElement) {
178
+ target.parentElement.style.cursor = '';
179
+ }
180
+ return;
181
+ }
182
+ if (e.nativeEvent.offsetX > target.offsetWidth - 8) {
92
183
  target.style.cursor = 'col-resize';
93
184
  } else {
94
- target.style.cursor = 'default';
185
+ target.style.cursor = item.fixed ? 'default' : '';
95
186
  }
96
187
  //取出暂存的Table Cell
97
188
  if (downRef.current === undefined) downRef.current = target;
@@ -99,33 +190,18 @@ export var DraggableShell = function DraggableShell(_ref) {
99
190
  },
100
191
  children: /*#__PURE__*/_jsx("span", {
101
192
  className: "value-viewer",
102
- children: item.title
193
+ children: typeof item.title === 'function' ? /*#__PURE__*/createElement(item.title) : item.title
103
194
  })
104
- }, (_item$dataIndex = item.dataIndex) !== null && _item$dataIndex !== void 0 ? _item$dataIndex : index));
105
- });
106
- return ths;
107
- }, [columns]);
108
- var colItems = useMemo(function () {
109
- var cols = [];
110
- if (hasControl) {
111
- cols.push( /*#__PURE__*/_jsx("col", {
112
- className: classNames('sheet-control'),
113
- style: {
114
- width: controlWidth
115
- }
116
- }, "sheet-control"));
117
- }
118
- columns.forEach(function (item, index) {
119
- var _item$dataIndex2;
120
- cols.push( /*#__PURE__*/_jsx("col", {
121
- className: classNames('cell'),
122
- style: {
123
- width: widths[index] || item.width || 'unset'
124
- }
125
195
  }, (_item$dataIndex2 = item.dataIndex) !== null && _item$dataIndex2 !== void 0 ? _item$dataIndex2 : index));
196
+ if (item.fixed === 'left') {
197
+ fixLeftPosition += colItems[positionIndex].props.style.width;
198
+ }
126
199
  });
127
- return cols;
128
- }, [widths, hasControl, columns]);
200
+ setTimeout(function () {
201
+ eventBus.emit('change-fixed-position', positionArr);
202
+ }, 16);
203
+ return ths;
204
+ }, [columns, colItems, isScrolledOver, isScrolledToEnd]);
129
205
  useEffect(function () {
130
206
  var handleMouseUp = function handleMouseUp() {
131
207
  //结束宽度调整
@@ -141,14 +217,18 @@ export var DraggableShell = function DraggableShell(_ref) {
141
217
  var _downRef$current$oldW, _downRef$current$oldX;
142
218
  downRef.current.style.cursor = 'default';
143
219
  if (((_downRef$current$oldW = downRef.current.oldWidth) !== null && _downRef$current$oldW !== void 0 ? _downRef$current$oldW : 0) + (e.x - ((_downRef$current$oldX = downRef.current.oldX) !== null && _downRef$current$oldX !== void 0 ? _downRef$current$oldX : 0)) > 0) {
144
- var _downRef$current$oldW2, _downRef$current$oldX2, _headRef$current;
220
+ var _downRef$current$oldW2, _downRef$current$oldX2, _headRef$current, _columns$actualIndex;
145
221
  var newWidth = Math.max(Number(((_downRef$current$oldW2 = downRef.current.oldWidth) !== null && _downRef$current$oldW2 !== void 0 ? _downRef$current$oldW2 : 0) + (e.x - ((_downRef$current$oldX2 = downRef.current.oldX) !== null && _downRef$current$oldX2 !== void 0 ? _downRef$current$oldX2 : 0))), 50);
146
222
  var cellList = [].slice.call((_headRef$current = headRef.current) === null || _headRef$current === void 0 ? void 0 : _headRef$current.cells);
147
223
  var changeIndex = cellList.indexOf(downRef.current);
224
+ var actualIndex = changeIndex - offset;
225
+ var isDoubleSpan = (((_columns$actualIndex = columns[actualIndex]) === null || _columns$actualIndex === void 0 || (_columns$actualIndex = _columns$actualIndex.titleConfig) === null || _columns$actualIndex === void 0 ? void 0 : _columns$actualIndex.colSpan) || 0) > 1;
226
+ var nextColumn = columns[actualIndex + 1] || {};
227
+ var nextWidth = +String(nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.width).replace('px', '');
148
228
  //调整该列中的每个Cell
149
229
  var _widths2 = _defineProperty({
150
230
  length: columns.length
151
- }, hasControl ? changeIndex - 1 : changeIndex, newWidth);
231
+ }, actualIndex, isDoubleSpan ? newWidth - nextWidth : newWidth);
152
232
  setWidth(_widths2);
153
233
  }
154
234
  }
@@ -159,7 +239,7 @@ export var DraggableShell = function DraggableShell(_ref) {
159
239
  document.removeEventListener('mouseup', handleMouseUp);
160
240
  document.removeEventListener('mousemove', handleMouseMove);
161
241
  };
162
- }, [hasControl]);
242
+ }, [hasControl, offset]);
163
243
  return /*#__PURE__*/_jsxs(_Fragment, {
164
244
  children: [/*#__PURE__*/_jsxs("table", {
165
245
  className: classNames('header', 'harvest-sheet', className),
@@ -171,6 +251,9 @@ export var DraggableShell = function DraggableShell(_ref) {
171
251
  children: [/*#__PURE__*/_jsx("colgroup", {
172
252
  children: colItems
173
253
  }), /*#__PURE__*/_jsx("thead", {
254
+ style: {
255
+ pointerEvents: 'all'
256
+ },
174
257
  children: /*#__PURE__*/_jsx("tr", {
175
258
  ref: headRef,
176
259
  children: thItems
@@ -1,5 +1,8 @@
1
+ /// <reference types="react" />
1
2
  import type { SheetType } from "../../type";
2
3
  import './draggableShell/index.less';
3
4
  export declare const TableShell: ({ columns, className, showGroup, showSelect, controlProps, controlWidth, }: SheetType.SheetShell) => import("react").FC<{
4
5
  children: React.ReactElement;
6
+ isScrolledOver: boolean;
7
+ isScrolledToEnd: boolean;
5
8
  }>;
@@ -1,4 +1,5 @@
1
1
  import { useMemo } from 'react';
2
+ import { useSheetEvent } from "../../hooks";
2
3
  import { classNames } from "../util";
3
4
  import { CheckViewer } from "../viewer/checkViewer";
4
5
  import { GroupViewer } from "../viewer/groupViewer";
@@ -15,10 +16,37 @@ export var TableShell = function TableShell(_ref) {
15
16
  _ref$controlWidth = _ref.controlWidth,
16
17
  controlWidth = _ref$controlWidth === void 0 ? 30 : _ref$controlWidth;
17
18
  var TableShell = function TableShell(_ref2) {
18
- var children = _ref2.children;
19
+ var children = _ref2.children,
20
+ isScrolledOver = _ref2.isScrolledOver,
21
+ isScrolledToEnd = _ref2.isScrolledToEnd;
22
+ var eventBus = useSheetEvent();
23
+ var colItems = useMemo(function () {
24
+ var cols = [];
25
+ if (showGroup || showSelect) {
26
+ cols.push( /*#__PURE__*/_jsx("col", {
27
+ className: classNames('sheet-control'),
28
+ style: {
29
+ width: controlWidth,
30
+ border: 'none'
31
+ }
32
+ }, "sheet-control"));
33
+ }
34
+ columns.forEach(function (item, index) {
35
+ cols.push( /*#__PURE__*/_jsx("col", {
36
+ className: classNames('cell'),
37
+ style: {
38
+ width: item.width || 'unset',
39
+ border: 'none'
40
+ }
41
+ }, item.dataIndex || index));
42
+ });
43
+ return cols;
44
+ }, [columns, showGroup || showSelect, controlWidth]);
19
45
  var thItems = useMemo(function () {
20
46
  var ths = [];
21
- if (showGroup || showSelect) {
47
+ var hasControl = showGroup || showSelect;
48
+ var positionArr = [];
49
+ if (hasControl) {
22
50
  var _controlProps$group, _controlProps$check, _controlProps$check2, _controlProps$check3;
23
51
  ths.push( /*#__PURE__*/_jsxs("th", {
24
52
  className: "cell cell-title read-only sheet-control",
@@ -27,59 +55,79 @@ export var TableShell = function TableShell(_ref) {
27
55
  col: -1,
28
56
  value: true,
29
57
  record: {
30
- open: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$group = controlProps.group) === null || _controlProps$group === void 0 ? void 0 : _controlProps$group.open,
58
+ open: controlProps === null || controlProps === void 0 || (_controlProps$group = controlProps.group) === null || _controlProps$group === void 0 ? void 0 : _controlProps$group.open,
31
59
  isHeader: true
32
60
  }
33
61
  }), showSelect && /*#__PURE__*/_jsx(CheckViewer, {
34
62
  row: -1,
35
63
  col: -1,
36
- value: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$check = controlProps.check) === null || _controlProps$check === void 0 ? void 0 : _controlProps$check.checked,
64
+ value: controlProps === null || controlProps === void 0 || (_controlProps$check = controlProps.check) === null || _controlProps$check === void 0 ? void 0 : _controlProps$check.checked,
37
65
  record: {
38
- open: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$check2 = controlProps.check) === null || _controlProps$check2 === void 0 ? void 0 : _controlProps$check2.checked,
66
+ open: controlProps === null || controlProps === void 0 || (_controlProps$check2 = controlProps.check) === null || _controlProps$check2 === void 0 ? void 0 : _controlProps$check2.checked,
39
67
  isHeader: true,
40
- indeterminate: controlProps === null || controlProps === void 0 ? void 0 : (_controlProps$check3 = controlProps.check) === null || _controlProps$check3 === void 0 ? void 0 : _controlProps$check3.indeterminate
68
+ indeterminate: controlProps === null || controlProps === void 0 || (_controlProps$check3 = controlProps.check) === null || _controlProps$check3 === void 0 ? void 0 : _controlProps$check3.indeterminate
41
69
  }
42
70
  })]
43
71
  }, "-1"));
72
+ positionArr.push({
73
+ isLastFixedLeft: false,
74
+ isFirstFixedRight: false,
75
+ fixPosition: 0
76
+ });
44
77
  }
78
+ var fixLeftPosition = 0;
79
+ var fixRightPosition = columns.reduce(function (pre, cur, index) {
80
+ if (cur.fixed === 'right') {
81
+ var positionIndex = hasControl ? index + 1 : index;
82
+ return pre + colItems[positionIndex].props.style.width;
83
+ }
84
+ return pre + 0;
85
+ }, 0);
45
86
  columns.forEach(function (item, index) {
46
87
  var _item$titleConfig, _item$titleConfig2, _ref3;
88
+ var positionIndex = hasControl ? index + 1 : index;
89
+ if (item.fixed === 'right') {
90
+ fixRightPosition -= colItems[positionIndex].props.style.width;
91
+ }
92
+ var isLastFixedLeft = item.fixed === 'left' && !columns.slice(index + 1).some(function (item) {
93
+ return item.fixed === 'left';
94
+ });
95
+ var isFirstFixedRight = item.fixed === 'right' && !columns.slice(0, index).some(function (item) {
96
+ return item.fixed === 'right';
97
+ });
98
+ positionArr.push({
99
+ isLastFixedLeft: isLastFixedLeft,
100
+ isFirstFixedRight: isFirstFixedRight,
101
+ fixPosition: item.fixed === 'right' ? fixRightPosition : fixLeftPosition
102
+ });
47
103
  ((_item$titleConfig = item.titleConfig) === null || _item$titleConfig === void 0 ? void 0 : _item$titleConfig.colSpan) !== 0 && ths.push( /*#__PURE__*/_jsx("th", {
48
- className: classNames('cell', 'cell-title', 'read-only', item.fixed && 'fixed', item.fixed && "fixed-".concat(item.fixed)),
104
+ className: classNames('cell', 'cell-title', 'read-only', item.fixed && 'fixed', item.fixed && "fixed-".concat(item.fixed), isLastFixedLeft && isScrolledOver ? "last-fixed-left" : '', isFirstFixedRight && !isScrolledToEnd ? "first-fixed-right" : ''),
49
105
  colSpan: (_item$titleConfig2 = item.titleConfig) === null || _item$titleConfig2 === void 0 ? void 0 : _item$titleConfig2.colSpan,
106
+ onClick: function onClick() {
107
+ eventBus.emit('col-select', {
108
+ col: index
109
+ });
110
+ },
50
111
  style: {
51
112
  textAlign: (_ref3 = item.align) !== null && _ref3 !== void 0 ? _ref3 : 'unset',
52
- left: item.fixed === 'left' ? 0 : 'unset',
53
- right: item.fixed === 'right' ? 0 : 'unset'
113
+ cursor: 'e-resizer',
114
+ left: item.fixed === 'left' ? fixLeftPosition : 'unset',
115
+ right: item.fixed === 'right' ? fixRightPosition : 'unset'
54
116
  },
55
117
  children: /*#__PURE__*/_jsx("span", {
56
118
  className: "value-viewer",
57
119
  children: item.title
58
120
  })
59
121
  }, item.dataIndex || index));
122
+ if (item.fixed === 'left') {
123
+ fixLeftPosition += colItems[positionIndex].props.style.width;
124
+ }
60
125
  });
126
+ setTimeout(function () {
127
+ eventBus.emit('change-fixed-position', positionArr);
128
+ }, 16);
61
129
  return ths;
62
- }, [columns, showGroup || showSelect, controlProps]);
63
- var colItems = useMemo(function () {
64
- var cols = [];
65
- if (showGroup || showSelect) {
66
- cols.push( /*#__PURE__*/_jsx("col", {
67
- className: classNames('sheet-control'),
68
- style: {
69
- width: controlWidth
70
- }
71
- }, "sheet-control"));
72
- }
73
- columns.forEach(function (item, index) {
74
- cols.push( /*#__PURE__*/_jsx("col", {
75
- className: classNames('cell'),
76
- style: {
77
- width: item.width || 'unset'
78
- }
79
- }, item.dataIndex || index));
80
- });
81
- return cols;
82
- }, [columns, showGroup || showSelect, controlWidth]);
130
+ }, [columns, showGroup || showSelect, controlProps, isScrolledOver, isScrolledToEnd]);
83
131
  return /*#__PURE__*/_jsxs(_Fragment, {
84
132
  children: [/*#__PURE__*/_jsxs("table", {
85
133
  className: classNames('header', 'harvest-sheet', className),
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import './index.less';
3
+ export declare const AddButton: React.FC<{
4
+ handleAdd?: () => void;
5
+ handleBatchAdd?: (count: number) => void;
6
+ }>;
@@ -0,0 +1,103 @@
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(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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { MoreOutlined } from "@ant-design/icons";
8
+ import { Form, InputNumber, Popover, Button } from "antd";
9
+ import React, { useEffect, useRef, useState } from "react";
10
+ import "./index.less";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ var RowPop = function RowPop(props) {
14
+ var handleBatchAdd = props.handleBatchAdd;
15
+ var inputRef = useRef(null);
16
+ useEffect(function () {
17
+ var interval = setInterval(function () {
18
+ var _inputRef$current;
19
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
20
+ }, 200);
21
+ return function () {
22
+ clearInterval(interval);
23
+ };
24
+ }, []);
25
+ if (!handleBatchAdd) {
26
+ return null;
27
+ }
28
+ return /*#__PURE__*/_jsx(Form, {
29
+ initialValues: {
30
+ count: 10
31
+ },
32
+ onFinish: function onFinish(values) {
33
+ handleBatchAdd && handleBatchAdd(values.count);
34
+ },
35
+ children: /*#__PURE__*/_jsx(Form.Item, {
36
+ style: {
37
+ marginBottom: 0
38
+ },
39
+ label: "\u884C\u6570",
40
+ name: "count",
41
+ children: /*#__PURE__*/_jsx(InputNumber, {
42
+ style: {
43
+ width: 100
44
+ },
45
+ ref: inputRef,
46
+ min: 1,
47
+ max: 100,
48
+ onClick: function onClick(e) {
49
+ e.stopPropagation();
50
+ }
51
+ })
52
+ })
53
+ });
54
+ };
55
+ export var AddButton = function AddButton(props) {
56
+ var handleAdd = props.handleAdd,
57
+ _handleBatchAdd = props.handleBatchAdd;
58
+ var _useState = useState(false),
59
+ _useState2 = _slicedToArray(_useState, 2),
60
+ open = _useState2[0],
61
+ setOpen = _useState2[1];
62
+ if (!handleAdd && !_handleBatchAdd) {
63
+ return null;
64
+ }
65
+ return /*#__PURE__*/_jsxs(Button, {
66
+ type: "dashed",
67
+ style: {
68
+ width: '100%',
69
+ height: 32,
70
+ backgroundColor: '#fff'
71
+ },
72
+ onClick: function onClick() {
73
+ handleAdd && handleAdd();
74
+ },
75
+ children: ["+ \u6DFB\u52A0", _handleBatchAdd && /*#__PURE__*/_jsx(Popover, {
76
+ open: open,
77
+ onOpenChange: setOpen,
78
+ trigger: ['click'],
79
+ destroyTooltipOnHide: true,
80
+ overlayClassName: "batch-add-pop",
81
+ content: /*#__PURE__*/_jsx("div", {
82
+ className: "batch-add-pop-content",
83
+ onClick: function onClick(e) {
84
+ return e.stopPropagation();
85
+ },
86
+ children: /*#__PURE__*/_jsx(RowPop, {
87
+ handleBatchAdd: function handleBatchAdd(value) {
88
+ _handleBatchAdd && _handleBatchAdd(value);
89
+ setOpen(false);
90
+ }
91
+ })
92
+ }),
93
+ children: /*#__PURE__*/_jsx(MoreOutlined, {
94
+ style: {
95
+ marginLeft: 0
96
+ },
97
+ onClick: function onClick(e) {
98
+ e.stopPropagation();
99
+ }
100
+ })
101
+ })]
102
+ });
103
+ };
@@ -7,9 +7,7 @@ export declare const SelectionEvent: FC<{
7
7
  }>;
8
8
  export declare const GroupEvent: FC<{
9
9
  hasChildren: boolean;
10
- rowGroupConfig: SheetType.RowGroupConfig;
11
10
  data: SheetType.Cell[][];
12
11
  sheetInstance: SheetType.SheetInstance | null;
13
- onGroupChange: (value: SheetType.RowGroupConfig) => void;
14
12
  onGridChange: (value: SheetType.Cell[][]) => void;
15
13
  }>;