@nosto/search-js 1.7.6 → 1.8.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("../utils/utils.cjs.js"),s=require("../InfiniteScrollWithObserver-DbErxedF.cjs"),x=require("preact"),F=require("../index.es-DlUp67LT.cjs"),m=require("preact/hooks");function z({pageSize:e}){const{loadMore:n}=s.useLoadMore(e);return s.u("button",{onClick:n,children:"More results"})}function R({children:e,loadMoreComponent:n,pageSize:t}){const{loading:o,query:r,response:a}=s.useNostoAppState(l=>s.pick(l,"loading","query","response")),i=!o&&s.hasMoreResults(r,a);return s.u(x.Fragment,{children:[e,i&&(n?s.u(n,{pageSize:t}):s.u(z,{pageSize:t}))]})}const T=!I.isBot()&&s.intersectionObserverSupported()?s.InfiniteScrollWithObserver:R;function E(e){return e.type==="input"}function L(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function N(e,n={depth:0}){const{children:t}=e;return x.toChildArray(t).map(o=>{if(!L(o))return o;const r=e.updateElement(o,n);return r===null?null:(r.props={...r.props,children:N({...e,children:r.props.children},{depth:n.depth+1})},r)})}function B({children:e,onSearchInput:n}){return N({children:e,updateElement:t=>(!E(t)||t.props.type!=="search"||(t.props={...t.props,onInput:o=>{o.target instanceof HTMLInputElement&&n(o.target)}}),t)})}const O="nosto:search:scrollPos";function j(){window.sessionStorage.setItem(O,window.scrollY.toString())}function D({children:e,hit:n,onClick:t}){const{pageType:o}=s.useConfig(),r=o==="autocomplete"?void 0:o;return N({children:e,updateElement:(a,i)=>(i.depth>0||(a.props={...a.props,onClick:l=>{n&&r&&F.s(p=>p.recordSearchClick(r,n)),j(),typeof t=="function"&&t(l)}}),a)})}function b(){m.useEffect(()=>{const e=window.setTimeout(()=>{console.error("Nosto client script has not loaded after 3 seconds.")},3e3);F.s(()=>{window.clearTimeout(e)})},[])}const k={defaultCurrency:"EUR",queryModifications:e=>e},V={...k};function W(e){return{pageType:"autocomplete",...V,...e}}function H({config:e,store:n,children:t}){const o=n??s.createStore();return b(),s.u(s.ConfigContext,{value:W(e),children:s.u(s.StoreContext,{value:o,children:t})})}const U={...k,persistentSearchCache:!1,preservePageScroll:!1};function _(e){return{pageType:"category",...U,...e}}function $({config:e,store:n,children:t}){const o=n??s.createStore();return b(),s.u(s.ConfigContext,{value:_(e),children:s.u(s.StoreContext,{value:o,children:t})})}const K={...k,persistentSearchCache:!1,preservePageScroll:!1};function Y(e={}){return{pageType:"serp",...K,...e}}function G({config:e,store:n,children:t}){const o=n??s.createStore();return b(),s.u(s.ConfigContext,{value:Y(e),children:s.u(s.StoreContext,{value:o,children:t})})}function J(e){const n=s.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&s.isPlainObject(e)?e:n}function Q(e){var i;const n=((i=e.data)==null?void 0:i.filter(l=>l.selected).length)??0,[t,o]=m.useState(n>0),{toggleProductFilter:r}=s.useActions();return{active:t,selectedFiltersCount:n,toggleActive:()=>{o(!t)},toggleProductFilter:r}}function X(){const{loading:e,facets:n}=s.useNostoAppState(t=>{var o,r;return{loading:t.loading,facets:((r=(o=t.response)==null?void 0:o.products)==null?void 0:r.facets)??[]}});return{loading:e,facets:n}}function Z(e,n){const t=n-e;return!isNaN(t)&&t>0?new Array(n-e).fill(void 0).map((o,r)=>r+e):[]}function ee(e){const{query:n,products:t}=s.useNostoAppState(o=>({query:o.query,products:o.response.products}));return m.useMemo(()=>{var A;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=((A=n.products)==null?void 0:A.from)??0,r=(e==null?void 0:e.width)??1/0,a=Math.max(Math.floor(r-1)/2,1),i=t.size>0?Math.floor(o/t.size)+1:1,l=t.size>0?Math.ceil(t.total/t.size):0,p=y=>y>=i-a&&y<=i+a,u=o+1,d=Math.min(o+t.total,t.total),c={from:o,page:i,current:!0},S=y=>({from:(y-1)*t.size,page:y,current:y===i}),h=i>1?S(i-1):void 0,f=i<l?S(i+1):void 0,C=a===1/0||i-a-1>1?S(1):void 0,g=a===1/0||i+a+1<l?S(l):void 0,v=Z(1,l+1).filter(p).map(S);return{totalPages:l,resultsFrom:u,resultsTo:d,current:c,prev:h,next:f,first:C,last:g,pages:v}},[n,t,e==null?void 0:e.width])}function te(){const[e,n]=m.useState([]),[t,o]=m.useState([]);return m.useEffect(()=>{F.s(async r=>{const{products:a,segments:i}=await r.getSearchSessionParams();n(i??[]),o((a==null?void 0:a.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function ne(){const{facets:e}=s.useNostoAppState(u=>{var d;return{facets:((d=u.response.products)==null?void 0:d.facets)??[]}}),{replaceFilter:n,toggleProductFilter:t}=s.useActions(),o=m.useCallback(u=>{const d=e==null?void 0:e.find(c=>c.type==="stats"&&c.field===u);if(d&&"min"in d&&"max"in d)return d},[e]),r=m.useCallback(u=>{var d;return((d=e==null?void 0:e.find(c=>c.field===u))==null?void 0:d.name)??u},[e]),a=m.useCallback(u=>"field"in u&&(u.value instanceof Array||u.range instanceof Array),[]),i=m.useCallback(u=>{var d;return{...u,range:(d=u.range)==null?void 0:d.map(c=>({gt:c.gt?Number(c.gt):c.gt,gte:c.gte?Number(c.gte):c.gte,lt:c.lt?Number(c.lt):c.lt,lte:c.lte?Number(c.lte):c.lte}))}},[]),l=m.useCallback(u=>(u.value??[]).map(c=>({value:c,field:u.field,name:r(u.field),filter:i(u),remove:()=>{t(u.field,c,!1)}})),[i,r,t]),p=m.useCallback(u=>(u.range??[]).map(c=>{var f,C;const S=c.gte??c.gt??((f=o(u.field))==null?void 0:f.min),h=c.lte??c.lt??((C=o(u.field))==null?void 0:C.max);if(S!==void 0&&h!==void 0)return{value:`${S} - ${h}`,field:u.field,name:r(u.field),filter:i(u),remove:()=>{n(u.field,void 0)}}}).filter(Boolean),[i,o,r,n]);return{selectFilters:a,toValueFilter:l,toRangeFilter:p}}function q(){const{filter:e}=s.useNostoAppState(l=>{var p;return{filter:((p=l.query.products)==null?void 0:p.filter)??[]}}),{updateSearch:n}=s.useActions(),{selectFilters:t,toValueFilter:o,toRangeFilter:r}=ne(),a=m.useMemo(()=>e?e.filter(t).flatMap(l=>"value"in l?o(l):"range"in l?r(l):[]).filter(Boolean):[],[e,t,r,o]),i=m.useCallback(()=>{n({products:{filter:[]}})},[n]);return{filters:a,removeAll:i}}function P(e){if(typeof e=="number")return e;if(typeof e!="string")return;const n=Number(e);return isNaN(n)?void 0:n}function w(e){var c,S,h;const{replaceFilter:n}=s.useActions(),{query:t,products:o}=s.useNostoAppState(f=>({query:f.query,products:f.response.products})),r=(c=o==null?void 0:o.facets)==null?void 0:c.find(f=>f.id===e);if(!r)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const a=(h=(S=t.products)==null?void 0:S.filter)==null?void 0:h.find(f=>f.field===r.field),i=a!=null&&a.range?a.range[0]:void 0,l=typeof i=="object"&&("gte"in i||"lte"in i)?[P(i.gte),P(i.lte)]:[void 0,void 0],p="min"in r?Math.floor(r.min):0,u="max"in r?Math.ceil(r.max):0,d=([f,C])=>{const g=f!==void 0?Math.floor(f):void 0,v=C!==void 0?Math.ceil(C):void 0,A=g!==void 0,y=v!==void 0;(p===g||!A)&&(u===v||!y)?n(r.field,void 0):(p===g||!A)&&y?n(r.field,{lte:v.toString()}):(u===v||!y)&&A?n(r.field,{gte:g.toString()}):A&&y&&n(r.field,{gte:g.toString(),lte:v.toString()})};return{min:p,max:u,range:[l[0]??p,l[1]??u],updateRange:d}}function oe(e,n){const{min:t,max:o,range:r,updateRange:a}=w(e),{filters:i}=q(),l=m.useMemo(()=>{var C;const c=i.find(g=>{var v;return(v=g==null?void 0:g.filter)==null?void 0:v.range});let S=null;if(c){const g=(C=c.filter.range)==null?void 0:C[0];S=[P(g==null?void 0:g.gte),P(g==null?void 0:g.lte)]}const h=[];let f=Math.floor(t/n)*n;for(;f<o;){const g=f+n,v=S&&S[0]===f&&S[1]===g;h.push({min:f,max:g,selected:v}),f=g}return h},[i,t,o,n]),p=c=>{a([c,r[1]])},u=c=>{a([r[0],c])},d=t!==r[0]||o!==r[1];return{min:t,max:o,range:r,updateRange:a,ranges:l,handleMinChange:p,handleMaxChange:u,isSelected:d}}function re(){const{products:e,keywords:n}=s.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:n??{hits:[],total:0}}}function se(){const e=s.useNostoAppState(t=>{var o;return(o=t.query.products)==null?void 0:o.filter});return m.useMemo(()=>e?e.reduce((t,o)=>t+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}function M(e){return e&&!Number.isNaN(e)?e:0}function ue(e,n){const{from:t,size:o,total:r}=s.useNostoAppState(u=>{var d,c,S,h,f;return{from:M(((d=u.query.products)==null?void 0:d.from)??0),size:M(((S=(c=u.response)==null?void 0:c.products)==null?void 0:S.size)??0),total:M(((f=(h=u.response)==null?void 0:h.products)==null?void 0:f.total)??0)}}),{updateSearch:a}=s.useActions(),i=t+o,l=[...e].reverse().filter(u=>u+n<r);return{from:t,to:i,total:r,size:o,sizeOptions:l,handleSizeChange:u=>{a({products:{size:u}})}}}function ie(e,n){return e.length!==n.length?!1:e.every(t=>n.find(o=>t.field===o.field&&t.order===o.order))}function ce(e){var a,i;const n=s.useNostoAppState(l=>l.query),{updateSearch:t}=s.useActions();return{activeSort:((a=e.find(l=>{var p;return ie(l.value.sort,((p=n.products)==null?void 0:p.sort)||[])}))==null?void 0:a.id)??((i=e[0])==null?void 0:i.id),setSort:l=>{const p=e.find(u=>u.id===l);p&&t({products:{sort:p.value.sort}})}}}exports.StoreContext=s.StoreContext;exports.createExtendableStore=s.createExtendableStore;exports.createStore=s.createStore;exports.defaultState=s.defaultState;exports.useActions=s.useActions;exports.useLoadMore=s.useLoadMore;exports.useNostoAppState=s.useNostoAppState;exports.AutocompletePageProvider=H;exports.CategoryPageProvider=$;exports.InfiniteScroll=T;exports.InfiniteScrollWithLink=R;exports.SearchInput=B;exports.SearchPageProvider=G;exports.SerpElement=D;exports.useDecoratedSearchResults=J;exports.useFacet=Q;exports.useFacets=X;exports.usePagination=ee;exports.usePersonalization=te;exports.useProductFilters=q;exports.useRange=w;exports.useRangeSelector=oe;exports.useResponse=re;exports.useSelectedFiltersCount=se;exports.useSizeOptions=ue;exports.useSort=ce;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../index.es-DlUp67LT.cjs"),N=require("preact"),E=require("../utils/utils.cjs.js"),s=require("../InfiniteScrollWithObserver-DbErxedF.cjs"),S=require("preact/hooks");function I(e){return e!==null&&typeof e=="object"&&"props"in e&&typeof e.type=="string"}function T({children:e,hit:n}){var o;if(!I(e))throw new Error("AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported.");const t=(o=e.props)==null?void 0:o.onClick;return N.cloneElement(e,{onClick:r=>{n&&M.s(a=>a.recordSearchClick("autocomplete",n)),typeof t=="function"&&t(r)}})}function z({pageSize:e}){const{loadMore:n}=s.useLoadMore(e);return s.u("button",{onClick:n,children:"More results"})}function w({children:e,loadMoreComponent:n,pageSize:t}){const{loading:o,query:r,response:a}=s.useNostoAppState(l=>s.pick(l,"loading","query","response")),i=!o&&s.hasMoreResults(r,a);return s.u(N.Fragment,{children:[e,i&&(n?s.u(n,{pageSize:t}):s.u(z,{pageSize:t}))]})}const L=!E.isBot()&&s.intersectionObserverSupported()?s.InfiniteScrollWithObserver:w;function O(e){return e.type==="input"}function B(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function b(e,n={depth:0}){const{children:t}=e;return N.toChildArray(t).map(o=>{if(!B(o))return o;const r=e.updateElement(o,n);return r===null?null:(r.props={...r.props,children:b({...e,children:r.props.children},{depth:n.depth+1})},r)})}function j({children:e,onSearchInput:n}){return b({children:e,updateElement:t=>(!O(t)||t.props.type!=="search"||(t.props={...t.props,onInput:o=>{o.target instanceof HTMLInputElement&&n(o.target)}}),t)})}const H="nosto:search:scrollPos";function V(){window.sessionStorage.setItem(H,window.scrollY.toString())}function D({children:e,hit:n,onClick:t}){const{pageType:o}=s.useConfig(),r=o==="autocomplete"?void 0:o;return b({children:e,updateElement:(a,i)=>(i.depth>0||(a.props={...a.props,onClick:l=>{n&&r&&M.s(p=>p.recordSearchClick(r,n)),V(),typeof t=="function"&&t(l)}}),a)})}function k(){S.useEffect(()=>{const e=window.setTimeout(()=>{console.error("Nosto client script has not loaded after 3 seconds.")},3e3);M.s(()=>{window.clearTimeout(e)})},[])}const x={defaultCurrency:"EUR",queryModifications:e=>e},W={...x};function U(e){return{pageType:"autocomplete",...W,...e}}function _({config:e,store:n,children:t}){const o=n??s.createStore();return k(),s.u(s.ConfigContext,{value:U(e),children:s.u(s.StoreContext,{value:o,children:t})})}const $={...x,persistentSearchCache:!1,preservePageScroll:!1};function K(e){return{pageType:"category",...$,...e}}function Y({config:e,store:n,children:t}){const o=n??s.createStore();return k(),s.u(s.ConfigContext,{value:K(e),children:s.u(s.StoreContext,{value:o,children:t})})}const G={...x,persistentSearchCache:!1,preservePageScroll:!1};function J(e={}){return{pageType:"serp",...G,...e}}function Q({config:e,store:n,children:t}){const o=n??s.createStore();return k(),s.u(s.ConfigContext,{value:J(e),children:s.u(s.StoreContext,{value:o,children:t})})}function X(e){const n=s.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&s.isPlainObject(e)?e:n}function Z(e){var i;const n=((i=e.data)==null?void 0:i.filter(l=>l.selected).length)??0,[t,o]=S.useState(n>0),{toggleProductFilter:r}=s.useActions();return{active:t,selectedFiltersCount:n,toggleActive:()=>{o(!t)},toggleProductFilter:r}}function ee(){const{loading:e,facets:n}=s.useNostoAppState(t=>{var o,r;return{loading:t.loading,facets:((r=(o=t.response)==null?void 0:o.products)==null?void 0:r.facets)??[]}});return{loading:e,facets:n}}function te(e,n){const t=n-e;return!isNaN(t)&&t>0?new Array(n-e).fill(void 0).map((o,r)=>r+e):[]}function ne(e){const{query:n,products:t}=s.useNostoAppState(o=>({query:o.query,products:o.response.products}));return S.useMemo(()=>{var A;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=((A=n.products)==null?void 0:A.from)??0,r=(e==null?void 0:e.width)??1/0,a=Math.max(Math.floor(r-1)/2,1),i=t.size>0?Math.floor(o/t.size)+1:1,l=t.size>0?Math.ceil(t.total/t.size):0,p=y=>y>=i-a&&y<=i+a,u=o+1,d=Math.min(o+t.total,t.total),c={from:o,page:i,current:!0},m=y=>({from:(y-1)*t.size,page:y,current:y===i}),h=i>1?m(i-1):void 0,f=i<l?m(i+1):void 0,C=a===1/0||i-a-1>1?m(1):void 0,g=a===1/0||i+a+1<l?m(l):void 0,v=te(1,l+1).filter(p).map(m);return{totalPages:l,resultsFrom:u,resultsTo:d,current:c,prev:h,next:f,first:C,last:g,pages:v}},[n,t,e==null?void 0:e.width])}function oe(){const[e,n]=S.useState([]),[t,o]=S.useState([]);return S.useEffect(()=>{M.s(async r=>{const{products:a,segments:i}=await r.getSearchSessionParams();n(i??[]),o((a==null?void 0:a.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function re(){const{facets:e}=s.useNostoAppState(u=>{var d;return{facets:((d=u.response.products)==null?void 0:d.facets)??[]}}),{replaceFilter:n,toggleProductFilter:t}=s.useActions(),o=S.useCallback(u=>{const d=e==null?void 0:e.find(c=>c.type==="stats"&&c.field===u);if(d&&"min"in d&&"max"in d)return d},[e]),r=S.useCallback(u=>{var d;return((d=e==null?void 0:e.find(c=>c.field===u))==null?void 0:d.name)??u},[e]),a=S.useCallback(u=>"field"in u&&(u.value instanceof Array||u.range instanceof Array),[]),i=S.useCallback(u=>{var d;return{...u,range:(d=u.range)==null?void 0:d.map(c=>({gt:c.gt?Number(c.gt):c.gt,gte:c.gte?Number(c.gte):c.gte,lt:c.lt?Number(c.lt):c.lt,lte:c.lte?Number(c.lte):c.lte}))}},[]),l=S.useCallback(u=>(u.value??[]).map(c=>({value:c,field:u.field,name:r(u.field),filter:i(u),remove:()=>{t(u.field,c,!1)}})),[i,r,t]),p=S.useCallback(u=>(u.range??[]).map(c=>{var f,C;const m=c.gte??c.gt??((f=o(u.field))==null?void 0:f.min),h=c.lte??c.lt??((C=o(u.field))==null?void 0:C.max);if(m!==void 0&&h!==void 0)return{value:`${m} - ${h}`,field:u.field,name:r(u.field),filter:i(u),remove:()=>{n(u.field,void 0)}}}).filter(Boolean),[i,o,r,n]);return{selectFilters:a,toValueFilter:l,toRangeFilter:p}}function R(){const{filter:e}=s.useNostoAppState(l=>{var p;return{filter:((p=l.query.products)==null?void 0:p.filter)??[]}}),{updateSearch:n}=s.useActions(),{selectFilters:t,toValueFilter:o,toRangeFilter:r}=re(),a=S.useMemo(()=>e?e.filter(t).flatMap(l=>"value"in l?o(l):"range"in l?r(l):[]).filter(Boolean):[],[e,t,r,o]),i=S.useCallback(()=>{n({products:{filter:[]}})},[n]);return{filters:a,removeAll:i}}function P(e){if(typeof e=="number")return e;if(typeof e!="string")return;const n=Number(e);return isNaN(n)?void 0:n}function q(e){var c,m,h;const{replaceFilter:n}=s.useActions(),{query:t,products:o}=s.useNostoAppState(f=>({query:f.query,products:f.response.products})),r=(c=o==null?void 0:o.facets)==null?void 0:c.find(f=>f.id===e);if(!r)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const a=(h=(m=t.products)==null?void 0:m.filter)==null?void 0:h.find(f=>f.field===r.field),i=a!=null&&a.range?a.range[0]:void 0,l=typeof i=="object"&&("gte"in i||"lte"in i)?[P(i.gte),P(i.lte)]:[void 0,void 0],p="min"in r?Math.floor(r.min):0,u="max"in r?Math.ceil(r.max):0,d=([f,C])=>{const g=f!==void 0?Math.floor(f):void 0,v=C!==void 0?Math.ceil(C):void 0,A=g!==void 0,y=v!==void 0;(p===g||!A)&&(u===v||!y)?n(r.field,void 0):(p===g||!A)&&y?n(r.field,{lte:v.toString()}):(u===v||!y)&&A?n(r.field,{gte:g.toString()}):A&&y&&n(r.field,{gte:g.toString(),lte:v.toString()})};return{min:p,max:u,range:[l[0]??p,l[1]??u],updateRange:d}}function se(e,n){const{min:t,max:o,range:r,updateRange:a}=q(e),{filters:i}=R(),l=S.useMemo(()=>{var C;const c=i.find(g=>{var v;return(v=g==null?void 0:g.filter)==null?void 0:v.range});let m=null;if(c){const g=(C=c.filter.range)==null?void 0:C[0];m=[P(g==null?void 0:g.gte),P(g==null?void 0:g.lte)]}const h=[];let f=Math.floor(t/n)*n;for(;f<o;){const g=f+n,v=m&&m[0]===f&&m[1]===g;h.push({min:f,max:g,selected:v}),f=g}return h},[i,t,o,n]),p=c=>{a([c,r[1]])},u=c=>{a([r[0],c])},d=t!==r[0]||o!==r[1];return{min:t,max:o,range:r,updateRange:a,ranges:l,handleMinChange:p,handleMaxChange:u,isSelected:d}}function ue(){const{products:e,keywords:n}=s.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:n??{hits:[],total:0}}}function ie(){const e=s.useNostoAppState(t=>{var o;return(o=t.query.products)==null?void 0:o.filter});return S.useMemo(()=>e?e.reduce((t,o)=>t+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}function F(e){return e&&!Number.isNaN(e)?e:0}function ce(e,n){const{from:t,size:o,total:r}=s.useNostoAppState(u=>{var d,c,m,h,f;return{from:F(((d=u.query.products)==null?void 0:d.from)??0),size:F(((m=(c=u.response)==null?void 0:c.products)==null?void 0:m.size)??0),total:F(((f=(h=u.response)==null?void 0:h.products)==null?void 0:f.total)??0)}}),{updateSearch:a}=s.useActions(),i=t+o,l=[...e].reverse().filter(u=>u+n<r);return{from:t,to:i,total:r,size:o,sizeOptions:l,handleSizeChange:u=>{a({products:{size:u}})}}}function ae(e,n){return e.length!==n.length?!1:e.every(t=>n.find(o=>t.field===o.field&&t.order===o.order))}function le(e){var a,i;const n=s.useNostoAppState(l=>l.query),{updateSearch:t}=s.useActions();return{activeSort:((a=e.find(l=>{var p;return ae(l.value.sort,((p=n.products)==null?void 0:p.sort)||[])}))==null?void 0:a.id)??((i=e[0])==null?void 0:i.id),setSort:l=>{const p=e.find(u=>u.id===l);p&&t({products:{sort:p.value.sort}})}}}exports.StoreContext=s.StoreContext;exports.createExtendableStore=s.createExtendableStore;exports.createStore=s.createStore;exports.defaultState=s.defaultState;exports.useActions=s.useActions;exports.useLoadMore=s.useLoadMore;exports.useNostoAppState=s.useNostoAppState;exports.AutocompleteElement=T;exports.AutocompletePageProvider=_;exports.CategoryPageProvider=Y;exports.InfiniteScroll=L;exports.InfiniteScrollWithLink=w;exports.SearchInput=j;exports.SearchPageProvider=Q;exports.SerpElement=D;exports.useDecoratedSearchResults=X;exports.useFacet=Z;exports.useFacets=ee;exports.usePagination=ne;exports.usePersonalization=oe;exports.useProductFilters=R;exports.useRange=q;exports.useRangeSelector=se;exports.useResponse=ue;exports.useSelectedFiltersCount=ie;exports.useSizeOptions=ce;exports.useSort=le;
|
package/dist/preact/preact.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @module preact */
|
|
2
|
+
export { AutocompleteElement } from './src/components/Autocomplete/AutocompleteElement';
|
|
2
3
|
export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
|
|
3
4
|
export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
|
|
4
5
|
export { SearchInput } from './src/components/SearchInput';
|
package/dist/preact/preact.es.js
CHANGED
|
@@ -1,43 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { useEffect as
|
|
7
|
-
function
|
|
8
|
-
|
|
1
|
+
import { s as b } from "../index.es-B8mbAxS4.js";
|
|
2
|
+
import { cloneElement as L, Fragment as B, toChildArray as j } from "preact";
|
|
3
|
+
import { isBot as H } from "../utils/utils.es.js";
|
|
4
|
+
import { u as V, a as C, b as v, h as O, p as D, i as U, I as W, c as $, d as x, S as R, C as T, e as K, f as P } from "../InfiniteScrollWithObserver-kuSGeBWr.js";
|
|
5
|
+
import { k as Ie, j as Le } from "../InfiniteScrollWithObserver-kuSGeBWr.js";
|
|
6
|
+
import { useEffect as I, useState as N, useMemo as A, useCallback as F } from "preact/hooks";
|
|
7
|
+
function Y(e) {
|
|
8
|
+
return e !== null && typeof e == "object" && "props" in e && typeof e.type == "string";
|
|
9
|
+
}
|
|
10
|
+
function he({ children: e, hit: n }) {
|
|
11
|
+
var r;
|
|
12
|
+
if (!Y(e))
|
|
13
|
+
throw new Error(
|
|
14
|
+
"AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
|
|
15
|
+
);
|
|
16
|
+
const t = (r = e.props) == null ? void 0 : r.onClick;
|
|
17
|
+
return L(e, {
|
|
18
|
+
onClick: (o) => {
|
|
19
|
+
n && b((a) => a.recordSearchClick("autocomplete", n)), typeof t == "function" && t(o);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function _({ pageSize: e }) {
|
|
24
|
+
const { loadMore: n } = V(e);
|
|
9
25
|
return /* @__PURE__ */ C("button", { onClick: n, children: "More results" });
|
|
10
26
|
}
|
|
11
|
-
function
|
|
12
|
-
const { loading: r, query: o, response: a } = v((u) =>
|
|
13
|
-
return /* @__PURE__ */ C(
|
|
27
|
+
function G({ children: e, loadMoreComponent: n, pageSize: t }) {
|
|
28
|
+
const { loading: r, query: o, response: a } = v((u) => D(u, "loading", "query", "response")), i = !r && O(o, a);
|
|
29
|
+
return /* @__PURE__ */ C(B, { children: [
|
|
14
30
|
e,
|
|
15
|
-
i && (n ? /* @__PURE__ */ C(n, { pageSize: t }) : /* @__PURE__ */ C(
|
|
31
|
+
i && (n ? /* @__PURE__ */ C(n, { pageSize: t }) : /* @__PURE__ */ C(_, { pageSize: t }))
|
|
16
32
|
] });
|
|
17
33
|
}
|
|
18
|
-
const
|
|
19
|
-
function
|
|
34
|
+
const ye = !H() && U() ? W : G;
|
|
35
|
+
function J(e) {
|
|
20
36
|
return e.type === "input";
|
|
21
37
|
}
|
|
22
|
-
function
|
|
38
|
+
function Q(e) {
|
|
23
39
|
return !!e && typeof e == "object" && "type" in e && "props" in e;
|
|
24
40
|
}
|
|
25
|
-
function
|
|
41
|
+
function q(e, n = { depth: 0 }) {
|
|
26
42
|
const { children: t } = e;
|
|
27
|
-
return
|
|
28
|
-
if (!
|
|
43
|
+
return j(t).map((r) => {
|
|
44
|
+
if (!Q(r))
|
|
29
45
|
return r;
|
|
30
46
|
const o = e.updateElement(r, n);
|
|
31
47
|
return o === null ? null : (o.props = {
|
|
32
48
|
...o.props,
|
|
33
|
-
children:
|
|
49
|
+
children: q({ ...e, children: o.props.children }, { depth: n.depth + 1 })
|
|
34
50
|
}, o);
|
|
35
51
|
});
|
|
36
52
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
53
|
+
function ve({ children: e, onSearchInput: n }) {
|
|
54
|
+
return q({
|
|
39
55
|
children: e,
|
|
40
|
-
updateElement: (t) => (!
|
|
56
|
+
updateElement: (t) => (!J(t) || t.props.type !== "search" || (t.props = {
|
|
41
57
|
...t.props,
|
|
42
58
|
onInput: (r) => {
|
|
43
59
|
r.target instanceof HTMLInputElement && n(r.target);
|
|
@@ -45,86 +61,86 @@ function me({ children: e, onSearchInput: n }) {
|
|
|
45
61
|
}), t)
|
|
46
62
|
});
|
|
47
63
|
}
|
|
48
|
-
const
|
|
49
|
-
function
|
|
50
|
-
window.sessionStorage.setItem(
|
|
64
|
+
const X = "nosto:search:scrollPos";
|
|
65
|
+
function Z() {
|
|
66
|
+
window.sessionStorage.setItem(X, window.scrollY.toString());
|
|
51
67
|
}
|
|
52
|
-
function
|
|
53
|
-
const { pageType: r } =
|
|
54
|
-
return
|
|
68
|
+
function Se({ children: e, hit: n, onClick: t }) {
|
|
69
|
+
const { pageType: r } = $(), o = r === "autocomplete" ? void 0 : r;
|
|
70
|
+
return q({
|
|
55
71
|
children: e,
|
|
56
72
|
updateElement: (a, i) => (i.depth > 0 || (a.props = {
|
|
57
73
|
...a.props,
|
|
58
74
|
onClick: (u) => {
|
|
59
|
-
n && o &&
|
|
75
|
+
n && o && b((d) => d.recordSearchClick(o, n)), Z(), typeof t == "function" && t(u);
|
|
60
76
|
}
|
|
61
77
|
}), a)
|
|
62
78
|
});
|
|
63
79
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
80
|
+
function E() {
|
|
81
|
+
I(() => {
|
|
66
82
|
const e = window.setTimeout(() => {
|
|
67
83
|
console.error("Nosto client script has not loaded after 3 seconds.");
|
|
68
84
|
}, 3e3);
|
|
69
|
-
|
|
85
|
+
b(() => {
|
|
70
86
|
window.clearTimeout(e);
|
|
71
87
|
});
|
|
72
88
|
}, []);
|
|
73
89
|
}
|
|
74
|
-
const
|
|
90
|
+
const z = {
|
|
75
91
|
defaultCurrency: "EUR",
|
|
76
92
|
queryModifications: (e) => e
|
|
77
|
-
},
|
|
78
|
-
...
|
|
93
|
+
}, ee = {
|
|
94
|
+
...z
|
|
79
95
|
};
|
|
80
|
-
function
|
|
96
|
+
function te(e) {
|
|
81
97
|
return {
|
|
82
98
|
pageType: "autocomplete",
|
|
83
|
-
...
|
|
99
|
+
...ee,
|
|
84
100
|
...e
|
|
85
101
|
};
|
|
86
102
|
}
|
|
87
|
-
function
|
|
88
|
-
const r = n ??
|
|
89
|
-
return
|
|
103
|
+
function Ce({ config: e, store: n, children: t }) {
|
|
104
|
+
const r = n ?? x();
|
|
105
|
+
return E(), /* @__PURE__ */ C(T, { value: te(e), children: /* @__PURE__ */ C(R, { value: r, children: t }) });
|
|
90
106
|
}
|
|
91
|
-
const
|
|
92
|
-
...
|
|
107
|
+
const ne = {
|
|
108
|
+
...z,
|
|
93
109
|
persistentSearchCache: !1,
|
|
94
110
|
preservePageScroll: !1
|
|
95
111
|
};
|
|
96
|
-
function
|
|
112
|
+
function re(e) {
|
|
97
113
|
return {
|
|
98
114
|
pageType: "category",
|
|
99
|
-
...
|
|
115
|
+
...ne,
|
|
100
116
|
...e
|
|
101
117
|
};
|
|
102
118
|
}
|
|
103
|
-
function
|
|
104
|
-
const r = n ??
|
|
105
|
-
return
|
|
119
|
+
function Me({ config: e, store: n, children: t }) {
|
|
120
|
+
const r = n ?? x();
|
|
121
|
+
return E(), /* @__PURE__ */ C(T, { value: re(e), children: /* @__PURE__ */ C(R, { value: r, children: t }) });
|
|
106
122
|
}
|
|
107
|
-
const
|
|
108
|
-
...
|
|
123
|
+
const oe = {
|
|
124
|
+
...z,
|
|
109
125
|
persistentSearchCache: !1,
|
|
110
126
|
preservePageScroll: !1
|
|
111
127
|
};
|
|
112
|
-
function
|
|
128
|
+
function se(e = {}) {
|
|
113
129
|
return {
|
|
114
130
|
pageType: "serp",
|
|
115
|
-
...
|
|
131
|
+
...oe,
|
|
116
132
|
...e
|
|
117
133
|
};
|
|
118
134
|
}
|
|
119
|
-
function
|
|
120
|
-
const r = n ??
|
|
121
|
-
return
|
|
135
|
+
function Fe({ config: e, store: n, children: t }) {
|
|
136
|
+
const r = n ?? x();
|
|
137
|
+
return E(), /* @__PURE__ */ C(T, { value: se(e), children: /* @__PURE__ */ C(R, { value: r, children: t }) });
|
|
122
138
|
}
|
|
123
|
-
function
|
|
139
|
+
function Pe(e) {
|
|
124
140
|
const n = v((t) => t.response);
|
|
125
|
-
return e && Array.isArray(e) || e &&
|
|
141
|
+
return e && Array.isArray(e) || e && K(e) ? e : n;
|
|
126
142
|
}
|
|
127
|
-
function
|
|
143
|
+
function we(e) {
|
|
128
144
|
var i;
|
|
129
145
|
const n = ((i = e.data) == null ? void 0 : i.filter((u) => u.selected).length) ?? 0, [t, r] = N(n > 0), { toggleProductFilter: o } = P();
|
|
130
146
|
return {
|
|
@@ -140,7 +156,7 @@ function Fe(e) {
|
|
|
140
156
|
toggleProductFilter: o
|
|
141
157
|
};
|
|
142
158
|
}
|
|
143
|
-
function
|
|
159
|
+
function be() {
|
|
144
160
|
const { loading: e, facets: n } = v((t) => {
|
|
145
161
|
var r, o;
|
|
146
162
|
return {
|
|
@@ -155,17 +171,17 @@ function Me() {
|
|
|
155
171
|
facets: n
|
|
156
172
|
};
|
|
157
173
|
}
|
|
158
|
-
function
|
|
174
|
+
function ie(e, n) {
|
|
159
175
|
const t = n - e;
|
|
160
176
|
return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((r, o) => o + e) : [];
|
|
161
177
|
}
|
|
162
|
-
function
|
|
178
|
+
function Ae(e) {
|
|
163
179
|
const { query: n, products: t } = v((r) => ({
|
|
164
180
|
query: r.query,
|
|
165
181
|
products: r.response.products
|
|
166
182
|
}));
|
|
167
|
-
return
|
|
168
|
-
var
|
|
183
|
+
return A(() => {
|
|
184
|
+
var M;
|
|
169
185
|
if (!t)
|
|
170
186
|
return {
|
|
171
187
|
totalPages: 0,
|
|
@@ -173,32 +189,32 @@ function Pe(e) {
|
|
|
173
189
|
resultsTo: 0,
|
|
174
190
|
pages: []
|
|
175
191
|
};
|
|
176
|
-
const r = ((
|
|
192
|
+
const r = ((M = n.products) == null ? void 0 : M.from) ?? 0, o = (e == null ? void 0 : e.width) ?? 1 / 0, a = Math.max(Math.floor(o - 1) / 2, 1), i = t.size > 0 ? Math.floor(r / t.size) + 1 : 1, u = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (y) => y >= i - a && y <= i + a, s = r + 1, l = Math.min(r + t.total, t.total), c = {
|
|
177
193
|
from: r,
|
|
178
194
|
page: i,
|
|
179
195
|
current: !0
|
|
180
|
-
}, g = (
|
|
181
|
-
from: (
|
|
182
|
-
page:
|
|
183
|
-
current:
|
|
184
|
-
}), m = i > 1 ? g(i - 1) : void 0,
|
|
196
|
+
}, g = (y) => ({
|
|
197
|
+
from: (y - 1) * t.size,
|
|
198
|
+
page: y,
|
|
199
|
+
current: y === i
|
|
200
|
+
}), m = i > 1 ? g(i - 1) : void 0, f = i < u ? g(i + 1) : void 0, S = a === 1 / 0 || i - a - 1 > 1 ? g(1) : void 0, p = a === 1 / 0 || i + a + 1 < u ? g(u) : void 0, h = ie(1, u + 1).filter(d).map(g);
|
|
185
201
|
return {
|
|
186
202
|
totalPages: u,
|
|
187
203
|
resultsFrom: s,
|
|
188
204
|
resultsTo: l,
|
|
189
205
|
current: c,
|
|
190
206
|
prev: m,
|
|
191
|
-
next:
|
|
192
|
-
first:
|
|
207
|
+
next: f,
|
|
208
|
+
first: S,
|
|
193
209
|
last: p,
|
|
194
210
|
pages: h
|
|
195
211
|
};
|
|
196
212
|
}, [n, t, e == null ? void 0 : e.width]);
|
|
197
213
|
}
|
|
198
|
-
function
|
|
214
|
+
function ke() {
|
|
199
215
|
const [e, n] = N([]), [t, r] = N([]);
|
|
200
|
-
return
|
|
201
|
-
|
|
216
|
+
return I(() => {
|
|
217
|
+
b(async (o) => {
|
|
202
218
|
const { products: a, segments: i } = await o.getSearchSessionParams();
|
|
203
219
|
n(i ?? []), r((a == null ? void 0 : a.personalizationBoost) ?? []);
|
|
204
220
|
});
|
|
@@ -207,26 +223,26 @@ function be() {
|
|
|
207
223
|
boost: t
|
|
208
224
|
};
|
|
209
225
|
}
|
|
210
|
-
function
|
|
226
|
+
function ce() {
|
|
211
227
|
const { facets: e } = v((s) => {
|
|
212
228
|
var l;
|
|
213
229
|
return {
|
|
214
230
|
facets: ((l = s.response.products) == null ? void 0 : l.facets) ?? []
|
|
215
231
|
};
|
|
216
|
-
}), { replaceFilter: n, toggleProductFilter: t } = P(), r =
|
|
232
|
+
}), { replaceFilter: n, toggleProductFilter: t } = P(), r = F(
|
|
217
233
|
(s) => {
|
|
218
234
|
const l = e == null ? void 0 : e.find((c) => c.type === "stats" && c.field === s);
|
|
219
235
|
if (l && "min" in l && "max" in l)
|
|
220
236
|
return l;
|
|
221
237
|
},
|
|
222
238
|
[e]
|
|
223
|
-
), o =
|
|
239
|
+
), o = F(
|
|
224
240
|
(s) => {
|
|
225
241
|
var l;
|
|
226
242
|
return ((l = e == null ? void 0 : e.find((c) => c.field === s)) == null ? void 0 : l.name) ?? s;
|
|
227
243
|
},
|
|
228
244
|
[e]
|
|
229
|
-
), a =
|
|
245
|
+
), a = F((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), i = F((s) => {
|
|
230
246
|
var l;
|
|
231
247
|
return {
|
|
232
248
|
...s,
|
|
@@ -237,7 +253,7 @@ function se() {
|
|
|
237
253
|
lte: c.lte ? Number(c.lte) : c.lte
|
|
238
254
|
}))
|
|
239
255
|
};
|
|
240
|
-
}, []), u =
|
|
256
|
+
}, []), u = F(
|
|
241
257
|
(s) => (s.value ?? []).map((c) => ({
|
|
242
258
|
value: c,
|
|
243
259
|
field: s.field,
|
|
@@ -248,10 +264,10 @@ function se() {
|
|
|
248
264
|
}
|
|
249
265
|
})),
|
|
250
266
|
[i, o, t]
|
|
251
|
-
),
|
|
267
|
+
), d = F(
|
|
252
268
|
(s) => (s.range ?? []).map((c) => {
|
|
253
|
-
var
|
|
254
|
-
const g = c.gte ?? c.gt ?? ((
|
|
269
|
+
var f, S;
|
|
270
|
+
const g = c.gte ?? c.gt ?? ((f = r(s.field)) == null ? void 0 : f.min), m = c.lte ?? c.lt ?? ((S = r(s.field)) == null ? void 0 : S.max);
|
|
255
271
|
if (g !== void 0 && m !== void 0)
|
|
256
272
|
return {
|
|
257
273
|
value: `${g} - ${m}`,
|
|
@@ -268,16 +284,16 @@ function se() {
|
|
|
268
284
|
return {
|
|
269
285
|
selectFilters: a,
|
|
270
286
|
toValueFilter: u,
|
|
271
|
-
toRangeFilter:
|
|
287
|
+
toRangeFilter: d
|
|
272
288
|
};
|
|
273
289
|
}
|
|
274
|
-
function
|
|
290
|
+
function ae() {
|
|
275
291
|
const { filter: e } = v((u) => {
|
|
276
|
-
var
|
|
292
|
+
var d;
|
|
277
293
|
return {
|
|
278
|
-
filter: ((
|
|
294
|
+
filter: ((d = u.query.products) == null ? void 0 : d.filter) ?? []
|
|
279
295
|
};
|
|
280
|
-
}), { updateSearch: n } = P(), { selectFilters: t, toValueFilter: r, toRangeFilter: o } =
|
|
296
|
+
}), { updateSearch: n } = P(), { selectFilters: t, toValueFilter: r, toRangeFilter: o } = ce(), a = A(() => e ? e.filter(t).flatMap((u) => "value" in u ? r(u) : "range" in u ? o(u) : []).filter(Boolean) : [], [e, t, o, r]), i = F(() => {
|
|
281
297
|
n({
|
|
282
298
|
products: {
|
|
283
299
|
filter: []
|
|
@@ -291,7 +307,7 @@ function ie() {
|
|
|
291
307
|
removeAll: i
|
|
292
308
|
};
|
|
293
309
|
}
|
|
294
|
-
function
|
|
310
|
+
function w(e) {
|
|
295
311
|
if (typeof e == "number")
|
|
296
312
|
return e;
|
|
297
313
|
if (typeof e != "string")
|
|
@@ -299,12 +315,12 @@ function b(e) {
|
|
|
299
315
|
const n = Number(e);
|
|
300
316
|
return isNaN(n) ? void 0 : n;
|
|
301
317
|
}
|
|
302
|
-
function
|
|
318
|
+
function ue(e) {
|
|
303
319
|
var c, g, m;
|
|
304
|
-
const { replaceFilter: n } = P(), { query: t, products: r } = v((
|
|
305
|
-
query:
|
|
306
|
-
products:
|
|
307
|
-
})), o = (c = r == null ? void 0 : r.facets) == null ? void 0 : c.find((
|
|
320
|
+
const { replaceFilter: n } = P(), { query: t, products: r } = v((f) => ({
|
|
321
|
+
query: f.query,
|
|
322
|
+
products: f.response.products
|
|
323
|
+
})), o = (c = r == null ? void 0 : r.facets) == null ? void 0 : c.find((f) => f.id === e);
|
|
308
324
|
if (!o)
|
|
309
325
|
return {
|
|
310
326
|
min: 0,
|
|
@@ -313,52 +329,52 @@ function ce(e) {
|
|
|
313
329
|
updateRange: () => {
|
|
314
330
|
}
|
|
315
331
|
};
|
|
316
|
-
const a = (m = (g = t.products) == null ? void 0 : g.filter) == null ? void 0 : m.find((
|
|
317
|
-
const p =
|
|
318
|
-
(
|
|
332
|
+
const a = (m = (g = t.products) == null ? void 0 : g.filter) == null ? void 0 : m.find((f) => f.field === o.field), i = a != null && a.range ? a.range[0] : void 0, u = typeof i == "object" && ("gte" in i || "lte" in i) ? [w(i.gte), w(i.lte)] : [void 0, void 0], d = "min" in o ? Math.floor(o.min) : 0, s = "max" in o ? Math.ceil(o.max) : 0, l = ([f, S]) => {
|
|
333
|
+
const p = f !== void 0 ? Math.floor(f) : void 0, h = S !== void 0 ? Math.ceil(S) : void 0, M = p !== void 0, y = h !== void 0;
|
|
334
|
+
(d === p || !M) && (s === h || !y) ? n(o.field, void 0) : (d === p || !M) && y ? n(o.field, {
|
|
319
335
|
lte: h.toString()
|
|
320
|
-
}) : (s === h || !
|
|
336
|
+
}) : (s === h || !y) && M ? n(o.field, {
|
|
321
337
|
gte: p.toString()
|
|
322
|
-
}) :
|
|
338
|
+
}) : M && y && n(o.field, {
|
|
323
339
|
gte: p.toString(),
|
|
324
340
|
lte: h.toString()
|
|
325
341
|
});
|
|
326
342
|
};
|
|
327
343
|
return {
|
|
328
344
|
/** Min value */
|
|
329
|
-
min:
|
|
345
|
+
min: d,
|
|
330
346
|
/** Max value */
|
|
331
347
|
max: s,
|
|
332
348
|
/** Range value */
|
|
333
|
-
range: [u[0] ??
|
|
349
|
+
range: [u[0] ?? d, u[1] ?? s],
|
|
334
350
|
/** Update range function */
|
|
335
351
|
updateRange: l
|
|
336
352
|
};
|
|
337
353
|
}
|
|
338
|
-
function
|
|
339
|
-
const { min: t, max: r, range: o, updateRange: a } =
|
|
340
|
-
var
|
|
354
|
+
function Ne(e, n) {
|
|
355
|
+
const { min: t, max: r, range: o, updateRange: a } = ue(e), { filters: i } = ae(), u = A(() => {
|
|
356
|
+
var S;
|
|
341
357
|
const c = i.find((p) => {
|
|
342
358
|
var h;
|
|
343
359
|
return (h = p == null ? void 0 : p.filter) == null ? void 0 : h.range;
|
|
344
360
|
});
|
|
345
361
|
let g = null;
|
|
346
362
|
if (c) {
|
|
347
|
-
const p = (
|
|
348
|
-
g = [
|
|
363
|
+
const p = (S = c.filter.range) == null ? void 0 : S[0];
|
|
364
|
+
g = [w(p == null ? void 0 : p.gte), w(p == null ? void 0 : p.lte)];
|
|
349
365
|
}
|
|
350
366
|
const m = [];
|
|
351
|
-
let
|
|
352
|
-
for (;
|
|
353
|
-
const p =
|
|
367
|
+
let f = Math.floor(t / n) * n;
|
|
368
|
+
for (; f < r; ) {
|
|
369
|
+
const p = f + n, h = g && g[0] === f && g[1] === p;
|
|
354
370
|
m.push({
|
|
355
|
-
min:
|
|
371
|
+
min: f,
|
|
356
372
|
max: p,
|
|
357
373
|
selected: h
|
|
358
|
-
}),
|
|
374
|
+
}), f = p;
|
|
359
375
|
}
|
|
360
376
|
return m;
|
|
361
|
-
}, [i, t, r, n]),
|
|
377
|
+
}, [i, t, r, n]), d = (c) => {
|
|
362
378
|
a([c, o[1]]);
|
|
363
379
|
}, s = (c) => {
|
|
364
380
|
a([o[0], c]);
|
|
@@ -375,14 +391,14 @@ function we(e, n) {
|
|
|
375
391
|
/** Ranges */
|
|
376
392
|
ranges: u,
|
|
377
393
|
/** Handle min change */
|
|
378
|
-
handleMinChange:
|
|
394
|
+
handleMinChange: d,
|
|
379
395
|
/** Handle max change */
|
|
380
396
|
handleMaxChange: s,
|
|
381
397
|
/** Is selected */
|
|
382
398
|
isSelected: l
|
|
383
399
|
};
|
|
384
400
|
}
|
|
385
|
-
function
|
|
401
|
+
function xe() {
|
|
386
402
|
const { products: e, keywords: n } = v((t) => t.response);
|
|
387
403
|
return {
|
|
388
404
|
/** Array of products */
|
|
@@ -391,23 +407,23 @@ function Ae() {
|
|
|
391
407
|
keywords: n ?? { hits: [], total: 0 }
|
|
392
408
|
};
|
|
393
409
|
}
|
|
394
|
-
function
|
|
410
|
+
function Re() {
|
|
395
411
|
const e = v((t) => {
|
|
396
412
|
var r;
|
|
397
413
|
return (r = t.query.products) == null ? void 0 : r.filter;
|
|
398
414
|
});
|
|
399
|
-
return
|
|
415
|
+
return A(() => e ? e.reduce((t, r) => t + (Array.isArray(r.value) ? r.value.length : 1), 0) : 0, [e]);
|
|
400
416
|
}
|
|
401
|
-
function
|
|
417
|
+
function k(e) {
|
|
402
418
|
return e && !Number.isNaN(e) ? e : 0;
|
|
403
419
|
}
|
|
404
|
-
function
|
|
420
|
+
function Te(e, n) {
|
|
405
421
|
const { from: t, size: r, total: o } = v((s) => {
|
|
406
|
-
var l, c, g, m,
|
|
422
|
+
var l, c, g, m, f;
|
|
407
423
|
return {
|
|
408
|
-
from:
|
|
409
|
-
size:
|
|
410
|
-
total:
|
|
424
|
+
from: k(((l = s.query.products) == null ? void 0 : l.from) ?? 0),
|
|
425
|
+
size: k(((g = (c = s.response) == null ? void 0 : c.products) == null ? void 0 : g.size) ?? 0),
|
|
426
|
+
total: k(((f = (m = s.response) == null ? void 0 : m.products) == null ? void 0 : f.total) ?? 0)
|
|
411
427
|
};
|
|
412
428
|
}), { updateSearch: a } = P(), i = t + r, u = [...e].reverse().filter((s) => s + n < o);
|
|
413
429
|
return {
|
|
@@ -431,54 +447,55 @@ function Re(e, n) {
|
|
|
431
447
|
}
|
|
432
448
|
};
|
|
433
449
|
}
|
|
434
|
-
function
|
|
450
|
+
function le(e, n) {
|
|
435
451
|
return e.length !== n.length ? !1 : e.every((t) => n.find((r) => t.field === r.field && t.order === r.order));
|
|
436
452
|
}
|
|
437
|
-
function
|
|
453
|
+
function qe(e) {
|
|
438
454
|
var a, i;
|
|
439
455
|
const n = v((u) => u.query), { updateSearch: t } = P();
|
|
440
456
|
return {
|
|
441
457
|
/** Active sort */
|
|
442
458
|
activeSort: ((a = e.find((u) => {
|
|
443
|
-
var
|
|
444
|
-
return
|
|
459
|
+
var d;
|
|
460
|
+
return le(u.value.sort, ((d = n.products) == null ? void 0 : d.sort) || []);
|
|
445
461
|
})) == null ? void 0 : a.id) ?? ((i = e[0]) == null ? void 0 : i.id),
|
|
446
462
|
/** Set sort function */
|
|
447
463
|
setSort: (u) => {
|
|
448
|
-
const
|
|
449
|
-
|
|
464
|
+
const d = e.find((s) => s.id === u);
|
|
465
|
+
d && t({
|
|
450
466
|
products: {
|
|
451
|
-
sort:
|
|
467
|
+
sort: d.value.sort
|
|
452
468
|
}
|
|
453
469
|
});
|
|
454
470
|
}
|
|
455
471
|
};
|
|
456
472
|
}
|
|
457
473
|
export {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
474
|
+
he as AutocompleteElement,
|
|
475
|
+
Ce as AutocompletePageProvider,
|
|
476
|
+
Me as CategoryPageProvider,
|
|
477
|
+
ye as InfiniteScroll,
|
|
478
|
+
G as InfiniteScrollWithLink,
|
|
479
|
+
ve as SearchInput,
|
|
480
|
+
Fe as SearchPageProvider,
|
|
481
|
+
Se as SerpElement,
|
|
482
|
+
R as StoreContext,
|
|
483
|
+
Ie as createExtendableStore,
|
|
484
|
+
x as createStore,
|
|
485
|
+
Le as defaultState,
|
|
469
486
|
P as useActions,
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
487
|
+
Pe as useDecoratedSearchResults,
|
|
488
|
+
we as useFacet,
|
|
489
|
+
be as useFacets,
|
|
490
|
+
V as useLoadMore,
|
|
474
491
|
v as useNostoAppState,
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
492
|
+
Ae as usePagination,
|
|
493
|
+
ke as usePersonalization,
|
|
494
|
+
ae as useProductFilters,
|
|
495
|
+
ue as useRange,
|
|
496
|
+
Ne as useRangeSelector,
|
|
497
|
+
xe as useResponse,
|
|
498
|
+
Re as useSelectedFiltersCount,
|
|
499
|
+
Te as useSizeOptions,
|
|
500
|
+
qe as useSort
|
|
484
501
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComponentChildren } from 'preact';
|
|
2
|
+
/**
|
|
3
|
+
* @group Components
|
|
4
|
+
*/
|
|
5
|
+
export type AutocompleteElementProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Rendered content.
|
|
8
|
+
*/
|
|
9
|
+
children: ComponentChildren;
|
|
10
|
+
/**
|
|
11
|
+
* Get product data for analytics
|
|
12
|
+
*/
|
|
13
|
+
hit: {
|
|
14
|
+
productId: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
keyword?: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Wraps elements to interactive component that handles selection based on provided configuration.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```jsx
|
|
24
|
+
* // Render product
|
|
25
|
+
* {products?.hits?.map(hit => <AutocompleteElement hit={hit}>
|
|
26
|
+
* <a href={hit.url} class="nosto-product">
|
|
27
|
+
* <img src={hit.imageUrl} alt={hit.name} />
|
|
28
|
+
* <span>{hit.name}</span>
|
|
29
|
+
* <span>{hit.price}</span>
|
|
30
|
+
* </a>
|
|
31
|
+
* </AutocompleteElement>)}
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @group Components
|
|
35
|
+
*/
|
|
36
|
+
export declare function AutocompleteElement({ children, hit }: AutocompleteElementProps): import('preact').VNode<any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"test:watch": "vitest",
|
|
61
61
|
"lint": "eslint",
|
|
62
62
|
"lint-fix": "eslint --fix",
|
|
63
|
-
"install:dev": "(cd dev/preact && npm i --ignore-scripts)"
|
|
63
|
+
"install:dev": "(cd dev/preact && npm i --ignore-scripts)",
|
|
64
|
+
"prepare": "husky"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@nosto/nosto-js": "^1.7.0",
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
78
79
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
79
80
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
81
|
+
"husky": "^9.1.7",
|
|
80
82
|
"isbot": "^5.1.25",
|
|
81
83
|
"jsdom": "^26.0.0",
|
|
82
84
|
"prettier": "^3.5.3",
|