@zhenliang/sheet 0.0.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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/core/config.js +13 -0
  4. package/dist/core/editor/cascaderEditor/index.js +63 -0
  5. package/dist/core/editor/cascaderEditor/index.less +24 -0
  6. package/dist/core/editor/dateEditor/index.js +42 -0
  7. package/dist/core/editor/dateEditor/index.less +7 -0
  8. package/dist/core/editor/numberEditor/index.js +25 -0
  9. package/dist/core/editor/numberEditor/index.less +17 -0
  10. package/dist/core/editor/selectEditor/index.js +44 -0
  11. package/dist/core/editor/selectEditor/index.less +41 -0
  12. package/dist/core/reducers/index.js +36 -0
  13. package/dist/core/reducers/keyboardReducer.js +91 -0
  14. package/dist/core/reducers/mouseReducer.js +151 -0
  15. package/dist/core/reducers/sideEffectReducer.js +324 -0
  16. package/dist/core/reducers/stateReducer.js +140 -0
  17. package/dist/core/sheet/Cell.js +160 -0
  18. package/dist/core/sheet/DataEditor.js +21 -0
  19. package/dist/core/sheet/DefaultCell.js +31 -0
  20. package/dist/core/sheet/DefaultRow.js +25 -0
  21. package/dist/core/sheet/DefaultRowMapper.js +15 -0
  22. package/dist/core/sheet/DefaultShell.js +12 -0
  23. package/dist/core/sheet/Event.js +17 -0
  24. package/dist/core/sheet/ValueViewer.js +9 -0
  25. package/dist/core/sheet/index.js +201 -0
  26. package/dist/core/sheet/index.less +261 -0
  27. package/dist/core/sheet/useCellEvent.js +22 -0
  28. package/dist/core/sheet/useContextMenu.js +86 -0
  29. package/dist/core/sheet/useKeyBoardEvent.js +44 -0
  30. package/dist/core/sheet/useMouseEvent.js +298 -0
  31. package/dist/core/sheet/useVirtualList.js +74 -0
  32. package/dist/core/sheet/var.less +41 -0
  33. package/dist/core/shell/draggableShell/index.js +182 -0
  34. package/dist/core/shell/draggableShell/index.less +16 -0
  35. package/dist/core/shell/resizeShell.js +57 -0
  36. package/dist/core/shell/tableShell.js +105 -0
  37. package/dist/core/table/index.js +311 -0
  38. package/dist/core/table/useGroupConfig.js +32 -0
  39. package/dist/core/table/useRowSelection.js +24 -0
  40. package/dist/core/table/util.js +29 -0
  41. package/dist/core/util.js +363 -0
  42. package/dist/core/viewer/checkViewer/index.js +23 -0
  43. package/dist/core/viewer/groupViewer/index.js +28 -0
  44. package/dist/example/basic.js +120 -0
  45. package/dist/example/draggable.js +0 -0
  46. package/dist/example/ellipsis.js +63 -0
  47. package/dist/example/fixed.js +88 -0
  48. package/dist/example/group.js +84 -0
  49. package/dist/example/index.less +5 -0
  50. package/dist/example/selection.js +85 -0
  51. package/dist/example/sheet.js +356 -0
  52. package/dist/hooks/index.js +6 -0
  53. package/dist/hooks/useEventBus.js +17 -0
  54. package/dist/hooks/useKeyboard.js +108 -0
  55. package/dist/hooks/useMiddlewareReducer.js +47 -0
  56. package/dist/hooks/useMouse.js +52 -0
  57. package/dist/hooks/useSetState.js +27 -0
  58. package/dist/hooks/useSheetEvent.js +5 -0
  59. package/dist/index.js +3 -0
  60. package/dist/standardUtils/index.js +32 -0
  61. package/dist/typings/index.d.ts +1 -0
  62. package/dist/typings/sheet.d.ts +209 -0
  63. package/dist/typings/table.js +0 -0
  64. package/package.json +84 -0
