@douyinfe/semi-ui 2.48.0-alpha.0 → 2.48.0

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.
@@ -20,7 +20,7 @@ import ReactDOM from 'react-dom';
20
20
  import cls from 'classnames';
21
21
  import PropTypes from 'prop-types';
22
22
  import TreeSelectFoundation from '@douyinfe/semi-foundation/lib/es/treeSelect/foundation';
23
- import { convertDataToEntities, flattenTreeData, calcExpandedKeysForValues, calcMotionKeys, findKeysForValues, calcCheckedKeys, calcExpandedKeys, getValueOrKey, normalizeKeyList, calcDisabledKeys, normalizeValue, updateKeys, filterTreeData } from '@douyinfe/semi-foundation/lib/es/tree/treeUtil';
23
+ import { convertDataToEntities, flattenTreeData, calcExpandedKeysForValues, calcMotionKeys, findKeysForValues, calcCheckedKeys, calcExpandedKeys, getValueOrKey, normalizeKeyList, calcDisabledKeys, normalizeValue, updateKeys } from '@douyinfe/semi-foundation/lib/es/tree/treeUtil';
24
24
  import { cssClasses, strings } from '@douyinfe/semi-foundation/lib/es/treeSelect/constants';
25
25
  import { numbers as popoverNumbers } from '@douyinfe/semi-foundation/lib/es/popover/constants';
26
26
  import { FixedSizeList as VirtualList } from 'react-window';
@@ -680,27 +680,13 @@ class TreeSelect extends BaseComponent {
680
680
  searchAutoFocus,
681
681
  searchPosition
682
682
  } = this.props;
683
- // inputValue 清空,如果有选中值的话,选中项能够快速回显
684
- // Clear the inputValue. If there is a selected value, the selected item can be quickly echoed.
685
- if (isVisible === false && filterTreeNode) {
686
- this.foundation.clearInputValue();
683
+ if (isVisible === false && Boolean(filterTreeNode)) {
684
+ this.foundation.clearInput();
687
685
  }
688
686
  if (filterTreeNode && searchPosition === strings.SEARCH_POSITION_DROPDOWN && isVisible && searchAutoFocus) {
689
687
  this.foundation.focusInput(true);
690
688
  }
691
689
  };
