acud 1.0.21 → 1.0.23
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 +148 -0
- package/dist/acud.css +543 -246
- package/dist/acud.css.map +1 -1
- package/dist/acud.js +18653 -17994
- package/dist/acud.js.map +1 -1
- package/dist/acud.min.css +1 -1
- package/dist/acud.min.css.map +1 -1
- package/dist/acud.min.js +11 -11
- package/dist/acud.min.js.map +1 -1
- package/es/avatar/SizeContext.d.ts +10 -0
- package/es/avatar/SizeContext.js +12 -0
- package/es/avatar/avatar.d.ts +25 -0
- package/es/avatar/avatar.js +206 -0
- package/es/avatar/group.d.ts +15 -0
- package/es/avatar/group.js +64 -0
- package/es/avatar/index.d.ts +11 -0
- package/es/avatar/index.js +6 -0
- package/es/avatar/style/css.js +5 -0
- package/es/avatar/style/group.less +17 -0
- package/es/avatar/style/index.css +108 -0
- package/es/avatar/style/index.d.ts +3 -0
- package/es/avatar/style/index.js +5 -0
- package/es/avatar/style/index.less +68 -0
- package/es/avatar/style/rtl.less +15 -0
- package/es/divider/index.d.ts +14 -0
- package/es/divider/index.js +63 -0
- package/es/divider/style/css.js +2 -0
- package/es/divider/style/index.css +126 -0
- package/es/divider/style/index.d.ts +2 -0
- package/es/divider/style/index.js +2 -0
- package/es/divider/style/index.less +137 -0
- package/es/divider/style/rtl.less +38 -0
- package/es/dropdown/style/index.css +4 -4
- package/es/dropdown/style/index.less +5 -5
- package/es/grid/hooks/useBreakpoint.d.ts +1 -1
- package/es/grid/hooks/useBreakpoint.js +11 -9
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/menu/style/index.css +16 -12
- package/es/menu/style/index.less +5 -3
- package/es/menu/style/sider.less +2 -0
- package/es/modal/DialogBox.d.ts +2 -2
- package/es/modal/DialogBox.js +3 -2
- package/es/pagination/rc-pagination/Pagination.js +0 -1
- package/es/style/themes/default/components/avatar.less +13 -0
- package/es/style/themes/default/components/divider.less +6 -0
- package/es/style/themes/default/components/index.less +2 -0
- package/es/table/style/index.css +4 -3
- package/es/table/style/index.less +4 -0
- package/es/tag/style/index.css +46 -0
- package/es/tag/style/index.less +37 -0
- package/es/tree-select/index.d.ts +4 -4
- package/es/tree-select/index.js +1 -1
- package/es/tree-select/src/LegacyContext.d.ts +24 -0
- package/es/tree-select/src/LegacyContext.js +3 -0
- package/es/tree-select/src/OptionList.d.ts +8 -0
- package/es/tree-select/src/OptionList.js +338 -0
- package/es/tree-select/src/TreeNode.d.ts +9 -0
- package/es/tree-select/src/TreeNode.js +6 -0
- package/es/tree-select/src/TreeSelect.d.ts +122 -0
- package/es/tree-select/src/TreeSelect.js +534 -0
- package/es/tree-select/src/TreeSelectContext.d.ts +16 -0
- package/es/tree-select/src/TreeSelectContext.js +3 -0
- package/es/tree-select/src/hooks/useCache.d.ts +7 -0
- package/es/tree-select/src/hooks/useCache.js +29 -0
- package/es/tree-select/src/hooks/useCheckedKeys.d.ts +5 -0
- package/es/tree-select/src/hooks/useCheckedKeys.js +29 -0
- package/es/tree-select/src/hooks/useDataEntities.d.ts +7 -0
- package/es/tree-select/src/hooks/useDataEntities.js +30 -0
- package/es/tree-select/src/hooks/useFilterTreeData.d.ts +7 -0
- package/es/tree-select/src/hooks/useFilterTreeData.js +49 -0
- package/es/tree-select/src/hooks/useRefFunc.d.ts +5 -0
- package/es/tree-select/src/hooks/useRefFunc.js +14 -0
- package/es/tree-select/src/hooks/useTreeData.d.ts +8 -0
- package/es/tree-select/src/hooks/useTreeData.js +55 -0
- package/es/tree-select/src/index.d.ts +7 -0
- package/es/tree-select/src/index.js +9 -0
- package/es/tree-select/src/interface.d.ts +77 -0
- package/es/tree-select/src/interface.js +1 -0
- package/es/tree-select/src/utils/legacyUtil.d.ts +6 -0
- package/es/tree-select/src/utils/legacyUtil.js +144 -0
- package/es/tree-select/src/utils/strategyUtil.d.ts +9 -0
- package/es/tree-select/src/utils/strategyUtil.js +40 -0
- package/es/tree-select/src/utils/valueUtil.d.ts +14 -0
- package/es/tree-select/src/utils/valueUtil.js +46 -0
- package/es/tree-select/src/utils/warningPropsUtil.d.ts +5 -0
- package/es/tree-select/src/utils/warningPropsUtil.js +31 -0
- package/es/tree-select/style/index.css +10 -0
- package/es/tree-select/style/index.less +11 -0
- package/lib/avatar/SizeContext.d.ts +10 -0
- package/lib/avatar/SizeContext.js +26 -0
- package/lib/avatar/avatar.d.ts +25 -0
- package/lib/avatar/avatar.js +233 -0
- package/lib/avatar/group.d.ts +15 -0
- package/lib/avatar/group.js +88 -0
- package/lib/avatar/index.d.ts +11 -0
- package/lib/avatar/index.js +23 -0
- package/lib/avatar/style/css.js +7 -0
- package/lib/avatar/style/group.less +17 -0
- package/lib/avatar/style/index.css +108 -0
- package/lib/avatar/style/index.d.ts +3 -0
- package/lib/avatar/style/index.js +7 -0
- package/lib/avatar/style/index.less +68 -0
- package/lib/avatar/style/rtl.less +15 -0
- package/lib/divider/index.d.ts +14 -0
- package/lib/divider/index.js +74 -0
- package/lib/divider/style/css.js +5 -0
- package/lib/divider/style/index.css +126 -0
- package/lib/divider/style/index.d.ts +2 -0
- package/lib/divider/style/index.js +5 -0
- package/lib/divider/style/index.less +137 -0
- package/lib/divider/style/rtl.less +38 -0
- package/lib/dropdown/style/index.css +4 -4
- package/lib/dropdown/style/index.less +5 -5
- package/lib/grid/hooks/useBreakpoint.d.ts +1 -1
- package/lib/grid/hooks/useBreakpoint.js +11 -9
- package/lib/index.d.ts +2 -0
- package/lib/index.js +16 -0
- package/lib/menu/style/index.css +16 -12
- package/lib/menu/style/index.less +5 -3
- package/lib/menu/style/sider.less +2 -0
- package/lib/modal/DialogBox.d.ts +2 -2
- package/lib/modal/DialogBox.js +3 -2
- package/lib/pagination/rc-pagination/Pagination.js +0 -1
- package/lib/style/components.less +2 -0
- package/lib/style/themes/default/components/avatar.less +13 -0
- package/lib/style/themes/default/components/divider.less +6 -0
- package/lib/style/themes/default/components/index.less +2 -0
- package/lib/table/style/index.css +4 -3
- package/lib/table/style/index.less +4 -0
- package/lib/tag/style/index.css +46 -0
- package/lib/tag/style/index.less +37 -0
- package/lib/tree-select/index.d.ts +4 -4
- package/lib/tree-select/index.js +7 -7
- package/lib/tree-select/src/LegacyContext.d.ts +24 -0
- package/lib/tree-select/src/LegacyContext.js +18 -0
- package/lib/tree-select/src/OptionList.d.ts +8 -0
- package/lib/tree-select/src/OptionList.js +366 -0
- package/lib/tree-select/src/TreeNode.d.ts +9 -0
- package/lib/tree-select/src/TreeNode.js +14 -0
- package/lib/tree-select/src/TreeSelect.d.ts +122 -0
- package/lib/tree-select/src/TreeSelect.js +572 -0
- package/lib/tree-select/src/TreeSelectContext.d.ts +16 -0
- package/lib/tree-select/src/TreeSelectContext.js +18 -0
- package/lib/tree-select/src/hooks/useCache.d.ts +7 -0
- package/lib/tree-select/src/hooks/useCache.js +47 -0
- package/lib/tree-select/src/hooks/useCheckedKeys.d.ts +5 -0
- package/lib/tree-select/src/hooks/useCheckedKeys.js +49 -0
- package/lib/tree-select/src/hooks/useDataEntities.d.ts +7 -0
- package/lib/tree-select/src/hooks/useDataEntities.js +52 -0
- package/lib/tree-select/src/hooks/useFilterTreeData.d.ts +7 -0
- package/lib/tree-select/src/hooks/useFilterTreeData.js +70 -0
- package/lib/tree-select/src/hooks/useRefFunc.d.ts +5 -0
- package/lib/tree-select/src/hooks/useRefFunc.js +27 -0
- package/lib/tree-select/src/hooks/useTreeData.d.ts +8 -0
- package/lib/tree-select/src/hooks/useTreeData.js +71 -0
- package/lib/tree-select/src/index.d.ts +7 -0
- package/lib/tree-select/src/index.js +45 -0
- package/lib/tree-select/src/interface.d.ts +77 -0
- package/lib/tree-select/src/interface.js +5 -0
- package/lib/tree-select/src/utils/legacyUtil.d.ts +6 -0
- package/lib/tree-select/src/utils/legacyUtil.js +166 -0
- package/lib/tree-select/src/utils/strategyUtil.d.ts +9 -0
- package/lib/tree-select/src/utils/strategyUtil.js +53 -0
- package/lib/tree-select/src/utils/valueUtil.d.ts +14 -0
- package/lib/tree-select/src/utils/valueUtil.js +61 -0
- package/lib/tree-select/src/utils/warningPropsUtil.d.ts +5 -0
- package/lib/tree-select/src/utils/warningPropsUtil.js +43 -0
- package/lib/tree-select/style/index.css +10 -0
- package/lib/tree-select/style/index.less +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
5
|
+
|
|
6
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
7
|
+
var t = {};
|
|
8
|
+
|
|
9
|
+
for (var p in s) {
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
14
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
15
|
+
}
|
|
16
|
+
return t;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
import * as React from 'react';
|
|
20
|
+
import { BaseSelect } from 'rc-select';
|
|
21
|
+
import { conductCheck } from "rc-tree/es/utils/conductUtil";
|
|
22
|
+
import useId from "rc-select/es/hooks/useId";
|
|
23
|
+
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
24
|
+
import OptionList from './OptionList';
|
|
25
|
+
import TreeNode from './TreeNode';
|
|
26
|
+
import { formatStrategyValues, SHOW_ALL, SHOW_PARENT, SHOW_CHILD } from './utils/strategyUtil';
|
|
27
|
+
import TreeSelectContext from './TreeSelectContext';
|
|
28
|
+
import LegacyContext from './LegacyContext';
|
|
29
|
+
import useTreeData from './hooks/useTreeData';
|
|
30
|
+
import { toArray, fillFieldNames, isNil } from './utils/valueUtil';
|
|
31
|
+
import useCache from './hooks/useCache';
|
|
32
|
+
import useRefFunc from './hooks/useRefFunc';
|
|
33
|
+
import useDataEntities from './hooks/useDataEntities';
|
|
34
|
+
import { fillAdditionalInfo, fillLegacyProps } from './utils/legacyUtil';
|
|
35
|
+
import useCheckedKeys from './hooks/useCheckedKeys';
|
|
36
|
+
import useFilterTreeData from './hooks/useFilterTreeData';
|
|
37
|
+
import warningProps from './utils/warningPropsUtil';
|
|
38
|
+
import warning from "rc-util/es/warning";
|
|
39
|
+
|
|
40
|
+
function isRawValue(value) {
|
|
41
|
+
return !value || _typeof(value) !== 'object';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var TreeSelect = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
45
|
+
var id = props.id,
|
|
46
|
+
_props$prefixCls = props.prefixCls,
|
|
47
|
+
prefixCls = _props$prefixCls === void 0 ? 'rc-tree-select' : _props$prefixCls,
|
|
48
|
+
value = props.value,
|
|
49
|
+
defaultValue = props.defaultValue,
|
|
50
|
+
onChange = props.onChange,
|
|
51
|
+
onSelect = props.onSelect,
|
|
52
|
+
onDeselect = props.onDeselect,
|
|
53
|
+
searchValue = props.searchValue,
|
|
54
|
+
inputValue = props.inputValue,
|
|
55
|
+
onSearch = props.onSearch,
|
|
56
|
+
_props$autoClearSearc = props.autoClearSearchValue,
|
|
57
|
+
autoClearSearchValue = _props$autoClearSearc === void 0 ? true : _props$autoClearSearc,
|
|
58
|
+
filterTreeNode = props.filterTreeNode,
|
|
59
|
+
_props$treeNodeFilter = props.treeNodeFilterProp,
|
|
60
|
+
treeNodeFilterProp = _props$treeNodeFilter === void 0 ? 'value' : _props$treeNodeFilter,
|
|
61
|
+
_props$showCheckedStr = props.showCheckedStrategy,
|
|
62
|
+
showCheckedStrategy = _props$showCheckedStr === void 0 ? SHOW_CHILD : _props$showCheckedStr,
|
|
63
|
+
treeNodeLabelProp = props.treeNodeLabelProp,
|
|
64
|
+
multiple = props.multiple,
|
|
65
|
+
treeCheckable = props.treeCheckable,
|
|
66
|
+
treeCheckStrictly = props.treeCheckStrictly,
|
|
67
|
+
labelInValue = props.labelInValue,
|
|
68
|
+
fieldNames = props.fieldNames,
|
|
69
|
+
treeDataSimpleMode = props.treeDataSimpleMode,
|
|
70
|
+
treeData = props.treeData,
|
|
71
|
+
children = props.children,
|
|
72
|
+
loadData = props.loadData,
|
|
73
|
+
treeLoadedKeys = props.treeLoadedKeys,
|
|
74
|
+
onTreeLoad = props.onTreeLoad,
|
|
75
|
+
treeDefaultExpandAll = props.treeDefaultExpandAll,
|
|
76
|
+
treeExpandedKeys = props.treeExpandedKeys,
|
|
77
|
+
treeDefaultExpandedKeys = props.treeDefaultExpandedKeys,
|
|
78
|
+
onTreeExpand = props.onTreeExpand,
|
|
79
|
+
treeExpandAction = props.treeExpandAction,
|
|
80
|
+
virtual = props.virtual,
|
|
81
|
+
_props$listHeight = props.listHeight,
|
|
82
|
+
listHeight = _props$listHeight === void 0 ? 200 : _props$listHeight,
|
|
83
|
+
_props$listItemHeight = props.listItemHeight,
|
|
84
|
+
listItemHeight = _props$listItemHeight === void 0 ? 20 : _props$listItemHeight,
|
|
85
|
+
onDropdownVisibleChange = props.onDropdownVisibleChange,
|
|
86
|
+
_props$dropdownMatchS = props.dropdownMatchSelectWidth,
|
|
87
|
+
dropdownMatchSelectWidth = _props$dropdownMatchS === void 0 ? true : _props$dropdownMatchS,
|
|
88
|
+
treeLine = props.treeLine,
|
|
89
|
+
treeIcon = props.treeIcon,
|
|
90
|
+
showTreeIcon = props.showTreeIcon,
|
|
91
|
+
switcherIcon = props.switcherIcon,
|
|
92
|
+
treeMotion = props.treeMotion,
|
|
93
|
+
restProps = __rest(props, ["id", "prefixCls", "value", "defaultValue", "onChange", "onSelect", "onDeselect", "searchValue", "inputValue", "onSearch", "autoClearSearchValue", "filterTreeNode", "treeNodeFilterProp", "showCheckedStrategy", "treeNodeLabelProp", "multiple", "treeCheckable", "treeCheckStrictly", "labelInValue", "fieldNames", "treeDataSimpleMode", "treeData", "children", "loadData", "treeLoadedKeys", "onTreeLoad", "treeDefaultExpandAll", "treeExpandedKeys", "treeDefaultExpandedKeys", "onTreeExpand", "treeExpandAction", "virtual", "listHeight", "listItemHeight", "onDropdownVisibleChange", "dropdownMatchSelectWidth", "treeLine", "treeIcon", "showTreeIcon", "switcherIcon", "treeMotion"]);
|
|
94
|
+
|
|
95
|
+
var mergedId = useId(id);
|
|
96
|
+
var treeConduction = treeCheckable && !treeCheckStrictly;
|
|
97
|
+
var mergedCheckable = treeCheckable || treeCheckStrictly;
|
|
98
|
+
var mergedLabelInValue = treeCheckStrictly || labelInValue;
|
|
99
|
+
var mergedMultiple = mergedCheckable || multiple; // ========================== Warning ===========================
|
|
100
|
+
|
|
101
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
102
|
+
warningProps(props);
|
|
103
|
+
} // ========================= FieldNames =========================
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
var mergedFieldNames = React.useMemo(function () {
|
|
107
|
+
return fillFieldNames(fieldNames);
|
|
108
|
+
},
|
|
109
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
110
|
+
[JSON.stringify(fieldNames)]); // =========================== Search ===========================
|
|
111
|
+
|
|
112
|
+
var _useMergedState = useMergedState('', {
|
|
113
|
+
value: searchValue !== undefined ? searchValue : inputValue,
|
|
114
|
+
postState: function postState(search) {
|
|
115
|
+
return search || '';
|
|
116
|
+
}
|
|
117
|
+
}),
|
|
118
|
+
_useMergedState2 = _slicedToArray(_useMergedState, 2),
|
|
119
|
+
mergedSearchValue = _useMergedState2[0],
|
|
120
|
+
setSearchValue = _useMergedState2[1];
|
|
121
|
+
|
|
122
|
+
var onInternalSearch = function onInternalSearch(searchText) {
|
|
123
|
+
setSearchValue(searchText);
|
|
124
|
+
onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchText);
|
|
125
|
+
}; // ============================ Data ============================
|
|
126
|
+
// `useTreeData` only do convert of `children` or `simpleMode`.
|
|
127
|
+
// Else will return origin `treeData` for perf consideration.
|
|
128
|
+
// Do not do anything to loop the data.
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
var mergedTreeData = useTreeData(treeData, children, treeDataSimpleMode);
|
|
132
|
+
|
|
133
|
+
var _useDataEntities = useDataEntities(mergedTreeData, mergedFieldNames),
|
|
134
|
+
keyEntities = _useDataEntities.keyEntities,
|
|
135
|
+
valueEntities = _useDataEntities.valueEntities;
|
|
136
|
+
/** Get `missingRawValues` which not exist in the tree yet */
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
var splitRawValues = React.useCallback(function (newRawValues) {
|
|
140
|
+
var missingRawValues = [];
|
|
141
|
+
var existRawValues = []; // Keep missing value in the cache
|
|
142
|
+
|
|
143
|
+
newRawValues.forEach(function (val) {
|
|
144
|
+
if (valueEntities.has(val)) {
|
|
145
|
+
existRawValues.push(val);
|
|
146
|
+
} else {
|
|
147
|
+
missingRawValues.push(val);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
missingRawValues: missingRawValues,
|
|
152
|
+
existRawValues: existRawValues
|
|
153
|
+
};
|
|
154
|
+
}, [valueEntities]); // Filtered Tree
|
|
155
|
+
|
|
156
|
+
var filteredTreeData = useFilterTreeData(mergedTreeData, mergedSearchValue, {
|
|
157
|
+
fieldNames: mergedFieldNames,
|
|
158
|
+
treeNodeFilterProp: treeNodeFilterProp,
|
|
159
|
+
filterTreeNode: filterTreeNode
|
|
160
|
+
}); // =========================== Label ============================
|
|
161
|
+
|
|
162
|
+
var getLabel = React.useCallback(function (item) {
|
|
163
|
+
if (item) {
|
|
164
|
+
if (treeNodeLabelProp) {
|
|
165
|
+
return item[treeNodeLabelProp];
|
|
166
|
+
} // Loop from fieldNames
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
var titleList = mergedFieldNames._title;
|
|
170
|
+
|
|
171
|
+
for (var i = 0; i < titleList.length; i += 1) {
|
|
172
|
+
var title = item[titleList[i]];
|
|
173
|
+
|
|
174
|
+
if (title !== undefined) {
|
|
175
|
+
return title;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, [mergedFieldNames, treeNodeLabelProp]); // ========================= Wrap Value =========================
|
|
180
|
+
|
|
181
|
+
var toLabeledValues = React.useCallback(function (draftValues) {
|
|
182
|
+
var values = toArray(draftValues);
|
|
183
|
+
return values.map(function (val) {
|
|
184
|
+
if (isRawValue(val)) {
|
|
185
|
+
return {
|
|
186
|
+
value: val
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return val;
|
|
191
|
+
});
|
|
192
|
+
}, []);
|
|
193
|
+
var convert2LabelValues = React.useCallback(function (draftValues) {
|
|
194
|
+
var values = toLabeledValues(draftValues);
|
|
195
|
+
return values.map(function (item) {
|
|
196
|
+
var rawLabel = item.label;
|
|
197
|
+
var rawValue = item.value,
|
|
198
|
+
rawHalfChecked = item.halfChecked;
|
|
199
|
+
var rawDisabled;
|
|
200
|
+
var entity = valueEntities.get(rawValue); // Fill missing label & status
|
|
201
|
+
|
|
202
|
+
if (entity) {
|
|
203
|
+
rawLabel = rawLabel !== null && rawLabel !== void 0 ? rawLabel : getLabel(entity.node);
|
|
204
|
+
rawDisabled = entity.node.disabled;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
label: rawLabel,
|
|
209
|
+
value: rawValue,
|
|
210
|
+
halfChecked: rawHalfChecked,
|
|
211
|
+
disabled: rawDisabled
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
}, [valueEntities, getLabel, toLabeledValues]); // =========================== Values ===========================
|
|
215
|
+
|
|
216
|
+
var _useMergedState3 = useMergedState(defaultValue, {
|
|
217
|
+
value: value
|
|
218
|
+
}),
|
|
219
|
+
_useMergedState4 = _slicedToArray(_useMergedState3, 2),
|
|
220
|
+
internalValue = _useMergedState4[0],
|
|
221
|
+
setInternalValue = _useMergedState4[1];
|
|
222
|
+
|
|
223
|
+
var rawMixedLabeledValues = React.useMemo(function () {
|
|
224
|
+
return toLabeledValues(internalValue);
|
|
225
|
+
}, [toLabeledValues, internalValue]); // Split value into full check and half check
|
|
226
|
+
|
|
227
|
+
var _React$useMemo = React.useMemo(function () {
|
|
228
|
+
var fullCheckValues = [];
|
|
229
|
+
var halfCheckValues = [];
|
|
230
|
+
rawMixedLabeledValues.forEach(function (item) {
|
|
231
|
+
if (item.halfChecked) {
|
|
232
|
+
halfCheckValues.push(item);
|
|
233
|
+
} else {
|
|
234
|
+
fullCheckValues.push(item);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
return [fullCheckValues, halfCheckValues];
|
|
238
|
+
}, [rawMixedLabeledValues]),
|
|
239
|
+
_React$useMemo2 = _slicedToArray(_React$useMemo, 2),
|
|
240
|
+
rawLabeledValues = _React$useMemo2[0],
|
|
241
|
+
rawHalfLabeledValues = _React$useMemo2[1]; // const [mergedValues] = useCache(rawLabeledValues);
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
var rawValues = React.useMemo(function () {
|
|
245
|
+
return rawLabeledValues.map(function (item) {
|
|
246
|
+
return item.value;
|
|
247
|
+
});
|
|
248
|
+
}, [rawLabeledValues]); // Convert value to key. Will fill missed keys for conduct check.
|
|
249
|
+
|
|
250
|
+
var _useCheckedKeys = useCheckedKeys(rawLabeledValues, rawHalfLabeledValues, treeConduction, keyEntities),
|
|
251
|
+
_useCheckedKeys2 = _slicedToArray(_useCheckedKeys, 2),
|
|
252
|
+
rawCheckedValues = _useCheckedKeys2[0],
|
|
253
|
+
rawHalfCheckedValues = _useCheckedKeys2[1]; // Convert rawCheckedKeys to check strategy related values
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
var displayValues = React.useMemo(function () {
|
|
257
|
+
// Collect keys which need to show
|
|
258
|
+
var displayKeys = formatStrategyValues(rawCheckedValues, showCheckedStrategy, keyEntities, mergedFieldNames); // Convert to value and filled with label
|
|
259
|
+
|
|
260
|
+
var values = displayKeys.map(function (key) {
|
|
261
|
+
var _a, _b, _c;
|
|
262
|
+
|
|
263
|
+
return (_c = (_b = (_a = keyEntities[key]) === null || _a === void 0 ? void 0 : _a.node) === null || _b === void 0 ? void 0 : _b[mergedFieldNames.value]) !== null && _c !== void 0 ? _c : key;
|
|
264
|
+
}); // Back fill with origin label
|
|
265
|
+
|
|
266
|
+
var labeledValues = values.map(function (val) {
|
|
267
|
+
var targetItem = rawLabeledValues.find(function (item) {
|
|
268
|
+
return item.value === val;
|
|
269
|
+
});
|
|
270
|
+
return {
|
|
271
|
+
value: val,
|
|
272
|
+
label: targetItem === null || targetItem === void 0 ? void 0 : targetItem.label
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
var rawDisplayValues = convert2LabelValues(labeledValues);
|
|
276
|
+
var firstVal = rawDisplayValues[0];
|
|
277
|
+
|
|
278
|
+
if (!mergedMultiple && firstVal && isNil(firstVal.value) && isNil(firstVal.label)) {
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return rawDisplayValues.map(function (item) {
|
|
283
|
+
var _a;
|
|
284
|
+
|
|
285
|
+
return _extends(_extends({}, item), {
|
|
286
|
+
label: (_a = item.label) !== null && _a !== void 0 ? _a : item.value
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}, [mergedFieldNames, mergedMultiple, rawCheckedValues, rawLabeledValues, convert2LabelValues, showCheckedStrategy, keyEntities]);
|
|
290
|
+
|
|
291
|
+
var _useCache = useCache(displayValues),
|
|
292
|
+
_useCache2 = _slicedToArray(_useCache, 1),
|
|
293
|
+
cachedDisplayValues = _useCache2[0]; // =========================== Change ===========================
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
var triggerChange = useRefFunc(function (newRawValues, extra, source) {
|
|
297
|
+
var labeledValues = convert2LabelValues(newRawValues);
|
|
298
|
+
setInternalValue(labeledValues); // Clean up if needed
|
|
299
|
+
|
|
300
|
+
if (autoClearSearchValue) {
|
|
301
|
+
setSearchValue('');
|
|
302
|
+
} // Generate rest parameters is costly, so only do it when necessary
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
if (onChange) {
|
|
306
|
+
var eventValues = newRawValues;
|
|
307
|
+
|
|
308
|
+
if (treeConduction) {
|
|
309
|
+
var formattedKeyList = formatStrategyValues(newRawValues, showCheckedStrategy, keyEntities, mergedFieldNames);
|
|
310
|
+
eventValues = formattedKeyList.map(function (key) {
|
|
311
|
+
var entity = valueEntities.get(key);
|
|
312
|
+
return entity ? entity.node[mergedFieldNames.value] : key;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
var _ref = extra || {
|
|
317
|
+
triggerValue: undefined,
|
|
318
|
+
selected: undefined
|
|
319
|
+
},
|
|
320
|
+
triggerValue = _ref.triggerValue,
|
|
321
|
+
selected = _ref.selected;
|
|
322
|
+
|
|
323
|
+
var returnRawValues = eventValues; // We need fill half check back
|
|
324
|
+
|
|
325
|
+
if (treeCheckStrictly) {
|
|
326
|
+
var halfValues = rawHalfLabeledValues.filter(function (item) {
|
|
327
|
+
return !eventValues.includes(item.value);
|
|
328
|
+
});
|
|
329
|
+
returnRawValues = [].concat(_toConsumableArray(returnRawValues), _toConsumableArray(halfValues));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
var returnLabeledValues = convert2LabelValues(returnRawValues);
|
|
333
|
+
var additionalInfo = {
|
|
334
|
+
// [Legacy] Always return as array contains label & value
|
|
335
|
+
preValue: rawLabeledValues,
|
|
336
|
+
triggerValue: triggerValue
|
|
337
|
+
}; // [Legacy] Fill legacy data if user query.
|
|
338
|
+
// This is expansive that we only fill when user query
|
|
339
|
+
// https://github.com/react-component/tree-select/blob/fe33eb7c27830c9ac70cd1fdb1ebbe7bc679c16a/src/Select.jsx
|
|
340
|
+
|
|
341
|
+
var showPosition = true;
|
|
342
|
+
|
|
343
|
+
if (treeCheckStrictly || source === 'selection' && !selected) {
|
|
344
|
+
showPosition = false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
fillAdditionalInfo(additionalInfo, triggerValue, newRawValues, mergedTreeData, showPosition, mergedFieldNames);
|
|
348
|
+
|
|
349
|
+
if (mergedCheckable) {
|
|
350
|
+
additionalInfo.checked = selected;
|
|
351
|
+
} else {
|
|
352
|
+
additionalInfo.selected = selected;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
var returnValues = mergedLabelInValue ? returnLabeledValues : returnLabeledValues.map(function (item) {
|
|
356
|
+
return item.value;
|
|
357
|
+
});
|
|
358
|
+
onChange(mergedMultiple ? returnValues : returnValues[0], mergedLabelInValue ? null : returnLabeledValues.map(function (item) {
|
|
359
|
+
return item.label;
|
|
360
|
+
}), additionalInfo);
|
|
361
|
+
}
|
|
362
|
+
}); // ========================== Options ===========================
|
|
363
|
+
|
|
364
|
+
/** Trigger by option list */
|
|
365
|
+
|
|
366
|
+
var onOptionSelect = React.useCallback(function (selectedKey, _ref2) {
|
|
367
|
+
var selected = _ref2.selected,
|
|
368
|
+
source = _ref2.source;
|
|
369
|
+
|
|
370
|
+
var _a;
|
|
371
|
+
|
|
372
|
+
var entity = keyEntities[selectedKey];
|
|
373
|
+
var node = entity === null || entity === void 0 ? void 0 : entity.node;
|
|
374
|
+
var selectedValue = (_a = node === null || node === void 0 ? void 0 : node[mergedFieldNames.value]) !== null && _a !== void 0 ? _a : selectedKey; // Never be falsy but keep it safe
|
|
375
|
+
|
|
376
|
+
if (!mergedMultiple) {
|
|
377
|
+
// Single mode always set value
|
|
378
|
+
triggerChange([selectedValue], {
|
|
379
|
+
selected: true,
|
|
380
|
+
triggerValue: selectedValue
|
|
381
|
+
}, 'option');
|
|
382
|
+
} else {
|
|
383
|
+
var newRawValues = selected ? [].concat(_toConsumableArray(rawValues), [selectedValue]) : rawCheckedValues.filter(function (v) {
|
|
384
|
+
return v !== selectedValue;
|
|
385
|
+
}); // Add keys if tree conduction
|
|
386
|
+
|
|
387
|
+
if (treeConduction) {
|
|
388
|
+
// Should keep missing values
|
|
389
|
+
var _splitRawValues = splitRawValues(newRawValues),
|
|
390
|
+
missingRawValues = _splitRawValues.missingRawValues,
|
|
391
|
+
existRawValues = _splitRawValues.existRawValues;
|
|
392
|
+
|
|
393
|
+
var keyList = existRawValues.map(function (val) {
|
|
394
|
+
return valueEntities.get(val).key;
|
|
395
|
+
}); // Conduction by selected or not
|
|
396
|
+
|
|
397
|
+
var checkedKeys;
|
|
398
|
+
|
|
399
|
+
if (selected) {
|
|
400
|
+
var _conductCheck = conductCheck(keyList, true, keyEntities);
|
|
401
|
+
|
|
402
|
+
checkedKeys = _conductCheck.checkedKeys;
|
|
403
|
+
} else {
|
|
404
|
+
var _conductCheck2 = conductCheck(keyList, {
|
|
405
|
+
checked: false,
|
|
406
|
+
halfCheckedKeys: rawHalfCheckedValues
|
|
407
|
+
}, keyEntities);
|
|
408
|
+
|
|
409
|
+
checkedKeys = _conductCheck2.checkedKeys;
|
|
410
|
+
} // Fill back of keys
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
newRawValues = [].concat(_toConsumableArray(missingRawValues), _toConsumableArray(checkedKeys.map(function (key) {
|
|
414
|
+
return keyEntities[key].node[mergedFieldNames.value];
|
|
415
|
+
})));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
triggerChange(newRawValues, {
|
|
419
|
+
selected: selected,
|
|
420
|
+
triggerValue: selectedValue
|
|
421
|
+
}, source || 'option');
|
|
422
|
+
} // Trigger select event
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
if (selected || !mergedMultiple) {
|
|
426
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(selectedValue, fillLegacyProps(node));
|
|
427
|
+
} else {
|
|
428
|
+
onDeselect === null || onDeselect === void 0 ? void 0 : onDeselect(selectedValue, fillLegacyProps(node));
|
|
429
|
+
}
|
|
430
|
+
}, [splitRawValues, valueEntities, keyEntities, mergedFieldNames, mergedMultiple, rawValues, triggerChange, treeConduction, onSelect, onDeselect, rawCheckedValues, rawHalfCheckedValues]); // ========================== Dropdown ==========================
|
|
431
|
+
|
|
432
|
+
var onInternalDropdownVisibleChange = React.useCallback(function (open) {
|
|
433
|
+
if (onDropdownVisibleChange) {
|
|
434
|
+
var legacyParam = {};
|
|
435
|
+
Object.defineProperty(legacyParam, 'documentClickClose', {
|
|
436
|
+
get: function get() {
|
|
437
|
+
warning(false, 'Second param of `onDropdownVisibleChange` has been removed.');
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
onDropdownVisibleChange(open, legacyParam);
|
|
442
|
+
}
|
|
443
|
+
}, [onDropdownVisibleChange]); // ====================== Display Change ========================
|
|
444
|
+
|
|
445
|
+
var onDisplayValuesChange = useRefFunc(function (newValues, info) {
|
|
446
|
+
var newRawValues = newValues.map(function (item) {
|
|
447
|
+
return item.value;
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
if (info.type === 'clear') {
|
|
451
|
+
triggerChange(newRawValues, {}, 'selection');
|
|
452
|
+
return;
|
|
453
|
+
} // TreeSelect only have multiple mode which means display change only has remove
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
if (info.values.length) {
|
|
457
|
+
onOptionSelect(info.values[0].value, {
|
|
458
|
+
selected: false,
|
|
459
|
+
source: 'selection'
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}); // ========================== Context ===========================
|
|
463
|
+
|
|
464
|
+
var treeSelectContext = React.useMemo(function () {
|
|
465
|
+
return {
|
|
466
|
+
virtual: virtual,
|
|
467
|
+
dropdownMatchSelectWidth: dropdownMatchSelectWidth,
|
|
468
|
+
listHeight: listHeight,
|
|
469
|
+
listItemHeight: listItemHeight,
|
|
470
|
+
treeData: filteredTreeData,
|
|
471
|
+
fieldNames: mergedFieldNames,
|
|
472
|
+
onSelect: onOptionSelect,
|
|
473
|
+
triggerChange: triggerChange,
|
|
474
|
+
treeExpandAction: treeExpandAction
|
|
475
|
+
};
|
|
476
|
+
}, [virtual, dropdownMatchSelectWidth, listHeight, listItemHeight, filteredTreeData, mergedFieldNames, onOptionSelect, treeExpandAction]); // ======================= Legacy Context =======================
|
|
477
|
+
|
|
478
|
+
var legacyContext = React.useMemo(function () {
|
|
479
|
+
return {
|
|
480
|
+
checkable: mergedCheckable,
|
|
481
|
+
loadData: loadData,
|
|
482
|
+
treeLoadedKeys: treeLoadedKeys,
|
|
483
|
+
onTreeLoad: onTreeLoad,
|
|
484
|
+
checkedKeys: rawCheckedValues,
|
|
485
|
+
halfCheckedKeys: rawHalfCheckedValues,
|
|
486
|
+
treeDefaultExpandAll: treeDefaultExpandAll,
|
|
487
|
+
treeExpandedKeys: treeExpandedKeys,
|
|
488
|
+
treeDefaultExpandedKeys: treeDefaultExpandedKeys,
|
|
489
|
+
onTreeExpand: onTreeExpand,
|
|
490
|
+
treeIcon: treeIcon,
|
|
491
|
+
treeMotion: treeMotion,
|
|
492
|
+
showTreeIcon: showTreeIcon,
|
|
493
|
+
switcherIcon: switcherIcon,
|
|
494
|
+
treeLine: treeLine,
|
|
495
|
+
treeNodeFilterProp: treeNodeFilterProp,
|
|
496
|
+
keyEntities: keyEntities
|
|
497
|
+
};
|
|
498
|
+
}, [mergedCheckable, loadData, treeLoadedKeys, onTreeLoad, rawCheckedValues, rawHalfCheckedValues, treeDefaultExpandAll, treeExpandedKeys, treeDefaultExpandedKeys, onTreeExpand, treeIcon, treeMotion, showTreeIcon, switcherIcon, treeLine, treeNodeFilterProp, keyEntities]); // =========================== Render ===========================
|
|
499
|
+
|
|
500
|
+
return /*#__PURE__*/React.createElement(TreeSelectContext.Provider, {
|
|
501
|
+
value: treeSelectContext
|
|
502
|
+
}, /*#__PURE__*/React.createElement(LegacyContext.Provider, {
|
|
503
|
+
value: legacyContext
|
|
504
|
+
}, /*#__PURE__*/React.createElement(BaseSelect, _extends({
|
|
505
|
+
ref: ref
|
|
506
|
+
}, restProps, {
|
|
507
|
+
// >>> MISC
|
|
508
|
+
id: mergedId,
|
|
509
|
+
prefixCls: prefixCls,
|
|
510
|
+
mode: mergedMultiple ? 'multiple' : undefined // >>> Display Value
|
|
511
|
+
,
|
|
512
|
+
displayValues: cachedDisplayValues,
|
|
513
|
+
onDisplayValuesChange: onDisplayValuesChange // >>> Search
|
|
514
|
+
,
|
|
515
|
+
searchValue: mergedSearchValue,
|
|
516
|
+
onSearch: onInternalSearch // >>> Options
|
|
517
|
+
,
|
|
518
|
+
OptionList: OptionList,
|
|
519
|
+
emptyOptions: !mergedTreeData.length,
|
|
520
|
+
onDropdownVisibleChange: onInternalDropdownVisibleChange,
|
|
521
|
+
dropdownMatchSelectWidth: dropdownMatchSelectWidth
|
|
522
|
+
}))));
|
|
523
|
+
}); // Assign name for Debug
|
|
524
|
+
|
|
525
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
526
|
+
TreeSelect.displayName = 'TreeSelect';
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
var GenericTreeSelect = TreeSelect;
|
|
530
|
+
GenericTreeSelect.TreeNode = TreeNode;
|
|
531
|
+
GenericTreeSelect.SHOW_ALL = SHOW_ALL;
|
|
532
|
+
GenericTreeSelect.SHOW_PARENT = SHOW_PARENT;
|
|
533
|
+
GenericTreeSelect.SHOW_CHILD = SHOW_CHILD;
|
|
534
|
+
export default GenericTreeSelect;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ExpandAction } from 'rc-tree/lib/Tree';
|
|
3
|
+
import type { DefaultOptionType, InternalFieldName, OnInternalSelect } from './TreeSelect';
|
|
4
|
+
export interface TreeSelectContextProps {
|
|
5
|
+
virtual?: boolean;
|
|
6
|
+
dropdownMatchSelectWidth?: boolean | number;
|
|
7
|
+
listHeight: number;
|
|
8
|
+
listItemHeight: number;
|
|
9
|
+
treeData: DefaultOptionType[];
|
|
10
|
+
fieldNames: InternalFieldName;
|
|
11
|
+
onSelect: OnInternalSelect;
|
|
12
|
+
triggerChange?: any;
|
|
13
|
+
treeExpandAction?: ExpandAction;
|
|
14
|
+
}
|
|
15
|
+
declare const TreeSelectContext: React.Context<TreeSelectContextProps>;
|
|
16
|
+
export default TreeSelectContext;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LabeledValueType } from '../TreeSelect';
|
|
2
|
+
/**
|
|
3
|
+
* This function will try to call requestIdleCallback if available to save performance.
|
|
4
|
+
* No need `getLabel` here since already fetch on `rawLabeledValue`.
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: (values: LabeledValueType[]) => [LabeledValueType[]];
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* This function will try to call requestIdleCallback if available to save performance.
|
|
5
|
+
* No need `getLabel` here since already fetch on `rawLabeledValue`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export default (function (values) {
|
|
9
|
+
var cacheRef = React.useRef({
|
|
10
|
+
valueLabels: new Map()
|
|
11
|
+
});
|
|
12
|
+
return React.useMemo(function () {
|
|
13
|
+
var valueLabels = cacheRef.current.valueLabels;
|
|
14
|
+
var valueLabelsCache = new Map();
|
|
15
|
+
var filledValues = values.map(function (item) {
|
|
16
|
+
var _a;
|
|
17
|
+
|
|
18
|
+
var value = item.value;
|
|
19
|
+
var mergedLabel = (_a = item.label) !== null && _a !== void 0 ? _a : valueLabels.get(value); // Save in cache
|
|
20
|
+
|
|
21
|
+
valueLabelsCache.set(value, mergedLabel);
|
|
22
|
+
return _extends(_extends({}, item), {
|
|
23
|
+
label: mergedLabel
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
cacheRef.current.valueLabels = valueLabelsCache;
|
|
27
|
+
return [filledValues];
|
|
28
|
+
}, [values]);
|
|
29
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { DataEntity } from 'rc-tree/lib/interface';
|
|
3
|
+
import type { LabeledValueType, RawValueType } from '../TreeSelect';
|
|
4
|
+
declare const _default: (rawLabeledValues: LabeledValueType[], rawHalfCheckedValues: LabeledValueType[], treeConduction: boolean, keyEntities: Record<React.Key, DataEntity>) => RawValueType[][];
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { conductCheck } from "rc-tree/es/utils/conductUtil";
|
|
4
|
+
export default (function (rawLabeledValues, rawHalfCheckedValues, treeConduction, keyEntities) {
|
|
5
|
+
return React.useMemo(function () {
|
|
6
|
+
var checkedKeys = rawLabeledValues.map(function (_ref) {
|
|
7
|
+
var value = _ref.value;
|
|
8
|
+
return value;
|
|
9
|
+
});
|
|
10
|
+
var halfCheckedKeys = rawHalfCheckedValues.map(function (_ref2) {
|
|
11
|
+
var value = _ref2.value;
|
|
12
|
+
return value;
|
|
13
|
+
});
|
|
14
|
+
var missingValues = checkedKeys.filter(function (key) {
|
|
15
|
+
return !keyEntities[key];
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (treeConduction) {
|
|
19
|
+
var _conductCheck = conductCheck(checkedKeys, true, keyEntities);
|
|
20
|
+
|
|
21
|
+
checkedKeys = _conductCheck.checkedKeys;
|
|
22
|
+
halfCheckedKeys = _conductCheck.halfCheckedKeys;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [// Checked keys should fill with missing keys which should de-duplicated
|
|
26
|
+
Array.from(new Set([].concat(_toConsumableArray(missingValues), _toConsumableArray(checkedKeys)))), // Half checked keys
|
|
27
|
+
halfCheckedKeys];
|
|
28
|
+
}, [rawLabeledValues, rawHalfCheckedValues, treeConduction, keyEntities]);
|
|
29
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DataEntity } from 'rc-tree/lib/interface';
|
|
2
|
+
import type { FieldNames, RawValueType } from '../TreeSelect';
|
|
3
|
+
declare const _default: (treeData: any, fieldNames: FieldNames) => {
|
|
4
|
+
valueEntities: Map<RawValueType, DataEntity>;
|
|
5
|
+
keyEntities: Record<string, DataEntity>;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { convertDataToEntities } from "rc-tree/es/utils/treeUtil";
|
|
4
|
+
import warning from "rc-util/es/warning";
|
|
5
|
+
import { isNil } from '../utils/valueUtil';
|
|
6
|
+
export default (function (treeData, fieldNames) {
|
|
7
|
+
return React.useMemo(function () {
|
|
8
|
+
var collection = convertDataToEntities(treeData, {
|
|
9
|
+
fieldNames: fieldNames,
|
|
10
|
+
initWrapper: function initWrapper(wrapper) {
|
|
11
|
+
return _extends(_extends({}, wrapper), {
|
|
12
|
+
valueEntities: new Map()
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
processEntity: function processEntity(entity, wrapper) {
|
|
16
|
+
var val = entity.node[fieldNames.value]; // Check if exist same value
|
|
17
|
+
|
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
+
var key = entity.node.key;
|
|
20
|
+
warning(!isNil(val), 'TreeNode `value` is invalidate: undefined');
|
|
21
|
+
warning(!wrapper.valueEntities.has(val), "Same `value` exist in the tree: ".concat(val));
|
|
22
|
+
warning(!key || String(key) === String(val), "`key` or `value` with TreeNode must be the same or you can remove one of them. key: ".concat(key, ", value: ").concat(val, "."));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
wrapper.valueEntities.set(val, entity);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return collection;
|
|
29
|
+
}, [treeData, fieldNames]);
|
|
30
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DefaultOptionType, InternalFieldName, TreeSelectProps } from '../TreeSelect';
|
|
2
|
+
declare const _default: (treeData: DefaultOptionType[], searchValue: string, { treeNodeFilterProp, filterTreeNode, fieldNames }: {
|
|
3
|
+
fieldNames: InternalFieldName;
|
|
4
|
+
treeNodeFilterProp: string;
|
|
5
|
+
filterTreeNode: TreeSelectProps['filterTreeNode'];
|
|
6
|
+
}) => any;
|
|
7
|
+
export default _default;
|