@douyinfe/semi-foundation 2.46.1 → 2.47.0-beta.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/button/button.scss +88 -20
- package/button/variables.scss +13 -0
- package/datePicker/inputFoundation.ts +7 -5
- package/lib/cjs/button/button.css +30 -2
- package/lib/cjs/button/button.scss +88 -20
- package/lib/cjs/button/variables.scss +13 -0
- package/lib/cjs/cascader/foundation.d.ts +1 -4
- package/lib/cjs/datePicker/inputFoundation.js +17 -8
- package/lib/cjs/table/foundation.d.ts +1 -1
- 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/cjs/typography/typography.css +5 -0
- package/lib/cjs/typography/typography.scss +5 -0
- package/lib/cjs/typography/variables.scss +4 -0
- package/lib/cjs/utils/array.d.ts +2 -2
- package/lib/cjs/utils/array.js +2 -2
- package/lib/es/button/button.css +30 -2
- package/lib/es/button/button.scss +88 -20
- package/lib/es/button/variables.scss +13 -0
- package/lib/es/cascader/foundation.d.ts +1 -4
- package/lib/es/datePicker/inputFoundation.js +17 -8
- package/lib/es/table/foundation.d.ts +1 -1
- 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/lib/es/typography/typography.css +5 -0
- package/lib/es/typography/typography.scss +5 -0
- package/lib/es/typography/variables.scss +4 -0
- package/lib/es/utils/array.d.ts +2 -2
- package/lib/es/utils/array.js +2 -2
- package/package.json +3 -3
- package/table/foundation.ts +1 -1
- package/tree/foundation.ts +14 -7
- package/tree/treeUtil.ts +47 -18
- package/treeSelect/foundation.ts +35 -26
- package/typography/typography.scss +5 -0
- package/typography/variables.scss +4 -0
- package/utils/array.ts +4 -4
package/tree/treeUtil.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* https://github.com/react-component/tree/blob/master/src/util.tsx
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { difference, uniq, max, isObject, isNull, isUndefined, isEmpty, pick, get } from 'lodash';
|
|
6
|
+
import { difference, uniq, max, isObject, isNull, isUndefined, isEmpty, pick, get, omit } from 'lodash';
|
|
7
7
|
|
|
8
8
|
export interface KeyEntities {
|
|
9
9
|
[x: string]: any
|
|
@@ -20,6 +20,16 @@ export interface NodeData {
|
|
|
20
20
|
children?: any
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export interface KeyMapProps {
|
|
24
|
+
key?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
value?: string;
|
|
27
|
+
disabled?: string;
|
|
28
|
+
children?: string;
|
|
29
|
+
isLeaf?: string;
|
|
30
|
+
icon?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
const DRAG_OFFSET = 0.45;
|
|
24
34
|
|
|
25
35
|
function getPosition(level: any, index: any) {
|
|
@@ -37,17 +47,28 @@ function isValid(val: any) {
|
|
|
37
47
|
* @param filteredShownKeys
|
|
38
48
|
* need expanded keys, provides `true` means all expanded
|
|
39
49
|
*/
|
|
40
|
-
export function flattenTreeData(treeNodeList: any[], expandedKeys: Set<string>, filteredShownKeys: boolean | Set<any> = false) {
|
|
50
|
+
export function flattenTreeData(treeNodeList: any[], expandedKeys: Set<string>, keyMaps: KeyMapProps, filteredShownKeys: boolean | Set<any> = false) {
|
|
41
51
|
const flattenList: any[] = [];
|
|
42
52
|
const filterSearch = Boolean(filteredShownKeys);
|
|
53
|
+
const realKeyName = get(keyMaps, 'key', 'key');
|
|
54
|
+
const realChildrenName = get(keyMaps, 'children', 'children');
|
|
43
55
|
function flatten(list: any[], parent: any = null) {
|
|
44
56
|
return list.map((treeNode, index) => {
|
|
45
57
|
const pos = getPosition(parent ? parent.pos : '0', index);
|
|
46
|
-
const mergedKey = treeNode
|
|
58
|
+
const mergedKey = treeNode[realKeyName];
|
|
59
|
+
|
|
60
|
+
const otherData = {};
|
|
61
|
+
if (keyMaps) {
|
|
62
|
+
Object.entries(omit(keyMaps, 'children')).forEach(([key, value]) => {
|
|
63
|
+
const result = treeNode[value as string];
|
|
64
|
+
!isUndefined(result) && (otherData[key] = result);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
47
67
|
|
|
48
68
|
// Add FlattenDataNode into list
|
|
49
69
|
const flattenNode: any = {
|
|
50
70
|
...pick(treeNode, ['key', 'label', 'value', 'icon', 'disabled', 'isLeaf']),
|
|
71
|
+
...otherData,
|
|
51
72
|
parent,
|
|
52
73
|
pos,
|
|
53
74
|
children: null,
|
|
@@ -61,7 +82,7 @@ export function flattenTreeData(treeNodeList: any[], expandedKeys: Set<string>,
|
|
|
61
82
|
|
|
62
83
|
// Loop treeNode children
|
|
63
84
|
if (expandedKeys.has(mergedKey) && (!filterSearch || (!isBooleanFilteredShownKeys && filteredShownKeys.has(mergedKey)))) {
|
|
64
|
-
flattenNode.children = flatten(treeNode
|
|
85
|
+
flattenNode.children = flatten(treeNode[realChildrenName] || [], flattenNode);
|
|
65
86
|
} else {
|
|
66
87
|
flattenNode.children = [];
|
|
67
88
|
}
|
|
@@ -100,17 +121,20 @@ export function convertJsonToData(treeJson: TreeDataSimpleJson) {
|
|
|
100
121
|
/**
|
|
101
122
|
* Traverse all the data by `treeData`.
|
|
102
123
|
*/
|
|
103
|
-
export function traverseDataNodes(treeNodes: any[], callback: (data: any) => void) {
|
|
124
|
+
export function traverseDataNodes(treeNodes: any[], callback: (data: any) => void, keyMaps: KeyMapProps) {
|
|
125
|
+
const realKeyName = get(keyMaps, 'key', 'key');
|
|
126
|
+
const realChildrenName = get(keyMaps, 'children', 'children');
|
|
104
127
|
const processNode = (node: any, ind?: number, parent?: any) => {
|
|
105
|
-
const children = node ? node
|
|
128
|
+
const children = node ? node[realChildrenName] : treeNodes;
|
|
106
129
|
const pos = node ? getPosition(parent.pos, ind) : '0';
|
|
107
130
|
// Process node if is not root
|
|
108
131
|
if (node) {
|
|
132
|
+
const nodeKey = get(node, realKeyName, null);
|
|
109
133
|
const data = {
|
|
110
134
|
data: { ...node },
|
|
111
135
|
ind,
|
|
112
136
|
pos,
|
|
113
|
-
key:
|
|
137
|
+
key: nodeKey !== null ? nodeKey : pos,
|
|
114
138
|
parentPos: parent.node ? parent.pos : null,
|
|
115
139
|
level: Number(parent.level) + 1,
|
|
116
140
|
};
|
|
@@ -132,7 +156,7 @@ export function traverseDataNodes(treeNodes: any[], callback: (data: any) => voi
|
|
|
132
156
|
}
|
|
133
157
|
|
|
134
158
|
/* Convert data to entities map */
|
|
135
|
-
export function convertDataToEntities(dataNodes: any[]) {
|
|
159
|
+
export function convertDataToEntities(dataNodes: any[], keyMaps?: KeyMapProps) {
|
|
136
160
|
const posEntities = {};
|
|
137
161
|
const keyEntities = {};
|
|
138
162
|
const valueEntities = {};
|
|
@@ -141,11 +165,12 @@ export function convertDataToEntities(dataNodes: any[]) {
|
|
|
141
165
|
keyEntities,
|
|
142
166
|
valueEntities,
|
|
143
167
|
};
|
|
168
|
+
const realValueName = get(keyMaps, 'value', 'value');
|
|
144
169
|
|
|
145
170
|
traverseDataNodes(dataNodes, (data: any) => {
|
|
146
171
|
const { pos, key, parentPos } = data;
|
|
147
172
|
const entity = { ...data };
|
|
148
|
-
const value = get(entity,
|
|
173
|
+
const value = get(entity, `data.${realValueName}`, null);
|
|
149
174
|
|
|
150
175
|
if (value !== null) {
|
|
151
176
|
valueEntities[value] = key;
|
|
@@ -160,7 +185,7 @@ export function convertDataToEntities(dataNodes: any[]) {
|
|
|
160
185
|
entity.parent.children = entity.parent.children || [];
|
|
161
186
|
entity.parent.children.push(entity);
|
|
162
187
|
}
|
|
163
|
-
});
|
|
188
|
+
}, keyMaps);
|
|
164
189
|
|
|
165
190
|
return wrapper;
|
|
166
191
|
}
|
|
@@ -566,6 +591,7 @@ export function filterTreeData(info: any) {
|
|
|
566
591
|
filterTreeNode,
|
|
567
592
|
filterProps,
|
|
568
593
|
prevExpandedKeys,
|
|
594
|
+
keyMaps
|
|
569
595
|
} = info;
|
|
570
596
|
|
|
571
597
|
let filteredOptsKeys = [];
|
|
@@ -579,7 +605,7 @@ export function filterTreeData(info: any) {
|
|
|
579
605
|
}
|
|
580
606
|
const shownChildKeys = findDescendantKeys(filteredOptsKeys, keyEntities, true);
|
|
581
607
|
const filteredShownKeys = new Set([...shownChildKeys, ...expandedOptsKeys]);
|
|
582
|
-
const flattenNodes = flattenTreeData(treeData, new Set(expandedOptsKeys), showFilteredOnly && filteredShownKeys);
|
|
608
|
+
const flattenNodes = flattenTreeData(treeData, new Set(expandedOptsKeys), keyMaps, showFilteredOnly && filteredShownKeys);
|
|
583
609
|
|
|
584
610
|
return {
|
|
585
611
|
flattenNodes,
|
|
@@ -590,17 +616,19 @@ export function filterTreeData(info: any) {
|
|
|
590
616
|
}
|
|
591
617
|
|
|
592
618
|
// return data.value if data.value exist else fall back to key
|
|
593
|
-
export function getValueOrKey(data: any) {
|
|
619
|
+
export function getValueOrKey(data: any, keyMaps?: KeyMapProps) {
|
|
620
|
+
const valueName = get(keyMaps, 'value', 'value');
|
|
621
|
+
const keyName = get(keyMaps, 'key', 'key');
|
|
594
622
|
if (Array.isArray(data)) {
|
|
595
|
-
return data.map(item => get(item,
|
|
623
|
+
return data.map(item => get(item, valueName, item[keyName]));
|
|
596
624
|
}
|
|
597
|
-
return get(data,
|
|
625
|
+
return get(data, valueName, data[keyName]);
|
|
598
626
|
}
|
|
599
627
|
|
|
600
628
|
/* Convert value to string */
|
|
601
|
-
export function normalizeValue(value: any, withObject: boolean) {
|
|
629
|
+
export function normalizeValue(value: any, withObject: boolean, keyMaps?: KeyMapProps) {
|
|
602
630
|
if (withObject && isValid(value)) {
|
|
603
|
-
return getValueOrKey(value);
|
|
631
|
+
return getValueOrKey(value, keyMaps);
|
|
604
632
|
} else {
|
|
605
633
|
return value;
|
|
606
634
|
}
|
|
@@ -611,8 +639,9 @@ export function updateKeys(keySet: Set<string> | string[], keyEntities: KeyEntit
|
|
|
611
639
|
return keyArr.filter(key => key in keyEntities);
|
|
612
640
|
}
|
|
613
641
|
|
|
614
|
-
export function calcDisabledKeys(keyEntities: KeyEntities) {
|
|
615
|
-
const
|
|
642
|
+
export function calcDisabledKeys(keyEntities: KeyEntities, keyMaps?: KeyMapProps) {
|
|
643
|
+
const disabledName = get(keyMaps, 'disabled', 'disabled');
|
|
644
|
+
const disabledKeys = Object.keys(keyEntities).filter(key => keyEntities[key].data[disabledName]);
|
|
616
645
|
const { checkedKeys } = calcCheckedKeys(disabledKeys, keyEntities);
|
|
617
646
|
return checkedKeys;
|
|
618
647
|
}
|
package/treeSelect/foundation.ts
CHANGED
|
@@ -271,7 +271,9 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
findDataForValue(findValue: string) {
|
|
274
|
-
const { value, defaultValue } = this.getProps();
|
|
274
|
+
const { value, defaultValue, keyMaps } = this.getProps();
|
|
275
|
+
const realValueName = get(keyMaps, 'value', 'value');
|
|
276
|
+
const realKeyName = get(keyMaps, 'key', 'key');
|
|
275
277
|
let valueArr = [];
|
|
276
278
|
if (value) {
|
|
277
279
|
valueArr = Array.isArray(value) ? value : [value];
|
|
@@ -279,15 +281,17 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
279
281
|
valueArr = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
280
282
|
}
|
|
281
283
|
return valueArr.find(item => {
|
|
282
|
-
return item
|
|
284
|
+
return item[realValueName] === findValue || item[realKeyName] === findValue;
|
|
283
285
|
});
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
constructDataForValue(value: string) {
|
|
287
|
-
const { treeNodeLabelProp } = this.getProps();
|
|
289
|
+
const { treeNodeLabelProp, keyMaps } = this.getProps();
|
|
290
|
+
const keyName = get(keyMaps, 'key', 'key');
|
|
291
|
+
const labelName = get(keyMaps, 'label', treeNodeLabelProp);
|
|
288
292
|
return {
|
|
289
|
-
|
|
290
|
-
[
|
|
293
|
+
[keyName]: value,
|
|
294
|
+
[labelName]: value
|
|
291
295
|
};
|
|
292
296
|
}
|
|
293
297
|
|
|
@@ -401,29 +405,30 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
401
405
|
|
|
402
406
|
_notifyMultipleChange(key: string[], e: any) {
|
|
403
407
|
const { keyEntities } = this.getStates();
|
|
404
|
-
const { leafOnly, checkRelation } = this.getProps();
|
|
408
|
+
const { leafOnly, checkRelation, keyMaps } = this.getProps();
|
|
405
409
|
let keyList = [];
|
|
406
410
|
if (checkRelation === 'related') {
|
|
407
411
|
keyList = normalizeKeyList(key, keyEntities, leafOnly, true);
|
|
408
412
|
} else if (checkRelation === 'unRelated') {
|
|
409
413
|
keyList = key as string[];
|
|
410
414
|
}
|
|
411
|
-
const nodes = keyList.map(key => (keyEntities[key] && keyEntities[key].
|
|
415
|
+
const nodes = keyList.map(key => (keyEntities[key] && keyEntities[key].key === key) ? keyEntities[key].data : this.getDataForKeyNotInKeyEntities(key));
|
|
412
416
|
if (this.getProp('onChangeWithObject')) {
|
|
413
417
|
this._adapter.notifyChangeWithObject(nodes, e);
|
|
414
418
|
} else {
|
|
415
|
-
const value = getValueOrKey(nodes);
|
|
419
|
+
const value = getValueOrKey(nodes, keyMaps);
|
|
416
420
|
this._adapter.notifyChange(value, nodes, e);
|
|
417
421
|
}
|
|
418
422
|
}
|
|
419
423
|
|
|
420
424
|
_notifyChange(key: any, e: any) {
|
|
421
425
|
const { keyEntities } = this.getStates();
|
|
426
|
+
const { keyMaps } = this.getProps();
|
|
422
427
|
if (this._isMultiple() && Array.isArray(key)) {
|
|
423
428
|
this._notifyMultipleChange(key, e);
|
|
424
429
|
} else {
|
|
425
430
|
const nodes = isUndefined(key) ? key : keyEntities[key].data;
|
|
426
|
-
const value = isUndefined(key) ? key : getValueOrKey(nodes);
|
|
431
|
+
const value = isUndefined(key) ? key : getValueOrKey(nodes, keyMaps);
|
|
427
432
|
if (this.getProp('onChangeWithObject')) {
|
|
428
433
|
this._adapter.notifyChangeWithObject(nodes, e);
|
|
429
434
|
} else {
|
|
@@ -552,10 +557,11 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
552
557
|
}
|
|
553
558
|
|
|
554
559
|
removeTag(eventKey: BasicTreeNodeData['key']) {
|
|
555
|
-
const { disableStrictly, checkRelation } = this.getProps();
|
|
560
|
+
const { disableStrictly, checkRelation, keyMaps } = this.getProps();
|
|
556
561
|
const { keyEntities, disabledKeys, realCheckedKeys } = this.getStates();
|
|
557
|
-
const item = (keyEntities[eventKey] && keyEntities[eventKey].
|
|
558
|
-
|
|
562
|
+
const item = (keyEntities[eventKey] && keyEntities[eventKey].key === eventKey) ? keyEntities[eventKey].data : this.getDataForKeyNotInKeyEntities(eventKey);
|
|
563
|
+
const disabledName = get(keyMaps, 'disabled', 'disabled');
|
|
564
|
+
if (item[disabledName] || (disableStrictly && disabledKeys.has(eventKey))) {
|
|
559
565
|
return;
|
|
560
566
|
}
|
|
561
567
|
if (checkRelation === 'unRelated') {
|
|
@@ -583,11 +589,12 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
583
589
|
|
|
584
590
|
clearInput() {
|
|
585
591
|
const { flattenNodes, expandedKeys, selectedKeys, keyEntities, treeData } = this.getStates();
|
|
592
|
+
const { keyMaps } = this.getProps();
|
|
586
593
|
const newExpandedKeys: Set<string> = new Set(expandedKeys);
|
|
587
594
|
const isExpandControlled = this._isExpandControlled();
|
|
588
595
|
const expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities);
|
|
589
596
|
expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
|
|
590
|
-
const newFlattenNodes = flattenTreeData(treeData, newExpandedKeys);
|
|
597
|
+
const newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
|
|
591
598
|
|
|
592
599
|
this._adapter.updateState({
|
|
593
600
|
expandedKeys: isExpandControlled ? expandedKeys : newExpandedKeys,
|
|
@@ -604,7 +611,8 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
604
611
|
// Input is used as controlled component
|
|
605
612
|
this._adapter.updateInputValue(sugInput);
|
|
606
613
|
const { flattenNodes, expandedKeys, selectedKeys, keyEntities, treeData } = this.getStates();
|
|
607
|
-
const { showFilteredOnly, filterTreeNode, treeNodeFilterProp } = this.getProps();
|
|
614
|
+
const { showFilteredOnly, filterTreeNode, treeNodeFilterProp, keyMaps } = this.getProps();
|
|
615
|
+
const realFilterProp = treeNodeFilterProp !== 'label' ? treeNodeFilterProp : get(keyMaps, 'label', 'label');
|
|
608
616
|
const newExpandedKeys: Set<string> = new Set(expandedKeys);
|
|
609
617
|
let filteredOptsKeys: string[] = [];
|
|
610
618
|
let expandedOptsKeys = [];
|
|
@@ -613,18 +621,18 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
613
621
|
if (!sugInput) {
|
|
614
622
|
expandedOptsKeys = findAncestorKeys(selectedKeys, keyEntities);
|
|
615
623
|
expandedOptsKeys.forEach(item => newExpandedKeys.add(item));
|
|
616
|
-
newFlattenNodes = flattenTreeData(treeData, newExpandedKeys);
|
|
624
|
+
newFlattenNodes = flattenTreeData(treeData, newExpandedKeys, keyMaps);
|
|
617
625
|
} else {
|
|
618
626
|
filteredOptsKeys = Object.values(keyEntities)
|
|
619
627
|
.filter((item: BasicKeyEntity) => {
|
|
620
628
|
const { data } = item;
|
|
621
|
-
return filter(sugInput, data, filterTreeNode,
|
|
629
|
+
return filter(sugInput, data, filterTreeNode, realFilterProp);
|
|
622
630
|
})
|
|
623
631
|
.map((item: BasicKeyEntity) => item.key);
|
|
624
632
|
expandedOptsKeys = findAncestorKeys(filteredOptsKeys, keyEntities, false);
|
|
625
633
|
const shownChildKeys = findDescendantKeys(filteredOptsKeys, keyEntities, true);
|
|
626
634
|
filteredShownKeys = new Set([...shownChildKeys, ...expandedOptsKeys]);
|
|
627
|
-
newFlattenNodes = flattenTreeData(treeData, new Set(expandedOptsKeys), showFilteredOnly && filteredShownKeys);
|
|
635
|
+
newFlattenNodes = flattenTreeData(treeData, new Set(expandedOptsKeys), keyMaps, showFilteredOnly && filteredShownKeys);
|
|
628
636
|
}
|
|
629
637
|
const newFilteredExpandedKeys = new Set(expandedOptsKeys);
|
|
630
638
|
this._adapter.notifySearch(sugInput, Array.from(newFilteredExpandedKeys));
|
|
@@ -733,7 +741,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
733
741
|
const nonDisabled = descendantKeys.filter(key => !disabledKeys.has(key));
|
|
734
742
|
const newCheckedKeys = targetStatus ?
|
|
735
743
|
[...nonDisabled, ...checkedKeys] :
|
|
736
|
-
difference(normalizeKeyList([...checkedKeys], keyEntities, true), nonDisabled);
|
|
744
|
+
difference(normalizeKeyList([...checkedKeys], keyEntities, true, true), nonDisabled);
|
|
737
745
|
return calcCheckedKeys(newCheckedKeys, keyEntities);
|
|
738
746
|
}
|
|
739
747
|
|
|
@@ -752,7 +760,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
752
760
|
return !allChecked;
|
|
753
761
|
}
|
|
754
762
|
handleNodeExpandInSearch(e: any, treeNode: BasicTreeNodeProps) {
|
|
755
|
-
const { treeData, filteredShownKeys, keyEntities } = this.getStates();
|
|
763
|
+
const { treeData, filteredShownKeys, keyEntities, keyMaps } = this.getStates();
|
|
756
764
|
const showFilteredOnly = this._showFilteredOnly();
|
|
757
765
|
// clone otherwise will be modified unexpectedly
|
|
758
766
|
const { filteredExpandedKeys } = this.getCopyFromState('filteredExpandedKeys');
|
|
@@ -772,7 +780,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
772
780
|
|
|
773
781
|
if (!this._isExpandControlled()) {
|
|
774
782
|
// debugger;
|
|
775
|
-
const flattenNodes = flattenTreeData(treeData, filteredExpandedKeys, showFilteredOnly && filteredShownKeys);
|
|
783
|
+
const flattenNodes = flattenTreeData(treeData, filteredExpandedKeys, keyMaps, showFilteredOnly && filteredShownKeys);
|
|
776
784
|
const motionKeys = this._isAnimated() ? getMotionKeys(eventKey, filteredExpandedKeys, keyEntities) : [];
|
|
777
785
|
const newState = {
|
|
778
786
|
filteredExpandedKeys,
|
|
@@ -792,7 +800,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
792
800
|
|
|
793
801
|
handleNodeExpand(e: any, treeNode: BasicTreeNodeProps) {
|
|
794
802
|
// debugger;
|
|
795
|
-
const { loadData } = this.getProps();
|
|
803
|
+
const { loadData, keyMaps } = this.getProps();
|
|
796
804
|
const { inputValue, keyEntities } = this.getStates();
|
|
797
805
|
const isSearching = Boolean(inputValue);
|
|
798
806
|
if (!loadData && (!treeNode.children || !treeNode.children.length)) {
|
|
@@ -820,7 +828,7 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
820
828
|
|
|
821
829
|
if (!isExpandControlled) {
|
|
822
830
|
// debugger;
|
|
823
|
-
const flattenNodes = flattenTreeData(treeData, expandedKeys);
|
|
831
|
+
const flattenNodes = flattenTreeData(treeData, expandedKeys, keyMaps);
|
|
824
832
|
const motionKeys = this._isAnimated() ? getMotionKeys(eventKey, expandedKeys, keyEntities) : [];
|
|
825
833
|
const newState = {
|
|
826
834
|
expandedKeys,
|
|
@@ -841,17 +849,18 @@ export default class TreeSelectFoundation<P = Record<string, any>, S = Record<st
|
|
|
841
849
|
* The selected items that need to be displayed in the search box when obtaining a single selection
|
|
842
850
|
*/
|
|
843
851
|
getRenderTextInSingle() {
|
|
844
|
-
const { renderSelectedItem: propRenderSelectedItem, treeNodeLabelProp } = this.getProps();
|
|
852
|
+
const { renderSelectedItem: propRenderSelectedItem, treeNodeLabelProp, keyMaps } = this.getProps();
|
|
845
853
|
const { selectedKeys, keyEntities } = this.getStates();
|
|
854
|
+
const realLabelName = get(keyMaps, 'label', treeNodeLabelProp);
|
|
846
855
|
const renderSelectedItem = isFunction(propRenderSelectedItem) ?
|
|
847
856
|
propRenderSelectedItem :
|
|
848
|
-
(item: BasicTreeNodeData) => get(item,
|
|
857
|
+
(item: BasicTreeNodeData) => get(item, realLabelName, null);
|
|
849
858
|
let item;
|
|
850
859
|
if (selectedKeys.length) {
|
|
851
860
|
const key = selectedKeys[0];
|
|
852
|
-
item = (keyEntities[key] && keyEntities[key].
|
|
861
|
+
item = (keyEntities[key] && keyEntities[key].key === key) ? keyEntities[key].data : this.getDataForKeyNotInKeyEntities(key);
|
|
853
862
|
}
|
|
854
|
-
const renderText = item
|
|
863
|
+
const renderText = item ? renderSelectedItem(item) : null;
|
|
855
864
|
return renderText;
|
|
856
865
|
}
|
|
857
866
|
|
|
@@ -53,6 +53,10 @@ $module: #{$prefix}-typography;
|
|
|
53
53
|
|
|
54
54
|
&-small {
|
|
55
55
|
@include font-size-small;
|
|
56
|
+
font-weight: $font-typography_smallText-regular-fontWeight;
|
|
57
|
+
&.#{$module}-paragraph{
|
|
58
|
+
font-weight: $font-typography_smallParagraph-regular-fontWeight;
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
code {
|
|
@@ -351,6 +355,7 @@ h6.#{$module},
|
|
|
351
355
|
p.#{$module}-extended,
|
|
352
356
|
.#{$module}-paragraph.#{$module}-extended {
|
|
353
357
|
line-height: $font-typography_paragraph_extended-lineHeight;
|
|
358
|
+
font-weight: $font-typography_normalParagraph-regular-fontWeight;
|
|
354
359
|
}
|
|
355
360
|
|
|
356
361
|
@import "./rtl.scss";
|
|
@@ -26,6 +26,10 @@ $font-typography_title-fontWeight: $font-weight-bold; // 标题文本字重
|
|
|
26
26
|
$font-typography_link-fontWeight: $font-weight-bold; // 链接文本字重
|
|
27
27
|
$font-typography_strong-fontWeight: $font-weight-bold; // 强调文本字重
|
|
28
28
|
$font-typography_paragraph_extended-lineHeight: 24px; // 宽松行距段落文本行高
|
|
29
|
+
$font-typography_normalText-regular-fontWeight: $font-weight-regular; // normal text 字重 - 正常
|
|
30
|
+
$font-typography_smallText-regular-fontWeight: $font-weight-regular; // small text 字重 - 正常
|
|
31
|
+
$font-typography_normalParagraph-regular-fontWeight: $font-weight-regular; // normal paragraph 字重 - 正常
|
|
32
|
+
$font-typography_smallParagraph-regular-fontWeight: $font-weight-regular; // small paragraph 字重 - 正常
|
|
29
33
|
|
|
30
34
|
$font-typography_title1-fontWeight: $font-typography_title-fontWeight; // 一级标题文本字重
|
|
31
35
|
$font-typography_title2-fontWeight: $font-typography_title-fontWeight; // 二级标题文本字重
|
package/utils/array.ts
CHANGED
|
@@ -21,24 +21,24 @@ export function pullAll(arrayA: any[], arrayB: any[]) {
|
|
|
21
21
|
}
|
|
22
22
|
return arrayA;
|
|
23
23
|
}
|
|
24
|
-
type CompareFn<T> = (a: T, b: T) => number;
|
|
24
|
+
type CompareFn<T> = (a: T, b: T, sortOrder: 'ascend' | 'descend') => number;
|
|
25
25
|
/**
|
|
26
26
|
* Adapt the descending order
|
|
27
27
|
* @param {Function} fn
|
|
28
28
|
* @param {String} order
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
export function withOrderSort<T = any>(fn: CompareFn<T>, order = 'ascend'):
|
|
31
|
+
export function withOrderSort<T = any>(fn: CompareFn<T>, order: 'ascend' | 'descend' = 'ascend'): (a: T, b: T) => number {
|
|
32
32
|
switch (order) {
|
|
33
33
|
case 'descend':
|
|
34
34
|
return (
|
|
35
35
|
(a: any, b: any) => {
|
|
36
|
-
const result = Number(fn(a, b));
|
|
36
|
+
const result = Number(fn(a, b, order));
|
|
37
37
|
return result !== 0 ? -result : result;
|
|
38
38
|
}
|
|
39
39
|
);
|
|
40
40
|
case 'ascend':
|
|
41
41
|
default:
|
|
42
|
-
return fn;
|
|
42
|
+
return (a: any, b: any) => fn(a, b, order);
|
|
43
43
|
}
|
|
44
44
|
}
|