@hi-ui/check-tree-select 4.5.0 → 4.6.1-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @hi-ui/check-tree-select
2
2
 
3
+ ## 4.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2952](https://github.com/XiaoMi/hiui/pull/2952) [`f7137e3db`](https://github.com/XiaoMi/hiui/commit/f7137e3dbff8a3a2735f9e7d8a09fc942c8a8a86) Thanks [@xiamiao1121](https://github.com/xiamiao1121)! - feat: 新增支持过滤已选择项
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`bc306526c`](https://github.com/XiaoMi/hiui/commit/bc306526c948cb2b1ecd73b63e903d941c78dd9a), [`7bdd549d0`](https://github.com/XiaoMi/hiui/commit/7bdd549d0fcb6a6b903742333e352e184723aa3b)]:
12
+ - @hi-ui/tree@4.6.0
13
+
3
14
  ## 4.5.0
4
15
 
5
16
  ### Minor Changes
@@ -89,13 +89,16 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
89
89
  itemHeight = _a.itemHeight,
90
90
  height = _a.height,
91
91
  showCheckAll = _a.showCheckAll,
92
+ _a$showOnlyShowChecke = _a.showOnlyShowChecked,
93
+ showOnlyShowChecked = _a$showOnlyShowChecke === void 0 ? false : _a$showOnlyShowChecke,
92
94
  tagInputProps = _a.tagInputProps,
93
95
  _a$size = _a.size,
94
96
  size = _a$size === void 0 ? 'md' : _a$size,
95
97
  customRender = _a.customRender,
96
98
  prefix = _a.prefix,
97
99
  suffix = _a.suffix,
98
- rest = tslib.__rest(_a, ["prefixCls", "role", "className", "data", "dataSource", "disabled", "visible", "onOpen", "onClose", "fieldNames", "checkedMode", "defaultExpandAll", "expandedIds", "defaultExpandedIds", "onExpand", "defaultValue", "value", "onChange", "searchable", "searchMode", "onLoadChildren", "render", "filterOption", "onSearch", "clearable", "invalid", "displayRender", "placeholder", "appearance", "virtual", "itemHeight", "height", "showCheckAll", "tagInputProps", "size", "customRender", "prefix", "suffix"]);
100
+ keywordProp = _a.keyword,
101
+ rest = tslib.__rest(_a, ["prefixCls", "role", "className", "data", "dataSource", "disabled", "visible", "onOpen", "onClose", "fieldNames", "checkedMode", "defaultExpandAll", "expandedIds", "defaultExpandedIds", "onExpand", "defaultValue", "value", "onChange", "searchable", "searchMode", "onLoadChildren", "render", "filterOption", "onSearch", "clearable", "invalid", "displayRender", "placeholder", "appearance", "virtual", "itemHeight", "height", "showCheckAll", "showOnlyShowChecked", "tagInputProps", "size", "customRender", "prefix", "suffix", "keyword"]);
99
102
  var i18n = core.useLocaleContext();
100
103
  var placeholder = typeAssertion.isUndef(placeholderProp) ? i18n.get('checkTreeSelect.placeholder') : placeholderProp;
101
104
  var _useUncontrolledToggl = useToggle.useUncontrolledToggle({
@@ -106,6 +109,11 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
106
109
  }),
107
110
  menuVisible = _useUncontrolledToggl[0],
108
111
  menuVisibleAction = _useUncontrolledToggl[1];
112
+ var _useState = React.useState(null),
113
+ filterItems = _useState[0],
114
+ setFilterItems = _useState[1];
115
+ var expandedViewRef = React.useRef('normal');
116
+ var activeExpandable = showOnlyShowChecked && !!filterItems && menuVisible;
109
117
  /**
110
118
  * 转换对象
111
119
  */
@@ -188,6 +196,7 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
188
196
  });
189
197
  var _useSearchMode = useSearchMode.useSearchMode({
190
198
  searchable: searchableProp,
199
+ keyword: keywordProp,
191
200
  strategies: [dataSourceStrategy, customSearchStrategy, filterSearchStrategy, highlightSearchStrategy]
192
201
  }),
193
202
  stateInSearch = _useSearchMode.state,
