@nosto/search-js 2.13.0 → 2.15.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.
@@ -0,0 +1 @@
1
+ "use strict";const C=require("./jsxRuntime.module-B3sGoTIU.cjs"),a=require("preact/hooks");function k({onClick:i,as:n,children:t,componentProps:e}){const u=a.useCallback(s=>{i(),e&&"onClick"in e&&typeof e.onClick=="function"&&e.onClick(s)},[i,e]),c={...e,onClick:u},l=n??"a";return C.u(l,{...c,children:t})}exports.BaseElement=k;
@@ -0,0 +1,17 @@
1
+ import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
2
+ import { useCallback as o } from "preact/hooks";
3
+ function r({ onClick: t, as: C, children: l, componentProps: i }) {
4
+ const n = o(
5
+ (c) => {
6
+ t(), i && "onClick" in i && typeof i.onClick == "function" && i.onClick(c);
7
+ },
8
+ [t, i]
9
+ ), a = {
10
+ ...i,
11
+ onClick: n
12
+ };
13
+ return /* @__PURE__ */ f(C ?? "a", { ...a, children: l });
14
+ }
15
+ export {
16
+ r as B
17
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../index.es-DlUp67LT.cjs"),a=require("preact"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../configContext-BR7w4VlU.cjs"),p=require("../baseConfig-BFFqFSg5.cjs");function m(e){return e!==null&&typeof e=="object"&&"props"in e&&typeof e.type=="string"}function f({children:e,hit:t}){var n;if(!m(e))throw new Error("AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported.");const o=(n=e.props)==null?void 0:n.onClick;return a.cloneElement(e,{onClick:r=>{t&&s.s(u=>u.recordSearchClick("autocomplete",t)),typeof o=="function"&&o(r)}})}function C({as:e,componentProps:t,onSearchInput:o,children:n}){const r={...t,onInput:l=>{o(l.target)}},u=e??"input";return e||(r.type="search"),i.u(u,{...r,children:n})}const g={...p.defaultBaseConfig};function d(e){return{pageType:"autocomplete",...g,...e}}function S({config:e,store:t,children:o}){const n=t??c.createStore();return p.useCheckClientScript(),i.u(c.ConfigContext,{value:d(e),children:i.u(c.StoreContext,{value:n,children:o})})}exports.AutocompleteElement=f;exports.AutocompletePageProvider=S;exports.SearchInput=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../index.es-DlUp67LT.cjs"),p=require("preact/hooks"),m=require("../BaseElement-8qy-gSKp.cjs"),i=require("../configContext-BR7w4VlU.cjs"),l=require("../baseConfig-BFFqFSg5.cjs");function f({children:e,hit:t,as:o,componentProps:n}){const u=p.useCallback(()=>{t&&"productId"in t&&s.s(c=>c.recordSearchClick("autocomplete",t))},[t]);return r.u(m.BaseElement,{onClick:u,as:o,componentProps:n,children:e})}function C({as:e,componentProps:t,onSearchInput:o,children:n}){const u={...t,onInput:a=>{o(a.target)}},c=e??"input";return e||(u.type="search"),r.u(c,{...u,children:n})}const d={...l.defaultBaseConfig};function g(e){return{pageType:"autocomplete",...d,...e}}function S({config:e,store:t,children:o}){const n=t??i.createStore();return l.useCheckClientScript(),r.u(i.ConfigContext,{value:g(e),children:r.u(i.StoreContext,{value:n,children:o})})}exports.AutocompleteElement=f;exports.AutocompletePageProvider=S;exports.SearchInput=C;
@@ -1,5 +1,5 @@
1
1
  /** @module preact/autocomplete */
2
- export { AutocompleteElement } from './src/components/Autocomplete/AutocompleteElement';
2
+ export { AutocompleteElement, type AutocompleteElementProps } from './src/components/AutocompleteElement';
3
3
  export { SearchInput } from './src/components/SearchInput';
4
4
  export type { PublicAutocompleteConfig as AutocompleteConfig } from './src/config/pages/autocomplete/config';
5
5
  export { AutocompletePageProvider } from './src/config/pages/autocomplete/provider';
