@hi-ui/check-tree-select 4.0.0-beta.29 → 4.0.0-beta.31

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.
@@ -123,11 +123,22 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
123
123
  return node[fieldNames[key] || key];
124
124
  }, [fieldNames]);
125
125
  var flattedData = React.useMemo(function () {
126
- return treeUtils.flattenTree(data, function (node) {
127
- node.id = getKeyFields(node.raw, 'id'); // @ts-ignore
128
-
129
- node.title = getKeyFields(node.raw, 'title');
130
- return node;
126
+ return treeUtils.baseFlattenTree({
127
+ tree: data,
128
+ childrenFieldName: function childrenFieldName(node) {
129
+ return getKeyFields(node, 'children');
130
+ },
131
+ transform: function transform(node) {
132
+ var _a, _b;
133
+
134
+ var flattedNode = node;
135
+ var raw = node.raw;
136
+ flattedNode.id = getKeyFields(raw, 'id');
137
+ flattedNode.title = getKeyFields(raw, 'title');
138
+ flattedNode.disabled = (_a = getKeyFields(raw, 'disabled')) !== null && _a !== void 0 ? _a : false;
139
+ flattedNode.isLeaf = (_b = getKeyFields(raw, 'isLeaf')) !== null && _b !== void 0 ? _b : false;
140
+ return flattedNode;
141
+ }
131
142
  });
132
143
  }, [data, getKeyFields]); // TODO: 抽离展开hook
133
144
  // TODO: onLoadChildren 和 defaultExpandAll 共存时
@@ -295,8 +306,9 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
295
306
  checkedIds: value,
296
307
  onCheck: onSelect,
297
308
  // TODO: 支持 fieldNames
298
- // 禁用时被选中的样式处理
299
- onLoadChildren: onLoadChildren
309
+ // @ts-ignore
310
+ onLoadChildren: onLoadChildren,
311
+ fieldNames: fieldNames
300
312
  }, treeProps)) : null);
301
313
  });
302
314
 
@@ -15,7 +15,7 @@ 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 { flattenTree } from '@hi-ui/tree-utils';
18
+ import { baseFlattenTree } 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';
@@ -90,11 +90,22 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
90
90
  return node[fieldNames[key] || key];
91
91
  }, [fieldNames]);
92
92
  var flattedData = useMemo(function () {
93
- return flattenTree(data, function (node) {
94
- node.id = getKeyFields(node.raw, 'id'); // @ts-ignore
95
-
96
- node.title = getKeyFields(node.raw, 'title');
97
- return node;
93
+ return baseFlattenTree({
94
+ tree: data,
95
+ childrenFieldName: function childrenFieldName(node) {
96
+ return getKeyFields(node, 'children');
97
+ },
98
+ transform: function transform(node) {
99
+ var _a, _b;
100
+
101
+ var flattedNode = node;
102
+ var raw = node.raw;
103
+ flattedNode.id = getKeyFields(raw, 'id');
104
+ flattedNode.title = getKeyFields(raw, 'title');
105
+ flattedNode.disabled = (_a = getKeyFields(raw, 'disabled')) !== null && _a !== void 0 ? _a : false;
106
+ flattedNode.isLeaf = (_b = getKeyFields(raw, 'isLeaf')) !== null && _b !== void 0 ? _b : false;
107
+ return flattedNode;
108
+ }
98
109
  });
99
110
  }, [data, getKeyFields]); // TODO: 抽离展开hook
100
111
  // TODO: onLoadChildren 和 defaultExpandAll 共存时
@@ -262,8 +273,9 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
262
273
  checkedIds: value,
263
274
  onCheck: onSelect,
264
275
  // TODO: 支持 fieldNames
265
- // 禁用时被选中的样式处理
266
- onLoadChildren: onLoadChildren
276
+ // @ts-ignore
277
+ onLoadChildren: onLoadChildren,
278
+ fieldNames: fieldNames
267
279
  }, treeProps)) : null);
268
280
  });
269
281
 
@@ -3,7 +3,6 @@ import { FieldNames, CheckTreeSelectDataItem } from './types';
3
3
  import { FlattedTreeNodeData, TreeNodeEventData } from '@hi-ui/tree';
4
4
  import { PickerProps } from '@hi-ui/picker';
5
5
  import { HiBaseAppearanceEnum } from '@hi-ui/core';
6
- import { UseDataSource } from '@hi-ui/use-data-source';
7
6
  /**
8
7
  * TODO: What is CheckTreeSelect
9
8
  */
@@ -18,12 +17,13 @@ export interface CheckTreeSelectProps extends Omit<PickerProps, 'data' | 'onChan
18
17
  */
19
18
  fieldNames?: FieldNames;
20
19
  /**
21
- * 数据回显模式 string
22
- * ALL: 所有被选中节点,不区分父子节点
20
+ * 多选数据交互时回填、回显模式
23
21
  * PARENT: 当所有子节点被选中时将只保留父节点
24
- * CHILD: 仅显示子节点
22
+ * ALL: 所有被选中节点,不区分父子节点(不支持异步数据加载勾选checkbox)
23
+ * CHILD: 仅显示子节点(不支持异步数据加载勾选checkbox)
24
+ * SEPARATE:父子完全独立受控
25
25
  */