@@ -210,8 +219,9 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
210
219
  return ret;
211
220
  }, [titleRender, searchValue, searchMode]);
212
221
  var shouldUseSearch = !!searchValue && !hasError;
222
+ var showData = shouldUseSearch ? stateInSearch.data : data;
213
223
  var treeProps = {
214
- data: shouldUseSearch ? stateInSearch.data : data,
224
+ data: filterItems !== null && filterItems !== void 0 ? filterItems : showData,
215
225
  expandedIds: shouldUseSearch ? stateInSearch.expandedIds : expandedIds,
216
226
  onExpand: shouldUseSearch ? function (ids) {
217
227
  return setStateInSearch(function (prev) {
@@ -291,6 +301,7 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
291
301
  // onChange={tryChangeValue}
292
302
  // data={mergedData}
293
303
  searchable: searchable,
304
+ keyword: keywordProp,
294
305
  onSearch: funcUtils.callAllFuncs(onSearchProp, onSearch),
295
306
  footer: renderDefaultFooter(),
296
307
  loading: rest.loading !== undefined ? rest.loading : loading,
@@ -311,7 +322,62 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
311
322
  onChange: onValueChange,
312
323
  data: mergedData,
313
324
  // @ts-ignore
314
- invalid: invalid
325
+ invalid: invalid,
326
+ // onExpand={() => {
327
+ // // setViewSelected(true)
328
+ // menuVisibleAction.on()
329
+ // }}
330
+ onClick: function onClick(evt) {
331
+ if (!showOnlyShowChecked) return;
332
+ evt.preventDefault();
333
+ if (filterItems) {
334
+ setFilterItems(null);
335
+ }
336
+ if (menuVisible) {
337
+ if (expandedViewRef.current === 'normal') {
338
+ menuVisibleAction.off();
339
+ }
340
+ } else {
341
+ menuVisibleAction.on();
342
+ }
343
+ expandedViewRef.current = 'normal';
344
+ },
345
+ expandable: showOnlyShowChecked,
346
+ activeExpandable: activeExpandable,
347
+ onExpand: function onExpand(evt) {
348
+ if (!showOnlyShowChecked) return;
349
+ // 阻止冒泡触发外层 onClick
350
+ evt.preventDefault();
351
+ evt.stopPropagation();
352
+ // 选中数据
353
+ setFilterItems(function () {
354
+ var filterFunc = function filterFunc(node) {
355
+ var _a;
356
+ if (parsedCheckedIds.includes(node.id)) {
357
+ return true;
358
+ }
359
+ if (node.children && ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
360
+ return node.children.some(function (child) {
361
+ return filterFunc(child);
362
+ });
363
+ }
364
+ return false;
365
+ };
366
+ // filterTree 过滤树结构,将不包含value中的节点分支过滤掉
367
+ // 返回过滤后的树结构
368
+ var treeData = treeUtils.filterTree(data, filterFunc);
369
+ return treeData;
370
+ });
371
+ // 展开/关闭操作
372
+ if (menuVisible) {
373
+ if (expandedViewRef.current !== 'normal') {
374
+ menuVisibleAction.off();
375
+ }
376
+ } else {
377
+ menuVisibleAction.on();
378
+ }
379
+ expandedViewRef.current = 'onlyChecked';
380
+ }
315
381
  })))
