@douyinfe/semi-ui 2.25.0 → 2.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66974,7 +66974,9 @@ const overflowList_constants_strings = {
66974
66974
  BOUNDARY_MAP,
66975
66975
  OVERFLOW_DIR
66976
66976
  };
66977
- const overflowList_constants_numbers = {};
66977
+ const overflowList_constants_numbers = {
66978
+ MINIMUM_HTML_ELEMENT_WIDTH: 4
66979
+ };
66978
66980
 
66979
66981
  // EXTERNAL MODULE: /home/runner/work/semi-design/semi-design/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js
66980
66982
  var ResizeObserver_es = __webpack_require__("LaGA");
@@ -67193,6 +67195,13 @@ class foundation_OverflowListFoundation extends foundation {
67193
67195
  } = this.getProps();
67194
67196
  return renderMode === 'scroll';
67195
67197
  };
67198
+
67199
+ this.getReversedItems = () => {
67200
+ const {
67201
+ items
67202
+ } = this.getProps();
67203
+ return cloneDeep_default()(items).reverse();
67204
+ };
67196
67205
  }
67197
67206
 
67198
67207
  getOverflowItem() {
@@ -67261,54 +67270,68 @@ class foundation_OverflowListFoundation extends foundation {
67261
67270
  this._adapter.notifyIntersect(res);
67262
67271
  }
67263
67272
 
67264
- handlePartition(growing) {
67273
+ handleCollapseOverflow() {
67265
67274
  const {
67266
- direction,
67267
- overflow,
67268
- lastOverflowCount,
67269
- visible
67275
+ minVisibleItems,
67276
+ collapseFrom
67277
+ } = this.getProps();
67278
+ const {
67279
+ overflowWidth,
67280
+ containerWidth,
67281
+ pivot: statePivot,
67282
+ overflowStatus
67270
67283
  } = this.getStates();
67271
67284
  const {
67272
- minVisibleItems,
67273
- collapseFrom,
67274
- items
67285
+ items,
67286
+ onOverflow
67275
67287
  } = this.getProps();
67276
- let updateState = {};
67288
+ let itemWidths = overflowWidth,
67289
+ _pivot = 0;
67290
+ let overflowed = false;
67277
67291
 
67278
- if (growing === OverflowDirection.NONE) {
67279
- updateState = {
67280
- direction: OverflowDirection.NONE
67281
- };
67282
- }
67292
+ for (const size of this._adapter.getItemSizeMap().values()) {
67293
+ itemWidths += size; // 触发overflow
67283
67294
 
67284
- if (growing === OverflowDirection.GROW) {
67285
- const updatedOverflowCount = direction === OverflowDirection.NONE ? overflow.length : lastOverflowCount;
67286
- updateState = {
67287
- direction: OverflowDirection.GROW,
67288
- lastOverflowCount: updatedOverflowCount,
67289
- overflow: [],
67290
- visible: items
67291
- };
67292
- }
67295
+ if (itemWidths > containerWidth) {
67296
+ overflowed = true;
67297
+ break;
67298
+ } // 顺利遍历完整个列表,说明不存在overflow,直接渲染全部
67293
67299
 
67294
- if (growing === OverflowDirection.SHRINK && visible.length > minVisibleItems) {
67295
- const collapseFromStart = collapseFrom === Boundary.START;
67296
- const newVisible = visible.slice();
67297
- const next = collapseFromStart ? newVisible.shift() : newVisible.pop();
67298
67300
 
67299
- if (next !== undefined) {
67300
- updateState = {
67301
- // set SHRINK mode unless a GROW is already in progress.
67302
- // GROW shows all items then shrinks until it settles, so we
67303
- // preserve the fact that the original trigger was a GROW.
67304
- direction: direction !== OverflowDirection.GROW ? OverflowDirection.SHRINK : direction,
67305
- overflow: collapseFromStart ? [...overflow, next] : [next, ...overflow],
67306
- visible: newVisible
67307
- };
67301
+ if (_pivot === items.length - 1) {
67302
+ this._adapter.updateStates({
67303
+ overflowStatus: "normal",
67304
+ pivot: items.length - 1,
67305
+ visible: items,
67306
+ overflow: []
67307
+ });
67308
+
67309
+ break;
67308
67310
  }
67311
+
67312
+ _pivot++;
67309
67313
  }
67310
67314
 
67311
- this._adapter.updateStates(updateState);
67315
+ if (overflowed) {
67316
+ const pivot = Math.max(minVisibleItems, _pivot);
67317
+ const isCollapseFromStart = collapseFrom === Boundary.START;
67318
+ const visible = isCollapseFromStart ? this.getReversedItems().slice(0, pivot).reverse() : items.slice(0, pivot);
67319
+ const overflow = isCollapseFromStart ? this.getReversedItems().slice(pivot).reverse() : items.slice(pivot);
67320
+
67321
+ this._adapter.updateStates({
67322
+ overflowStatus: "overflowed",
67323
+ pivot: pivot,
67324
+ visible,
67325
+ overflow
67326
+ }); // trigger onOverflow
67327
+
67328
+
67329
+ if (statePivot !== pivot) {
67330
+ onOverflow(overflow);
67331
+ }
67332
+
67333
+ return;
67334
+ }
67312
67335
  }
67313
67336
 
67314
67337
  }
@@ -67322,7 +67345,6 @@ var overflowList = __webpack_require__("O1Tx");
67322
67345
 
67323
67346
 
67324
67347
 
67325
-
67326
67348
  /* eslint-disable arrow-body-style */
67327
67349
 
67328
67350
 
@@ -67356,26 +67378,15 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67356
67378
 
67357
67379
  this.resize = function () {
67358
67380
  let entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
67359
- // if any parent is growing, assume we have more room than before
67360
- const growing = entries.some(entry => {
67361
- const previousWidth = _this.previousWidths.get(entry.target) || 0;
67362
- return entry.contentRect.width > previousWidth;
67363
- });
67364
67381
 
67365
- _this.repartition(growing);
67366
-
67367
- entries.forEach(entry => _this.previousWidths.set(entry.target, entry.contentRect.width));
67368
- };
67369
-
67370
- this.repartition = growing => {
67371
- // if not mounted or scroll mode, we do not
67372
- if (isNull_default()(this.spacer) || isUndefined_default()(this.spacer) || this.isScrollMode()) {
67373
- return;
67374
- } // spacer has flex-shrink and width 1px so if it's much smaller then we know to shrink
67382
+ var _a;
67375
67383
 
67384
+ const containerWidth = (_a = entries[0]) === null || _a === void 0 ? void 0 : _a.target.clientWidth;
67376
67385
 
67377
- const state = growing ? overflowList_OverflowDirection.GROW : this.spacer.getBoundingClientRect().width < 0.9 ? overflowList_OverflowDirection.SHRINK : overflowList_OverflowDirection.NONE;
67378
- this.foundation.handlePartition(state);
67386
+ _this.setState({
67387
+ containerWidth,
67388
+ overflowStatus: 'calculating'
67389
+ });
67379
67390
  };
67380
67391
 
67381
67392
  this.reintersect = entries => {
@@ -67397,6 +67408,18 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67397
67408
  return this.props.overflowRenderer(overflow);
67398
67409
  };
67399
67410
 
67411
+ this.getItemKey = (item, defalutKey) => {
67412
+ const {
67413
+ itemKey
67414
+ } = this.props;
67415
+
67416
+ if (isFunction_default()(itemKey)) {
67417
+ return itemKey(item);
67418
+ }
67419
+
67420
+ return get_default()(item, itemKey || 'key', defalutKey);
67421
+ };
67422
+
67400
67423
  this.renderItemList = () => {
67401
67424
  const {
67402
67425
  className,
@@ -67408,9 +67431,32 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67408
67431
  collapseFrom
67409
67432
  } = this.props;
67410
67433
  const {
67411
- visible
67434
+ visible,
67435
+ overflowStatus
67412
67436
  } = this.state;
67413
- const overflow = this.renderOverflow();
67437
+ let overflow = this.renderOverflow();
67438
+
67439
+ if (!this.isScrollMode()) {
67440
+ if (Array.isArray(overflow)) {
67441
+ overflow = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement(external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.Fragment, null, overflow);
67442
+ }
67443
+
67444
+ if ( /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.isValidElement(overflow)) {
67445
+ const child = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.cloneElement(overflow);
67446
+ overflow = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement(resizeObserver_ReactResizeObserver, {
67447
+ onResize: _ref => {
67448
+ let [entry] = _ref;
67449
+ this.setState({
67450
+ overflowWidth: entry.target.clientWidth,
67451
+ overflowStatus: 'calculating'
67452
+ });
67453
+ }
67454
+ }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", {
67455
+ className: "".concat(overflowList_prefixCls, "-overflow")
67456
+ }, child));
67457
+ }
67458
+ }
67459
+
67414
67460
  const inner = renderMode === RenderMode.SCROLL ? [overflow[0], /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", {
67415
67461
  className: classnames_default()(wrapperClassName, "".concat(overflowList_prefixCls, "-scroll-wrapper")),
67416
67462
  ref: ref => {
@@ -67418,7 +67464,7 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67418
67464
  },
67419
67465
  style: Object.assign({}, wrapperStyle),
67420
67466
  key: "".concat(overflowList_prefixCls, "-scroll-wrapper")
67421
- }, visible.map(visibleItemRenderer).map((item, ind) => {
67467
+ }, visible.map(visibleItemRenderer).map(item => {
67422
67468
  const {
67423
67469
  forwardRef,
67424
67470
  key
@@ -67428,24 +67474,71 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67428
67474
  'data-scrollkey': "".concat(key),
67429
67475
  key
67430
67476
  });
67431
- })), overflow[1]] : [collapseFrom === overflowList_Boundary.START ? overflow : null, visible.map(visibleItemRenderer), collapseFrom === overflowList_Boundary.END ? overflow : null, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", {
67432
- className: "".concat(overflowList_prefixCls, "-spacer"),
67433
- ref: ref => this.spacer = ref,
67434
- key: "".concat(overflowList_prefixCls, "-spacer")
67435
- })];
67477
+ })), overflow[1]] : [collapseFrom === overflowList_Boundary.START ? overflow : null, visible.map((item, idx) => {
67478
+ const {
67479
+ key
67480
+ } = item;
67481
+ const element = visibleItemRenderer(item, idx);
67482
+ const child = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.cloneElement(element);
67483
+ return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement(resizeObserver_ReactResizeObserver, {
67484
+ key: key,
67485
+ onResize: _ref2 => {
67486
+ let [entry] = _ref2;
67487
+ return this.onItemResize(entry, item, idx);
67488
+ }
67489
+ }, /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", {
67490
+ key: key,
67491
+ className: "".concat(overflowList_prefixCls, "-item")
67492
+ }, child));
67493
+ }), collapseFrom === overflowList_Boundary.END ? overflow : null];
67436
67494
  const list = /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement('div', {
67437
67495
  className: classnames_default()("".concat(overflowList_prefixCls), className),
67438
- style
67496
+ style: Object.assign(Object.assign({}, style), renderMode === RenderMode.COLLAPSE ? {
67497
+ maxWidth: '100%',
67498
+ visibility: overflowStatus === "calculating" ? "hidden" : "visible"
67499
+ } : null)
67439
67500
  }, ...inner);
