@findlane/browser 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { useAutocomplete, type AutocompleteItem, type AutocompleteOptions, type
|
|
|
4
4
|
export { useRecommendations, type UseRecommendationsOptions, type UseRecommendationsResult } from "./use-recommendations.js";
|
|
5
5
|
export { Recommendations, type RecommendationsProps } from "./recommendations.js";
|
|
6
6
|
export { ProductView, useProductView } from "./product-view.js";
|
|
7
|
-
export { SearchProvider, useCurrentRefinements, useDidYouMean, useGeoSearch, useHits, useLoadMore, usePagination, useRange, useRefinementList, useSearchBox, useSearchState, useSortBy, useToggle, type Range, type Refinement, type SearchProviderProps, } from "./search-provider.js";
|
|
7
|
+
export { SearchProvider, useCurrentRefinements, useDidYouMean, useGeoSearch, useHits, useLoadMore, usePagination, useRange, useRefinementList, useSearchBox, useSearchState, useSortBy, useSubindex, useToggle, type Range, type Refinement, type SearchProviderProps, } from "./search-provider.js";
|
|
8
8
|
export { CurrentRefinements, DefaultBanner, DefaultHit, DidYouMean, Hits, LoadMore, RefinementList, SearchBox, SearchInput, SortSelect, Stats, type HitsProps, type RefinementListProps, type SearchBoxProps, type SuggestionLabels, } from "./components.js";
|
|
9
9
|
export { SearchDialog, type SearchDialogProps } from "./dialog.js";
|
|
10
10
|
export { Highlight, Snippet, excerpt, highlightParts, type HighlightProps } from "./highlight.js";
|
package/dist/react/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { useAutocomplete } from "./use-autocomplete.js";
|
|
|
6
6
|
export { useRecommendations } from "./use-recommendations.js";
|
|
7
7
|
export { Recommendations } from "./recommendations.js";
|
|
8
8
|
export { ProductView, useProductView } from "./product-view.js";
|
|
9
|
-
export { SearchProvider, useCurrentRefinements, useDidYouMean, useGeoSearch, useHits, useLoadMore, usePagination, useRange, useRefinementList, useSearchBox, useSearchState, useSortBy, useToggle, } from "./search-provider.js";
|
|
9
|
+
export { SearchProvider, useCurrentRefinements, useDidYouMean, useGeoSearch, useHits, useLoadMore, usePagination, useRange, useRefinementList, useSearchBox, useSearchState, useSortBy, useSubindex, useToggle, } from "./search-provider.js";
|
|
10
10
|
export { CurrentRefinements, DefaultBanner, DefaultHit, DidYouMean, Hits, LoadMore, RefinementList, SearchBox, SearchInput, SortSelect, Stats, } from "./components.js";
|
|
11
11
|
export { SearchDialog } from "./dialog.js";
|
|
12
12
|
export { Highlight, Snippet, excerpt, highlightParts } from "./highlight.js";
|
|
@@ -2,7 +2,7 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
import type { DidYouMean, GeoBox } from "../index.js";
|
|
3
3
|
import { type ClientOptions } from "./client.js";
|
|
4
4
|
import { type ServerResults, type StateChange } from "./store.js";
|
|
5
|
-
import { type Near, type SearchConfig, type SearchState } from "./state.js";
|
|
5
|
+
import { type Hit, type Near, type SearchConfig, type SearchState } from "./state.js";
|
|
6
6
|
export type SearchProviderProps<T> = SearchConfig & ClientOptions & {
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
/** Keeps the state in the page's URL (`?q=shoe&brand=Acme`), so results can be shared and Back
|
|
@@ -32,8 +32,11 @@ export declare function useSearchBox(): {
|
|
|
32
32
|
/** Opens the connection to the API ahead of the first search: call it when the box gets focus. */
|
|
33
33
|
warm: () => void;
|
|
34
34
|
};
|
|
35
|
+
/** A subindex's results for the current query (SearchProvider's `subindexes`), such as categories to suggest
|
|
36
|
+
* above the results; none without a query, or when its search failed (0.23.0). */
|
|
37
|
+
export declare function useSubindex<T = Record<string, unknown>>(name: string): Hit<T>[];
|
|
35
38
|
export declare function useHits<T = Record<string, unknown>>(): {
|
|
36
|
-
hits:
|
|
39
|
+
hits: Hit<T>[];
|
|
37
40
|
total: number;
|
|
38
41
|
/** With the index's related results on, when nothing matched: the products closest in meaning. */
|
|
39
42
|
related: import("../index.js").SearchHit<T>[];
|
|
@@ -77,6 +77,13 @@ export function useSearchBox() {
|
|
|
77
77
|
/** Opens the connection to the API ahead of the first search: call it when the box gets focus. */
|
|
78
78
|
warm: () => store.warm() };
|
|
79
79
|
}
|
|
80
|
+
/** A subindex's results for the current query (SearchProvider's `subindexes`), such as categories to suggest
|
|
81
|
+
* above the results; none without a query, or when its search failed (0.23.0). */
|
|
82
|
+
export function useSubindex(name) {
|
|
83
|
+
const [{ results }] = useSnapshot();
|
|
84
|
+
const answer = results?.response.subindexes?.[name];
|
|
85
|
+
return answer && "hits" in answer ? answer.hits : [];
|
|
86
|
+
}
|
|
80
87
|
export function useHits() {
|
|
81
88
|
const [{ results, pending, error }, store] = useSnapshot();
|
|
82
89
|
return {
|
package/dist/react/state.d.ts
CHANGED
|
@@ -41,6 +41,9 @@ export type SearchConfig = {
|
|
|
41
41
|
facetMode?: "page" | "exact";
|
|
42
42
|
/** Contexts the page sends, which the index's rules may fire on, such as "category-page" (0.19.0). */
|
|
43
43
|
context?: string | string[];
|
|
44
|
+
/** The index's subindexes to search with each query, such as categories to suggest above the results, by
|
|
45
|
+
* name (0.23.0): in the same request, counted as one search. Read them with useSubindex. */
|
|
46
|
+
subindexes?: SearchRequest["subindexes"];
|
|
44
47
|
};
|
|
45
48
|
export declare const emptyState: SearchState;
|
|
46
49
|
/** The API's largest offset. */
|
package/dist/react/state.js
CHANGED
|
@@ -28,6 +28,8 @@ export function planSearch(config, state) {
|
|
|
28
28
|
countMode: config.countMode ?? "exact",
|
|
29
29
|
...(facets.length ? { facetMode: config.facetMode ?? "exact" } : {}),
|
|
30
30
|
...(config.context?.length ? { context: config.context } : {}),
|
|
31
|
+
// Subindexes only for a query: a page without words has nothing to suggest.
|
|
32
|
+
...(config.subindexes && state.q.trim() ? { subindexes: config.subindexes } : {}),
|
|
31
33
|
highlight: true,
|
|
32
34
|
};
|
|
33
35
|
}
|
package/dist/react/store.js
CHANGED
|
@@ -164,7 +164,7 @@ export class SearchStore {
|
|
|
164
164
|
const { results, loadingMore, pending } = this.snapshot;
|
|
165
165
|
if (!results?.hasMore || loadingMore || pending)
|
|
166
166
|
return;
|
|
167
|
-
const { facets: _, disjunctiveFacets: __, facetMode: ___, facetStats: ____, ...request } = results.request;
|
|
167
|
+
const { facets: _, disjunctiveFacets: __, facetMode: ___, facetStats: ____, subindexes: _____, ...request } = results.request;
|
|
168
168
|
const offset = (request.offset ?? 0) + results.hits.length;
|
|
169
169
|
const run = this.run;
|
|
170
170
|
this.set({ loadingMore: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@findlane/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Findlane browser SDK: fast, typo-tolerant public search from the browser with an index's public ID, plus React hooks and components.",
|
|
5
5
|
"keywords": ["findlane", "search", "full-text search", "typo tolerance", "instant search", "ecommerce search", "browser", "react", "autocomplete"],
|
|
6
6
|
"license": "MIT",
|