@hi-ui/check-tree-select 5.0.0-experimental.1 → 5.0.0-experimental.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.
- package/CHANGELOG.md +37 -0
- package/lib/cjs/CheckTreeSelect.js +51 -14
- package/lib/cjs/hooks/use-check.js +3 -0
- package/lib/cjs/utils/index.js +22 -6
- package/lib/esm/CheckTreeSelect.js +51 -14
- package/lib/esm/hooks/use-check.js +3 -0
- package/lib/esm/utils/index.js +22 -6
- package/lib/types/CheckTreeSelect.d.ts +7 -2
- package/lib/types/types.d.ts +9 -0
- package/package.json +13 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @hi-ui/check-tree-select
|
|
2
2
|
|
|
3
|
+
## 5.0.0-experimental.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 07a57b9c1: feat(check-tree-select): 支持设置 checkable (5.0)
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [07a57b9c1]
|
|
12
|
+
- Updated dependencies [95d930354]
|
|
13
|
+
- @hi-ui/tree@5.0.0-experimental.4
|
|
14
|
+
- @hi-ui/core@5.0.0-experimental.2
|
|
15
|
+
|
|
16
|
+
## 5.0.0-experimental.2
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- 59cef699f: feat: 组件语义化样式改造,增加 styles 和 classNames 属性 (5.0)
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- eb17c4697: style: 修复 UI/样式问题 (5.0)
|
|
25
|
+
- Updated dependencies [7f204c892]
|
|
26
|
+
- Updated dependencies [eb17c4697]
|
|
27
|
+
- Updated dependencies [eb17c4697]
|
|
28
|
+
- Updated dependencies [c407744fe]
|
|
29
|
+
- Updated dependencies [59cef699f]
|
|
30
|
+
- @hi-ui/icons@5.0.0-experimental.1
|
|
31
|
+
- @hi-ui/core@5.0.0-experimental.1
|
|
32
|
+
- @hi-ui/checkbox@5.0.0-experimental.1
|
|
33
|
+
- @hi-ui/highlighter@5.0.0-experimental.1
|
|
34
|
+
- @hi-ui/picker@5.0.0-experimental.2
|
|
35
|
+
- @hi-ui/popper@5.0.0-experimental.1
|
|
36
|
+
- @hi-ui/tag-input@5.0.0-experimental.2
|
|
37
|
+
- @hi-ui/tree@5.0.0-experimental.2
|
|
38
|
+
- @hi-ui/use-merge-semantic@5.0.0-experimental.0
|
|
39
|
+
|
|
3
40
|
## 5.0.0-experimental.1
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
|
@@ -21,6 +21,7 @@ var useToggle = require('@hi-ui/use-toggle');
|
|
|
21
21
|
var tree = require('@hi-ui/tree');
|
|
22
22
|
var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
|
|
23
23
|
var picker = require('@hi-ui/picker');
|
|
24
|
+
var useMergeSemantic = require('@hi-ui/use-merge-semantic');
|
|
24
25
|
var treeUtils = require('@hi-ui/tree-utils');
|
|
25
26
|
var typeAssertion = require('@hi-ui/type-assertion');
|
|
26
27
|
var arrayUtils = require('@hi-ui/array-utils');
|
|
@@ -105,11 +106,30 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
105
106
|
showIndicator = _a$showIndicator === void 0 ? true : _a$showIndicator,
|
|
106
107
|
renderExtraHeader = _a.renderExtraHeader,
|
|
107
108
|
renderExtraFooter = _a.renderExtraFooter,
|
|
108
|
-
|
|
109
|
+
classNamesProp = _a.classNames,
|
|
110
|
+
stylesProp = _a.styles,
|
|
111
|
+
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", "keyword", "onSearch", "clearSearchOnClosed", "clearable", "onClear", "invalid", "displayRender", "placeholder", "appearance", "virtual", "itemHeight", "height", "showCheckAll", "showOnlyShowChecked", "tagInputProps", "size", "customRender", "prefix", "suffix", "label", "showIndicator", "renderExtraHeader", "renderExtraFooter", "classNames", "styles"]);
|
|
109
112
|
var _useGlobalContext = core.useGlobalContext(),
|
|
110
|
-
globalSize = _useGlobalContext.size
|
|
113
|
+
globalSize = _useGlobalContext.size,
|
|
114
|
+
checkTreeSelectConfig = _useGlobalContext.checkTreeSelect;
|
|
111
115
|
var size = (_b = sizeProp !== null && sizeProp !== void 0 ? sizeProp : globalSize) !== null && _b !== void 0 ? _b : 'md';
|
|
112
116
|
var i18n = core.useLocaleContext();
|
|
117
|
+
var _useMergeSemantic = useMergeSemantic.useMergeSemantic({
|
|
118
|
+
classNamesList: [checkTreeSelectConfig === null || checkTreeSelectConfig === void 0 ? void 0 : checkTreeSelectConfig.classNames, classNamesProp],
|
|
119
|
+
stylesList: [checkTreeSelectConfig === null || checkTreeSelectConfig === void 0 ? void 0 : checkTreeSelectConfig.styles, stylesProp],
|
|
120
|
+
info: {
|
|
121
|
+
props: Object.assign(Object.assign({}, rest), {
|
|
122
|
+
data: data,
|
|
123
|
+
disabled: disabled,
|
|
124
|
+
searchable: searchableProp,
|
|
125
|
+
visible: visible,
|
|
126
|
+
size: size,
|
|
127
|
+
appearance: appearance
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
classNames = _useMergeSemantic.classNames,
|
|
132
|
+
styles = _useMergeSemantic.styles;
|
|
113
133
|
var pickerInnerRef = React.useRef(null);
|
|
114
134
|
var placeholder = typeAssertion.isUndef(placeholderProp) ? i18n.get('checkTreeSelect.placeholder') : placeholderProp;
|
|
115
135
|
var _useUncontrolledToggl = useToggle.useUncontrolledToggle({
|
|
@@ -145,6 +165,7 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
145
165
|
flattedNode.title = getKeyFields(raw, 'title');
|
|
146
166
|
flattedNode.disabled = (_a = getKeyFields(raw, 'disabled')) !== null && _a !== void 0 ? _a : false;
|
|
147
167
|
flattedNode.isLeaf = (_b = getKeyFields(raw, 'isLeaf')) !== null && _b !== void 0 ? _b : false;
|
|
168
|
+
flattedNode.checkable = raw.checkable !== false;
|
|
148
169
|
return flattedNode;
|
|
149
170
|
}
|
|
150
171
|
});
|
|
@@ -263,17 +284,17 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
263
284
|
// 全选操作
|
|
264
285
|
if (!currentAllChecked && !hasCheckedAll) {
|
|
265
286
|
tryChangeValue(flattedData.filter(function (item) {
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
if (checkedMode === 'CHILD') {
|
|
269
|
-
return !item.children;
|
|
270
|
-
}
|
|
271
|
-
if (checkedMode === 'PARENT') {
|
|
272
|
-
return item.depth === 0;
|
|
273
|
-
}
|
|
274
|
-
return true;
|
|
287
|
+
if (item.disabled || item.checkable === false) {
|
|
288
|
+
return false;
|
|
275
289
|
}
|
|
276
|
-
|
|
290
|
+
// 根据 checkedMode 类型过滤出已选项,保证全选操作下 onChange 回调的值是符合 checkedMode 的规则
|
|
291
|
+
if (checkedMode === 'CHILD') {
|
|
292
|
+
return !item.children;
|
|
293
|
+
}
|
|
294
|
+
if (checkedMode === 'PARENT') {
|
|
295
|
+
return item.depth === 0;
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
277
298
|
}).map(function (_ref) {
|
|
278
299
|
var id = _ref.id;
|
|
279
300
|
return id;
|
|
@@ -317,10 +338,25 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
317
338
|
(_a = pickerInnerRef.current) === null || _a === void 0 ? void 0 : _a.update();
|
|
318
339
|
}
|
|
319
340
|
}, [menuVisible, treeProps.expandedIds]);
|
|
341
|
+
var pickerSemanticKeys = ['root', 'container', 'panel', 'header', 'search', 'body', 'footer', 'loading', 'empty', 'creator'];
|
|
342
|
+
var pickerClassNames = pickerSemanticKeys.reduce(function (acc, key) {
|
|
343
|
+
if ((classNames === null || classNames === void 0 ? void 0 : classNames[key]) !== undefined) {
|
|
344
|
+
acc[key] = classNames[key];
|
|
345
|
+
}
|
|
346
|
+
return acc;
|
|
347
|
+
}, {});
|
|
348
|
+
var pickerStyles = pickerSemanticKeys.reduce(function (acc, key) {
|
|
349
|
+
if (styles === null || styles === void 0 ? void 0 : styles[key]) {
|
|
350
|
+
acc[key] = styles[key];
|
|
351
|
+
}
|
|
352
|
+
return acc;
|
|
353
|
+
}, {});
|
|
320
354
|
return /*#__PURE__*/React__default["default"].createElement(picker.Picker, Object.assign({
|
|
321
355
|
ref: ref,
|
|
322
356
|
innerRef: pickerInnerRef,
|
|
323
|
-
className: cls
|
|
357
|
+
className: cls,
|
|
358
|
+
classNames: pickerClassNames,
|
|
359
|
+
styles: pickerStyles
|
|
324
360
|
}, rest, {
|
|
325
361
|
visible: menuVisible,
|
|
326
362
|
onOpen: function onOpen() {
|
|
@@ -424,7 +460,8 @@ var CheckTreeSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
424
460
|
// 只做渲染,不做逻辑处理(比如搜索过滤后,check操作的是对过滤后的data操作,这是不符合预期的)
|
|
425
461
|
React__default["default"].createElement(tree.Tree, Object.assign({
|
|
426
462
|
size: 'md',
|
|
427
|
-
className: prefixCls + "__tree",
|
|
463
|
+
className: classname.cx(prefixCls + "__tree", classNames === null || classNames === void 0 ? void 0 : classNames.tree),
|
|
464
|
+
style: styles === null || styles === void 0 ? void 0 : styles.tree,
|
|
428
465
|
selectable: false,
|
|
429
466
|
checkable: true,
|
|
430
467
|
checkOnSelect: true,
|
package/lib/cjs/utils/index.js
CHANGED
|
@@ -120,12 +120,21 @@ function fillCheck(checkedIds, depthEntities, nodeEntities, maxDepth, allowCheck
|
|
|
120
120
|
children = entity.children;
|
|
121
121
|
if (visitedIds.has(id)) return;
|
|
122
122
|
if (typeAssertion.isArrayNonEmpty(children)) {
|
|
123
|
-
|
|
123
|
+
// 可勾选子节点需在 checkedIds;disabled / checkable:false 但有子树时走 visitedIds;
|
|
124
|
+
// checkable:false 且无子节点(纯展示叶)不阻塞父级全选
|
|
125
|
+
var childFails = function childFails(child) {
|
|
126
|
+
if (!allowCheck(child)) {
|
|
127
|
+
if (typeAssertion.isArrayNonEmpty(child.children)) {
|
|
128
|
+
return visitedIds.has(child.id) ? !visitedIds.get(child.id) : true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
124
132
|
if (visitedIds.has(child.id)) {
|
|
125
133
|
return !visitedIds.get(child.id);
|
|
126
134
|
}
|
|
127
135
|
return !checkedIdsSet.has(child.id);
|
|
128
|
-
}
|
|
136
|
+
};
|
|
137
|
+
var shouldChecked = !children.some(childFails);
|
|
129
138
|
visitedIds.set(id, shouldChecked);
|
|
130
139
|
if (shouldChecked && allowCheck(entity)) {
|
|
131
140
|
checkedIdsSet.add(id);
|
|
@@ -148,12 +157,19 @@ var getAllCheckedStatus = function getAllCheckedStatus(flattedData, values) {
|
|
|
148
157
|
treeIdsSet["delete"](id);
|
|
149
158
|
}
|
|
150
159
|
});
|
|
151
|
-
|
|
160
|
+
var nonCheckableCount = flattedData.filter(function (item) {
|
|
161
|
+
return item.disabled || item.checkable === false;
|
|
162
|
+
}).length;
|
|
163
|
+
var onlyNonCheckableLeft = treeIdsSet.size > 0 && [].concat(treeIdsSet).every(function (id) {
|
|
164
|
+
var n = flattedData.find(function (item) {
|
|
165
|
+
return item.id === id;
|
|
166
|
+
});
|
|
167
|
+
return n && (n.disabled || n.checkable === false);
|
|
168
|
+
});
|
|
169
|
+
return [hasValue && (treeIdsSet.size === 0 || onlyNonCheckableLeft), hasValue && treeIdsSet.size > 0 && !onlyNonCheckableLeft,
|
|
152
170
|
// 该值用来判断剩余未选中的节点是否都是 disabled 的
|
|
153
171
|
// 如果为 true 则表示可选值都已选中
|
|
154
|
-
treeIdsSet.size ===
|
|
155
|
-
return item.disabled;
|
|
156
|
-
}).length];
|
|
172
|
+
treeIdsSet.size === nonCheckableCount];
|
|
157
173
|
};
|
|
158
174
|
exports.getAllCheckedStatus = getAllCheckedStatus;
|
|
159
175
|
exports.parseCheckDataDirty = parseCheckDataDirty;
|
|
@@ -15,6 +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 { useMergeSemantic } from '@hi-ui/use-merge-semantic';
|
|
18
19
|
import { baseFlattenTree, filterTree } from '@hi-ui/tree-utils';
|
|
19
20
|
import { isUndef, isArrayNonEmpty } from '@hi-ui/type-assertion';
|
|
20
21
|
import { uniqBy } from '@hi-ui/array-utils';
|
|
@@ -92,11 +93,30 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
92
93
|
showIndicator = _a$showIndicator === void 0 ? true : _a$showIndicator,
|
|
93
94
|
renderExtraHeader = _a.renderExtraHeader,
|
|
94
95
|
renderExtraFooter = _a.renderExtraFooter,
|
|
95
|
-
|
|
96
|
+
classNamesProp = _a.classNames,
|
|
97
|
+
stylesProp = _a.styles,
|
|
98
|
+
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", "keyword", "onSearch", "clearSearchOnClosed", "clearable", "onClear", "invalid", "displayRender", "placeholder", "appearance", "virtual", "itemHeight", "height", "showCheckAll", "showOnlyShowChecked", "tagInputProps", "size", "customRender", "prefix", "suffix", "label", "showIndicator", "renderExtraHeader", "renderExtraFooter", "classNames", "styles"]);
|
|
96
99
|
var _useGlobalContext = useGlobalContext(),
|
|
97
|
-
globalSize = _useGlobalContext.size
|
|
100
|
+
globalSize = _useGlobalContext.size,
|
|
101
|
+
checkTreeSelectConfig = _useGlobalContext.checkTreeSelect;
|
|
98
102
|
var size = (_b = sizeProp !== null && sizeProp !== void 0 ? sizeProp : globalSize) !== null && _b !== void 0 ? _b : 'md';
|
|
99
103
|
var i18n = useLocaleContext();
|
|
104
|
+
var _useMergeSemantic = useMergeSemantic({
|
|
105
|
+
classNamesList: [checkTreeSelectConfig === null || checkTreeSelectConfig === void 0 ? void 0 : checkTreeSelectConfig.classNames, classNamesProp],
|
|
106
|
+
stylesList: [checkTreeSelectConfig === null || checkTreeSelectConfig === void 0 ? void 0 : checkTreeSelectConfig.styles, stylesProp],
|
|
107
|
+
info: {
|
|
108
|
+
props: Object.assign(Object.assign({}, rest), {
|
|
109
|
+
data: data,
|
|
110
|
+
disabled: disabled,
|
|
111
|
+
searchable: searchableProp,
|
|
112
|
+
visible: visible,
|
|
113
|
+
size: size,
|
|
114
|
+
appearance: appearance
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
}),
|
|
118
|
+
classNames = _useMergeSemantic.classNames,
|
|
119
|
+
styles = _useMergeSemantic.styles;
|
|
100
120
|
var pickerInnerRef = useRef(null);
|
|
101
121
|
var placeholder = isUndef(placeholderProp) ? i18n.get('checkTreeSelect.placeholder') : placeholderProp;
|
|
102
122
|
var _useUncontrolledToggl = useUncontrolledToggle({
|
|
@@ -132,6 +152,7 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
132
152
|
flattedNode.title = getKeyFields(raw, 'title');
|
|
133
153
|
flattedNode.disabled = (_a = getKeyFields(raw, 'disabled')) !== null && _a !== void 0 ? _a : false;
|
|
134
154
|
flattedNode.isLeaf = (_b = getKeyFields(raw, 'isLeaf')) !== null && _b !== void 0 ? _b : false;
|
|
155
|
+
flattedNode.checkable = raw.checkable !== false;
|
|
135
156
|
return flattedNode;
|
|
136
157
|
}
|
|
137
158
|
});
|
|
@@ -250,17 +271,17 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
250
271
|
// 全选操作
|
|
251
272
|
if (!currentAllChecked && !hasCheckedAll) {
|
|
252
273
|
tryChangeValue(flattedData.filter(function (item) {
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
if (checkedMode === 'CHILD') {
|
|
256
|
-
return !item.children;
|
|
257
|
-
}
|
|
258
|
-
if (checkedMode === 'PARENT') {
|
|
259
|
-
return item.depth === 0;
|
|
260
|
-
}
|
|
261
|
-
return true;
|
|
274
|
+
if (item.disabled || item.checkable === false) {
|
|
275
|
+
return false;
|
|
262
276
|
}
|
|
263
|
-
|
|
277
|
+
// 根据 checkedMode 类型过滤出已选项,保证全选操作下 onChange 回调的值是符合 checkedMode 的规则
|
|
278
|
+
if (checkedMode === 'CHILD') {
|
|
279
|
+
return !item.children;
|
|
280
|
+
}
|
|
281
|
+
if (checkedMode === 'PARENT') {
|
|
282
|
+
return item.depth === 0;
|
|
283
|
+
}
|
|
284
|
+
return true;
|
|
264
285
|
}).map(function (_ref) {
|
|
265
286
|
var id = _ref.id;
|
|
266
287
|
return id;
|
|
@@ -304,10 +325,25 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
304
325
|
(_a = pickerInnerRef.current) === null || _a === void 0 ? void 0 : _a.update();
|
|
305
326
|
}
|
|
306
327
|
}, [menuVisible, treeProps.expandedIds]);
|
|
328
|
+
var pickerSemanticKeys = ['root', 'container', 'panel', 'header', 'search', 'body', 'footer', 'loading', 'empty', 'creator'];
|
|
329
|
+
var pickerClassNames = pickerSemanticKeys.reduce(function (acc, key) {
|
|
330
|
+
if ((classNames === null || classNames === void 0 ? void 0 : classNames[key]) !== undefined) {
|
|
331
|
+
acc[key] = classNames[key];
|
|
332
|
+
}
|
|
333
|
+
return acc;
|
|
334
|
+
}, {});
|
|
335
|
+
var pickerStyles = pickerSemanticKeys.reduce(function (acc, key) {
|
|
336
|
+
if (styles === null || styles === void 0 ? void 0 : styles[key]) {
|
|
337
|
+
acc[key] = styles[key];
|
|
338
|
+
}
|
|
339
|
+
return acc;
|
|
340
|
+
}, {});
|
|
307
341
|
return /*#__PURE__*/React.createElement(Picker, Object.assign({
|
|
308
342
|
ref: ref,
|
|
309
343
|
innerRef: pickerInnerRef,
|
|
310
|
-
className: cls
|
|
344
|
+
className: cls,
|
|
345
|
+
classNames: pickerClassNames,
|
|
346
|
+
styles: pickerStyles
|
|
311
347
|
}, rest, {
|
|
312
348
|
visible: menuVisible,
|
|
313
349
|
onOpen: function onOpen() {
|
|
@@ -411,7 +447,8 @@ var CheckTreeSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
411
447
|
// 只做渲染,不做逻辑处理(比如搜索过滤后,check操作的是对过滤后的data操作,这是不符合预期的)
|
|
412
448
|
React.createElement(Tree, Object.assign({
|
|
413
449
|
size: 'md',
|
|
414
|
-
className: prefixCls + "__tree",
|
|
450
|
+
className: cx(prefixCls + "__tree", classNames === null || classNames === void 0 ? void 0 : classNames.tree),
|
|
451
|
+
style: styles === null || styles === void 0 ? void 0 : styles.tree,
|
|
415
452
|
selectable: false,
|
|
416
453
|
checkable: true,
|
|
417
454
|
checkOnSelect: true,
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -115,12 +115,21 @@ function fillCheck(checkedIds, depthEntities, nodeEntities, maxDepth, allowCheck
|
|
|
115
115
|
children = entity.children;
|
|
116
116
|
if (visitedIds.has(id)) return;
|
|
117
117
|
if (isArrayNonEmpty(children)) {
|
|
118
|
-
|
|
118
|
+
// 可勾选子节点需在 checkedIds;disabled / checkable:false 但有子树时走 visitedIds;
|
|
119
|
+
// checkable:false 且无子节点(纯展示叶)不阻塞父级全选
|
|
120
|
+
var childFails = function childFails(child) {
|
|
121
|
+
if (!allowCheck(child)) {
|
|
122
|
+
if (isArrayNonEmpty(child.children)) {
|
|
123
|
+
return visitedIds.has(child.id) ? !visitedIds.get(child.id) : true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
119
127
|
if (visitedIds.has(child.id)) {
|
|
120
128
|
return !visitedIds.get(child.id);
|
|
121
129
|
}
|
|
122
130
|
return !checkedIdsSet.has(child.id);
|
|
123
|
-
}
|
|
131
|
+
};
|
|
132
|
+
var shouldChecked = !children.some(childFails);
|
|
124
133
|
visitedIds.set(id, shouldChecked);
|
|
125
134
|
if (shouldChecked && allowCheck(entity)) {
|
|
126
135
|
checkedIdsSet.add(id);
|
|
@@ -143,11 +152,18 @@ var getAllCheckedStatus = function getAllCheckedStatus(flattedData, values) {
|
|
|
143
152
|
treeIdsSet["delete"](id);
|
|
144
153
|
}
|
|
145
154
|
});
|
|
146
|
-
|
|
155
|
+
var nonCheckableCount = flattedData.filter(function (item) {
|
|
156
|
+
return item.disabled || item.checkable === false;
|
|
157
|
+
}).length;
|
|
158
|
+
var onlyNonCheckableLeft = treeIdsSet.size > 0 && [].concat(treeIdsSet).every(function (id) {
|
|
159
|
+
var n = flattedData.find(function (item) {
|
|
160
|
+
return item.id === id;
|
|
161
|
+
});
|
|
162
|
+
return n && (n.disabled || n.checkable === false);
|
|
163
|
+
});
|
|
164
|
+
return [hasValue && (treeIdsSet.size === 0 || onlyNonCheckableLeft), hasValue && treeIdsSet.size > 0 && !onlyNonCheckableLeft,
|
|
147
165
|
// 该值用来判断剩余未选中的节点是否都是 disabled 的
|
|
148
166
|
// 如果为 true 则表示可选值都已选中
|
|
149
|
-
treeIdsSet.size ===
|
|
150
|
-
return item.disabled;
|
|
151
|
-
}).length];
|
|
167
|
+
treeIdsSet.size === nonCheckableCount];
|
|
152
168
|
};
|
|
153
169
|
export { getAllCheckedStatus, parseCheckDataDirty, processCheckedIds };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CheckTreeSelectDataItem, CheckTreeSelectItemEventData, CheckTreeSelectAppearanceEnum } from './types';
|
|
3
3
|
import { FlattedTreeNodeData } from '@hi-ui/tree';
|
|
4
|
-
import { PickerProps } from '@hi-ui/picker';
|
|
4
|
+
import { PickerProps, PickerSemanticName } from '@hi-ui/picker';
|
|
5
|
+
import type { ComponentSemantic, SemanticClassNamesType, SemanticStylesType } from '@hi-ui/use-merge-semantic';
|
|
5
6
|
import { TagInputMockProps } from '@hi-ui/tag-input';
|
|
6
7
|
import { HiBaseSizeEnum } from '@hi-ui/core';
|
|
7
8
|
import { UseDataSource } from '@hi-ui/use-data-source';
|
|
@@ -9,7 +10,11 @@ import { UseDataSource } from '@hi-ui/use-data-source';
|
|
|
9
10
|
* 多项树形选择器
|
|
10
11
|
*/
|
|
11
12
|
export declare const CheckTreeSelect: React.ForwardRefExoticComponent<CheckTreeSelectProps & React.RefAttributes<HTMLDivElement | null>>;
|
|
12
|
-
export
|
|
13
|
+
export type CheckTreeSelectSemanticName = PickerSemanticName | 'tree';
|
|
14
|
+
export type CheckTreeSelectSemanticClassNames = SemanticClassNamesType<CheckTreeSelectProps, CheckTreeSelectSemanticName>;
|
|
15
|
+
export type CheckTreeSelectSemanticStyles = SemanticStylesType<CheckTreeSelectProps, CheckTreeSelectSemanticName>;
|
|
16
|
+
export type CheckTreeSelectSemantic = ComponentSemantic<CheckTreeSelectSemanticClassNames, CheckTreeSelectSemanticStyles>;
|
|
17
|
+
export interface CheckTreeSelectProps extends Omit<PickerProps, 'data' | 'onChange' | 'value' | 'trigger' | 'scrollable' | 'header' | 'footer' | 'classNames' | 'styles'>, CheckTreeSelectSemantic {
|
|
13
18
|
/**
|
|
14
19
|
* 展示数据
|
|
15
20
|
*/
|
package/lib/types/types.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export interface CheckTreeSelectDataItem extends HiBaseDataItem {
|
|
|
22
22
|
* 是否为叶子节点,当 children 为空数组也表示为叶子结点
|
|
23
23
|
*/
|
|
24
24
|
isLeaf?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 节点是否展示复选框;为 `false` 时不展示复选框,且该节点不可被勾选(常用于仅作分组/展开的节点)
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
checkable?: boolean;
|
|
25
30
|
}
|
|
26
31
|
export interface FlattedCheckTreeSelectDataItem extends CheckTreeSelectDataItem {
|
|
27
32
|
/**
|
|
@@ -76,5 +81,9 @@ export interface CheckTreeSelectDataSource<T = any> {
|
|
|
76
81
|
transformResponse?: (response: object) => T;
|
|
77
82
|
}
|
|
78
83
|
export interface CheckTreeSelectItemEventData extends TreeNodeEventData {
|
|
84
|
+
/**
|
|
85
|
+
* 节点是否展示复选框(与数据项 `checkable` 一致,由 Tree 扁平化后透传)
|
|
86
|
+
*/
|
|
87
|
+
checkable?: boolean;
|
|
79
88
|
}
|
|
80
89
|
export type CheckTreeSelectAppearanceEnum = HiBaseAppearanceEnum | 'contained' | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ui/check-tree-select",
|
|
3
|
-
"version": "5.0.0-experimental.
|
|
3
|
+
"version": "5.0.0-experimental.3",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HiUI <mi-hiui@xiaomi.com>",
|
|
@@ -45,32 +45,33 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@hi-ui/array-utils": "^5.0.0-experimental.0",
|
|
48
|
-
"@hi-ui/checkbox": "^5.0.0-experimental.
|
|
48
|
+
"@hi-ui/checkbox": "^5.0.0-experimental.1",
|
|
49
49
|
"@hi-ui/classname": "^5.0.0-experimental.0",
|
|
50
50
|
"@hi-ui/env": "^5.0.0-experimental.0",
|
|
51
51
|
"@hi-ui/func-utils": "^5.0.0-experimental.0",
|
|
52
|
-
"@hi-ui/highlighter": "^5.0.0-experimental.
|
|
53
|
-
"@hi-ui/icons": "^5.0.0-experimental.
|
|
54
|
-
"@hi-ui/picker": "^5.0.0-experimental.
|
|
55
|
-
"@hi-ui/popper": "^5.0.0-experimental.
|
|
56
|
-
"@hi-ui/tag-input": "^5.0.0-experimental.
|
|
57
|
-
"@hi-ui/tree": "^5.0.0-experimental.
|
|
52
|
+
"@hi-ui/highlighter": "^5.0.0-experimental.1",
|
|
53
|
+
"@hi-ui/icons": "^5.0.0-experimental.1",
|
|
54
|
+
"@hi-ui/picker": "^5.0.0-experimental.2",
|
|
55
|
+
"@hi-ui/popper": "^5.0.0-experimental.1",
|
|
56
|
+
"@hi-ui/tag-input": "^5.0.0-experimental.2",
|
|
57
|
+
"@hi-ui/tree": "^5.0.0-experimental.4",
|
|
58
58
|
"@hi-ui/tree-utils": "^5.0.0-experimental.0",
|
|
59
59
|
"@hi-ui/type-assertion": "^5.0.0-experimental.0",
|
|
60
60
|
"@hi-ui/use-check": "^5.0.0-experimental.0",
|
|
61
61
|
"@hi-ui/use-data-source": "^5.0.0-experimental.0",
|
|
62
62
|
"@hi-ui/use-search-mode": "^5.0.0-experimental.0",
|
|
63
63
|
"@hi-ui/use-toggle": "^5.0.0-experimental.0",
|
|
64
|
-
"@hi-ui/use-uncontrolled-state": "^5.0.0-experimental.0"
|
|
64
|
+
"@hi-ui/use-uncontrolled-state": "^5.0.0-experimental.0",
|
|
65
|
+
"@hi-ui/use-merge-semantic": "^5.0.0-experimental.0"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
|
-
"@hi-ui/core": ">=5.0.0-experimental.
|
|
68
|
+
"@hi-ui/core": ">=5.0.0-experimental.2",
|
|
68
69
|
"react": ">=16.8.6",
|
|
69
70
|
"react-dom": ">=16.8.6"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@hi-ui/core": "^5.0.0-experimental.
|
|
73
|
-
"@hi-ui/core-css": "^5.0.0-experimental.
|
|
73
|
+
"@hi-ui/core": "^5.0.0-experimental.2",
|
|
74
|
+
"@hi-ui/core-css": "^5.0.0-experimental.2",
|
|
74
75
|
"react": "^17.0.1",
|
|
75
76
|
"react-dom": "^17.0.1"
|
|
76
77
|
}
|