-
Notifications
You must be signed in to change notification settings - Fork 498
/
widget.ts
116 lines (109 loc) · 2.43 KB
/
widget.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
import {
Helper,
SearchResults,
InstantSearch,
SearchParameters,
} from './instantsearch';
interface InitOptions {
instantSearchInstance: InstantSearch;
state: SearchParameters;
helper: Helper;
templatesConfig: object;
createURL(state: SearchParameters): string;
}
interface RenderOptions {
instantSearchInstance: InstantSearch;
templatesConfig: object;
results: SearchResults;
state: SearchParameters;
helper: Helper;
searchMetadata: {
isSearchStalled: boolean;
};
createURL(state: SearchParameters): string;
}
interface DisposeOptions {
helper: Helper;
state: SearchParameters;
}
export type UiState = {
query?: string;
refinementList?: {
[attribute: string]: string[];
};
menu?: {
[attribute: string]: string;
};
/**
* The list of hierarchical menus.
* Nested levels must contain the record separator.
*
* @example ['Audio', 'Audio > Headphones']
*/
hierarchicalMenu?: {
[attribute: string]: string[];
};
/**
* The numeric menu as a tuple.
*
* @example ':5'
* @example '5:10'
* @example '10:'
*/
numericMenu?: {
[attribute: string]: string;
};
ratingMenu?: {
[attribute: string]: number;
};
/**
* The range as a tuple.
*
* @example '100:500'
*/
range?: {
[attribute: string]: string;
};
toggle?: {
[attribute: string]: boolean;
};
geoSearch?: {
/**
* The rectangular area in geo coordinates.
* The rectangle is defined by two diagonally opposite points, hence by 4 floats separated by commas.
*
* @example '47.3165,4.9665,47.3424,5.0201'
*/
boundingBox: string;
};
sortBy?: string;
page?: number;
hitsPerPage?: number;
};
export interface Widget {
init?(options: InitOptions): void;
render?(options: RenderOptions): void;
dispose?(options: DisposeOptions): SearchParameters | void;
getConfiguration?(
previousConfiguration?: Partial<SearchParameters>
): Partial<SearchParameters>;
getWidgetState?(
uiState: UiState,
widgetStateOptions: {
searchParameters: SearchParameters;
helper: Helper;
}
): UiState;
getWidgetSearchParameters?(
state: SearchParameters,
widgetSearchParametersOptions: {
uiState: UiState;
}
): SearchParameters;
}
export type WidgetFactory<TWidgetParams> = (
widgetParams: TWidgetParams
) => Widget;
export type Template<TTemplateData = void> =
| string
| ((data: TTemplateData) => string);