@nosto/search-js 1.4.0 → 1.5.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.
Files changed (69) hide show
  1. package/README.md +3 -39
  2. package/dist/core/core.d.ts +2 -2
  3. package/dist/core/src/applyDecorators.d.ts +9 -9
  4. package/dist/core/src/search.d.ts +9 -9
  5. package/dist/core/src/searchWithRetries.d.ts +2 -2
  6. package/dist/core/src/types.d.ts +5 -6
  7. package/dist/currencies/currencies.d.ts +2 -2
  8. package/dist/currencies/src/getCurrencyFormatting.d.ts +2 -3
  9. package/dist/currencies/src/priceDecorator.d.ts +2 -2
  10. package/dist/preact/preact.cjs.js +1 -1
  11. package/dist/preact/preact.d.ts +24 -5
  12. package/dist/preact/preact.es.js +741 -100
  13. package/dist/preact/src/actions/newSearch.d.ts +4 -0
  14. package/dist/preact/src/actions/replaceFilter.d.ts +3 -0
  15. package/dist/preact/src/actions/toggleProductFilter.d.ts +2 -0
  16. package/dist/preact/src/actions/types.d.ts +6 -0
  17. package/dist/preact/src/actions/updateSearch.d.ts +4 -0
  18. package/dist/preact/src/api/types.d.ts +4 -0
  19. package/dist/preact/src/components/SearchInput.d.ts +7 -0
  20. package/dist/preact/src/components/SerpElement.d.ts +18 -0
  21. package/dist/preact/src/config/base/baseConfig.d.ts +41 -0
  22. package/dist/preact/src/config/config.d.ts +4 -0
  23. package/dist/preact/src/config/configContext.d.ts +6 -0
  24. package/dist/preact/src/config/pages/autocomplete/config.d.ts +15 -0
  25. package/dist/preact/src/config/pages/autocomplete/provider.d.ts +10 -0
  26. package/dist/preact/src/config/pages/category/config.d.ts +44 -0
  27. package/dist/preact/src/config/pages/category/provider.d.ts +10 -0
  28. package/dist/preact/src/config/pages/serp/config.d.ts +34 -0
  29. package/dist/preact/src/config/pages/serp/provider.d.ts +10 -0
  30. package/dist/preact/src/dom/renderHeadless.d.ts +18 -0
  31. package/dist/preact/src/dom/utils.d.ts +5 -0
  32. package/dist/preact/src/hooks/useActions.d.ts +32 -0
  33. package/dist/preact/src/hooks/useCheckClientScript.d.ts +1 -0
  34. package/dist/preact/src/hooks/useDecoratedSearchResults.d.ts +27 -0
  35. package/dist/preact/src/hooks/useFacet.d.ts +60 -0
  36. package/dist/preact/src/hooks/useFacets.d.ts +39 -0
  37. package/dist/preact/src/hooks/useNostoAppState.d.ts +3 -2
  38. package/dist/preact/src/hooks/usePersonalization.d.ts +1 -1
  39. package/dist/preact/src/hooks/useProductFilters/useProductFilters.d.ts +59 -0
  40. package/dist/preact/src/hooks/useProductFilters/useProductFiltersUtils.d.ts +48 -0
  41. package/dist/preact/src/hooks/useRange.d.ts +34 -0
  42. package/dist/preact/src/hooks/useRangeSelector.d.ts +98 -0
  43. package/dist/preact/src/hooks/useResponse.d.ts +82 -0
  44. package/dist/preact/src/hooks/useSelectedFiltersCount.d.ts +17 -0
  45. package/dist/preact/src/hooks/useSizeOptions.d.ts +50 -0
  46. package/dist/preact/src/hooks/useSort/useSort.d.ts +47 -0
  47. package/dist/preact/src/hooks/useSort/utils.d.ts +9 -0
  48. package/dist/preact/src/search/defaults.d.ts +45 -0
  49. package/dist/preact/src/search/resultCaching.d.ts +4 -0
  50. package/dist/preact/src/store.d.ts +9 -1387
  51. package/dist/preact/src/storeContext.d.ts +5 -1389
  52. package/dist/preact/src/storeExtensions.d.ts +17 -0
  53. package/dist/thumbnails/src/generateThumbnailUrl.d.ts +1 -1
  54. package/dist/thumbnails/src/nostoThumbnailDecorator.d.ts +2 -2
  55. package/dist/thumbnails/src/shopifyThumbnailDecorator.d.ts +2 -2
  56. package/dist/thumbnails/src/thumbnailDecorator.d.ts +2 -2
  57. package/dist/thumbnails/thumbnails.d.ts +5 -5
  58. package/dist/utils/src/deepFreeze.d.ts +1 -1
  59. package/dist/utils/src/deepMerge.d.ts +5 -3
  60. package/dist/utils/src/mergeArrays.d.ts +2 -1
  61. package/dist/utils/src/parseNumber.d.ts +1 -0
  62. package/dist/utils/src/performance.d.ts +1 -0
  63. package/dist/utils/src/savePageScroll.d.ts +2 -0
  64. package/dist/utils/src/simplify.d.ts +1 -1
  65. package/dist/utils/src/storage.d.ts +6 -0
  66. package/dist/utils/src/types.d.ts +3 -0
  67. package/dist/utils/src/unique.d.ts +1 -0
  68. package/package.json +22 -15
  69. package/dist/preact/test/mocks/mocks.d.ts +0 -1384