67440
67501
  return list;
67441
67502
  };
67442
67503
 
67504
+ this.onItemResize = (entry, item, idx) => {
67505
+ const key = this.getItemKey(item, idx);
67506
+ const width = this.itemSizeMap.get(key);
67507
+
67508
+ if (!width) {
67509
+ this.itemSizeMap.set(key, entry.target.clientWidth);
67510
+ } else if (width !== entry.target.clientWidth) {
67511
+ // 某个item发生resize后,重新计算
67512
+ this.itemSizeMap.set(key, entry.target.clientWidth);
67513
+ this.setState({
67514
+ overflowStatus: 'calculating'
67515
+ });
67516
+ }
67517
+
67518
+ const {
67519
+ maxCount
67520
+ } = this.state; // 已经按照最大值maxCount渲染完毕,触发真正的渲染。(-1 是overflow部分会占1)
67521
+ // Already rendered maxCount items, trigger the real rendering. (-1 for the overflow part)
67522
+
67523
+ if (this.itemSizeMap.size === maxCount - 1) {
67524
+ this.setState({
67525
+ overflowStatus: 'calculating'
67526
+ });
67527
+ }
67528
+ };
67529
+
67443
67530
  this.state = {
67444
67531
  direction: overflowList_OverflowDirection.GROW,
67445
67532
  lastOverflowCount: 0,
67446
67533
  overflow: [],
67447
- visible: props.items,
67448
- visibleState: new Map()
67534
+ visible: [],
67535
+ containerWidth: 0,
67536
+ visibleState: new Map(),
67537
+ itemSizeMap: new Map(),
67538
+ overflowStatus: "calculating",
67539
+ pivot: 0,
67540
+ overflowWidth: 0,
67541
+ maxCount: 0
67449
67542
  };
