index.js
36.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
/* eslint-disable */
// var React = require('react');
import React from 'react';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
var freeGlobal$1 = freeGlobal;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = freeGlobal$1 || freeSelf || Function('return this')();
var root$1 = root;
/** Built-in value references. */
var Symbol = root$1.Symbol;
var Symbol$1 = Symbol;
/** Used for built-in method references. */
var objectProto$1 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto$1.hasOwnProperty;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString$1 = objectProto$1.toString;
/** Built-in value references. */
var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag$1),
tag = value[symToStringTag$1];
try {
value[symToStringTag$1] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString$1.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag$1] = tag;
} else {
delete value[symToStringTag$1];
}
}
return result;
}
/** Used for built-in method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString.call(value);
}
/** `Object#toString` result references. */
var nullTag = '[object Null]',
undefinedTag = '[object Undefined]';
/** Built-in value references. */
var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag && symToStringTag in Object(value))
? getRawTag(value)
: objectToString(value);
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
/** `Object#toString` result references. */
var symbolTag = '[object Symbol]';
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(isObjectLike(value) && baseGetTag(value) == symbolTag);
}
/** Used to match a single whitespace character. */
var reWhitespace = /\s/;
/**
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
* character of `string`.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the index of the last non-whitespace character.
*/
function trimmedEndIndex(string) {
var index = string.length;
while (index-- && reWhitespace.test(string.charAt(index))) {}
return index;
}
/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;
/**
* The base implementation of `_.trim`.
*
* @private
* @param {string} string The string to trim.
* @returns {string} Returns the trimmed string.
*/
function baseTrim(string) {
return string
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
: string;
}
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3.2);
* // => 3.2
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3.2');
* // => 3.2
*/
function toNumber(value) {
if (typeof value == 'number') {
return value;
}
if (isSymbol(value)) {
return NAN;
}
if (isObject(value)) {
var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
value = isObject(other) ? (other + '') : other;
}
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = baseTrim(value);
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: (reIsBadHex.test(value) ? NAN : +value);
}
/**
* Gets the timestamp of the number of milliseconds that have elapsed since
* the Unix epoch (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @since 2.4.0
* @category Date
* @returns {number} Returns the timestamp.
* @example
*
* _.defer(function(stamp) {
* console.log(_.now() - stamp);
* }, _.now());
* // => Logs the number of milliseconds it took for the deferred invocation.
*/
var now = function() {
return root$1.Date.now();
};
var now$1 = now;
/** Error message constants. */
var FUNC_ERROR_TEXT$1 = 'Expected a function';
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
nativeMin = Math.min;
/**
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed `func` invocations and a `flush` method to immediately invoke them.
* Provide `options` to indicate whether `func` should be invoked on the
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked
* with the last arguments provided to the debounced function. Subsequent
* calls to the debounced function return the result of the last `func`
* invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is
* invoked on the trailing edge of the timeout only if the debounced function
* is invoked more than once during the `wait` timeout.
*
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
*
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
* for details over the differences between `_.debounce` and `_.throttle`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to debounce.
* @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=false]
* Specify invoking on the leading edge of the timeout.
* @param {number} [options.maxWait]
* The maximum time `func` is allowed to be delayed before it's invoked.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
* @example
*
* // Avoid costly calculations while the window size is in flux.
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
*
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
* jQuery(element).on('click', _.debounce(sendMail, 300, {
* 'leading': true,
* 'trailing': false
* }));
*
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
* var source = new EventSource('/stream');
* jQuery(source).on('message', debounced);
*
* // Cancel the trailing debounced invocation.
* jQuery(window).on('popstate', debounced.cancel);
*/
function debounce(func, wait, options) {
var lastArgs,
lastThis,
maxWait,
result,
timerId,
lastCallTime,
lastInvokeTime = 0,
leading = false,
maxing = false,
trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT$1);
}
wait = toNumber(wait) || 0;
if (isObject(options)) {
leading = !!options.leading;
maxing = 'maxWait' in options;
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs,
thisArg = lastThis;
lastArgs = lastThis = undefined;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function leadingEdge(time) {
// Reset any `maxWait` timer.
lastInvokeTime = time;
// Start the timer for the trailing edge.
timerId = setTimeout(timerExpired, wait);
// Invoke the leading edge.
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime,
timeWaiting = wait - timeSinceLastCall;
return maxing
? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
: timeWaiting;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime;
// Either this is the first call, activity has stopped and we're at the
// trailing edge, the system time has gone backwards and we're treating
// it as the trailing edge, or we've hit the `maxWait` limit.
return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
}
function timerExpired() {
var time = now$1();
if (shouldInvoke(time)) {
return trailingEdge(time);
}
// Restart the timer.
timerId = setTimeout(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = undefined;
// Only invoke if we have `lastArgs` which means `func` has been
// debounced at least once.
if (trailing && lastArgs) {
return invokeFunc(time);
}
lastArgs = lastThis = undefined;
return result;
}
function cancel() {
if (timerId !== undefined) {
clearTimeout(timerId);
}
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = undefined;
}
function flush() {
return timerId === undefined ? result : trailingEdge(now$1());
}
function debounced() {
var time = now$1(),
isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === undefined) {
return leadingEdge(lastCallTime);
}
if (maxing) {
// Handle invocations in a tight loop.
clearTimeout(timerId);
timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === undefined) {
timerId = setTimeout(timerExpired, wait);
}
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
return debounced;
}
/** `Object#toString` result references. */
var numberTag = '[object Number]';
/**
* Checks if `value` is classified as a `Number` primitive or object.
*
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
* classified as numbers, use the `_.isFinite` method.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a number, else `false`.
* @example
*
* _.isNumber(3);
* // => true
*
* _.isNumber(Number.MIN_VALUE);
* // => true
*
* _.isNumber(Infinity);
* // => true
*
* _.isNumber('3');
* // => false
*/
function isNumber(value) {
return typeof value == 'number' ||
(isObjectLike(value) && baseGetTag(value) == numberTag);
}
/** Error message constants. */
var FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a throttled function that only invokes `func` at most once per
* every `wait` milliseconds. The throttled function comes with a `cancel`
* method to cancel delayed `func` invocations and a `flush` method to
* immediately invoke them. Provide `options` to indicate whether `func`
* should be invoked on the leading and/or trailing edge of the `wait`
* timeout. The `func` is invoked with the last arguments provided to the
* throttled function. Subsequent calls to the throttled function return the
* result of the last `func` invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is
* invoked on the trailing edge of the timeout only if the throttled function
* is invoked more than once during the `wait` timeout.
*
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
*
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
* for details over the differences between `_.throttle` and `_.debounce`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to throttle.
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=true]
* Specify invoking on the leading edge of the timeout.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new throttled function.
* @example
*
* // Avoid excessively updating the position while scrolling.
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
*
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
* jQuery(element).on('click', throttled);
*
* // Cancel the trailing throttled invocation.
* jQuery(window).on('popstate', throttled.cancel);
*/
function throttle(func, wait, options) {
var leading = true,
trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
if (isObject(options)) {
leading = 'leading' in options ? !!options.leading : leading;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
return debounce(func, wait, {
'leading': leading,
'maxWait': wait,
'trailing': trailing
});
}
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (!css || typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css_248z = ".virtuallist .ant-table-tbody>tr>td>div{-webkit-box-sizing:border-box;box-sizing:border-box;white-space:nowrap;vertical-align:middle;overflow:hidden;text-overflow:ellipsis;width:100%}.virtuallist .ant-table-tbody>tr>td.ant-table-row-expand-icon-cell>div{overflow:inherit}.ant-table-bordered .virtuallist>table>.ant-table-tbody>tr>td{border-right:1px solid #f0f0f0}";
styleInject(css_248z);
// ===============reducer ============== //
var initialState = {
// 行高度
rowHeight: 0,
// 当前的scrollTop
curScrollTop: 0,
// 总行数
totalLen: 0,
// 每行的高度list
trHeightList: [],
};
function reducer(state, action) {
var _a;
var curScrollTop = action.curScrollTop, rowHeight = action.rowHeight, totalLen = action.totalLen, ifScrollTopClear = action.ifScrollTopClear, trHeight = action.trHeight, trIndex = action.trIndex;
var stateScrollTop = state.curScrollTop;
var trHeightList = state.trHeightList;
switch (action.type) {
// 改变trs 即 改变渲染的列表trs
case 'changeTrs':
return __assign(__assign({}, state), { curScrollTop: curScrollTop });
// 初始化每行的高度, 表格总高度, 渲染的条数
case 'initHeight':
return __assign(__assign({}, state), { rowHeight: rowHeight });
// 更改totalLen
case 'changeTotalLen':
if (totalLen === 0) {
stateScrollTop = 0;
}
else if (totalLen) {
for (var i = 0; i < totalLen; i++) {
trHeightList[i] = (_a = trHeightList[i]) !== null && _a !== void 0 ? _a : 29;
}
}
return __assign(__assign({}, state), { totalLen: totalLen, curScrollTop: stateScrollTop, trHeightList: trHeightList });
case 'reset':
return __assign(__assign({}, state), { curScrollTop: ifScrollTopClear ? 0 : state.curScrollTop });
case 'setTrList':
trHeightList[trIndex] = trHeight;
if (trHeightList.length > state.totalLen) {
trHeightList = trHeightList.slice(0, state.totalLen);
}
return __assign(__assign({}, state), { trHeightList: trHeightList });
default:
throw new Error();
}
}
// ==============全局常量 ================== //
var DEFAULT_VID = 'vtable';
var vidMap = new Map();
var debounceListRender;
// ===============context ============== //
var ScrollContext = React.createContext({
dispatch: undefined,
renderLen: 1,
start: 0,
offsetStart: 0,
// =============
rowHeight: initialState.rowHeight,
totalLen: 0,
vid: DEFAULT_VID,
});
// =============组件 =================== //
function VCell(props) {
var children = props.children, restProps = __rest(props, ["children"]);
return (React.createElement("td", __assign({}, restProps),
React.createElement("div", null, children)));
}
function VRow(props, ref) {
var _a = React.useContext(ScrollContext), dispatch = _a.dispatch, rowHeight = _a.rowHeight, totalLen = _a.totalLen, vid = _a.vid;
var children = props.children, style = props.style, restProps = __rest(props, ["children", "style"]);
var trRef = React.useRef(null);
React.useEffect(function () {
var initHeight = function (tempRef) {
var _a, _b, _c;
if (((_a = tempRef === null || tempRef === void 0 ? void 0 : tempRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) && !rowHeight && totalLen) {
var tempRowHeight = (_c = (_b = tempRef === null || tempRef === void 0 ? void 0 : tempRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) !== null && _c !== void 0 ? _c : 0;
vidMap.set(vid, __assign(__assign({}, vidMap.get(vid)), { rowItemHeight: tempRowHeight }));
dispatch({
type: 'initHeight',
rowHeight: tempRowHeight,
});
}
};
initHeight(Object.prototype.hasOwnProperty.call(ref, 'current') ? ref : trRef);
}, [trRef, dispatch, rowHeight, totalLen, ref, vid]);
// zhangzhen
React.useEffect(function () {
var _a, _b, _c;
if (restProps.index !== undefined) {
if ((_a = trRef === null || trRef === void 0 ? void 0 : trRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height) {
var nextSibling = trRef.current.nextSibling;
if (nextSibling && Array.from(nextSibling.classList).includes('ant-table-expanded-row')) {
dispatch({
type: 'setTrList',
trIndex: restProps.index,
trHeight: (((_b = trRef === null || trRef === void 0 ? void 0 : trRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect().height) + nextSibling.getBoundingClientRect().height) || 0
});
}
else {
dispatch({
type: 'setTrList',
trIndex: restProps.index,
trHeight: ((_c = trRef === null || trRef === void 0 ? void 0 : trRef.current) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().height) || 0
});
}
}
}
}, [children]);
return (React.createElement("tr", __assign({}, restProps, { ref: Object.prototype.hasOwnProperty.call(ref, 'current')
? ref
: trRef, style: __assign(__assign({}, style), {
// height: rowHeight || 'auto',
height: 'auto',
boxSizing: 'border-box' }) }), children));
}
function VWrapper(props) {
var children = props.children, restProps = __rest(props, ["children"]);
var _a = React.useContext(ScrollContext), renderLen = _a.renderLen, start = _a.start, dispatch = _a.dispatch, vid = _a.vid, totalLen = _a.totalLen;
var contents = React.useMemo(function () {
return children[1];
}, [children]);
var contentsLen = React.useMemo(function () {
var _a;
return (_a = contents === null || contents === void 0 ? void 0 : contents.length) !== null && _a !== void 0 ? _a : 0;
}, [contents]);
React.useEffect(function () {
if (totalLen !== contentsLen) {
dispatch({
type: 'changeTotalLen',
totalLen: contentsLen !== null && contentsLen !== void 0 ? contentsLen : 0,
});
}
}, [contentsLen, dispatch, vid, totalLen]);
var tempNode = null;
if (Array.isArray(contents) && contents.length) {
tempNode = [
children[0],
contents.slice(start, start + (renderLen !== null && renderLen !== void 0 ? renderLen : 1)).map(function (item) {
if (Array.isArray(item)) {
// 兼容antd v4.3.5 --- rc-table 7.8.1及以下
return item[0];
}
// 处理antd ^v4.4.0 --- rc-table ^7.8.2
return item;
}),
];
}
else {
tempNode = children;
}
return React.createElement("tbody", __assign({}, restProps), tempNode);
}
function VTable(props, otherParams) {
var _a, _b, _c, _d, _e, _f, _g, _h;
var style = props.style, children = props.children, rest = __rest(props, ["style", "children"]);
var width = style.width, rest_style = __rest(style, ["width"]);
var _j = otherParams !== null && otherParams !== void 0 ? otherParams : {}, vid = _j.vid, scrollY = _j.scrollY, reachEnd = _j.reachEnd, onScroll = _j.onScroll, resetScrollTopWhenDataChange = _j.resetScrollTopWhenDataChange;
var _k = React.useReducer(reducer, initialState), state = _k[0], dispatch = _k[1];
var wrap_tableRef = React.useRef(null);
var tableRef = React.useRef(null);
var ifChangeRef = React.useRef(false);
// 数据的总条数
var _l = React.useState((_d = (_c = (_b = (_a = children[1]) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0), totalLen = _l[0], setTotalLen = _l[1];
React.useEffect(function () {
setTotalLen(state.totalLen);
}, [state.totalLen]);
// 组件卸载的清除操作
React.useEffect(function () {
return function () {
vidMap.delete(vid);
};
}, [vid]);
// 数据变更
React.useEffect(function () {
var _a, _b, _c, _d, _e, _f, _g;
ifChangeRef.current = true;
// console.log('数据变更')
if (isNumber((_c = (_b = (_a = children[1]) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.length)) {
dispatch({
type: 'changeTotalLen',
totalLen: (_g = (_f = (_e = (_d = children[1]) === null || _d === void 0 ? void 0 : _d.props) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [children[1].props.data]);
// table总高度
var tableHeight = 'auto';
if (state.trHeightList.length && totalLen) {
tableHeight = 0;
// zhangzhen
for (var i = 1; i < state.trHeightList.length; i++) {
tableHeight += (_e = state.trHeightList[i]) !== null && _e !== void 0 ? _e : 0;
}
var parentTobdy = (_f = wrap_tableRef.current) === null || _f === void 0 ? void 0 : _f.parentNode;
if (parentTobdy) {
tableHeight = Math.max(tableHeight, parseFloat(parentTobdy.style.maxHeight));
}
}
// table的scrollY值
var _m = React.useState(0), tableScrollY = _m[0], setTableScrollY = _m[1];
// tableScrollY 随scrollY / tableHeight 进行变更
React.useEffect(function () {
var _a, _b, _c;
var temp = 0;
if (typeof scrollY === 'string') {
temp = (_c = (_b = (_a = wrap_tableRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.offsetHeight) !== null && _c !== void 0 ? _c : 0;
}
else {
temp = scrollY;
}
// if (isNumber(tableHeight) && tableHeight < temp) {
// temp = tableHeight;
// }
// 处理tableScrollY <= 0的情况
if (temp <= 0) {
temp = 0;
}
setTableScrollY(temp);
}, [scrollY, tableHeight]);
// 渲染的条数
var renderLen = React.useMemo(function () {
var temp = 1;
if (state.rowHeight && totalLen && tableScrollY) {
if (tableScrollY <= 0) {
temp = 0;
}
else {
var tempRenderLen = ((tableScrollY / state.rowHeight) | 0) + 1 + 2;
// console.log('tempRenderLen', tempRenderLen)
// temp = tempRenderLen > totalLen ? totalLen : tempRenderLen;
temp = tempRenderLen;
}
}
temp = Math.max(temp, 20);
return temp;
}, [state.rowHeight, totalLen, tableScrollY]);
// 渲染中的第一条
// zhangzhen
// let start = state.rowHeight ? (state.curScrollTop / state.rowHeight) | 0 : 0
var start = 0;
var totalLength = 0;
var currentHeight = 0;
if (state.trHeightList && state.curScrollTop) {
for (var i = 0; i < state.trHeightList.length; i++) {
totalLength += (_g = state.trHeightList[i]) !== null && _g !== void 0 ? _g : 0;
if (totalLength >= state.curScrollTop) {
currentHeight = state.trHeightList[i];
start = i;
break;
}
}
}
// 偏移量
// let offsetStart = state.rowHeight ? state.curScrollTop % state.rowHeight : 0
// let offsetStart = 0;
var offsetStart = (1 - (totalLength - state.curScrollTop) / currentHeight) * currentHeight;
if (!offsetStart || offsetStart !== offsetStart) {
offsetStart = 0;
}
// 用来优化向上滚动出现的空白
// if (
// state.curScrollTop &&
// state.rowHeight &&
// state.curScrollTop > state.rowHeight
// ) {
// start -= 1
// offsetStart += state.rowHeight
// } else {
// start = 0
// }
// 数据变更 操作scrollTop
React.useEffect(function () {
var _a;
var scrollNode = (_a = wrap_tableRef.current) === null || _a === void 0 ? void 0 : _a.parentNode;
if (ifChangeRef === null || ifChangeRef === void 0 ? void 0 : ifChangeRef.current) {
ifChangeRef.current = false;
if (resetScrollTopWhenDataChange) {
// 重置scrollTop
if (scrollNode) {
scrollNode.scrollTop = 0;
}
dispatch({ type: 'reset', ifScrollTopClear: true });
}
else {
// 不重置scrollTop 不清空curScrollTop
dispatch({ type: 'reset', ifScrollTopClear: false });
}
}
if (vidMap.has(vid)) {
vidMap.set(vid, __assign(__assign({}, vidMap.get(vid)), { scrollNode: scrollNode }));
}
}, [totalLen, resetScrollTopWhenDataChange, vid, children]);
React.useEffect(function () {
var _a;
var throttleScroll = throttle(function (e) {
var _a, _b, _c, _d, _e, _f;
var scrollTop = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.scrollTop) !== null && _b !== void 0 ? _b : 0;
var scrollHeight = (_d = (_c = e === null || e === void 0 ? void 0 : e.target) === null || _c === void 0 ? void 0 : _c.scrollHeight) !== null && _d !== void 0 ? _d : 0;
var clientHeight = (_f = (_e = e === null || e === void 0 ? void 0 : e.target) === null || _e === void 0 ? void 0 : _e.clientHeight) !== null && _f !== void 0 ? _f : 0;
// 到底了 没有滚动条就不会触发reachEnd. 建议设置scrolly高度少点或者数据量多点.
if (scrollTop === scrollHeight) ;
else if (scrollTop + clientHeight >= scrollHeight) {
// 有滚动条的情况
// eslint-disable-next-line no-unused-expressions
reachEnd && reachEnd();
}
// eslint-disable-next-line no-unused-expressions
onScroll && onScroll();
// 若renderLen大于totalLen, 置空curScrollTop. => table paddingTop会置空.
dispatch({
type: 'changeTrs',
curScrollTop: renderLen <= totalLen ? scrollTop : 0,
});
}, 60);
var ref = (_a = wrap_tableRef === null || wrap_tableRef === void 0 ? void 0 : wrap_tableRef.current) === null || _a === void 0 ? void 0 : _a.parentNode;
if (ref) {
ref.addEventListener('scroll', throttleScroll);
}
return function () {
ref.removeEventListener('scroll', throttleScroll);
};
}, [onScroll, reachEnd, renderLen, totalLen]);
// console.log(start, renderLen)
debounceListRender(start, renderLen);
return (React.createElement("div", { className: "virtuallist", ref: wrap_tableRef, style: {
width: '100%',
position: 'relative',
height: tableHeight,
boxSizing: 'border-box',
paddingTop: state.curScrollTop,
} },
React.createElement(ScrollContext.Provider, { value: {
dispatch: dispatch,
rowHeight: (_h = vidMap === null || vidMap === void 0 ? void 0 : vidMap.get(vid)) === null || _h === void 0 ? void 0 : _h.rowItemHeight,
start: start,
offsetStart: offsetStart,
renderLen: renderLen,
totalLen: totalLen,
vid: vid,
} },
React.createElement("table", __assign({}, rest, { ref: tableRef, style: __assign(__assign({}, rest_style), { width: width, position: 'relative', transform: "translateY(-" + offsetStart + "px)" }) }), children))));
}
// ================导出===================
export function VList(props) {
var _a = props.vid, vid = _a === void 0 ? DEFAULT_VID : _a, height = props.height, onReachEnd = props.onReachEnd, onScroll = props.onScroll, onListRender = props.onListRender, debounceListRenderMS = props.debounceListRenderMS; props.resetTopWhenDataChange;
// const resetScrollTopWhenDataChange = onReachEnd
// ? false
// : resetTopWhenDataChange
var resetScrollTopWhenDataChange = false;
if (!vidMap.has(vid)) {
vidMap.set(vid, { _id: vid });
}
debounceListRender = onListRender
? debounce(function (_start, _renderLen) {
onListRender({ start: _start, renderLen: _renderLen });
}, debounceListRenderMS !== null && debounceListRenderMS !== void 0 ? debounceListRenderMS : 300)
: function () { };
return {
table: function (p) {
return VTable(p, {
vid: vid,
scrollY: height,
reachEnd: onReachEnd,
onScroll: onScroll,
onListRender: onListRender,
resetScrollTopWhenDataChange: resetScrollTopWhenDataChange,
});
},
body: {
wrapper: VWrapper,
row: VRow,
cell: VCell,
},
};
}
export function scrollTo(option) {
var row = option.row, y = option.y, _a = option.vid, vid = _a === void 0 ? DEFAULT_VID : _a;
var _b = vidMap.get(vid), scrollNode = _b.scrollNode, rowItemHeight = _b.rowItemHeight;
if (row) {
if (row - 1 > 0) {
scrollNode.scrollTop = (row - 1) * (rowItemHeight !== null && rowItemHeight !== void 0 ? rowItemHeight : 0);
}
else {
scrollNode.scrollTop = 0;
}
}
else {
scrollNode.scrollTop = y !== null && y !== void 0 ? y : 0;
}
return { vid: vid, rowItemHeight: rowItemHeight };
}
// exports.VList = VList;
// exports.scrollTo = scrollTo;