@nutui/nutui-react-taro 1.3.5 → 1.3.7
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.
- package/CHANGELOG.md +14 -0
- package/dist/esm/Audio.js +4 -4
- package/dist/esm/Calendar.js +4 -4
- package/dist/esm/CalendarItem.js +3 -3
- package/dist/esm/DatePicker.js +4 -4
- package/dist/esm/Drag.js +3 -4
- package/dist/esm/Elevator.js +2 -4
- package/dist/esm/Menu.js +2 -2
- package/dist/esm/MenuItem.js +2 -2
- package/dist/esm/NoticeBar.js +3 -3
- package/dist/esm/Picker.js +3 -3
- package/dist/esm/Popover.js +3 -3
- package/dist/esm/Range.js +3 -3
- package/dist/esm/SearchBar.js +3 -2
- package/dist/esm/Signature.js +3 -2
- package/dist/esm/Swipe.js +3 -3
- package/dist/esm/actionsheet.taro-360d8d34.js +15 -25
- package/dist/esm/address.taro-f16cef31.js +151 -219
- package/dist/esm/animatingnumbers.taro-6f40a2e9.js +13 -41
- package/dist/esm/{audio.taro-29f5568f.js → audio.taro-57d4f0da.js} +33 -60
- package/dist/esm/avatar.taro-ec620cdd.js +25 -50
- package/dist/esm/avatargroup-5b2584d9.js +2 -9
- package/dist/esm/backtop.taro-aa8b2bc5.js +29 -55
- package/dist/esm/badge.taro-38684262.js +9 -20
- package/dist/esm/barrage.taro-d86c367a.js +8 -21
- package/dist/esm/button.taro-a9ebb937.js +22 -37
- package/dist/esm/{calendar.taro-438940bd.js → calendar.taro-533b3219.js} +13 -24
- package/dist/esm/{calendaritem.taro-11333579.js → calendaritem.taro-fe5dd4bd.js} +71 -183
- package/dist/esm/card.taro-1bc35ebe.js +14 -20
- package/dist/esm/cascader.taro-77100fb4.js +77 -197
- package/dist/esm/cell.taro-a4c3bb7b.js +20 -30
- package/dist/esm/cellgroup.taro-8c87bf08.js +6 -12
- package/dist/esm/checkbox.taro-104557c1.js +27 -48
- package/dist/esm/checkboxgroup.taro-3d380042.js +12 -30
- package/dist/esm/circleprogress.taro-3c89a157.js +14 -41
- package/dist/esm/col.taro-2a437387.js +11 -22
- package/dist/esm/collapse.taro-72e58ba2.js +11 -27
- package/dist/esm/collapseitem-75843a5e.js +33 -47
- package/dist/esm/configprovider-3e87d67a.js +2 -6
- package/dist/esm/configprovider.taro-6c7b3056.js +4 -14
- package/dist/esm/countdown.taro-f2d9ffed.js +37 -74
- package/dist/esm/{datepicker.taro-1acec61f.js → datepicker.taro-49a4cf0c.js} +43 -104
- package/dist/esm/dialog.taro-492e2b9a.js +27 -58
- package/dist/esm/divider.taro-5236fe6a.js +8 -15
- package/dist/esm/drag.taro-0717c783.js +153 -0
- package/dist/esm/{elevator.taro-8e385785.js → elevator.taro-443253ec.js} +99 -124
- package/dist/esm/empty.taro-ab9c4f03.js +11 -24
- package/dist/esm/fixednav.taro-582322a1.js +16 -27
- package/dist/esm/grid.taro-5d75c0ad.js +13 -28
- package/dist/esm/griditem.taro-866cd288.js +18 -34
- package/dist/esm/icon-8dc4de10.js +11 -21
- package/dist/esm/icon.taro-1d0d4fb7.js +11 -21
- package/dist/esm/imagepreview.taro-1199e977.js +36 -71
- package/dist/esm/indicator.taro-183ea169.js +9 -20
- package/dist/esm/infiniteloading.taro-b95e62bf.js +23 -49
- package/dist/esm/input.taro-2453d7c4.js +62 -106
- package/dist/esm/inputnumber.taro-0cf7c1b7.js +25 -52
- package/dist/esm/layout.taro-358f014f.js +0 -6
- package/dist/esm/{menu.taro-9345dcfd.js → menu.taro-f8ca86db.js} +24 -42
- package/dist/esm/{menuitem.taro-fc0961b7.js → menuitem.taro-7bf564c9.js} +32 -57
- package/dist/esm/navbar.taro-c931c078.js +18 -34
- package/dist/esm/{noticebar.taro-1fa04a96.js → noticebar.taro-332691f9.js} +55 -107
- package/dist/esm/notify.taro-d9c48fae.js +18 -34
- package/dist/esm/numberkeyboard.taro-53c350b8.js +21 -52
- package/dist/esm/nutui-react.es.js +18 -18
- package/dist/esm/offsetContext-0e3d04b3.js +0 -3
- package/dist/esm/overlay.taro-be45fed5.js +12 -23
- package/dist/esm/pagination.taro-62bbd23f.js +38 -71
- package/dist/esm/{picker.taro-6a4dad23.js → picker.taro-f003b725.js} +95 -186
- package/dist/esm/{popover.taro-eddd0bd2.js → popover.taro-7e5dff8c.js} +33 -76
- package/dist/esm/popup.taro-33d0bbc8.js +40 -72
- package/dist/esm/price.taro-97393d8f.js +7 -24
- package/dist/esm/progress.taro-623bc807.js +23 -31
- package/dist/esm/pulltorefresh.taro-e66c78ad.js +29 -92
- package/dist/esm/radio.taro-95d43860.js +24 -47
- package/dist/esm/radiogroup.taro-b5dad516.js +14 -24
- package/dist/esm/{range.taro-515d37a4.js → range.taro-fc7c0b6a.js} +50 -133
- package/dist/esm/rate.taro-69c85081.js +21 -39
- package/dist/esm/row.taro-cec13a7e.js +7 -16
- package/dist/esm/{searchbar.taro-f134fb96.js → searchbar.taro-0d3c0081.js} +55 -70
- package/dist/esm/shortpassword.taro-2e96ca22.js +29 -56
- package/dist/esm/sidenavbar.taro-87f056cd.js +9 -16
- package/dist/esm/sidenavbaritem.taro-77e077f4.js +4 -11
- package/dist/esm/signature.taro-59b3b3ab.js +146 -0
- package/dist/esm/skeleton.taro-b9ff84b9.js +13 -23
- package/dist/esm/step.taro-f1057500.js +12 -28
- package/dist/esm/steps.taro-943f4fbb.js +6 -14
- package/dist/esm/sticky.taro-30d4e453.js +0 -7
- package/dist/esm/subsidenavbar.taro-2c1fcf16.js +7 -22
- package/dist/esm/{swipe.taro-dfb9a049.js → swipe.taro-83bc248f.js} +98 -91
- package/dist/esm/swiper.taro-f314d67a.js +110 -196
- package/dist/esm/swiperitem-d00e7513.js +2 -12
- package/dist/esm/switch.taro-be5eb823.js +13 -27
- package/dist/esm/tabbar.taro-da72fa2c.js +13 -25
- package/dist/esm/tabbaritem.taro-94cd62c2.js +15 -23
- package/dist/esm/table.taro-7ac89a6c.js +19 -39
- package/dist/esm/tabpane.taro-95aa185b.js +4 -10
- package/dist/esm/tabs.taro-86186dff.js +28 -54
- package/dist/esm/tag.taro-95d7f5c2.js +19 -36
- package/dist/esm/textarea.taro-388d1f90.js +18 -35
- package/dist/esm/timedetail.taro-519808cf.js +15 -28
- package/dist/esm/timepannel.taro-9904f6e6.js +5 -12
- package/dist/esm/timeselect.taro-73796bfc.js +35 -59
- package/dist/esm/toast.taro-86862dff.js +26 -46
- package/dist/esm/types/src/packages/elevator/demo.d.ts +1 -0
- package/dist/esm/types/src/packages/searchbar/searchbar.d.ts +2 -0
- package/dist/esm/types/src/packages/searchbar/searchbar.taro.d.ts +2 -0
- package/dist/esm/types/src/packages/signature/signature.taro.d.ts +10 -2
- package/dist/esm/uploader.taro-6184abe7.js +52 -144
- package/dist/esm/{useClientRect-8b7cc406.js → useClientRect-bf69d7b3.js} +1 -40
- package/dist/esm/useTouch-a2ea68c6.js +27 -47
- package/dist/esm/video-c1090c92.js +8 -19
- package/dist/esm/virtuallist.taro-6858f690.js +84 -118
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/nutui.react.es.js +10848 -11365
- package/dist/nutui.react.umd.js +10840 -11357
- package/dist/packages/menu/menu.scss +4 -0
- package/dist/packages/menuitem/menuitem.scss +27 -2
- package/dist/packages/searchbar/searchbar.scss +20 -3
- package/dist/style.css +1 -1
- package/dist/style.es.js +1 -1
- package/dist/types/index.d.ts +17 -8
- package/package.json +1 -1
- package/dist/esm/drag.taro-56e8c87a.js +0 -134
- package/dist/esm/signature.taro-a9286cd1.js +0 -178
|
@@ -1,73 +1,58 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
var MIN_DISTANCE = 10;
|
|
4
|
-
|
|
5
4
|
function getDirection(x, y) {
|
|
6
5
|
if (x > y && x > MIN_DISTANCE) {
|
|
7
6
|
return 'horizontal';
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
if (y > x && y > MIN_DISTANCE) {
|
|
11
9
|
return 'vertical';
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return '';
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
function useTouch() {
|
|
18
14
|
var _useState = useState(0),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
16
|
+
startX = _useState2[0],
|
|
17
|
+
SetStartX = _useState2[1];
|
|
23
18
|
var _useState3 = useState(0),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
20
|
+
startY = _useState4[0],
|
|
21
|
+
SetStartY = _useState4[1];
|
|
28
22
|
var _useState5 = useState(0),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
24
|
+
moveX = _useState6[0],
|
|
25
|
+
SetMoveX = _useState6[1];
|
|
33
26
|
var _useState7 = useState(0),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
28
|
+
moveY = _useState8[0],
|
|
29
|
+
SetMoveY = _useState8[1];
|
|
38
30
|
var _useState9 = useState(0),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
32
|
+
deltaX = _useState10[0],
|
|
33
|
+
SetDeltaX = _useState10[1];
|
|
43
34
|
var _useState11 = useState(0),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
36
|
+
deltaY = _useState12[0],
|
|
37
|
+
SetDeltaY = _useState12[1];
|
|
48
38
|
var _useState13 = useState(0),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
40
|
+
offsetX = _useState14[0],
|
|
41
|
+
SetOffsetX = _useState14[1];
|
|
53
42
|
var _useState15 = useState(0),
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
44
|
+
offsetY = _useState16[0],
|
|
45
|
+
SetOffsetY = _useState16[1];
|
|
58
46
|
var _useState17 = useState(''),
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
48
|
+
direction = _useState18[0],
|
|
49
|
+
SetDirection = _useState18[1];
|
|
63
50
|
var isVertical = function isVertical() {
|
|
64
51
|
return direction === 'vertical';
|
|
65
52
|
};
|
|
66
|
-
|
|
67
53
|
var isHorizontal = function isHorizontal() {
|
|
68
54
|
return direction === 'horizontal';
|
|
69
55
|
};
|
|
70
|
-
|
|
71
56
|
var reset = function reset() {
|
|
72
57
|
SetDeltaX(0);
|
|
73
58
|
SetDeltaY(0);
|
|
@@ -75,13 +60,11 @@ function useTouch() {
|
|
|
75
60
|
SetOffsetY(0);
|
|
76
61
|
SetDirection('');
|
|
77
62
|
};
|
|
78
|
-
|
|
79
63
|
var start = function start(event) {
|
|
80
64
|
reset();
|
|
81
65
|
SetStartX(event.touches[0].clientX);
|
|
82
66
|
SetStartY(event.touches[0].clientY);
|
|
83
67
|
};
|
|
84
|
-
|
|
85
68
|
var move = function move(event) {
|
|
86
69
|
var touch = event.touches[0];
|
|
87
70
|
var dX = touch.clientX - startX;
|
|
@@ -92,12 +75,10 @@ function useTouch() {
|
|
|
92
75
|
SetMoveY(touch.clientY);
|
|
93
76
|
SetOffsetX(Math.abs(dX));
|
|
94
77
|
SetOffsetY(Math.abs(dY));
|
|
95
|
-
|
|
96
78
|
if (!direction) {
|
|
97
79
|
SetDirection(getDirection(offsetX, offsetY));
|
|
98
80
|
}
|
|
99
81
|
};
|
|
100
|
-
|
|
101
82
|
return {
|
|
102
83
|
move: move,
|
|
103
84
|
start: start,
|
|
@@ -115,5 +96,4 @@ function useTouch() {
|
|
|
115
96
|
isHorizontal: isHorizontal
|
|
116
97
|
};
|
|
117
98
|
}
|
|
118
|
-
|
|
119
99
|
export { useTouch as u };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["children", "source", "options", "className", "play", "pause", "playend"];
|
|
4
|
-
|
|
5
4
|
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; }
|
|
6
|
-
|
|
7
5
|
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; }
|
|
8
|
-
|
|
9
6
|
import React__default, { useRef, useEffect } from 'react';
|
|
10
7
|
import classNames from 'classnames';
|
|
11
8
|
import { c as cn } from './bem-893ad28d.js';
|
|
@@ -23,42 +20,36 @@ var defaultProps = {
|
|
|
23
20
|
loop: false
|
|
24
21
|
}
|
|
25
22
|
};
|
|
26
|
-
|
|
27
23
|
var Video = function Video(props) {
|
|
28
24
|
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
children = _defaultProps$props.children,
|
|
26
|
+
source = _defaultProps$props.source,
|
|
27
|
+
options = _defaultProps$props.options,
|
|
28
|
+
className = _defaultProps$props.className,
|
|
29
|
+
play = _defaultProps$props.play,
|
|
30
|
+
pause = _defaultProps$props.pause,
|
|
31
|
+
playend = _defaultProps$props.playend,
|
|
32
|
+
restProps = _objectWithoutProperties(_defaultProps$props, _excluded);
|
|
38
33
|
var rootRef = useRef(null);
|
|
39
34
|
var b = cn('video');
|
|
40
35
|
var classes = classNames(className, b(''));
|
|
41
36
|
useEffect(function () {
|
|
42
37
|
init();
|
|
43
38
|
}, []);
|
|
44
|
-
|
|
45
39
|
var init = function init() {
|
|
46
40
|
if (rootRef.current) {
|
|
47
41
|
var videoRef = rootRef.current;
|
|
48
|
-
|
|
49
42
|
if (options.autoplay) {
|
|
50
43
|
setTimeout(function () {
|
|
51
44
|
videoRef.play();
|
|
52
45
|
}, 200);
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
if (options.playsinline) {
|
|
56
48
|
videoRef.setAttribute('playsinline', String(options.playsinline));
|
|
57
49
|
videoRef.setAttribute('webkit-playsinline', String(options.playsinline));
|
|
58
50
|
videoRef.setAttribute('x5-video-player-type', 'h5-page');
|
|
59
51
|
videoRef.setAttribute('x5-video-player-fullscreen', 'false');
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
videoRef.addEventListener('play', function () {
|
|
63
54
|
play && play(videoRef);
|
|
64
55
|
});
|
|
@@ -71,7 +62,6 @@ var Video = function Video(props) {
|
|
|
71
62
|
});
|
|
72
63
|
}
|
|
73
64
|
};
|
|
74
|
-
|
|
75
65
|
return React__default.createElement("div", _objectSpread({
|
|
76
66
|
className: classes
|
|
77
67
|
}, restProps), React__default.createElement("video", {
|
|
@@ -90,7 +80,6 @@ var Video = function Video(props) {
|
|
|
90
80
|
kind: "captions"
|
|
91
81
|
})));
|
|
92
82
|
};
|
|
93
|
-
|
|
94
83
|
Video.defaultProps = defaultProps;
|
|
95
84
|
Video.displayName = 'NutVideo';
|
|
96
85
|
export { Video as V };
|
|
@@ -2,19 +2,16 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["sourceData", "ItemRender", "itemEqualSize", "itemSize", "horizontal", "overscan", "key", "handleScroll", "className", "containerSize"];
|
|
5
|
-
|
|
6
5
|
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; }
|
|
7
|
-
|
|
8
6
|
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; }
|
|
9
|
-
|
|
10
7
|
import React__default, { useRef, useState, useEffect, useCallback } from 'react';
|
|
11
|
-
import { u as useConfig } from './configprovider.taro-6c7b3056.js';
|
|
8
|
+
import { u as useConfig } from './configprovider.taro-6c7b3056.js';
|
|
12
9
|
|
|
10
|
+
// 缓存列表初始化信息
|
|
13
11
|
var initPositinoCache = function initPositinoCache(reaItemSize) {
|
|
14
12
|
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
15
13
|
var index = 0;
|
|
16
14
|
var positions = Array(length);
|
|
17
|
-
|
|
18
15
|
while (index < length) {
|
|
19
16
|
positions[index] = {
|
|
20
17
|
index: index,
|
|
@@ -27,25 +24,20 @@ var initPositinoCache = function initPositinoCache(reaItemSize) {
|
|
|
27
24
|
};
|
|
28
25
|
index++;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
return positions;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
};
|
|
29
|
+
// 获取列表总高度
|
|
35
30
|
var getListTotalSize = function getListTotalSize(positions, horizontal) {
|
|
36
31
|
var index = positions.length - 1;
|
|
37
32
|
var size = 0;
|
|
38
|
-
|
|
39
33
|
if (index < 0) {
|
|
40
34
|
size = 0;
|
|
41
35
|
} else {
|
|
42
36
|
size = horizontal ? positions[index].right : positions[index].bottom;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
38
|
return size;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
};
|
|
40
|
+
// 通过二分法找到 scrollOffset 对应的值
|
|
49
41
|
var binarySearch = function binarySearch(positionsList) {
|
|
50
42
|
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
51
43
|
var horizontal = arguments.length > 2 ? arguments[2] : undefined;
|
|
@@ -53,74 +45,63 @@ var binarySearch = function binarySearch(positionsList) {
|
|
|
53
45
|
var end = positionsList.length - 1;
|
|
54
46
|
var tempIndex = null;
|
|
55
47
|
var key = horizontal ? 'right' : 'bottom';
|
|
56
|
-
|
|
57
48
|
while (start <= end) {
|
|
58
49
|
var midIndex = Math.floor((start + end) / 2);
|
|
59
|
-
var midValue = positionsList[midIndex][key];
|
|
60
|
-
|
|
50
|
+
var midValue = positionsList[midIndex][key];
|
|
51
|
+
// 相等则直接返回(因为是bottom, 因此startIndex应该是下一个节点)
|
|
61
52
|
if (midValue === value) {
|
|
62
53
|
return midIndex + 1;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
}
|
|
55
|
+
// 中间值 < 传入值,则说明 value对应的节点 大于 start, start往后移动一位
|
|
66
56
|
if (midValue < value) {
|
|
67
57
|
start = midIndex + 1;
|
|
68
|
-
}
|
|
58
|
+
}
|
|
59
|
+
// 中间值 > 传入值,则说明 value 在 中间值之前,end 节点移动到 mid - 1
|
|
69
60
|
else if (midValue > value) {
|
|
70
61
|
// tempIndex存放最靠近值为value的所有
|
|
71
62
|
if (tempIndex === null || tempIndex > midIndex) {
|
|
72
63
|
tempIndex = midIndex;
|
|
73
64
|
}
|
|
74
|
-
|
|
75
65
|
end = midIndex - 1;
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
tempIndex = tempIndex || 0;
|
|
80
69
|
return tempIndex;
|
|
81
70
|
};
|
|
82
|
-
|
|
83
71
|
var getEndIndex = function getEndIndex(_ref) {
|
|
84
72
|
var sourceData = _ref.sourceData,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
73
|
+
startIndex = _ref.startIndex,
|
|
74
|
+
visibleCount = _ref.visibleCount,
|
|
75
|
+
_ref$itemEqualSize = _ref.itemEqualSize,
|
|
76
|
+
itemEqualSize = _ref$itemEqualSize === void 0 ? true : _ref$itemEqualSize,
|
|
77
|
+
positions = _ref.positions,
|
|
78
|
+
offSetSize = _ref.offSetSize,
|
|
79
|
+
overscan = _ref.overscan,
|
|
80
|
+
_ref$sizeKey = _ref.sizeKey,
|
|
81
|
+
sizeKey = _ref$sizeKey === void 0 ? 'width' : _ref$sizeKey;
|
|
94
82
|
var dataLength = sourceData.length;
|
|
95
83
|
var tempIndex = null;
|
|
96
|
-
|
|
97
84
|
if (itemEqualSize) {
|
|
98
85
|
var endIndex = startIndex + visibleCount;
|
|
99
86
|
tempIndex = dataLength > 0 ? Math.min(dataLength, endIndex) : endIndex;
|
|
100
87
|
} else {
|
|
101
88
|
var sizeNum = 0;
|
|
102
|
-
|
|
103
89
|
for (var i = startIndex; i < dataLength; i++) {
|
|
104
90
|
sizeNum += positions[i][sizeKey] || 0;
|
|
105
|
-
|
|
106
91
|
if (sizeNum > offSetSize) {
|
|
107
92
|
var _endIndex = i + overscan;
|
|
108
|
-
|
|
109
93
|
tempIndex = dataLength > 0 ? Math.min(dataLength, _endIndex) : _endIndex;
|
|
110
94
|
break;
|
|
111
95
|
}
|
|
112
96
|
}
|
|
113
|
-
|
|
114
97
|
if (sizeNum < offSetSize) {
|
|
115
98
|
tempIndex = dataLength;
|
|
116
99
|
}
|
|
117
100
|
}
|
|
118
|
-
|
|
119
101
|
tempIndex = tempIndex || 0;
|
|
120
102
|
return tempIndex;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
|
|
103
|
+
};
|
|
104
|
+
// 更新Item大小
|
|
124
105
|
var updateItemSize = function updateItemSize(positions, items, sizeKey) {
|
|
125
106
|
var newPos = positions.concat();
|
|
126
107
|
Array.from(items).forEach(function (item) {
|
|
@@ -128,15 +109,13 @@ var updateItemSize = function updateItemSize(positions, items, sizeKey) {
|
|
|
128
109
|
var styleVal = item.getAttribute('style');
|
|
129
110
|
if (styleVal && styleVal.includes('none')) return;
|
|
130
111
|
var nowSize = item.getBoundingClientRect()[sizeKey];
|
|
131
|
-
var oldSize = positions[index][sizeKey];
|
|
132
|
-
|
|
112
|
+
var oldSize = positions[index][sizeKey];
|
|
113
|
+
// 存在差值, 更新该节点以后所有的节点
|
|
133
114
|
var dValue = oldSize - nowSize;
|
|
134
|
-
|
|
135
115
|
if (dValue) {
|
|
136
116
|
if (sizeKey === 'width') {
|
|
137
117
|
newPos[index].right -= dValue;
|
|
138
118
|
newPos[index][sizeKey] = nowSize;
|
|
139
|
-
|
|
140
119
|
for (var k = index + 1; k < positions.length; k++) {
|
|
141
120
|
newPos[k].left = positions[k - 1].right;
|
|
142
121
|
newPos[k].right -= dValue;
|
|
@@ -144,7 +123,6 @@ var updateItemSize = function updateItemSize(positions, items, sizeKey) {
|
|
|
144
123
|
} else if (sizeKey === 'height') {
|
|
145
124
|
newPos[index].bottom -= dValue;
|
|
146
125
|
newPos[index][sizeKey] = nowSize;
|
|
147
|
-
|
|
148
126
|
for (var _k = index + 1; _k < positions.length; _k++) {
|
|
149
127
|
newPos[_k].top = positions[_k - 1].bottom;
|
|
150
128
|
newPos[_k].bottom -= dValue;
|
|
@@ -153,79 +131,70 @@ var updateItemSize = function updateItemSize(positions, items, sizeKey) {
|
|
|
153
131
|
}
|
|
154
132
|
});
|
|
155
133
|
};
|
|
156
|
-
|
|
157
134
|
var defaultProps = {};
|
|
158
|
-
|
|
159
135
|
var VirtualList = function VirtualList(props) {
|
|
160
136
|
var _props$sourceData = props.sourceData,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
137
|
+
sourceData = _props$sourceData === void 0 ? [] : _props$sourceData,
|
|
138
|
+
ItemRender = props.ItemRender,
|
|
139
|
+
_props$itemEqualSize = props.itemEqualSize,
|
|
140
|
+
itemEqualSize = _props$itemEqualSize === void 0 ? true : _props$itemEqualSize,
|
|
141
|
+
_props$itemSize = props.itemSize,
|
|
142
|
+
itemSize = _props$itemSize === void 0 ? 200 : _props$itemSize,
|
|
143
|
+
_props$horizontal = props.horizontal,
|
|
144
|
+
horizontal = _props$horizontal === void 0 ? false : _props$horizontal,
|
|
145
|
+
_props$overscan = props.overscan,
|
|
146
|
+
overscan = _props$overscan === void 0 ? 2 : _props$overscan,
|
|
147
|
+
key = props.key,
|
|
148
|
+
handleScroll = props.handleScroll,
|
|
149
|
+
className = props.className,
|
|
150
|
+
containerSize = props.containerSize,
|
|
151
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
177
152
|
var sizeKey = horizontal ? 'width' : 'height';
|
|
178
153
|
var scrollKey = horizontal ? 'scrollLeft' : 'scrollTop';
|
|
179
154
|
var offsetKey = horizontal ? 'left' : 'top';
|
|
180
|
-
useConfig();
|
|
181
|
-
|
|
182
|
-
var scrollRef = useRef(null);
|
|
183
|
-
|
|
155
|
+
useConfig();
|
|
156
|
+
// 虚拟列表容器ref
|
|
157
|
+
var scrollRef = useRef(null);
|
|
158
|
+
// 虚拟列表显示区域ref
|
|
184
159
|
var itemsRef = useRef(null);
|
|
185
|
-
var firstItemRef = useRef(null);
|
|
186
|
-
|
|
160
|
+
var firstItemRef = useRef(null);
|
|
161
|
+
// 列表位置信息
|
|
187
162
|
var _useState = useState([{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
163
|
+
index: 0,
|
|
164
|
+
left: 0,
|
|
165
|
+
top: 0,
|
|
166
|
+
bottom: 0,
|
|
167
|
+
width: 0,
|
|
168
|
+
height: 0,
|
|
169
|
+
right: 0
|
|
170
|
+
}]),
|
|
171
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
172
|
+
positions = _useState2[0],
|
|
173
|
+
setPositions = _useState2[1];
|
|
174
|
+
// 列表总大小
|
|
201
175
|
var _useState3 = useState(99999999),
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
176
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
177
|
+
listTotalSize = _useState4[0],
|
|
178
|
+
setListTotalSize = _useState4[1];
|
|
179
|
+
// 可视区域条数
|
|
207
180
|
var _useState5 = useState(0),
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
181
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
182
|
+
visibleCount = _useState6[0],
|
|
183
|
+
setVisibleCount = _useState6[1];
|
|
212
184
|
var _useState7 = useState(containerSize || 0),
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
185
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
186
|
+
offSetSize = _useState8[0],
|
|
187
|
+
setOffSetSize = _useState8[1];
|
|
217
188
|
var _useState9 = useState({
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
189
|
+
startOffset: 0,
|
|
190
|
+
startIndex: 0,
|
|
191
|
+
overStart: 0,
|
|
192
|
+
endIndex: 10 // 可视区域结束索引
|
|
193
|
+
}),
|
|
194
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
195
|
+
options = _useState10[0],
|
|
196
|
+
setOptions = _useState10[1];
|
|
197
|
+
// 列表位置信息
|
|
229
198
|
useEffect(function () {
|
|
230
199
|
var pos = initPositinoCache(itemSize, sourceData.length);
|
|
231
200
|
setPositions(pos);
|
|
@@ -234,7 +203,6 @@ var VirtualList = function VirtualList(props) {
|
|
|
234
203
|
}, [sourceData, itemSize, horizontal]);
|
|
235
204
|
var getElement = useCallback(function () {
|
|
236
205
|
var _scrollRef$current;
|
|
237
|
-
|
|
238
206
|
return ((_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 ? void 0 : _scrollRef$current.parentElement) || document.body;
|
|
239
207
|
}, []);
|
|
240
208
|
useEffect(function () {
|
|
@@ -256,8 +224,8 @@ var VirtualList = function VirtualList(props) {
|
|
|
256
224
|
var updateTotalSize = useCallback(function () {
|
|
257
225
|
if (!itemsRef.current) return;
|
|
258
226
|
var items = itemsRef.current.children;
|
|
259
|
-
if (!items.length) return;
|
|
260
|
-
|
|
227
|
+
if (!items.length) return;
|
|
228
|
+
// 更新缓存
|
|
261
229
|
updateItemSize(positions, items, sizeKey);
|
|
262
230
|
var totalSize = getListTotalSize(positions, horizontal);
|
|
263
231
|
setListTotalSize(totalSize);
|
|
@@ -266,12 +234,11 @@ var VirtualList = function VirtualList(props) {
|
|
|
266
234
|
requestAnimationFrame(function (e) {
|
|
267
235
|
var scrollSize = getElement()[scrollKey];
|
|
268
236
|
var startIndex = binarySearch(positions, scrollSize, horizontal);
|
|
269
|
-
var overStart = startIndex - overscan > -1 ? startIndex - overscan : 0;
|
|
270
|
-
|
|
237
|
+
var overStart = startIndex - overscan > -1 ? startIndex - overscan : 0;
|
|
238
|
+
// const offSetSize = horizontal ? getElement().offsetWidth : getElement().offsetHeight
|
|
271
239
|
if (!itemEqualSize) {
|
|
272
240
|
updateTotalSize();
|
|
273
241
|
}
|
|
274
|
-
|
|
275
242
|
var endIndex = getEndIndex({
|
|
276
243
|
sourceData: sourceData,
|
|
277
244
|
startIndex: startIndex,
|
|
@@ -288,8 +255,8 @@ var VirtualList = function VirtualList(props) {
|
|
|
288
255
|
startIndex: startIndex,
|
|
289
256
|
overStart: overStart,
|
|
290
257
|
endIndex: endIndex
|
|
291
|
-
});
|
|
292
|
-
|
|
258
|
+
});
|
|
259
|
+
// 无限下滑
|
|
293
260
|
if (endIndex > sourceData.length - 1) {
|
|
294
261
|
handleScroll && handleScroll();
|
|
295
262
|
}
|
|
@@ -320,7 +287,7 @@ var VirtualList = function VirtualList(props) {
|
|
|
320
287
|
}
|
|
321
288
|
}, sourceData.slice(options.overStart, options.endIndex).map(function (data, index) {
|
|
322
289
|
var startIndex = options.startIndex,
|
|
323
|
-
|
|
290
|
+
overStart = options.overStart;
|
|
324
291
|
var dataIndex = overStart + index;
|
|
325
292
|
var styleVal = dataIndex < startIndex ? 'none' : 'block';
|
|
326
293
|
var keyVal = key && data[key] ? data[key] : dataIndex;
|
|
@@ -338,7 +305,6 @@ var VirtualList = function VirtualList(props) {
|
|
|
338
305
|
}) : data);
|
|
339
306
|
}))));
|
|
340
307
|
};
|
|
341
|
-
|
|
342
308
|
VirtualList.defaultProps = defaultProps;
|
|
343
309
|
VirtualList.displayName = 'NutVirtualList';
|
|
344
310
|
export { VirtualList as V };
|
package/dist/locales/base.js
CHANGED
package/dist/locales/en-US.js
CHANGED
package/dist/locales/id-ID.js
CHANGED
package/dist/locales/zh-CN.js
CHANGED
package/dist/locales/zh-TW.js
CHANGED