@hi-ui/check-select 4.3.1 → 4.3.3

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.
@@ -11,12 +11,11 @@ import { useMemo } from 'react';
11
11
  import { baseFlattenTree } from '@hi-ui/tree-utils';
12
12
  var NOOP_ARRAY = [];
13
13
  var DEFAULT_FIELD_NAMES = {};
14
-
15
14
  var useFlattenData = function useFlattenData(_ref) {
16
15
  var _ref$data = _ref.data,
17
- data = _ref$data === void 0 ? NOOP_ARRAY : _ref$data,
18
- _ref$fieldNames = _ref.fieldNames,
19
- fieldNames = _ref$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _ref$fieldNames;
16
+ data = _ref$data === void 0 ? NOOP_ARRAY : _ref$data,
17
+ _ref$fieldNames = _ref.fieldNames,
18
+ fieldNames = _ref$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _ref$fieldNames;
20
19
  var flattedData = useMemo(function () {
21
20
  return flattenData({
22
21
  data: data,
@@ -25,29 +24,25 @@ var useFlattenData = function useFlattenData(_ref) {
25
24
  }, [data, fieldNames]);
26
25
  return flattedData;
27
26
  };
28
-
29
27
  var flattenData = function flattenData(_ref2) {
30
28
  var _ref2$data = _ref2.data,
31
- data = _ref2$data === void 0 ? NOOP_ARRAY : _ref2$data,
32
- _ref2$fieldNames = _ref2.fieldNames,
33
- fieldNames = _ref2$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _ref2$fieldNames; // 转换对象
34
-
29
+ data = _ref2$data === void 0 ? NOOP_ARRAY : _ref2$data,
30
+ _ref2$fieldNames = _ref2.fieldNames,
31
+ fieldNames = _ref2$fieldNames === void 0 ? DEFAULT_FIELD_NAMES : _ref2$fieldNames;
32
+ // 转换对象
35
33
  var getKeyFields = function getKeyFields(node, key) {
36
34
  return node[fieldNames[key] || key];
37
35
  };
38
-
39
36
  return baseFlattenTree({
40
37
  tree: data,
41
38
  childrenFieldName: function childrenFieldName(node) {
42
39
  return getKeyFields(node, 'children');
43
40
  },
44
41
  transform: function transform(node) {
45
- var _a; // 不对外暴露
46
-
47
-
42
+ var _a;
43
+ // 不对外暴露
48
44
  delete node.parent;
49
45
  var raw = node.raw;
50
-
51
46
  if ('groupId' in raw) {
52
47
  // 用于虚拟列表唯一 id
53
48
  node.id = raw.groupId;
@@ -59,10 +54,8 @@ var flattenData = function flattenData(_ref2) {
59
54
  node.title = getKeyFields(raw, 'title');
60
55
  node.disabled = (_a = getKeyFields(raw, 'disabled')) !== null && _a !== void 0 ? _a : false;
61
56
  }
62
-
63
57
  return node;
64
58
  }
65
59
  });
66
60
  };
67
-
68
61
  export { flattenData, useFlattenData };
@@ -9,7 +9,5 @@
9
9
  */
10
10
  import __styleInject__ from 'style-inject';
11
11
  var css_248z = ".hi-v4-check-select-option {-webkit-box-sizing: border-box;box-sizing: border-box;width: 100%;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;position: relative;border-radius: var(--hi-v4-border-radius-md, 4px);cursor: pointer;font-size: var(--hi-v4-text-size-md, 0.875rem);font-weight: var(--hi-v4-text-weight-normal, 400);color: var(--hi-v4-color-gray-700, #1f2733);line-height: var(--hi-v4-text-lineheight-sm, 1.25rem);}.hi-v4-check-select-option__indent {display: inline-block;width: 16px;height: 100%;}.hi-v4-check-select-option__title {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;-webkit-box-sizing: border-box;box-sizing: border-box;width: 100%;padding: var(--hi-v4-spacing-3, 6px) var(--hi-v4-spacing-3, 6px);font-size: inherit;-webkit-text-size-adjust: none;-moz-text-size-adjust: none;-ms-text-size-adjust: none;text-size-adjust: none;font-weight: inherit;color: inherit;line-height: inherit;}.hi-v4-check-select-option:hover {background-color: var(--hi-v4-color-gray-100, #f2f4f7);}.hi-v4-check-select-option--focused {background-color: var(--hi-v4-color-gray-100, #f2f4f7);}.hi-v4-check-select-option--disabled {cursor: not-allowed;color: var(--hi-v4-color-gray-500, #929aa6);}.hi-v4-check-select-option-group {display: inline-block;margin-top: var(--hi-v4-spacing-6, 12px);margin-bottom: var(--hi-v4-spacing-2, 4px);padding: var(--hi-v4-spacing-3, 6px) 0 var(--hi-v4-spacing-3, 6px) var(--hi-v4-spacing-3, 6px);font-size: var(--hi-v4-text-size-md, 0.875rem);font-weight: var(--hi-v4-text-weight-normal, 400);color: var(--hi-v4-color-gray-500, #929aa6);line-height: var(--hi-v4-text-lineheight-sm, 1.25rem);}.hi-v4-check-select-option-group:first-child {margin-top: var(--hi-v4-spacing-2, 4px);}";
12
-
13
12
  __styleInject__(css_248z);
14
-
15
13
  export { css_248z as default };
@@ -20,52 +20,44 @@ import '@hi-ui/env';
20
20
  import '@hi-ui/type-assertion';
21
21
  var NOOP_ARRAY = [];
22
22
  var NOOP_VALUE = [];
23
-
24
23
  var useCheckSelect = function useCheckSelect(_a) {
25
24
  var _a$data = _a.data,
26
- dataProp = _a$data === void 0 ? NOOP_ARRAY : _a$data,
27
- children = _a.children,
28
- _a$disabled = _a.disabled,
29
- disabled = _a$disabled === void 0 ? false : _a$disabled,
30
- valueProp = _a.value,
31
- _a$defaultValue = _a.defaultValue,
32
- defaultValue = _a$defaultValue === void 0 ? NOOP_VALUE : _a$defaultValue,
33
- onChangeProp = _a.onChange,
34
- onSelect = _a.onSelect,
35
- fieldNames = _a.fieldNames,
36
- rest = __rest(_a, ["data", "children", "disabled", "value", "defaultValue", "onChange", "onSelect", "fieldNames"]);
37
-
25
+ dataProp = _a$data === void 0 ? NOOP_ARRAY : _a$data,
26
+ children = _a.children,
27
+ _a$disabled = _a.disabled,
28
+ disabled = _a$disabled === void 0 ? false : _a$disabled,
29
+ valueProp = _a.value,
30
+ _a$defaultValue = _a.defaultValue,
31
+ defaultValue = _a$defaultValue === void 0 ? NOOP_VALUE : _a$defaultValue,
32
+ onChangeProp = _a.onChange,
33
+ onSelect = _a.onSelect,
34
+ fieldNames = _a.fieldNames,
35
+ rest = __rest(_a, ["data", "children", "disabled", "value", "defaultValue", "onChange", "onSelect", "fieldNames"]);
38
36
  var data = useData({
39
37
  data: dataProp,
40
38
  children: children
41
39
  });
42
-
43
40
  var _useCache = useCache(data),
44
- cacheData = _useCache[0],
45
- setCacheData = _useCache[1];
46
-
41
+ cacheData = _useCache[0],
42
+ setCacheData = _useCache[1];
47
43
  var flattedData = useFlattenData({
48
44
  data: cacheData,
49
45
  fieldNames: fieldNames
50
46
  });
51
47
  var flattedDataRef = useLatestRef(flattedData);
52
-
53
48
  var _useUncontrolledState = useUncontrolledState(defaultValue, valueProp, onChangeProp),
54
- value = _useUncontrolledState[0],
55
- tryChangeValue = _useUncontrolledState[1];
56
-
49
+ value = _useUncontrolledState[0],
50
+ tryChangeValue = _useUncontrolledState[1];
57
51
  var onSelectLatest = useLatestCallback(onSelect);
58
- var usedItemsRef = useRef([]); // 扁平化的选中数据,可能包括异步临时选中缓存数据
59
-
52
+ var usedItemsRef = useRef([]);
53
+ // 扁平化的选中数据,可能包括异步临时选中缓存数据
60
54
  var _useState = useState([]),
61
- checkedItems = _useState[0],
62
- setCheckedItems = _useState[1];
55
+ checkedItems = _useState[0],
56
+ setCheckedItems = _useState[1];
63
57
  /**
64
58
  * 更新缓存的 data 数据
65
59
  * 兼容在搜索异步加载结果的场景时,将选中的项加入到 cacheData 数据中,这样再次打开下拉框时可以显示之前选中的值
66
60
  */
67
-
68
-
69
61
  var updateCacheData = useCallback(function (nextCheckedItems) {
70
62
  var newData = [].concat(cacheData);
71
63
  nextCheckedItems.forEach(function (item) {
@@ -79,38 +71,35 @@ var useCheckSelect = function useCheckSelect(_a) {
79
71
  }, [cacheData, flattedData, setCacheData]);
80
72
  var proxyTryChangeValue = useCallback(function (value, item, shouldChecked) {
81
73
  var changedItems = item;
82
-
83
74
  if (!Array.isArray(item)) {
84
75
  changedItems = [item];
85
76
  onSelectLatest(value, item, shouldChecked);
86
77
  }
87
-
88
78
  var usedItems = uniqBy([].concat(changedItems, usedItemsRef.current, flattedDataRef.current), 'id');
89
- usedItemsRef.current = usedItems; // 使用最新的value
90
-
79
+ usedItemsRef.current = usedItems;
80
+ // 使用最新的value
91
81
  var nextCheckedItems = usedItems.filter(function (item) {
92
82
  return value.includes(item.id);
93
83
  });
94
84
  setCheckedItems(nextCheckedItems);
95
- tryChangeValue(value, // 处理脏数据
85
+ tryChangeValue(value,
86
+ // 处理脏数据
96
87
  changedItems.map(function (item) {
97
88
  return 'raw' in item ? item.raw : item;
98
89
  }), nextCheckedItems.map(function (item) {
99
90
  return 'raw' in item ? item.raw : item;
100
- })); // 每次更新 value 时,同步更新下 cacheData
101
-
91
+ }));
92
+ // 每次更新 value 时,同步更新下 cacheData
102
93
  updateCacheData(nextCheckedItems);
103
94
  }, [flattedDataRef, tryChangeValue, updateCacheData, onSelectLatest]);
104
-
105
95
  var _useCheckDefault = useCheck({
106
- disabled: disabled,
107
- checkedIds: value,
108
- onCheck: proxyTryChangeValue,
109
- allowCheck: allowCheck
110
- }),
111
- onOptionCheck = _useCheckDefault[0],
112
- isCheckedId = _useCheckDefault[1];
113
-
96
+ disabled: disabled,
97
+ checkedIds: value,
98
+ onCheck: proxyTryChangeValue,
99
+ allowCheck: allowCheck
100
+ }),
101
+ onOptionCheck = _useCheckDefault[0],
102
+ isCheckedId = _useCheckDefault[1];
114
103
  return {
115
104
  rootProps: rest,
116
105
  data: data,
@@ -122,9 +111,7 @@ var useCheckSelect = function useCheckSelect(_a) {
122
111
  checkedItems: checkedItems
123
112
  };
124
113
  };
125
-
126
114
  var allowCheck = function allowCheck(option) {
127
115
  return !option.disabled;
128
116
  };
129
-
130
117
  export { useCheckSelect };
@@ -7,7 +7,6 @@
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
-
11
10
  /**
12
11
  * 判断选项是否进行可选操作
13
12
  */
@@ -19,13 +18,10 @@ var isCheckableOption = function isCheckableOption(item) {
19
18
  /**
20
19
  * 判断选项为
21
20
  */
22
-
23
-
24
21
  var isOption = function isOption(item) {
25
22
  if ('groupTitle' in item) return false;
26
23
  return true;
27
24
  };
28
-
29
25
  var getAllCheckedStatus = function getAllCheckedStatus(dropdownItems, values, filterFunc) {
30
26
  var dropdownIds = dropdownItems.filter(filterFunc).map(function (_ref) {
31
27
  var id = _ref.id;
@@ -41,5 +37,4 @@ var getAllCheckedStatus = function getAllCheckedStatus(dropdownItems, values, fi
41
37
  });
42
38
  return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
43
39
  };
44
-
45
40
  export { getAllCheckedStatus, isCheckableOption, isOption };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/check-select",
3
- "version": "4.3.1",
3
+ "version": "4.3.3",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -43,38 +43,38 @@
43
43
  "url": "https://github.com/XiaoMi/hiui/issues"
44
44
  },
45
45
  "dependencies": {
46
- "@hi-ui/array-utils": "^4.0.1",
47
- "@hi-ui/checkbox": "^4.0.5",
48
- "@hi-ui/classname": "^4.0.1",
49
- "@hi-ui/dom-utils": "^4.0.4",
50
- "@hi-ui/env": "^4.0.1",
51
- "@hi-ui/func-utils": "^4.0.1",
52
- "@hi-ui/highlighter": "^4.0.5",
53
- "@hi-ui/icons": "^4.0.6",
54
- "@hi-ui/input": "^4.0.9",
55
- "@hi-ui/picker": "^4.1.1",
56
- "@hi-ui/popper": "^4.0.5",
57
- "@hi-ui/tag-input": "^4.0.6",
58
- "@hi-ui/times": "^4.0.1",
59
- "@hi-ui/tree-utils": "^4.0.2",
60
- "@hi-ui/type-assertion": "^4.0.1",
61
- "@hi-ui/use-check": "^4.0.2",
62
- "@hi-ui/use-children": "^4.0.1",
63
- "@hi-ui/use-data-source": "^4.0.1",
64
- "@hi-ui/use-latest": "^4.0.1",
65
- "@hi-ui/use-search-mode": "^4.0.6",
66
- "@hi-ui/use-toggle": "^4.0.1",
67
- "@hi-ui/use-uncontrolled-state": "^4.0.1",
68
- "@hi-ui/virtual-list": "^4.0.4"
46
+ "@hi-ui/array-utils": "^4.0.2",
47
+ "@hi-ui/checkbox": "^4.0.6",
48
+ "@hi-ui/classname": "^4.0.2",
49
+ "@hi-ui/dom-utils": "^4.0.5",
50
+ "@hi-ui/env": "^4.0.2",
51
+ "@hi-ui/func-utils": "^4.0.2",
52
+ "@hi-ui/highlighter": "^4.0.6",
53
+ "@hi-ui/icons": "^4.0.16",
54
+ "@hi-ui/input": "^4.0.11",
55
+ "@hi-ui/picker": "^4.1.2",
56
+ "@hi-ui/popper": "^4.1.1",
57
+ "@hi-ui/tag-input": "^4.0.8",
58
+ "@hi-ui/times": "^4.0.2",
59
+ "@hi-ui/tree-utils": "^4.1.2",
60
+ "@hi-ui/type-assertion": "^4.0.2",
61
+ "@hi-ui/use-check": "^4.0.3",
62
+ "@hi-ui/use-children": "^4.0.2",
63
+ "@hi-ui/use-data-source": "^4.0.2",
64
+ "@hi-ui/use-latest": "^4.0.2",
65
+ "@hi-ui/use-search-mode": "^4.1.2",
66
+ "@hi-ui/use-toggle": "^4.0.2",
67
+ "@hi-ui/use-uncontrolled-state": "^4.0.2",
68
+ "@hi-ui/virtual-list": "^4.0.5"
69
69
  },
70
70
  "peerDependencies": {
71
- "@hi-ui/core": ">=4.0.0",
71
+ "@hi-ui/core": ">=4.0.6",
72
72
  "react": ">=16.8.6",
73
73
  "react-dom": ">=16.8.6"
74
74
  },
75
75
  "devDependencies": {
76
- "@hi-ui/core": "^4.0.4",
77
- "@hi-ui/core-css": "^4.1.1",
76
+ "@hi-ui/core": "^4.0.6",
77
+ "@hi-ui/core-css": "^4.1.3",
78
78
  "react": "^17.0.1",
79
79
  "react-dom": "^17.0.1"
80
80
  }