11/** @jsx h */
2- import { AutocompletePlugin } from '@algolia/autocomplete-js' ;
2+ import {
3+ AutocompletePlugin ,
4+ AutocompleteSource ,
5+ AutocompleteState ,
6+ } from '@algolia/autocomplete-js' ;
37import {
48 createLocalStorageRecentSearchesPlugin ,
59 search ,
10+ SearchParams ,
611} from '@algolia/autocomplete-plugin-recent-searches' ;
12+ import { MaybePromise } from '@algolia/autocomplete-shared' ;
713import { h , Fragment } from 'preact' ;
814
9- type RecentlyViewedItem = {
15+ import { Highlighted } from './types' ;
16+
17+ type RecentlyViewedRecord = {
1018 id : string ;
1119 label : string ;
20+ url : string ;
1221 image : string ;
13- _highlightResult : {
14- label : {
15- value : string ;
16- } ;
17- } ;
1822} ;
1923
20- type CreateLocalStorageRecentlyViewedItemsParams < TItem > = {
24+ type CreateLocalStorageRecentlyViewedItemsParams <
25+ TItem extends RecentlyViewedRecord
26+ > = {
2127 key : string ;
2228 limit ?: number ;
23- search ?( params : any ) : any [ ] ;
29+ search ?( params : SearchParams < TItem > ) : Array < Highlighted < TItem > > ;
30+ transformSource ?( params : {
31+ source : AutocompleteSource < TItem > ;
32+ state : AutocompleteState < TItem > ;
33+ onRemove ( id : string ) : void ;
34+ } ) : AutocompleteSource < TItem > ;
2435} ;
2536
26- type RecentlyViewedItemsPluginData < TItem > = {
37+ type RecentlyViewedItemsPluginData < TItem extends RecentlyViewedRecord > = {
2738 addItem ( item : TItem ) : void ;
2839 removeItem ( id : string ) : void ;
29- getAll ( query ?: string ) : any [ ] ;
40+ getAll ( query ?: string ) : MaybePromise < Array < Highlighted < TItem > > > ;
3041} ;
3142
3243export function createLocalStorageRecentlyViewedItems <
33- TItem extends RecentlyViewedItem
44+ TItem extends RecentlyViewedRecord
3445> (
3546 params : CreateLocalStorageRecentlyViewedItemsParams < TItem >
3647) : AutocompletePlugin < TItem , RecentlyViewedItemsPluginData < TItem > > {
@@ -39,7 +50,7 @@ export function createLocalStorageRecentlyViewedItems<
3950 onSubmit,
4051 subscribe,
4152 ...plugin
42- } = createLocalStorageRecentSearchesPlugin ( {
53+ } = createLocalStorageRecentSearchesPlugin < TItem > ( {
4354 ...params ,
4455 search ( params ) {
4556 if ( params . query ) {
0 commit comments