@douyinfe/semi-ui 2.49.1 → 2.49.2

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.
@@ -59010,11 +59010,7 @@ class YearAndMonth extends BaseComponent {
59010
59010
  const right = datePicker_constants_strings.PANEL_TYPE_RIGHT;
59011
59011
  const needDisabled = year => {
59012
59012
  if (panelType === right && currentYear[left]) {
59013
- if (currentMonth[left] <= currentMonth[right]) {
59014
- return currentYear[left] > year;
59015
- } else {
59016
- return currentYear[left] >= year;
59017
- }
59013
+ return currentYear[left] > year;
59018
59014
  }
59019
59015
  return false;
59020
59016
  };
@@ -68036,6 +68032,7 @@ class NotificationList extends BaseComponent {
68036
68032
  }
68037
68033
  static addNotice(notice) {
68038
68034
  var _a;
68035
+ notice = Object.assign(Object.assign({}, notification_defaultConfig), notice);
68039
68036
  const id = (_a = notice.id) !== null && _a !== void 0 ? _a : getUuid('notification');
68040
68037
  if (!ref) {
68041
68038
  const {
@@ -68079,27 +68076,27 @@ class NotificationList extends BaseComponent {
68079
68076
  return id;
68080
68077
  }
68081
68078
  static info(opts) {
68082
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68079
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68083
68080
  type: 'info'
68084
68081
  }));
68085
68082
  }
68086
68083
  static success(opts) {
68087
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68084
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68088
68085
  type: 'success'
68089
68086
  }));
68090
68087
  }
68091
68088
  static error(opts) {
68092
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68089
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68093
68090
  type: 'error'
68094
68091
  }));
68095
68092
  }
68096
68093
  static warning(opts) {
68097
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68094
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68098
68095
  type: 'warning'
68099
68096
  }));
68100
68097
  }
