@hi-ui/check-tree-select 4.3.0 → 4.3.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.
- package/CHANGELOG.md +53 -0
- package/lib/cjs/CheckTreeSelect.js +110 -165
- package/lib/cjs/hooks/use-check.js +31 -44
- package/lib/cjs/index.js +0 -3
- package/lib/cjs/styles/index.scss.js +0 -3
- package/lib/cjs/utils/index.js +10 -36
- package/lib/esm/CheckTreeSelect.js +107 -137
- package/lib/esm/hooks/use-check.js +31 -39
- package/lib/esm/styles/index.scss.js +0 -2
- package/lib/esm/utils/index.js +10 -33
- package/package.json +22 -22
package/lib/esm/utils/index.js
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
*/
|
10
10
|
import { fFindNodeById, getNodeAncestors, findNestedChildren } from '@hi-ui/tree-utils';
|
11
11
|
import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
12
|
+
|
12
13
|
/**
|
13
14
|
* 处理选中的回显数据
|
14
15
|
*
|
@@ -16,18 +17,14 @@ import { isArrayNonEmpty } from '@hi-ui/type-assertion';
|
|
16
17
|
* @param nodeEntries 所有数据的Map 集合
|
17
18
|
* @param type 数据回显方式
|
18
19
|
*/
|
19
|
-
|
20
20
|
var processCheckedIds = function processCheckedIds(type, checkedIds, flattenData, allowCheck) {
|
21
21
|
var keySet = new Set(checkedIds);
|
22
|
-
|
23
22
|
switch (type) {
|
24
23
|
case 'CHILD':
|
25
24
|
return checkedIds.filter(function (id) {
|
26
25
|
var node = fFindNodeById(flattenData, id);
|
27
|
-
|
28
26
|
if (node) {
|
29
27
|
var children = node.children;
|
30
|
-
|
31
28
|
if (isArrayNonEmpty(children)) {
|
32
29
|
if (children.filter(allowCheck).every(function (node) {
|
33
30
|
return keySet.has(node.id);
|
@@ -35,48 +32,38 @@ var processCheckedIds = function processCheckedIds(type, checkedIds, flattenData
|
|
35
32
|
return false;
|
36
33
|
}
|
37
34
|
}
|
38
|
-
}
|
39
|
-
|
40
|
-
|
35
|
+
}
|
36
|
+
// 没有孩子节点,保留
|
41
37
|
return true;
|
42
38
|
});
|
43
|
-
|
44
39
|
case 'PARENT':
|
45
40
|
return checkedIds.filter(function (id) {
|
46
41
|
var node = fFindNodeById(flattenData, id);
|
47
|
-
|
48
42
|
if (node) {
|
49
43
|
// 向上递归遍历是否被勾选
|
50
44
|
var ancestors = getNodeAncestors(node);
|
51
|
-
|
52
45
|
if (ancestors.some(function (parent) {
|
53
46
|
return keySet.has(parent.id);
|
54
47
|
})) {
|
55
48
|
return false;
|
56
49
|
}
|
57
50
|
}
|
58
|
-
|
59
51
|
return true;
|
60
52
|
});
|
61
53
|
}
|
62
|
-
|
63
54
|
return checkedIds;
|
64
55
|
};
|
65
56
|
/**
|
66
57
|
* 根据传入的 checkedIds 解析全选/半选数据
|
67
58
|
*/
|
68
|
-
|
69
|
-
|
70
59
|
var parseCheckDataDirty = function parseCheckDataDirty(type, checkedIds, flattenData, allowCheck) {
|
71
60
|
switch (type) {
|
72
61
|
case 'CHILD':
|
73
62
|
case 'PARENT':
|
74
63
|
return dirtyCheck(checkedIds, flattenData, allowCheck);
|
75
64
|
}
|
76
|
-
|
77
65
|
return checkedIds;
|
78
66
|
};
|
79
|
-
|
80
67
|
function dirtyCheck(checkedIds, flattenData, allowCheck) {
|
81
68
|
var nodeEntities = flattenData.reduce(function (prev, cur) {
|
82
69
|
prev[cur.id] = cur;
|
@@ -86,18 +73,16 @@ function dirtyCheck(checkedIds, flattenData, allowCheck) {
|
|
86
73
|
return !!nodeEntities[id];
|
87
74
|
}));
|
88
75
|
var depthEntities = new Map();
|
89
|
-
var maxDepth = 0;
|
90
|
-
|
76
|
+
var maxDepth = 0;
|
77
|
+
// Convert entities by depth for calculation
|
91
78
|
Object.keys(nodeEntities).forEach(function (id) {
|
92
79
|
var entity = nodeEntities[id];
|
93
80
|
var depth = entity.depth;
|
94
81
|
var depthSet = depthEntities.get(depth);
|
95
|
-
|
96
82
|
if (!depthSet) {
|
97
83
|
depthSet = new Set();
|
98
84
|
depthEntities.set(depth, depthSet);
|
99
85
|
}
|
100
|
-
|
101
86
|
depthSet.add(entity);
|
102
87
|
maxDepth = Math.max(maxDepth, depth);
|
103
88
|
});
|
@@ -109,8 +94,6 @@ function dirtyCheck(checkedIds, flattenData, allowCheck) {
|
|
109
94
|
* 1. 把所有嵌套孩子节点 allowCheck 的都标记为 checked
|
110
95
|
* 2. 祖先节点从下至上维护 checked 状态
|
111
96
|
*/
|
112
|
-
|
113
|
-
|
114
97
|
function fillCheck(checkedIds, depthEntities, nodeEntities, maxDepth, allowCheck) {
|
115
98
|
var checkedIdsSet = new Set(checkedIds);
|
116
99
|
checkedIdsSet.forEach(function (id) {
|
@@ -119,37 +102,31 @@ function fillCheck(checkedIds, depthEntities, nodeEntities, maxDepth, allowCheck
|
|
119
102
|
nestedChildren.forEach(function (child) {
|
120
103
|
checkedIdsSet.add(child.id);
|
121
104
|
});
|
122
|
-
});
|
123
|
-
|
105
|
+
});
|
106
|
+
// 缓存中间结果,优化查询
|
124
107
|
var visitedIds = new Map();
|
125
|
-
|
126
108
|
for (var depth = maxDepth - 1; depth >= 0; --depth) {
|
127
109
|
var entities = depthEntities.get(depth);
|
128
110
|
entities === null || entities === void 0 ? void 0 : entities.forEach(function (entity) {
|
129
111
|
var id = entity.id,
|
130
|
-
|
112
|
+
children = entity.children;
|
131
113
|
if (visitedIds.has(id)) return;
|
132
|
-
|
133
114
|
if (isArrayNonEmpty(children)) {
|
134
115
|
var shouldChecked = !children.some(function (child) {
|
135
116
|
if (visitedIds.has(child.id)) {
|
136
117
|
return !visitedIds.get(child.id);
|
137
118
|
}
|
138
|
-
|
139
119
|
return !checkedIdsSet.has(child.id);
|
140
120
|
});
|
141
121
|
visitedIds.set(id, shouldChecked);
|
142
|
-
|
143
122
|
if (shouldChecked && allowCheck(entity)) {
|
144
123
|
checkedIdsSet.add(id);
|
145
124
|
}
|
146
125
|
}
|
147
126
|
});
|
148
127
|
}
|
149
|
-
|
150
128
|
return Array.from(checkedIdsSet);
|
151
129
|
}
|
152
|
-
|
153
130
|
var getAllCheckedStatus = function getAllCheckedStatus(flattedData, values) {
|
154
131
|
var treeIds = flattedData.map(function (_ref) {
|
155
132
|
var id = _ref.id;
|
@@ -163,11 +140,11 @@ var getAllCheckedStatus = function getAllCheckedStatus(flattedData, values) {
|
|
163
140
|
treeIdsSet["delete"](id);
|
164
141
|
}
|
165
142
|
});
|
166
|
-
return [hasValue && treeIdsSet.size === 0, hasValue && treeIdsSet.size > 0,
|
143
|
+
return [hasValue && treeIdsSet.size === 0, hasValue && treeIdsSet.size > 0,
|
144
|
+
// 该值用来判断剩余未选中的节点是否都是 disabled 的
|
167
145
|
// 如果为 true 则表示可选值都已选中
|
168
146
|
treeIdsSet.size === flattedData.filter(function (item) {
|
169
147
|
return item.disabled;
|
170
148
|
}).length];
|
171
149
|
};
|
172
|
-
|
173
150
|
export { getAllCheckedStatus, parseCheckDataDirty, processCheckedIds };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hi-ui/check-tree-select",
|
3
|
-
"version": "4.3.
|
3
|
+
"version": "4.3.2",
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
5
5
|
"keywords": [],
|
6
6
|
"author": "HiUI <mi-hiui@xiaomi.com>",
|
@@ -43,33 +43,33 @@
|
|
43
43
|
"url": "https://github.com/XiaoMi/hiui/issues"
|
44
44
|
},
|
45
45
|
"dependencies": {
|
46
|
-
"@hi-ui/array-utils": "^4.0.
|
47
|
-
"@hi-ui/checkbox": "^4.0.
|
48
|
-
"@hi-ui/classname": "^4.0.
|
49
|
-
"@hi-ui/env": "^4.0.
|
50
|
-
"@hi-ui/func-utils": "^4.0.
|
51
|
-
"@hi-ui/highlighter": "^4.0.
|
52
|
-
"@hi-ui/icons": "^4.0.
|
53
|
-
"@hi-ui/picker": "^4.1.
|
54
|
-
"@hi-ui/popper": "^4.
|
55
|
-
"@hi-ui/tag-input": "^4.0.
|
56
|
-
"@hi-ui/tree": "^4.5.
|
57
|
-
"@hi-ui/tree-utils": "^4.
|
58
|
-
"@hi-ui/type-assertion": "^4.0.
|
59
|
-
"@hi-ui/use-check": "^4.0.
|
60
|
-
"@hi-ui/use-data-source": "^4.0.
|
61
|
-
"@hi-ui/use-search-mode": "^4.
|
62
|
-
"@hi-ui/use-toggle": "^4.0.
|
63
|
-
"@hi-ui/use-uncontrolled-state": "^4.0.
|
46
|
+
"@hi-ui/array-utils": "^4.0.3",
|
47
|
+
"@hi-ui/checkbox": "^4.0.7",
|
48
|
+
"@hi-ui/classname": "^4.0.3",
|
49
|
+
"@hi-ui/env": "^4.0.3",
|
50
|
+
"@hi-ui/func-utils": "^4.0.3",
|
51
|
+
"@hi-ui/highlighter": "^4.0.7",
|
52
|
+
"@hi-ui/icons": "^4.0.17",
|
53
|
+
"@hi-ui/picker": "^4.1.3",
|
54
|
+
"@hi-ui/popper": "^4.1.2",
|
55
|
+
"@hi-ui/tag-input": "^4.0.9",
|
56
|
+
"@hi-ui/tree": "^4.5.7",
|
57
|
+
"@hi-ui/tree-utils": "^4.1.3",
|
58
|
+
"@hi-ui/type-assertion": "^4.0.3",
|
59
|
+
"@hi-ui/use-check": "^4.0.4",
|
60
|
+
"@hi-ui/use-data-source": "^4.0.3",
|
61
|
+
"@hi-ui/use-search-mode": "^4.1.3",
|
62
|
+
"@hi-ui/use-toggle": "^4.0.3",
|
63
|
+
"@hi-ui/use-uncontrolled-state": "^4.0.3"
|
64
64
|
},
|
65
65
|
"peerDependencies": {
|
66
|
-
"@hi-ui/core": ">=4.0.
|
66
|
+
"@hi-ui/core": ">=4.0.7",
|
67
67
|
"react": ">=16.8.6",
|
68
68
|
"react-dom": ">=16.8.6"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
71
|
-
"@hi-ui/core": "^4.0.
|
72
|
-
"@hi-ui/core-css": "^4.1.
|
71
|
+
"@hi-ui/core": "^4.0.7",
|
72
|
+
"@hi-ui/core-css": "^4.1.4",
|
73
73
|
"react": "^17.0.1",
|
74
74
|
"react-dom": "^17.0.1"
|
75
75
|
}
|