@@ -1,49 +1,45 @@
1
- import { s as c } from "../index.es-B8mbAxS4.js";
2
- import { cloneElement as a } from "preact";
3
- import { u as i } from "../jsxRuntime.module-Bzuv3cXw.js";
4
- import { c as m, S as l, C as s } from "../configContext-GuZOIX3o.js";
5
- import { d as f, u as C } from "../baseConfig-Bafl02NY.js";
6
- function g(t) {
7
- return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
1
+ import { u as c } from "../jsxRuntime.module-Bzuv3cXw.js";
2
+ import { s as p } from "../index.es-B8mbAxS4.js";
3
+ import { useCallback as m } from "preact/hooks";
4
+ import { B as i } from "../BaseElement-Df1Kv7sB.js";
5
+ import { c as l, S as f, C as s } from "../configContext-GuZOIX3o.js";
6
+ import { d as C, u as d } from "../baseConfig-Bafl02NY.js";
7
+ function P({
8
+ children: t,
9
+ hit: e,
10
+ as: o,
11
+ componentProps: r
12
+ }) {
13
+ const n = m(() => {
14
+ e && "productId" in e && p((u) => u.recordSearchClick("autocomplete", e));
15
+ }, [e]);
16
+ return /* @__PURE__ */ c(i, { onClick: n, as: o, componentProps: r, children: t });
8
17
  }
9
- function x({ children: t, hit: e }) {
10
- var n;
11
- if (!g(t))
12
- throw new Error(
13
- "AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
14
- );
15
- const o = (n = t.props) == null ? void 0 : n.onClick;
16
- return a(t, {
17
- onClick: (r) => {
18
- e && c((p) => p.recordSearchClick("autocomplete", e)), typeof o == "function" && o(r);
19
- }
20
- });
21
- }
22
- function P({ as: t, componentProps: e, onSearchInput: o, children: n }) {
23
- const r = {
18
+ function h({ as: t, componentProps: e, onSearchInput: o, children: r }) {
19
+ const n = {
24
20
  ...e,
25
- onInput: (u) => {
26
- o(u.target);
21
+ onInput: (a) => {
22
+ o(a.target);
27
23
  }
28
- }, p = t ?? "input";
29
- return t || (r.type = "search"), /* @__PURE__ */ i(p, { ...r, children: n });
24
+ }, u = t ?? "input";
25
+ return t || (n.type = "search"), /* @__PURE__ */ c(u, { ...n, children: r });
30
26
  }
31
- const d = {
32
- ...f
27
+ const g = {
28
+ ...C
33
29
  };
34
30
  function S(t) {
35
31
  return {
36
32
  pageType: "autocomplete",
37
- ...d,
33
+ ...g,
38
34
  ...t
39
35
  };
40
36
  }
41
- function T({ config: t, store: e, children: o }) {
42
- const n = e ?? m();
43
- return C(), /* @__PURE__ */ i(s, { value: S(t), children: /* @__PURE__ */ i(l, { value: n, children: o }) });
37
+ function y({ config: t, store: e, children: o }) {
38
+ const r = e ?? l();
39
+ return d(), /* @__PURE__ */ c(s, { value: S(t), children: /* @__PURE__ */ c(f, { value: r, children: o }) });
44
40
  }
45
41
  export {
46
- x as AutocompleteElement,
47
- T as AutocompletePageProvider,
48
- P as SearchInput
42
+ P as AutocompleteElement,
43
+ y as AutocompletePageProvider,
44
+ h as SearchInput
49
45
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../useLoadMore-BJWBvbZ1.cjs"),z=require("../logger-BcHMZObS.cjs"),p=require("preact/hooks"),P=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function T(e){const r=S.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&z.isPlainObject(e)?e:r}function q(e,r){var d;const t=((d=e.data)==null?void 0:d.filter(s=>s.selected).length)??0,{active:n}={active:t>0,...r},[o,i]=p.useState(n),{toggleProductFilter:c}=S.useActions(),a=p.useCallback(()=>{i(!o)},[o]);return{active:o,selectedFiltersCount:t,toggleActive:a,toggleProductFilter:c}}function L(){const{loading:e,facets:r}=S.useNostoAppState(t=>{var n,o;return{loading:t.loading,facets:((o=(n=t.response)==null?void 0:n.products)==null?void 0:o.facets)??[]}});return{loading:e,facets:r}}function O(e,r){const t=r-e;return!isNaN(t)&&t>0?new Array(r-e).fill(void 0).map((n,o)=>o+e):[]}function j(e){const{query:r,products:t}=S.useNostoAppState(n=>({query:n.query,products:n.response.products}));return p.useMemo(()=>{var F,y,R;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=r.products)==null?void 0:F.from)??0,o=(e==null?void 0:e.width)??1/0,i=Math.max(Math.floor(o-1)/2,1),c=t.size>0?Math.floor(n/t.size)+1:1,a=t.size>0?Math.ceil(t.total/t.size):0,d=A=>A>=c-i&&A<=c+i,s=n+1,l=Math.min(n+t.total,t.total),u={from:n,page:c,current:!0},g=A=>({from:(A-1)*t.size,page:A,current:A===c}),m=c>1?g(c-1):void 0,f=c<a?g(c+1):void 0,b=c-i-1>1?g(1):void 0,h=c+i+1<a?g(a):void 0,v=O(1,a+1).filter(d).map(g);return!b&&((y=v[0])==null?void 0:y.page)===2&&v.unshift(g(1)),!h&&((R=v[v.length-1])==null?void 0:R.page)===a-1&&v.push(g(a)),{totalPages:a,resultsFrom:s,resultsTo:l,current:u,prev:m,next:f,first:b,last:h,pages:v}},[r,t,e==null?void 0:e.width])}function V(){const[e,r]=p.useState([]),[t,n]=p.useState([]);return p.useEffect(()=>{P.s(async o=>{const{products:i,segments:c}=await o.getSearchSessionParams();r(c??[]),n((i==null?void 0:i.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function B(){const{facets:e}=S.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:r,toggleProductFilter:t}=S.useActions(),n=p.useCallback(s=>{const l=e==null?void 0:e.find(u=>u.type==="stats"&&u.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),o=p.useCallback(s=>{var l;return((l=e==null?void 0:e.find(u=>u.field===s))==null?void 0:l.name)??s},[e]),i=p.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),c=p.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(u=>({gt:u.gt?Number(u.gt):u.gt,gte:u.gte?Number(u.gte):u.gte,lt:u.lt?Number(u.lt):u.lt,lte:u.lte?Number(u.lte):u.lte}))}},[]),a=p.useCallback(s=>(s.value??[]).map(u=>({value:u,field:s.field,name:o(s.field),filter:c(s),remove:()=>{t(s.field,u,!1)}})),[c,o,t]),d=p.useCallback(s=>(s.range??[]).map(u=>{var f,b;const g=u.gte??u.gt??((f=n(s.field))==null?void 0:f.min),m=u.lte??u.lt??((b=n(s.field))==null?void 0:b.max);if(g!==void 0&&m!==void 0)return{value:`${g} - ${m}`,field:s.field,name:o(s.field),filter:c(s),remove:()=>{r(s.field,void 0)}}}).filter(Boolean),[c,n,o,r]);return{selectFilters:i,toValueFilter:a,toRangeFilter:d}}function C(){const{filter:e}=S.useNostoAppState(a=>{var d;return{filter:((d=a.query.products)==null?void 0:d.filter)??[]}}),{updateSearch:r}=S.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:o}=B(),i=p.useMemo(()=>e?e.filter(t).flatMap(a=>"value"in a?n(a):"range"in a?o(a):[]).filter(Boolean):[],[e,t,o,n]),c=p.useCallback(()=>{r({products:{filter:[]}})},[r]);return{filters:i,removeAll:c}}function k(e){var u,g,m;const{replaceFilter:r}=S.useActions(),{query:t,products:n}=S.useNostoAppState(f=>({query:f.query,products:f.response.products})),o=(u=n==null?void 0:n.facets)==null?void 0:u.find(f=>f.id===e);if(!o)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const i=(m=(g=t.products)==null?void 0:g.filter)==null?void 0:m.find(f=>f.field===o.field),c=i!=null&&i.range?i.range[0]:void 0,a=typeof c=="object"&&("gte"in c||"lte"in c)?[N.parseNumber(c.gte),N.parseNumber(c.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,b])=>{const h=f!==void 0?Math.floor(f):void 0,v=b!==void 0?Math.ceil(b):void 0,F=h!==void 0,y=v!==void 0;(d===h||!F)&&(s===v||!y)?r(o.field,void 0):(d===h||!F)&&y?r(o.field,{lte:v.toString()}):(s===v||!y)&&F?r(o.field,{gte:h.toString()}):F&&y&&r(o.field,{gte:h.toString(),lte:v.toString()})};return{min:d,max:s,range:[a[0]??d,a[1]??s],updateRange:l}}function D(e,r){const{min:t,max:n,range:o,updateRange:i}=k(e),{filters:c}=C(),a=p.useMemo(()=>{var b;const u=c.find(h=>{var v;return(v=h==null?void 0:h.filter)==null?void 0:v.range});let g=null;if(u){const h=(b=u.filter.range)==null?void 0:b[0];g=[N.parseNumber(h==null?void 0:h.gte),N.parseNumber(h==null?void 0:h.lte)]}const m=[];let f=Math.floor(t/r)*r;for(;f<n;){const h=f+r,v=g&&g[0]===f&&g[1]===h;m.push({min:f,max:h,selected:v}),f=h}return m},[c,t,n,r]),d=u=>{i([u,o[1]])},s=u=>{i([o[0],u])},l=t!==o[0]||n!==o[1];return{min:t,max:n,range:o,updateRange:i,ranges:a,handleMinChange:d,handleMaxChange:s,isSelected:l}}function U(){const{products:e,keywords:r}=S.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:r??{hits:[],total:0}}}function E(){const e=S.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return p.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function M(e){return e&&!Number.isNaN(e)?e:0}function _(e,r){const{from:t,size:n,total:o}=S.useNostoAppState(s=>{var l,u,g,m,f;return{from:M(((l=s.query.products)==null?void 0:l.from)??0),size:M(((g=(u=s.response)==null?void 0:u.products)==null?void 0:g.size)??0),total:M(((f=(m=s.response)==null?void 0:m.products)==null?void 0:f.total)??0)}}),{updateSearch:i}=S.useActions(),c=t+n,a=[...e].reverse().filter(s=>s+r<o);return{from:t,to:c,total:o,size:n,sizeOptions:a,handleSizeChange:s=>{i({products:{size:N.parseNumber(s)}})}}}function $(e,r){return e.length!==r.length?!1:e.every(t=>r.find(n=>t.field===n.field&&t.order===n.order))}function I(e){var i,c;const r=S.useNostoAppState(a=>a.query),{updateSearch:t}=S.useActions();return{activeSort:((i=e.find(a=>{var d;return $(a.value.sort,((d=r.products)==null?void 0:d.sort)||[])}))==null?void 0:i.id)??((c=e[0])==null?void 0:c.id),setSort:a=>{const d=e.find(s=>s.id===a);d&&t({products:{sort:d.value.sort}})}}}const w=window.SpeechRecognition||window.webkitSpeechRecognition,x=!!(w&&typeof w=="function");function G(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function H({language:e="en-US",interimResults:r=!1}={}){const[t,n]=p.useState(!1),o=p.useRef(null),i=p.useCallback(({onResult:a,onError:d})=>{const s=new w;s.lang=e,s.interimResults=r,s.onstart=()=>n(!0),s.onresult=l=>{var g,m;const{transcript:u}=(m=(g=l.results)==null?void 0:g[0])==null?void 0:m[0];a(u)},d&&(s.onerror=l=>d(l.error)),s.onend=()=>n(!1),o.current=s,s.start()},[e,r]),c=p.useCallback(()=>{var a;(a=o.current)==null||a.stop()},[o]);return{listening:t,startListening:i,stopListening:c}}const J=x?H:G;function K(e,r){if(!e.length||!r.length)return[];const t=r.reduce((n,o)=>(n[o]={},n),{});return e.forEach(n=>{var o;(o=n.customFields)==null||o.forEach(({key:i,value:c})=>{const a=i.toLowerCase();r.includes(a)&&(t[a][c]=t[a][c]||[],t[a][c].push(n))})}),Object.entries(t).filter(n=>Object.keys(n[1]).length).map(([n,o])=>({field:n,options:Object.entries(o).map(([i,c])=>({value:i,skus:c,unavailable:!1,selected:!1}))}))}function Q(e,r){return e.length?e.map(({field:t,options:n})=>({field:t,options:n.map(o=>{var a;const i=!((a=o.skus)!=null&&a.some(d=>Object.entries(r).every(([s,l])=>{var g,m;return s===t?!0:((m=(g=d.customFields)==null?void 0:g.find(f=>f.key.toLowerCase()===s))==null?void 0:m.value)===l}))),c=r[t]===o.value;return{...o,unavailable:i,selected:c}})})):[]}function W(e=[],r=[]){const[t,n]=p.useState({}),o=p.useMemo(()=>K(e,r),[e,r]),i=p.useMemo(()=>Q(o,t),[o,t]),c=p.useCallback((d,s)=>{n(l=>{const u={...l};return u[d]===s?delete u[d]:u[d]=s,u})},[]),a=p.useMemo(()=>Object.keys(t).filter(l=>t[l]).length===0?[]:i.filter(({field:l})=>t[l]).map(({field:l,options:u})=>{const g=t[l],m=u.find(f=>f.value===g);return(m==null?void 0:m.skus)??[]}).reduce((l,u)=>l.filter(g=>u.includes(g))),[i,t]);return{swatches:i,toggleOption:c,matchedSkus:a}}exports.useActions=S.useActions;exports.useLoadMore=S.useLoadMore;exports.useNostoAppState=S.useNostoAppState;exports.speechToTextSupported=x;exports.useDecoratedSearchResults=T;exports.useFacet=q;exports.useFacets=L;exports.usePagination=j;exports.usePersonalization=V;exports.useProductFilters=C;exports.useRange=k;exports.useRangeSelector=D;exports.useResponse=U;exports.useSelectedFiltersCount=E;exports.useSizeOptions=_;exports.useSort=I;exports.useSpeechToText=J;exports.useSwatches=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../useLoadMore-BJWBvbZ1.cjs"),z=require("../logger-BcHMZObS.cjs"),p=require("preact/hooks"),P=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function T(e){const r=h.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&z.isPlainObject(e)?e:r}function q(e,r){var d;const t=((d=e.data)==null?void 0:d.filter(s=>s.selected).length)??0,{active:n}={active:t>0,...r},[o,a]=p.useState(n),{toggleProductFilter:c}=h.useActions(),i=p.useCallback(()=>{a(!o)},[o]);return{active:o,selectedFiltersCount:t,toggleActive:i,toggleProductFilter:c}}function X(){const{loading:e,facets:r}=h.useNostoAppState(t=>{var n,o;return{loading:t.loading,facets:((o=(n=t.response)==null?void 0:n.products)==null?void 0:o.facets)??[]}});return{loading:e,facets:r}}function O(e,r){const t=r-e;return!isNaN(t)&&t>0?new Array(r-e).fill(void 0).map((n,o)=>o+e):[]}function j(e){const{query:r,products:t}=h.useNostoAppState(n=>({query:n.query,products:n.response.products}));return p.useMemo(()=>{var F,y,w;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=r.products)==null?void 0:F.from)??0,o=(e==null?void 0:e.width)??1/0,a=Math.max(Math.floor(o-1)/2,1),c=t.size>0?Math.floor(n/t.size)+1:1,i=t.size>0?Math.ceil(t.total/t.size):0,d=A=>A>=c-a&&A<=c+a,s=n+1,l=Math.min(n+t.total,t.total),u={from:n,page:c,current:!0},f=A=>({from:(A-1)*t.size,page:A,current:A===c}),m=c>1?f(c-1):void 0,g=c<i?f(c+1):void 0,b=c-a-1>1?f(1):void 0,S=c+a+1<i?f(i):void 0,v=O(1,i+1).filter(d).map(f);return!b&&((y=v[0])==null?void 0:y.page)===2&&v.unshift(f(1)),!S&&((w=v[v.length-1])==null?void 0:w.page)===i-1&&v.push(f(i)),{totalPages:i,resultsFrom:s,resultsTo:l,current:u,prev:m,next:g,first:b,last:S,pages:v}},[r,t,e==null?void 0:e.width])}function V(){const[e,r]=p.useState([]),[t,n]=p.useState([]);return p.useEffect(()=>{P.s(async o=>{const{products:a,segments:c}=await o.getSearchSessionParams();r(c??[]),n((a==null?void 0:a.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function D(){const{facets:e}=h.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:r,toggleProductFilter:t}=h.useActions(),n=p.useCallback(s=>{const l=e==null?void 0:e.find(u=>u.type==="stats"&&u.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),o=p.useCallback(s=>{var l;return((l=e==null?void 0:e.find(u=>u.field===s))==null?void 0:l.name)??s},[e]),a=p.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),c=p.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(u=>({gt:u.gt?Number(u.gt):u.gt,gte:u.gte?Number(u.gte):u.gte,lt:u.lt?Number(u.lt):u.lt,lte:u.lte?Number(u.lte):u.lte}))}},[]),i=p.useCallback(s=>(s.value??[]).map(u=>({value:u,field:s.field,name:o(s.field),filter:c(s),remove:()=>{t(s.field,u,!1)}})),[c,o,t]),d=p.useCallback(s=>(s.range??[]).map(u=>{var g,b;const f=u.gte??u.gt??((g=n(s.field))==null?void 0:g.min),m=u.lte??u.lt??((b=n(s.field))==null?void 0:b.max);if(f!==void 0&&m!==void 0)return{value:`${f} - ${m}`,field:s.field,name:o(s.field),filter:c(s),remove:()=>{r(s.field,void 0)}}}).filter(Boolean),[c,n,o,r]);return{selectFilters:a,toValueFilter:i,toRangeFilter:d}}function k(){const{filter:e}=h.useNostoAppState(i=>{var d;return{filter:((d=i.query.products)==null?void 0:d.filter)??[]}}),{updateSearch:r}=h.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:o}=D(),a=p.useMemo(()=>e?e.filter(t).flatMap(i=>"value"in i?n(i):"range"in i?o(i):[]).filter(Boolean):[],[e,t,o,n]),c=p.useCallback(()=>{r({products:{filter:[]}})},[r]);return{filters:a,removeAll:c}}function x(e){var u,f,m;const{replaceFilter:r}=h.useActions(),{query:t,products:n}=h.useNostoAppState(g=>({query:g.query,products:g.response.products})),o=(u=n==null?void 0:n.facets)==null?void 0:u.find(g=>g.id===e);if(!o)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const a=(m=(f=t.products)==null?void 0:f.filter)==null?void 0:m.find(g=>g.field===o.field),c=a!=null&&a.range?a.range[0]:void 0,i=typeof c=="object"&&("gte"in c||"lte"in c)?[N.parseNumber(c.gte),N.parseNumber(c.lte)]:[void 0,void 0],d="min"in o?Math.floor(o.min):0,s="max"in o?Math.ceil(o.max):0,l=([g,b])=>{const S=g!==void 0?Math.floor(g):void 0,v=b!==void 0?Math.ceil(b):void 0,F=S!==void 0,y=v!==void 0;(d===S||!F)&&(s===v||!y)?r(o.field,void 0):(d===S||!F)&&y?r(o.field,{lte:v.toString()}):(s===v||!y)&&F?r(o.field,{gte:S.toString()}):F&&y&&r(o.field,{gte:S.toString(),lte:v.toString()})};return{min:d,max:s,range:[i[0]??d,i[1]??s],updateRange:l}}function B(e,r){const{min:t,max:n,range:o,updateRange:a}=x(e),{filters:c}=k(),i=p.useMemo(()=>{var b;const u=c.find(S=>{var v;return(v=S==null?void 0:S.filter)==null?void 0:v.range});let f=null;if(u){const S=(b=u.filter.range)==null?void 0:b[0];f=[N.parseNumber(S==null?void 0:S.gte),N.parseNumber(S==null?void 0:S.lte)]}const m=[];let g=Math.floor(t/r)*r;for(;g<n;){const S=g+r,v=f&&f[0]===g&&f[1]===S;m.push({min:g,max:S,selected:v}),g=S}return m},[c,t,n,r]),d=u=>{a([u,o[1]])},s=u=>{a([o[0],u])},l=t!==o[0]||n!==o[1];return{min:t,max:n,range:o,updateRange:a,ranges:i,handleMinChange:d,handleMaxChange:s,isSelected:l}}function E(){const{products:e,keywords:r}=h.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:r??{hits:[],total:0}}}function _(){const e=h.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return p.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function M(e){return e&&!Number.isNaN(e)?e:0}function U(e,r){const{from:t,size:n,total:o}=h.useNostoAppState(s=>{var l,u,f,m,g;return{from:M(((l=s.query.products)==null?void 0:l.from)??0),size:M(((f=(u=s.response)==null?void 0:u.products)==null?void 0:f.size)??0),total:M(((g=(m=s.response)==null?void 0:m.products)==null?void 0:g.total)??0)}}),{updateSearch:a}=h.useActions(),c=t+n,i=[...e].reverse().filter(s=>s+r<o);return{from:t,to:c,total:o,size:n,sizeOptions:i,handleSizeChange:s=>{a({products:{size:N.parseNumber(s)}})}}}function $(e,r){return e.length!==r.length?!1:e.every(t=>r.find(n=>t.field===n.field&&t.order===n.order))}function I(e){var a,c;const r=h.useNostoAppState(i=>i.query),{updateSearch:t}=h.useActions();return{activeSort:((a=e.find(i=>{var d;return $(i.value.sort,((d=r.products)==null?void 0:d.sort)||[])}))==null?void 0:a.id)??((c=e[0])==null?void 0:c.id),setSort:i=>{const d=e.find(s=>s.id===i);d&&t({products:{sort:d.value.sort}})}}}const R=window.SpeechRecognition||window.webkitSpeechRecognition,L=!!(R&&typeof R=="function");function Z(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function G({language:e="en-US",interimResults:r=!1}={}){const[t,n]=p.useState(!1),o=p.useRef(null),a=p.useCallback(({onResult:i,onError:d})=>{const s=new R;s.lang=e,s.interimResults=r,s.onstart=()=>n(!0),s.onresult=l=>{var f,m;const{transcript:u}=(m=(f=l.results)==null?void 0:f[0])==null?void 0:m[0];i(u)},d&&(s.onerror=l=>d(l.error)),s.onend=()=>n(!1),o.current=s,s.start()},[e,r]),c=p.useCallback(()=>{var i;(i=o.current)==null||i.stop()},[o]);return{listening:t,startListening:a,stopListening:c}}const H=L?G:Z;function J(e,r){if(!e.length||!r.length)return[];const t=r.reduce((n,o)=>(n[o]={},n),{});return e.forEach(n=>{var o;(o=n.customFields)==null||o.forEach(({key:a,value:c})=>{const i=a.toLowerCase();r.includes(i)&&(t[i][c]=t[i][c]||[],t[i][c].push(n))})}),Object.entries(t).filter(n=>Object.keys(n[1]).length).map(([n,o])=>({field:n,options:Object.entries(o).map(([a,c])=>({value:a,skus:c,unavailable:!1,selected:!1}))}))}function K(e,r){return e.length?e.map(({field:t,options:n})=>({field:t,options:n.map(o=>{var i;const a=!((i=o.skus)!=null&&i.some(d=>Object.entries(r).every(([s,l])=>{var f,m;return s===t?!0:((m=(f=d.customFields)==null?void 0:f.find(g=>g.key.toLowerCase()===s))==null?void 0:m.value)===l}))),c=r[t]===o.value;return{...o,unavailable:a,selected:c}})})):[]}const C=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function Q(e){if(C.includes(e))return 1e3+C.indexOf(e);const r=parseFloat(e);return isNaN(r)?e:r}function W(e,r){return[...r].sort((t,n)=>{const[o,a]=[t.value,n.value].map(Q);return o<a?-1:1})}function Y(e=[],r=[]){const[t,n]=p.useState({}),o=p.useMemo(()=>J(e,r).map(({field:s,options:l})=>({field:s,options:W(s,l)})),[e,r]),a=p.useMemo(()=>K(o,t),[o,t]),c=p.useCallback((d,s)=>{n(l=>{const u={...l};return u[d]===s?delete u[d]:u[d]=s,u})},[]),i=p.useMemo(()=>Object.keys(t).filter(l=>t[l]).length===0?[]:a.filter(({field:l})=>t[l]).map(({field:l,options:u})=>{const f=t[l],m=u.find(g=>g.value===f);return(m==null?void 0:m.skus)??[]}).reduce((l,u)=>l.filter(f=>u.includes(f))),[a,t]);return{swatches:a,toggleOption:c,matchedSkus:i}}exports.useActions=h.useActions;exports.useLoadMore=h.useLoadMore;exports.useNostoAppState=h.useNostoAppState;exports.speechToTextSupported=L;exports.useDecoratedSearchResults=T;exports.useFacet=q;exports.useFacets=X;exports.usePagination=j;exports.usePersonalization=V;exports.useProductFilters=k;exports.useRange=x;exports.useRangeSelector=B;exports.useResponse=E;exports.useSelectedFiltersCount=_;exports.useSizeOptions=U;exports.useSort=I;exports.useSpeechToText=H;exports.useSwatches=Y;
@@ -1,19 +1,19 @@
1
1
  import { a as y, c as x } from "../useLoadMore-CzqfcD1v.js";
2
- import { b as ue } from "../useLoadMore-CzqfcD1v.js";
3
- import { a as T } from "../logger-DVwg4Wor.js";
4
- import { useState as M, useCallback as S, useMemo as b, useEffect as C, useRef as k } from "preact/hooks";
5
- import { s as q } from "../index.es-B8mbAxS4.js";
6
- import { p as z } from "../parseNumber-QA48nJLp.js";
7
- function Q(e) {
2
+ import { b as fe } from "../useLoadMore-CzqfcD1v.js";
3
+ import { a as P } from "../logger-DVwg4Wor.js";
4
+ import { useState as L, useCallback as S, useMemo as b, useEffect as O, useRef as T } from "preact/hooks";
5
+ import { s as C } from "../index.es-B8mbAxS4.js";
6
+ import { p as M } from "../parseNumber-QA48nJLp.js";
7
+ function W(e) {
8
8
  const o = y((t) => t.response);
9
- return e && Array.isArray(e) || e && T(e) ? e : o;
9
+ return e && Array.isArray(e) || e && P(e) ? e : o;
10
10
  }
11
- function W(e, o) {
11
+ function Y(e, o) {
12
12
  var d;
13
13
  const t = ((d = e.data) == null ? void 0 : d.filter((n) => n.selected).length) ?? 0, { active: r } = {
14
14
  active: t > 0,
15
15
  ...o
16
- }, [s, u] = M(r), { toggleProductFilter: i } = x(), a = S(() => {
16
+ }, [s, u] = L(r), { toggleProductFilter: c } = x(), a = S(() => {
17
17
  u(!s);
18
18
  }, [s]);
19
19
  return {
@@ -24,10 +24,10 @@ function W(e, o) {
24
24
  /** Toggle active function */
25
25
  toggleActive: a,
26
26
  /** Toggle product filter function */
27
- toggleProductFilter: i
27
+ toggleProductFilter: c
28
28
  };
29
29
  }
30
- function X() {
30
+ function ee() {
31
31
  const { loading: e, facets: o } = y((t) => {
32
32
  var r, s;
33
33
  return {
@@ -42,17 +42,17 @@ function X() {
42
42
  facets: o
43
43
  };
44
44
  }
45
- function L(e, o) {
45
+ function k(e, o) {
46
46
  const t = o - e;
47
47
  return !isNaN(t) && t > 0 ? new Array(o - e).fill(void 0).map((r, s) => s + e) : [];
48
48
  }
49
- function Y(e) {
49
+ function te(e) {
50
50
  const { query: o, products: t } = y((r) => ({
51
51
  query: r.query,
52
52
  products: r.response.products
53
53
  }));
54
54
  return b(() => {
55
- var F, w, N;
55
+ var F, w, A;
56
56
  if (!t)
57
57
  return {
58
58
  totalPages: 0,
@@ -60,41 +60,41 @@ function Y(e) {
60
60
  resultsTo: 0,
61
61
  pages: []
62
62
  };
63
- const r = ((F = o.products) == null ? void 0 : F.from) ?? 0, s = (e == null ? void 0 : e.width) ?? 1 / 0, u = Math.max(Math.floor(s - 1) / 2, 1), i = t.size > 0 ? Math.floor(r / t.size) + 1 : 1, a = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (R) => R >= i - u && R <= i + u, n = r + 1, l = Math.min(r + t.total, t.total), c = {
63
+ const r = ((F = o.products) == null ? void 0 : F.from) ?? 0, s = (e == null ? void 0 : e.width) ?? 1 / 0, u = Math.max(Math.floor(s - 1) / 2, 1), c = t.size > 0 ? Math.floor(r / t.size) + 1 : 1, a = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (R) => R >= c - u && R <= c + u, n = r + 1, l = Math.min(r + t.total, t.total), i = {
64
64
  from: r,
65
- page: i,
65
+ page: c,
66
66
  current: !0
67
67
  }, f = (R) => ({
68
68
  from: (R - 1) * t.size,
69
69
  page: R,
70
- current: R === i
71
- }), m = i > 1 ? f(i - 1) : void 0, g = i < a ? f(i + 1) : void 0, v = i - u - 1 > 1 ? f(1) : void 0, p = i + u + 1 < a ? f(a) : void 0, h = L(1, a + 1).filter(d).map(f);
72
- return !v && ((w = h[0]) == null ? void 0 : w.page) === 2 && h.unshift(f(1)), !p && ((N = h[h.length - 1]) == null ? void 0 : N.page) === a - 1 && h.push(f(a)), {
70
+ current: R === c
71
+ }), p = c > 1 ? f(c - 1) : void 0, g = c < a ? f(c + 1) : void 0, v = c - u - 1 > 1 ? f(1) : void 0, m = c + u + 1 < a ? f(a) : void 0, h = k(1, a + 1).filter(d).map(f);
72
+ return !v && ((w = h[0]) == null ? void 0 : w.page) === 2 && h.unshift(f(1)), !m && ((A = h[h.length - 1]) == null ? void 0 : A.page) === a - 1 && h.push(f(a)), {
73
73
  totalPages: a,
74
74
  resultsFrom: n,
75
75
  resultsTo: l,
76
- current: c,
77
- prev: m,
76
+ current: i,
77
+ prev: p,
78
78
  next: g,
79
79
  first: v,
80
- last: p,
80
+ last: m,
81
81
  pages: h
82
82
  };
83
83
  }, [o, t, e == null ? void 0 : e.width]);
84
84
  }
85
- function Z() {
86
- const [e, o] = M([]), [t, r] = M([]);
87
- return C(() => {
88
- q(async (s) => {
89
- const { products: u, segments: i } = await s.getSearchSessionParams();
90
- o(i ?? []), r((u == null ? void 0 : u.personalizationBoost) ?? []);
85
+ function ne() {
86
+ const [e, o] = L([]), [t, r] = L([]);
87
+ return O(() => {
88
+ C(async (s) => {
89
+ const { products: u, segments: c } = await s.getSearchSessionParams();
90
+ o(c ?? []), r((u == null ? void 0 : u.personalizationBoost) ?? []);
91
91
  });
92
92
  }, []), {
93
93
  segments: e,
94
94
  boost: t
95
95
  };
96
96
  }
97
- function O() {
97
+ function q() {
98
98
  const { facets: e } = y((n) => {
99
99
  var l;
100
100
  return {
@@ -102,7 +102,7 @@ function O() {
102
102
  };
103
103
  }), { replaceFilter: o, toggleProductFilter: t } = x(), r = S(
104
104
  (n) => {
105
- const l = e == null ? void 0 : e.find((c) => c.type === "stats" && c.field === n);
105
+ const l = e == null ? void 0 : e.find((i) => i.type === "stats" && i.field === n);
106
106
  if (l && "min" in l && "max" in l)
107
107
  return l;
108
108
  },
@@ -110,47 +110,47 @@ function O() {
110
110
  ), s = S(
111
111
  (n) => {
112
112
  var l;
113
- return ((l = e == null ? void 0 : e.find((c) => c.field === n)) == null ? void 0 : l.name) ?? n;
113
+ return ((l = e == null ? void 0 : e.find((i) => i.field === n)) == null ? void 0 : l.name) ?? n;
114
114
  },
115
115
  [e]
116
- ), u = S((n) => "field" in n && (n.value instanceof Array || n.range instanceof Array), []), i = S((n) => {
116
+ ), u = S((n) => "field" in n && (n.value instanceof Array || n.range instanceof Array), []), c = S((n) => {
117
117
  var l;
118
118
  return {
119
119
  ...n,
120
- range: (l = n.range) == null ? void 0 : l.map((c) => ({
121
- gt: c.gt ? Number(c.gt) : c.gt,
122
- gte: c.gte ? Number(c.gte) : c.gte,
123
- lt: c.lt ? Number(c.lt) : c.lt,
124
- lte: c.lte ? Number(c.lte) : c.lte
120
+ range: (l = n.range) == null ? void 0 : l.map((i) => ({
121
+ gt: i.gt ? Number(i.gt) : i.gt,
122
+ gte: i.gte ? Number(i.gte) : i.gte,
123
+ lt: i.lt ? Number(i.lt) : i.lt,
124
+ lte: i.lte ? Number(i.lte) : i.lte
125
125
  }))
126
126
  };
127
127
  }, []), a = S(
128
- (n) => (n.value ?? []).map((c) => ({
129
- value: c,
128
+ (n) => (n.value ?? []).map((i) => ({
129
+ value: i,
130
130
  field: n.field,
131
131
  name: s(n.field),
132
- filter: i(n),
132
+ filter: c(n),
133
133
  remove: () => {
134
- t(n.field, c, !1);
134
+ t(n.field, i, !1);
135
135
  }
136
136
  })),
137
- [i, s, t]
137
+ [c, s, t]
138
138
  ), d = S(
139
- (n) => (n.range ?? []).map((c) => {
139
+ (n) => (n.range ?? []).map((i) => {
140
140
  var g, v;
141
- const f = c.gte ?? c.gt ?? ((g = r(n.field)) == null ? void 0 : g.min), m = c.lte ?? c.lt ?? ((v = r(n.field)) == null ? void 0 : v.max);
142
- if (f !== void 0 && m !== void 0)
141
+ const f = i.gte ?? i.gt ?? ((g = r(n.field)) == null ? void 0 : g.min), p = i.lte ?? i.lt ?? ((v = r(n.field)) == null ? void 0 : v.max);
142
+ if (f !== void 0 && p !== void 0)
143
143
  return {
144
- value: `${f} - ${m}`,
144
+ value: `${f} - ${p}`,
145
145
  field: n.field,
146
146
  name: s(n.field),
147
- filter: i(n),
147
+ filter: c(n),
148
148
  remove: () => {
149
149
  o(n.field, void 0);
150
150
  }
151
151
  };
152
152
  }).filter(Boolean),
153
- [i, r, s, o]
153
+ [c, r, s, o]
154
154
  );
155
155
  return {
156
156
  selectFilters: u,
@@ -164,7 +164,7 @@ function j() {
164
164
  return {
165
165
  filter: ((d = a.query.products) == null ? void 0 : d.filter) ?? []
166
166
  };
167
- }), { updateSearch: o } = x(), { selectFilters: t, toValueFilter: r, toRangeFilter: s } = O(), u = b(() => e ? e.filter(t).flatMap((a) => "value" in a ? r(a) : "range" in a ? s(a) : []).filter(Boolean) : [], [e, t, s, r]), i = S(() => {
167
+ }), { updateSearch: o } = x(), { selectFilters: t, toValueFilter: r, toRangeFilter: s } = q(), u = b(() => e ? e.filter(t).flatMap((a) => "value" in a ? r(a) : "range" in a ? s(a) : []).filter(Boolean) : [], [e, t, s, r]), c = S(() => {
168
168
  o({
169
169
  products: {
170
170
  filter: []
@@ -175,15 +175,15 @@ function j() {
175
175
  /** Selected filters array. */
176
176
  filters: u,
177
177
  /** Should remove all selected filters. */
178
- removeAll: i
178
+ removeAll: c
179
179
  };
180
180
  }
181
181
  function V(e) {
182
- var c, f, m;
182
+ var i, f, p;
183
183
  const { replaceFilter: o } = x(), { query: t, products: r } = y((g) => ({
184
184
  query: g.query,
185
185
  products: g.response.products
186
- })), s = (c = r == null ? void 0 : r.facets) == null ? void 0 : c.find((g) => g.id === e);
186
+ })), s = (i = r == null ? void 0 : r.facets) == null ? void 0 : i.find((g) => g.id === e);
187
187
  if (!s)
188
188
  return {
189
189
  min: 0,
@@ -192,14 +192,14 @@ function V(e) {
192
192
  updateRange: () => {
193
193
  }
194
194
  };
195
- const u = (m = (f = t.products) == null ? void 0 : f.filter) == null ? void 0 : m.find((g) => g.field === s.field), i = u != null && u.range ? u.range[0] : void 0, a = typeof i == "object" && ("gte" in i || "lte" in i) ? [z(i.gte), z(i.lte)] : [void 0, void 0], d = "min" in s ? Math.floor(s.min) : 0, n = "max" in s ? Math.ceil(s.max) : 0, l = ([g, v]) => {
196
- const p = g !== void 0 ? Math.floor(g) : void 0, h = v !== void 0 ? Math.ceil(v) : void 0, F = p !== void 0, w = h !== void 0;
197
- (d === p || !F) && (n === h || !w) ? o(s.field, void 0) : (d === p || !F) && w ? o(s.field, {
195
+ const u = (p = (f = t.products) == null ? void 0 : f.filter) == null ? void 0 : p.find((g) => g.field === s.field), c = u != null && u.range ? u.range[0] : void 0, a = typeof c == "object" && ("gte" in c || "lte" in c) ? [M(c.gte), M(c.lte)] : [void 0, void 0], d = "min" in s ? Math.floor(s.min) : 0, n = "max" in s ? Math.ceil(s.max) : 0, l = ([g, v]) => {
196
+ const m = g !== void 0 ? Math.floor(g) : void 0, h = v !== void 0 ? Math.ceil(v) : void 0, F = m !== void 0, w = h !== void 0;
197
+ (d === m || !F) && (n === h || !w) ? o(s.field, void 0) : (d === m || !F) && w ? o(s.field, {
198
198
  lte: h.toString()
199
199
  }) : (n === h || !w) && F ? o(s.field, {
200
- gte: p.toString()
200
+ gte: m.toString()
201
201
  }) : F && w && o(s.field, {
202
- gte: p.toString(),
202
+ gte: m.toString(),
203
203
  lte: h.toString()
204
204
  });
205
205
  };
@@ -214,33 +214,33 @@ function V(e) {
214
214
  updateRange: l
215
215
  };
216
216
  }
217
- function ee(e, o) {
218
- const { min: t, max: r, range: s, updateRange: u } = V(e), { filters: i } = j(), a = b(() => {
217
+ function re(e, o) {
218
+ const { min: t, max: r, range: s, updateRange: u } = V(e), { filters: c } = j(), a = b(() => {
219
219
  var v;
220
- const c = i.find((p) => {
220
+ const i = c.find((m) => {
221
221
  var h;
222
- return (h = p == null ? void 0 : p.filter) == null ? void 0 : h.range;
222
+ return (h = m == null ? void 0 : m.filter) == null ? void 0 : h.range;
223
223
  });
224
224
  let f = null;
225
- if (c) {
226
- const p = (v = c.filter.range) == null ? void 0 : v[0];
227
- f = [z(p == null ? void 0 : p.gte), z(p == null ? void 0 : p.lte)];
225
+ if (i) {
226
+ const m = (v = i.filter.range) == null ? void 0 : v[0];
227
+ f = [M(m == null ? void 0 : m.gte), M(m == null ? void 0 : m.lte)];
228
228
  }
229
- const m = [];
229
+ const p = [];
230
230
  let g = Math.floor(t / o) * o;
231
231
  for (; g < r; ) {
232
- const p = g + o, h = f && f[0] === g && f[1] === p;
233
- m.push({
232
+ const m = g + o, h = f && f[0] === g && f[1] === m;
233
+ p.push({
234
234
  min: g,
235
- max: p,
235
+ max: m,
236
236
  selected: h
237
- }), g = p;
237
+ }), g = m;
238
238
  }
239
- return m;
240
- }, [i, t, r, o]), d = (c) => {
241
- u([c, s[1]]);
242
- }, n = (c) => {
243
- u([s[0], c]);
239
+ return p;
240
+ }, [c, t, r, o]), d = (i) => {
241
+ u([i, s[1]]);
242
+ }, n = (i) => {
243
+ u([s[0], i]);
244
244
  }, l = t !== s[0] || r !== s[1];
245
245
  return {
246
246
  /** Minimum value */
@@ -261,7 +261,7 @@ function ee(e, o) {
261
261
  isSelected: l
262
262
  };
263
263
  }
264
- function te() {
264
+ function se() {
265
265
  const { products: e, keywords: o } = y((t) => t.response);
266
266
  return {
267
267
  /** Array of products */
@@ -270,30 +270,30 @@ function te() {
270
270
  keywords: o ?? { hits: [], total: 0 }
271
271
  };
272
272
  }
273
- function ne() {
273
+ function oe() {
274
274
  const e = y((t) => {
275
275
  var r;
276
276
  return (r = t.query.products) == null ? void 0 : r.filter;
277
277
  });
278
278
  return b(() => e ? e.reduce((t, r) => t + (Array.isArray(r.value) ? r.value.length : 1), 0) : 0, [e]);
279
279
  }
280
- function A(e) {
280
+ function z(e) {
281
281
  return e && !Number.isNaN(e) ? e : 0;
282
282
  }
283
- function re(e, o) {
283
+ function ie(e, o) {
284
284
  const { from: t, size: r, total: s } = y((n) => {
285
- var l, c, f, m, g;
285
+ var l, i, f, p, g;
286
286
  return {
287
- from: A(((l = n.query.products) == null ? void 0 : l.from) ?? 0),
288
- size: A(((f = (c = n.response) == null ? void 0 : c.products) == null ? void 0 : f.size) ?? 0),
289
- total: A(((g = (m = n.response) == null ? void 0 : m.products) == null ? void 0 : g.total) ?? 0)
287
+ from: z(((l = n.query.products) == null ? void 0 : l.from) ?? 0),
288
+ size: z(((f = (i = n.response) == null ? void 0 : i.products) == null ? void 0 : f.size) ?? 0),
289
+ total: z(((g = (p = n.response) == null ? void 0 : p.products) == null ? void 0 : g.total) ?? 0)
290
290
  };
291
- }), { updateSearch: u } = x(), i = t + r, a = [...e].reverse().filter((n) => n + o < s);
291
+ }), { updateSearch: u } = x(), c = t + r, a = [...e].reverse().filter((n) => n + o < s);
292
292
  return {
293
293
  /** from value */
294
294
  from: t,
295
295
  /** to value */
296
- to: i,
296
+ to: c,
297
297
  /** total value */
298
298
  total: s,
299
299
  /** size value */
@@ -304,7 +304,7 @@ function re(e, o) {
304
304
  handleSizeChange: (n) => {
305
305
  u({
306
306
  products: {
307
- size: z(n)
307
+ size: M(n)
308
308
  }
309
309
  });
310
310
  }
@@ -313,15 +313,15 @@ function re(e, o) {
313
313
  function B(e, o) {
314
314
  return e.length !== o.length ? !1 : e.every((t) => o.find((r) => t.field === r.field && t.order === r.order));
315
315
  }
316
- function se(e) {
317
- var u, i;
316
+ function ce(e) {
317
+ var u, c;
318
318
  const o = y((a) => a.query), { updateSearch: t } = x();
319
319
  return {
320
320
  /** Active sort */
321
321
  activeSort: ((u = e.find((a) => {
322
322
  var d;
323
323
  return B(a.value.sort, ((d = o.products) == null ? void 0 : d.sort) || []);
324
- })) == null ? void 0 : u.id) ?? ((i = e[0]) == null ? void 0 : i.id),
324
+ })) == null ? void 0 : u.id) ?? ((c = e[0]) == null ? void 0 : c.id),
325
325
  /** Set sort function */
326
326
  setSort: (a) => {
327
327
  const d = e.find((n) => n.id === a);
@@ -333,8 +333,8 @@ function se(e) {
333
333
  }
334
334
  };
335
335
  }
336
- const P = window.SpeechRecognition || window.webkitSpeechRecognition, D = !!(P && typeof P == "function");
337
- function U() {
336
+ const X = window.SpeechRecognition || window.webkitSpeechRecognition, D = !!(X && typeof X == "function");
337
+ function E() {
338
338
  return {
339
339
  listening: !1,
340
340
  startListening: () => {
@@ -343,96 +343,112 @@ function U() {
343
343
  }
344
344
  };
345
345
  }
346
- function E({
346
+ function U({
347
347
  language: e = "en-US",
348
348
  interimResults: o = !1
349
349
  } = {}) {
350
- const [t, r] = M(!1), s = k(null), u = S(
350
+ const [t, r] = L(!1), s = T(null), u = S(
351
351
  ({ onResult: a, onError: d }) => {
352
- const n = new P();
352
+ const n = new X();
353
353
  n.lang = e, n.interimResults = o, n.onstart = () => r(!0), n.onresult = (l) => {
354
- var f, m;
355
- const { transcript: c } = (m = (f = l.results) == null ? void 0 : f[0]) == null ? void 0 : m[0];
356
- a(c);
354
+ var f, p;
355
+ const { transcript: i } = (p = (f = l.results) == null ? void 0 : f[0]) == null ? void 0 : p[0];
356
+ a(i);
357
357
  }, d && (n.onerror = (l) => d(l.error)), n.onend = () => r(!1), s.current = n, n.start();
358
358
  },
359
359
  [e, o]
360
- ), i = S(() => {
360
+ ), c = S(() => {
361
361
  var a;
362
362
  (a = s.current) == null || a.stop();
363
363
  }, [s]);
364
364
  return {
365
365
  listening: t,
366
366
  startListening: u,
367
- stopListening: i
367
+ stopListening: c
368
368
  };
369
369
  }
370
- const oe = D ? E : U;
371
- function $(e, o) {
370
+ const ae = D ? U : E;
371
+ function _(e, o) {
372
372
  if (!e.length || !o.length) return [];
373
373
  const t = o.reduce((r, s) => (r[s] = {}, r), {});
374
374
  return e.forEach((r) => {
375
375
  var s;
376
- (s = r.customFields) == null || s.forEach(({ key: u, value: i }) => {
376
+ (s = r.customFields) == null || s.forEach(({ key: u, value: c }) => {
377
377
  const a = u.toLowerCase();
378
- o.includes(a) && (t[a][i] = t[a][i] || [], t[a][i].push(r));
378
+ o.includes(a) && (t[a][c] = t[a][c] || [], t[a][c].push(r));
379
379
  });
380
380
  }), Object.entries(t).filter((r) => Object.keys(r[1]).length).map(([r, s]) => ({
381
381
  field: r,
382
- options: Object.entries(s).map(([u, i]) => ({
382
+ options: Object.entries(s).map(([u, c]) => ({
383
383
  value: u,
384
- skus: i,
384
+ skus: c,
385
385
  unavailable: !1,
386
386
  selected: !1
387
387
  }))
388
388
  }));
389
389
  }
390
- function I(e, o) {
390
+ function $(e, o) {
391
391
  return e.length ? e.map(({ field: t, options: r }) => ({
392
392
  field: t,
393
393
  options: r.map((s) => {
394
394
  var a;
395
395
  const u = !((a = s.skus) != null && a.some((d) => Object.entries(o).every(([n, l]) => {
396
- var f, m;
397
- return n === t ? !0 : ((m = (f = d.customFields) == null ? void 0 : f.find((g) => g.key.toLowerCase() === n)) == null ? void 0 : m.value) === l;
398
- }))), i = o[t] === s.value;
396
+ var f, p;
397
+ return n === t ? !0 : ((p = (f = d.customFields) == null ? void 0 : f.find((g) => g.key.toLowerCase() === n)) == null ? void 0 : p.value) === l;
398
+ }))), c = o[t] === s.value;
399
399
  return {
400
400
  ...s,
401
401
  unavailable: u,
402
- selected: i
402
+ selected: c
403
403
  };
404
404
  })
405
405
  })) : [];
406
406
  }
407
- function ce(e = [], o = []) {
408
- const [t, r] = M({}), s = b(() => $(e, o), [e, o]), u = b(() => I(s, t), [s, t]), i = S((d, n) => {
407
+ const N = ["4XS", "3XS", "2XS", "XXS", "XS", "S", "M", "L", "XL", "XXL", "2XL", "XXXL", "3XL", "4XL"];
408
+ function I(e) {
409
+ if (N.includes(e))
410
+ return 1e3 + N.indexOf(e);
411
+ const o = parseFloat(e);
412
+ return isNaN(o) ? e : o;
413
+ }
414
+ function Z(e, o) {
415
+ return [...o].sort((t, r) => {
416
+ const [s, u] = [t.value, r.value].map(I);
417
+ return s < u ? -1 : 1;
418
+ });
419
+ }
420
+ function ue(e = [], o = []) {
421
+ const [t, r] = L({}), s = b(() => _(e, o).map(({ field: n, options: l }) => ({
422
+ field: n,
423
+ options: Z(n, l)
424
+ })), [e, o]), u = b(() => $(s, t), [s, t]), c = S((d, n) => {
409
425
  r((l) => {
410
- const c = { ...l };
411
- return c[d] === n ? delete c[d] : c[d] = n, c;
426
+ const i = { ...l };
427
+ return i[d] === n ? delete i[d] : i[d] = n, i;
412
428
  });
413
- }, []), a = b(() => Object.keys(t).filter((l) => t[l]).length === 0 ? [] : u.filter(({ field: l }) => t[l]).map(({ field: l, options: c }) => {
414
- const f = t[l], m = c.find((g) => g.value === f);
415
- return (m == null ? void 0 : m.skus) ?? [];
416
- }).reduce((l, c) => l.filter((f) => c.includes(f))), [u, t]);
417
- return { swatches: u, toggleOption: i, matchedSkus: a };
429
+ }, []), a = b(() => Object.keys(t).filter((l) => t[l]).length === 0 ? [] : u.filter(({ field: l }) => t[l]).map(({ field: l, options: i }) => {
430
+ const f = t[l], p = i.find((g) => g.value === f);
431
+ return (p == null ? void 0 : p.skus) ?? [];
432
+ }).reduce((l, i) => l.filter((f) => i.includes(f))), [u, t]);
433
+ return { swatches: u, toggleOption: c, matchedSkus: a };
418
434
  }
419
435
  export {
420
436
  D as speechToTextSupported,
421
437
  x as useActions,
422
- Q as useDecoratedSearchResults,
423
- W as useFacet,
424
- X as useFacets,
425
- ue as useLoadMore,
438
+ W as useDecoratedSearchResults,
439
+ Y as useFacet,
440
+ ee as useFacets,
441
+ fe as useLoadMore,
426
442
  y as useNostoAppState,
427
- Y as usePagination,
428
- Z as usePersonalization,
443
+ te as usePagination,
444
+ ne as usePersonalization,
429
445
  j as useProductFilters,
430
446
  V as useRange,
431
- ee as useRangeSelector,
432
- te as useResponse,
433
- ne as useSelectedFiltersCount,
434
- re as useSizeOptions,
435
- se as useSort,
436
- oe as useSpeechToText,
437
- ce as useSwatches
447
+ re as useRangeSelector,
448
+ se as useResponse,
449
+ oe as useSelectedFiltersCount,
450
+ ie as useSizeOptions,
451
+ ce as useSort,
452
+ ae as useSpeechToText,
453
+ ue as useSwatches
438
454
  };
@@ -1,5 +1,5 @@
1
1
  /** @module preact */
2
- export { AutocompleteElement } from './src/components/Autocomplete/AutocompleteElement';
2
+ export { AutocompleteElement, type AutocompleteElementProps } from './src/components/AutocompleteElement';
3
3
  export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
4
4
  export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
5
5
  export { SearchInput } from './src/components/SearchInput';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../jsxRuntime.module-B3sGoTIU.cjs"),g=require("../index.es-DlUp67LT.cjs"),t=require("../configContext-BR7w4VlU.cjs"),d=require("preact/hooks"),a=require("../baseConfig-BFFqFSg5.cjs"),k="nosto:search:scrollPos";function h(){window.sessionStorage.setItem(k,window.scrollY.toString())}function p({as:o,children:n,hit:r,componentProps:e}){const{pageType:c}=t.useConfig(),s=c==="autocomplete"?void 0:c==="search"?"serp":c,l=d.useCallback(f=>{r&&s&&g.s(S=>S.recordSearchClick(s,r)),h(),e&&"onClick"in e&&typeof e.onClick=="function"&&e.onClick(f)},[r,e,s]),u={...e,onClick:l},C=o??"a";return i.u(C,{...u,children:n})}const v={...a.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function y(o={}){return{pageType:"search",...v,...o}}function m({config:o,store:n,children:r}){const e=n??t.createStore();return a.useCheckClientScript(),i.u(t.ConfigContext,{value:y(o),children:i.u(t.StoreContext,{value:e,children:r})})}exports.SearchPageProvider=m;exports.SerpElement=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../jsxRuntime.module-B3sGoTIU.cjs"),S=require("../index.es-DlUp67LT.cjs"),r=require("../configContext-BR7w4VlU.cjs"),g=require("preact/hooks"),f=require("../BaseElement-8qy-gSKp.cjs"),i=require("../baseConfig-BFFqFSg5.cjs"),C="nosto:search:scrollPos";function p(){window.sessionStorage.setItem(C,window.scrollY.toString())}function d({children:e,hit:o,componentProps:t,as:n}){const{pageType:s}=r.useConfig(),c=s==="autocomplete"?void 0:s==="search"?"serp":s,l=g.useCallback(()=>{o&&c&&S.s(u=>u.recordSearchClick(c,o)),p()},[o,c]);return a.u(f.BaseElement,{as:n,onClick:l,componentProps:t,children:e})}const m={...i.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function h(e={}){return{pageType:"search",...m,...e}}function P({config:e,store:o,children:t}){const n=o??r.createStore();return i.useCheckClientScript(),a.u(r.ConfigContext,{value:h(e),children:a.u(r.StoreContext,{value:n,children:t})})}exports.SearchPageProvider=P;exports.SerpElement=d;
@@ -1,41 +1,36 @@
1
1
  import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
2
- import { s as u } from "../index.es-B8mbAxS4.js";
3
- import { u as C, c as S, S as g, C as p } from "../configContext-GuZOIX3o.js";
4
- import { useCallback as m } from "preact/hooks";
5
- import { d, u as k } from "../baseConfig-Bafl02NY.js";
2
+ import { s as l } from "../index.es-B8mbAxS4.js";
3
+ import { u as f, c as p, S as u, C as m } from "../configContext-GuZOIX3o.js";
4
+ import { useCallback as S } from "preact/hooks";
5
+ import { B as C } from "../BaseElement-Df1Kv7sB.js";
6
+ import { d as g, u as d } from "../baseConfig-Bafl02NY.js";
6
7
  const h = "nosto:search:scrollPos";
7
- function v() {
8
+ function k() {
8
9
  window.sessionStorage.setItem(h, window.scrollY.toString());
9
10
  }
10
- function B({ as: o, children: t, hit: r, componentProps: e }) {
11
- const { pageType: a } = C(), c = a === "autocomplete" ? void 0 : a === "search" ? "serp" : a, s = m(
12
- (l) => {
13
- r && c && u((f) => f.recordSearchClick(c, r)), v(), e && "onClick" in e && typeof e.onClick == "function" && e.onClick(l);
14
- },
15
- [r, e, c]
16
- ), i = {
17
- ...e,
18
- onClick: s
19
- };
20
- return /* @__PURE__ */ n(o ?? "a", { ...i, children: t });
11
+ function b({ children: e, hit: o, componentProps: r, as: t }) {
12
+ const { pageType: s } = f(), a = s === "autocomplete" ? void 0 : s === "search" ? "serp" : s, c = S(() => {
13
+ o && a && l((i) => i.recordSearchClick(a, o)), k();
14
+ }, [o, a]);
15
+ return /* @__PURE__ */ n(C, { as: t, onClick: c, componentProps: r, children: e });
21
16
  }
22
- const w = {
23
- ...d,
17
+ const v = {
18
+ ...g,
24
19
  persistentSearchCache: !1,
25
20
  preservePageScroll: !1
26
21
  };
27
- function y(o = {}) {
22
+ function P(e = {}) {
28
23
  return {
29
24
  pageType: "search",
30
- ...w,
31
- ...o
25
+ ...v,
26
+ ...e
32
27
  };
33
28
  }
34
- function E({ config: o, store: t, children: r }) {
35
- const e = t ?? S();
36
- return k(), /* @__PURE__ */ n(p, { value: y(o), children: /* @__PURE__ */ n(g, { value: e, children: r }) });
29
+ function I({ config: e, store: o, children: r }) {
30
+ const t = o ?? p();
31
+ return d(), /* @__PURE__ */ n(m, { value: P(e), children: /* @__PURE__ */ n(u, { value: t, children: r }) });
37
32
  }
38
33
  export {
39
- E as SearchPageProvider,
40
- B as SerpElement
34
+ I as SearchPageProvider,
35
+ b as SerpElement
41
36
  };
@@ -0,0 +1,12 @@
1
+ import { AsComponent, BaseElementProps } from './BaseElement';
2
+ type AutocompleteHit = {
3
+ productId: string;
4
+ url?: string;
5
+ } | {
6
+ keyword: string;
7
+ };
8
+ export type AutocompleteElementProps<C extends AsComponent> = Omit<BaseElementProps<C>, "onClick"> & {
9
+ hit: AutocompleteHit;
10
+ };
11
+ export declare function AutocompleteElement<C extends AsComponent>({ children, hit, as, componentProps }: AutocompleteElementProps<C>): import("preact").JSX.Element;
12
+ export {};
@@ -0,0 +1,17 @@
1
+ import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
2
+ export type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
3
+ /**
4
+ * @group Components
5
+ */
6
+ export type BaseElementProps<C extends AsComponent> = {
7
+ onClick: () => void;
8
+ as?: C;
9
+ componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
10
+ children?: ComponentChildren;
11
+ };
12
+ /**
13
+ * Wrapper component that can be used to wrap any element in the search result list.
14
+ *
15
+ * @group Components
16
+ */
17
+ export declare function BaseElement<C extends AsComponent>({ onClick, as, children, componentProps }: BaseElementProps<C>): JSX.Element;
@@ -1,21 +1,16 @@
1
- import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
2
- type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
1
+ import { AsComponent, BaseElementProps } from './BaseElement';
3
2
  /**
4
3
  * @group Components
5
4
  */
6
- export type SerpElementProps<C extends AsComponent> = {
5
+ export type SerpElementProps<C extends AsComponent> = Omit<BaseElementProps<C>, "onClick"> & {
7
6
  hit: {
8
7
  productId: string;
9
8
  url?: string;
10
9
  };
11
- as?: C;
12
- componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
13
- children?: ComponentChildren;
14
10
  };
15
11
  /**
16
12
  * Wrapper component that can be used to wrap any element in the search result list.
17
13
  *
18
14
  * @group Components
19
15
  */
20
- export declare function SerpElement<C extends AsComponent>({ as, children, hit, componentProps }: SerpElementProps<C>): JSX.Element;
21
- export {};
16
+ export declare function SerpElement<C extends AsComponent>({ children, hit, componentProps, as }: SerpElementProps<C>): import("preact").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { SwatchOption } from '../types';
2
+ export declare function sortOptions(_: string, options: SwatchOption[]): SwatchOption[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "2.13.0",
3
+ "version": "2.15.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,36 +0,0 @@
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>;
@@ -1,5 +0,0 @@
1
- import { ComponentChildren, JSX } from 'preact';
2
- /**
3
- * Check if the provided children is a valid HTML element (div/anchor/etc).
4
- */
5
- export declare function isValidHTMLElement(children: ComponentChildren): children is JSX.Element;