diff --git a/examples/recently-viewed-items/recentlyViewedItemsPlugin.tsx b/examples/recently-viewed-items/recentlyViewedItemsPlugin.tsx index 26272643c..1ad84cf49 100644 --- a/examples/recently-viewed-items/recentlyViewedItemsPlugin.tsx +++ b/examples/recently-viewed-items/recentlyViewedItemsPlugin.tsx @@ -48,9 +48,9 @@ export function createLocalStorageRecentlyViewedItems< return search(params); }, - transformSource({ source, onRemove }) { + transformSource({ source, onRemove, state }) { const transformedSource = params.transformSource - ? params.transformSource({ source, onRemove }) + ? params.transformSource({ source, onRemove, state }) : source; return { diff --git a/packages/autocomplete-plugin-query-suggestions/src/createQuerySuggestionsPlugin.ts b/packages/autocomplete-plugin-query-suggestions/src/createQuerySuggestionsPlugin.ts index c1ecfd82e..e4757b292 100644 --- a/packages/autocomplete-plugin-query-suggestions/src/createQuerySuggestionsPlugin.ts +++ b/packages/autocomplete-plugin-query-suggestions/src/createQuerySuggestionsPlugin.ts @@ -18,6 +18,7 @@ export type CreateQuerySuggestionsPluginParams< getSearchParams?(params: { state: AutocompleteState }): SearchOptions; transformSource?(params: { source: AutocompleteSource; + state: AutocompleteState; onTapAhead(item: TItem): void; }): AutocompleteSource; /** @@ -115,6 +116,7 @@ export function createQuerySuggestionsPlugin< templates: getTemplates({ onTapAhead }), }, onTapAhead, + state, }), ]; }, diff --git a/packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts b/packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts index 360da4b56..e056c566d 100644 --- a/packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts +++ b/packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts @@ -1,5 +1,6 @@ import { AutocompletePlugin, + AutocompleteState, PluginSubscribeParams, } from '@algolia/autocomplete-core'; import { AutocompleteSource } from '@algolia/autocomplete-js'; @@ -21,6 +22,7 @@ export type CreateRecentSearchesPluginParams< storage: Storage; transformSource?(params: { source: AutocompleteSource; + state: AutocompleteState; onRemove(id: string): void; onTapAhead(item: TItem): void; }): AutocompleteSource; @@ -70,7 +72,7 @@ export function createRecentSearchesPlugin({ store.addItem(recentItem as TItem); } }, - getSources({ query, setQuery, refresh }) { + getSources({ query, setQuery, refresh, state }) { lastItemsRef.current = store.getAll(query); function onRemove(id: string) { @@ -102,6 +104,7 @@ export function createRecentSearchesPlugin({ }, onRemove, onTapAhead, + state, }), ]; }); diff --git a/packages/website/docs/createLocalStorageRecentSearchesPlugin.md b/packages/website/docs/createLocalStorageRecentSearchesPlugin.md index 0170b869e..5f02239c6 100644 --- a/packages/website/docs/createLocalStorageRecentSearchesPlugin.md +++ b/packages/website/docs/createLocalStorageRecentSearchesPlugin.md @@ -140,7 +140,7 @@ function search({ query, items, limit }) { ### `transformSource` -> `(params: { source: AutocompleteSource, onRemove: () => void, onTapAhead: () => void })` +> `(params: { source: AutocompleteSource, state: AutocompleteState, onRemove: () => void, onTapAhead: () => void })` A function to transform the provided source. diff --git a/packages/website/docs/createQuerySuggestionsPlugin.md b/packages/website/docs/createQuerySuggestionsPlugin.md index 5541b7ebe..172798104 100644 --- a/packages/website/docs/createQuerySuggestionsPlugin.md +++ b/packages/website/docs/createQuerySuggestionsPlugin.md @@ -104,7 +104,7 @@ A function returning [Algolia search parameters](https://www.algolia.com/doc/api ### `transformSource` -> `(params: { source: AutocompleteSource, onTapAhead: () => void })` +> `(params: { source: AutocompleteSource, state: AutocompleteState, onTapAhead: () => void })` A function to transform the provided source. diff --git a/packages/website/docs/createRecentSearchesPlugin.md b/packages/website/docs/createRecentSearchesPlugin.md index 5f2884c6e..baad22d2b 100644 --- a/packages/website/docs/createRecentSearchesPlugin.md +++ b/packages/website/docs/createRecentSearchesPlugin.md @@ -145,7 +145,7 @@ type RecentSearchesStorage = { ### `transformSource` -> `(params: { source: AutocompleteSource, onRemove: () => void, onTapAhead: () => void })` +> `(params: { source: AutocompleteSource, state: AutocompleteState, onRemove: () => void, onTapAhead: () => void })` A function to transform the provided source.