@nutui/nutui-react 1.1.5-beta.1 → 1.1.5-beta.4

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.
@@ -229,13 +229,11 @@ var CustomRender = function CustomRender(props) {
229
229
 
230
230
 
231
231
  var getTabName = function getTabName(item, index) {
232
- if (item.name) return item.name;
233
-
234
- if (tabIndex < index) {
232
+ if (tabIndex > index) {
235
233
  return item.name;
234
+ } else {
235
+ return locale.select;
236
236
  }
237
-
238
- return locale.select;
239
237
  };
240
238
 
241
239
  var mapRef = {
@@ -1,5 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["children", "title", "isOpen", "onToggle", "name", "disabled", "icon", "rotate", "subTitle", "titleIcon", "titleIconColor", "titleIconPosition", "titleIconSize", "iconSize", "iconColor"];
3
5
 
4
6
  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; }
5
7
 
@@ -41,7 +43,8 @@ var CollapseItem = function CollapseItem(props) {
41
43
  titleIconPosition = _defaultProps$props.titleIconPosition,
42
44
  titleIconSize = _defaultProps$props.titleIconSize,
43
45
  iconSize = _defaultProps$props.iconSize,
44
- iconColor = _defaultProps$props.iconColor;
46
+ iconColor = _defaultProps$props.iconColor,
47
+ rest = _objectWithoutProperties(_defaultProps$props, _excluded);
45
48
 
46
49
  var _useState = useState(-1),
47
50
  _useState2 = _slicedToArray(_useState, 2),
@@ -91,9 +94,9 @@ var CollapseItem = function CollapseItem(props) {
91
94
  };
92
95
  setIconStyle(newIconStyle);
93
96
  }, [isOpen, domHeight]);
94
- return React__default.createElement("div", {
97
+ return React__default.createElement("div", _objectSpread({
95
98
  className: colBem()
96
- }, React__default.createElement("div", {
99
+ }, rest), React__default.createElement("div", {
97
100
  className: colBem('header', {
98
101
  disabled: disabled
99
102
  }),
@@ -235,8 +235,8 @@ function confirm(config, renderFunc) {
235
235
  }
236
236
 
237
237
  var defaultProps = {
238
- okText: '确定',
239
- cancelText: '取消',
238
+ okText: '',
239
+ cancelText: '',
240
240
  mask: true,
241
241
  closeOnClickOverlay: true,
242
242
  noFooter: false,
@@ -297,7 +297,7 @@ var BaseDialog = function BaseDialog(props, ref) {
297
297
  onClick: function onClick() {
298
298
  return handleCancel();
299
299
  }
300
- }, locale.cancel || cancelText), !noOkBtn && React__default.createElement(Button, {
300
+ }, cancelText || locale.cancel), !noOkBtn && React__default.createElement(Button, {
301
301
  size: "small",
302
302
  type: "primary",
303
303
  className: classNames('nut-dialog__footer-ok', {
@@ -307,7 +307,7 @@ var BaseDialog = function BaseDialog(props, ref) {
307
307
  onClick: function onClick() {
308
308
  return handleOk();
309
309
  }
310
- }, locale.confirm || okText));
310
+ }, okText || locale.confirm));
311
311
  return footerContent;
312
312
  };
313
313
 
@@ -0,0 +1,2 @@
1
+
2
+ require('../../../packages/virtuallist/virtuallist.scss')
@@ -0,0 +1,344 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["sourceData", "ItemRender", "itemEqualSize", "itemSize", "horizontal", "overscan", "key", "handleScroll", "className", "containerSize"];
5
+
6
+ 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
+ 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
+ import React__default, { useRef, useState, useEffect, useCallback } from 'react';
11
+ import { useConfig } from './ConfigProvider.js'; // 缓存列表初始化信息
12
+
13
+ var initPositinoCache = function initPositinoCache(reaItemSize) {
14
+ var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
15
+ var index = 0;
16
+ var positions = Array(length);
17
+
18
+ while (index < length) {
19
+ positions[index] = {
20
+ index: index,
21
+ height: reaItemSize,
22
+ width: reaItemSize,
23
+ top: index * reaItemSize,
24
+ bottom: (index + 1) * reaItemSize,
25
+ left: index * reaItemSize,
26
+ right: (index + 1) * reaItemSize
27
+ };
28
+ index++;
29
+ }
30
+
31
+ return positions;
32
+ }; // 获取列表总高度
33
+
34
+
35
+ var getListTotalSize = function getListTotalSize(positions, horizontal) {
36
+ var index = positions.length - 1;
37
+ var size = 0;
38
+
39
+ if (index < 0) {
40
+ size = 0;
41
+ } else {
42
+ size = horizontal ? positions[index].right : positions[index].bottom;
43
+ }
44
+
45
+ return size;
46
+ }; // 通过二分法找到 scrollOffset 对应的值
47
+
48
+
49
+ var binarySearch = function binarySearch(positionsList) {
50
+ var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
51
+ var horizontal = arguments.length > 2 ? arguments[2] : undefined;
52
+ var start = 0;
53
+ var end = positionsList.length - 1;
54
+ var tempIndex = null;
55
+ var key = horizontal ? 'right' : 'bottom';
56
+
57
+ while (start <= end) {
58
+ var midIndex = Math.floor((start + end) / 2);
59
+ var midValue = positionsList[midIndex][key]; // 相等则直接返回(因为是bottom, 因此startIndex应该是下一个节点)
60
+
61
+ if (midValue === value) {
62
+ return midIndex + 1;
63
+ } // 中间值 < 传入值,则说明 value对应的节点 大于 start, start往后移动一位
64
+
65
+
66
+ if (midValue < value) {
67
+ start = midIndex + 1;
68
+ } // 中间值 > 传入值,则说明 value 在 中间值之前,end 节点移动到 mid - 1
69
+ else if (midValue > value) {
70
+ // tempIndex存放最靠近值为value的所有
71
+ if (tempIndex === null || tempIndex > midIndex) {
72
+ tempIndex = midIndex;
73
+ }
74
+
75
+ end = midIndex - 1;
76
+ }
77
+ }
78
+
79
+ tempIndex = tempIndex || 0;
80
+ return tempIndex;
81
+ };
82
+
83
+ var getEndIndex = function getEndIndex(_ref) {
84
+ var sourceData = _ref.sourceData,
85
+ startIndex = _ref.startIndex,
86
+ visibleCount = _ref.visibleCount,
87
+ _ref$itemEqualSize = _ref.itemEqualSize,
88
+ itemEqualSize = _ref$itemEqualSize === void 0 ? true : _ref$itemEqualSize,
89
+ positions = _ref.positions,
90
+ offSetSize = _ref.offSetSize,
91
+ overscan = _ref.overscan,
92
+ _ref$sizeKey = _ref.sizeKey,
93
+ sizeKey = _ref$sizeKey === void 0 ? 'width' : _ref$sizeKey;
94
+ var dataLength = sourceData.length;
95
+ var tempIndex = null;
96
+
97
+ if (itemEqualSize) {
98
+ var endIndex = startIndex + visibleCount;
99
+ tempIndex = dataLength > 0 ? Math.min(dataLength, endIndex) : endIndex;
100
+ } else {
101
+ var sizeNum = 0;
102
+
103
+ for (var i = startIndex; i < dataLength; i++) {
104
+ sizeNum += positions[i][sizeKey] || 0;
105
+
106
+ if (sizeNum > offSetSize) {
107
+ var _endIndex = i + overscan;
108
+
109
+ tempIndex = dataLength > 0 ? Math.min(dataLength, _endIndex) : _endIndex;
110
+ break;
111
+ }
112
+ }
113
+
114
+ if (sizeNum < offSetSize) {
115
+ tempIndex = dataLength;
116
+ }
117
+ }
118
+
119
+ tempIndex = tempIndex || 0;
120
+ return tempIndex;
121
+ }; // 更新Item大小
122
+
123
+
124
+ var updateItemSize = function updateItemSize(positions, items, sizeKey) {
125
+ var newPos = positions.concat();
126
+ Array.from(items).forEach(function (item) {
127
+ var index = Number(item.getAttribute('data-index'));
128
+ var styleVal = item.getAttribute('style');
129
+ if (styleVal && styleVal.includes('none')) return;
130
+ var nowSize = item.getBoundingClientRect()[sizeKey];
131
+ var oldSize = positions[index][sizeKey]; // 存在差值, 更新该节点以后所有的节点
132
+
133
+ var dValue = oldSize - nowSize;
134
+
135
+ if (dValue) {
136
+ if (sizeKey === 'width') {
137
+ newPos[index].right -= dValue;
138
+ newPos[index][sizeKey] = nowSize;
139
+
140
+ for (var k = index + 1; k < positions.length; k++) {
141
+ newPos[k].left = positions[k - 1].right;
142
+ newPos[k].right -= dValue;
143
+ }
144
+ } else if (sizeKey === 'height') {
145
+ newPos[index].bottom -= dValue;
146
+ newPos[index][sizeKey] = nowSize;
147
+
148
+ for (var _k = index + 1; _k < positions.length; _k++) {
149
+ newPos[_k].top = positions[_k - 1].bottom;
150
+ newPos[_k].bottom -= dValue;
151
+ }
152
+ }
153
+ }
154
+ });
155
+ };
156
+
157
+ var defaultProps = {};
158
+
159
+ var VirtualList = function VirtualList(props) {
160
+ var _props$sourceData = props.sourceData,
161
+ sourceData = _props$sourceData === void 0 ? [] : _props$sourceData,
162
+ ItemRender = props.ItemRender,
163
+ _props$itemEqualSize = props.itemEqualSize,
164
+ itemEqualSize = _props$itemEqualSize === void 0 ? true : _props$itemEqualSize,
165
+ _props$itemSize = props.itemSize,
166
+ itemSize = _props$itemSize === void 0 ? 200 : _props$itemSize,
167
+ _props$horizontal = props.horizontal,
168
+ horizontal = _props$horizontal === void 0 ? false : _props$horizontal,
169
+ _props$overscan = props.overscan,
170
+ overscan = _props$overscan === void 0 ? 2 : _props$overscan,
171
+ key = props.key,
172
+ handleScroll = props.handleScroll,
173
+ className = props.className,
174
+ containerSize = props.containerSize,
175
+ rest = _objectWithoutProperties(props, _excluded);
176
+
177
+ var sizeKey = horizontal ? 'width' : 'height';
178
+ var scrollKey = horizontal ? 'scrollLeft' : 'scrollTop';
179
+ var offsetKey = horizontal ? 'left' : 'top';
180
+ useConfig(); // 虚拟列表容器ref
181
+
182
+ var scrollRef = useRef(null); // 虚拟列表显示区域ref
183
+
184
+ var itemsRef = useRef(null);
185
+ var firstItemRef = useRef(null); // 列表位置信息
186
+
187
+ var _useState = useState([{
188
+ index: 0,
189
+ left: 0,
190
+ top: 0,
191
+ bottom: 0,
192
+ width: 0,
193
+ height: 0,
194
+ right: 0
195
+ }]),
196
+ _useState2 = _slicedToArray(_useState, 2),
197
+ positions = _useState2[0],
198
+ setPositions = _useState2[1]; // 列表总大小
199
+
200
+
201
+ var _useState3 = useState(99999999),
202
+ _useState4 = _slicedToArray(_useState3, 2),
203
+ listTotalSize = _useState4[0],
204
+ setListTotalSize = _useState4[1]; // 可视区域条数
205
+
206
+
207
+ var _useState5 = useState(0),
208
+ _useState6 = _slicedToArray(_useState5, 2),
209
+ visibleCount = _useState6[0],
210
+ setVisibleCount = _useState6[1];
211
+
212
+ var _useState7 = useState(containerSize || 0),
213
+ _useState8 = _slicedToArray(_useState7, 2),
214
+ offSetSize = _useState8[0],
215
+ setOffSetSize = _useState8[1];
216
+
217
+ var _useState9 = useState({
218
+ startOffset: 0,
219
+ startIndex: 0,
220
+ overStart: 0,
221
+ endIndex: 10 // 可视区域结束索引
222
+
223
+ }),
224
+ _useState10 = _slicedToArray(_useState9, 2),
225
+ options = _useState10[0],
226
+ setOptions = _useState10[1]; // 列表位置信息
227
+
228
+
229
+ useEffect(function () {
230
+ var pos = initPositinoCache(itemSize, sourceData.length);
231
+ setPositions(pos);
232
+ var totalSize = getListTotalSize(pos, horizontal);
233
+ setListTotalSize(totalSize);
234
+ }, [sourceData, itemSize, horizontal]);
235
+ var getElement = useCallback(function () {
236
+ var _scrollRef$current;
237
+
238
+ return ((_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 ? void 0 : _scrollRef$current.parentElement) || document.body;
239
+ }, []);
240
+ useEffect(function () {
241
+ if (containerSize) return;
242
+ var size = horizontal ? getElement().offsetWidth : getElement().offsetHeight;
243
+ setOffSetSize(size);
244
+ }, [getElement, horizontal, containerSize]);
245
+ useEffect(function () {
246
+ // 初始-计算visibleCount
247
+ if (offSetSize === 0) return;
248
+ var count = Math.ceil(offSetSize / itemSize) + overscan;
249
+ setVisibleCount(count);
250
+ setOptions(function (options) {
251
+ return _objectSpread(_objectSpread({}, options), {}, {
252
+ endIndex: count
253
+ });
254
+ });
255
+ }, [getElement, horizontal, itemSize, overscan, offSetSize]);
256
+ var updateTotalSize = useCallback(function () {
257
+ if (!itemsRef.current) return;
258
+ var items = itemsRef.current.children;
259
+ if (!items.length) return; // 更新缓存
260
+
261
+ updateItemSize(positions, items, sizeKey);
262
+ var totalSize = getListTotalSize(positions, horizontal);
263
+ setListTotalSize(totalSize);
264
+ }, [positions, sizeKey, horizontal]);
265
+ var onScroll = useCallback(function () {
266
+ requestAnimationFrame(function (e) {
267
+ var scrollSize = getElement()[scrollKey];
268
+ var startIndex = binarySearch(positions, scrollSize, horizontal);
269
+ var overStart = startIndex - overscan > -1 ? startIndex - overscan : 0; // const offSetSize = horizontal ? getElement().offsetWidth : getElement().offsetHeight
270
+
271
+ if (!itemEqualSize) {
272
+ updateTotalSize();
273
+ }
274
+
275
+ var endIndex = getEndIndex({
276
+ sourceData: sourceData,
277
+ startIndex: startIndex,
278
+ visibleCount: visibleCount,
279
+ itemEqualSize: itemEqualSize,
280
+ positions: positions,
281
+ offSetSize: offSetSize,
282
+ sizeKey: sizeKey,
283
+ overscan: overscan
284
+ });
285
+ var startOffset = positions[startIndex][offsetKey];
286
+ setOptions({
287
+ startOffset: startOffset,
288
+ startIndex: startIndex,
289
+ overStart: overStart,
290
+ endIndex: endIndex
291
+ }); // 无限下滑
292
+
293
+ if (endIndex > sourceData.length - 1) {
294
+ handleScroll && handleScroll();
295
+ }
296
+ });
297
+ }, [positions, getElement, sourceData, visibleCount, itemEqualSize, updateTotalSize, offsetKey, sizeKey, scrollKey, horizontal, overscan, handleScroll, offSetSize]);
298
+ useEffect(function () {
299
+ var element = getElement();
300
+ element.addEventListener('scroll', onScroll, false);
301
+ return function () {
302
+ element.removeEventListener('scroll', onScroll, false);
303
+ };
304
+ }, [getElement, onScroll]);
305
+ return React__default.createElement("div", _objectSpread(_objectSpread({
306
+ className: className ? "".concat(className, " nut-virtualList-box") : 'nut-virtualList-box'
307
+ }, rest), {}, {
308
+ style: _defineProperty({}, sizeKey, containerSize ? "".concat(offSetSize, "px") : '')
309
+ }), React__default.createElement("div", {
310
+ ref: scrollRef,
311
+ className: horizontal ? 'nut-horizontal-box' : 'nut-vertical-box',
312
+ style: _defineProperty({
313
+ position: 'relative'
314
+ }, sizeKey, "".concat(listTotalSize, "px"))
315
+ }, React__default.createElement("ul", {
316
+ className: horizontal ? 'nut-virtuallist-items nut-horizontal-items' : 'nut-virtuallist-items nut-vertical-items',
317
+ ref: itemsRef,
318
+ style: {
319
+ transform: horizontal ? "translate3d(".concat(options.startOffset, "px,0,0)") : "translate3d(0,".concat(options.startOffset, "px,0)")
320
+ }
321
+ }, sourceData.slice(options.overStart, options.endIndex).map(function (data, index) {
322
+ var startIndex = options.startIndex,
323
+ overStart = options.overStart;
324
+ var dataIndex = overStart + index;
325
+ var styleVal = dataIndex < startIndex ? 'none' : 'block';
326
+ var keyVal = key && data[key] ? data[key] : dataIndex;
327
+ return React__default.createElement("li", {
328
+ ref: dataIndex === 0 ? firstItemRef : null,
329
+ "data-index": "".concat(dataIndex),
330
+ className: dataIndex % 2 === 0 ? 'nut-virtuallist-item even' : 'nut-virtuallist-item odd',
331
+ key: "".concat(keyVal),
332
+ style: {
333
+ display: styleVal
334
+ }
335
+ }, ItemRender ? React__default.createElement(ItemRender, {
336
+ data: data,
337
+ index: "".concat(dataIndex)
338
+ }) : data);
339
+ }))));
340
+ };
341
+
342
+ VirtualList.defaultProps = defaultProps;
343
+ VirtualList.displayName = 'NutVirtualList';
344
+ export { VirtualList as default };
@@ -58,6 +58,7 @@ export { default as CollapseItem } from './CollapseItem.js';
58
58
  export { default as AnimatingNumbers } from './AnimatingNumbers.js';
59
59
  export { default as Empty } from './Empty.js';
60
60
  export { default as ConfigProvider } from './ConfigProvider.js';
61
+ export { default as VirtualList } from './VirtualList.js';
61
62
  export { default as Address } from './Address.js';
62
63
  export { default as Barrage } from './Barrage.js';
63
64
  export { default as Signature } from './Signature.js';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v1.1.5-beta.1 Mon Jun 27 2022 19:39:37 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v1.1.5-beta.4 Wed Jul 06 2022 14:29:18 GMT+0800 (China Standard Time)
3
3
  * (c) 2022 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v1.1.5-beta.1 Mon Jun 27 2022 19:39:37 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v1.1.5-beta.4 Wed Jul 06 2022 14:29:18 GMT+0800 (China Standard Time)
3
3
  * (c) 2022 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v1.1.5-beta.1 Mon Jun 27 2022 19:39:37 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v1.1.5-beta.4 Wed Jul 06 2022 14:29:18 GMT+0800 (China Standard Time)
3
3
  * (c) 2022 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v1.1.5-beta.1 Mon Jun 27 2022 19:39:37 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v1.1.5-beta.4 Wed Jul 06 2022 14:29:18 GMT+0800 (China Standard Time)
3
3
  * (c) 2022 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */