@sheinx/hooks 3.3.6-beta.4 → 3.3.6-beta.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
1
|
+
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM;CAwFlD,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -16,6 +16,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
16
16
|
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; }
|
17
17
|
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; } }
|
18
18
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
19
|
+
var MAX_ROW_SPAN = 200;
|
19
20
|
var useTableVirtual = function useTableVirtual(props) {
|
20
21
|
var _useState = (0, _react.useState)(0),
|
21
22
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -98,7 +99,9 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
98
99
|
topTimer: null,
|
99
100
|
controlScrollRate: null,
|
100
101
|
heightCallback: null,
|
101
|
-
preIndex: null
|
102
|
+
preIndex: null,
|
103
|
+
rowSpanRows: 0,
|
104
|
+
autoAddRows: 0
|
102
105
|
}),
|
103
106
|
context = _useRef.current;
|
104
107
|
var getTranslate = (0, _usePersistFn.usePersistFn)(function (left, top) {
|
@@ -149,17 +152,20 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
149
152
|
var top = 0;
|
150
153
|
var maxIndex = Math.max(props.data.length - rowsInView, 0);
|
151
154
|
for (var i = 0; i <= maxIndex; i++) {
|
155
|
+
context.rowSpanRows = 0;
|
152
156
|
sum += context.cachedHeight[i] || props.rowHeight;
|
153
157
|
var rowSpanHeight = 0;
|
154
158
|
if (rowSpanInfos) {
|
159
|
+
var maxRowSpanLenth = Math.min(rowSpanInfos.length, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN);
|
155
160
|
var siblingsIndexs = [];
|
156
|
-
for (var k = 0; k <
|
161
|
+
for (var k = 0; k < maxRowSpanLenth; k++) {
|
157
162
|
if (rowSpanInfos[k] <= i && k > i) {
|
158
163
|
siblingsIndexs.push(k);
|
159
164
|
}
|
160
165
|
}
|
161
166
|
for (var j = 0; j < siblingsIndexs.length; j++) {
|
162
167
|
var index = siblingsIndexs[j];
|
168
|
+
context.rowSpanRows += 1;
|
163
169
|
rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
|
164
170
|
}
|
165
171
|
}
|
@@ -250,6 +256,24 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
250
256
|
props.scrollRef.current.scrollTop = beforeHeight;
|
251
257
|
}
|
252
258
|
});
|
259
|
+
(0, _react.useEffect)(function () {
|
260
|
+
var scrollRefHeight = props.scrollRef.current ? props.scrollRef.current.clientHeight : 0;
|
261
|
+
var tableRefHeight = props.innerRef.current ? props.innerRef.current.clientHeight : 0;
|
262
|
+
var remainHeight = scrollRefHeight - tableRefHeight;
|
263
|
+
if (remainHeight > 0) {
|
264
|
+
var addonHeight = 0;
|
265
|
+
var addonCount = 0;
|
266
|
+
for (var i = startIndex + rowsInView; i < props.data.length; i++) {
|
267
|
+
var height = context.cachedHeight[i] || props.rowHeight;
|
268
|
+
addonHeight += height;
|
269
|
+
addonCount += 1;
|
270
|
+
if (addonHeight >= remainHeight + context.cachedHeight[0]) break;
|
271
|
+
}
|
272
|
+
if (addonCount > 0) {
|
273
|
+
context.autoAddRows = addonCount;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}, []);
|
253
277
|
(0, _react.useEffect)(function () {
|
254
278
|
// 记录preIndex
|
255
279
|
context.preIndex = startIndex;
|
@@ -284,7 +308,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
284
308
|
cb();
|
285
309
|
}
|
286
310
|
}, [scrollHeight]);
|
287
|
-
var
|
311
|
+
var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
|
312
|
+
var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
|
288
313
|
return {
|
289
314
|
scrollHeight: scrollHeight,
|
290
315
|
startIndex: startIndex,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
1
|
+
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM;CAwFlD,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -10,6 +10,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
11
|
import { usePersistFn } from "../../common/use-persist-fn";
|
12
12
|
import { useState, useRef, useEffect, useMemo } from 'react';
|
13
|
+
var MAX_ROW_SPAN = 200;
|
13
14
|
var useTableVirtual = function useTableVirtual(props) {
|
14
15
|
var _useState = useState(0),
|
15
16
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -92,7 +93,9 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
92
93
|
topTimer: null,
|
93
94
|
controlScrollRate: null,
|
94
95
|
heightCallback: null,
|
95
|
-
preIndex: null
|
96
|
+
preIndex: null,
|
97
|
+
rowSpanRows: 0,
|
98
|
+
autoAddRows: 0
|
96
99
|
}),
|
97
100
|
context = _useRef.current;
|
98
101
|
var getTranslate = usePersistFn(function (left, top) {
|
@@ -143,17 +146,20 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
143
146
|
var top = 0;
|
144
147
|
var maxIndex = Math.max(props.data.length - rowsInView, 0);
|
145
148
|
for (var i = 0; i <= maxIndex; i++) {
|
149
|
+
context.rowSpanRows = 0;
|
146
150
|
sum += context.cachedHeight[i] || props.rowHeight;
|
147
151
|
var rowSpanHeight = 0;
|
148
152
|
if (rowSpanInfos) {
|
153
|
+
var maxRowSpanLenth = Math.min(rowSpanInfos.length, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN);
|
149
154
|
var siblingsIndexs = [];
|
150
|
-
for (var k = 0; k <
|
155
|
+
for (var k = 0; k < maxRowSpanLenth; k++) {
|
151
156
|
if (rowSpanInfos[k] <= i && k > i) {
|
152
157
|
siblingsIndexs.push(k);
|
153
158
|
}
|
154
159
|
}
|
155
160
|
for (var j = 0; j < siblingsIndexs.length; j++) {
|
156
161
|
var index = siblingsIndexs[j];
|
162
|
+
context.rowSpanRows += 1;
|
157
163
|
rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
|
158
164
|
}
|
159
165
|
}
|
@@ -244,6 +250,24 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
244
250
|
props.scrollRef.current.scrollTop = beforeHeight;
|
245
251
|
}
|
246
252
|
});
|
253
|
+
useEffect(function () {
|
254
|
+
var scrollRefHeight = props.scrollRef.current ? props.scrollRef.current.clientHeight : 0;
|
255
|
+
var tableRefHeight = props.innerRef.current ? props.innerRef.current.clientHeight : 0;
|
256
|
+
var remainHeight = scrollRefHeight - tableRefHeight;
|
257
|
+
if (remainHeight > 0) {
|
258
|
+
var addonHeight = 0;
|
259
|
+
var addonCount = 0;
|
260
|
+
for (var i = startIndex + rowsInView; i < props.data.length; i++) {
|
261
|
+
var height = context.cachedHeight[i] || props.rowHeight;
|
262
|
+
addonHeight += height;
|
263
|
+
addonCount += 1;
|
264
|
+
if (addonHeight >= remainHeight + context.cachedHeight[0]) break;
|
265
|
+
}
|
266
|
+
if (addonCount > 0) {
|
267
|
+
context.autoAddRows = addonCount;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}, []);
|
247
271
|
useEffect(function () {
|
248
272
|
// 记录preIndex
|
249
273
|
context.preIndex = startIndex;
|
@@ -278,7 +302,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
278
302
|
cb();
|
279
303
|
}
|
280
304
|
}, [scrollHeight]);
|
281
|
-
var
|
305
|
+
var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
|
306
|
+
var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
|
282
307
|
return {
|
283
308
|
scrollHeight: scrollHeight,
|
284
309
|
startIndex: startIndex,
|