Skip to content

Commit 38ba3f8

Browse files
committed
feat: more definitions
1 parent 9e25280 commit 38ba3f8

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

index.d.ts

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
1+
/* eslint camelcase: ["off"] */
2+
13
import { SearchResponse, SearchParams, Hits, Config } from 'meilisearch'
24

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> {
444
hostUrl: string
545
apiKey: string
646
indexUid: string
@@ -17,23 +57,35 @@ interface Options {
1757
}
1858
keyboardShortcuts?: (string | number)[]
1959
}
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
2371
enhancedSearchInput?: boolean
2472
layout?: 'column' | 'simple'
2573
enableDarkMode?: boolean | 'auto'
2674
clientAgents?: Config['clientAgents']
2775
}
2876

29-
declare class DocsSearchBar {
30-
constructor(options: Options)
77+
declare class DocsSearchBar<FormattedHit> {
78+
constructor(options: Options<FormattedHit>)
3179
}
3280

3381
declare global {
3482
interface Window {
35-
docsSearchBar: (options: Options) => void
83+
docsSearchBar: <FormattedHit = DefaultFormattedHit>(
84+
options: Options<FormattedHit>,
85+
) => void
3686
}
3787
}
3888

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

Comments
 (0)