@@ -0,0 +1,86 @@
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
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
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."); }
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); }
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
+ 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
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { useSetState } from "../../hooks";
14
+ import { useEffect } from 'react';
15
+ import { calcMenuPosition, extractDataRowAndCol, findParentTd } from "../util";
16
+ export var useContextMenu = function useContextMenu(dispatch, elementRef) {
17
+ var enableContextMenu = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
18
+ var contextMenuRef = arguments.length > 3 ? arguments[3] : undefined;
19
+ var _useSetState = useSetState({
20
+ showMenu: false,
21
+ position: {
22
+ top: 0,
23
+ left: 0
24
+ },
25
+ cellPosition: {
26
+ row: 0,
27
+ col: 0
28
+ }
29
+ }),
30
+ _useSetState2 = _slicedToArray(_useSetState, 2),
31
+ menuEvent = _useSetState2[0],
32
+ setMenuEvent = _useSetState2[1];
33
+ var handleContextMenu = function handleContextMenu(e) {
34
+ var _contextMenuRef$curre;
35
+ e.preventDefault();
36
+ var currentCell = findParentTd(e.target);
37
+ if (!currentCell) return;
38
+ var currentPos = extractDataRowAndCol(currentCell);
39
+ dispatch({
40
+ type: 'mouseDown',
41
+ payload: {
42
+ pos: currentPos,
43
+ shiftKey: e.shiftKey
44
+ }
45
+ });
46
+ var _calcMenuPosition = calcMenuPosition({
47
+ tableElement: elementRef.current,
48
+ menuElement: (_contextMenuRef$curre = contextMenuRef.current) === null || _contextMenuRef$curre === void 0 ? void 0 : _contextMenuRef$curre.firstElementChild,
49
+ x: e.clientX,
50
+ y: e.clientY
51
+ }),
52
+ top = _calcMenuPosition.top,
53
+ left = _calcMenuPosition.left;
54
+ setMenuEvent({
55
+ showMenu: true,
56
+ position: {
57
+ top: top,
58
+ left: left
59
+ },
60
+ cellPosition: currentPos
61
+ });
62
+ };
63
+ useEffect(function () {
64
+ var _contextMenuRef$curre2, _contextMenuRef$curre3;
65
+ if (!elementRef.current || !enableContextMenu) return;
66
+ // 添加统一规范
67
+ (_contextMenuRef$curre2 = contextMenuRef.current) === null || _contextMenuRef$curre2 === void 0 ? void 0 : (_contextMenuRef$curre3 = _contextMenuRef$curre2.firstElementChild) === null || _contextMenuRef$curre3 === void 0 ? void 0 : _contextMenuRef$curre3.setAttribute('style', 'z-index: 5;word-break: keep-all;');
68
+ var handleClose = function handleClose() {
69
+ setMenuEvent({
70
+ showMenu: false
71
+ });
72
+ };
73
+ elementRef.current.addEventListener('contextmenu', handleContextMenu);
74
+ document.addEventListener('click', handleClose);
75
+ document.addEventListener('scroll', function () {
76
+ setMenuEvent({
77
+ showMenu: false
78
+ });
79
+ }, true);
80
+ return function () {
81
+ document.removeEventListener('contextmenu', handleContextMenu);
82
+ document.removeEventListener('click', handleClose);
83
+ };
84
+ }, [elementRef.current, enableContextMenu]);
85
+ return _objectSpread({}, menuEvent);
86
+ };
@@ -0,0 +1,44 @@
1
+ import { useKeyBoard } from "../../hooks";
2
+ import { sideEffectReducer } from "../reducers/sideEffectReducer";
3
+ export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
4
+ useKeyBoard({
5
+ move: function move(e, value) {
6
+ dispatch({
7
+ type: 'move',
8
+ payload: value
9
+ });
10
+ },
11
+ escape: function escape() {
12
+ dispatch({
13
+ type: 'escape'
14
+ });
15
+ },
16
+ reverse: function reverse() {
17
+ dispatch(sideEffectReducer.reverse);
18
+ },
19
+ delete: function _delete() {
20
+ dispatch(sideEffectReducer.delete);
21
+ },
22
+ enter: function enter() {
23
+ dispatch({
24
+ type: 'enter'
25
+ });
26
+ },
27
+ otherInput: function otherInput(e, value) {
28
+ dispatch({
29
+ type: 'otherInput',
30
+ payload: value
31
+ });
32
+ },
33
+ copy: function copy() {
34
+ dispatch(sideEffectReducer.copy);
35
+ },
36
+ paste: function paste() {
37
+ dispatch(sideEffectReducer.paste);
38
+ },
39
+ cut: function cut() {
40
+ dispatch(sideEffectReducer.copy);
41
+ dispatch(sideEffectReducer.delete);
42
+ }
43
+ }, elementRef.current);
44
+ };
@@ -0,0 +1,298 @@
1
+ import { useMouse } from "../../hooks";
2
+ import { useCallback, useRef } from 'react';
3
+ import { extractDataRowAndCol, findParentTd } from "../util";
4
+ var rowCount = 10; //每秒10行
5
+ var colCount = 5; //每秒3列
6
+
7
+ export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
8
+ var animateRef = useRef(false);
9
+ // const animateScrollCalled = useRef<number>(0);
10
+ var rowHeightRef = useRef(40);
11
+ var colWidthRef = useRef(100);
12
+ var resetInterval = useCallback(function () {
13
+ if (animateRef.current) {
14
+ animateRef.current = false;
15
+ // animateScrollCalled.current -= 1;
16
+ }
17
+ }, []);
18
+ var scrollTo = useCallback(function (type) {
19
+ if (!elementRef.current) return;
20
+ // 当前滚动高度
21
+ var _ref = elementRef.current || {},
22
+ scrollTop = _ref.scrollTop,
23
+ scrollLeft = _ref.scrollLeft,
24
+ scrollHeight = _ref.scrollHeight,
25
+ scrollWidth = _ref.scrollWidth;
26
+ var destination = {
27
+ y: scrollTop,
28
+ x: scrollLeft
29
+ };
30
+ var called = 0;
31
+ var rowCalled = 0;
32
+ var colCalled = 0;
33
+ var step = function step() {
34
+ var _elementRef$current;
35
+ (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.style.setProperty('scroll-behavior', 'auto');
36
+ var position = {
37
+ x: destination.x,
38
+ y: destination.y
39
+ };
40
+ if (type === 'bottom') {
41
+ position.y = scrollHeight;
42
+ if (Math.round(called / 60 * rowCount) - rowCalled > 1) {
43
+ rowCalled++;
44
+ dispatch({
45
+ type: 'rowMove',
46
+ payload: 1
47
+ });
48
+ }
49
+ }
50
+ if (type === 'right') {
51
+ position.x = scrollWidth;
52
+ if (Math.round(called / 60 * colCount) - colCalled > 1) {
53
+ colCalled++;
54
+ dispatch({
55
+ type: 'colMove',
56
+ payload: 1
57
+ });
58
+ }
59
+ }
60
+ if (type === 'left') {
61
+ position.x = 0;
62
+ if (Math.round(called / 60 * colCount) - colCalled > 1) {
63
+ colCalled++;
64
+ dispatch({
65
+ type: 'colMove',
66
+ payload: -1
67
+ });
68
+ }
69
+ }
70
+ if (type === 'top') {
71
+ position.y = 0;
72
+ if (Math.round(called / 60 * rowCount) - rowCalled > 1) {
73
+ rowCalled++;
74
+ dispatch({
75
+ type: 'rowMove',
76
+ payload: -1
77
+ });
78
+ }
79
+ }
80
+
81
+ // 距离目标滚动距离
82
+ var distance = {
83
+ x: position.x - destination.x,
84
+ // x: 0,
85
+ y: position.y - destination.y
86
+ };
87
+ // 目标滚动位置
88
+ destination = {
89
+ x: destination.x + (distance.x !== 0 ? distance.x * colWidthRef.current * colCount / 60 / Math.abs(distance.x) : 0),
90
+ // x: 0,
91
+ y: destination.y + (distance.y !== 0 ? distance.y * rowHeightRef.current * rowCount / 60 / Math.abs(distance.y) : 0)
92
+ };
93
+ if (!animateRef.current) return;
94
+ if (Math.abs(distance.x) + Math.abs(distance.y) < 2) {
95
+ var _elementRef$current2;
96
+ (_elementRef$current2 = elementRef.current) === null || _elementRef$current2 === void 0 ? void 0 : _elementRef$current2.scrollTo(destination.x, destination.y);
97
+ resetInterval();
98
+ } else {
99
+ var _elementRef$current3;
100
+ (_elementRef$current3 = elementRef.current) === null || _elementRef$current3 === void 0 ? void 0 : _elementRef$current3.scrollTo(destination.x, destination.y);
101
+ requestAnimationFrame(step);
102
+ called++;
103
+ }
104
+ };
105
+ step();
106
+ }, []);
107
+ var mouseDown = useCallback(function (e) {
108
+ var _elementRef$current4;
109
+ if (e.button !== 0) return;
110
+ e.preventDefault();
111
+ if (!((_elementRef$current4 = elementRef.current) !== null && _elementRef$current4 !== void 0 && _elementRef$current4.contains(e.target))) {
112
+ dispatch({
113
+ type: 'loseFocus'
114
+ });
115
+ }
116
+ var currentCell = findParentTd(e.target);
117
+ if (!currentCell) {
118
+ return;
119
+ }
120
+ var currentPos = extractDataRowAndCol(currentCell);
121
+ dispatch({
122
+ type: 'mouseDown',
123
+ payload: {
124
+ pos: currentPos,
125
+ shiftKey: e.shiftKey
126
+ }
127
+ });
128
+ }, []);
129
+ var mouseOver = useCallback(function (e) {
130
+ var _elementRef$current5, _elementRef$current6;
131
+ e.preventDefault();
132
+ if (!((_elementRef$current5 = elementRef.current) !== null && _elementRef$current5 !== void 0 && _elementRef$current5.contains(e.target))) return;
133
+ var currentCell = findParentTd(e.target);
134
+ if (!currentCell || currentCell.classList.contains('fixed')) return;
135
+ (_elementRef$current6 = elementRef.current) === null || _elementRef$current6 === void 0 ? void 0 : _elementRef$current6.style.setProperty('scroll-behavior', 'smooth');
136
+ var currentPos = extractDataRowAndCol(currentCell);
137
+ dispatch({
138
+ type: 'mouseOver',
139
+ payload: currentPos
140
+ });
141
+ dispatch(function (d, getState) {
142
+ var _elementRef$current7;
143
+ var _getState = getState(),
144
+ mouseDown = _getState.mouseDown;
145
+ if (!mouseDown || !elementRef.current) return;
146
+ var cellBounding = currentCell.getBoundingClientRect();
147
+ var parentBounding = (_elementRef$current7 = elementRef.current) === null || _elementRef$current7 === void 0 ? void 0 : _elementRef$current7.getBoundingClientRect();
148
+ var left = cellBounding.left,
149
+ top = cellBounding.top,
150
+ bottom = cellBounding.bottom,
151
+ right = cellBounding.right;
152
+ var parentLeft = parentBounding.left,
153
+ parentTop = parentBounding.top,
154
+ parentBottom = parentBounding.bottom,
155
+ parentRight = parentBounding.right;
156
+ var dBottom = bottom - parentBottom;
157
+ var dTop = top - parentTop;
158
+ var dLeft = left - parentLeft;
159
+ var dRight = right - parentRight;
160
+ var cellHeight = currentCell.clientHeight;
161
+ var cellWidth = currentCell.clientWidth;
162
+ rowHeightRef.current = cellHeight;
163
+ colWidthRef.current = cellWidth;
164
+ var isElementEdge = dBottom > -40 || dTop < 40 || dLeft < 40 || dRight > -40;
165
+ if (isElementEdge) {
166
+ if (animateRef.current === true) return;
167
+ animateRef.current = true;
168
+ // animateScrollCalled.current += 1;
169
+ } else {
170
+ resetInterval();
171
+ }
172
+ if (dBottom > -40) {
173
+ scrollTo('bottom');
174
+ // elementRef.current.scrollTop += cellHeight;
175
+ }
176
+
177
+ if (dTop < 40) {
178
+ scrollTo('top');
179
+ // elementRef.current.scrollTop -= cellHeight;
180
+ }
181
+
182
+ if (dLeft < 40) {
183
+ scrollTo('left');
184
+ // elementRef.current.scrollLeft -= cellWidth;
185
+ }
186
+
187
+ if (dRight > -40) {
188
+ scrollTo('right');
189
+ // elementRef.current.scrollLeft += cellWidth;
190
+ }
191
+ });
192
+ }, []);
193
+ var mouseUp = useCallback(function (e) {
194
+ e.preventDefault();
195
+ resetInterval();
196
+ var currentCell = findParentTd(e.target);
197
+ if (!currentCell || currentCell.classList.contains('fixed')) {
198
+ dispatch({
199
+ type: 'changes',
200
+ payload: {
201
+ mouseDown: false
202
+ }
203
+ });
204
+ return;
205
+ }
206
+ var currentPos = extractDataRowAndCol(currentCell);
207
+ dispatch({
208
+ type: 'mouseUp',
209
+ payload: currentPos
210
+ });
211
+ }, []);
212
+ var mouseLeave = useCallback(function (e) {
213
+ dispatch(function (d, getState) {
214
+ var _getState2 = getState(),
215
+ mouseDown = _getState2.mouseDown;
216
+ if (mouseDown && elementRef.current) {
217
+ var _elementRef$current8;
218
+ var parentBounding = (_elementRef$current8 = elementRef.current) === null || _elementRef$current8 === void 0 ? void 0 : _elementRef$current8.getBoundingClientRect();
219
+ var left = parentBounding.left,
220
+ top = parentBounding.top,
221
+ right = parentBounding.right,
222
+ bottom = parentBounding.bottom;
223
+ var x = e.x,
224
+ y = e.y;
225
+ resetInterval();
226
+ if (animateRef.current === true) return;
227
+ animateRef.current = true;
228
+
229
+ // animateScrollCalled.current += 1;
230
+ if (y > bottom) {
231
+ scrollTo('bottom');
232
+ }
233
+ if (y < top) {
234
+ scrollTo('top');
235
+ }
236
+ if (x < left) {
237
+ scrollTo('left');
238
+ }
239
+ if (x > right) {
240
+ scrollTo('right');
241
+ }
242
+ } else {
243
+ mouseDown && dispatch({
244
+ type: 'changes',
245
+ payload: {
246
+ mouseDown: false
247
+ }
248
+ });
249
+ }
250
+ });
251
+ }, []);
252
+ var doubleClick = useCallback(function (e) {
253
+ var _elementRef$current9;
254
+ if (!((_elementRef$current9 = elementRef.current) !== null && _elementRef$current9 !== void 0 && _elementRef$current9.contains(e.target))) {
255
+ return;
256
+ }
257
+ e.preventDefault();
258
+ var currentCell = findParentTd(e.target);
259
+ if (!(currentCell !== null && currentCell !== void 0 && currentCell.classList) || currentCell.classList.contains('read-only')) {
260
+ // 只读
261
+ return;
262
+ }
263
+ var currentPos = extractDataRowAndCol(currentCell);
264
+ dispatch({
265
+ type: 'doubleClick',
266
+ payload: currentPos
267
+ });
268
+ }, []);
269
+ var loseFocus = useCallback(function (e) {
270
+ var _elementRef$current10;
271
+ if (!((_elementRef$current10 = elementRef.current) !== null && _elementRef$current10 !== void 0 && _elementRef$current10.contains(e.target))) {
272
+ dispatch({
273
+ type: 'loseFocus'
274
+ });
275
+ return;
276
+ }
277
+ e.preventDefault();
278
+ var currentCell = findParentTd(e.target);
279
+ if (currentCell.classList.contains('read-only')) {
280
+ // 只读
281
+ return;
282
+ }
283
+ var currentPos = extractDataRowAndCol(currentCell);
284
+ dispatch({
285
+ type: 'doubleClick',
286
+ payload: currentPos
287
+ });
288
+ }, []);
289
+ useMouse({
290
+ mouseDown: mouseDown,
291
+ mouseOver: mouseOver,
292
+ mouseUp: mouseUp,
293
+ mouseLeave: mouseLeave,
294
+ mouseEnter: resetInterval,
295
+ doubleClick: doubleClick,
296
+ loseFocus: loseFocus
297
+ }, elementRef.current);
298
+ };
@@ -0,0 +1,74 @@
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 { isEqual, throttle } from 'lodash';
8
+ import { useEffect, useRef, useState } from 'react';
9
+ import { getRowHeight } from "../util";
10
+ var extra = 20;
11
+ // 虚拟列表
12
+ export var useVirtualList = function useVirtualList(elementRef) {
13
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
14
+ var virtualized = arguments.length > 2 ? arguments[2] : undefined;
15
+ var _useState = useState({
16
+ virtualStart: 0,
17
+ virtualEnd: data.length - 1,
18
+ paddingTop: 0,
19
+ paddingBottom: 0
20
+ }),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ state = _useState2[0],
23
+ setState = _useState2[1];
24
+ var virtualStart = state.virtualStart,
25
+ virtualEnd = state.virtualEnd,
26
+ paddingTop = state.paddingTop,
27
+ paddingBottom = state.paddingBottom;
28
+ var virtualRef = useRef();
29
+ useEffect(function () {
30
+ if (!elementRef.current) return;
31
+
32
+ // 当前位定高的表格,所以可以直接获取第一行的高度
33
+
34
+ var rowHeight = getRowHeight(elementRef.current);
35
+ var handleScroll = throttle(function () {
36
+ var _ref = elementRef.current,
37
+ scrollTop = _ref.scrollTop,
38
+ clientHeight = _ref.clientHeight;
39
+ var itemHeight = rowHeight || 30;
40
+ var start = Math.floor(scrollTop / itemHeight) - extra;
41
+ var end = Math.ceil((scrollTop + clientHeight) / itemHeight) + extra;
42
+ var updateVirtualConfig = {
43
+ virtualStart: start,
44
+ virtualEnd: end,
45
+ paddingTop: start * itemHeight,
46
+ paddingBottom: (data.length - end) * itemHeight
47
+ };
48
+ if (isEqual(updateVirtualConfig, virtualRef.current)) {
49
+ return;
50
+ }
51
+ setState(updateVirtualConfig);
52
+ virtualRef.current = updateVirtualConfig;
53
+ }, 50);
54
+ elementRef.current.addEventListener('scroll', handleScroll);
55
+ return function () {
56
+ var _elementRef$current;
57
+ (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.removeEventListener('scroll', handleScroll);
58
+ };
59
+ }, [elementRef.current]);
60
+ if (!virtualized) {
61
+ return {
62
+ virtualStart: 0,
63
+ virtualEnd: data.length,
64
+ paddingTop: 0,
65
+ paddingBottom: 0
66
+ };
67
+ }
68
+ return {
69
+ virtualStart: Math.max(0, virtualStart),
70
+ virtualEnd: Math.min(data.length, virtualEnd),
71
+ paddingTop: Math.max(0, paddingTop),
72
+ paddingBottom: data.length - 1 <= virtualEnd ? 0 : paddingBottom
73
+ };
74
+ };
@@ -0,0 +1,41 @@
1
+ .harvest{
2
+ --row-height:40px;
3
+ --cell-font-size:12px;
4
+ --cell-title-font-size:12px;
5
+ --cell-line-height:40px;
6
+ --cell-inner-height:39px;
7
+ --cell-padding-vertical:0;
8
+ --cell-padding-horizontal:5px;
9
+ --cell-border-color: #DDD;
10
+ --cell-background-color:white;
11
+ --cell-title-background-color:#f7f9fc;
12
+ --cell-read-only-background-color:#f7f9fc;
13
+ --cell-hover:white;
14
+ --cell-box-shadow:inset 0 -100px 0 rgba(33, 133, 208, 15%);;
15
+ --cell-fixed-box-shadow-left:inset 10px 0 8px -8px rgba(5, 5, 5,6%);
16
+ --cell-fixed-box-shadow-right:inset -10px 0 8px -8px rgba(5, 5, 5,6%);
17
+ --resizer: #2185d0;
18
+ --color:black;
19
+ --title-color:#999;
20
+ --read-color:#999;
21
+ }
22
+
23
+ .ali-devops{
24
+ --row-height:40px;
25
+ --cell-font-size:14px;
26
+ --cell-line-height:20px;
27
+ --cell-padding-vertical:12px;
28
+ --cell-padding-horizontal:12px;
29
+ --cell-border-color: #e5e5e5;
30
+ --cell-background-color:white;
31
+ --cell-title-background-color:white;
32
+ --cell-read-only-background-color:white;
33
+ --cell-fixed-box-shadow:inset -10px 0 8px -8px rgba(5, 5, 5,6%);
34
+ --cell-hover:#f7f7f7;
35
+ --cell-fixed-box-shadow-left:inset 10px 0 8px -8px rgba(5, 5, 5,6%);
36
+ --cell-fixed-box-shadow-right:inset -10px 0 8px -8px rgba(5, 5, 5,6%);
37
+ --resizer: #1b9aee;
38
+ --color:#262626;
39
+ --title-color:#8c8c8c;
40
+ --read-color:#8c8c8c;
41
+ }