67450
67543
  this.foundation = new overflowList_foundation(this.adapter);
67451
67544
  this.previousWidths = new Map();
@@ -67468,8 +67561,18 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67468
67561
  // reset visible state if the above props change.
67469
67562
  newState.direction = overflowList_OverflowDirection.GROW;
67470
67563
  newState.lastOverflowCount = 0;
67471
- newState.overflow = [];
67472
- newState.visible = props.items;
67564
+
67565
+ if (props.renderMode === RenderMode.SCROLL) {
67566
+ newState.visible = props.items;
67567
+ newState.overflow = [];
67568
+ } else {
67569
+ newState.visible = [];
67570
+ newState.overflow = [];
67571
+ }
67572
+
67573
+ newState.pivot = 0;
67574
+ newState.maxCount = 0;
67575
+ newState.overflowStatus = "calculating";
67473
67576
  }
67474
67577
 
67475
67578
  return newState;
@@ -67487,45 +67590,45 @@ class overflowList_OverflowList extends baseComponent_BaseComponent {
67487
67590
  },
67488
67591
  notifyIntersect: res => {
67489
67592
  this.props.onIntersect && this.props.onIntersect(res);
67490
- }
67593
+ },
67594
+ getItemSizeMap: () => this.itemSizeMap
67491
67595
  });