316
382
  }), typeAssertion.isArrayNonEmpty(treeProps.data) ? ( /*#__PURE__*/
317
383
  // 只做渲染,不做逻辑处理(比如搜索过滤后,check操作的是对过滤后的data操作,这是不符合预期的)
@@ -8,14 +8,14 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
  import { __rest } from 'tslib';
11
- import React, { forwardRef, useCallback, useMemo } from 'react';
11
+ import React, { forwardRef, useState, useRef, useCallback, useMemo } from 'react';
12
12
  import { getPrefixCls, cx } from '@hi-ui/classname';
13
13
  import { __DEV__ } from '@hi-ui/env';
14
14
  import { useUncontrolledToggle } from '@hi-ui/use-toggle';
15
15
  import { Tree } from '@hi-ui/tree';
16
16
  import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state';
17
17
  import { Picker } from '@hi-ui/picker';
18
- import { baseFlattenTree } from '@hi-ui/tree-utils';
18
+ import { baseFlattenTree, filterTree } from '@hi-ui/tree-utils';
19
19
  import { isUndef, isArrayNonEmpty } from '@hi-ui/type-assertion';
20
20
  import { uniqBy } from '@hi-ui/array-utils';
21
21
  import { Highlighter } from '@hi-ui/highlighter';
@@ -76,13 +76,16 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
76
76
  itemHeight = _a.itemHeight,
77
77
  height = _a.height,
78
78
  showCheckAll = _a.showCheckAll,
79
+ _a$showOnlyShowChecke = _a.showOnlyShowChecked,
80
+ showOnlyShowChecked = _a$showOnlyShowChecke === void 0 ? false : _a$showOnlyShowChecke,
79
81
  tagInputProps = _a.tagInputProps,
80
82
  _a$size = _a.size,
81
83
  size = _a$size === void 0 ? 'md' : _a$size,
82
84
  customRender = _a.customRender,
83
85
  prefix = _a.prefix,
84
86
  suffix = _a.suffix,
85
- rest = __rest(_a, ["prefixCls", "role", "className", "data", "dataSource", "disabled", "visible", "onOpen", "onClose", "fieldNames", "checkedMode", "defaultExpandAll", "expandedIds", "defaultExpandedIds", "onExpand", "defaultValue", "value", "onChange", "searchable", "searchMode", "onLoadChildren", "render", "filterOption", "onSearch", "clearable", "invalid", "displayRender", "placeholder", "appearance", "virtual", "itemHeight", "height", "showCheckAll", "tagInputProps", "size", "customRender", "prefix", "suffix"]);
87
+ keywordProp = _a.keyword,
88
+ rest = __rest(_a, ["prefixCls", "role", "className", "data", "dataSource", "disabled", "visible", "onOpen", "onClose", "fieldNames", "checkedMode", "defaultExpandAll", "expandedIds", "defaultExpandedIds", "onExpand", "defaultValue", "value", "onChange", "searchable", "searchMode", "onLoadChildren", "render", "filterOption", "onSearch", "clearable", "invalid", "displayRender", "placeholder", "appearance", "virtual", "itemHeight", "height", "showCheckAll", "showOnlyShowChecked", "tagInputProps", "size", "customRender", "prefix", "suffix", "keyword"]);
86
89
  var i18n = useLocaleContext();
87
90
  var placeholder = isUndef(placeholderProp) ? i18n.get('checkTreeSelect.placeholder') : placeholderProp;
88
91
  var _useUncontrolledToggl = useUncontrolledToggle({
@@ -93,6 +96,11 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
93
96
  }),
94
97
  menuVisible = _useUncontrolledToggl[0],
95
98
  menuVisibleAction = _useUncontrolledToggl[1];
99
+ var _useState = useState(null),
100
+ filterItems = _useState[0],
101
+ setFilterItems = _useState[1];
102
+ var expandedViewRef = useRef('normal');
103
+ var activeExpandable = showOnlyShowChecked && !!filterItems && menuVisible;
96
104
  /**
97
105
  * 转换对象
98
106
  */
@@ -175,6 +183,7 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
175
183
  });
176
184
  var _useSearchMode = useSearchMode({
177
185
  searchable: searchableProp,
186
+ keyword: keywordProp,
178
187
  strategies: [dataSourceStrategy, customSearchStrategy, filterSearchStrategy, highlightSearchStrategy]
179
188
  }),
180
189
  stateInSearch = _useSearchMode.state,
@@ -197,8 +206,9 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
197
206
  return ret;
198
207
  }, [titleRender, searchValue, searchMode]);
199
208
  var shouldUseSearch = !!searchValue && !hasError;
