@@ -28,22 +28,9 @@ import type { CheckedStrategy } from './utils/strategyUtil';
28
28
import { formatStrategyValues , SHOW_ALL , SHOW_CHILD , SHOW_PARENT } from './utils/strategyUtil' ;
29
29
import { fillFieldNames , isNil , toArray } from './utils/valueUtil' ;
30
30
import warningProps from './utils/warningPropsUtil' ;
31
+ import type { LabeledValueType , SafeKey , SelectSource , DefaultValueType } from './interface' ;
31
32
32
- export type OnInternalSelect = ( value : RawValueType , info : { selected : boolean } ) => void ;
33
-
34
- export type RawValueType = string | number ;
35
-
36
- export interface LabeledValueType {
37
- key ?: React . Key ;
38
- value ?: RawValueType ;
39
- label ?: React . ReactNode ;
40
- /** Only works on `treeCheckStrictly` */
41
- halfChecked ?: boolean ;
42
- }
43
-
44
- export type SelectSource = 'option' | 'selection' | 'input' | 'clear' ;
45
-
46
- export type DraftValueType = RawValueType | LabeledValueType | ( RawValueType | LabeledValueType ) [ ] ;
33
+ export type OnInternalSelect = ( value : SafeKey , info : { selected : boolean } ) => void ;
47
34
48
35
/** @deprecated This is only used for legacy compatible. Not works on new code. */
49
36
export interface LegacyCheckedNode {
@@ -55,7 +42,7 @@ export interface LegacyCheckedNode {
55
42
export interface ChangeEventExtra {
56
43
/** @deprecated Please save prev value by control logic instead */
57
44
preValue : LabeledValueType [ ] ;
58
- triggerValue : RawValueType ;
45
+ triggerValue : SafeKey ;
59
46
/** @deprecated Use `onSelect` or `onDeselect` instead. */
60
47
selected ?: boolean ;
61
48
/** @deprecated Use `onSelect` or `onDeselect` instead. */
@@ -79,9 +66,9 @@ export interface InternalFieldName extends Omit<FieldNames, 'label'> {
79
66
}
80
67
81
68
export interface SimpleModeConfig {
82
- id ?: React . Key ;
83
- pId ?: React . Key ;
84
- rootPId ?: React . Key ;
69
+ id ?: SafeKey ;
70
+ pId ?: SafeKey ;
71
+ rootPId ?: SafeKey ;
85
72
}
86
73
87
74
export interface BaseOptionType {
@@ -93,10 +80,10 @@ export interface BaseOptionType {
93
80
}
94
81
95
82
export interface DefaultOptionType extends BaseOptionType {
96
- value ?: RawValueType ;
83
+ value ?: SafeKey ;
97
84
title ?: React . ReactNode ;
98
85
label ?: React . ReactNode ;
99
- key ?: React . Key ;
86
+ key ?: SafeKey ;
100
87
children ?: DefaultOptionType [ ] ;
101
88
}
102
89
@@ -145,14 +132,14 @@ export interface TreeSelectProps<
145
132
treeData ?: OptionType [ ] ;
146
133
treeDataSimpleMode ?: boolean | SimpleModeConfig ;
147
134
loadData ?: ( dataNode : LegacyDataNode ) => Promise < unknown > ;
148
- treeLoadedKeys ?: React . Key [ ] ;
149
- onTreeLoad ?: ( loadedKeys : React . Key [ ] ) => void ;
135
+ treeLoadedKeys ?: SafeKey [ ] ;
136
+ onTreeLoad ?: ( loadedKeys : SafeKey [ ] ) => void ;
150
137
151
138
// >>> Expanded
152
139
treeDefaultExpandAll ?: boolean ;
153
- treeExpandedKeys ?: React . Key [ ] ;
154
- treeDefaultExpandedKeys ?: React . Key [ ] ;
155
- onTreeExpand ?: ( expandedKeys : React . Key [ ] ) => void ;
140
+ treeExpandedKeys ?: SafeKey [ ] ;
141
+ treeDefaultExpandedKeys ?: SafeKey [ ] ;
142
+ onTreeExpand ?: ( expandedKeys : SafeKey [ ] ) => void ;
156
143
treeExpandAction ?: ExpandAction ;
157
144
158
145
// >>> Options
@@ -171,7 +158,7 @@ export interface TreeSelectProps<
171
158
treeMotion ?: any ;
172
159
}
173
160
174
- function isRawValue ( value : RawValueType | LabeledValueType ) : value is RawValueType {
161
+ function isRawValue ( value : SafeKey | LabeledValueType ) : value is SafeKey {
175
162
return ! value || typeof value !== 'object' ;
176
163
}
177
164
@@ -295,7 +282,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
295
282
296
283
/** Get `missingRawValues` which not exist in the tree yet */
297
284
const splitRawValues = React . useCallback (
298
- ( newRawValues : RawValueType [ ] ) => {
285
+ ( newRawValues : SafeKey [ ] ) => {
299
286
const missingRawValues = [ ] ;
300
287
const existRawValues = [ ] ;
301
288
@@ -343,7 +330,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
343
330
) ;
344
331
345
332
// ========================= Wrap Value =========================
346
- const toLabeledValues = React . useCallback ( ( draftValues : DraftValueType ) => {
333
+ const toLabeledValues = React . useCallback ( ( draftValues : DefaultValueType ) => {
347
334
const values = toArray ( draftValues ) ;
348
335
349
336
return values . map ( val => {
@@ -355,7 +342,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
355
342
} , [ ] ) ;
356
343
357
344
const convert2LabelValues = React . useCallback (
358
- ( draftValues : DraftValueType ) => {
345
+ ( draftValues : DefaultValueType ) => {
359
346
const values = toLabeledValues ( draftValues ) ;
360
347
361
348
return values . map ( item => {
@@ -368,7 +355,9 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
368
355
369
356
// Fill missing label & status
370
357
if ( entity ) {
371
- rawLabel = treeTitleRender ? treeTitleRender ( entity . node ) : rawLabel ?? getLabel ( entity . node ) ;
358
+ rawLabel = treeTitleRender
359
+ ? treeTitleRender ( entity . node )
360
+ : ( rawLabel ?? getLabel ( entity . node ) ) ;
372
361
rawDisabled = entity . node . disabled ;
373
362
} else if ( rawLabel === undefined ) {
374
363
// We try to find in current `labelInValue` value
@@ -475,8 +464,8 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
475
464
// =========================== Change ===========================
476
465
const triggerChange = useRefFunc (
477
466
(
478
- newRawValues : RawValueType [ ] ,
479
- extra : { triggerValue ?: RawValueType ; selected ?: boolean } ,
467
+ newRawValues : SafeKey [ ] ,
468
+ extra : { triggerValue ?: SafeKey ; selected ?: boolean } ,
480
469
source : SelectSource ,
481
470
) => {
482
471
const labeledValues = convert2LabelValues ( newRawValues ) ;
@@ -489,7 +478,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
489
478
490
479
// Generate rest parameters is costly, so only do it when necessary
491
480
if ( onChange ) {
492
- let eventValues : RawValueType [ ] = newRawValues ;
481
+ let eventValues : SafeKey [ ] = newRawValues ;
493
482
if ( treeConduction ) {
494
483
const formattedKeyList = formatStrategyValues (
495
484
newRawValues ,
@@ -508,7 +497,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
508
497
selected : undefined ,
509
498
} ;
510
499
511
- let returnRawValues : ( LabeledValueType | RawValueType ) [ ] = eventValues ;
500
+ let returnRawValues : ( LabeledValueType | SafeKey ) [ ] = eventValues ;
512
501
513
502
// We need fill half check back
514
503
if ( treeCheckStrictly ) {
@@ -563,7 +552,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
563
552
// ========================== Options ===========================
564
553
/** Trigger by option list */
565
554
const onOptionSelect = React . useCallback (
566
- ( selectedKey : React . Key , { selected, source } : { selected : boolean ; source : SelectSource } ) => {
555
+ ( selectedKey : SafeKey , { selected, source } : { selected : boolean ; source : SelectSource } ) => {
567
556
const entity = keyEntities [ selectedKey ] ;
568
557
const node = entity ?. node ;
569
558
const selectedValue = node ?. [ mergedFieldNames . value ] ?? selectedKey ;
@@ -584,7 +573,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
584
573
const keyList = existRawValues . map ( val => valueEntities . get ( val ) . key ) ;
585
574
586
575
// Conduction by selected or not
587
- let checkedKeys : React . Key [ ] ;
576
+ let checkedKeys : SafeKey [ ] ;
588
577
if ( selected ) {
589
578
( { checkedKeys } = conductCheck ( keyList , true , keyEntities ) ) ;
590
579
} else {
0 commit comments