67492
67596
  }
67493
67597
 
67494
- componentDidMount() {
67495
- this.repartition(false);
67496
- }
67497
-
67498
- shouldComponentUpdate(_nextProps, nextState) {
67499
- // We want this component to always re-render, even when props haven't changed, so that
67500
- // changes in the renderers' behavior can be reflected.
67501
- // The following statement prevents re-rendering only in the case where the state changes
67502
- // identity (i.e. setState was called), but the state is still the same when
67503
- // shallow-compared to the previous state.
67504
- const currState = omit_default()(this.state, 'prevProps');
67505
-
67506
- const comingState = omit_default()(nextState, 'prevProps');
67507
-
67508
- return !(currState !== comingState && isEqual_default()(currState, comingState));
67509
- }
67510
-
67511
67598
  componentDidUpdate(prevProps, prevState) {
67512
67599
  if (!isEqual_default()(prevProps.items, this.props.items)) {
67513
67600
  this.itemRefs = {};
67514
67601
  }
67515
67602
 
67516
- if (!isEqual_default()(omit_default()(prevState, 'prevProps'), omit_default()(this.state, 'prevProps'))) {
67517
- this.repartition(false);
67518
- }
67519
-
67520
67603
  const {
67521
- direction,
67522
67604
  overflow,
67523
- lastOverflowCount
67605
+ containerWidth,
67606
+ visible,
67607
+ overflowStatus
67524
67608
  } = this.state;
67525
67609
 
67526
- if ( // if a resize operation has just completed (transition to NONE)
67527
- direction === overflowList_OverflowDirection.NONE && direction !== prevState.direction && overflow.length !== lastOverflowCount) {
67528
- this.props.onOverflow && this.props.onOverflow(overflow);
67610
+ if (this.isScrollMode() || overflowStatus !== "calculating") {
67611
+ return;
67612
+ }
67613
+
67614
+ if (visible.length === 0 && overflow.length === 0 && this.props.items.length !== 0) {
67615
+ // 推测container最多能渲染的数量
67616
+ // Figure out the maximum number of items in this container
67617
+ const maxCount = Math.min(this.props.items.length, Math.floor(containerWidth / overflowList_constants_numbers.MINIMUM_HTML_ELEMENT_WIDTH)); // 如果collapseFrom是start, 第一次用来计算容量时,倒转列表顺序渲染
67618
+ // If collapseFrom === start, render item from end to start. Figuring out how many items in the end could fit in container.
67619
+
67620
+ const isCollapseFromStart = this.props.collapseFrom === overflowList_Boundary.START;
67621
+ const visible = isCollapseFromStart ? this.foundation.getReversedItems().slice(0, maxCount) : this.props.items.slice(0, maxCount);
67622
+ const overflow = isCollapseFromStart ? this.foundation.getReversedItems().slice(maxCount) : this.props.items.slice(maxCount);
67623
+ this.setState({
67624
+ overflowStatus: 'calculating',
67625
+ visible,
67626
+ overflow,
67627
+ maxCount: maxCount
67628
+ });
67629
+ this.itemSizeMap.clear();
67630
+ } else {
67631
+ this.foundation.handleCollapseOverflow();
67529
67632
  }
67530
67633
  }
67531
67634
 
@@ -67557,7 +67660,8 @@ overflowList_OverflowList.defaultProps = {
67557
67660
  overflowRenderer: () => null,
67558
67661
  renderMode: 'collapse',
67559
67662
  threshold: 0.75,
67560
- visibleItemRenderer: () => null
67663
+ visibleItemRenderer: () => null,
67664
+ onOverflow: () => null
67561
67665
  };
67562
67666
  overflowList_OverflowList.propTypes = {
67563
67667
  // if render in scroll mode, key is required in items
@@ -72536,7 +72640,8 @@ class select_Select extends baseComponent_BaseComponent {
72536
72640
  innerBottomSlot,
72537
72641
  loading,
72538
72642
  virtualize,
72539
- multiple
72643
+ multiple,
72644
+ emptyContent
72540
72645
  } = this.props; // Do a filter first, instead of directly judging in forEach, so that the focusIndex can correspond to
72541
72646
 
72542
72647
  const visibleOptions = options.filter(item => item._show);
@@ -72559,7 +72664,11 @@ class select_Select extends baseComponent_BaseComponent {
72559
72664
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
72560
72665
  external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", {
72561
72666
  id: "".concat(select_prefixcls, "-").concat(this.selectOptionListID),
72562
- className: classnames_default()("".concat(select_prefixcls, "-option-list-wrapper"), dropdownClassName),
72667
+ className: classnames_default()({
72668
+ // When emptyContent is null and the option is empty, there is no need for the drop-down option for the user,
72669
+ // so there is no need to set padding through this className
72670
+ ["".concat(select_prefixcls, "-option-list-wrapper")]: !(isEmpty && emptyContent === null)
72671
+ }, dropdownClassName),
72563
72672
  style: style,
72564
72673
  ref: this.setOptionContainerEl,
72565
72674
  onKeyDown: e => this.foundation.handleContainerKeyDown(e)