@nosto/search-js 3.20.0 → 3.21.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 v=require("../../useActions-CY9uts_o.cjs"),q=require("../../logger-Boh_C6Bz.cjs"),S=require("../../useLoadMore-CBshMpps.cjs"),R=require("../../eventBusSubscribe-oONOUGH8.cjs"),d=require("preact/hooks"),M=require("../../useHistory-rc2PvSkv.cjs"),L=require("../../index.es-Dp6Iaxz3.cjs"),z=require("../../eventBusDispatch-BKQcSHAB.cjs"),A=require("../../parseNumber-FsZ8w61u.cjs");function O(e){const s=S.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&q.isPlainObject(e)?e:s}function X(e,s){const t=e.data?.filter(f=>f.selected).length??0,{active:o}={active:t>0,...s},[n,c]=d.useState(o),{toggleProductFilter:u}=v.useActions(),a=d.useCallback(()=>{c(!n)},[n]);return R.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{c(!1)}}),{active:n,selectedFiltersCount:t,toggleActive:a,toggleProductFilter:u}}function j(){const{loading:e,facets:s}=S.useNostoAppState(t=>({loading:t.loading,facets:t.response?.products?.facets??[]}));return{loading:e,facets:s}}function E(e,s){const t=s-e;return!isNaN(t)&&t>0?new Array(s-e).fill(void 0).map((o,n)=>n+e):[]}function B(e){const{query:s,products:t}=S.useNostoAppState(o=>({query:o.query,products:o.response.products}));return d.useMemo(()=>{if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=s.products?.from??0,n=e?.width??1/0,c=Math.max(Math.floor(n-1)/2,1),u=t.size>0?Math.floor(o/t.size)+1:1,a=t.size>0?Math.ceil(t.total/t.size):0,f=F=>F>=u-c&&F<=u+c,r=o+1,i=Math.min(o+t.total,t.total),l={from:o,page:u,current:!0},p=F=>({from:(F-1)*t.size,page:F,current:F===u}),h=u>1?p(u-1):void 0,g=u<a?p(u+1):void 0,m=u-c-1>1?p(1):void 0,b=u+c+1<a?p(a):void 0,y=E(1,a+1).filter(f).map(p);return!m&&y[0]?.page===2&&y.unshift(p(1)),!b&&y[y.length-1]?.page===a-1&&y.push(p(a)),{totalPages:a,resultsFrom:r,resultsTo:i,current:l,prev:h,next:g,first:m,last:b,pages:y}},[s,t,e?.width])}function D(){const[e,s]=d.useState([]),[t,o]=d.useState([]);return d.useEffect(()=>{L.s(async n=>{const{products:c,segments:u}=await n.getSearchSessionParams();s(u??[]),o(c?.personalizationBoost??[])})},[]),{segments:e,boost:t}}function V(){const{facets:e}=S.useNostoAppState(r=>({facets:r.response.products?.facets??[]})),{replaceFilter:s,toggleProductFilter:t}=v.useActions(),o=d.useCallback(r=>{const i=e?.find(l=>l.type==="stats"&&l.field===r);if(i&&"min"in i&&"max"in i)return i},[e]),n=d.useCallback(r=>e?.find(i=>i.field===r)?.name??r,[e]),c=d.useCallback(r=>"field"in r&&(r.value instanceof Array||r.range instanceof Array),[]),u=d.useCallback(r=>({...r,range:r.range?.map(i=>({gt:i.gt?Number(i.gt):i.gt,gte:i.gte?Number(i.gte):i.gte,lt:i.lt?Number(i.lt):i.lt,lte:i.lte?Number(i.lte):i.lte}))}),[]),a=d.useCallback(r=>(r.value??[]).map(l=>({value:l,field:r.field,name:n(r.field),filter:u(r),remove:()=>{t(r.field,l,!1)}})),[u,n,t]),f=d.useCallback(r=>(r.range??[]).map(l=>{const p=l.gte??l.gt??o(r.field)?.min,h=l.lte??l.lt??o(r.field)?.max;if(p!==void 0&&h!==void 0)return{value:`${p} - ${h}`,field:r.field,name:n(r.field),filter:u(r),remove:()=>{s(r.field,void 0)}}}).filter(Boolean),[u,o,n,s]);return{selectFilters:c,toValueFilter:a,toRangeFilter:f}}function T(){const{filter:e}=S.useNostoAppState(a=>({filter:a.query.products?.filter??[]})),{updateSearch:s}=v.useActions(),{selectFilters:t,toValueFilter:o,toRangeFilter:n}=V(),c=d.useMemo(()=>e?e.filter(t).flatMap(a=>"value"in a?o(a):"range"in a?n(a):[]).filter(Boolean):[],[e,t,n,o]),u=d.useCallback(()=>{s({products:{filter:[]}}),z.dispatchNostoEvent({event:"events/removeAllFilters",params:null})},[s]);return{filters:c,removeAll:u}}function x(e){const{replaceFilter:s}=v.useActions(),{query:t,products:o}=S.useNostoAppState(g=>({query:g.query,products:g.response.products})),n=o?.facets?.find(g=>g.id===e),c=t.products?.filter?.find(g=>g.field===n?.field),u=H(c),a=n&&"min"in n?Math.floor(n.min??0):0,f=n&&"max"in n?Math.ceil(n.max??0):0,r=u[0]!==void 0||u[1]!==void 0,[i,l]=d.useState(r),p=d.useCallback(()=>{l(g=>!g)},[]),h=d.useCallback(([g,m])=>{if(!n)return;const b=$(g,m,a,f);s(n.field,b)},[a,f,s,n]);return R.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{l(!1)}}),n?{min:a,max:f,range:[u[0]??a,u[1]??f],updateRange:h,active:i,toggleActive:p}:{min:0,max:0,range:[0,0],active:!1,toggleActive:()=>{},updateRange:()=>{}}}function H(e){const s=e?.range?.[0];return typeof s=="object"&&("gte"in s||"lte"in s)?[A.parseNumber(s.gte),A.parseNumber(s.lte)]:[void 0,void 0]}function $(e,s,t,o){const n=e!==void 0?Math.floor(e):void 0,c=s!==void 0?Math.ceil(s):void 0,u=n!==void 0,a=c!==void 0;if((t===n||!u)&&(o===c||!a))return;const f={};return u&&n!==t&&(f.gte=n.toString()),a&&c!==o&&(f.lte=c.toString()),Object.keys(f).length>0?f:void 0}function _(e,s){const{min:t,max:o,range:n,updateRange:c}=x(e),{filters:u}=T(),a=d.useMemo(()=>{const l=u.find(m=>m?.filter?.range);let p=null;if(l){const m=l.filter.range?.[0];p=[A.parseNumber(m?.gte),A.parseNumber(m?.lte)]}const h=[];let g=Math.floor(t/s)*s;for(;g<o;){const m=g+s,b=p&&p[0]===g&&p[1]===m;h.push({min:g,max:m,selected:b}),g=m}return h},[u,t,o,s]),f=l=>{c([l,n[1]])},r=l=>{c([n[0],l])},i=t!==n[0]||o!==n[1];return{min:t,max:o,range:n,updateRange:c,ranges:a,handleMinChange:f,handleMaxChange:r,isSelected:i}}function U(){const{products:e,keywords:s}=S.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:s??{hits:[],total:0}}}function I(){const e=S.useNostoAppState(t=>t.query.products?.filter);return d.useMemo(()=>e?e.reduce((t,o)=>t+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}const Z=5*60*1e3,w=new Map;function G(e){const[s,t]=d.useState({product:null,loading:!0,error:null});return d.useEffect(()=>{if(!e){t({product:null,loading:!1,error:"Product handle is required"});return}t(n=>({...n,loading:!0,error:null}));const o=K(e);if(o){t({product:o,loading:!1,error:null});return}J(e).then(n=>{Q(e,n),t({product:n,loading:!1,error:null})}).catch(n=>{t({product:null,loading:!1,error:n.message||"Failed to fetch product"})})},[e]),s}async function J(e){const s=await fetch(`/products/${e}.js`);if(!s.ok)throw new Error(`Failed to fetch product: ${s.status} ${s.statusText}`);return s.json()}function K(e){const s=w.get(e);return s?Date.now()-s.created>Z?(w.delete(e),null):s.product:null}function Q(e,s){w.set(e,{product:s,created:Date.now()})}function N(e){return e&&!Number.isNaN(e)?e:0}function W(e,s){const{from:t,size:o,total:n}=S.useNostoAppState(r=>({from:N(r.query.products?.from??0),size:N(r.response?.products?.size??s),total:N(r.response?.products?.total??0)})),{updateSearch:c}=v.useActions(),u=t+o,a=d.useMemo(()=>[...e].reverse().filter(r=>r<n),[e,n]),f=d.useCallback(r=>{c({products:{size:A.parseNumber(r)}})},[c]);return{from:t,to:u,total:n,size:o,sizeOptions:a,handleSizeChange:f}}function Y(e,s){return e.length!==s.length?!1:e.every(t=>s.find(o=>t.field===o.field&&t.order===o.order))}function ee(e){const s=S.useNostoAppState(c=>c.query),{updateSearch:t}=v.useActions();return{activeSort:e.find(c=>Y(c.value.sort,s.products?.sort||[]))?.id??e[0]?.id,setSort:c=>{const u=e.find(a=>a.id===c);u&&t({products:{sort:u.value.sort}})}}}const k=window.SpeechRecognition||window.webkitSpeechRecognition,P=!!(k&&typeof k=="function");function te(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function se({language:e="en-US",interimResults:s=!1,onResult:t,onError:o}={}){const[n,c]=d.useState(!1),u=d.useRef(null),a=d.useCallback(()=>{const r=new k;r.lang=e,r.interimResults=s,r.onstart=()=>c(!0),t&&(r.onresult=i=>{const{transcript:l}=i.results?.[0]?.[0];t(l)}),o&&(r.onerror=i=>o(i.error)),r.onend=()=>c(!1),u.current=r,r.start()},[e,s,o,t]),f=d.useCallback(()=>{u.current?.stop()},[u]);return{listening:n,startListening:a,stopListening:f}}const ne=P?se:te;function oe(e,s){if(!e.length||!s.length)return[];const t=s.reduce((o,n)=>(o[n]={},o),{});return e.forEach(o=>{o.customFields?.forEach(({key:n,value:c})=>{const u=n.toLowerCase();s.includes(u)&&(t[u][c]=t[u][c]||[],t[u][c].push(o))})}),Object.entries(t).filter(o=>Object.keys(o[1]).length).map(([o,n])=>({field:o,options:Object.entries(n).map(([c,u])=>({value:c,skus:u,unavailable:!1,selected:!1}))}))}function re(e,s){return e.length?e.map(({field:t,options:o})=>({field:t,options:o.map(n=>{const c=!n.skus?.some(a=>Object.entries(s).every(([f,r])=>f===t?!0:a.customFields?.find(l=>l.key.toLowerCase()===f)?.value===r)),u=s[t]===n.value;return{...n,unavailable:c,selected:u}})})):[]}const C=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function ue(e){if(C.includes(e))return 1e3+C.indexOf(e);const s=parseFloat(e);return isNaN(s)?e:s}function ce(e,s){return[...s].sort((t,o)=>{const[n,c]=[t.value,o.value].map(ue);return n<c?-1:1})}function ie(e=[],s=[]){const[t,o]=d.useState({}),n=d.useMemo(()=>oe(e,s).map(({field:r,options:i})=>({field:r,options:ce(r,i)})),[e,s]),c=d.useMemo(()=>re(n,t),[n,t]),u=d.useCallback((f,r)=>{o(i=>{const l={...i};return l[f]===r?delete l[f]:l[f]=r,l})},[]),a=d.useMemo(()=>Object.keys(t).filter(i=>t[i]).length===0?[]:c.filter(({field:i})=>t[i]).map(({field:i,options:l})=>{const p=t[i];return l.find(g=>g.value===p)?.skus??[]}).reduce((i,l)=>i.filter(p=>l.includes(p))),[c,t]);return{swatches:c,toggleOption:u,matchedSkus:a}}exports.useActions=v.useActions;exports.useLoadMore=S.useLoadMore;exports.useNostoAppState=S.useNostoAppState;exports.addToHistory=M.addToHistory;exports.getSavedHistory=M.getSavedHistory;exports.useHistory=M.useHistory;exports.speechToTextSupported=P;exports.useDecoratedSearchResults=O;exports.useFacet=X;exports.useFacets=j;exports.usePagination=B;exports.usePersonalization=D;exports.useProductFilters=T;exports.useRange=x;exports.useRangeSelector=_;exports.useResponse=U;exports.useSelectedFiltersCount=I;exports.useShopifyProduct=G;exports.useSizeOptions=W;exports.useSort=ee;exports.useSpeechToText=ne;exports.useSwatches=ie;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("../../useActions-CY9uts_o.cjs"),P=require("../../logger-Boh_C6Bz.cjs"),h=require("../../useLoadMore-CBshMpps.cjs"),R=require("../../eventBusSubscribe-oONOUGH8.cjs"),l=require("preact/hooks"),C=require("../../useHistory-rc2PvSkv.cjs"),q=require("../../index.es-Dp6Iaxz3.cjs"),z=require("../../eventBusDispatch-BKQcSHAB.cjs"),F=require("../../parseNumber-FsZ8w61u.cjs");function O(e){const s=h.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&P.isPlainObject(e)?e:s}function X(e,s){const t=e.data?.filter(f=>f.selected).length??0,{active:o}={active:t>0,...s},[n,u]=l.useState(o),{toggleProductFilter:c}=A.useActions(),a=l.useCallback(()=>{u(!n)},[n]);return R.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{u(!1)}}),{active:n,selectedFiltersCount:t,toggleActive:a,toggleProductFilter:c}}function E(){const{loading:e,facets:s}=h.useNostoAppState(t=>({loading:t.loading,facets:t.response?.products?.facets??[]}));return{loading:e,facets:s}}function j(e,s){const t=s-e;return!isNaN(t)&&t>0?new Array(s-e).fill(void 0).map((o,n)=>n+e):[]}function B(e){const{query:s,products:t}=h.useNostoAppState(o=>({query:o.query,products:o.response.products}));return l.useMemo(()=>{if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=s.products?.from??0,n=e?.width??1/0,u=Math.max(Math.floor(n-1)/2,1),c=t.size>0?Math.floor(o/t.size)+1:1,a=t.size>0?Math.ceil(t.total/t.size):0,f=y=>y>=c-u&&y<=c+u,r=o+1,i=Math.min(o+t.total,t.total),d={from:o,page:c,current:!0},p=y=>({from:(y-1)*t.size,page:y,current:y===c}),S=c>1?p(c-1):void 0,v=c<a?p(c+1):void 0,m=c-u-1>1?p(1):void 0,g=c+u+1<a?p(a):void 0,b=j(1,a+1).filter(f).map(p);return!m&&b[0]?.page===2&&b.unshift(p(1)),!g&&b[b.length-1]?.page===a-1&&b.push(p(a)),{totalPages:a,resultsFrom:r,resultsTo:i,current:d,prev:S,next:v,first:m,last:g,pages:b}},[s,t,e?.width])}function V(){const[e,s]=l.useState([]),[t,o]=l.useState([]);return l.useEffect(()=>{q.s(async n=>{const{products:u,segments:c}=await n.getSearchSessionParams();s(c??[]),o(u?.personalizationBoost??[])})},[]),{segments:e,boost:t}}function D(){const{facets:e}=h.useNostoAppState(r=>({facets:r.response.products?.facets??[]})),{replaceFilter:s,toggleProductFilter:t}=A.useActions(),o=l.useCallback(r=>{const i=e?.find(d=>d.type==="stats"&&d.field===r);if(i&&"min"in i&&"max"in i)return i},[e]),n=l.useCallback(r=>e?.find(i=>i.field===r)?.name??r,[e]),u=l.useCallback(r=>"field"in r&&(r.value instanceof Array||r.range instanceof Array),[]),c=l.useCallback(r=>({...r,range:r.range?.map(i=>({gt:i.gt?Number(i.gt):i.gt,gte:i.gte?Number(i.gte):i.gte,lt:i.lt?Number(i.lt):i.lt,lte:i.lte?Number(i.lte):i.lte}))}),[]),a=l.useCallback(r=>(r.value??[]).map(d=>({value:d,field:r.field,name:n(r.field),filter:c(r),remove:()=>{t(r.field,d,!1)}})),[c,n,t]),f=l.useCallback(r=>(r.range??[]).map(d=>{const p=d.gte??d.gt??o(r.field)?.min,S=d.lte??d.lt??o(r.field)?.max;if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:r.field,name:n(r.field),filter:c(r),remove:()=>{s(r.field,void 0)}}}).filter(Boolean),[c,o,n,s]);return{selectFilters:u,toValueFilter:a,toRangeFilter:f}}function L(){const{filter:e}=h.useNostoAppState(a=>({filter:a.query.products?.filter??[]})),{updateSearch:s}=A.useActions(),{selectFilters:t,toValueFilter:o,toRangeFilter:n}=D(),u=l.useMemo(()=>e?e.filter(t).flatMap(a=>"value"in a?o(a):"range"in a?n(a):[]).filter(Boolean):[],[e,t,n,o]),c=l.useCallback(()=>{s({products:{filter:[]}}),z.dispatchNostoEvent({event:"events/removeAllFilters",params:null})},[s]);return{filters:u,removeAll:c}}function T(e){const{replaceFilter:s}=A.useActions(),{query:t,products:o}=h.useNostoAppState(g=>({query:g.query,products:g.response.products})),n=o?.facets?.find(g=>g.id===e),u=t.products?.filter?.find(g=>g.field===n?.field),[c,a]=_(u),f=n&&"min"in n?Math.floor(n.min??0):0,r=n&&"max"in n?Math.ceil(n.max??0):0,i=l.useMemo(()=>[c??f,a??r],[c,a,f,r]),d=c!==void 0||a!==void 0,[p,S]=l.useState(d),v=l.useCallback(()=>{S(g=>!g)},[]),m=l.useCallback(([g,b])=>{if(!n)return;const y=$(g,b,f,r);s(n.field,y)},[f,r,s,n]);return R.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{S(!1)}}),n?{min:f,max:r,range:i,updateRange:m,active:p,toggleActive:v}:H}const H={min:0,max:0,range:[0,0],active:!1,toggleActive:()=>{},updateRange:()=>{}};function _(e){const s=e?.range?.[0];return typeof s=="object"&&("gte"in s||"lte"in s)?[F.parseNumber(s.gte),F.parseNumber(s.lte)]:[void 0,void 0]}function $(e,s,t,o){const n=e!==void 0?Math.floor(e):void 0,u=s!==void 0?Math.ceil(s):void 0,c=n!==void 0,a=u!==void 0;if((t===n||!c)&&(o===u||!a))return;const f={};return c&&n!==t&&(f.gte=n.toString()),a&&u!==o&&(f.lte=u.toString()),Object.keys(f).length>0?f:void 0}function U(e,s){const{min:t,max:o,range:n,updateRange:u}=T(e),{filters:c}=L(),a=l.useMemo(()=>{const d=c.find(m=>m?.filter?.range);let p=null;if(d){const m=d.filter.range?.[0];p=[F.parseNumber(m?.gte),F.parseNumber(m?.lte)]}const S=[];let v=Math.floor(t/s)*s;for(;v<o;){const m=v+s,g=p&&p[0]===v&&p[1]===m;S.push({min:v,max:m,selected:g}),v=m}return S},[c,t,o,s]),f=l.useCallback(d=>{u([d,n[1]])},[n,u]),r=l.useCallback(d=>{u([n[0],d])},[n,u]),i=t!==n[0]||o!==n[1];return{min:t,max:o,range:n,updateRange:u,ranges:a,handleMinChange:f,handleMaxChange:r,isSelected:i}}function I(){const{products:e,keywords:s}=h.useNostoAppState(t=>({products:t.response.products??{hits:[],total:0},keywords:t.response.keywords??{hits:[],total:0}}));return{products:e,keywords:s}}function K(){const e=h.useNostoAppState(t=>t.query.products?.filter);return l.useMemo(()=>e?e.reduce((t,o)=>t+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}const Z=5*60*1e3,N=new Map;function G(e){const[s,t]=l.useState({product:null,loading:!0,error:null});return l.useEffect(()=>{if(!e){t({product:null,loading:!1,error:"Product handle is required"});return}t(n=>({...n,loading:!0,error:null}));const o=Q(e);if(o){t({product:o,loading:!1,error:null});return}J(e).then(n=>{W(e,n),t({product:n,loading:!1,error:null})}).catch(n=>{t({product:null,loading:!1,error:n.message||"Failed to fetch product"})})},[e]),s}async function J(e){const s=await fetch(`/products/${e}.js`);if(!s.ok)throw new Error(`Failed to fetch product: ${s.status} ${s.statusText}`);return s.json()}function Q(e){const s=N.get(e);return s?Date.now()-s.created>Z?(N.delete(e),null):s.product:null}function W(e,s){N.set(e,{product:s,created:Date.now()})}function k(e){return e&&!Number.isNaN(e)?e:0}function Y(e,s){const{from:t,size:o,total:n}=h.useNostoAppState(r=>({from:k(r.query.products?.from??0),size:k(r.response?.products?.size??s),total:k(r.response?.products?.total??0)})),{updateSearch:u}=A.useActions(),c=t+o,a=l.useMemo(()=>[...e].reverse().filter(r=>r<n),[e,n]),f=l.useCallback(r=>{u({products:{size:F.parseNumber(r)}})},[u]);return{from:t,to:c,total:n,size:o,sizeOptions:a,handleSizeChange:f}}function ee(e,s){return e.length!==s.length?!1:e.every(t=>s.find(o=>t.field===o.field&&t.order===o.order))}function te(e){const s=h.useNostoAppState(u=>u.query),{updateSearch:t}=A.useActions(),o=e.find(u=>ee(u.value.sort,s.products?.sort||[]))?.id??e[0]?.id,n=l.useCallback(u=>{const c=e.find(a=>a.id===u);c&&t({products:{sort:c.value.sort}})},[e,t]);return{activeSort:o,setSort:n}}const w=window.SpeechRecognition||window.webkitSpeechRecognition,x=!!(w&&typeof w=="function");function se(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function ne({language:e="en-US",interimResults:s=!1,onResult:t,onError:o}={}){const[n,u]=l.useState(!1),c=l.useRef(null),a=l.useCallback(()=>{const r=new w;r.lang=e,r.interimResults=s,r.onstart=()=>u(!0),t&&(r.onresult=i=>{const{transcript:d}=i.results?.[0]?.[0];t(d)}),o&&(r.onerror=i=>o(i.error)),r.onend=()=>u(!1),c.current=r,r.start()},[e,s,o,t]),f=l.useCallback(()=>{c.current?.stop()},[c]);return{listening:n,startListening:a,stopListening:f}}const oe=x?ne:se;function re(e,s){if(!e.length||!s.length)return[];const t=s.reduce((o,n)=>(o[n]={},o),{});return e.forEach(o=>{o.customFields?.forEach(({key:n,value:u})=>{const c=n.toLowerCase();s.includes(c)&&(t[c][u]=t[c][u]||[],t[c][u].push(o))})}),Object.entries(t).filter(o=>Object.keys(o[1]).length).map(([o,n])=>({field:o,options:Object.entries(n).map(([u,c])=>({value:u,skus:c,unavailable:!1,selected:!1}))}))}function ue(e,s){return e.length?e.map(({field:t,options:o})=>({field:t,options:o.map(n=>{const u=!n.skus?.some(a=>Object.entries(s).every(([f,r])=>f===t?!0:a.customFields?.find(d=>d.key.toLowerCase()===f)?.value===r)),c=s[t]===n.value;return{...n,unavailable:u,selected:c}})})):[]}const M=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function ce(e){if(M.includes(e))return 1e3+M.indexOf(e);const s=parseFloat(e);return isNaN(s)?e:s}function ie(e,s){return[...s].sort((t,o)=>{const[n,u]=[t.value,o.value].map(ce);return n<u?-1:1})}function ae(e=[],s=[]){const[t,o]=l.useState({}),n=l.useMemo(()=>re(e,s).map(({field:r,options:i})=>({field:r,options:ie(r,i)})),[e,s]),u=l.useMemo(()=>ue(n,t),[n,t]),c=l.useCallback((f,r)=>{o(i=>{const d={...i};return d[f]===r?delete d[f]:d[f]=r,d})},[]),a=l.useMemo(()=>Object.keys(t).filter(i=>t[i]).length===0?[]:u.filter(({field:i})=>t[i]).map(({field:i,options:d})=>{const p=t[i];return d.find(v=>v.value===p)?.skus??[]}).reduce((i,d)=>i.filter(p=>d.includes(p))),[u,t]);return{swatches:u,toggleOption:c,matchedSkus:a}}exports.useActions=A.useActions;exports.useLoadMore=h.useLoadMore;exports.useNostoAppState=h.useNostoAppState;exports.addToHistory=C.addToHistory;exports.getSavedHistory=C.getSavedHistory;exports.useHistory=C.useHistory;exports.speechToTextSupported=x;exports.useDecoratedSearchResults=O;exports.useFacet=X;exports.useFacets=E;exports.usePagination=B;exports.usePersonalization=V;exports.useProductFilters=L;exports.useRange=T;exports.useRangeSelector=U;exports.useResponse=I;exports.useSelectedFiltersCount=K;exports.useShopifyProduct=G;exports.useSizeOptions=Y;exports.useSort=te;exports.useSpeechToText=oe;exports.useSwatches=ae;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
4
|
-
import { u as
|
|
5
|
-
import { u as
|
|
6
|
-
import { useState as
|
|
7
|
-
import { a as
|
|
1
|
+
import { h as A } from "../../useActions-CSNwQtT1.js";
|
|
2
|
+
import { a as k } from "../../logger-_fg_Za9y.js";
|
|
3
|
+
import { a as S } from "../../useLoadMore-2OmOqicJ.js";
|
|
4
|
+
import { u as Ae } from "../../useLoadMore-2OmOqicJ.js";
|
|
5
|
+
import { u as N } from "../../eventBusSubscribe-CzlS132j.js";
|
|
6
|
+
import { useState as b, useCallback as g, useMemo as y, useEffect as P, useRef as X } from "preact/hooks";
|
|
7
|
+
import { a as xe, g as Le, u as Me } from "../../useHistory-joVBx1r2.js";
|
|
8
8
|
import { s as z } from "../../index.es-XNBESE3P.js";
|
|
9
|
-
import { d as
|
|
10
|
-
import { p as
|
|
11
|
-
function
|
|
12
|
-
const n =
|
|
13
|
-
return e && Array.isArray(e) || e &&
|
|
9
|
+
import { d as C } from "../../eventBusDispatch-DPR2Vwd4.js";
|
|
10
|
+
import { p as R } from "../../parseNumber-QA48nJLp.js";
|
|
11
|
+
function ae(e) {
|
|
12
|
+
const n = S((t) => t.response);
|
|
13
|
+
return e && Array.isArray(e) || e && k(e) ? e : n;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function ue(e, n) {
|
|
16
16
|
const t = e.data?.filter((d) => d.selected).length ?? 0, { active: o } = {
|
|
17
17
|
active: t > 0,
|
|
18
18
|
...n
|
|
19
|
-
}, [r,
|
|
20
|
-
|
|
19
|
+
}, [r, c] = b(o), { toggleProductFilter: i } = A(), u = g(() => {
|
|
20
|
+
c(!r);
|
|
21
21
|
}, [r]);
|
|
22
|
-
return
|
|
22
|
+
return N({
|
|
23
23
|
event: "events/removeAllFilters",
|
|
24
24
|
callback: () => {
|
|
25
|
-
|
|
25
|
+
c(!1);
|
|
26
26
|
}
|
|
27
27
|
}), {
|
|
28
28
|
/** Active value */
|
|
@@ -32,11 +32,11 @@ function ae(e, n) {
|
|
|
32
32
|
/** Toggle active function */
|
|
33
33
|
toggleActive: u,
|
|
34
34
|
/** Toggle product filter function */
|
|
35
|
-
toggleProductFilter:
|
|
35
|
+
toggleProductFilter: i
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
const { loading: e, facets: n } =
|
|
38
|
+
function le() {
|
|
39
|
+
const { loading: e, facets: n } = S((t) => ({
|
|
40
40
|
loading: t.loading,
|
|
41
41
|
facets: t.response?.products?.facets ?? []
|
|
42
42
|
}));
|
|
@@ -47,16 +47,16 @@ function ue() {
|
|
|
47
47
|
facets: n
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function O(e, n) {
|
|
51
51
|
const t = n - e;
|
|
52
52
|
return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((o, r) => r + e) : [];
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
const { query: n, products: t } =
|
|
54
|
+
function de(e) {
|
|
55
|
+
const { query: n, products: t } = S((o) => ({
|
|
56
56
|
query: o.query,
|
|
57
57
|
products: o.response.products
|
|
58
58
|
}));
|
|
59
|
-
return
|
|
59
|
+
return y(() => {
|
|
60
60
|
if (!t)
|
|
61
61
|
return {
|
|
62
62
|
totalPages: 0,
|
|
@@ -64,34 +64,34 @@ function le(e) {
|
|
|
64
64
|
resultsTo: 0,
|
|
65
65
|
pages: []
|
|
66
66
|
};
|
|
67
|
-
const o = n.products?.from ?? 0, r = e?.width ?? 1 / 0,
|
|
67
|
+
const o = n.products?.from ?? 0, r = e?.width ?? 1 / 0, c = Math.max(Math.floor(r - 1) / 2, 1), i = t.size > 0 ? Math.floor(o / t.size) + 1 : 1, u = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (w) => w >= i - c && w <= i + c, s = o + 1, a = Math.min(o + t.total, t.total), l = {
|
|
68
68
|
from: o,
|
|
69
|
-
page:
|
|
69
|
+
page: i,
|
|
70
70
|
current: !0
|
|
71
|
-
}, f = (
|
|
72
|
-
from: (
|
|
73
|
-
page:
|
|
74
|
-
current:
|
|
75
|
-
}), h =
|
|
76
|
-
return !m &&
|
|
71
|
+
}, f = (w) => ({
|
|
72
|
+
from: (w - 1) * t.size,
|
|
73
|
+
page: w,
|
|
74
|
+
current: w === i
|
|
75
|
+
}), h = i > 1 ? f(i - 1) : void 0, v = i < u ? f(i + 1) : void 0, m = i - c - 1 > 1 ? f(1) : void 0, p = i + c + 1 < u ? f(u) : void 0, F = O(1, u + 1).filter(d).map(f);
|
|
76
|
+
return !m && F[0]?.page === 2 && F.unshift(f(1)), !p && F[F.length - 1]?.page === u - 1 && F.push(f(u)), {
|
|
77
77
|
totalPages: u,
|
|
78
78
|
resultsFrom: s,
|
|
79
79
|
resultsTo: a,
|
|
80
80
|
current: l,
|
|
81
81
|
prev: h,
|
|
82
|
-
next:
|
|
82
|
+
next: v,
|
|
83
83
|
first: m,
|
|
84
|
-
last:
|
|
85
|
-
pages:
|
|
84
|
+
last: p,
|
|
85
|
+
pages: F
|
|
86
86
|
};
|
|
87
87
|
}, [n, t, e?.width]);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
const [e, n] =
|
|
91
|
-
return
|
|
89
|
+
function fe() {
|
|
90
|
+
const [e, n] = b([]), [t, o] = b([]);
|
|
91
|
+
return P(() => {
|
|
92
92
|
z(async (r) => {
|
|
93
|
-
const { products:
|
|
94
|
-
n(
|
|
93
|
+
const { products: c, segments: i } = await r.getSearchSessionParams();
|
|
94
|
+
n(i ?? []), o(c?.personalizationBoost ?? []);
|
|
95
95
|
});
|
|
96
96
|
}, []), {
|
|
97
97
|
segments: e,
|
|
@@ -99,19 +99,19 @@ function de() {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
function j() {
|
|
102
|
-
const { facets: e } =
|
|
102
|
+
const { facets: e } = S((s) => ({
|
|
103
103
|
facets: s.response.products?.facets ?? []
|
|
104
|
-
})), { replaceFilter: n, toggleProductFilter: t } =
|
|
104
|
+
})), { replaceFilter: n, toggleProductFilter: t } = A(), o = g(
|
|
105
105
|
(s) => {
|
|
106
106
|
const a = e?.find((l) => l.type === "stats" && l.field === s);
|
|
107
107
|
if (a && "min" in a && "max" in a)
|
|
108
108
|
return a;
|
|
109
109
|
},
|
|
110
110
|
[e]
|
|
111
|
-
), r =
|
|
111
|
+
), r = g(
|
|
112
112
|
(s) => e?.find((a) => a.field === s)?.name ?? s,
|
|
113
113
|
[e]
|
|
114
|
-
),
|
|
114
|
+
), c = g((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), i = g((s) => ({
|
|
115
115
|
...s,
|
|
116
116
|
range: s.range?.map((a) => ({
|
|
117
117
|
gt: a.gt ? Number(a.gt) : a.gt,
|
|
@@ -119,18 +119,18 @@ function j() {
|
|
|
119
119
|
lt: a.lt ? Number(a.lt) : a.lt,
|
|
120
120
|
lte: a.lte ? Number(a.lte) : a.lte
|
|
121
121
|
}))
|
|
122
|
-
}), []), u =
|
|
122
|
+
}), []), u = g(
|
|
123
123
|
(s) => (s.value ?? []).map((l) => ({
|
|
124
124
|
value: l,
|
|
125
125
|
field: s.field,
|
|
126
126
|
name: r(s.field),
|
|
127
|
-
filter:
|
|
127
|
+
filter: i(s),
|
|
128
128
|
remove: () => {
|
|
129
129
|
t(s.field, l, !1);
|
|
130
130
|
}
|
|
131
131
|
})),
|
|
132
|
-
[
|
|
133
|
-
), d =
|
|
132
|
+
[i, r, t]
|
|
133
|
+
), d = g(
|
|
134
134
|
(s) => (s.range ?? []).map((l) => {
|
|
135
135
|
const f = l.gte ?? l.gt ?? o(s.field)?.min, h = l.lte ?? l.lt ?? o(s.field)?.max;
|
|
136
136
|
if (f !== void 0 && h !== void 0)
|
|
@@ -138,119 +138,126 @@ function j() {
|
|
|
138
138
|
value: `${f} - ${h}`,
|
|
139
139
|
field: s.field,
|
|
140
140
|
name: r(s.field),
|
|
141
|
-
filter:
|
|
141
|
+
filter: i(s),
|
|
142
142
|
remove: () => {
|
|
143
143
|
n(s.field, void 0);
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
}).filter(Boolean),
|
|
147
|
-
[
|
|
147
|
+
[i, o, r, n]
|
|
148
148
|
);
|
|
149
149
|
return {
|
|
150
|
-
selectFilters:
|
|
150
|
+
selectFilters: c,
|
|
151
151
|
toValueFilter: u,
|
|
152
152
|
toRangeFilter: d
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
function q() {
|
|
156
|
-
const { filter: e } =
|
|
156
|
+
const { filter: e } = S((u) => ({
|
|
157
157
|
filter: u.query.products?.filter ?? []
|
|
158
|
-
})), { updateSearch: n } =
|
|
158
|
+
})), { updateSearch: n } = A(), { selectFilters: t, toValueFilter: o, toRangeFilter: r } = j(), c = y(() => e ? e.filter(t).flatMap((u) => "value" in u ? o(u) : "range" in u ? r(u) : []).filter(Boolean) : [], [e, t, r, o]), i = g(() => {
|
|
159
159
|
n({
|
|
160
160
|
products: {
|
|
161
161
|
filter: []
|
|
162
162
|
}
|
|
163
|
-
}),
|
|
163
|
+
}), C({
|
|
164
164
|
event: "events/removeAllFilters",
|
|
165
165
|
params: null
|
|
166
166
|
});
|
|
167
167
|
}, [n]);
|
|
168
168
|
return {
|
|
169
169
|
/** Selected filters array. */
|
|
170
|
-
filters:
|
|
170
|
+
filters: c,
|
|
171
171
|
/** Should remove all selected filters. */
|
|
172
|
-
removeAll:
|
|
172
|
+
removeAll: i
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
function E(e) {
|
|
176
|
-
const { replaceFilter: n } =
|
|
177
|
-
query:
|
|
178
|
-
products:
|
|
179
|
-
})), r = o?.facets?.find((
|
|
180
|
-
|
|
181
|
-
}, []),
|
|
182
|
-
([
|
|
176
|
+
const { replaceFilter: n } = A(), { query: t, products: o } = S((p) => ({
|
|
177
|
+
query: p.query,
|
|
178
|
+
products: p.response.products
|
|
179
|
+
})), r = o?.facets?.find((p) => p.id === e), c = t.products?.filter?.find((p) => p.field === r?.field), [i, u] = B(c), d = r && "min" in r ? Math.floor(r.min ?? 0) : 0, s = r && "max" in r ? Math.ceil(r.max ?? 0) : 0, a = y(() => [i ?? d, u ?? s], [i, u, d, s]), l = i !== void 0 || u !== void 0, [f, h] = b(l), v = g(() => {
|
|
180
|
+
h((p) => !p);
|
|
181
|
+
}, []), m = g(
|
|
182
|
+
([p, F]) => {
|
|
183
183
|
if (!r)
|
|
184
184
|
return;
|
|
185
|
-
const
|
|
186
|
-
n(r.field,
|
|
185
|
+
const w = D(p, F, d, s);
|
|
186
|
+
n(r.field, w);
|
|
187
187
|
},
|
|
188
|
-
[
|
|
188
|
+
[d, s, n, r]
|
|
189
189
|
);
|
|
190
|
-
return
|
|
190
|
+
return N({
|
|
191
191
|
event: "events/removeAllFilters",
|
|
192
192
|
callback: () => {
|
|
193
|
-
|
|
193
|
+
h(!1);
|
|
194
194
|
}
|
|
195
195
|
}), r ? {
|
|
196
196
|
/** Min value */
|
|
197
|
-
min:
|
|
197
|
+
min: d,
|
|
198
198
|
/** Max value */
|
|
199
|
-
max:
|
|
199
|
+
max: s,
|
|
200
200
|
/** Range value */
|
|
201
|
-
range:
|
|
201
|
+
range: a,
|
|
202
202
|
/** Update range function */
|
|
203
|
-
updateRange:
|
|
203
|
+
updateRange: m,
|
|
204
204
|
/** Is the range filter active */
|
|
205
|
-
active:
|
|
205
|
+
active: f,
|
|
206
206
|
/** Toggle active state function */
|
|
207
|
-
toggleActive:
|
|
208
|
-
} :
|
|
209
|
-
min: 0,
|
|
210
|
-
max: 0,
|
|
211
|
-
range: [0, 0],
|
|
212
|
-
active: !1,
|
|
213
|
-
toggleActive: () => {
|
|
214
|
-
},
|
|
215
|
-
updateRange: () => {
|
|
216
|
-
}
|
|
217
|
-
};
|
|
207
|
+
toggleActive: v
|
|
208
|
+
} : V;
|
|
218
209
|
}
|
|
219
|
-
|
|
210
|
+
const V = {
|
|
211
|
+
min: 0,
|
|
212
|
+
max: 0,
|
|
213
|
+
range: [0, 0],
|
|
214
|
+
active: !1,
|
|
215
|
+
toggleActive: () => {
|
|
216
|
+
},
|
|
217
|
+
updateRange: () => {
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
function B(e) {
|
|
220
221
|
const n = e?.range?.[0];
|
|
221
|
-
return typeof n == "object" && ("gte" in n || "lte" in n) ? [
|
|
222
|
+
return typeof n == "object" && ("gte" in n || "lte" in n) ? [R(n.gte), R(n.lte)] : [void 0, void 0];
|
|
222
223
|
}
|
|
223
224
|
function D(e, n, t, o) {
|
|
224
|
-
const r = e !== void 0 ? Math.floor(e) : void 0,
|
|
225
|
-
if ((t === r || !
|
|
225
|
+
const r = e !== void 0 ? Math.floor(e) : void 0, c = n !== void 0 ? Math.ceil(n) : void 0, i = r !== void 0, u = c !== void 0;
|
|
226
|
+
if ((t === r || !i) && (o === c || !u))
|
|
226
227
|
return;
|
|
227
228
|
const d = {};
|
|
228
|
-
return
|
|
229
|
+
return i && r !== t && (d.gte = r.toString()), u && c !== o && (d.lte = c.toString()), Object.keys(d).length > 0 ? d : void 0;
|
|
229
230
|
}
|
|
230
|
-
function
|
|
231
|
-
const { min: t, max: o, range: r, updateRange:
|
|
232
|
-
const l =
|
|
231
|
+
function ge(e, n) {
|
|
232
|
+
const { min: t, max: o, range: r, updateRange: c } = E(e), { filters: i } = q(), u = y(() => {
|
|
233
|
+
const l = i.find((m) => m?.filter?.range);
|
|
233
234
|
let f = null;
|
|
234
235
|
if (l) {
|
|
235
236
|
const m = l.filter.range?.[0];
|
|
236
|
-
f = [
|
|
237
|
+
f = [R(m?.gte), R(m?.lte)];
|
|
237
238
|
}
|
|
238
239
|
const h = [];
|
|
239
|
-
let
|
|
240
|
-
for (;
|
|
241
|
-
const m =
|
|
240
|
+
let v = Math.floor(t / n) * n;
|
|
241
|
+
for (; v < o; ) {
|
|
242
|
+
const m = v + n, p = f && f[0] === v && f[1] === m;
|
|
242
243
|
h.push({
|
|
243
|
-
min:
|
|
244
|
+
min: v,
|
|
244
245
|
max: m,
|
|
245
|
-
selected:
|
|
246
|
-
}),
|
|
246
|
+
selected: p
|
|
247
|
+
}), v = m;
|
|
247
248
|
}
|
|
248
249
|
return h;
|
|
249
|
-
}, [
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
}, [i, t, o, n]), d = g(
|
|
251
|
+
(l) => {
|
|
252
|
+
c([l, r[1]]);
|
|
253
|
+
},
|
|
254
|
+
[r, c]
|
|
255
|
+
), s = g(
|
|
256
|
+
(l) => {
|
|
257
|
+
c([r[0], l]);
|
|
258
|
+
},
|
|
259
|
+
[r, c]
|
|
260
|
+
), a = t !== r[0] || o !== r[1];
|
|
254
261
|
return {
|
|
255
262
|
/** Minimum value */
|
|
256
263
|
min: t,
|
|
@@ -259,7 +266,7 @@ function fe(e, n) {
|
|
|
259
266
|
/** Range value */
|
|
260
267
|
range: r,
|
|
261
268
|
/** Update range function */
|
|
262
|
-
updateRange:
|
|
269
|
+
updateRange: c,
|
|
263
270
|
/** Ranges */
|
|
264
271
|
ranges: u,
|
|
265
272
|
/** Handle min change */
|
|
@@ -270,27 +277,30 @@ function fe(e, n) {
|
|
|
270
277
|
isSelected: a
|
|
271
278
|
};
|
|
272
279
|
}
|
|
273
|
-
function
|
|
274
|
-
const { products: e, keywords: n } =
|
|
280
|
+
function pe() {
|
|
281
|
+
const { products: e, keywords: n } = S((t) => ({
|
|
282
|
+
products: t.response.products ?? { hits: [], total: 0 },
|
|
283
|
+
keywords: t.response.keywords ?? { hits: [], total: 0 }
|
|
284
|
+
}));
|
|
275
285
|
return {
|
|
276
286
|
/** Array of products */
|
|
277
|
-
products: e
|
|
287
|
+
products: e,
|
|
278
288
|
/** Array of keywords */
|
|
279
|
-
keywords: n
|
|
289
|
+
keywords: n
|
|
280
290
|
};
|
|
281
291
|
}
|
|
282
|
-
function
|
|
283
|
-
const e =
|
|
284
|
-
return
|
|
292
|
+
function me() {
|
|
293
|
+
const e = S((t) => t.query.products?.filter);
|
|
294
|
+
return y(() => e ? e.reduce((t, o) => t + (Array.isArray(o.value) ? o.value.length : 1), 0) : 0, [e]);
|
|
285
295
|
}
|
|
286
296
|
const $ = 5 * 60 * 1e3, L = /* @__PURE__ */ new Map();
|
|
287
|
-
function
|
|
288
|
-
const [n, t] =
|
|
297
|
+
function he(e) {
|
|
298
|
+
const [n, t] = b({
|
|
289
299
|
product: null,
|
|
290
300
|
loading: !0,
|
|
291
301
|
error: null
|
|
292
302
|
});
|
|
293
|
-
return
|
|
303
|
+
return P(() => {
|
|
294
304
|
if (!e) {
|
|
295
305
|
t({
|
|
296
306
|
product: null,
|
|
@@ -304,7 +314,7 @@ function me(e) {
|
|
|
304
314
|
loading: !0,
|
|
305
315
|
error: null
|
|
306
316
|
}));
|
|
307
|
-
const o =
|
|
317
|
+
const o = _(e);
|
|
308
318
|
if (o) {
|
|
309
319
|
t({
|
|
310
320
|
product: o,
|
|
@@ -313,8 +323,8 @@ function me(e) {
|
|
|
313
323
|
});
|
|
314
324
|
return;
|
|
315
325
|
}
|
|
316
|
-
|
|
317
|
-
|
|
326
|
+
U(e).then((r) => {
|
|
327
|
+
H(e, r), t({
|
|
318
328
|
product: r,
|
|
319
329
|
loading: !1,
|
|
320
330
|
error: null
|
|
@@ -328,45 +338,45 @@ function me(e) {
|
|
|
328
338
|
});
|
|
329
339
|
}, [e]), n;
|
|
330
340
|
}
|
|
331
|
-
async function
|
|
341
|
+
async function U(e) {
|
|
332
342
|
const n = await fetch(`/products/${e}.js`);
|
|
333
343
|
if (!n.ok)
|
|
334
344
|
throw new Error(`Failed to fetch product: ${n.status} ${n.statusText}`);
|
|
335
345
|
return n.json();
|
|
336
346
|
}
|
|
337
|
-
function
|
|
347
|
+
function _(e) {
|
|
338
348
|
const n = L.get(e);
|
|
339
349
|
return n ? Date.now() - n.created > $ ? (L.delete(e), null) : n.product : null;
|
|
340
350
|
}
|
|
341
|
-
function
|
|
351
|
+
function H(e, n) {
|
|
342
352
|
L.set(e, {
|
|
343
353
|
product: n,
|
|
344
354
|
created: Date.now()
|
|
345
355
|
});
|
|
346
356
|
}
|
|
347
|
-
function
|
|
357
|
+
function x(e) {
|
|
348
358
|
return e && !Number.isNaN(e) ? e : 0;
|
|
349
359
|
}
|
|
350
|
-
function
|
|
351
|
-
const { from: t, size: o, total: r } =
|
|
352
|
-
from:
|
|
353
|
-
size:
|
|
354
|
-
total:
|
|
355
|
-
})), { updateSearch:
|
|
360
|
+
function ve(e, n) {
|
|
361
|
+
const { from: t, size: o, total: r } = S((s) => ({
|
|
362
|
+
from: x(s.query.products?.from ?? 0),
|
|
363
|
+
size: x(s.response?.products?.size ?? n),
|
|
364
|
+
total: x(s.response?.products?.total ?? 0)
|
|
365
|
+
})), { updateSearch: c } = A(), i = t + o, u = y(() => [...e].reverse().filter((s) => s < r), [e, r]), d = g(
|
|
356
366
|
(s) => {
|
|
357
|
-
|
|
367
|
+
c({
|
|
358
368
|
products: {
|
|
359
|
-
size:
|
|
369
|
+
size: R(s)
|
|
360
370
|
}
|
|
361
371
|
});
|
|
362
372
|
},
|
|
363
|
-
[
|
|
373
|
+
[c]
|
|
364
374
|
);
|
|
365
375
|
return {
|
|
366
376
|
/** from value */
|
|
367
377
|
from: t,
|
|
368
378
|
/** to value */
|
|
369
|
-
to:
|
|
379
|
+
to: i,
|
|
370
380
|
/** total value */
|
|
371
381
|
total: r,
|
|
372
382
|
/** size value */
|
|
@@ -377,26 +387,29 @@ function he(e, n) {
|
|
|
377
387
|
handleSizeChange: d
|
|
378
388
|
};
|
|
379
389
|
}
|
|
380
|
-
function
|
|
390
|
+
function I(e, n) {
|
|
381
391
|
return e.length !== n.length ? !1 : e.every((t) => n.find((o) => t.field === o.field && t.order === o.order));
|
|
382
392
|
}
|
|
383
|
-
function
|
|
384
|
-
const n =
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
/** Set sort function */
|
|
389
|
-
setSort: (i) => {
|
|
390
|
-
const c = e.find((u) => u.id === i);
|
|
391
|
-
c && t({
|
|
393
|
+
function Se(e) {
|
|
394
|
+
const n = S((c) => c.query), { updateSearch: t } = A(), o = e.find((c) => I(c.value.sort, n.products?.sort || []))?.id ?? e[0]?.id, r = g(
|
|
395
|
+
(c) => {
|
|
396
|
+
const i = e.find((u) => u.id === c);
|
|
397
|
+
i && t({
|
|
392
398
|
products: {
|
|
393
|
-
sort:
|
|
399
|
+
sort: i.value.sort
|
|
394
400
|
}
|
|
395
401
|
});
|
|
396
|
-
}
|
|
402
|
+
},
|
|
403
|
+
[e, t]
|
|
404
|
+
);
|
|
405
|
+
return {
|
|
406
|
+
/** Active sort */
|
|
407
|
+
activeSort: o,
|
|
408
|
+
/** Set sort function */
|
|
409
|
+
setSort: r
|
|
397
410
|
};
|
|
398
411
|
}
|
|
399
|
-
const M = window.SpeechRecognition || window.webkitSpeechRecognition,
|
|
412
|
+
const M = window.SpeechRecognition || window.webkitSpeechRecognition, K = !!(M && typeof M == "function");
|
|
400
413
|
function Z() {
|
|
401
414
|
return {
|
|
402
415
|
listening: !1,
|
|
@@ -412,102 +425,102 @@ function G({
|
|
|
412
425
|
onResult: t,
|
|
413
426
|
onError: o
|
|
414
427
|
} = {}) {
|
|
415
|
-
const [r,
|
|
428
|
+
const [r, c] = b(!1), i = X(null), u = g(() => {
|
|
416
429
|
const s = new M();
|
|
417
|
-
s.lang = e, s.interimResults = n, s.onstart = () =>
|
|
430
|
+
s.lang = e, s.interimResults = n, s.onstart = () => c(!0), t && (s.onresult = (a) => {
|
|
418
431
|
const { transcript: l } = a.results?.[0]?.[0];
|
|
419
432
|
t(l);
|
|
420
|
-
}), o && (s.onerror = (a) => o(a.error)), s.onend = () =>
|
|
421
|
-
}, [e, n, o, t]), d =
|
|
422
|
-
|
|
423
|
-
}, [
|
|
433
|
+
}), o && (s.onerror = (a) => o(a.error)), s.onend = () => c(!1), i.current = s, s.start();
|
|
434
|
+
}, [e, n, o, t]), d = g(() => {
|
|
435
|
+
i.current?.stop();
|
|
436
|
+
}, [i]);
|
|
424
437
|
return {
|
|
425
438
|
listening: r,
|
|
426
439
|
startListening: u,
|
|
427
440
|
stopListening: d
|
|
428
441
|
};
|
|
429
442
|
}
|
|
430
|
-
const
|
|
443
|
+
const ye = K ? G : Z;
|
|
431
444
|
function J(e, n) {
|
|
432
445
|
if (!e.length || !n.length) return [];
|
|
433
446
|
const t = n.reduce((o, r) => (o[r] = {}, o), {});
|
|
434
447
|
return e.forEach((o) => {
|
|
435
|
-
o.customFields?.forEach(({ key: r, value:
|
|
436
|
-
const
|
|
437
|
-
n.includes(
|
|
448
|
+
o.customFields?.forEach(({ key: r, value: c }) => {
|
|
449
|
+
const i = r.toLowerCase();
|
|
450
|
+
n.includes(i) && (t[i][c] = t[i][c] || [], t[i][c].push(o));
|
|
438
451
|
});
|
|
439
452
|
}), Object.entries(t).filter((o) => Object.keys(o[1]).length).map(([o, r]) => ({
|
|
440
453
|
field: o,
|
|
441
|
-
options: Object.entries(r).map(([
|
|
442
|
-
value:
|
|
443
|
-
skus:
|
|
454
|
+
options: Object.entries(r).map(([c, i]) => ({
|
|
455
|
+
value: c,
|
|
456
|
+
skus: i,
|
|
444
457
|
unavailable: !1,
|
|
445
458
|
selected: !1
|
|
446
459
|
}))
|
|
447
460
|
}));
|
|
448
461
|
}
|
|
449
|
-
function
|
|
462
|
+
function Q(e, n) {
|
|
450
463
|
return e.length ? e.map(({ field: t, options: o }) => ({
|
|
451
464
|
field: t,
|
|
452
465
|
options: o.map((r) => {
|
|
453
|
-
const
|
|
466
|
+
const c = !r.skus?.some((u) => Object.entries(n).every(([d, s]) => d === t ? !0 : u.customFields?.find((l) => l.key.toLowerCase() === d)?.value === s)), i = n[t] === r.value;
|
|
454
467
|
return {
|
|
455
468
|
...r,
|
|
456
|
-
unavailable:
|
|
457
|
-
selected:
|
|
469
|
+
unavailable: c,
|
|
470
|
+
selected: i
|
|
458
471
|
};
|
|
459
472
|
})
|
|
460
473
|
})) : [];
|
|
461
474
|
}
|
|
462
|
-
const
|
|
463
|
-
function
|
|
464
|
-
if (
|
|
465
|
-
return 1e3 +
|
|
475
|
+
const T = ["4XS", "3XS", "2XS", "XXS", "XS", "S", "M", "L", "XL", "XXL", "2XL", "XXXL", "3XL", "4XL"];
|
|
476
|
+
function W(e) {
|
|
477
|
+
if (T.includes(e))
|
|
478
|
+
return 1e3 + T.indexOf(e);
|
|
466
479
|
const n = parseFloat(e);
|
|
467
480
|
return isNaN(n) ? e : n;
|
|
468
481
|
}
|
|
469
|
-
function
|
|
482
|
+
function Y(e, n) {
|
|
470
483
|
return [...n].sort((t, o) => {
|
|
471
|
-
const [r,
|
|
472
|
-
return r <
|
|
484
|
+
const [r, c] = [t.value, o.value].map(W);
|
|
485
|
+
return r < c ? -1 : 1;
|
|
473
486
|
});
|
|
474
487
|
}
|
|
475
|
-
function
|
|
476
|
-
const [t, o] =
|
|
488
|
+
function Fe(e = [], n = []) {
|
|
489
|
+
const [t, o] = b({}), r = y(() => J(e, n).map(({ field: s, options: a }) => ({
|
|
477
490
|
field: s,
|
|
478
|
-
options:
|
|
479
|
-
})), [e, n]),
|
|
491
|
+
options: Y(s, a)
|
|
492
|
+
})), [e, n]), c = y(() => Q(r, t), [r, t]), i = g((d, s) => {
|
|
480
493
|
o((a) => {
|
|
481
494
|
const l = { ...a };
|
|
482
495
|
return l[d] === s ? delete l[d] : l[d] = s, l;
|
|
483
496
|
});
|
|
484
|
-
}, []), u =
|
|
497
|
+
}, []), u = y(() => Object.keys(t).filter((a) => t[a]).length === 0 ? [] : c.filter(({ field: a }) => t[a]).map(({ field: a, options: l }) => {
|
|
485
498
|
const f = t[a];
|
|
486
|
-
return l.find((
|
|
487
|
-
}).reduce((a, l) => a.filter((f) => l.includes(f))), [
|
|
488
|
-
return { swatches:
|
|
499
|
+
return l.find((v) => v.value === f)?.skus ?? [];
|
|
500
|
+
}).reduce((a, l) => a.filter((f) => l.includes(f))), [c, t]);
|
|
501
|
+
return { swatches: c, toggleOption: i, matchedSkus: u };
|
|
489
502
|
}
|
|
490
503
|
export {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
504
|
+
xe as addToHistory,
|
|
505
|
+
Le as getSavedHistory,
|
|
506
|
+
K as speechToTextSupported,
|
|
507
|
+
A as useActions,
|
|
508
|
+
ae as useDecoratedSearchResults,
|
|
509
|
+
ue as useFacet,
|
|
510
|
+
le as useFacets,
|
|
511
|
+
Me as useHistory,
|
|
512
|
+
Ae as useLoadMore,
|
|
513
|
+
S as useNostoAppState,
|
|
514
|
+
de as usePagination,
|
|
515
|
+
fe as usePersonalization,
|
|
503
516
|
q as useProductFilters,
|
|
504
517
|
E as useRange,
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
518
|
+
ge as useRangeSelector,
|
|
519
|
+
pe as useResponse,
|
|
520
|
+
me as useSelectedFiltersCount,
|
|
521
|
+
he as useShopifyProduct,
|
|
522
|
+
ve as useSizeOptions,
|
|
523
|
+
Se as useSort,
|
|
524
|
+
ye as useSpeechToText,
|
|
525
|
+
Fe as useSwatches
|
|
513
526
|
};
|
|
@@ -31,6 +31,13 @@ type RangeProps = [number | undefined, number | undefined];
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
export declare function useRange(id: string): {
|
|
34
|
+
readonly min: 0;
|
|
35
|
+
readonly max: 0;
|
|
36
|
+
readonly range: readonly [0, 0];
|
|
37
|
+
readonly active: false;
|
|
38
|
+
readonly toggleActive: () => void;
|
|
39
|
+
readonly updateRange: () => void;
|
|
40
|
+
} | {
|
|
34
41
|
/** Min value */
|
|
35
42
|
min: number;
|
|
36
43
|
/** Max value */
|
|
@@ -80,9 +80,9 @@ export declare function useRangeSelector(id: string, rangeSize: number): {
|
|
|
80
80
|
/** Maximum value */
|
|
81
81
|
max: number;
|
|
82
82
|
/** Range value */
|
|
83
|
-
range: number[];
|
|
83
|
+
range: number[] | readonly [0, 0];
|
|
84
84
|
/** Update range function */
|
|
85
|
-
updateRange: ([from, to]: [number | undefined, number | undefined]) => void;
|
|
85
|
+
updateRange: (([from, to]: [number | undefined, number | undefined]) => void) | (() => void);
|
|
86
86
|
/** Ranges */
|
|
87
87
|
ranges: {
|
|
88
88
|
min: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.21.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -97,22 +97,22 @@
|
|
|
97
97
|
"prepare": "husky"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
|
-
"@commitlint/cli": "^20.
|
|
100
|
+
"@commitlint/cli": "^20.1.0",
|
|
101
101
|
"@commitlint/config-conventional": "^20.0.0",
|
|
102
|
-
"@nosto/nosto-js": "^2.
|
|
102
|
+
"@nosto/nosto-js": "^2.8.0",
|
|
103
103
|
"@testing-library/dom": "^10.4.1",
|
|
104
|
-
"@types/dom-speech-recognition": "^0.0.
|
|
104
|
+
"@types/dom-speech-recognition": "^0.0.7",
|
|
105
105
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
106
|
-
"@types/node": "^24.
|
|
106
|
+
"@types/node": "^24.7.0",
|
|
107
107
|
"@vitest/coverage-v8": "^3.2.4",
|
|
108
108
|
"concurrently": "^9.2.1",
|
|
109
109
|
"copyfiles": "^2.4.1",
|
|
110
|
-
"eslint": "^9.
|
|
110
|
+
"eslint": "^9.37.0",
|
|
111
111
|
"eslint-config-prettier": "^10.1.8",
|
|
112
112
|
"eslint-plugin-barrel-files": "^3.0.1",
|
|
113
113
|
"eslint-plugin-prettier": "^5.5.4",
|
|
114
114
|
"eslint-plugin-react": "^7.37.5",
|
|
115
|
-
"eslint-plugin-react-hooks": "^
|
|
115
|
+
"eslint-plugin-react-hooks": "^6.1.1",
|
|
116
116
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
117
117
|
"eslint-plugin-unused-imports": "^4.2.0",
|
|
118
118
|
"husky": "^9.1.7",
|
|
@@ -120,9 +120,9 @@
|
|
|
120
120
|
"jsdom": "^27.0.0",
|
|
121
121
|
"prettier": "^3.6.2",
|
|
122
122
|
"typedoc": "^0.28.13",
|
|
123
|
-
"typescript": "^5.9.
|
|
124
|
-
"typescript-eslint": "^8.
|
|
125
|
-
"vite": "^7.1.
|
|
123
|
+
"typescript": "^5.9.3",
|
|
124
|
+
"typescript-eslint": "^8.46.0",
|
|
125
|
+
"vite": "^7.1.9",
|
|
126
126
|
"vite-plugin-dts": "^4.5.4",
|
|
127
127
|
"vitest": "^3.1.3"
|
|
128
128
|
},
|