@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.
- package/README.md +3 -39
- package/dist/core/core.d.ts +2 -2
- package/dist/core/src/applyDecorators.d.ts +9 -9
- package/dist/core/src/search.d.ts +9 -9
- package/dist/core/src/searchWithRetries.d.ts +2 -2
- package/dist/core/src/types.d.ts +5 -6
- package/dist/currencies/currencies.d.ts +2 -2
- package/dist/currencies/src/getCurrencyFormatting.d.ts +2 -3
- package/dist/currencies/src/priceDecorator.d.ts +2 -2
- package/dist/preact/preact.cjs.js +1 -1
- package/dist/preact/preact.d.ts +24 -5
- package/dist/preact/preact.es.js +741 -100
- package/dist/preact/src/actions/newSearch.d.ts +4 -0
- package/dist/preact/src/actions/replaceFilter.d.ts +3 -0
- package/dist/preact/src/actions/toggleProductFilter.d.ts +2 -0
- package/dist/preact/src/actions/types.d.ts +6 -0
- package/dist/preact/src/actions/updateSearch.d.ts +4 -0
- package/dist/preact/src/api/types.d.ts +4 -0
- package/dist/preact/src/components/SearchInput.d.ts +7 -0
- package/dist/preact/src/components/SerpElement.d.ts +18 -0
- package/dist/preact/src/config/base/baseConfig.d.ts +41 -0
- package/dist/preact/src/config/config.d.ts +4 -0
- package/dist/preact/src/config/configContext.d.ts +6 -0
- package/dist/preact/src/config/pages/autocomplete/config.d.ts +15 -0
- package/dist/preact/src/config/pages/autocomplete/provider.d.ts +10 -0
- package/dist/preact/src/config/pages/category/config.d.ts +44 -0
- package/dist/preact/src/config/pages/category/provider.d.ts +10 -0
- package/dist/preact/src/config/pages/serp/config.d.ts +34 -0
- package/dist/preact/src/config/pages/serp/provider.d.ts +10 -0
- package/dist/preact/src/dom/renderHeadless.d.ts +18 -0
- package/dist/preact/src/dom/utils.d.ts +5 -0
- package/dist/preact/src/hooks/useActions.d.ts +32 -0
- package/dist/preact/src/hooks/useCheckClientScript.d.ts +1 -0
- package/dist/preact/src/hooks/useDecoratedSearchResults.d.ts +27 -0
- package/dist/preact/src/hooks/useFacet.d.ts +60 -0
- package/dist/preact/src/hooks/useFacets.d.ts +39 -0
- package/dist/preact/src/hooks/useNostoAppState.d.ts +3 -2
- package/dist/preact/src/hooks/usePersonalization.d.ts +1 -1
- package/dist/preact/src/hooks/useProductFilters/useProductFilters.d.ts +59 -0
- package/dist/preact/src/hooks/useProductFilters/useProductFiltersUtils.d.ts +48 -0
- package/dist/preact/src/hooks/useRange.d.ts +34 -0
- package/dist/preact/src/hooks/useRangeSelector.d.ts +98 -0
- package/dist/preact/src/hooks/useResponse.d.ts +82 -0
- package/dist/preact/src/hooks/useSelectedFiltersCount.d.ts +17 -0
- package/dist/preact/src/hooks/useSizeOptions.d.ts +50 -0
- package/dist/preact/src/hooks/useSort/useSort.d.ts +47 -0
- package/dist/preact/src/hooks/useSort/utils.d.ts +9 -0
- package/dist/preact/src/search/defaults.d.ts +45 -0
- package/dist/preact/src/search/resultCaching.d.ts +4 -0
- package/dist/preact/src/store.d.ts +9 -1387
- package/dist/preact/src/storeContext.d.ts +5 -1389
- package/dist/preact/src/storeExtensions.d.ts +17 -0
- package/dist/thumbnails/src/generateThumbnailUrl.d.ts +1 -1
- package/dist/thumbnails/src/nostoThumbnailDecorator.d.ts +2 -2
- package/dist/thumbnails/src/shopifyThumbnailDecorator.d.ts +2 -2
- package/dist/thumbnails/src/thumbnailDecorator.d.ts +2 -2
- package/dist/thumbnails/thumbnails.d.ts +5 -5
- package/dist/utils/src/deepFreeze.d.ts +1 -1
- package/dist/utils/src/deepMerge.d.ts +5 -3
- package/dist/utils/src/mergeArrays.d.ts +2 -1
- package/dist/utils/src/parseNumber.d.ts +1 -0
- package/dist/utils/src/performance.d.ts +1 -0
- package/dist/utils/src/savePageScroll.d.ts +2 -0
- package/dist/utils/src/simplify.d.ts +1 -1
- package/dist/utils/src/storage.d.ts +6 -0
- package/dist/utils/src/types.d.ts +3 -0
- package/dist/utils/src/unique.d.ts +1 -0
- package/package.json +22 -15
- package/dist/preact/test/mocks/mocks.d.ts +0 -1384
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get range selector state
|
|
3
|
+
* @param id - Id of the range Selector
|
|
4
|
+
* @example
|
|
5
|
+
* ```jsx
|
|
6
|
+
* import { useRangeCheckboxes } from "@nosto/search-js/preact"
|
|
7
|
+
* import { useState } from "preact/hooks"
|
|
8
|
+
* import RadioButton from "./elements/RadioButton"
|
|
9
|
+
* import RangeInput from "./elements/RangeInput"
|
|
10
|
+
*
|
|
11
|
+
* export default function RangeSelector({ facet }) {
|
|
12
|
+
* const {
|
|
13
|
+
* min,
|
|
14
|
+
* max,
|
|
15
|
+
* range,
|
|
16
|
+
* ranges,
|
|
17
|
+
* updateRange,
|
|
18
|
+
* handleMinChange,
|
|
19
|
+
* handleMaxChange,
|
|
20
|
+
* isSelected,
|
|
21
|
+
* } = useRangeSelector(facet.id, 100)
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <li>
|
|
25
|
+
* <div>
|
|
26
|
+
* <ul>
|
|
27
|
+
* {ranges.map(({ min, max, selected }, index) => {
|
|
28
|
+
* return (
|
|
29
|
+
* <li>
|
|
30
|
+
* <RadioButton
|
|
31
|
+
* key={index}
|
|
32
|
+
* value={`${min} - ${max}`}
|
|
33
|
+
* selected={selected}
|
|
34
|
+
* onChange={() => updateRange([min, max])}
|
|
35
|
+
* />
|
|
36
|
+
* </li>
|
|
37
|
+
* )
|
|
38
|
+
* })}
|
|
39
|
+
* <div>
|
|
40
|
+
* <div>
|
|
41
|
+
* <label htmlFor={`ns-${facet.id}-min`}>
|
|
42
|
+
* Min.
|
|
43
|
+
* </label>
|
|
44
|
+
* <RangeInput
|
|
45
|
+
* id={`ns-${facet.id}-min`}
|
|
46
|
+
* min={min}
|
|
47
|
+
* max={max}
|
|
48
|
+
* range={range}
|
|
49
|
+
* value={range[0] ?? min}
|
|
50
|
+
* onChange={e => handleMinChange(parseFloat(e.currentTarget.value) || min)}
|
|
51
|
+
* />
|
|
52
|
+
* </div>
|
|
53
|
+
* <div>
|
|
54
|
+
* <label htmlFor={`ns-${facet.id}-max`}>
|
|
55
|
+
* Max.
|
|
56
|
+
* </label>
|
|
57
|
+
* <RangeInput
|
|
58
|
+
* id={`ns-${facet.id}-max`}
|
|
59
|
+
* min={min}
|
|
60
|
+
* max={max}
|
|
61
|
+
* range={range}
|
|
62
|
+
* value={range[1] ?? max}
|
|
63
|
+
* onChange={e => handleMaxChange(parseFloat(e.currentTarget.value) || max)}
|
|
64
|
+
* />
|
|
65
|
+
* </div>
|
|
66
|
+
* </div>
|
|
67
|
+
* </ul>
|
|
68
|
+
* </div>
|
|
69
|
+
* </li>
|
|
70
|
+
* )
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
*```
|
|
74
|
+
*
|
|
75
|
+
* @group Hooks
|
|
76
|
+
*/
|
|
77
|
+
export declare function useRangeSelector(id: string, rangeSize: number): {
|
|
78
|
+
/** Minimum value */
|
|
79
|
+
min: number;
|
|
80
|
+
/** Maximum value */
|
|
81
|
+
max: number;
|
|
82
|
+
/** Range value */
|
|
83
|
+
range: number[];
|
|
84
|
+
/** Update range function */
|
|
85
|
+
updateRange: ([from, to]: [number | undefined, number | undefined]) => void;
|
|
86
|
+
/** Ranges */
|
|
87
|
+
ranges: {
|
|
88
|
+
min: number;
|
|
89
|
+
max: number;
|
|
90
|
+
selected: boolean | null;
|
|
91
|
+
}[];
|
|
92
|
+
/** Handle min change */
|
|
93
|
+
handleMinChange: (value: number) => void;
|
|
94
|
+
/** Handle max change */
|
|
95
|
+
handleMaxChange: (value: number) => void;
|
|
96
|
+
/** Is selected */
|
|
97
|
+
isSelected: boolean;
|
|
98
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { SearchKeywords, SearchProducts } from '@nosto/nosto-js/client';
|
|
2
|
+
/**
|
|
3
|
+
* Preact hook that imports response data to the component.
|
|
4
|
+
* @example
|
|
5
|
+
* ```jsx
|
|
6
|
+
* import { useResponse } from '@nosto/search-js/preact'
|
|
7
|
+
* import { defaultConfig } from "../config"
|
|
8
|
+
*
|
|
9
|
+
* export default () => {
|
|
10
|
+
* const { products, keywords } = useResponse()
|
|
11
|
+
* return (
|
|
12
|
+
* <div>
|
|
13
|
+
* <div>
|
|
14
|
+
* {keywords.hits.length > 0 && (
|
|
15
|
+
* <div>
|
|
16
|
+
* <div>
|
|
17
|
+
* Keywords
|
|
18
|
+
* </div>
|
|
19
|
+
* <div>
|
|
20
|
+
* <Keywords
|
|
21
|
+
* hits={keywords.hits}
|
|
22
|
+
* keywordComponent={Keyword}
|
|
23
|
+
* elementComponent={Element}
|
|
24
|
+
* keywordInCategoryComponent={KeywordInCategory}
|
|
25
|
+
* />
|
|
26
|
+
* </div>
|
|
27
|
+
* {!products.hits.length && <SubmitButton />}
|
|
28
|
+
* </div>
|
|
29
|
+
* )}
|
|
30
|
+
* {products.hits.length > 0 && (
|
|
31
|
+
* <div>
|
|
32
|
+
* <div>
|
|
33
|
+
* Products
|
|
34
|
+
* </div>
|
|
35
|
+
* <div>
|
|
36
|
+
* {products.hits.map(hit => {
|
|
37
|
+
* return (
|
|
38
|
+
* <AutocompleteElement hit={hit}>
|
|
39
|
+
* <div
|
|
40
|
+
* data-url={hit.url}
|
|
41
|
+
* data-nosto-element="product"
|
|
42
|
+
* >
|
|
43
|
+
* <img
|
|
44
|
+
* src={hit.imageUrl ?? productImagePlaceholder}
|
|
45
|
+
* alt={hit.name}
|
|
46
|
+
* />
|
|
47
|
+
* <div>
|
|
48
|
+
* {hit.brand && (
|
|
49
|
+
* <div>{hit.brand}</div>
|
|
50
|
+
* )}
|
|
51
|
+
* <div>
|
|
52
|
+
* {hit.name}
|
|
53
|
+
* </div>
|
|
54
|
+
* <div>
|
|
55
|
+
* <span>{formatCurrency(hit.price)}</span>
|
|
56
|
+
* {hit.listPrice && hit.listPrice > hit.price && (
|
|
57
|
+
* <span>
|
|
58
|
+
* {formatCurrency(hit.listPrice)}
|
|
59
|
+
* </span>
|
|
60
|
+
* )}
|
|
61
|
+
* </div>
|
|
62
|
+
* </div>
|
|
63
|
+
* </div>
|
|
64
|
+
* </AutocompleteElement>
|
|
65
|
+
* )
|
|
66
|
+
* })}
|
|
67
|
+
* </div>
|
|
68
|
+
* <SubmitButton />
|
|
69
|
+
* </div>
|
|
70
|
+
* )}
|
|
71
|
+
* </div>
|
|
72
|
+
* </div>
|
|
73
|
+
* )
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
* @group Hooks
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
export declare function useResponse(): {
|
|
80
|
+
products: SearchProducts;
|
|
81
|
+
keywords: SearchKeywords;
|
|
82
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @group Hooks
|
|
3
|
+
* @returns The number of selected filters.
|
|
4
|
+
* @example
|
|
5
|
+
* ```jsx
|
|
6
|
+
* import { useSelectedFiltersCount } from '@nosto/search-js/preact'
|
|
7
|
+
* export default () => {
|
|
8
|
+
* const selectedFiltersCount = useSelectedFiltersCount()
|
|
9
|
+
* return (
|
|
10
|
+
* <div>
|
|
11
|
+
* {selectedFiltersCount} filters selected
|
|
12
|
+
* </div>
|
|
13
|
+
* )
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useSelectedFiltersCount(): number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preact hook that provides size options to the component.
|
|
3
|
+
* @param sizes
|
|
4
|
+
* @param serpSize
|
|
5
|
+
* @example
|
|
6
|
+
* ```jsx
|
|
7
|
+
* import { useSizeOptions } from "@nosto/search-js/preact"
|
|
8
|
+
* import { defaultConfig, sizes } from "../config"
|
|
9
|
+
*
|
|
10
|
+
* export default () => {
|
|
11
|
+
* const options = useSizeOptions(sizes, defaultConfig.serpSize)
|
|
12
|
+
* const { from, to, total, size, sizeOptions, handleSizeChange } = options
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <div>
|
|
16
|
+
* <div>
|
|
17
|
+
* {from} - {total < to ? total : to} of {total} items
|
|
18
|
+
* </div>
|
|
19
|
+
* {sizeOptions.length > 0 && (
|
|
20
|
+
* <div>
|
|
21
|
+
* <select
|
|
22
|
+
* value={size}
|
|
23
|
+
* onChange={e => handleSizeChange(e.target.value)}
|
|
24
|
+
* >
|
|
25
|
+
* {sizeOptions.map(v => (
|
|
26
|
+
* <option value={v}>{v} items per page</option>
|
|
27
|
+
* ))}
|
|
28
|
+
* </select>
|
|
29
|
+
* </div>
|
|
30
|
+
* )}
|
|
31
|
+
* </div>
|
|
32
|
+
* )
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
* @group Hooks
|
|
36
|
+
*/
|
|
37
|
+
export declare function useSizeOptions(sizes: number[], serpSize: number): {
|
|
38
|
+
/** from value */
|
|
39
|
+
from: number;
|
|
40
|
+
/** to value */
|
|
41
|
+
to: number;
|
|
42
|
+
/** total value */
|
|
43
|
+
total: number;
|
|
44
|
+
/** size value */
|
|
45
|
+
size: number;
|
|
46
|
+
/** Array of size options */
|
|
47
|
+
sizeOptions: number[];
|
|
48
|
+
/** Should be called when size is changed */
|
|
49
|
+
handleSizeChange: (size: number) => void;
|
|
50
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { InputSearchSort } from '@nosto/nosto-js/client';
|
|
2
|
+
export interface SortOption {
|
|
3
|
+
id: string;
|
|
4
|
+
value: {
|
|
5
|
+
name: string;
|
|
6
|
+
sort: InputSearchSort[];
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Preact hook that import sort state to the component.
|
|
11
|
+
* @param sortOptions
|
|
12
|
+
* @example
|
|
13
|
+
* ```jsx
|
|
14
|
+
* import { useSort } from '@nosto/search-js/preact'
|
|
15
|
+
* import { sortOptions } from '../config'
|
|
16
|
+
*
|
|
17
|
+
* export default () => {
|
|
18
|
+
* const { activeSort, setSort } = useSort(sortOptions)
|
|
19
|
+
*
|
|
20
|
+
* const handleSortChange = (event) => {
|
|
21
|
+
* setSort(event.target.value)
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <div>
|
|
26
|
+
* <select
|
|
27
|
+
* value={activeSort}
|
|
28
|
+
* onChange={e => setSort(e.target.value)}
|
|
29
|
+
* >
|
|
30
|
+
* {sortOptions.map(option => (
|
|
31
|
+
* <option key={option.id} value={option.id}>
|
|
32
|
+
* {option.value.name}
|
|
33
|
+
* </option>
|
|
34
|
+
* ))}
|
|
35
|
+
* </select>
|
|
36
|
+
* </div>
|
|
37
|
+
* )
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
* @group Hooks
|
|
41
|
+
*/
|
|
42
|
+
export declare function useSort(sortOptions: SortOption[]): {
|
|
43
|
+
/** Active sort */
|
|
44
|
+
activeSort: string;
|
|
45
|
+
/** Set sort function */
|
|
46
|
+
setSort: (sortId: string) => void;
|
|
47
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InputSearchSort } from '@nosto/nosto-js/client';
|
|
2
|
+
export declare function createSortOption(id: string, name: string, ...sort: InputSearchSort[]): {
|
|
3
|
+
id: string;
|
|
4
|
+
value: {
|
|
5
|
+
name: string;
|
|
6
|
+
sort: InputSearchSort[];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare function isMatchingSort(optionSort: InputSearchSort[], querySort: InputSearchSort[]): boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
2
|
+
import { PageType } from '../api/types';
|
|
3
|
+
export declare function applyQueryDefaults(pageType: PageType, query: SearchQuery): {
|
|
4
|
+
keywords?: import('@nosto/nosto-js/client').InputSearchQuery["keywords"] & {
|
|
5
|
+
fields: string[];
|
|
6
|
+
facets: string[];
|
|
7
|
+
};
|
|
8
|
+
products: {
|
|
9
|
+
boost?: import('@nosto/nosto-js/client').InputSearchBoost[];
|
|
10
|
+
categoryId?: string;
|
|
11
|
+
categoryPath?: string;
|
|
12
|
+
collapse?: string;
|
|
13
|
+
customFacets?: import('@nosto/nosto-js/client').InputSearchFacetConfig[];
|
|
14
|
+
emptyQueryMatchesAll?: boolean;
|
|
15
|
+
exclusionBehaviour?: import('@nosto/nosto-js/client').SearchExclusionBehaviour;
|
|
16
|
+
facets: string[];
|
|
17
|
+
filter?: import('@nosto/nosto-js/client').InputSearchTopLevelFilter[];
|
|
18
|
+
from?: number;
|
|
19
|
+
outOfStockBehaviour?: import('@nosto/nosto-js/client').SearchOutOfStockBehaviour;
|
|
20
|
+
personalizationBoost?: import('@nosto/nosto-js/client').InputSearchBoost[];
|
|
21
|
+
personalizationWeight?: number;
|
|
22
|
+
pin?: import('@nosto/nosto-js/client').InputSearchPin[];
|
|
23
|
+
preFilter?: import('@nosto/nosto-js/client').InputSearchFilter[];
|
|
24
|
+
queryFields?: import('@nosto/nosto-js/client').SearchQueryField[];
|
|
25
|
+
relevanceWeight?: number;
|
|
26
|
+
showPrivateFields?: boolean;
|
|
27
|
+
size?: number;
|
|
28
|
+
sort?: import('@nosto/nosto-js/client').InputSearchSort[];
|
|
29
|
+
variationId?: string;
|
|
30
|
+
fields: string[];
|
|
31
|
+
};
|
|
32
|
+
explain?: boolean | undefined;
|
|
33
|
+
query?: string | undefined;
|
|
34
|
+
redirect?: string | undefined;
|
|
35
|
+
abTests?: import('@nosto/nosto-js/client').InputSearchABTest[] | undefined;
|
|
36
|
+
accountId?: string | undefined;
|
|
37
|
+
customRules?: import('@nosto/nosto-js/client').InputSearchRule[] | undefined;
|
|
38
|
+
rules?: string[] | undefined;
|
|
39
|
+
segments?: string[] | undefined;
|
|
40
|
+
sessionParams?: import('@nosto/nosto-js/client').InputSearchQuery | undefined;
|
|
41
|
+
time?: number | undefined;
|
|
42
|
+
name?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare const defaultProductFields: string[];
|
|
45
|
+
export declare const defaultKeywordFields: string[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
+
export declare const STORAGE_ENTRY_NAME = "nosto:search:searchResult";
|
|
3
|
+
export declare function cacheSearchResult(usePersistentCache: boolean, query: SearchQuery, result: SearchResult): void;
|
|
4
|
+
export declare function loadCachedResultIfApplicable(usePersistentCache: boolean, query: SearchQuery): SearchResult | null;
|