68101
68098
  static open(opts) {
68102
- return this.addNotice(Object.assign(Object.assign(Object.assign({}, notification_defaultConfig), opts), {
68099
+ return this.addNotice(Object.assign(Object.assign({}, opts), {
68103
68100
  type: 'default'
68104
68101
  }));
68105
68102
  }
@@ -69374,6 +69371,9 @@ class SelectFoundation extends foundation {
69374
69371
  const newOptions = this._filterOption(options, sugInput).filter(item => !item._inputCreateOnly);
69375
69372
  this._adapter.updateOptions(newOptions);
69376
69373
  this.toggle2SearchInput(true);
69374
+ } else {
69375
+ // whether it is a filter or not, isFocus is guaranteed to be true when open
69376
+ this._adapter.updateFocusState(true);
69377
69377
  }
69378
69378
  this._adapter.openMenu();
69379
69379
  this._setDropdownWidth();
@@ -69383,7 +69383,6 @@ class SelectFoundation extends foundation {
69383
69383
  this.close(e);
69384
69384
  this._notifyBlur(e);
69385
69385
  this._adapter.updateFocusState(false);
69386
- this._adapter.unregisterClickOutsideHandler();
69387
69386
  });
69388
69387
  }
69389
69388
  toggle2SearchInput(isShow) {
@@ -69402,6 +69401,7 @@ class SelectFoundation extends foundation {
69402
69401
  // this.unBindKeyBoardEvent();
69403
69402
  // this._notifyBlur(e);
69404
69403
  // this._adapter.updateFocusState(false);
69404
+ this._adapter.unregisterClickOutsideHandler();
69405
69405
  const isFilterable = this._isFilterable();
69406
69406
  if (isFilterable) {
69407
69407
  this.toggle2SearchInput(false);
@@ -70088,7 +70088,6 @@ class SelectFoundation extends foundation {
70088
70088
  this._adapter.setIsFocusInContainer(false);
70089
70089
  }
70090
70090
  handleTriggerBlur(e) {
70091
- this._adapter.updateFocusState(false);
70092
70091
  const {
70093
70092
  filter,
70094
70093
  autoFocus
@@ -70101,6 +70100,7 @@ class SelectFoundation extends foundation {
70101
70100
  // But when autoFocus or the panel is close, because clickOutsideHandler is not register or unregister, you need to listen for the trigger's blur and trigger the notify callback
70102
70101
  if (isFocus && !isOpen) {
70103
70102
  this._notifyBlur(e);
70103
+ this._adapter.updateFocusState(false);
70104
70104
  }
70105
70105
  }
70106
70106
  handleInputBlur(e) {
@@ -89631,6 +89631,12 @@ class TreeSelectFoundation extends foundation {
89631
89631
  this.close(e);
89632
89632
  });
89633
89633
  };
89634
+ this.clearInputValue = () => {
89635
+ const {
89636
+ inputValue
89637
+ } = this.getStates();
89638
+ inputValue && this._adapter.updateInputValue('');
89639
+ };
89634
89640
  }
89635
89641
  init() {
89636
89642
  const {
@@ -89782,7 +89788,7 @@ class TreeSelectFoundation extends foundation {
89782
89788
  const isSearching = Boolean(inputValue);
89783
89789
  const treeNodeProps = {
89784
89790
  eventKey: key,
89785
- expanded: isSearching && !this._isExpandControlled() ? filteredExpandedKeys.has(key) : expandedKeys.has(key),
89791
+ expanded: isSearching ? filteredExpandedKeys.has(key) : expandedKeys.has(key),
89786
89792
  selected: selectedKeys.includes(key),
89787
89793
  checked: realChecked,
89788
89794
  halfChecked: realHalfChecked,
@@ -90055,8 +90061,8 @@ class TreeSelectFoundation extends foundation {
90055
90061
  expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
90056
90062
  const newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
90057
90063
  this._adapter.updateState({
90058
- expandedKeys: isExpandControlled ? expandedKeys : newExpandedKeys,
90059
- flattenNodes: isExpandControlled ? flattenNodes : newFlattenNodes,
90064
+ expandedKeys: newExpandedKeys,
90065
+ flattenNodes: newFlattenNodes,
90060
90066
  inputValue: '',
90061
90067
  motionKeys: new Set([]),
90062
90068
  filteredKeys: new Set([]),
@@ -90105,8 +90111,8 @@ class TreeSelectFoundation extends foundation {
90105
90111
  const newFilteredExpandedKeys = new Set(expandedOptsKeys);
90106
90112
  this._adapter.notifySearch(sugInput, Array.from(newFilteredExpandedKeys));
90107
90113
  this._adapter.updateState({
90108
- expandedKeys: this._isExpandControlled() ? expandedKeys : newExpandedKeys,
90109
- flattenNodes: this._isExpandControlled() ? flattenNodes : newFlattenNodes,
90114
+ expandedKeys: newExpandedKeys,
90115
+ flattenNodes: newFlattenNodes,
90110
90116
  motionKeys: new Set([]),
90111
90117
  filteredKeys: new Set(filteredOptsKeys),
90112
90118
  filteredExpandedKeys: newFilteredExpandedKeys,
@@ -90314,7 +90320,7 @@ class TreeSelectFoundation extends foundation {
90314
90320
  return;
90315
90321
  }
90316
90322
  const isExpandControlled = this._isExpandControlled();
90317
- if (isSearching && !isExpandControlled) {
90323
+ if (isSearching) {
90318
90324
  this.handleNodeExpandInSearch(e, treeNode);
90319
90325
  return;
90320
90326
  }
@@ -91084,13 +91090,27 @@ class TreeSelect extends BaseComponent {
91084
91090
  searchAutoFocus,
91085
91091
  searchPosition
91086
91092
  } = this.props;
91087
- if (isVisible === false && Boolean(filterTreeNode)) {
91088
- this.foundation.clearInput();
91093
+ // inputValue 清空,如果有选中值的话,选中项能够快速回显
91094
+ // Clear the inputValue. If there is a selected value, the selected item can be quickly echoed.
91095
+ if (isVisible === false && filterTreeNode) {
91096
+ this.foundation.clearInputValue();
91089
91097
  }
91090
91098
  if (filterTreeNode && searchPosition === treeSelect_constants_strings.SEARCH_POSITION_DROPDOWN && isVisible && searchAutoFocus) {
91091
91099
  this.foundation.focusInput(true);
91092
91100
  }
91093
91101
  };
91102
+ this.afterClose = () => {
91103
+ // flattenNode 的变化将导致弹出层面板中的选项数目变化
91104
+ // 在弹层完全收起之后,再通过 clearInput 重新计算 state 中的 expandedKey, flattenNode
91105
+ // 防止在弹出层未收起时弹层面板中选项数目变化导致视觉上出现弹层闪动问题
91106
+ // Changes to flattenNode will cause the number of options in the popup panel to change
91107
+ // After the pop-up layer is completely closed, recalculate the expandedKey and flattenNode in the state through clearInput.
91108
+ // Prevent the pop-up layer from flickering visually due to changes in the number of options in the pop-up panel when the pop-up layer is not collapsed.
91109
+ const {
91110
+ filterTreeNode
91111
+ } = this.props;
91112
+ filterTreeNode && this.foundation.clearInput();
91113
+ };
91094
91114
  this.renderTreeNode = (treeNode, ind, style) => {
91095
91115
  const {
91096
91116
  data,
@@ -91123,6 +91143,7 @@ class TreeSelect extends BaseComponent {
91123
91143
  this.renderNodeList = () => {
91124
91144
  const {
91125
91145
  flattenNodes,
91146
+ cachedFlattenNodes,
91126
91147
  motionKeys,
91127
91148
  motionType,
91128
91149
  filteredKeys
@@ -91138,7 +91159,7 @@ class TreeSelect extends BaseComponent {
91138
91159
  if (!virtualize || isEmpty_default()(virtualize)) {
91139
91160
  return /*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement(NodeList, {
91140
91161
  flattenNodes: flattenNodes,
91141
- flattenList: this._flattenNodes,
91162
+ flattenList: cachedFlattenNodes,
91142
91163
  motionKeys: motionExpand ? motionKeys : new Set([]),
91143
91164
  motionType: motionType,
91144
91165
  // When motionKeys is empty, but filteredKeys is not empty (that is, the search hits), this situation should be distinguished from ordinary motionKeys
@@ -91257,6 +91278,7 @@ class TreeSelect extends BaseComponent {
91257
91278
  keyEntities: {},
91258
91279
  treeData: [],
91259
91280
  flattenNodes: [],
91281
+ cachedFlattenNodes: undefined,
91260
91282
  selectedKeys: [],
91261
91283
  checkedKeys: new Set(),
91262
91284
  halfCheckedKeys: new Set(),
@@ -91286,6 +91308,7 @@ class TreeSelect extends BaseComponent {
91286
91308
  };
91287
91309
  }
91288
91310
  static getDerivedStateFromProps(props, prevState) {
91311
+ var _a;
91289
91312
  const {
91290
91313
  prevProps,
91291
91314
  rePosKey
@@ -91303,6 +91326,8 @@ class TreeSelect extends BaseComponent {
91303
91326
  };
91304
91327
  const needUpdateTreeData = needUpdate('treeData');
91305
91328
  const needUpdateExpandedKeys = needUpdate('expandedKeys');
91329
+ const isExpandControlled = ('expandedKeys' in props);
91330
+ const isSearching = Boolean(props.filterTreeNode && prevState.inputValue && prevState.inputValue.length);
91306
91331
  // TreeNode
91307
91332
  if (needUpdateTreeData) {
91308
91333
  treeData = props.treeData;
@@ -91321,31 +91346,97 @@ class TreeSelect extends BaseComponent {
91321
91346
  }
91322
91347
  }
91323
91348
  const expandAllWhenDataChange = needUpdateTreeData && props.expandAll;
91324
- // expandedKeys
91325
- if (needUpdateExpandedKeys || prevProps && needUpdate('autoExpandParent')) {
91326
- newState.expandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
91327
- // only show animation when treeData does not change
91328
- if (prevProps && props.motion && !treeData) {
91329
- const {
91330
- motionKeys,
91331
- motionType
91332
- } = calcMotionKeys(prevState.expandedKeys, newState.expandedKeys, keyEntities);
91333
- newState.motionKeys = new Set(motionKeys);
91334
- newState.motionType = motionType;
91335
- }
91336
- } else if (!prevProps && (props.defaultExpandAll || props.expandAll) || expandAllWhenDataChange) {
91337
- newState.expandedKeys = new Set(Object.keys(keyEntities));
91338
- } else if (!prevProps && props.defaultExpandedKeys) {
91339
- newState.expandedKeys = calcExpandedKeys(props.defaultExpandedKeys, keyEntities);
91340
- } else if (!prevProps && props.defaultValue) {
91341
- newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.defaultValue, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91342
- } else if (!prevProps && props.value) {
91343
- newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.value, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91344
- }
91345
- // flattenNodes
91346
- if (treeData || needUpdateExpandedKeys) {
91347
- const flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.expandedKeys || prevState.expandedKeys, keyMaps);
91348
- newState.flattenNodes = flattenNodes;
91349
+ if (!isSearching) {
91350
+ // expandedKeys
91351
+ if (needUpdateExpandedKeys || prevProps && needUpdate('autoExpandParent')) {
91352
+ newState.expandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
91353
+ // only show animation when treeData does not change
91354
+ if (prevProps && props.motion && !treeData) {
91355
+ const {
91356
+ motionKeys,
91357
+ motionType
91358
+ } = calcMotionKeys(prevState.expandedKeys, newState.expandedKeys, keyEntities);
91359
+ newState.motionKeys = new Set(motionKeys);
91360
+ newState.motionType = motionType;
91361
+ if (motionType === 'hide') {
91362
+ // cache flatten nodes: expandedKeys changed may not be triggered by interaction
91363
+ newState.cachedFlattenNodes = treeUtil_cloneDeep(prevState.flattenNodes);
91364
+ }
91365
+ }
91366
+ } else if (!prevProps && (props.defaultExpandAll || props.expandAll) || expandAllWhenDataChange) {
91367
+ newState.expandedKeys = new Set(Object.keys(keyEntities));
91368
+ } else if (!prevProps && props.defaultExpandedKeys) {
91369
+ newState.expandedKeys = calcExpandedKeys(props.defaultExpandedKeys, keyEntities);
91370
+ } else if (!prevProps && props.defaultValue) {
91371
+ newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.defaultValue, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91372
+ } else if (!prevProps && props.value) {
91373
+ newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.value, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
91374
+ } else if (!isExpandControlled && needUpdateTreeData && props.value) {
91375
+ // 当 treeData 已经设置具体的值,并且设置了 props.loadData ,则认为 treeData 的更新是因为 loadData 导致的
91376
+ // 如果是因为 loadData 导致 treeData改变, 此时在这里重新计算 key 会导致为未选中的展开项目被收起
91377
+ // 所以此时不需要重新计算 expandedKeys,因为在点击展开按钮时候已经把被展开的项添加到 expandedKeys 中
91378
+ // When treeData has a specific value and props.loadData is set, it is considered that the update of treeData is caused by loadData
91379
+ // If the treeData is changed because of loadData, recalculating the key here will cause the unselected expanded items to be collapsed
91380
+ // So there is no need to recalculate expandedKeys at this time, because the expanded item has been added to expandedKeys when the expand button is clicked
91381
+ if (!(prevState.treeData && ((_a = prevState.treeData) === null || _a === void 0 ? void 0 : _a.length) > 0 && props.loadData)) {
91382
+ newState.expandedKeys = calcExpandedKeysForValues(props.value, keyEntities, props.multiple, valueEntities);
91383
+ }
91384
+ }
91385
+ if (!newState.expandedKeys) {
91386
+ delete newState.expandedKeys;
91387
+ }
91388
+ if (treeData || newState.expandedKeys) {
91389
+ const flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.expandedKeys || prevState.expandedKeys, keyMaps);
91390
+ newState.flattenNodes = flattenNodes;
91391
+ }
91392
+ } else {
91393
+ let filteredState;
91394
+ // treeData changed while searching
91395
+ if (treeData) {
91396
+ // Get filter data
91397
+ filteredState = filterTreeData({
91398
+ treeData,
91399
+ inputValue: prevState.inputValue,
91400
+ filterTreeNode: props.filterTreeNode,
91401
+ filterProps: props.treeNodeFilterProp,
91402
+ showFilteredOnly: props.showFilteredOnly,
91403
+ keyEntities: newState.keyEntities,
91404
+ prevExpandedKeys: [...prevState.filteredExpandedKeys],
91405
+ keyMaps: keyMaps
91406
+ });
91407
+ newState.flattenNodes = filteredState.flattenNodes;
91408
+ newState.motionKeys = new Set([]);
91409
+ newState.filteredKeys = filteredState.filteredKeys;
91410
+ newState.filteredShownKeys = filteredState.filteredShownKeys;
91411
+ newState.filteredExpandedKeys = filteredState.filteredExpandedKeys;
91412
+ }
91413
+ // expandedKeys changed while searching
91414
+ if (props.expandedKeys) {
91415
+ newState.filteredExpandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
91416
+ if (prevProps && props.motion) {
91417
+ const prevKeys = prevState ? prevState.filteredExpandedKeys : new Set([]);
91418
+ // only show animation when treeData does not change
91419
+ if (!treeData) {
91420
+ const motionResult = calcMotionKeys(prevKeys, newState.filteredExpandedKeys, keyEntities);
91421
+ let {
91422
+ motionKeys
91423
+ } = motionResult;
91424
+ const {
91425
+ motionType
91426
+ } = motionResult;
91427
+ if (props.showFilteredOnly) {
91428
+ motionKeys = motionKeys.filter(key => prevState.filteredShownKeys.has(key));
91429
+ }
91430
+ if (motionType === 'hide') {
91431
+ // cache flatten nodes: expandedKeys changed may not be triggered by interaction
91432
+ newState.cachedFlattenNodes = treeUtil_cloneDeep(prevState.flattenNodes);
91433
+ }
91434
+ newState.motionKeys = new Set(motionKeys);
91435
+ newState.motionType = motionType;
91436
+ }
91437
+ }
91438
+ newState.flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.filteredExpandedKeys || prevState.filteredExpandedKeys, keyMaps, props.showFilteredOnly && prevState.filteredShownKeys);
91439
+ }
91349
91440
  }
91350
91441
  // selectedKeys: single mode controlled
91351
91442
  const isMultiple = props.multiple;
@@ -91452,7 +91543,9 @@ class TreeSelect extends BaseComponent {
91452
91543
  this.props.onSearch && this.props.onSearch(input, filteredExpandedKeys);
91453
91544
  },
91454
91545
  cacheFlattenNodes: bool => {
91455
- this._flattenNodes = bool ? treeUtil_cloneDeep(this.state.flattenNodes) : null;
91546
+ this.setState({
91547
+ cachedFlattenNodes: bool ? treeUtil_cloneDeep(this.state.flattenNodes) : undefined
91548
+ });
91456
91549
  },
91457
91550
  notifyLoad: (newLoadedKeys, data) => {
91458
91551
  const {
@@ -91597,7 +91690,8 @@ class TreeSelect extends BaseComponent {
91597
91690
  autoAdjustOverflow: autoAdjustOverflow,
91598
91691
  mouseLeaveDelay: mouseLeaveDelay,
91599
91692
  mouseEnterDelay: mouseEnterDelay,
91600
- onVisibleChange: this.handlePopoverClose
91693
+ onVisibleChange: this.handlePopoverClose,
91694
+ afterClose: this.afterClose
91601
91695
  }, selection);
91602
91696
  }
91603
91697
  }