692
- this.afterClose = () => {
693
- // flattenNode 的变化将导致弹出层面板中的选项数目变化
694
- // 在弹层完全收起之后,再通过 clearInput 重新计算 state 中的 expandedKey, flattenNode
695
- // 防止在弹出层未收起时弹层面板中选项数目变化导致视觉上出现弹层闪动问题
696
- // Changes to flattenNode will cause the number of options in the popup panel to change
697
- // After the pop-up layer is completely closed, recalculate the expandedKey and flattenNode in the state through clearInput.
698
- // 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.
699
- const {
700
- filterTreeNode
701
- } = this.props;
702
- filterTreeNode && this.foundation.clearInput();
703
- };
704
690
  this.renderTreeNode = (treeNode, ind, style) => {
705
691
  const {
706
692
  data,
@@ -733,7 +719,6 @@ class TreeSelect extends BaseComponent {
733
719
  this.renderNodeList = () => {
734
720
  const {
735
721
  flattenNodes,
736
- cachedFlattenNodes,
737
722
  motionKeys,
738
723
  motionType,
739
724
  filteredKeys
@@ -749,7 +734,7 @@ class TreeSelect extends BaseComponent {
749
734
  if (!virtualize || _isEmpty(virtualize)) {
750
735
  return /*#__PURE__*/React.createElement(NodeList, {
751
736
  flattenNodes: flattenNodes,
752
- flattenList: cachedFlattenNodes,
737
+ flattenList: this._flattenNodes,
753
738
  motionKeys: motionExpand ? motionKeys : new Set([]),
754
739
  motionType: motionType,
755
740
  // When motionKeys is empty, but filteredKeys is not empty (that is, the search hits), this situation should be distinguished from ordinary motionKeys
@@ -868,7 +853,6 @@ class TreeSelect extends BaseComponent {
868
853
  keyEntities: {},
869
854
  treeData: [],
870
855
  flattenNodes: [],
871
- cachedFlattenNodes: undefined,
872
856
  selectedKeys: [],
873
857
  checkedKeys: new Set(),
874
858
  halfCheckedKeys: new Set(),
@@ -898,7 +882,6 @@ class TreeSelect extends BaseComponent {
898
882
  };
899
883
  }
900
884
  static getDerivedStateFromProps(props, prevState) {
901
- var _a;
902
885
  const {
903
886
  prevProps,
904
887
  rePosKey
@@ -916,8 +899,6 @@ class TreeSelect extends BaseComponent {
916
899
  };
917
900
  const needUpdateTreeData = needUpdate('treeData');
918
901
  const needUpdateExpandedKeys = needUpdate('expandedKeys');
919
- const isExpandControlled = ('expandedKeys' in props);
920
- const isSearching = Boolean(props.filterTreeNode && prevState.inputValue && prevState.inputValue.length);
921
902
  // TreeNode
922
903
  if (needUpdateTreeData) {
923
904
  treeData = props.treeData;
@@ -936,97 +917,31 @@ class TreeSelect extends BaseComponent {
936
917
  }
937
918
  }
938
919
  const expandAllWhenDataChange = needUpdateTreeData && props.expandAll;
939
- if (!isSearching) {
940
- // expandedKeys
941
- if (needUpdateExpandedKeys || prevProps && needUpdate('autoExpandParent')) {
942
- newState.expandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
943
- // only show animation when treeData does not change
944
- if (prevProps && props.motion && !treeData) {
945
- const {
946
- motionKeys,
947
- motionType
948
- } = calcMotionKeys(prevState.expandedKeys, newState.expandedKeys, keyEntities);
949
- newState.motionKeys = new Set(motionKeys);
950
- newState.motionType = motionType;
951
- if (motionType === 'hide') {
952
- // cache flatten nodes: expandedKeys changed may not be triggered by interaction
953
- newState.cachedFlattenNodes = cloneDeep(prevState.flattenNodes);
954
- }
955
- }
956
- } else if (!prevProps && (props.defaultExpandAll || props.expandAll) || expandAllWhenDataChange) {
957
- newState.expandedKeys = new Set(Object.keys(keyEntities));
958
- } else if (!prevProps && props.defaultExpandedKeys) {
959
- newState.expandedKeys = calcExpandedKeys(props.defaultExpandedKeys, keyEntities);
960
- } else if (!prevProps && props.defaultValue) {
961
- newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.defaultValue, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
962
- } else if (!prevProps && props.value) {
963
- newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.value, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
964
- } else if (!isExpandControlled && needUpdateTreeData && props.value) {
965
- // 当 treeData 已经设置具体的值,并且设置了 props.loadData ,则认为 treeData 的更新是因为 loadData 导致的
966
- // 如果是因为 loadData 导致 treeData改变, 此时在这里重新计算 key 会导致为未选中的展开项目被收起
967
- // 所以此时不需要重新计算 expandedKeys,因为在点击展开按钮时候已经把被展开的项添加到 expandedKeys 中
968
- // When treeData has a specific value and props.loadData is set, it is considered that the update of treeData is caused by loadData
969
- // If the treeData is changed because of loadData, recalculating the key here will cause the unselected expanded items to be collapsed
970
- // 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
971
- if (!(prevState.treeData && ((_a = prevState.treeData) === null || _a === void 0 ? void 0 : _a.length) > 0 && props.loadData)) {
972
- newState.expandedKeys = calcExpandedKeysForValues(props.value, keyEntities, props.multiple, valueEntities);
973
- }
974
- }
975
- if (!newState.expandedKeys) {
976
- delete newState.expandedKeys;
977
- }
978
- if (treeData || newState.expandedKeys) {
979
- const flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.expandedKeys || prevState.expandedKeys, keyMaps);
980
- newState.flattenNodes = flattenNodes;
981
- }
982
- } else {
983
- let filteredState;
984
- // treeData changed while searching
985
- if (treeData) {
986
- // Get filter data
987
- filteredState = filterTreeData({
988
- treeData,
989
- inputValue: prevState.inputValue,
990
- filterTreeNode: props.filterTreeNode,
991
- filterProps: props.treeNodeFilterProp,
992
- showFilteredOnly: props.showFilteredOnly,
993
- keyEntities: newState.keyEntities,
994
- prevExpandedKeys: [...prevState.filteredExpandedKeys],
995
- keyMaps: keyMaps
996
- });
997
- newState.flattenNodes = filteredState.flattenNodes;
998
- newState.motionKeys = new Set([]);
999
- newState.filteredKeys = filteredState.filteredKeys;
1000
- newState.filteredShownKeys = filteredState.filteredShownKeys;
1001
- newState.filteredExpandedKeys = filteredState.filteredExpandedKeys;
1002
- }
1003
- // expandedKeys changed while searching
1004
- if (props.expandedKeys) {
1005
- newState.filteredExpandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
1006
- if (prevProps && props.motion) {
1007
- const prevKeys = prevState ? prevState.filteredExpandedKeys : new Set([]);
1008
- // only show animation when treeData does not change
1009
- if (!treeData) {
1010
- const motionResult = calcMotionKeys(prevKeys, newState.filteredExpandedKeys, keyEntities);
1011
- let {
1012
- motionKeys
1013
- } = motionResult;
1014
- const {
1015
- motionType
1016
- } = motionResult;
1017
- if (props.showFilteredOnly) {
1018
- motionKeys = motionKeys.filter(key => prevState.filteredShownKeys.has(key));
1019
- }
1020
- if (motionType === 'hide') {
1021
- // cache flatten nodes: expandedKeys changed may not be triggered by interaction
1022
- newState.cachedFlattenNodes = cloneDeep(prevState.flattenNodes);
1023
- }
1024
- newState.motionKeys = new Set(motionKeys);
1025
- newState.motionType = motionType;
1026
- }
1027
- }
1028
- newState.flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.filteredExpandedKeys || prevState.filteredExpandedKeys, keyMaps, props.showFilteredOnly && prevState.filteredShownKeys);
920
+ // expandedKeys
921
+ if (needUpdateExpandedKeys || prevProps && needUpdate('autoExpandParent')) {
922
+ newState.expandedKeys = calcExpandedKeys(props.expandedKeys, keyEntities, props.autoExpandParent || !prevProps);
923
+ // only show animation when treeData does not change
924
+ if (prevProps && props.motion && !treeData) {
925
+ const {
926
+ motionKeys,
927
+ motionType
928
+ } = calcMotionKeys(prevState.expandedKeys, newState.expandedKeys, keyEntities);
929
+ newState.motionKeys = new Set(motionKeys);
930
+ newState.motionType = motionType;
1029
931
  }
932
+ } else if (!prevProps && (props.defaultExpandAll || props.expandAll) || expandAllWhenDataChange) {
933
+ newState.expandedKeys = new Set(Object.keys(keyEntities));
934
+ } else if (!prevProps && props.defaultExpandedKeys) {
935
+ newState.expandedKeys = calcExpandedKeys(props.defaultExpandedKeys, keyEntities);
936
+ } else if (!prevProps && props.defaultValue) {
937
+ newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.defaultValue, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
938
+ } else if (!prevProps && props.value) {
939
+ newState.expandedKeys = calcExpandedKeysForValues(normalizeValue(props.value, withObject, keyMaps), keyEntities, props.multiple, valueEntities);
940
+ }
941
+ // flattenNodes
942
+ if (treeData || needUpdateExpandedKeys) {
943
+ const flattenNodes = flattenTreeData(treeData || prevState.treeData, newState.expandedKeys || prevState.expandedKeys, keyMaps);
944
+ newState.flattenNodes = flattenNodes;
1030
945
  }
1031
946
  // selectedKeys: single mode controlled
1032
947
  const isMultiple = props.multiple;
@@ -1133,9 +1048,7 @@ class TreeSelect extends BaseComponent {
1133
1048
  this.props.onSearch && this.props.onSearch(input, filteredExpandedKeys);
1134
1049
  },
1135
1050
  cacheFlattenNodes: bool => {
1136
- this.setState({
1137
- cachedFlattenNodes: bool ? cloneDeep(this.state.flattenNodes) : undefined
1138
- });
1051
+ this._flattenNodes = bool ? cloneDeep(this.state.flattenNodes) : null;
1139
1052
  },
1140
1053
  notifyLoad: (newLoadedKeys, data) => {
1141
1054
  const {
@@ -1280,8 +1193,7 @@ class TreeSelect extends BaseComponent {
1280
1193
  autoAdjustOverflow: autoAdjustOverflow,
1281
1194
  mouseLeaveDelay: mouseLeaveDelay,
1282
1195
  mouseEnterDelay: mouseEnterDelay,
1283
- onVisibleChange: this.handlePopoverClose,
1284
- afterClose: this.afterClose
1196
+ onVisibleChange: this.handlePopoverClose
1285
1197
  }, selection);
1286
1198
  }
1287
1199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-ui",
3
- "version": "2.48.0-alpha.0",
3
+ "version": "2.48.0",
4
4
  "description": "A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es/index.js",
@@ -20,12 +20,12 @@
20
20
  "@dnd-kit/core": "^6.0.8",
21
21
  "@dnd-kit/sortable": "^7.0.2",
22
22
  "@dnd-kit/utilities": "^3.2.1",
23
- "@douyinfe/semi-animation": "2.48.0-alpha.0",
24
- "@douyinfe/semi-animation-react": "2.48.0-alpha.0",
25
- "@douyinfe/semi-foundation": "2.48.0-alpha.0",
26
- "@douyinfe/semi-icons": "2.48.0-alpha.0",
27
- "@douyinfe/semi-illustrations": "2.48.0-alpha.0",
28
- "@douyinfe/semi-theme-default": "2.48.0-alpha.0",
23
+ "@douyinfe/semi-animation": "2.48.0",
24
+ "@douyinfe/semi-animation-react": "2.48.0",
25
+ "@douyinfe/semi-foundation": "2.48.0",
26
+ "@douyinfe/semi-icons": "2.48.0",
27
+ "@douyinfe/semi-illustrations": "2.48.0",
28
+ "@douyinfe/semi-theme-default": "2.48.0",
29
29
  "async-validator": "^3.5.0",
30
30
  "classnames": "^2.2.6",
31
31
  "copy-text-to-clipboard": "^2.1.1",
@@ -75,7 +75,7 @@
75
75
  ],
76
76
  "author": "",
77
77
  "license": "MIT",
78
- "gitHead": "930287380571d83f7a34d99fb13d80b4474adff8",
78
+ "gitHead": "6f3b0957a0fbd5b5cf5a2187782bac2f767162b3",
79
79
  "devDependencies": {
80
80
  "@babel/plugin-proposal-decorators": "^7.15.8",
81
81
  "@babel/plugin-transform-runtime": "^7.15.8",