@nosto/search-js 2.8.1 → 2.8.2
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/{InfiniteScrollWithObserver-PqDE6YMh.cjs → InfiniteScrollWithObserver-Dqkhs6xC.cjs} +1 -1
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/src/applyDecorators.d.ts +1 -1
- package/dist/core/src/resultCaching.d.ts +0 -5
- package/dist/core/src/types.d.ts +2 -2
- package/dist/core/src/withCache.d.ts +2 -2
- package/dist/core/src/withRetries.d.ts +2 -2
- package/dist/preact/common.cjs.js +1 -1
- package/dist/preact/hooks.cjs.js +1 -1
- package/dist/preact/legacy.cjs.js +1 -1
- package/dist/preact/src/hooks/useActions.d.ts +1 -1
- package/dist/preact/src/hooks/useDecoratedSearchResults.d.ts +2 -2
- package/dist/preact/src/hooks/useFacet.d.ts +1 -1
- package/dist/preact/src/hooks/useFacets.d.ts +1 -1
- package/dist/preact/src/hooks/useLoadMore/useLoadMore.d.ts +1 -1
- package/dist/preact/src/hooks/useNostoAppState.d.ts +2 -2
- package/dist/preact/src/hooks/usePagination.d.ts +1 -1
- package/dist/preact/src/hooks/usePersonalization.d.ts +1 -1
- package/dist/preact/src/hooks/useProductFilters/useProductFilters.d.ts +1 -1
- package/dist/preact/src/hooks/useRange.d.ts +1 -1
- package/dist/preact/src/hooks/useRangeSelector.d.ts +1 -1
- package/dist/preact/src/hooks/useResponse.d.ts +1 -1
- package/dist/preact/src/hooks/useSelectedFiltersCount.d.ts +1 -1
- package/dist/preact/src/hooks/useSizeOptions.d.ts +1 -1
- package/dist/preact/src/hooks/useSort/useSort.d.ts +1 -1
- package/dist/{search-BUagWuec.cjs → search-Diw6abza.cjs} +1 -1
- package/dist/{useLoadMore-BqRzn6Z9.cjs → useLoadMore-MtlFB35p.cjs} +1 -1
- package/dist/utils/utils.cjs.js +1 -1
- package/dist/utils/utils.es.js +11 -11
- package/package.json +1 -1
package/dist/{InfiniteScrollWithObserver-PqDE6YMh.cjs → InfiniteScrollWithObserver-Dqkhs6xC.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-
|
|
1
|
+
"use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-MtlFB35p.cjs"),a=require("./pick-rYi1lc2m.cjs"),d=require("preact/hooks"),b=require("preact");function f(s,i){var o,e,r;const t=((o=i.products)==null?void 0:o.total)??0,c=((e=s.products)==null?void 0:e.from)??0,n=((r=s.products)==null?void 0:r.size)??0;return t>0&&t>c+n}function h(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function O({children:s,pageSize:i}){const t=d.useRef(null),{query:c,response:n}=p.useNostoAppState(e=>a.pick(e,"query","response")),{loadMore:o}=p.useLoadMore(i);return d.useEffect(()=>{let e,r;return f(c,n)&&(e=t.current,r=new IntersectionObserver(v=>{const u=v[0];u!=null&&u.isIntersecting&&o()}),e&&r.observe(e)),()=>{e&&r.unobserve(e)}},[n]),l.u(b.Fragment,{children:[s,l.u("div",{ref:t,style:{height:"1px"}})]})}exports.InfiniteScrollWithObserver=O;exports.hasMoreResults=f;exports.intersectionObserverSupported=h;
|
package/dist/core/core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-Diw6abza.cjs");async function d(r,a,t=1){await e.L(a,void 0,t),await e.s(async c=>await c.recordSearchAddToCart(r,a))}exports.search=o.search;exports.addToCart=d;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
2
2
|
import { DecoratedResult, HitDecorator, SearchFn, SearchOptions } from './types';
|
|
3
|
-
export declare function applyDecorators<HD extends readonly HitDecorator[]>(query: SearchQuery, { hitDecorators, ...options }: SearchOptions<HD>, searchFn: SearchFn
|
|
3
|
+
export declare function applyDecorators<HD extends readonly HitDecorator[]>(query: SearchQuery, { hitDecorators, ...options }: SearchOptions<HD>, searchFn: SearchFn): Promise<DecoratedResult<HD>>;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
2
|
export declare const STORAGE_ENTRY_NAME = "nosto:search:searchResult";
|
|
3
|
-
export type SearchResultDto = {
|
|
4
|
-
query: SearchQuery;
|
|
5
|
-
result: SearchResult;
|
|
6
|
-
};
|
|
7
3
|
export declare function cacheSearchResult(query: SearchQuery, result: SearchResult): void;
|
|
8
4
|
export declare function loadCachedResult(query: SearchQuery): SearchResult | null;
|
|
9
|
-
export declare function isValueShapeCorrect(value: unknown): value is SearchResultDto;
|
package/dist/core/src/types.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export type SearchOptions<HD extends readonly HitDecorator[] = readonly HitDecor
|
|
|
17
17
|
*/
|
|
18
18
|
usePersistentCache?: boolean;
|
|
19
19
|
};
|
|
20
|
-
export type SearchFn
|
|
21
|
-
export type SearchWithNext
|
|
20
|
+
export type SearchFn = (query: SearchQuery, options: SearchOptions) => Promise<SearchResult>;
|
|
21
|
+
export type SearchWithNext = (query: SearchQuery, options: SearchOptions, searchFn: SearchFn) => Promise<SearchResult>;
|
|
22
22
|
export type HitDecorator = (hit: SearchProduct) => SearchProduct;
|
|
23
23
|
export type ToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
24
24
|
export type DecoratedProduct<HD extends readonly HitDecorator[]> = ToIntersection<ReturnType<HD[number]>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SearchFn, SearchOptions } from './types';
|
|
2
2
|
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
3
|
-
export declare function searchWithCache
|
|
3
|
+
export declare function searchWithCache(query: SearchQuery, { usePersistentCache, ...options }: SearchOptions, searchFn: SearchFn): Promise<SearchResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
-
import {
|
|
3
|
-
export declare function searchWithRetries
|
|
2
|
+
import { SearchFn, SearchOptions } from './types';
|
|
3
|
+
export declare function searchWithRetries(query: SearchQuery, { maxRetries, retryInterval, ...options }: SearchOptions, searchFn: SearchFn): Promise<SearchResult>;
|
|
4
4
|
/**
|
|
5
5
|
* Should the error trigger a search retry
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-BCAEb4ek.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-BCAEb4ek.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-MtlFB35p.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-Dqkhs6xC.cjs"),q=require("preact"),r=require("../configContext-BR7w4VlU.cjs");function b({pageSize:o}){const{loadMore:e}=c.useLoadMore(o);return t.u("button",{onClick:e,children:"More results"})}function u({children:o,loadMoreComponent:e,pageSize:i}){const{loading:s,query:l,response:a}=c.useNostoAppState(S=>p.pick(S,"loading","query","response")),d=!s&&n.hasMoreResults(l,a);return t.u(q.Fragment,{children:[o,d&&(e?t.u(e,{pageSize:i}):t.u(b,{pageSize:i}))]})}const M=!f.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=r.StoreContext;exports.createExtendableStore=r.createExtendableStore;exports.createStore=r.createStore;exports.defaultState=r.defaultState;exports.InfiniteScroll=M;exports.InfiniteScrollWithLink=u;
|
package/dist/preact/hooks.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-MtlFB35p.cjs"),P=require("../logger-BcHMZObS.cjs"),v=require("preact/hooks"),C=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function q(e){const o=m.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&P.isPlainObject(e)?e:o}function z(e){var a;const o=((a=e.data)==null?void 0:a.filter(c=>c.selected).length)??0,[t,n]=v.useState(o>0),{toggleProductFilter:u}=m.useActions();return{active:t,selectedFiltersCount:o,toggleActive:()=>{n(!t)},toggleProductFilter:u}}function x(){const{loading:e,facets:o}=m.useNostoAppState(t=>{var n,u;return{loading:t.loading,facets:((u=(n=t.response)==null?void 0:n.products)==null?void 0:u.facets)??[]}});return{loading:e,facets:o}}function k(e,o){const t=o-e;return!isNaN(t)&&t>0?new Array(o-e).fill(void 0).map((n,u)=>u+e):[]}function w(e){const{query:o,products:t}=m.useNostoAppState(n=>({query:n.query,products:n.response.products}));return v.useMemo(()=>{var F;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=o.products)==null?void 0:F.from)??0,u=(e==null?void 0:e.width)??1/0,i=Math.max(Math.floor(u-1)/2,1),a=t.size>0?Math.floor(n/t.size)+1:1,c=t.size>0?Math.ceil(t.total/t.size):0,g=A=>A>=a-i&&A<=a+i,s=n+1,l=Math.min(n+t.total,t.total),r={from:n,page:a,current:!0},p=A=>({from:(A-1)*t.size,page:A,current:A===a}),S=a>1?p(a-1):void 0,d=a<c?p(a+1):void 0,y=i===1/0||a-i-1>1?p(1):void 0,f=i===1/0||a+i+1<c?p(c):void 0,h=k(1,c+1).filter(g).map(p);return{totalPages:c,resultsFrom:s,resultsTo:l,current:r,prev:S,next:d,first:y,last:f,pages:h}},[o,t,e==null?void 0:e.width])}function T(){const[e,o]=v.useState([]),[t,n]=v.useState([]);return v.useEffect(()=>{C.s(async u=>{const{products:i,segments:a}=await u.getSearchSessionParams();o(a??[]),n((i==null?void 0:i.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function B(){const{facets:e}=m.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:o,toggleProductFilter:t}=m.useActions(),n=v.useCallback(s=>{const l=e==null?void 0:e.find(r=>r.type==="stats"&&r.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),u=v.useCallback(s=>{var l;return((l=e==null?void 0:e.find(r=>r.field===s))==null?void 0:l.name)??s},[e]),i=v.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),a=v.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(r=>({gt:r.gt?Number(r.gt):r.gt,gte:r.gte?Number(r.gte):r.gte,lt:r.lt?Number(r.lt):r.lt,lte:r.lte?Number(r.lte):r.lte}))}},[]),c=v.useCallback(s=>(s.value??[]).map(r=>({value:r,field:s.field,name:u(s.field),filter:a(s),remove:()=>{t(s.field,r,!1)}})),[a,u,t]),g=v.useCallback(s=>(s.range??[]).map(r=>{var d,y;const p=r.gte??r.gt??((d=n(s.field))==null?void 0:d.min),S=r.lte??r.lt??((y=n(s.field))==null?void 0:y.max);if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:s.field,name:u(s.field),filter:a(s),remove:()=>{o(s.field,void 0)}}}).filter(Boolean),[a,n,u,o]);return{selectFilters:i,toValueFilter:c,toRangeFilter:g}}function M(){const{filter:e}=m.useNostoAppState(c=>{var g;return{filter:((g=c.query.products)==null?void 0:g.filter)??[]}}),{updateSearch:o}=m.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:u}=B(),i=v.useMemo(()=>e?e.filter(t).flatMap(c=>"value"in c?n(c):"range"in c?u(c):[]).filter(Boolean):[],[e,t,u,n]),a=v.useCallback(()=>{o({products:{filter:[]}})},[o]);return{filters:i,removeAll:a}}function R(e){var r,p,S;const{replaceFilter:o}=m.useActions(),{query:t,products:n}=m.useNostoAppState(d=>({query:d.query,products:d.response.products})),u=(r=n==null?void 0:n.facets)==null?void 0:r.find(d=>d.id===e);if(!u)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const i=(S=(p=t.products)==null?void 0:p.filter)==null?void 0:S.find(d=>d.field===u.field),a=i!=null&&i.range?i.range[0]:void 0,c=typeof a=="object"&&("gte"in a||"lte"in a)?[N.parseNumber(a.gte),N.parseNumber(a.lte)]:[void 0,void 0],g="min"in u?Math.floor(u.min):0,s="max"in u?Math.ceil(u.max):0,l=([d,y])=>{const f=d!==void 0?Math.floor(d):void 0,h=y!==void 0?Math.ceil(y):void 0,F=f!==void 0,A=h!==void 0;(g===f||!F)&&(s===h||!A)?o(u.field,void 0):(g===f||!F)&&A?o(u.field,{lte:h.toString()}):(s===h||!A)&&F?o(u.field,{gte:f.toString()}):F&&A&&o(u.field,{gte:f.toString(),lte:h.toString()})};return{min:g,max:s,range:[c[0]??g,c[1]??s],updateRange:l}}function D(e,o){const{min:t,max:n,range:u,updateRange:i}=R(e),{filters:a}=M(),c=v.useMemo(()=>{var y;const r=a.find(f=>{var h;return(h=f==null?void 0:f.filter)==null?void 0:h.range});let p=null;if(r){const f=(y=r.filter.range)==null?void 0:y[0];p=[N.parseNumber(f==null?void 0:f.gte),N.parseNumber(f==null?void 0:f.lte)]}const S=[];let d=Math.floor(t/o)*o;for(;d<n;){const f=d+o,h=p&&p[0]===d&&p[1]===f;S.push({min:d,max:f,selected:h}),d=f}return S},[a,t,n,o]),g=r=>{i([r,u[1]])},s=r=>{i([u[0],r])},l=t!==u[0]||n!==u[1];return{min:t,max:n,range:u,updateRange:i,ranges:c,handleMinChange:g,handleMaxChange:s,isSelected:l}}function j(){const{products:e,keywords:o}=m.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:o??{hits:[],total:0}}}function I(){const e=m.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return v.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function b(e){return e&&!Number.isNaN(e)?e:0}function L(e,o){const{from:t,size:n,total:u}=m.useNostoAppState(s=>{var l,r,p,S,d;return{from:b(((l=s.query.products)==null?void 0:l.from)??0),size:b(((p=(r=s.response)==null?void 0:r.products)==null?void 0:p.size)??0),total:b(((d=(S=s.response)==null?void 0:S.products)==null?void 0:d.total)??0)}}),{updateSearch:i}=m.useActions(),a=t+n,c=[...e].reverse().filter(s=>s+o<u);return{from:t,to:a,total:u,size:n,sizeOptions:c,handleSizeChange:s=>{i({products:{size:N.parseNumber(s)}})}}}function O(e,o){return e.length!==o.length?!1:e.every(t=>o.find(n=>t.field===n.field&&t.order===n.order))}function V(e){var i,a;const o=m.useNostoAppState(c=>c.query),{updateSearch:t}=m.useActions();return{activeSort:((i=e.find(c=>{var g;return O(c.value.sort,((g=o.products)==null?void 0:g.sort)||[])}))==null?void 0:i.id)??((a=e[0])==null?void 0:a.id),setSort:c=>{const g=e.find(s=>s.id===c);g&&t({products:{sort:g.value.sort}})}}}exports.useActions=m.useActions;exports.useLoadMore=m.useLoadMore;exports.useNostoAppState=m.useNostoAppState;exports.useDecoratedSearchResults=q;exports.useFacet=z;exports.useFacets=x;exports.usePagination=w;exports.usePersonalization=T;exports.useProductFilters=M;exports.useRange=R;exports.useRangeSelector=D;exports.useResponse=j;exports.useSelectedFiltersCount=I;exports.useSizeOptions=L;exports.useSort=V;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-MtlFB35p.cjs"),r=require("../InfiniteScrollWithObserver-Dqkhs6xC.cjs");exports.getNextPageQuery=e.getNextPageQuery;exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;
|
|
@@ -5,7 +5,7 @@ import { InputSearchRangeFilter, SearchOptions, SearchQuery } from '@nosto/nosto
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```jsx
|
|
8
|
-
* import { useActions } from '@nosto/search-js/preact'
|
|
8
|
+
* import { useActions } from '@nosto/search-js/preact/hooks'
|
|
9
9
|
*
|
|
10
10
|
* export default () => {
|
|
11
11
|
* const { newSearch } = useActions()
|
|
@@ -6,7 +6,7 @@ import { SearchProduct, SearchResult } from '@nosto/nosto-js/client';
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```jsx
|
|
9
|
-
* import { useDecoratedSearchResults } from '@nosto/search-js/preact'
|
|
9
|
+
* import { useDecoratedSearchResults } from '@nosto/search-js/preact/hooks'
|
|
10
10
|
* import { priceDecorator } from '@nosto/search-js/currencies'
|
|
11
11
|
*
|
|
12
12
|
* export default () => {
|
|
@@ -23,5 +23,5 @@ import { SearchProduct, SearchResult } from '@nosto/nosto-js/client';
|
|
|
23
23
|
* @group Hooks
|
|
24
24
|
*/
|
|
25
25
|
export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(): DecoratedResult<T>;
|
|
26
|
-
export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(
|
|
26
|
+
export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(product: SearchProduct): DecoratedProduct<T>;
|
|
27
27
|
export declare function useDecoratedSearchResults<T extends readonly HitDecorator[]>(products: SearchResult): DecoratedResult<T>;
|
|
@@ -4,7 +4,7 @@ import { SearchTermsFacet } from '@nosto/nosto-js/client';
|
|
|
4
4
|
* @param facet
|
|
5
5
|
* @example
|
|
6
6
|
* ```jsx
|
|
7
|
-
* import { useFacet } from '@nosto/search-js/preact'
|
|
7
|
+
* import { useFacet } from '@nosto/search-js/preact/hooks'
|
|
8
8
|
*
|
|
9
9
|
* export default () => {
|
|
10
10
|
* const { active, selectedFiltersCount, toggleActive, toggleProductFilter } = useFacet(facet)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Preact hook that imports the facets to the component.
|
|
3
3
|
* @example
|
|
4
4
|
* ```jsx
|
|
5
|
-
* import { useFacets } from '@nosto/search-js/preact'
|
|
5
|
+
* import { useFacets } from '@nosto/search-js/preact/hooks'
|
|
6
6
|
* import { defaultConfig } from "../config"
|
|
7
7
|
*
|
|
8
8
|
* export default () => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Hook for loading more results by specified pageSize value
|
|
3
3
|
* @example
|
|
4
4
|
* ```jsx
|
|
5
|
-
* import { useLoadMore } from '@nosto/search-js/preact'
|
|
5
|
+
* import { useLoadMore } from '@nosto/search-js/preact/hooks'
|
|
6
6
|
*
|
|
7
7
|
* function LoadMoreButton({ pageSize }) {
|
|
8
8
|
* const { loadMore } = useLoadMore(pageSize)
|
|
@@ -4,7 +4,7 @@ import { State } from '../store';
|
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* ```jsx
|
|
7
|
-
* import { useNostoAppState } from '@nosto/search-js/preact'
|
|
7
|
+
* import { useNostoAppState } from '@nosto/search-js/preact/hooks'
|
|
8
8
|
*
|
|
9
9
|
* export default () => {
|
|
10
10
|
* const pageType = useNostoAppState(state => state.pageType)
|
|
@@ -22,7 +22,7 @@ import { State } from '../store';
|
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* ```jsx
|
|
25
|
-
* import { useNostoAppState } from '@nosto/search-js/preact'
|
|
25
|
+
* import { useNostoAppState } from '@nosto/search-js/preact/hooks'
|
|
26
26
|
*
|
|
27
27
|
* export default () => {
|
|
28
28
|
* const state = useNostoAppState()
|
|
@@ -11,7 +11,7 @@ import { PersonalizationBoost } from '@nosto/nosto-js/client';
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```jsx
|
|
14
|
-
* import { usePersonalization } from '@nosto/preact'
|
|
14
|
+
* import { usePersonalization } from '@nosto/preact/hooks'
|
|
15
15
|
*
|
|
16
16
|
* export default () => {
|
|
17
17
|
* const { segments, boost } = usePersonalization()
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param id - Id of the range Selector
|
|
4
4
|
* @example
|
|
5
5
|
* ```jsx
|
|
6
|
-
* import { useRangeCheckboxes } from "@nosto/search-js/preact"
|
|
6
|
+
* import { useRangeCheckboxes } from "@nosto/search-js/preact/hooks"
|
|
7
7
|
* import { useState } from "preact/hooks"
|
|
8
8
|
* import RadioButton from "./elements/RadioButton"
|
|
9
9
|
* import RangeInput from "./elements/RangeInput"
|
|
@@ -3,7 +3,7 @@ import { SearchKeywords, SearchProducts } from '@nosto/nosto-js/client';
|
|
|
3
3
|
* Preact hook that imports response data to the component.
|
|
4
4
|
* @example
|
|
5
5
|
* ```jsx
|
|
6
|
-
* import { useResponse } from '@nosto/search-js/preact'
|
|
6
|
+
* import { useResponse } from '@nosto/search-js/preact/hooks'
|
|
7
7
|
* import { defaultConfig } from "../config"
|
|
8
8
|
*
|
|
9
9
|
* export default () => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @returns The number of selected filters.
|
|
4
4
|
* @example
|
|
5
5
|
* ```jsx
|
|
6
|
-
* import { useSelectedFiltersCount } from '@nosto/search-js/preact'
|
|
6
|
+
* import { useSelectedFiltersCount } from '@nosto/search-js/preact/hooks'
|
|
7
7
|
* export default () => {
|
|
8
8
|
* const selectedFiltersCount = useSelectedFiltersCount()
|
|
9
9
|
* return (
|
|
@@ -11,7 +11,7 @@ export interface SortOption {
|
|
|
11
11
|
* @param sortOptions
|
|
12
12
|
* @example
|
|
13
13
|
* ```jsx
|
|
14
|
-
* import { useSort } from '@nosto/search-js/preact'
|
|
14
|
+
* import { useSort } from '@nosto/search-js/preact/hooks'
|
|
15
15
|
* import { sortOptions } from '../config'
|
|
16
16
|
*
|
|
17
17
|
* export default () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const m=require("./index.es-DlUp67LT.cjs"),a=require("./logger-BcHMZObS.cjs");async function R(t,{hitDecorators:e,...r},
|
|
1
|
+
"use strict";const m=require("./index.es-DlUp67LT.cjs"),a=require("./logger-BcHMZObS.cjs");async function R(t,{hitDecorators:e,...r},c){var o,i;const n=await c(t,r);if(!((i=(o=n.products)==null?void 0:o.hits)!=null&&i.length)||!(e!=null&&e.length))return n;const s=l=>e.reduce((f,u)=>u(f),l);return{...n,products:{...n.products,hits:n.products.hits.map(s)}}}function b(t,e,r){const c=JSON.stringify(e);try{r.setItem(t,c)}catch(n){a.logger.warn(n)}}function N(t,e){try{const r=e.getItem(t);if(r)return JSON.parse(r)}catch(r){a.logger.warn(r)}}function k(t,e){b(t,e,sessionStorage)}function C(t){return N(t,sessionStorage)}const y="nosto:search:searchResult";function O(t,e){k(y,{query:t,result:e})}function z(t){const e=C(y);if(!e||!E(e))return null;const r=w(e.query);return a.isEqual(w(t),r)?e.result:null}function w(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function E(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t}async function I(t,{usePersistentCache:e,...r},c){if(!e)return c(t,r);const n=await J(t,r,c);return O(t,n),n}async function J(t,e,r){var p,d,g,h,S;const{from:c=0,size:n=0}=t.products||{},s=z(t);if(!s)return await r(t,e);const o=((p=s==null?void 0:s.products)==null?void 0:p.hits)||[];if(n===o.length)return s;if(n<o.length)return{...s,products:{...s.products,hits:o.slice(0,n),total:((d=s.products)==null?void 0:d.total)||0}};const i=n-o.length,l=c>0?c+1:n-i,f={...t,products:{...t.products,from:l,size:i}},u=await r(f,e);return{...s,products:{...s.products,hits:[...((g=s.products)==null?void 0:g.hits)||[],...((h=u.products)==null?void 0:h.hits)||[]],total:((S=u.products)==null?void 0:S.total)||0}}}function V(t){return new Promise(e=>setTimeout(e,t))}async function T(t,{maxRetries:e=0,retryInterval:r=0,...c},n){let s=0;for(;;)try{return await n(t,c)}catch(o){if(s>=e)throw o;if(!W(o))throw a.logger.info("Skipping retry logic for",o),o;s++,await V(r)}}function W(t){return!t||typeof t!="object"?!1:!("status"in t)||_(t.status)}function _(t){return typeof t=="number"&&(t<400||t>=500)}async function j(t,e={}){const r=await new Promise(m.s);return q(r.search,T,I,R)(t,e)}function q(t,...e){return e.reduce((r,c)=>(n,s)=>c(n,s,r),t)}exports.search=j;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const y=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),M=require("./search-
|
|
1
|
+
"use strict";const y=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),M=require("./search-Diw6abza.cjs"),g=require("./unique-BCAEb4ek.cjs"),h=require("./deepMerge-lDscDfII.cjs"),v=require("./logger-BcHMZObS.cjs");function T(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:A,...t.products},...t.keywords?{keywords:{...t.keywords,fields:g.unique([...I,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const A=["productId","url","name","imageUrl","imageHash","thumbUrl","description","brand","variantId","availability","price","priceText","categoryIds","categories","customFields.key","customFields.value","priceCurrencyCode","datePublished","listPrice","unitPricingBaseMeasure","unitPricingUnit","unitPricingMeasure","googleCategory","gtin","ageGroup","gender","condition","alternateImageUrls","ratingValue","reviewCount","inventoryLevel","skus.id","skus.name","skus.price","skus.listPrice","skus.priceText","skus.url","skus.imageUrl","skus.inventoryLevel","skus.customFields.key","skus.customFields.value","skus.availability","pid","onDiscount","extra.key","extra.value","saleable","available","tags1","tags2","tags3"],I=["keyword","_redirect"];async function k(e,t,r){var d,l,S,m,C,w,b;const o=g.measure("newSearch"),c=e.config.pageType,u=c==="search"?"serp":c,a=h.deepMerge(e.store.getInitialState().query,t),s=h.deepMerge(e.config.search,r,{track:u,redirect:c!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword),usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache});(l=(d=e.config).onBeforeSearch)==null||l.call(d,e,s),e.store.updateState({query:a,loading:!0,initialized:!0});const i=e.config.queryModifications({...a,products:{...a.products,filter:g.mergeArrays((m=(S=e.store.getInitialState().query)==null?void 0:S.products)==null?void 0:m.filter,(C=t.products)==null?void 0:C.filter)}},c);try{const p=await M.search(T(e.config.pageType,i),s);e.store.updateState({response:p,loading:!1})}catch(p){v.logger.error("Search action failed",p),(b=(w=e.config).onSearchError)==null||b.call(w,p,i,s,c)}o()}async function f(e,t,r){const o=g.measure("updateSearch"),c=h.deepMerge(e.store.getState().query,{products:{from:0}},t);await k(e,c,r),o()}function P(e=Q){const t=n.useContext(y.StoreContext),[r,o]=n.useState(e(t.getState()));return t.onChange(e,o),n.useEffect(()=>()=>t.clearOnChange(o),[t]),r}const Q=e=>e;async function U(e,t,r){var a;const o=g.measure("replaceFilter"),c=(a=e.store.getState().query.products)==null?void 0:a.filter,u=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await f(e,{products:{filter:[...(c==null?void 0:c.filter(s=>s.field!==t))??[],...u]}}),o()}async function L(e,t,r,o){var i,d;const c=g.measure("toggleProductFilter"),u=(i=e.store.getState().query.products)==null?void 0:i.filter,a=u==null?void 0:u.find(l=>l.value instanceof Array&&l.field===t),s=a!=null&&a.value?{...a,value:[...a.value.filter(l=>!v.isEqual(l,r)),...o?[r]:[]]}:o?{field:t,value:[r]}:void 0;await f(e,{products:{filter:[...(u==null?void 0:u.filter(l=>l!==a))??[],...(d=s==null?void 0:s.value)!=null&&d.length?[s]:[]]}}),c()}function F(){const e=y.useConfig(),t=n.useContext(y.StoreContext),r=n.useMemo(()=>({config:e,store:t}),[e,t]),o=n.useCallback((s,i)=>k(r,s,i),[r]),c=n.useCallback((s,i)=>f(r,s,i),[r]),u=n.useCallback((s,i,d)=>L(r,s,i,d),[r]),a=n.useCallback((s,i)=>U(r,s,i),[r]);return{newSearch:o,updateSearch:c,toggleProductFilter:u,replaceFilter:a}}function q({from:e,size:t,pageSize:r}){return g.isBot()?{products:{from:e+r}}:{products:{size:t+r}}}function N(e=24){const{from:t,size:r}=P(u=>{var a,s;return{from:((a=u.query.products)==null?void 0:a.from)??0,size:((s=u.query.products)==null?void 0:s.size)??0}}),{updateSearch:o}=F();return{loadMore:n.useCallback(async()=>{await o(q({from:t,size:r,pageSize:e}))},[t,r,e,o])}}exports.getNextPageQuery=q;exports.newSearch=k;exports.updateSearch=f;exports.useActions=F;exports.useLoadMore=N;exports.useNostoAppState=P;
|
package/dist/utils/utils.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../deepMerge-lDscDfII.cjs"),c=require("../unique-BCAEb4ek.cjs"),t=require("../logger-BcHMZObS.cjs"),n=require("../parseNumber-FsZ8w61u.cjs"),q=require("../pick-rYi1lc2m.cjs");function k(i){i.setAttribute("autocomplete","off")}function m(i,{onClick:a,onFocus:f,onInput:d,onKeyDown:u,onSubmit:s},{form:p=i.form??void 0}={}){const o=[];function r(e,l,v){e.addEventListener(l,v),o.push(()=>e.removeEventListener(l,v))}return(u||s)&&r(i,"keydown",e=>{u==null||u(i.value,e.key),(u&&(e.key==="ArrowDown"||e.key==="ArrowUp")||s&&e.key==="Enter")&&e.preventDefault()}),s&&p&&(r(p,"submit",e=>{e.preventDefault(),s(i.value)}),p.querySelectorAll("[type=submit]").forEach(e=>{r(e,"click",l=>{l.preventDefault(),s(i.value)})})),a&&r(i,"click",()=>a(i.value)),f&&r(i,"focus",()=>f(i.value)),d&&r(i,"input",()=>d(i.value)),{destroy(){o.forEach(e=>e())}}}exports.deepMerge=b.deepMerge;exports.isBot=c.isBot;exports.measure=c.measure;exports.mergeArrays=c.mergeArrays;exports.unique=c.unique;exports.isEqual=t.isEqual;exports.isPlainObject=t.isPlainObject;exports.logger=t.logger;exports.parseNumber=n.parseNumber;exports.pick=q.pick;exports.bindInput=m;exports.disableNativeAutocomplete=k;
|
package/dist/utils/utils.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as
|
|
1
|
+
import { d as E } from "../deepMerge-CZwCJzEe.js";
|
|
2
2
|
import { i as A, a as b, m as q, u as y } from "../unique-CyAMhegX.js";
|
|
3
3
|
import { i as h, a as N, l as j } from "../logger-DVwg4Wor.js";
|
|
4
4
|
import { p as M } from "../parseNumber-QA48nJLp.js";
|
|
@@ -6,18 +6,18 @@ import { p as P } from "../pick-DReBictn.js";
|
|
|
6
6
|
function d(s) {
|
|
7
7
|
s.setAttribute("autocomplete", "off");
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function v(s, { onClick: l, onFocus: p, onInput: c, onKeyDown: i, onSubmit: u }, { form: a = s.form ?? void 0 } = {}) {
|
|
10
10
|
const o = [];
|
|
11
|
-
function r(e, f,
|
|
12
|
-
e.addEventListener(f,
|
|
11
|
+
function r(e, f, t) {
|
|
12
|
+
e.addEventListener(f, t), o.push(() => e.removeEventListener(f, t));
|
|
13
13
|
}
|
|
14
|
-
return (
|
|
15
|
-
|
|
16
|
-
}),
|
|
17
|
-
e.preventDefault(),
|
|
14
|
+
return (i || u) && r(s, "keydown", (e) => {
|
|
15
|
+
i == null || i(s.value, e.key), (i && (e.key === "ArrowDown" || e.key === "ArrowUp") || u && e.key === "Enter") && e.preventDefault();
|
|
16
|
+
}), u && a && (r(a, "submit", (e) => {
|
|
17
|
+
e.preventDefault(), u(s.value);
|
|
18
18
|
}), a.querySelectorAll("[type=submit]").forEach((e) => {
|
|
19
19
|
r(e, "click", (f) => {
|
|
20
|
-
f.preventDefault(),
|
|
20
|
+
f.preventDefault(), u(s.value);
|
|
21
21
|
});
|
|
22
22
|
})), l && r(s, "click", () => l(s.value)), p && r(s, "focus", () => p(s.value)), c && r(s, "input", () => c(s.value)), {
|
|
23
23
|
destroy() {
|
|
@@ -26,8 +26,8 @@ function m(s, { onClick: l, onFocus: p, onInput: c, onKeyDown: u, onSubmit: i },
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
v as bindInput,
|
|
30
|
+
E as deepMerge,
|
|
31
31
|
d as disableNativeAutocomplete,
|
|
32
32
|
A as isBot,
|
|
33
33
|
h as isEqual,
|