26
- checkedMode?: 'ALL' | 'PARENT' | 'CHILD';
26
+ checkedMode?: 'ALL' | 'PARENT' | 'CHILD' | 'SEPARATE';
27
27
  /**
28
28
  * 数据选择类型
29
29
  */
@@ -87,13 +87,8 @@ export interface CheckTreeSelectProps extends Omit<PickerProps, 'data' | 'onChan
87
87
  */
88
88
  onLoadChildren?: (node: TreeNodeEventData) => void | Promise<CheckTreeSelectDataItem[] | void>;
89
89
  /**
90
- * 从远端获取数据,初始时是否自动加载
90
+ * 异步加载数据。暂不对外暴露
91
91
  */
92
- autoload?: boolean;
93
- /**
94
- * 异步加载数据
95
- */
96
- dataSource?: UseDataSource<CheckTreeSelectDataItem[]>;
97
92
  /**
98
93
  * 没有选项时的提示
99
94
  */
@@ -1,13 +1,14 @@
1
+ import { HiBaseDataItem } from '@hi-ui/core';
1
2
  import React from 'react';
2
- export interface CheckTreeSelectDataItem {
3
+ export interface CheckTreeSelectDataItem extends HiBaseDataItem {
3
4
  /**
4
5
  * 节点唯一 id
5
6
  */
6
- id: React.ReactText;
7
+ id?: React.ReactText;
7
8
  /**
8
9
  * 节点标题
9
10
  */
10
- title: React.ReactNode;
11
+ title?: React.ReactNode;
11
12
  /**
12
13
  * 子级数据
13
14
  */
@@ -16,6 +17,28 @@ export interface CheckTreeSelectDataItem {
16
17
  * 是否禁用
17
18
  */
18
19
  disabled?: boolean;
20
+ /**
21
+ * 是否为叶子节点
22
+ */
23
+ isLeaf?: boolean;
24
+ }
25
+ export interface FlattedCheckTreeSelectDataItem extends CheckTreeSelectDataItem {
26
+ /**
27
+ * 该节点的子节点列表
28
+ */
29
+ children?: FlattedCheckTreeSelectDataItem[];
30
+ /**
31
+ * 关联用户传入的原始节点
32
+ */
33
+ raw: CheckTreeSelectDataItem;
34
+ /**
35
+ * 该节点的层级,从 0(顶层)开始
36
+ */
37
+ depth: number;
38
+ /**
39
+ * 该节点的父节点
40
+ */
41
+ parent?: FlattedCheckTreeSelectDataItem;
19
42
  }
20
43
  export interface CheckTreeSelectDataSource<T = any> {
21
44
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/check-tree-select",
3
- "version": "4.0.0-beta.29",
3
+ "version": "4.0.0-beta.31",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HIUI <mi-hiui@xiaomi.com>",
@@ -48,18 +48,18 @@
48
48
  "@hi-ui/core": "^4.0.0-beta.8",
49
49
  "@hi-ui/core-css": "^4.0.0-beta.5",
50
50
  "@hi-ui/env": "^4.0.0-beta.0",
51
- "@hi-ui/func-utils": "^4.0.0-beta.11",
52
- "@hi-ui/highlighter": "^4.0.0-beta.8",
51
+ "@hi-ui/func-utils": "^4.0.0-beta.12",
52
+ "@hi-ui/highlighter": "^4.0.0-beta.9",
53
53
  "@hi-ui/icons": "^4.0.0-beta.10",
54
- "@hi-ui/locale-context": "^4.0.0-beta.17",
55
- "@hi-ui/picker": "^4.0.0-beta.22",
56
- "@hi-ui/popper": "^4.0.0-beta.12",
57
- "@hi-ui/tag-input": "^4.0.0-beta.17",
58
- "@hi-ui/tree": "^4.0.0-beta.27",
54
+ "@hi-ui/locale-context": "^4.0.0-beta.18",
55
+ "@hi-ui/picker": "^4.0.0-beta.23",
56
+ "@hi-ui/popper": "^4.0.0-beta.13",
57
+ "@hi-ui/tag-input": "^4.0.0-beta.18",
58
+ "@hi-ui/tree": "^4.0.0-beta.29",
59
59
  "@hi-ui/tree-utils": "^4.0.0-beta.4",
60
60
  "@hi-ui/type-assertion": "^4.0.0-beta.4",
61
61
  "@hi-ui/use-data-source": "^4.0.0-beta.5",
62
- "@hi-ui/use-search-mode": "^4.0.0-beta.16",
62
+ "@hi-ui/use-search-mode": "^4.0.0-beta.18",
63
63
  "@hi-ui/use-toggle": "^4.0.0-beta.4",
64
64
  "@hi-ui/use-uncontrolled-state": "^4.0.0-beta.4"
65
65
  },
@@ -72,5 +72,5 @@
72
72
  "react": "^17.0.1",
73
73
  "react-dom": "^17.0.1"
74
74
  },
75
- "gitHead": "b967631f11b4382d5d5a2581984979f2b6b4d369"
75
+ "gitHead": "7f47840510e6dfce429eeed1591c154e321cd14f"
76
76
  }