1
+ /* eslint camelcase: ["off"] */
2
+
1
3
import { SearchResponse , SearchParams , Hits , Config } from 'meilisearch'
2
4
3
- interface Options {
5
+ interface HitResponse {
6
+ anchor : string
7
+ content : string
8
+ hierarchy_lvl0 : string | null
9
+ hierarchy_lvl1 : string | null
10
+ hierarchy_lvl2 : string | null
11
+ hierarchy_lvl3 : string | null
12
+ hierarchy_lvl4 : string | null
13
+ hierarchy_lvl5 : string | null
14
+ hierarchy_lvl6 : string | null
15
+ objectID : string
16
+ url : string
17
+ [ key : string ] : unknown
18
+ }
19
+
20
+ interface DefaultFormattedHit {
21
+ isLvl0 : boolean
22
+ isLvl1 : boolean
23
+ isLbl2 : boolean
24
+ isLvl1EmptyOrDuplicate : boolean
25
+ isCategoryHeader : boolean
26
+ isSubCategoryHeader : boolean
27
+ isTextOrSubcategoryNonEmpty : boolean
28
+ subcategory : string | null
29
+ text : string | null
30
+ title : string | null
31
+ url : string | null
32
+ }
33
+
34
+ interface AutoCompleteInput {
35
+ open : ( ) => void
36
+ close : ( ) => void
37
+ destroy : ( ) => void
38
+ getWrapper : ( ) => Element
39
+ getVal : ( ) => string
40
+ setVal : ( val : string ) => void
41
+ }
42
+
43
+ interface Options < FormattedHit = DefaultFormattedHit > {
4
44
hostUrl : string
5
45
apiKey : string
6
46
indexUid : string
@@ -17,23 +57,35 @@ interface Options {
17
57
}
18
58
keyboardShortcuts ?: ( string | number ) [ ]
19
59
}
20
- transformData ?: ( hits : Hits ) => Hits
21
- queryHook ?: ( query : unknown ) => unknown
22
- handleSelected ?: ( input , event , suggestion , datasetNumber , context ) => void
60
+ transformData ?: ( hits : Hits < HitResponse > ) => Hits < FormattedHit >
61
+ queryHook ?: ( query : string ) => string
62
+ handleSelected ?: (
63
+ input : AutoCompleteInput ,
64
+ event : Event ,
65
+ suggestion : FormattedHit ,
66
+ datasetNumber : number ,
67
+ context : {
68
+ selectionMethod : 'click' | 'blur' | 'enterKey' | 'tabKey' | string
69
+ } ,
70
+ ) => void
23
71
enhancedSearchInput ?: boolean
24
72
layout ?: 'column' | 'simple'
25
73
enableDarkMode ?: boolean | 'auto'
26
74
clientAgents ?: Config [ 'clientAgents' ]
27
75
}
28
76
29
- declare class DocsSearchBar {
30
- constructor ( options : Options )
77
+ declare class DocsSearchBar < FormattedHit > {
78
+ constructor ( options : Options < FormattedHit > )
31
79
}
32
80
33
81
declare global {
34
82
interface Window {
35
- docsSearchBar : ( options : Options ) => void
83
+ docsSearchBar : < FormattedHit = DefaultFormattedHit > (
84
+ options : Options < FormattedHit > ,
85
+ ) => void
36
86
}
37
87
}
38
88
39
- export default function docsSearchBar ( options : Options ) : DocsSearchBar
89
+ export default function docsSearchBar < FormattedHit = DefaultFormattedHit > (
90
+ options : Options < FormattedHit > ,
91
+ ) : DocsSearchBar < FormattedHit >
0 commit comments