@@ -0,0 +1,4 @@
1
+ import { Options as SearchConfig } from '../../../core/src/types';
2
+ import { SearchQuery } from '@nosto/nosto-js/client';
3
+ import { ActionContext } from './types';
4
+ export declare function newSearch(context: ActionContext, query: SearchQuery, options?: SearchConfig): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { InputSearchRangeFilter } from '@nosto/nosto-js/client';
2
+ import { ActionContext } from './types';
3
+ export declare function replaceFilter(context: ActionContext, field: string, value: InputSearchRangeFilter | string | undefined): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import { ActionContext } from './types';
2
+ export declare function toggleProductFilter(context: ActionContext, field: string, value: string, active: boolean): Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { Config } from '../config/config';
2
+ import { Store } from '../store';
3
+ export type ActionContext = {
4
+ store: Store;
5
+ config: Config;
6
+ };
@@ -0,0 +1,4 @@
1
+ import { Options as SearchConfig } from '../../../core/src/types';
2
+ import { SearchQuery } from '@nosto/nosto-js/client';
3
+ import { ActionContext } from './types';
4
+ export declare function updateSearch(context: ActionContext, query: SearchQuery, options?: SearchConfig): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { SearchQuery } from '@nosto/nosto-js/client';
2
+ export type PageType = "serp" | "category" | "autocomplete";
3
+ export type MaybeProvider<T> = T | (() => T);
4
+ export type QueryProvider = MaybeProvider<Partial<SearchQuery>>;
@@ -0,0 +1,7 @@
1
+ import { ComponentChildren } from 'preact';
2
+ type Props = {
3
+ children: ComponentChildren;
4
+ onSearchInput: (target: HTMLInputElement) => void;
5
+ };
6
+ export declare function SearchInput({ children, onSearchInput }: Props): ComponentChildren;
7
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ComponentChildren } from 'preact';
2
+ /**
3
+ * @group Components
4
+ */
5
+ export type SerpElementProps = {
6
+ children: ComponentChildren;
7
+ hit: {
8
+ productId: string;
9
+ url?: string;
10
+ };
11
+ onClick?: (event: Event) => void;
12
+ };
13
+ /**
14
+ * Wrapper component that can be used to wrap any element in the search result list.
15
+ *
16
+ * @group Components
17
+ */
18
+ export declare function SerpElement({ children, hit, onClick }: SerpElementProps): ComponentChildren;
@@ -0,0 +1,41 @@
1
+ import { Options as SearchConfig } from '../../../../core/src/types';
2
+ import { SearchQuery } from '@nosto/nosto-js/client';
3
+ import { PageType } from '../../api/types';
4
+ export declare const defaultBaseConfig: {
5
+ defaultCurrency: string;
6
+ queryModifications: (query: SearchQuery) => SearchQuery;
7
+ };
8
+ export interface BaseConfig {
9
+ /**
10
+ * Merchant's default Currency.
11
+ */
12
+ defaultCurrency: string;
13
+ /**
14
+ * Configuration for the search queries
15
+ */
16
+ search?: SearchConfig;
17
+ /**
18
+ * Custom function, when provided, can be used to modify search query before sending it to the server.
19
+ * A default implementation is provided in the config that returns the query without any modification.
20
+ * Note: The query parameter itself should not be touched, but instead a new object should be returned in case modifications are needed.
21
+ * @param query SearchQuery
22
+ * @param pageType PageType | undefined
23
+ * @default queryModifications: query => query
24
+ * @example
25
+ * ```
26
+ * (query, pageType) => {
27
+ * return {
28
+ * ...query,
29
+ * products: {
30
+ * ...query.products,
31
+ * filter: [
32
+ * ...(query.products?.filter ?? []),
33
+ * { field: "availability", value: ["InStock"] }
34
+ * ]
35
+ * }
36
+ * }
37
+ * }
38
+ * ```
39
+ */
40
+ queryModifications: (query: SearchQuery, pageType: PageType | undefined) => SearchQuery;
41
+ }
@@ -0,0 +1,4 @@
1
+ import { AutocompleteConfig } from './pages/autocomplete/config';
2
+ import { CategoryConfig } from './pages/category/config';
3
+ import { SerpConfig } from './pages/serp/config';
4
+ export type Config = SerpConfig | CategoryConfig | AutocompleteConfig;
@@ -0,0 +1,6 @@
1
+ import { Config } from './config';
2
+ export declare const ConfigContext: import('preact').Context<Config | null>;
3
+ export declare const useConfig: () => Config;
4
+ export declare const useSerpConfig: () => import('./pages/serp/config').SerpConfig;
5
+ export declare const useCategoryConfig: () => import('./pages/category/config').CategoryConfig;
6
+ export declare const useAutocompleteConfig: () => import('./pages/autocomplete/config').AutocompleteConfig;
@@ -0,0 +1,15 @@
1
+ import { BaseConfig } from '../../base/baseConfig';
2
+ export declare const defaultAutocompleteConfig: {
3
+ defaultCurrency: string;
4
+ queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery) => import('@nosto/nosto-js/client').SearchQuery;
5
+ };
6
+ export interface AutocompleteConfig extends BaseConfig {
7
+ pageType: "autocomplete";
8
+ }
9
+ export type PublicAutocompleteConfig = Omit<AutocompleteConfig, keyof typeof defaultAutocompleteConfig | "pageType"> & Partial<Pick<AutocompleteConfig, keyof typeof defaultAutocompleteConfig>>;
10
+ export declare function makeAutocompleteConfig(config: PublicAutocompleteConfig): {
11
+ search?: import('../../../../../core/src/types').Options | undefined;
12
+ defaultCurrency: string;
13
+ queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
14
+ pageType: "autocomplete";
15
+ };
@@ -0,0 +1,10 @@
1
+ import { Store } from '../../../store';
2
+ import { ComponentChildren } from 'preact';
3
+ import { PublicAutocompleteConfig } from './config';
4
+ type AutocompleteProps = {
5
+ config: PublicAutocompleteConfig;
6
+ store?: Store;
7
+ children: ComponentChildren;
8
+ };
9
+ export declare function AutocompletePageProvider({ config, store, children }: AutocompleteProps): import("preact").JSX.Element;
10
+ export {};
@@ -0,0 +1,44 @@
1
+ import { BaseConfig } from '../../base/baseConfig';
2
+ export declare const defaultCategoryConfig: {
3
+ persistentSearchCache: false;
4
+ preservePageScroll: false;
5
+ defaultCurrency: string;
6
+ queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery) => import('@nosto/nosto-js/client').SearchQuery;
7
+ };
8
+ export interface CategoryConfig extends BaseConfig {
9
+ pageType: "category";
10
+ /**
11
+ * returns current category id
12
+ */
13
+ categoryId: () => string;
14
+ /**
15
+ * returns current category path
16
+ */
17
+ categoryPath: () => string;
18
+ /**
19
+ * Enable persistent caching for search results.
20
+ *
21
+ * If enabled, the search results will be restored from cache when returning to the search page,
22
+ * for example, from a product page.
23
+ *
24
+ * The cache is stored in the browser's session storage.
25
+ */
26
+ persistentSearchCache: boolean;
27
+ /**
28
+ * Preserve page scroll position when navigating back to search page.
29
+ *
30
+ * If enabled, it's highly recommended to also enabled `persistentSearchCache` for best user experience.
31
+ */
32
+ preservePageScroll: boolean;
33
+ }
34
+ export type PublicCategoryConfig = Omit<CategoryConfig, keyof typeof defaultCategoryConfig | "pageType"> & Partial<Pick<CategoryConfig, keyof typeof defaultCategoryConfig>>;
35
+ export declare function makeCategoryConfig(config: PublicCategoryConfig): {
36
+ search?: import('../../../../../core/src/types').Options | undefined;
37
+ categoryId: () => string;
38
+ categoryPath: () => string;
39
+ defaultCurrency: string;
40
+ queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
41
+ persistentSearchCache: boolean;
42
+ preservePageScroll: boolean;
43
+ pageType: "category";
44
+ };
@@ -0,0 +1,10 @@
1
+ import { Store } from '../../../store';
2
+ import { ComponentChildren } from 'preact';
3
+ import { PublicCategoryConfig } from './config';
4
+ type CategoryProps = {
5
+ config: PublicCategoryConfig;
6
+ store?: Store;
7
+ children: ComponentChildren;
8
+ };
9
+ export declare function CategoryPageProvider({ config, store, children }: CategoryProps): import("preact").JSX.Element;
10
+ export {};
@@ -0,0 +1,34 @@
1
+ import { BaseConfig } from '../../base/baseConfig';
2
+ export declare const defaultSerpConfig: {
3
+ persistentSearchCache: false;
4
+ preservePageScroll: false;
5
+ defaultCurrency: string;
6
+ queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery) => import('@nosto/nosto-js/client').SearchQuery;
7
+ };
8
+ export interface SerpConfig extends BaseConfig {
9
+ pageType: "serp";
10
+ /**
11
+ * Enable persistent caching for search results.
12
+ *
13
+ * If enabled, the search results will be restored from cache when returning to the search page,
14
+ * for example, from a product page.
15
+ *
16
+ * The cache is stored in the browser's session storage.
17
+ */
18
+ persistentSearchCache: boolean;
19
+ /**
20
+ * Preserve page scroll position when navigating back to search page.
21
+ *
22
+ * If enabled, it's highly recommended to also enabled `persistentSearchCache` for best user experience.
23
+ */
24
+ preservePageScroll: boolean;
25
+ }
26
+ export type PublicSerpConfig = Omit<SerpConfig, keyof typeof defaultSerpConfig | "pageType"> & Partial<Pick<SerpConfig, keyof typeof defaultSerpConfig>>;
27
+ export declare function makeSerpConfig(config?: PublicSerpConfig): {
28
+ search?: import('../../../../../core/src/types').Options | undefined;
29
+ defaultCurrency: string;
30
+ queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
31
+ persistentSearchCache: boolean;
32
+ preservePageScroll: boolean;
33
+ pageType: "serp";
34
+ };
@@ -0,0 +1,10 @@
1
+ import { Store } from '../../../store';
2
+ import { ComponentChildren } from 'preact';
3
+ import { PublicSerpConfig } from './config';
4
+ type SearchProps = {
5
+ config: PublicSerpConfig;
6
+ store?: Store;
7
+ children: ComponentChildren;
8
+ };
9
+ export declare function SearchPageProvider({ config, store, children }: SearchProps): import("preact").JSX.Element;
10
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ComponentChildren, VNode } from 'preact';
2
+ type Props = {
3
+ children: ComponentChildren;
4
+ /**
5
+ * Update the element with custom logic. Each vnode (valid JSX element) will be passed to this function recursively.
6
+ * You may either mutate the existing node, or create a new one.
7
+ *
8
+ * @param vnode Current target node
9
+ * @returns {VNode} if the vnode should be updated
10
+ * @returns {null} if the vnode should be removed
11
+ */
12
+ updateElement: <P extends object>(vnode: VNode<P>, context: Context) => VNode<P> | null;
13
+ };
14
+ type Context = {
15
+ depth: number;
16
+ };
17
+ export declare function renderHeadless(props: Props, ctx?: Context): ComponentChildren;
18
+ export {};
@@ -0,0 +1,5 @@
1
+ import { VNode } from 'preact';
2
+ import { JSX } from 'preact/jsx-runtime';
3
+ export type UnknownVnode = VNode<any>;
4
+ export declare function isHTMLInput(vnode: UnknownVnode): vnode is VNode<JSX.IntrinsicElements["input"]>;
5
+ export declare function isVNode(child: unknown): child is VNode;
@@ -0,0 +1,32 @@
1
+ import { InputSearchRangeFilter, SearchOptions, SearchQuery } from '@nosto/nosto-js/client';
2
+ /**
3
+ * Preact hook that import current actions to the component.
4
+ * Actions should be used to modify state, making new searches, etc.
5
+ *
6
+ * @example
7
+ * ```jsx
8
+ * import { useActions } from '@nosto/search-js/preact'
9
+ *
10
+ * export default () => {
11
+ * const { newSearch } = useActions()
12
+ *
13
+ * return <button onClick={() => {
14
+ * newSearch({
15
+ * query: {
16
+ * query: "shoes"
17
+ * }
18
+ * })
19
+ * }}>
20
+ * Search for "shoes"
21
+ * </button>
22
+ * }
23
+ * ```
24
+ *
25
+ * @group Hooks
26
+ */
27
+ export declare function useActions(): {
28
+ newSearch: (query: SearchQuery, options?: SearchOptions) => Promise<void>;
29
+ updateSearch: (query: SearchQuery, options?: SearchOptions) => Promise<void>;
30
+ toggleProductFilter: (field: string, value: string, active: boolean) => Promise<void>;
31
+ replaceFilter: (field: string, value: InputSearchRangeFilter | string | undefined) => Promise<void>;
32
+ };
@@ -0,0 +1 @@
1
+ export declare function useCheckClientScript(): void;
@@ -0,0 +1,27 @@
1
+ import { DecoratedProduct, DecoratedResult, HitDecorator } from '../../../core/src/types';
2
+ import { SearchProduct, SearchResult } from '@nosto/nosto-js/client';
3
+ /**
4
+ * Applies decorator types to provided products.
5
+ * If value is not provided, returns the latest search results from the store instead.
6
+ *
7
+ * @example
8
+ * ```jsx
9
+ * import { useDecoratedSearchResults } from '@nosto/search-js/preact'
10
+ * import { priceDecorator } from '@nosto/search-js/currencies'
11
+ *
12
+ * export default () => {
13
+ * const results = useDecoratedSearchResults<[typeof priceDecorator]>()
14
+ *
15
+ * return (
16
+ * <div>
17
+ * List price is {results[0].listPriceText}
18
+ * </div>
19
+ * )
20
+ * }
21
+ * ```
22
+ *
23
+ * @group Hooks
24
+ */
25
+ export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(): DecoratedResult<T>;
26
+ export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(products: SearchProduct): DecoratedProduct<T>;
27
+ export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(products: SearchResult): DecoratedResult<T>;
@@ -0,0 +1,60 @@
1
+ import { SearchTermsFacet } from '@nosto/nosto-js/client';
2
+ /**
3
+ * Preact hook that provides facet state to the component.
4
+ * @param facet
5
+ * @example
6
+ * ```jsx
7
+ * import { useFacet } from '@nosto/search-js/preact'
8
+ *
9
+ * export default () => {
10
+ * const { active, selectedFiltersCount, toggleActive, toggleProductFilter } = useFacet(facet)
11
+ * return (
12
+ * <li class={`ns-sidebar-dropdown ${active ? "ns-active" : ""}`}>
13
+ * <span
14
+ * onClick={toggleActive}
15
+ * >
16
+ * <span>{facet.name}</span>
17
+ * {selectedFiltersCount > 0 && (
18
+ * <span>{selectedFiltersCount}</span>
19
+ * )}
20
+ * </span>
21
+ * <div>
22
+ * <ul>
23
+ * {facet.data?.map(value => (
24
+ * <li key={value.value}>
25
+ * <label>
26
+ * {value.value}
27
+ * <input
28
+ * type="checkbox"
29
+ * checked={value.selected}
30
+ * onChange={e => {
31
+ * e.preventDefault()
32
+ * toggleProductFilter(
33
+ * facet.field,
34
+ * value.value,
35
+ * !value.selected
36
+ * )
37
+ * }}
38
+ * />
39
+ * </label>
40
+ * <span>{value.count}</span>
41
+ * </li>
42
+ * ))}
43
+ * </ul>
44
+ * </div>
45
+ * </li>
46
+ * );
47
+ * }
48
+ * ```
49
+ * @group Hooks
50
+ */
51
+ export declare function useFacet(facet: SearchTermsFacet): {
52
+ /** Active value */
53
+ active: boolean;
54
+ /** Selected filters count */
55
+ selectedFiltersCount: number;
56
+ /** Toggle active function */
57
+ toggleActive: () => void;
58
+ /** Toggle product filter function */
59
+ toggleProductFilter: (field: string, value: string, active: boolean) => Promise<void>;
60
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Preact hook that imports the facets to the component.
3
+ * @example
4
+ * ```jsx
5
+ * import { useFacets } from '@nosto/search-js/preact'
6
+ * import { defaultConfig } from "../config"
7
+ *
8
+ * export default () => {
9
+ * const { loading, facets } = useFacets()
10
+ *
11
+ * return (
12
+ * <div style={loading ? "opacity: 0.3;" : ""}>
13
+ * <div>
14
+ * <ul>
15
+ * {facets.map(facet => {
16
+ * switch (facet.type) {
17
+ * case "terms":
18
+ * return <Facet facet={facet} />
19
+ * case "stats":
20
+ * return <RangeFacet facet={facet} />
21
+ * default:
22
+ * return null
23
+ * }
24
+ * })}
25
+ * </ul>
26
+ * </div>
27
+ * </div>
28
+ * )
29
+ * }
30
+ * ```
31
+ * @group Hooks
32
+ *
33
+ */
34
+ export declare function useFacets(): {
35
+ /** Loading state */
36
+ loading: boolean;
37
+ /** Array of facets*/
38
+ facets: import('@nosto/nosto-js/client').SearchFacet[];
39
+ };
@@ -1,4 +1,4 @@
1
- import { State } from "@preact/store";
1
+ import { State } from '../store';
2
2
  /**
3
3
  * Imports a part of the Nosto state to the component.
4
4
  *
@@ -37,4 +37,5 @@ import { State } from "@preact/store";
37
37
  *
38
38
  * @group Hooks
39
39
  */
40
- export declare function useNostoAppState<Selected>(selector?: (state: State) => Selected): Selected;
40
+ export declare function useNostoAppState(): State;
41
+ export declare function useNostoAppState<Selected>(selector: (state: State) => Selected): Selected;
@@ -1,4 +1,4 @@
1
- import type { PersonalizationBoost } from "@nosto/nosto-js/client";
1
+ import { PersonalizationBoost } from '@nosto/nosto-js/client';
2
2
  /**
3
3
  * Custom hook to fetch personalization data such as segments and boost.
4
4
  *
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Preact hook that imports the product filters to the component.
3
+ *
4
+ * @example
5
+ * ```jsx
6
+ * import { useProductFilters, useActions } from '@nosto/search-js/preact'
7
+ *
8
+ * export default () => {
9
+ * const { filters } = useProductFilters()
10
+ * const { toggleProductFilter } = useActions()
11
+ *
12
+ * return filters.map((filter) => <li>
13
+ * <button
14
+ * title="Remove Filter"
15
+ * onClick={(e) => {
16
+ * e.preventDefault()
17
+ * toggleProductFilter(
18
+ * filter.field,
19
+ * filter.value,
20
+ * false
21
+ * )
22
+ * }}
23
+ * >
24
+ * {filter.filter}: {filter.value}{' '}
25
+ * <span>&#10005;</span>
26
+ * </button>
27
+ * </li>)
28
+ * }
29
+ * ```
30
+ *
31
+ * @group Hooks
32
+ */
33
+ export declare function useProductFilters(): {
34
+ /** Selected filters array. */
35
+ filters: ({
36
+ value: string;
37
+ field: string;
38
+ name: string;
39
+ filter: {
40
+ range: {
41
+ gt: string | number | undefined;
42
+ gte: string | number | undefined;
43
+ lt: string | number | undefined;
44
+ lte: string | number | undefined;
45
+ }[] | undefined;
46
+ all?: import('@nosto/nosto-js/client').InputSearchFilter[];
47
+ any?: import('@nosto/nosto-js/client').InputSearchFilter[];
48
+ excludeFacets?: string[];
49
+ field?: string;
50
+ hasValue?: boolean;
51
+ not?: import('@nosto/nosto-js/client').InputSearchFilter[];
52
+ prefix?: string[];
53
+ value?: string[];
54
+ };
55
+ remove: () => void;
56
+ } | undefined)[];
57
+ /** Should remove all selected filters. */
58
+ removeAll: () => void;
59
+ };
@@ -0,0 +1,48 @@
1
+ import { InputSearchTopLevelFilter } from '@nosto/nosto-js/client';
2
+ export declare function useProductFiltersUtils(): {
3
+ selectFilters: (filter: InputSearchTopLevelFilter) => boolean;
4
+ toValueFilter: (filter: InputSearchTopLevelFilter) => {
5
+ value: string;
6
+ field: string;
7
+ name: string;
8
+ filter: {
9
+ range: {
10
+ gt: string | number | undefined;
11
+ gte: string | number | undefined;
12
+ lt: string | number | undefined;
13
+ lte: string | number | undefined;
14
+ }[] | undefined;
15
+ all?: import('@nosto/nosto-js/client').InputSearchFilter[];
16
+ any?: import('@nosto/nosto-js/client').InputSearchFilter[];
17
+ excludeFacets?: string[];
18
+ field?: string;
19
+ hasValue?: boolean;
20
+ not?: import('@nosto/nosto-js/client').InputSearchFilter[];
21
+ prefix?: string[];
22
+ value?: string[];
23
+ };
24
+ remove: () => void;
25
+ }[];
26
+ toRangeFilter: (filter: InputSearchTopLevelFilter) => ({
27
+ value: string;
28
+ field: string;
29
+ name: string;
30
+ filter: {
31
+ range: {
32
+ gt: string | number | undefined;
33
+ gte: string | number | undefined;
34
+ lt: string | number | undefined;
35
+ lte: string | number | undefined;
36
+ }[] | undefined;
37
+ all?: import('@nosto/nosto-js/client').InputSearchFilter[];
38
+ any?: import('@nosto/nosto-js/client').InputSearchFilter[];
39
+ excludeFacets?: string[];
40
+ field?: string;
41
+ hasValue?: boolean;
42
+ not?: import('@nosto/nosto-js/client').InputSearchFilter[];
43
+ prefix?: string[];
44
+ value?: string[];
45
+ };
46
+ remove: () => void;
47
+ } | undefined)[];
48
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A hook that returns range information and functions to update the range.
3
+ *
4
+ * @param id - The identifier for the specific range facet.
5
+ * @returns An object containing range information and functions to update the range.
6
+ *
7
+ * @example
8
+ * General usage with `useRange`:
9
+ * ```jsx
10
+ * import { useRange } from "@nosto/search-js/preact";
11
+ * import { useState } from "react";
12
+ *
13
+ * const Component = ({ facetId }) => {
14
+ * const { min, max, range, updateRange } = useRange(facetId);
15
+ *
16
+ * return (
17
+ * <div>
18
+ * Current Range: {range[0]} to {range[1]}
19
+ * <button onClick={() => updateRange([min, max])}>Reset Range</button>
20
+ * </div>
21
+ * );
22
+ * };
23
+ * ```
24
+ */
25
+ export declare function useRange(id: string): {
26
+ /** Min value */
27
+ min: number;
28
+ /** Max value */
29
+ max: number;
30
+ /** Range value */
31
+ range: number[];
32
+ /** Update range function */
33
+ updateRange: ([from, to]: [number | undefined, number | undefined]) => void;
34
+ };