1
- import type {
2
- BaseSelectProps ,
3
- BaseSelectPropsWithoutPrivate ,
4
- BaseSelectRef ,
5
- SelectProps ,
6
- } from 'rc-select' ;
1
+ import type { BaseSelectPropsWithoutPrivate , BaseSelectRef } from 'rc-select' ;
7
2
import { BaseSelect } from 'rc-select' ;
8
3
import useId from 'rc-select/lib/hooks/useId' ;
9
4
import type { IconType } from 'rc-tree/lib/interface' ;
@@ -28,72 +23,21 @@ import type { CheckedStrategy } from './utils/strategyUtil';
28
23
import { formatStrategyValues , SHOW_ALL , SHOW_CHILD , SHOW_PARENT } from './utils/strategyUtil' ;
29
24
import { fillFieldNames , isNil , toArray } from './utils/valueUtil' ;
30
25
import warningProps from './utils/warningPropsUtil' ;
31
- import type { LabeledValueType , SafeKey , SelectSource , DefaultValueType } from './interface' ;
32
-
33
- export type OnInternalSelect = ( value : SafeKey , info : { selected : boolean } ) => void ;
34
-
35
- /** @deprecated This is only used for legacy compatible. Not works on new code. */
36
- export interface LegacyCheckedNode {
37
- pos : string ;
38
- node : React . ReactElement ;
39
- children ?: LegacyCheckedNode [ ] ;
40
- }
41
-
42
- export interface ChangeEventExtra {
43
- /** @deprecated Please save prev value by control logic instead */
44
- preValue : LabeledValueType [ ] ;
45
- triggerValue : SafeKey ;
46
- /** @deprecated Use `onSelect` or `onDeselect` instead. */
47
- selected ?: boolean ;
48
- /** @deprecated Use `onSelect` or `onDeselect` instead. */
49
- checked ?: boolean ;
50
-
51
- // Not sure if exist user still use this. We have to keep but not recommend user to use
52
- /** @deprecated This prop not work as react node anymore. */
53
- triggerNode : React . ReactElement ;
54
- /** @deprecated This prop not work as react node anymore. */
55
- allCheckedNodes : LegacyCheckedNode [ ] ;
56
- }
57
-
58
- export interface FieldNames {
59
- value ?: string ;
60
- label ?: string ;
61
- children ?: string ;
62
- }
63
-
64
- export interface InternalFieldName extends Omit < FieldNames , 'label' > {
65
- _title : string [ ] ;
66
- }
67
-
68
- export interface SimpleModeConfig {
69
- id ?: SafeKey ;
70
- pId ?: SafeKey ;
71
- rootPId ?: SafeKey ;
72
- }
73
-
74
- export interface BaseOptionType {
75
- disabled ?: boolean ;
76
- checkable ?: boolean ;
77
- disableCheckbox ?: boolean ;
78
- children ?: BaseOptionType [ ] ;
79
- [ name : string ] : any ;
80
- }
81
-
82
- export interface DefaultOptionType extends BaseOptionType {
83
- value ?: SafeKey ;
84
- title ?: React . ReactNode | ( ( data : DefaultOptionType ) => React . ReactNode ) ;
85
- label ?: React . ReactNode ;
86
- key ?: SafeKey ;
87
- children ?: DefaultOptionType [ ] ;
88
- }
89
-
90
- export interface LegacyDataNode extends DefaultOptionType {
91
- props : any ;
92
- }
93
- export interface TreeSelectProps <
94
- ValueType = any ,
95
- OptionType extends BaseOptionType = DefaultOptionType ,
96
- > extends Omit < BaseSelectPropsWithoutPrivate , 'mode' > {
26
+ import type {
27
+ LabeledValueType ,
28
+ SafeKey ,
29
+ Key ,
30
+ DataNode ,
31
+ SimpleModeConfig ,
32
+ ChangeEventExtra ,
33
+ SelectSource ,
34
+ DefaultValueType ,
35
+ FieldNames ,
36
+ LegacyDataNode ,
37
+ } from './interface' ;
38
+
39
+ export interface TreeSelectProps < ValueType = any , OptionType extends DataNode = DataNode >
40
+ extends Omit < BaseSelectPropsWithoutPrivate , 'mode' > {
97
41
prefixCls ?: string ;
98
42
id ?: string ;
99
43
children ?: React . ReactNode ;
@@ -109,12 +53,12 @@ export interface TreeSelectProps<
109
53
inputValue ?: string ;
110
54
onSearch ?: ( value : string ) => void ;
111
55
autoClearSearchValue ?: boolean ;
112
- filterTreeNode ?: boolean | ( ( inputValue : string , treeNode : DefaultOptionType ) => boolean ) ;
56
+ filterTreeNode ?: boolean | ( ( inputValue : string , treeNode : DataNode ) => boolean ) ;
113
57
treeNodeFilterProp ?: string ;
114
58
115
59
// >>> Select
116
- onSelect ?: SelectProps < ValueType , OptionType > [ 'onSelect' ] ;
117
- onDeselect ?: SelectProps < ValueType , OptionType > [ 'onDeselect' ] ;
60
+ onSelect ?: ( value : ValueType , option : OptionType ) => void ;
61
+ onDeselect ?: ( value : ValueType , option : OptionType ) => void ;
118
62
119
63
// >>> Selector
120
64
showCheckedStrategy ?: CheckedStrategy ;
@@ -255,7 +199,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
255
199
}
256
200
257
201
// ========================= FieldNames =========================
258
- const mergedFieldNames : InternalFieldName = React . useMemo (
202
+ const mergedFieldNames : FieldNames = React . useMemo (
259
203
( ) => fillFieldNames ( fieldNames ) ,
260
204
/* eslint-disable react-hooks/exhaustive-deps */
261
205
[ JSON . stringify ( fieldNames ) ] ,
@@ -268,7 +212,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
268
212
postState : search => search || '' ,
269
213
} ) ;
270
214
271
- const onInternalSearch : BaseSelectProps [ 'onSearch' ] = searchText => {
215
+ const onInternalSearch = searchText => {
272
216
setSearchValue ( searchText ) ;
273
217
onSearch ?.( searchText ) ;
274
218
} ;
@@ -310,7 +254,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
310
254
311
255
// =========================== Label ============================
312
256
const getLabel = React . useCallback (
313
- ( item : DefaultOptionType ) => {
257
+ ( item : DataNode ) => {
314
258
if ( item ) {
315
259
if ( treeNodeLabelProp ) {
316
260
return item [ treeNodeLabelProp ] ;
@@ -418,7 +362,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
418
362
const displayValues = React . useMemo ( ( ) => {
419
363
// Collect keys which need to show
420
364
const displayKeys = formatStrategyValues (
421
- rawCheckedValues ,
365
+ rawCheckedValues as SafeKey [ ] ,
422
366
mergedShowCheckedStrategy ,
423
367
keyEntities ,
424
368
mergedFieldNames ,
@@ -574,7 +518,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
574
518
const keyList = existRawValues . map ( val => valueEntities . get ( val ) . key ) ;
575
519
576
520
// Conduction by selected or not
577
- let checkedKeys : SafeKey [ ] ;
521
+ let checkedKeys : Key [ ] ;
578
522
if ( selected ) {
579
523
( { checkedKeys } = conductCheck ( keyList , true , keyEntities ) ) ;
580
524
} else {
@@ -588,7 +532,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
588
532
// Fill back of keys
589
533
newRawValues = [
590
534
...missingRawValues ,
591
- ...checkedKeys . map ( key => keyEntities [ key ] . node [ mergedFieldNames . value ] ) ,
535
+ ...checkedKeys . map ( key => keyEntities [ key as SafeKey ] . node [ mergedFieldNames . value ] ) ,
592
536
] ;
593
537
}
594
538
triggerChange ( newRawValues , { selected, triggerValue : selectedValue } , source || 'option' ) ;
@@ -637,21 +581,19 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
637
581
) ;
638
582
639
583
// ====================== Display Change ========================
640
- const onDisplayValuesChange = useRefFunc < BaseSelectProps [ 'onDisplayValuesChange' ] > (
641
- ( newValues , info ) => {
642
- const newRawValues = newValues . map ( item => item . value ) ;
584
+ const onDisplayValuesChange = useRefFunc ( ( newValues , info ) => {
585
+ const newRawValues = newValues . map ( item => item . value ) ;
643
586
644
- if ( info . type === 'clear' ) {
645
- triggerChange ( newRawValues , { } , 'selection' ) ;
646
- return ;
647
- }
587
+ if ( info . type === 'clear' ) {
588
+ triggerChange ( newRawValues , { } , 'selection' ) ;
589
+ return ;
590
+ }
648
591
649
- // TreeSelect only have multiple mode which means display change only has remove
650
- if ( info . values . length ) {
651
- onOptionSelect ( info . values [ 0 ] . value , { selected : false , source : 'selection' } ) ;
652
- }
653
- } ,
654
- ) ;
592
+ // TreeSelect only have multiple mode which means display change only has remove
593
+ if ( info . values . length ) {
594
+ onOptionSelect ( info . values [ 0 ] . value , { selected : false , source : 'selection' } ) ;
595
+ }
596
+ } ) ;
655
597
656
598
// ========================== Context ===========================
657
599
const treeSelectContext = React . useMemo < TreeSelectContextProps > (
@@ -760,7 +702,7 @@ if (process.env.NODE_ENV !== 'production') {
760
702
761
703
const GenericTreeSelect = TreeSelect as unknown as ( <
762
704
ValueType = any ,
763
- OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType ,
705
+ OptionType extends DataNode = DataNode ,
764
706
> (
765
707
props : React . PropsWithChildren < TreeSelectProps < ValueType , OptionType > > & {
766
708
ref ?: React . Ref < BaseSelectRef > ;
0 commit comments