209
+ var showData = shouldUseSearch ? stateInSearch.data : data;
200
210
  var treeProps = {
201
- data: shouldUseSearch ? stateInSearch.data : data,
211
+ data: filterItems !== null && filterItems !== void 0 ? filterItems : showData,
202
212
  expandedIds: shouldUseSearch ? stateInSearch.expandedIds : expandedIds,
203
213
  onExpand: shouldUseSearch ? function (ids) {
204
214
  return setStateInSearch(function (prev) {
@@ -278,6 +288,7 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
278
288
  // onChange={tryChangeValue}
279
289
  // data={mergedData}
280
290
  searchable: searchable,
291
+ keyword: keywordProp,
281
292
  onSearch: callAllFuncs(onSearchProp, onSearch),
282
293
  footer: renderDefaultFooter(),
283
294
  loading: rest.loading !== undefined ? rest.loading : loading,
@@ -298,7 +309,62 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
298
309
  onChange: onValueChange,
299
310
  data: mergedData,
300
311
  // @ts-ignore
301
- invalid: invalid
312
+ invalid: invalid,
313
+ // onExpand={() => {
314
+ // // setViewSelected(true)
315
+ // menuVisibleAction.on()
316
+ // }}
317
+ onClick: function onClick(evt) {
318
+ if (!showOnlyShowChecked) return;
319
+ evt.preventDefault();
320
+ if (filterItems) {
321
+ setFilterItems(null);
322
+ }
323
+ if (menuVisible) {
324
+ if (expandedViewRef.current === 'normal') {
325
+ menuVisibleAction.off();
326
+ }
327
+ } else {
328
+ menuVisibleAction.on();
329
+ }
330
+ expandedViewRef.current = 'normal';
331
+ },
332
+ expandable: showOnlyShowChecked,
333
+ activeExpandable: activeExpandable,
334
+ onExpand: function onExpand(evt) {
335
+ if (!showOnlyShowChecked) return;
336
+ // 阻止冒泡触发外层 onClick
337
+ evt.preventDefault();
338
+ evt.stopPropagation();
339
+ // 选中数据
340
+ setFilterItems(function () {
341
+ var filterFunc = function filterFunc(node) {
342
+ var _a;
343
+ if (parsedCheckedIds.includes(node.id)) {
344
+ return true;
345
+ }
346
+ if (node.children && ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
347
+ return node.children.some(function (child) {
348
+ return filterFunc(child);
349
+ });
350
+ }
351
+ return false;
352
+ };
353
+ // filterTree 过滤树结构,将不包含value中的节点分支过滤掉
354
+ // 返回过滤后的树结构
355
+ var treeData = filterTree(data, filterFunc);
356
+ return treeData;
357
+ });
358
+ // 展开/关闭操作
359
+ if (menuVisible) {
360
+ if (expandedViewRef.current !== 'normal') {
361
+ menuVisibleAction.off();
362
+ }
363
+ } else {
364
+ menuVisibleAction.on();
365
+ }
366
+ expandedViewRef.current = 'onlyChecked';
367
+ }
302
368
  })))
303
369
  }), isArrayNonEmpty(treeProps.data) ? ( /*#__PURE__*/
304
370
  // 只做渲染,不做逻辑处理(比如搜索过滤后,check操作的是对过滤后的data操作,这是不符合预期的)
@@ -137,6 +137,10 @@ export interface CheckTreeSelectProps extends Omit<PickerProps, 'data' | 'onChan
137
137
  * 是否开启全选功能,需要对数据全量操作。异步数据场景暂不支持,可自行渲染弹层底部实现
138
138
  */
139
139
  showCheckAll?: boolean;
140
+ /**
141
+ * 是否开启查看仅已选功能
142
+ */
143
+ showOnlyShowChecked?: boolean;
140
144
  /**
141
145
  * TagInput 参数设置
142
146
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/check-tree-select",
3
- "version": "4.5.0",
3
+ "version": "4.6.1-alpha.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -53,7 +53,7 @@
53
53
  "@hi-ui/picker": "^4.1.6",
54
54
  "@hi-ui/popper": "^4.1.5",
55
55
  "@hi-ui/tag-input": "^4.1.1",
56
- "@hi-ui/tree": "^4.5.10",
56
+ "@hi-ui/tree": "^4.6.0",
57
57
  "@hi-ui/tree-utils": "^4.1.6",
58
58
  "@hi-ui/type-assertion": "^4.0.4",
59
59
  "@hi-ui/use-check": "^4.0.5",