This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathtypings.d.ts
179 lines (158 loc) · 4.13 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
type Type = 'country' | 'city' | 'busStop' | 'townhall' | 'trainStation' | 'airport' | 'address'
/** @see src/formatHit.js:94 */
type Highlight = {
administrative?: string,
city?: string,
country?: string,
county?: string,
name?: string,
postcode?: string,
suburb?: string,
}
/** @see src/formatHit.js:132
* Initial undefined parameters can be missing in some situations,
* because of Autocomplete.js, which remove undefined values.
*/
type Suggestion = {
administrative?: string,
city?: string,
country: string,
countryCode?: string,
county?: string,
highlight: Highlight,
hit: Hit,
hitIndex: number,
latlng: Geoloc,
name: string,
postcode?: string,
postcodes?: string[],
query: string,
rawAnswer: RawAnswer,
suburb?: string,
type: Type,
value: string,
}
type Geoloc = {
lat: number,
lng: number,
}
type HighlightMatch = {
value: string,
matchLevel: string,
matchedWords: string[],
}
type HighlightResults = {
country: HighlightMatch,
city: HighlightMatch[],
postcode: HighlightMatch[],
county: HighlightMatch[],
administrative: HighlightMatch[],
locale_names: (HighlightMatch & { fullyHighlighted: boolean })[],
}
type Hit = {
_geoloc: Geoloc,
_highlightResult: HighlightResults,
_tags: string[],
admin_level: number,
administrative: string[],
city: string[],
country: string,
country_code: string,
county: string[],
importance: number,
is_city: boolean,
is_country: boolean,
is_highway: boolean,
is_popular: boolean,
is_suburb: boolean,
locale_names: string[],
objectID: string,
population: number,
postcode: string[],
}
type RawAnswer = {
hits: Hit[],
nbHits: number,
processingTimeMS: number,
query: string,
params: string,
degradedQuery: boolean,
}
type SuggestionsEvent = {
query: string,
rawAnswer: RawAnswer,
suggestions: Suggestion[],
}
type ChangeEvent = {
query: string,
rawAnswer: RawAnswer,
suggestion: Suggestion,
suggestionIndex: number,
}
type CursorChangedEvent = {
query: string,
rawAnswer: RawAnswer,
suggestion: Suggestion,
suggestionIndex: number,
}
type PlacesEventsHandlers = {
change: (changeEvent: ChangeEvent) => void,
suggestions: (suggestionsEvent: SuggestionsEvent) => void,
cursorchanged: (cursorChangedEvent: CursorChangedEvent) => void,
limit: (e: { message: string }) => void,
error: (e: { message: string }) => void,
clear: () => void,
}
/** @see https://community.algolia.com/places/documentation.html#static-options */
type StaticOptions = {
container: HTMLInputElement | string,
appId?: string,
apiKey?: string,
templates?: { value: (suggestion: Suggestion) => string, suggestion: (suggestion: Suggestion) => string },
style?: boolean,
clientOptions?: object,
autocompleteOptions?: object,
}
/** @see https://community.algolia.com/places/documentation.html#reconfigurable-options */
type ReconfigurableOptions = {
type?: Type,
language?: string,
countries?: string[],
aroundLatLng?: string,
aroundLatLngViaIP?: boolean,
aroundRadius?: number,
insideBoundingBox?: string,
insidePolygon?: string,
getRankingInfo?: boolean,
useDeviceLocation?: boolean,
computeQueryParams?: object,
hitsPerPage?: number,
}
type SearchClientOptions = ReconfigurableOptions & {
query: string,
}
type ReverseClientOptions = {
aroundLatLng: string,
hitsPerPage: number,
language: string,
}
type ClientReturn = {
hits: Hit[],
nbHits: number,
processingTimeMs: number,
params: string,
}
/** @see https://community.algolia.com/places/documentation.html#methods */
type PlacesInstance = {
on: <T extends keyof PlacesEventsHandlers>(eventName: T, callback: PlacesEventsHandlers[T]) => void,
removeAllListeners: (eventName: keyof PlacesEventsHandlers) => void,
configure: (configuration: ReconfigurableOptions) => PlacesInstance,
reverse: (options: ReverseClientOptions) => Promise<ClientReturn>,
search: (options: SearchClientOptions) => Promise<ClientReturn>,
open: () => void,
close: () => void,
getVal: () => string,
setVal: (...args: any) => void, // TODO
destroy: () => void,
}
export default function (options: StaticOptions & ReconfigurableOptions): PlacesInstance