Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
686: Add index.d.ts file for typescript compatible r=bidoubiwa a=hirohe # Pull Request ## Related issue Fixes #479 ## What does this PR do? - add `index.d.ts` types declare file - add dependencies related to typescript and eslint config - update .eslintrc.js file, with typescript related configs - replace `no-unused-vars` with ``@typescript-eslint/no-unused-vars`` [refer](https://typescript-eslint.io/rules/no-unused-vars/) there's some definitions unclear in `index.d.ts` - ~`queryHook` dont know the arguments definitons~ - ~`handleSelected` dont know the arguments definitons~ - all methods of class DocsSearchBar should be defined ? ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: hirohe <hesreg@hotmail.com> Co-authored-by: hirohe <hirohe@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
283 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* eslint camelcase: ["off"] */ | ||
|
||
import { SearchResponse, SearchParams, Hits, Config } from 'meilisearch' | ||
|
||
interface HitResponse { | ||
anchor: string | ||
content: string | ||
hierarchy_lvl0: string | null | ||
hierarchy_lvl1: string | null | ||
hierarchy_lvl2: string | null | ||
hierarchy_lvl3: string | null | ||
hierarchy_lvl4: string | null | ||
hierarchy_lvl5: string | null | ||
hierarchy_lvl6: string | null | ||
objectID: string | ||
url: string | ||
[key: string]: unknown | ||
} | ||
|
||
interface DefaultFormattedHit { | ||
isLvl0: boolean | ||
isLvl1: boolean | ||
isLbl2: boolean | ||
isLvl1EmptyOrDuplicate: boolean | ||
isCategoryHeader: boolean | ||
isSubCategoryHeader: boolean | ||
isTextOrSubcategoryNonEmpty: boolean | ||
subcategory: string | null | ||
text: string | null | ||
title: string | null | ||
url: string | null | ||
} | ||
|
||
interface AutoCompleteInput { | ||
open: () => void | ||
close: () => void | ||
destroy: () => void | ||
getWrapper: () => Element | ||
getVal: () => string | ||
setVal: (val: string) => void | ||
} | ||
|
||
interface Options<FormattedHit = DefaultFormattedHit> { | ||
hostUrl: string | ||
apiKey: string | ||
indexUid: string | ||
inputSelector?: string | ||
inputElement?: Element | ||
debug?: boolean | ||
meilisearchOptions?: SearchParams | ||
queryDataCallback?: (data?: SearchResponse) => void | ||
autocompleteOptions?: { | ||
ariaLabel?: string | ||
cssClasses?: { | ||
prefix?: string | ||
root?: string | ||
} | ||
keyboardShortcuts?: (string | number)[] | ||
} | ||
transformData?: (hits: Hits<HitResponse>) => Hits<FormattedHit> | ||
queryHook?: (query: string) => string | ||
handleSelected?: ( | ||
input: AutoCompleteInput, | ||
event: Event, | ||
suggestion: FormattedHit, | ||
datasetNumber: number, | ||
context: { | ||
selectionMethod: 'click' | 'blur' | 'enterKey' | 'tabKey' | string | ||
}, | ||
) => void | ||
enhancedSearchInput?: boolean | ||
layout?: 'column' | 'simple' | ||
enableDarkMode?: boolean | 'auto' | ||
clientAgents?: Config['clientAgents'] | ||
} | ||
|
||
declare class DocsSearchBar<FormattedHit> { | ||
constructor(options: Options<FormattedHit>) | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
docsSearchBar: <FormattedHit = DefaultFormattedHit>( | ||
options: Options<FormattedHit>, | ||
) => void | ||
} | ||
} | ||
|
||
export default function docsSearchBar<FormattedHit = DefaultFormattedHit>( | ||
options: Options<FormattedHit>, | ||
): DocsSearchBar<FormattedHit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.