@douyinfe/semi-foundation 2.46.2 → 2.47.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/datePicker/inputFoundation.ts +7 -5
- package/lib/cjs/cascader/foundation.d.ts +1 -4
- package/lib/cjs/datePicker/inputFoundation.js +17 -8
- package/lib/cjs/table/foundation.js +2 -2
- package/lib/cjs/tree/foundation.d.ts +2 -1
- package/lib/cjs/tree/foundation.js +17 -8
- package/lib/cjs/tree/treeUtil.d.ts +15 -6
- package/lib/cjs/tree/treeUtil.js +39 -20
- package/lib/cjs/treeSelect/foundation.d.ts +0 -1
- package/lib/cjs/treeSelect/foundation.js +47 -26
- package/lib/es/cascader/foundation.d.ts +1 -4
- package/lib/es/datePicker/inputFoundation.js +17 -8
- package/lib/es/table/foundation.js +2 -2
- package/lib/es/tree/foundation.d.ts +2 -1
- package/lib/es/tree/foundation.js +17 -8
- package/lib/es/tree/treeUtil.d.ts +15 -6
- package/lib/es/tree/treeUtil.js +39 -20
- package/lib/es/treeSelect/foundation.d.ts +0 -1
- package/lib/es/treeSelect/foundation.js +47 -26
- package/package.json +3 -3
- package/table/foundation.ts +1 -2
- package/tree/foundation.ts +14 -7
- package/tree/treeUtil.ts +47 -18
- package/treeSelect/foundation.ts +35 -26
|
@@ -189,12 +189,14 @@ export default class InputFoundation extends BaseFoundation<DateInputAdapter> {
|
|
|
189
189
|
|
|
190
190
|
handleInsetInputChange(options: InsetInputChangeFoundationProps) {
|
|
191
191
|
const { value, valuePath, insetInputValue } = options;
|
|
192
|
-
const { format, type } = this._adapter.getProps();
|
|
192
|
+
const { format, type, rangeSeparator } = this._adapter.getProps();
|
|
193
193
|
const insetFormatToken = getInsetInputFormatToken({ type, format });
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
this.
|
|
194
|
+
const newInsetInputValue = set(cloneDeep(insetInputValue), valuePath, value);
|
|
195
|
+
const insetInputStr = this.concatInsetInputValue({ insetInputValue: newInsetInputValue });
|
|
196
|
+
const parsedInsetInputValueFromInputStr = getInsetInputValueFromInsetInputStr({ inputValue: insetInputStr, type, rangeSeparator });
|
|
197
|
+
const filledTimeInsetInputValue = this._autoFillTimeToInsetInputValue({ insetInputValue: parsedInsetInputValueFromInputStr, valuePath, format: insetFormatToken });
|
|
198
|
+
const finalInsetInputStr = this.concatInsetInputValue({ insetInputValue: filledTimeInsetInputValue });
|
|
199
|
+
this._adapter.notifyInsetInputChange({ insetInputValue: filledTimeInsetInputValue, format: insetFormatToken, insetInputStr: finalInsetInputStr });
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
_autoFillTimeToInsetInputValue(options: { insetInputValue: InsetInputValue; format: string; valuePath: string}) {
|
|
@@ -239,10 +239,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
239
239
|
* @param {boolean} curCheckedStatus checked status of node
|
|
240
240
|
*/
|
|
241
241
|
calcCheckedKeys(key: string, curCheckedStatus: boolean): {
|
|
242
|
-
checkedKeys: Set<string>;
|
|
243
|
-
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
244
|
-
* the option is considered to be selected, even if the option is disabled
|
|
245
|
-
*/
|
|
242
|
+
checkedKeys: Set<string>;
|
|
246
243
|
halfCheckedKeys: Set<string>;
|
|
247
244
|
};
|
|
248
245
|
handleInputChange(sugInput: string): void;
|
|
@@ -113,25 +113,34 @@ class InputFoundation extends _foundation.default {
|
|
|
113
113
|
} = options;
|
|
114
114
|
const {
|
|
115
115
|
format,
|
|
116
|
-
type
|
|
116
|
+
type,
|
|
117
|
+
rangeSeparator
|
|
117
118
|
} = this._adapter.getProps();
|
|
118
119
|
const insetFormatToken = (0, _getInsetInputFormatToken.default)({
|
|
119
120
|
type,
|
|
120
121
|
format
|
|
121
122
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
insetInputValue: newInsetInputValue
|
|
123
|
+
const newInsetInputValue = (0, _set2.default)((0, _cloneDeep2.default)(insetInputValue), valuePath, value);
|
|
124
|
+
const insetInputStr = this.concatInsetInputValue({
|
|
125
|
+
insetInputValue: newInsetInputValue
|
|
126
|
+
});
|
|
127
|
+
const parsedInsetInputValueFromInputStr = (0, _getInsetInputValueFromInsetInputStr.default)({
|
|
128
|
+
inputValue: insetInputStr,
|
|
129
|
+
type,
|
|
130
|
+
rangeSeparator
|
|
131
|
+
});
|
|
132
|
+
const filledTimeInsetInputValue = this._autoFillTimeToInsetInputValue({
|
|
133
|
+
insetInputValue: parsedInsetInputValueFromInputStr,
|
|
125
134
|
valuePath,
|
|
126
135
|
format: insetFormatToken
|
|
127
136
|
});
|
|
128
|
-
const
|
|
129
|
-
insetInputValue:
|
|
137
|
+
const finalInsetInputStr = this.concatInsetInputValue({
|
|
138
|
+
insetInputValue: filledTimeInsetInputValue
|
|
130
139
|
});
|
|
131
140
|
this._adapter.notifyInsetInputChange({
|
|
132
|
-
insetInputValue:
|
|
141
|
+
insetInputValue: filledTimeInsetInputValue,
|
|
133
142
|
format: insetFormatToken,
|
|
134
|
-
insetInputStr:
|
|
143
|
+
insetInputStr: finalInsetInputStr
|
|
135
144
|
});
|
|
136
145
|
}
|
|
137
146
|
_autoFillTimeToInsetInputValue(options) {
|
|
@@ -392,9 +392,9 @@ class TableFoundation extends _foundation.default {
|
|
|
392
392
|
}, pagination);
|
|
393
393
|
if (!this._pagerIsControlled()) {
|
|
394
394
|
const total = (0, _get2.default)(propPagination, 'total', dataSource.length);
|
|
395
|
-
const pageSize = (0, _get2.default)(propPagination, 'pageSize', pagination.pageSize);
|
|
396
395
|
const {
|
|
397
|
-
currentPage
|
|
396
|
+
currentPage,
|
|
397
|
+
pageSize
|
|
398
398
|
} = pagination;
|
|
399
399
|
const realTotalPage = Math.ceil(total / pageSize);
|
|
400
400
|
pagination.total = total;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* https://github.com/react-component/tree
|
|
4
4
|
*/
|
|
5
5
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
6
|
+
export { KeyMapProps } from './treeUtil';
|
|
6
7
|
export interface BasicTreeNodeProps {
|
|
7
8
|
[x: string]: any;
|
|
8
9
|
expanded?: boolean;
|
|
@@ -24,7 +25,7 @@ export interface BasicTreeNodeProps {
|
|
|
24
25
|
}
|
|
25
26
|
export interface BasicTreeNodeData {
|
|
26
27
|
[x: string]: any;
|
|
27
|
-
key
|
|
28
|
+
key?: string;
|
|
28
29
|
value?: number | string;
|
|
29
30
|
label?: any;
|
|
30
31
|
icon?: any;
|
|
@@ -129,7 +129,8 @@ class TreeFoundation extends _foundation.default {
|
|
|
129
129
|
} = this.getStates();
|
|
130
130
|
const {
|
|
131
131
|
leafOnly,
|
|
132
|
-
checkRelation
|
|
132
|
+
checkRelation,
|
|
133
|
+
keyMaps
|
|
133
134
|
} = this.getProps();
|
|
134
135
|
let value;
|
|
135
136
|
let keyList = [];
|
|
@@ -141,12 +142,15 @@ class TreeFoundation extends _foundation.default {
|
|
|
141
142
|
if (this.getProp('onChangeWithObject')) {
|
|
142
143
|
value = keyList.map(itemKey => keyEntities[itemKey].data);
|
|
143
144
|
} else {
|
|
144
|
-
value = (0, _treeUtil.getValueOrKey)(keyList.map(itemKey => keyEntities[itemKey].data));
|
|
145
|
+
value = (0, _treeUtil.getValueOrKey)(keyList.map(itemKey => keyEntities[itemKey].data), keyMaps);
|
|
145
146
|
}
|
|
146
147
|
this._adapter.notifyChange(value);
|
|
147
148
|
}
|
|
148
149
|
notifyChange(key, e) {
|
|
149
150
|
const isMultiple = this._isMultiple();
|
|
151
|
+
const {
|
|
152
|
+
keyMaps
|
|
153
|
+
} = this.getProps();
|
|
150
154
|
const {
|
|
151
155
|
keyEntities
|
|
152
156
|
} = this.getStates();
|
|
@@ -162,7 +166,7 @@ class TreeFoundation extends _foundation.default {
|
|
|
162
166
|
const {
|
|
163
167
|
data
|
|
164
168
|
} = (0, _get2.default)(keyEntities, key);
|
|
165
|
-
value = (0, _treeUtil.getValueOrKey)(data);
|
|
169
|
+
value = (0, _treeUtil.getValueOrKey)(data, keyMaps);
|
|
166
170
|
}
|
|
167
171
|
this._adapter.notifyChange(value);
|
|
168
172
|
}
|
|
@@ -179,8 +183,10 @@ class TreeFoundation extends _foundation.default {
|
|
|
179
183
|
const {
|
|
180
184
|
showFilteredOnly,
|
|
181
185
|
filterTreeNode,
|
|
182
|
-
treeNodeFilterProp
|
|
186
|
+
treeNodeFilterProp,
|
|
187
|
+
keyMaps
|
|
183
188
|
} = this.getProps();
|
|
189
|
+
const realFilterProp = treeNodeFilterProp !== 'label' ? treeNodeFilterProp : (0, _get2.default)(keyMaps, 'label', 'label');
|
|
184
190
|
let filteredOptsKeys = [];
|
|
185
191
|
let expandedOptsKeys = [];
|
|
186
192
|
let flattenNodes = [];
|
|
@@ -188,13 +194,13 @@ class TreeFoundation extends _foundation.default {
|
|
|
188
194
|
if (!sugInput) {
|
|
189
195
|
expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities);
|
|
190
196
|
expandedOptsKeys.forEach(item => expandedKeys.add(item));
|
|
191
|
-
flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, expandedKeys);
|
|
197
|
+
flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, expandedKeys, keyMaps);
|
|
192
198
|
} else {
|
|
193
|
-
filteredOptsKeys = Object.values(keyEntities).filter(item => (0, _treeUtil.filter)(sugInput, item.data, filterTreeNode,
|
|
199
|
+
filteredOptsKeys = Object.values(keyEntities).filter(item => (0, _treeUtil.filter)(sugInput, item.data, filterTreeNode, realFilterProp)).map(item => item.key);
|
|
194
200
|
expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(filteredOptsKeys, keyEntities, false);
|
|
195
201
|
const shownChildKeys = (0, _treeUtil.findDescendantKeys)(filteredOptsKeys, keyEntities, true);
|
|
196
202
|
filteredShownKeys = new Set([...shownChildKeys, ...expandedOptsKeys]);
|
|
197
|
-
flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, new Set(expandedOptsKeys), showFilteredOnly && filteredShownKeys);
|
|
203
|
+
flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, new Set(expandedOptsKeys), keyMaps, showFilteredOnly && filteredShownKeys);
|
|
198
204
|
}
|
|
199
205
|
const newFilteredExpandedKeys = new Set(expandedOptsKeys);
|
|
200
206
|
this._adapter.notifySearch(sugInput, Array.from(newFilteredExpandedKeys));
|
|
@@ -362,6 +368,9 @@ class TreeFoundation extends _foundation.default {
|
|
|
362
368
|
filteredShownKeys,
|
|
363
369
|
keyEntities
|
|
364
370
|
} = this.getStates();
|
|
371
|
+
const {
|
|
372
|
+
keyMaps
|
|
373
|
+
} = this.getProps();
|
|
365
374
|
const isSearching = Boolean(inputValue);
|
|
366
375
|
const showFilteredOnly = this._showFilteredOnly();
|
|
367
376
|
const expandedStateKey = isSearching ? 'filteredExpandedKeys' : 'expandedKeys';
|
|
@@ -380,7 +389,7 @@ class TreeFoundation extends _foundation.default {
|
|
|
380
389
|
}
|
|
381
390
|
this._adapter.cacheFlattenNodes(motionType === 'hide' && this._isAnimated());
|
|
382
391
|
if (!this._isExpandControlled()) {
|
|
383
|
-
const flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, expandedKeys, isSearching && showFilteredOnly && filteredShownKeys);
|
|
392
|
+
const flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, expandedKeys, keyMaps, isSearching && showFilteredOnly && filteredShownKeys);
|
|
384
393
|
const motionKeys = this._isAnimated() ? (0, _treeUtil.getMotionKeys)(eventKey, expandedKeys, keyEntities) : [];
|
|
385
394
|
const newState = {
|
|
386
395
|
[expandedStateKey]: expandedKeys,
|
|
@@ -14,6 +14,15 @@ export interface NodeData {
|
|
|
14
14
|
value: any;
|
|
15
15
|
children?: any;
|
|
16
16
|
}
|
|
17
|
+
export interface KeyMapProps {
|
|
18
|
+
key?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
disabled?: string;
|
|
22
|
+
children?: string;
|
|
23
|
+
isLeaf?: string;
|
|
24
|
+
icon?: string;
|
|
25
|
+
}
|
|
17
26
|
/**
|
|
18
27
|
* Flat nest tree data into flatten list. This is used for virtual list render.
|
|
19
28
|
* @param treeNodeList Origin data node list
|
|
@@ -21,13 +30,13 @@ export interface NodeData {
|
|
|
21
30
|
* @param filteredShownKeys
|
|
22
31
|
* need expanded keys, provides `true` means all expanded
|
|
23
32
|
*/
|
|
24
|
-
export declare function flattenTreeData(treeNodeList: any[], expandedKeys: Set<string>, filteredShownKeys?: boolean | Set<any>): any[];
|
|
33
|
+
export declare function flattenTreeData(treeNodeList: any[], expandedKeys: Set<string>, keyMaps: KeyMapProps, filteredShownKeys?: boolean | Set<any>): any[];
|
|
25
34
|
export declare function convertJsonToData(treeJson: TreeDataSimpleJson): any[];
|
|
26
35
|
/**
|
|
27
36
|
* Traverse all the data by `treeData`.
|
|
28
37
|
*/
|
|
29
|
-
export declare function traverseDataNodes(treeNodes: any[], callback: (data: any) => void): void;
|
|
30
|
-
export declare function convertDataToEntities(dataNodes: any[]): {
|
|
38
|
+
export declare function traverseDataNodes(treeNodes: any[], callback: (data: any) => void, keyMaps: KeyMapProps): void;
|
|
39
|
+
export declare function convertDataToEntities(dataNodes: any[], keyMaps?: KeyMapProps): {
|
|
31
40
|
posEntities: {};
|
|
32
41
|
keyEntities: {};
|
|
33
42
|
valueEntities: {};
|
|
@@ -71,10 +80,10 @@ export declare function filterTreeData(info: any): {
|
|
|
71
80
|
filteredExpandedKeys: Set<any>;
|
|
72
81
|
filteredShownKeys: Set<any>;
|
|
73
82
|
};
|
|
74
|
-
export declare function getValueOrKey(data: any): any;
|
|
75
|
-
export declare function normalizeValue(value: any, withObject: boolean): any;
|
|
83
|
+
export declare function getValueOrKey(data: any, keyMaps?: KeyMapProps): any;
|
|
84
|
+
export declare function normalizeValue(value: any, withObject: boolean, keyMaps?: KeyMapProps): any;
|
|
76
85
|
export declare function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntities): string[];
|
|
77
|
-
export declare function calcDisabledKeys(keyEntities: KeyEntities): Set<string>;
|
|
86
|
+
export declare function calcDisabledKeys(keyEntities: KeyEntities, keyMaps?: KeyMapProps): Set<string>;
|
|
78
87
|
export declare function calcDropRelativePosition(event: any, treeNode: any): 1 | -1 | 0;
|
|
79
88
|
export declare function getDragNodesKeys(key: string, keyEntities: KeyEntities): string[];
|
|
80
89
|
export declare function calcDropActualPosition(pos: string, relativeDropPos: any): any;
|
package/lib/cjs/tree/treeUtil.js
CHANGED
|
@@ -31,6 +31,7 @@ exports.normalizeValue = normalizeValue;
|
|
|
31
31
|
exports.normalizedArr = normalizedArr;
|
|
32
32
|
exports.traverseDataNodes = traverseDataNodes;
|
|
33
33
|
exports.updateKeys = updateKeys;
|
|
34
|
+
var _omit2 = _interopRequireDefault(require("lodash/omit"));
|
|
34
35
|
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
35
36
|
var _pick2 = _interopRequireDefault(require("lodash/pick"));
|
|
36
37
|
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
@@ -60,17 +61,27 @@ function isValid(val) {
|
|
|
60
61
|
* @param filteredShownKeys
|
|
61
62
|
* need expanded keys, provides `true` means all expanded
|
|
62
63
|
*/
|
|
63
|
-
function flattenTreeData(treeNodeList, expandedKeys) {
|
|
64
|
-
let filteredShownKeys = arguments.length >
|
|
64
|
+
function flattenTreeData(treeNodeList, expandedKeys, keyMaps) {
|
|
65
|
+
let filteredShownKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
65
66
|
const flattenList = [];
|
|
66
67
|
const filterSearch = Boolean(filteredShownKeys);
|
|
68
|
+
const realKeyName = (0, _get2.default)(keyMaps, 'key', 'key');
|
|
69
|
+
const realChildrenName = (0, _get2.default)(keyMaps, 'children', 'children');
|
|
67
70
|
function flatten(list) {
|
|
68
71
|
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
69
72
|
return list.map((treeNode, index) => {
|
|
70
73
|
const pos = getPosition(parent ? parent.pos : '0', index);
|
|
71
|
-
const mergedKey = treeNode
|
|
74
|
+
const mergedKey = treeNode[realKeyName];
|
|
75
|
+
const otherData = {};
|
|
76
|
+
if (keyMaps) {
|
|
77
|
+
Object.entries((0, _omit2.default)(keyMaps, 'children')).forEach(_ref => {
|
|
78
|
+
let [key, value] = _ref;
|
|
79
|
+
const result = treeNode[value];
|
|
80
|
+
!(0, _isUndefined2.default)(result) && (otherData[key] = result);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
72
83
|
// Add FlattenDataNode into list
|
|
73
|
-
const flattenNode = Object.assign(Object.assign({}, (0, _pick2.default)(treeNode, ['key', 'label', 'value', 'icon', 'disabled', 'isLeaf'])), {
|
|
84
|
+
const flattenNode = Object.assign(Object.assign(Object.assign({}, (0, _pick2.default)(treeNode, ['key', 'label', 'value', 'icon', 'disabled', 'isLeaf'])), otherData), {
|
|
74
85
|
parent,
|
|
75
86
|
pos,
|
|
76
87
|
children: null,
|
|
@@ -83,7 +94,7 @@ function flattenTreeData(treeNodeList, expandedKeys) {
|
|
|
83
94
|
}
|
|
84
95
|
// Loop treeNode children
|
|
85
96
|
if (expandedKeys.has(mergedKey) && (!filterSearch || !isBooleanFilteredShownKeys && filteredShownKeys.has(mergedKey))) {
|
|
86
|
-
flattenNode.children = flatten(treeNode
|
|
97
|
+
flattenNode.children = flatten(treeNode[realChildrenName] || [], flattenNode);
|
|
87
98
|
} else {
|
|
88
99
|
flattenNode.children = [];
|
|
89
100
|
}
|
|
@@ -118,17 +129,20 @@ function convertJsonToData(treeJson) {
|
|
|
118
129
|
/**
|
|
119
130
|
* Traverse all the data by `treeData`.
|
|
120
131
|
*/
|
|
121
|
-
function traverseDataNodes(treeNodes, callback) {
|
|
132
|
+
function traverseDataNodes(treeNodes, callback, keyMaps) {
|
|
133
|
+
const realKeyName = (0, _get2.default)(keyMaps, 'key', 'key');
|
|
134
|
+
const realChildrenName = (0, _get2.default)(keyMaps, 'children', 'children');
|
|
122
135
|
const processNode = (node, ind, parent) => {
|
|
123
|
-
const children = node ? node
|
|
136
|
+
const children = node ? node[realChildrenName] : treeNodes;
|
|
124
137
|
const pos = node ? getPosition(parent.pos, ind) : '0';
|
|
125
138
|
// Process node if is not root
|
|
126
139
|
if (node) {
|
|
140
|
+
const nodeKey = (0, _get2.default)(node, realKeyName, null);
|
|
127
141
|
const data = {
|
|
128
142
|
data: Object.assign({}, node),
|
|
129
143
|
ind,
|
|
130
144
|
pos,
|
|
131
|
-
key:
|
|
145
|
+
key: nodeKey !== null ? nodeKey : pos,
|
|
132
146
|
parentPos: parent.node ? parent.pos : null,
|
|
133
147
|
level: Number(parent.level) + 1
|
|
134
148
|
};
|
|
@@ -148,7 +162,7 @@ function traverseDataNodes(treeNodes, callback) {
|
|
|
148
162
|
processNode(null);
|
|
149
163
|
}
|
|
150
164
|
/* Convert data to entities map */
|
|
151
|
-
function convertDataToEntities(dataNodes) {
|
|
165
|
+
function convertDataToEntities(dataNodes, keyMaps) {
|
|
152
166
|
const posEntities = {};
|
|
153
167
|
const keyEntities = {};
|
|
154
168
|
const valueEntities = {};
|
|
@@ -157,6 +171,7 @@ function convertDataToEntities(dataNodes) {
|
|
|
157
171
|
keyEntities,
|
|
158
172
|
valueEntities
|
|
159
173
|
};
|
|
174
|
+
const realValueName = (0, _get2.default)(keyMaps, 'value', 'value');
|
|
160
175
|
traverseDataNodes(dataNodes, data => {
|
|
161
176
|
const {
|
|
162
177
|
pos,
|
|
@@ -164,7 +179,7 @@ function convertDataToEntities(dataNodes) {
|
|
|
164
179
|
parentPos
|
|
165
180
|
} = data;
|
|
166
181
|
const entity = Object.assign({}, data);
|
|
167
|
-
const value = (0, _get2.default)(entity,
|
|
182
|
+
const value = (0, _get2.default)(entity, `data.${realValueName}`, null);
|
|
168
183
|
if (value !== null) {
|
|
169
184
|
valueEntities[value] = key;
|
|
170
185
|
}
|
|
@@ -176,7 +191,7 @@ function convertDataToEntities(dataNodes) {
|
|
|
176
191
|
entity.parent.children = entity.parent.children || [];
|
|
177
192
|
entity.parent.children.push(entity);
|
|
178
193
|
}
|
|
179
|
-
});
|
|
194
|
+
}, keyMaps);
|
|
180
195
|
return wrapper;
|
|
181
196
|
}
|
|
182
197
|
/* Get key by value */
|
|
@@ -574,7 +589,8 @@ function filterTreeData(info) {
|
|
|
574
589
|
treeData,
|
|
575
590
|
filterTreeNode,
|
|
576
591
|
filterProps,
|
|
577
|
-
prevExpandedKeys
|
|
592
|
+
prevExpandedKeys,
|
|
593
|
+
keyMaps
|
|
578
594
|
} = info;
|
|
579
595
|
let filteredOptsKeys = [];
|
|
580
596
|
filteredOptsKeys = Object.values(keyEntities).filter(item => filter(inputValue, item.data, filterTreeNode, filterProps)).map(item => item.key);
|
|
@@ -585,7 +601,7 @@ function filterTreeData(info) {
|
|
|
585
601
|
}
|
|
586
602
|
const shownChildKeys = findDescendantKeys(filteredOptsKeys, keyEntities, true);
|
|
587
603
|
const filteredShownKeys = new Set([...shownChildKeys, ...expandedOptsKeys]);
|
|
588
|
-
const flattenNodes = flattenTreeData(treeData, new Set(expandedOptsKeys), showFilteredOnly && filteredShownKeys);
|
|
604
|
+
const flattenNodes = flattenTreeData(treeData, new Set(expandedOptsKeys), keyMaps, showFilteredOnly && filteredShownKeys);
|
|
589
605
|
return {
|
|
590
606
|
flattenNodes,
|
|
591
607
|
filteredKeys: new Set(filteredOptsKeys),
|
|
@@ -594,16 +610,18 @@ function filterTreeData(info) {
|
|
|
594
610
|
};
|
|
595
611
|
}
|
|
596
612
|
// return data.value if data.value exist else fall back to key
|
|
597
|
-
function getValueOrKey(data) {
|
|
613
|
+
function getValueOrKey(data, keyMaps) {
|
|
614
|
+
const valueName = (0, _get2.default)(keyMaps, 'value', 'value');
|
|
615
|
+
const keyName = (0, _get2.default)(keyMaps, 'key', 'key');
|
|
598
616
|
if (Array.isArray(data)) {
|
|
599
|
-
return data.map(item => (0, _get2.default)(item,
|
|
617
|
+
return data.map(item => (0, _get2.default)(item, valueName, item[keyName]));
|
|
600
618
|
}
|
|
601
|
-
return (0, _get2.default)(data,
|
|
619
|
+
return (0, _get2.default)(data, valueName, data[keyName]);
|
|
602
620
|
}
|
|
603
621
|
/* Convert value to string */
|
|
604
|
-
function normalizeValue(value, withObject) {
|
|
622
|
+
function normalizeValue(value, withObject, keyMaps) {
|
|
605
623
|
if (withObject && isValid(value)) {
|
|
606
|
-
return getValueOrKey(value);
|
|
624
|
+
return getValueOrKey(value, keyMaps);
|
|
607
625
|
} else {
|
|
608
626
|
return value;
|
|
609
627
|
}
|
|
@@ -612,8 +630,9 @@ function updateKeys(keySet, keyEntities) {
|
|
|
612
630
|
const keyArr = [...keySet];
|
|
613
631
|
return keyArr.filter(key => key in keyEntities);
|
|
614
632
|
}
|
|
615
|
-
function calcDisabledKeys(keyEntities) {
|
|
616
|
-
const
|
|
633
|
+
function calcDisabledKeys(keyEntities, keyMaps) {
|
|
634
|
+
const disabledName = (0, _get2.default)(keyMaps, 'disabled', 'disabled');
|
|
635
|
+
const disabledKeys = Object.keys(keyEntities).filter(key => keyEntities[key].data[disabledName]);
|
|
617
636
|
const {
|
|
618
637
|
checkedKeys
|
|
619
638
|
} = calcCheckedKeys(disabledKeys, keyEntities);
|
|
@@ -122,7 +122,6 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
122
122
|
findDataForValue(findValue: string): any;
|
|
123
123
|
constructDataForValue(value: string): {
|
|
124
124
|
[x: number]: string;
|
|
125
|
-
key: string;
|
|
126
125
|
};
|
|
127
126
|
getDataForKeyNotInKeyEntities(value: string): any;
|
|
128
127
|
getCopyFromState(items: string | string[]): BasicTreeInnerData;
|
|
@@ -96,8 +96,11 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
96
96
|
findDataForValue(findValue) {
|
|
97
97
|
const {
|
|
98
98
|
value,
|
|
99
|
-
defaultValue
|
|
99
|
+
defaultValue,
|
|
100
|
+
keyMaps
|
|
100
101
|
} = this.getProps();
|
|
102
|
+
const realValueName = (0, _get2.default)(keyMaps, 'value', 'value');
|
|
103
|
+
const realKeyName = (0, _get2.default)(keyMaps, 'key', 'key');
|
|
101
104
|
let valueArr = [];
|
|
102
105
|
if (value) {
|
|
103
106
|
valueArr = Array.isArray(value) ? value : [value];
|
|
@@ -105,16 +108,19 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
105
108
|
valueArr = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
106
109
|
}
|
|
107
110
|
return valueArr.find(item => {
|
|
108
|
-
return item
|
|
111
|
+
return item[realValueName] === findValue || item[realKeyName] === findValue;
|
|
109
112
|
});
|
|
110
113
|
}
|
|
111
114
|
constructDataForValue(value) {
|
|
112
115
|
const {
|
|
113
|
-
treeNodeLabelProp
|
|
116
|
+
treeNodeLabelProp,
|
|
117
|
+
keyMaps
|
|
114
118
|
} = this.getProps();
|
|
119
|
+
const keyName = (0, _get2.default)(keyMaps, 'key', 'key');
|
|
120
|
+
const labelName = (0, _get2.default)(keyMaps, 'label', treeNodeLabelProp);
|
|
115
121
|
return {
|
|
116
|
-
|
|
117
|
-
[
|
|
122
|
+
[keyName]: value,
|
|
123
|
+
[labelName]: value
|
|
118
124
|
};
|
|
119
125
|
}
|
|
120
126
|
getDataForKeyNotInKeyEntities(value) {
|
|
@@ -231,7 +237,8 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
231
237
|
} = this.getStates();
|
|
232
238
|
const {
|
|
233
239
|
leafOnly,
|
|
234
|
-
checkRelation
|
|
240
|
+
checkRelation,
|
|
241
|
+
keyMaps
|
|
235
242
|
} = this.getProps();
|
|
236
243
|
let keyList = [];
|
|
237
244
|
if (checkRelation === 'related') {
|
|
@@ -239,11 +246,11 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
239
246
|
} else if (checkRelation === 'unRelated') {
|
|
240
247
|
keyList = key;
|
|
241
248
|
}
|
|
242
|
-
const nodes = keyList.map(key => keyEntities[key] && keyEntities[key].
|
|
249
|
+
const nodes = keyList.map(key => keyEntities[key] && keyEntities[key].key === key ? keyEntities[key].data : this.getDataForKeyNotInKeyEntities(key));
|
|
243
250
|
if (this.getProp('onChangeWithObject')) {
|
|
244
251
|
this._adapter.notifyChangeWithObject(nodes, e);
|
|
245
252
|
} else {
|
|
246
|
-
const value = (0, _treeUtil.getValueOrKey)(nodes);
|
|
253
|
+
const value = (0, _treeUtil.getValueOrKey)(nodes, keyMaps);
|
|
247
254
|
this._adapter.notifyChange(value, nodes, e);
|
|
248
255
|
}
|
|
249
256
|
}
|
|
@@ -251,11 +258,14 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
251
258
|
const {
|
|
252
259
|
keyEntities
|
|
253
260
|
} = this.getStates();
|
|
261
|
+
const {
|
|
262
|
+
keyMaps
|
|
263
|
+
} = this.getProps();
|
|
254
264
|
if (this._isMultiple() && Array.isArray(key)) {
|
|
255
265
|
this._notifyMultipleChange(key, e);
|
|
256
266
|
} else {
|
|
257
267
|
const nodes = (0, _isUndefined2.default)(key) ? key : keyEntities[key].data;
|
|
258
|
-
const value = (0, _isUndefined2.default)(key) ? key : (0, _treeUtil.getValueOrKey)(nodes);
|
|
268
|
+
const value = (0, _isUndefined2.default)(key) ? key : (0, _treeUtil.getValueOrKey)(nodes, keyMaps);
|
|
259
269
|
if (this.getProp('onChangeWithObject')) {
|
|
260
270
|
this._adapter.notifyChangeWithObject(nodes, e);
|
|
261
271
|
} else {
|
|
@@ -382,15 +392,17 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
382
392
|
removeTag(eventKey) {
|
|
383
393
|
const {
|
|
384
394
|
disableStrictly,
|
|
385
|
-
checkRelation
|
|
395
|
+
checkRelation,
|
|
396
|
+
keyMaps
|
|
386
397
|
} = this.getProps();
|
|
387
398
|
const {
|
|
388
399
|
keyEntities,
|
|
389
400
|
disabledKeys,
|
|
390
401
|
realCheckedKeys
|
|
391
402
|
} = this.getStates();
|
|
392
|
-
const item = keyEntities[eventKey] && keyEntities[eventKey].
|
|
393
|
-
|
|
403
|
+
const item = keyEntities[eventKey] && keyEntities[eventKey].key === eventKey ? keyEntities[eventKey].data : this.getDataForKeyNotInKeyEntities(eventKey);
|
|
404
|
+
const disabledName = (0, _get2.default)(keyMaps, 'disabled', 'disabled');
|
|
405
|
+
if (item[disabledName] || disableStrictly && disabledKeys.has(eventKey)) {
|
|
394
406
|
return;
|
|
395
407
|
}
|
|
396
408
|
if (checkRelation === 'unRelated') {
|
|
@@ -429,11 +441,14 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
429
441
|
keyEntities,
|
|
430
442
|
treeData
|
|
431
443
|
} = this.getStates();
|
|
444
|
+
const {
|
|
445
|
+
keyMaps
|
|
446
|
+
} = this.getProps();
|
|
432
447
|
const newExpandedKeys = new Set(expandedKeys);
|
|
433
448
|
const isExpandControlled = this._isExpandControlled();
|
|
434
449
|
const expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities);
|
|
435
450
|
expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
|
|
436
|
-
const newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, newExpandedKeys);
|
|
451
|
+
const newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, newExpandedKeys, keyMaps);
|
|
437
452
|
this._adapter.updateState({
|
|
438
453
|
expandedKeys: isExpandControlled ? expandedKeys : newExpandedKeys,
|
|
439
454
|
flattenNodes: isExpandControlled ? flattenNodes : newFlattenNodes,
|
|
@@ -457,8 +472,10 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
457
472
|
const {
|
|
458
473
|
showFilteredOnly,
|
|
459
474
|
filterTreeNode,
|
|
460
|
-
treeNodeFilterProp
|
|
475
|
+
treeNodeFilterProp,
|
|
476
|
+
keyMaps
|
|
461
477
|
} = this.getProps();
|
|
478
|
+
const realFilterProp = treeNodeFilterProp !== 'label' ? treeNodeFilterProp : (0, _get2.default)(keyMaps, 'label', 'label');
|
|
462
479
|
const newExpandedKeys = new Set(expandedKeys);
|
|
463
480
|
let filteredOptsKeys = [];
|
|
464
481
|
let expandedOptsKeys = [];
|
|
@@ -467,18 +484,18 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
467
484
|
if (!sugInput) {
|
|
468
485
|
expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(selectedKeys, keyEntities);
|
|
469
486
|
expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
|
|
470
|
-
newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, newExpandedKeys);
|
|
487
|
+
newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, newExpandedKeys, keyMaps);
|
|
471
488
|
} else {
|
|
472
489
|
filteredOptsKeys = Object.values(keyEntities).filter(item => {
|
|
473
490
|
const {
|
|
474
491
|
data
|
|
475
492
|
} = item;
|
|
476
|
-
return (0, _treeUtil.filter)(sugInput, data, filterTreeNode,
|
|
493
|
+
return (0, _treeUtil.filter)(sugInput, data, filterTreeNode, realFilterProp);
|
|
477
494
|
}).map(item => item.key);
|
|
478
495
|
expandedOptsKeys = (0, _treeUtil.findAncestorKeys)(filteredOptsKeys, keyEntities, false);
|
|
479
496
|
const shownChildKeys = (0, _treeUtil.findDescendantKeys)(filteredOptsKeys, keyEntities, true);
|
|
480
497
|
filteredShownKeys = new Set([...shownChildKeys, ...expandedOptsKeys]);
|
|
481
|
-
newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, new Set(expandedOptsKeys), showFilteredOnly && filteredShownKeys);
|
|
498
|
+
newFlattenNodes = (0, _treeUtil.flattenTreeData)(treeData, new Set(expandedOptsKeys), keyMaps, showFilteredOnly && filteredShownKeys);
|
|
482
499
|
}
|
|
483
500
|
const newFilteredExpandedKeys = new Set(expandedOptsKeys);
|
|
484
501
|
this._adapter.notifySearch(sugInput, Array.from(newFilteredExpandedKeys));
|
|
@@ -612,7 +629,7 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
612
629
|
return this.calcCheckedKeys(eventKey, targetStatus);
|
|
613
630
|
}
|
|
614
631
|
const nonDisabled = descendantKeys.filter(key => !disabledKeys.has(key));
|
|
615
|
-
const newCheckedKeys = targetStatus ? [...nonDisabled, ...checkedKeys] : (0, _difference2.default)((0, _treeUtil.normalizeKeyList)([...checkedKeys], keyEntities, true), nonDisabled);
|
|
632
|
+
const newCheckedKeys = targetStatus ? [...nonDisabled, ...checkedKeys] : (0, _difference2.default)((0, _treeUtil.normalizeKeyList)([...checkedKeys], keyEntities, true, true), nonDisabled);
|
|
616
633
|
return (0, _treeUtil.calcCheckedKeys)(newCheckedKeys, keyEntities);
|
|
617
634
|
}
|
|
618
635
|
calcCheckedStatus(targetStatus, eventKey) {
|
|
@@ -637,7 +654,8 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
637
654
|
const {
|
|
638
655
|
treeData,
|
|
639
656
|
filteredShownKeys,
|
|
640
|
-
keyEntities
|
|
657
|
+
keyEntities,
|
|
658
|
+
keyMaps
|
|
641
659
|
} = this.getStates();
|
|
642
660
|
const showFilteredOnly = this._showFilteredOnly();
|
|
643
661
|
// clone otherwise will be modified unexpectedly
|
|
@@ -661,7 +679,7 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
661
679
|
this._adapter.cacheFlattenNodes(motionType === 'hide' && this._isAnimated());
|
|
662
680
|
if (!this._isExpandControlled()) {
|
|
663
681
|
// debugger;
|
|
664
|
-
const flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, filteredExpandedKeys, showFilteredOnly && filteredShownKeys);
|
|
682
|
+
const flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, filteredExpandedKeys, keyMaps, showFilteredOnly && filteredShownKeys);
|
|
665
683
|
const motionKeys = this._isAnimated() ? (0, _treeUtil.getMotionKeys)(eventKey, filteredExpandedKeys, keyEntities) : [];
|
|
666
684
|
const newState = {
|
|
667
685
|
filteredExpandedKeys,
|
|
@@ -679,7 +697,8 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
679
697
|
handleNodeExpand(e, treeNode) {
|
|
680
698
|
// debugger;
|
|
681
699
|
const {
|
|
682
|
-
loadData
|
|
700
|
+
loadData,
|
|
701
|
+
keyMaps
|
|
683
702
|
} = this.getProps();
|
|
684
703
|
const {
|
|
685
704
|
inputValue,
|
|
@@ -716,7 +735,7 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
716
735
|
this._adapter.cacheFlattenNodes(motionType === 'hide' && this._isAnimated());
|
|
717
736
|
if (!isExpandControlled) {
|
|
718
737
|
// debugger;
|
|
719
|
-
const flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, expandedKeys);
|
|
738
|
+
const flattenNodes = (0, _treeUtil.flattenTreeData)(treeData, expandedKeys, keyMaps);
|
|
720
739
|
const motionKeys = this._isAnimated() ? (0, _treeUtil.getMotionKeys)(eventKey, expandedKeys, keyEntities) : [];
|
|
721
740
|
const newState = {
|
|
722
741
|
expandedKeys,
|
|
@@ -737,19 +756,21 @@ class TreeSelectFoundation extends _foundation.default {
|
|
|
737
756
|
getRenderTextInSingle() {
|
|
738
757
|
const {
|
|
739
758
|
renderSelectedItem: propRenderSelectedItem,
|
|
740
|
-
treeNodeLabelProp
|
|
759
|
+
treeNodeLabelProp,
|
|
760
|
+
keyMaps
|
|
741
761
|
} = this.getProps();
|
|
742
762
|
const {
|
|
743
763
|
selectedKeys,
|
|
744
764
|
keyEntities
|
|
745
765
|
} = this.getStates();
|
|
746
|
-
const
|
|
766
|
+
const realLabelName = (0, _get2.default)(keyMaps, 'label', treeNodeLabelProp);
|
|
767
|
+
const renderSelectedItem = (0, _isFunction2.default)(propRenderSelectedItem) ? propRenderSelectedItem : item => (0, _get2.default)(item, realLabelName, null);
|
|
747
768
|
let item;
|
|
748
769
|
if (selectedKeys.length) {
|
|
749
770
|
const key = selectedKeys[0];
|
|
750
|
-
item = keyEntities[key] && keyEntities[key].
|
|
771
|
+
item = keyEntities[key] && keyEntities[key].key === key ? keyEntities[key].data : this.getDataForKeyNotInKeyEntities(key);
|
|
751
772
|
}
|
|
752
|
-
const renderText = item
|
|
773
|
+
const renderText = item ? renderSelectedItem(item) : null;
|
|
753
774
|
return renderText;
|
|
754
775
|
}
|
|
755
776
|
/**
|
|
@@ -239,10 +239,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
239
239
|
* @param {boolean} curCheckedStatus checked status of node
|
|
240
240
|
*/
|
|
241
241
|
calcCheckedKeys(key: string, curCheckedStatus: boolean): {
|
|
242
|
-
checkedKeys: Set<string>;
|
|
243
|
-
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
244
|
-
* the option is considered to be selected, even if the option is disabled
|
|
245
|
-
*/
|
|
242
|
+
checkedKeys: Set<string>;
|
|
246
243
|
halfCheckedKeys: Set<string>;
|
|
247
244
|
};
|
|
248
245
|
handleInputChange(sugInput: string): void;
|