@@ -8,18 +8,14 @@ import { useComponentContext } from '../../context/ComponentContext';
8
8
import { Item } from './Item' ;
9
9
import { escapeRegExp } from '../Message/renderText' ;
10
10
11
- import type { CustomTrigger , UnknownType } from '../../types/types' ;
12
11
import type {
13
12
SuggestionEmoji ,
14
13
SuggestionItem ,
15
14
SuggestionListProps ,
16
15
SuggestionUser ,
17
16
} from '../ChatAutoComplete' ;
18
17
19
- export const List = <
20
- V extends CustomTrigger = CustomTrigger ,
21
- EmojiData extends UnknownType = UnknownType ,
22
- > ( {
18
+ export const List = ( {
23
19
className,
24
20
component,
25
21
currentTrigger,
@@ -34,7 +30,7 @@ export const List = <
34
30
SuggestionItem : PropSuggestionItem ,
35
31
value : propValue ,
36
32
values,
37
- } : SuggestionListProps < V > ) => {
33
+ } : SuggestionListProps ) => {
38
34
const { AutocompleteSuggestionItem } = useComponentContext ( 'SuggestionList' ) ;
39
35
const SuggestionItem = PropSuggestionItem || AutocompleteSuggestionItem || Item ;
40
36
@@ -44,42 +40,40 @@ export const List = <
44
40
45
41
const itemsRef : HTMLElement [ ] = [ ] ;
46
42
47
- const isSelected = ( item : SuggestionItem < EmojiData > ) =>
43
+ const isSelected = ( item : SuggestionItem ) =>
48
44
// @ts -expect-error tmp
49
45
selectedItemIndex === values . findIndex ( ( value ) => getId ( value ) === getId ( item ) ) ;
50
46
51
- const getId = ( item : SuggestionItem < EmojiData > ) => {
52
- // @ts -expect-error tmp
47
+ const getId = ( item : SuggestionItem ) => {
53
48
const textToReplace = getTextToReplace ( item ) ;
54
49
if ( textToReplace . key ) {
55
50
return textToReplace . key ;
56
51
}
57
52
58
- if ( typeof item === 'string' || ! ( item as SuggestionEmoji < EmojiData > ) . key ) {
53
+ if ( typeof item === 'string' || ! ( item as SuggestionEmoji ) . key ) {
59
54
return textToReplace . text ;
60
55
}
61
56
62
- return ( item as SuggestionEmoji < V > ) . key ;
57
+ return ( item as SuggestionEmoji ) . key ;
63
58
} ;
64
59
65
60
const findItemIndex = useCallback (
66
- ( item : SuggestionItem < V > ) =>
61
+ ( item : SuggestionItem ) =>
62
+ // @ts -expect-error tmp
67
63
values . findIndex ( ( value ) =>
68
64
value . id ? value . id === ( item as SuggestionUser ) . id : value . name === item . name ,
69
65
) ,
70
66
[ values ] ,
71
67
) ;
72
68
73
- const modifyText = ( value : SuggestionListProps < V > [ 'values' ] [ number ] ) => {
69
+ const modifyText = ( value : SuggestionListProps [ 'values' ] [ number ] ) => {
74
70
if ( ! value ) return ;
75
- // @ts -expect-error tmp
76
71
onSelect ( getTextToReplace ( value ) ) ;
77
- // @ts -expect-error tmp
78
72
if ( getSelectedItem ) getSelectedItem ( value ) ;
79
73
} ;
80
74
81
75
const handleClick = useCallback (
82
- ( e : React . MouseEvent < Element , MouseEvent > , item : SuggestionItem < V > ) => {
76
+ ( e : React . MouseEvent < Element , MouseEvent > , item : SuggestionItem ) => {
83
77
e ?. preventDefault ( ) ;
84
78
85
79
const index = findItemIndex ( item ) ;
@@ -90,7 +84,7 @@ export const List = <
90
84
) ;
91
85
92
86
const selectItem = useCallback (
93
- ( item : SuggestionItem < V > ) => {
87
+ ( item : SuggestionItem ) => {
94
88
const index = findItemIndex ( item ) ;
95
89
setSelectedItemIndex ( index ) ;
96
90
} ,
@@ -135,12 +129,11 @@ export const List = <
135
129
} , [ handleKeyDown ] ) ;
136
130
137
131
useEffect ( ( ) => {
138
- // @ts -expect-error tmp
139
132
if ( values ?. length ) selectItem ( values [ 0 ] ) ;
140
133
} , [ selectItem , values ] ) ;
141
134
142
135
const restructureItem = useCallback (
143
- ( item : SuggestionItem < V > ) => {
136
+ ( item : SuggestionItem ) => {
144
137
const matched = item . name || ( item as SuggestionUser ) . id ;
145
138
146
139
const textBeforeCursor = ( propValue || '' ) . slice ( 0 , selectionEnd ) ;
@@ -157,19 +150,20 @@ export const List = <
157
150
) ;
158
151
159
152
const restructuredValues = useMemo (
160
- // @ts -expect-error tmp
161
153
( ) => values . map ( restructureItem ) ,
162
154
[ values , restructureItem ] ,
163
155
) ;
164
156
165
157
return (
166
158
< ul className = { clsx ( 'str-chat__suggestion-list' , className ) } style = { style } >
159
+ { /* @ts -expect-error tmp */ }
167
160
{ restructuredValues . map ( ( item , i ) => (
168
161
< SuggestionItem
169
162
className = { itemClassName }
170
163
// @ts -expect-error tmp
171
164
component = { component }
172
165
item = { item }
166
+ // @ts -expect-error tmp
173
167
key = { getId ( item ) . toString ( ) }
174
168
onClickHandler = { handleClick }
175
169
onSelectHandler = { selectItem }
0 commit comments