@nosto/search-js 2.11.1 → 2.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preact/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete.es.js +29 -32
- package/dist/preact/hooks.cjs.js +1 -1
- package/dist/preact/hooks.d.ts +1 -1
- package/dist/preact/hooks.es.js +173 -170
- package/dist/preact/serp.cjs.js +1 -1
- package/dist/preact/serp.es.js +25 -25
- package/dist/preact/src/components/SearchInput.d.ts +7 -4
- package/dist/preact/src/components/SerpElement.d.ts +8 -5
- package/dist/preact/src/hooks/useFacet.d.ts +7 -1
- package/package.json +1 -1
- package/dist/preact/src/dom/renderHeadless.d.ts +0 -18
- package/dist/preact/src/dom/utils.d.ts +0 -5
- package/dist/renderHeadless-BteGML1G.js +0 -23
- package/dist/renderHeadless-xhkLegO4.cjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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,52 +1,49 @@
|
|
|
1
|
-
import { s as
|
|
1
|
+
import { s as c } from "../index.es-B8mbAxS4.js";
|
|
2
2
|
import { cloneElement as a } from "preact";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
function E(t) {
|
|
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) {
|
|
8
7
|
return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
|
|
9
8
|
}
|
|
10
|
-
function
|
|
11
|
-
var
|
|
12
|
-
if (!
|
|
9
|
+
function x({ children: t, hit: e }) {
|
|
10
|
+
var n;
|
|
11
|
+
if (!g(t))
|
|
13
12
|
throw new Error(
|
|
14
13
|
"AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
|
|
15
14
|
);
|
|
16
|
-
const
|
|
15
|
+
const o = (n = t.props) == null ? void 0 : n.onClick;
|
|
17
16
|
return a(t, {
|
|
18
|
-
onClick: (
|
|
19
|
-
|
|
17
|
+
onClick: (r) => {
|
|
18
|
+
e && c((p) => p.recordSearchClick("autocomplete", e)), typeof o == "function" && o(r);
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}), e)
|
|
32
|
-
});
|
|
22
|
+
function P({ as: t, componentProps: e, onSearchInput: o, children: n }) {
|
|
23
|
+
const r = {
|
|
24
|
+
...e,
|
|
25
|
+
onInput: (u) => {
|
|
26
|
+
o(u.target);
|
|
27
|
+
}
|
|
28
|
+
}, p = t ?? "input";
|
|
29
|
+
return t || (r.type = "search"), /* @__PURE__ */ i(p, { ...r, children: n });
|
|
33
30
|
}
|
|
34
|
-
const
|
|
35
|
-
...
|
|
31
|
+
const d = {
|
|
32
|
+
...f
|
|
36
33
|
};
|
|
37
|
-
function
|
|
34
|
+
function S(t) {
|
|
38
35
|
return {
|
|
39
36
|
pageType: "autocomplete",
|
|
40
|
-
...
|
|
37
|
+
...d,
|
|
41
38
|
...t
|
|
42
39
|
};
|
|
43
40
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
return
|
|
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 }) });
|
|
47
44
|
}
|
|
48
45
|
export {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
x as AutocompleteElement,
|
|
47
|
+
T as AutocompletePageProvider,
|
|
48
|
+
P as SearchInput
|
|
52
49
|
};
|
package/dist/preact/hooks.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../useLoadMore-BFEnHdOH.cjs"),z=require("../logger-BcHMZObS.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../useLoadMore-BFEnHdOH.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(s=>s.response);return e&&Array.isArray(e)||e&&z.isPlainObject(e)?e:r}function q(e,r){var d;const s=((d=e.data)==null?void 0:d.filter(t=>t.selected).length)??0,{active:o}={active:s>0,...r},[n,l]=p.useState(o),{toggleProductFilter:c}=S.useActions(),u=p.useCallback(()=>{l(!n)},[n]);return{active:n,selectedFiltersCount:s,toggleActive:u,toggleProductFilter:c}}function L(){const{loading:e,facets:r}=S.useNostoAppState(s=>{var o,n;return{loading:s.loading,facets:((n=(o=s.response)==null?void 0:o.products)==null?void 0:n.facets)??[]}});return{loading:e,facets:r}}function O(e,r){const s=r-e;return!isNaN(s)&&s>0?new Array(r-e).fill(void 0).map((o,n)=>n+e):[]}function j(e){const{query:r,products:s}=S.useNostoAppState(o=>({query:o.query,products:o.response.products}));return p.useMemo(()=>{var F,y,R;if(!s)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=((F=r.products)==null?void 0:F.from)??0,n=(e==null?void 0:e.width)??1/0,l=Math.max(Math.floor(n-1)/2,1),c=s.size>0?Math.floor(o/s.size)+1:1,u=s.size>0?Math.ceil(s.total/s.size):0,d=A=>A>=c-l&&A<=c+l,t=o+1,a=Math.min(o+s.total,s.total),i={from:o,page:c,current:!0},f=A=>({from:(A-1)*s.size,page:A,current:A===c}),h=c>1?f(c-1):void 0,g=c<u?f(c+1):void 0,b=c-l-1>1?f(1):void 0,m=c+l+1<u?f(u):void 0,v=O(1,u+1).filter(d).map(f);return!b&&((y=v[0])==null?void 0:y.page)===2&&v.unshift(f(1)),!m&&((R=v[v.length-1])==null?void 0:R.page)===u-1&&v.push(f(u)),{totalPages:u,resultsFrom:t,resultsTo:a,current:i,prev:h,next:g,first:b,last:m,pages:v}},[r,s,e==null?void 0:e.width])}function V(){const[e,r]=p.useState([]),[s,o]=p.useState([]);return p.useEffect(()=>{P.s(async n=>{const{products:l,segments:c}=await n.getSearchSessionParams();r(c??[]),o((l==null?void 0:l.personalizationBoost)??[])})},[]),{segments:e,boost:s}}function B(){const{facets:e}=S.useNostoAppState(t=>{var a;return{facets:((a=t.response.products)==null?void 0:a.facets)??[]}}),{replaceFilter:r,toggleProductFilter:s}=S.useActions(),o=p.useCallback(t=>{const a=e==null?void 0:e.find(i=>i.type==="stats"&&i.field===t);if(a&&"min"in a&&"max"in a)return a},[e]),n=p.useCallback(t=>{var a;return((a=e==null?void 0:e.find(i=>i.field===t))==null?void 0:a.name)??t},[e]),l=p.useCallback(t=>"field"in t&&(t.value instanceof Array||t.range instanceof Array),[]),c=p.useCallback(t=>{var a;return{...t,range:(a=t.range)==null?void 0:a.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}))}},[]),u=p.useCallback(t=>(t.value??[]).map(i=>({value:i,field:t.field,name:n(t.field),filter:c(t),remove:()=>{s(t.field,i,!1)}})),[c,n,s]),d=p.useCallback(t=>(t.range??[]).map(i=>{var g,b;const f=i.gte??i.gt??((g=o(t.field))==null?void 0:g.min),h=i.lte??i.lt??((b=o(t.field))==null?void 0:b.max);if(f!==void 0&&h!==void 0)return{value:`${f} - ${h}`,field:t.field,name:n(t.field),filter:c(t),remove:()=>{r(t.field,void 0)}}}).filter(Boolean),[c,o,n,r]);return{selectFilters:l,toValueFilter:u,toRangeFilter:d}}function C(){const{filter:e}=S.useNostoAppState(u=>{var d;return{filter:((d=u.query.products)==null?void 0:d.filter)??[]}}),{updateSearch:r}=S.useActions(),{selectFilters:s,toValueFilter:o,toRangeFilter:n}=B(),l=p.useMemo(()=>e?e.filter(s).flatMap(u=>"value"in u?o(u):"range"in u?n(u):[]).filter(Boolean):[],[e,s,n,o]),c=p.useCallback(()=>{r({products:{filter:[]}})},[r]);return{filters:l,removeAll:c}}function k(e){var i,f,h;const{replaceFilter:r}=S.useActions(),{query:s,products:o}=S.useNostoAppState(g=>({query:g.query,products:g.response.products})),n=(i=o==null?void 0:o.facets)==null?void 0:i.find(g=>g.id===e);if(!n)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const l=(h=(f=s.products)==null?void 0:f.filter)==null?void 0:h.find(g=>g.field===n.field),c=l!=null&&l.range?l.range[0]:void 0,u=typeof c=="object"&&("gte"in c||"lte"in c)?[N.parseNumber(c.gte),N.parseNumber(c.lte)]:[void 0,void 0],d="min"in n?Math.floor(n.min):0,t="max"in n?Math.ceil(n.max):0,a=([g,b])=>{const m=g!==void 0?Math.floor(g):void 0,v=b!==void 0?Math.ceil(b):void 0,F=m!==void 0,y=v!==void 0;(d===m||!F)&&(t===v||!y)?r(n.field,void 0):(d===m||!F)&&y?r(n.field,{lte:v.toString()}):(t===v||!y)&&F?r(n.field,{gte:m.toString()}):F&&y&&r(n.field,{gte:m.toString(),lte:v.toString()})};return{min:d,max:t,range:[u[0]??d,u[1]??t],updateRange:a}}function D(e,r){const{min:s,max:o,range:n,updateRange:l}=k(e),{filters:c}=C(),u=p.useMemo(()=>{var b;const i=c.find(m=>{var v;return(v=m==null?void 0:m.filter)==null?void 0:v.range});let f=null;if(i){const m=(b=i.filter.range)==null?void 0:b[0];f=[N.parseNumber(m==null?void 0:m.gte),N.parseNumber(m==null?void 0:m.lte)]}const h=[];let g=Math.floor(s/r)*r;for(;g<o;){const m=g+r,v=f&&f[0]===g&&f[1]===m;h.push({min:g,max:m,selected:v}),g=m}return h},[c,s,o,r]),d=i=>{l([i,n[1]])},t=i=>{l([n[0],i])},a=s!==n[0]||o!==n[1];return{min:s,max:o,range:n,updateRange:l,ranges:u,handleMinChange:d,handleMaxChange:t,isSelected:a}}function U(){const{products:e,keywords:r}=S.useNostoAppState(s=>s.response);return{products:e??{hits:[],total:0},keywords:r??{hits:[],total:0}}}function E(){const e=S.useNostoAppState(s=>{var o;return(o=s.query.products)==null?void 0:o.filter});return p.useMemo(()=>e?e.reduce((s,o)=>s+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}function M(e){return e&&!Number.isNaN(e)?e:0}function _(e,r){const{from:s,size:o,total:n}=S.useNostoAppState(t=>{var a,i,f,h,g;return{from:M(((a=t.query.products)==null?void 0:a.from)??0),size:M(((f=(i=t.response)==null?void 0:i.products)==null?void 0:f.size)??0),total:M(((g=(h=t.response)==null?void 0:h.products)==null?void 0:g.total)??0)}}),{updateSearch:l}=S.useActions(),c=s+o,u=[...e].reverse().filter(t=>t+r<n);return{from:s,to:c,total:n,size:o,sizeOptions:u,handleSizeChange:t=>{l({products:{size:N.parseNumber(t)}})}}}function $(e,r){return e.length!==r.length?!1:e.every(s=>r.find(o=>s.field===o.field&&s.order===o.order))}function I(e){var l,c;const r=S.useNostoAppState(u=>u.query),{updateSearch:s}=S.useActions();return{activeSort:((l=e.find(u=>{var d;return $(u.value.sort,((d=r.products)==null?void 0:d.sort)||[])}))==null?void 0:l.id)??((c=e[0])==null?void 0:c.id),setSort:u=>{const d=e.find(t=>t.id===u);d&&s({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[s,o]=p.useState(!1),n=p.useRef(null),l=p.useCallback(({onResult:u,onError:d})=>{const t=new w;t.lang=e,t.interimResults=r,t.onstart=()=>o(!0),t.onresult=a=>{var f,h;const{transcript:i}=(h=(f=a.results)==null?void 0:f[0])==null?void 0:h[0];u(i)},d&&(t.onerror=a=>d(a.error)),t.onend=()=>o(!1),n.current=t,t.start()},[e,r]),c=p.useCallback(()=>{var u;(u=n.current)==null||u.stop()},[n]);return{listening:s,startListening:l,stopListening:c}}const J=x?H:G;function K(e,r){if(!e.length||!r.length)return[];const s=r.reduce((o,n)=>(o[n]={},o),{});return e.forEach(o=>{var n;(n=o.customFields)==null||n.forEach(({key:l,value:c})=>{const u=l.toLowerCase();r.includes(u)&&(s[u][c]=s[u][c]||[],s[u][c].push(o))})}),Object.entries(s).map(([o,n])=>({field:o,options:Object.entries(n).map(([l,c])=>({value:l,skus:c,unavailable:!1,selected:!1}))}))}function Q(e,r){return e.length?e.map(({field:s,options:o})=>({field:s,options:o.map(n=>{var u;const l=!((u=n.skus)!=null&&u.some(d=>Object.entries(r).every(([t,a])=>{var f,h;return t===s?!0:((h=(f=d.customFields)==null?void 0:f.find(g=>g.key.toLowerCase()===t))==null?void 0:h.value)===a}))),c=r[s]===n.value;return{...n,unavailable:l,selected:c}})})):[]}function W(e=[],r=[]){const[s,o]=p.useState({}),n=p.useMemo(()=>Q(K(e,r),s),[e,r,s]),l=p.useCallback((u,d)=>{o(t=>{const a={...t};return a[u]===d?delete a[u]:a[u]=d,a})},[]),c=p.useMemo(()=>Object.keys(s).filter(t=>s[t]).length===0?[]:n.filter(({field:t})=>s[t]).map(({field:t,options:a})=>{const i=s[t],f=a.find(h=>h.value===i);return(f==null?void 0:f.skus)??[]}).reduce((t,a)=>t.filter(i=>a.includes(i))),[n,s]);return{swatches:n,toggleOption:l,matchedSkus:c}}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;
|
package/dist/preact/hooks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @module preact/hooks */
|
|
2
2
|
export { useActions } from './src/hooks/useActions';
|
|
3
3
|
export { useDecoratedSearchResults } from './src/hooks/useDecoratedSearchResults';
|
|
4
|
-
export { useFacet } from './src/hooks/useFacet';
|
|
4
|
+
export { useFacet, type UseFacetOptions } from './src/hooks/useFacet';
|
|
5
5
|
export { useFacets } from './src/hooks/useFacets';
|
|
6
6
|
export { useLoadMore } from './src/hooks/useLoadMore/useLoadMore';
|
|
7
7
|
export { useNostoAppState } from './src/hooks/useNostoAppState';
|
package/dist/preact/hooks.es.js
CHANGED
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
import { a as y, c as x } from "../useLoadMore-jrN1VGDU.js";
|
|
2
|
-
import { b as
|
|
2
|
+
import { b as ue } from "../useLoadMore-jrN1VGDU.js";
|
|
3
3
|
import { a as T } from "../logger-DVwg4Wor.js";
|
|
4
|
-
import { useState as M,
|
|
4
|
+
import { useState as M, useCallback as S, useMemo as b, useEffect as C, useRef as q } from "preact/hooks";
|
|
5
5
|
import { s as L } from "../index.es-B8mbAxS4.js";
|
|
6
6
|
import { p as z } from "../parseNumber-QA48nJLp.js";
|
|
7
7
|
function Q(e) {
|
|
8
|
-
const o = y((
|
|
8
|
+
const o = y((n) => n.response);
|
|
9
9
|
return e && Array.isArray(e) || e && T(e) ? e : o;
|
|
10
10
|
}
|
|
11
|
-
function W(e) {
|
|
12
|
-
var
|
|
13
|
-
const
|
|
11
|
+
function W(e, o) {
|
|
12
|
+
var d;
|
|
13
|
+
const n = ((d = e.data) == null ? void 0 : d.filter((t) => t.selected).length) ?? 0, { active: s } = {
|
|
14
|
+
active: n > 0,
|
|
15
|
+
...o
|
|
16
|
+
}, [r, l] = M(s), { toggleProductFilter: i } = x(), c = S(() => {
|
|
17
|
+
l(!r);
|
|
18
|
+
}, [r]);
|
|
14
19
|
return {
|
|
15
20
|
/** Active value */
|
|
16
|
-
active:
|
|
21
|
+
active: r,
|
|
17
22
|
/** Selected filters count */
|
|
18
|
-
selectedFiltersCount:
|
|
23
|
+
selectedFiltersCount: n,
|
|
19
24
|
/** Toggle active function */
|
|
20
|
-
toggleActive:
|
|
21
|
-
r(!t);
|
|
22
|
-
},
|
|
25
|
+
toggleActive: c,
|
|
23
26
|
/** Toggle product filter function */
|
|
24
|
-
toggleProductFilter:
|
|
27
|
+
toggleProductFilter: i
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
function X() {
|
|
28
|
-
const { loading: e, facets: o } = y((
|
|
29
|
-
var
|
|
31
|
+
const { loading: e, facets: o } = y((n) => {
|
|
32
|
+
var s, r;
|
|
30
33
|
return {
|
|
31
|
-
loading:
|
|
32
|
-
facets: ((
|
|
34
|
+
loading: n.loading,
|
|
35
|
+
facets: ((r = (s = n.response) == null ? void 0 : s.products) == null ? void 0 : r.facets) ?? []
|
|
33
36
|
};
|
|
34
37
|
});
|
|
35
38
|
return {
|
|
@@ -40,128 +43,128 @@ function X() {
|
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
function k(e, o) {
|
|
43
|
-
const
|
|
44
|
-
return !isNaN(
|
|
46
|
+
const n = o - e;
|
|
47
|
+
return !isNaN(n) && n > 0 ? new Array(o - e).fill(void 0).map((s, r) => r + e) : [];
|
|
45
48
|
}
|
|
46
49
|
function Y(e) {
|
|
47
|
-
const { query: o, products:
|
|
48
|
-
query:
|
|
49
|
-
products:
|
|
50
|
+
const { query: o, products: n } = y((s) => ({
|
|
51
|
+
query: s.query,
|
|
52
|
+
products: s.response.products
|
|
50
53
|
}));
|
|
51
54
|
return b(() => {
|
|
52
55
|
var F, w, N;
|
|
53
|
-
if (!
|
|
56
|
+
if (!n)
|
|
54
57
|
return {
|
|
55
58
|
totalPages: 0,
|
|
56
59
|
resultsFrom: 0,
|
|
57
60
|
resultsTo: 0,
|
|
58
61
|
pages: []
|
|
59
62
|
};
|
|
60
|
-
const
|
|
61
|
-
from:
|
|
63
|
+
const s = ((F = o.products) == null ? void 0 : F.from) ?? 0, r = (e == null ? void 0 : e.width) ?? 1 / 0, l = Math.max(Math.floor(r - 1) / 2, 1), i = n.size > 0 ? Math.floor(s / n.size) + 1 : 1, c = n.size > 0 ? Math.ceil(n.total / n.size) : 0, d = (R) => R >= i - l && R <= i + l, t = s + 1, u = Math.min(s + n.total, n.total), a = {
|
|
64
|
+
from: s,
|
|
62
65
|
page: i,
|
|
63
66
|
current: !0
|
|
64
|
-
},
|
|
65
|
-
from: (R - 1) *
|
|
67
|
+
}, f = (R) => ({
|
|
68
|
+
from: (R - 1) * n.size,
|
|
66
69
|
page: R,
|
|
67
70
|
current: R === i
|
|
68
|
-
}), p = i > 1 ?
|
|
69
|
-
return !v && ((w = h[0]) == null ? void 0 : w.page) === 2 && h.unshift(
|
|
71
|
+
}), p = i > 1 ? f(i - 1) : void 0, g = i < c ? f(i + 1) : void 0, v = i - l - 1 > 1 ? f(1) : void 0, m = i + l + 1 < c ? f(c) : void 0, h = k(1, c + 1).filter(d).map(f);
|
|
72
|
+
return !v && ((w = h[0]) == null ? void 0 : w.page) === 2 && h.unshift(f(1)), !m && ((N = h[h.length - 1]) == null ? void 0 : N.page) === c - 1 && h.push(f(c)), {
|
|
70
73
|
totalPages: c,
|
|
71
|
-
resultsFrom:
|
|
72
|
-
resultsTo:
|
|
73
|
-
current:
|
|
74
|
+
resultsFrom: t,
|
|
75
|
+
resultsTo: u,
|
|
76
|
+
current: a,
|
|
74
77
|
prev: p,
|
|
75
78
|
next: g,
|
|
76
79
|
first: v,
|
|
77
80
|
last: m,
|
|
78
81
|
pages: h
|
|
79
82
|
};
|
|
80
|
-
}, [o,
|
|
83
|
+
}, [o, n, e == null ? void 0 : e.width]);
|
|
81
84
|
}
|
|
82
85
|
function Z() {
|
|
83
|
-
const [e, o] = M([]), [
|
|
86
|
+
const [e, o] = M([]), [n, s] = M([]);
|
|
84
87
|
return C(() => {
|
|
85
|
-
L(async (
|
|
86
|
-
const { products: l, segments: i } = await
|
|
87
|
-
o(i ?? []),
|
|
88
|
+
L(async (r) => {
|
|
89
|
+
const { products: l, segments: i } = await r.getSearchSessionParams();
|
|
90
|
+
o(i ?? []), s((l == null ? void 0 : l.personalizationBoost) ?? []);
|
|
88
91
|
});
|
|
89
92
|
}, []), {
|
|
90
93
|
segments: e,
|
|
91
|
-
boost:
|
|
94
|
+
boost: n
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
97
|
function O() {
|
|
95
|
-
const { facets: e } = y((
|
|
96
|
-
var
|
|
98
|
+
const { facets: e } = y((t) => {
|
|
99
|
+
var u;
|
|
97
100
|
return {
|
|
98
|
-
facets: ((
|
|
101
|
+
facets: ((u = t.response.products) == null ? void 0 : u.facets) ?? []
|
|
99
102
|
};
|
|
100
|
-
}), { replaceFilter: o, toggleProductFilter:
|
|
101
|
-
(
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
return
|
|
103
|
+
}), { replaceFilter: o, toggleProductFilter: n } = x(), s = S(
|
|
104
|
+
(t) => {
|
|
105
|
+
const u = e == null ? void 0 : e.find((a) => a.type === "stats" && a.field === t);
|
|
106
|
+
if (u && "min" in u && "max" in u)
|
|
107
|
+
return u;
|
|
105
108
|
},
|
|
106
109
|
[e]
|
|
107
|
-
),
|
|
108
|
-
(
|
|
109
|
-
var
|
|
110
|
-
return ((
|
|
110
|
+
), r = S(
|
|
111
|
+
(t) => {
|
|
112
|
+
var u;
|
|
113
|
+
return ((u = e == null ? void 0 : e.find((a) => a.field === t)) == null ? void 0 : u.name) ?? t;
|
|
111
114
|
},
|
|
112
115
|
[e]
|
|
113
|
-
), l = S((
|
|
114
|
-
var
|
|
116
|
+
), l = S((t) => "field" in t && (t.value instanceof Array || t.range instanceof Array), []), i = S((t) => {
|
|
117
|
+
var u;
|
|
115
118
|
return {
|
|
116
|
-
...
|
|
117
|
-
range: (
|
|
118
|
-
gt:
|
|
119
|
-
gte:
|
|
120
|
-
lt:
|
|
121
|
-
lte:
|
|
119
|
+
...t,
|
|
120
|
+
range: (u = t.range) == null ? void 0 : u.map((a) => ({
|
|
121
|
+
gt: a.gt ? Number(a.gt) : a.gt,
|
|
122
|
+
gte: a.gte ? Number(a.gte) : a.gte,
|
|
123
|
+
lt: a.lt ? Number(a.lt) : a.lt,
|
|
124
|
+
lte: a.lte ? Number(a.lte) : a.lte
|
|
122
125
|
}))
|
|
123
126
|
};
|
|
124
127
|
}, []), c = S(
|
|
125
|
-
(
|
|
126
|
-
value:
|
|
127
|
-
field:
|
|
128
|
-
name:
|
|
129
|
-
filter: i(
|
|
128
|
+
(t) => (t.value ?? []).map((a) => ({
|
|
129
|
+
value: a,
|
|
130
|
+
field: t.field,
|
|
131
|
+
name: r(t.field),
|
|
132
|
+
filter: i(t),
|
|
130
133
|
remove: () => {
|
|
131
|
-
t
|
|
134
|
+
n(t.field, a, !1);
|
|
132
135
|
}
|
|
133
136
|
})),
|
|
134
|
-
[i,
|
|
135
|
-
),
|
|
136
|
-
(
|
|
137
|
+
[i, r, n]
|
|
138
|
+
), d = S(
|
|
139
|
+
(t) => (t.range ?? []).map((a) => {
|
|
137
140
|
var g, v;
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
141
|
+
const f = a.gte ?? a.gt ?? ((g = s(t.field)) == null ? void 0 : g.min), p = a.lte ?? a.lt ?? ((v = s(t.field)) == null ? void 0 : v.max);
|
|
142
|
+
if (f !== void 0 && p !== void 0)
|
|
140
143
|
return {
|
|
141
|
-
value: `${
|
|
142
|
-
field:
|
|
143
|
-
name:
|
|
144
|
-
filter: i(
|
|
144
|
+
value: `${f} - ${p}`,
|
|
145
|
+
field: t.field,
|
|
146
|
+
name: r(t.field),
|
|
147
|
+
filter: i(t),
|
|
145
148
|
remove: () => {
|
|
146
|
-
o(
|
|
149
|
+
o(t.field, void 0);
|
|
147
150
|
}
|
|
148
151
|
};
|
|
149
152
|
}).filter(Boolean),
|
|
150
|
-
[i,
|
|
153
|
+
[i, s, r, o]
|
|
151
154
|
);
|
|
152
155
|
return {
|
|
153
156
|
selectFilters: l,
|
|
154
157
|
toValueFilter: c,
|
|
155
|
-
toRangeFilter:
|
|
158
|
+
toRangeFilter: d
|
|
156
159
|
};
|
|
157
160
|
}
|
|
158
161
|
function j() {
|
|
159
162
|
const { filter: e } = y((c) => {
|
|
160
|
-
var
|
|
163
|
+
var d;
|
|
161
164
|
return {
|
|
162
|
-
filter: ((
|
|
165
|
+
filter: ((d = c.query.products) == null ? void 0 : d.filter) ?? []
|
|
163
166
|
};
|
|
164
|
-
}), { updateSearch: o } = x(), { selectFilters:
|
|
167
|
+
}), { updateSearch: o } = x(), { selectFilters: n, toValueFilter: s, toRangeFilter: r } = O(), l = b(() => e ? e.filter(n).flatMap((c) => "value" in c ? s(c) : "range" in c ? r(c) : []).filter(Boolean) : [], [e, n, r, s]), i = S(() => {
|
|
165
168
|
o({
|
|
166
169
|
products: {
|
|
167
170
|
filter: []
|
|
@@ -176,12 +179,12 @@ function j() {
|
|
|
176
179
|
};
|
|
177
180
|
}
|
|
178
181
|
function V(e) {
|
|
179
|
-
var
|
|
180
|
-
const { replaceFilter: o } = x(), { query:
|
|
182
|
+
var a, f, p;
|
|
183
|
+
const { replaceFilter: o } = x(), { query: n, products: s } = y((g) => ({
|
|
181
184
|
query: g.query,
|
|
182
185
|
products: g.response.products
|
|
183
|
-
})),
|
|
184
|
-
if (!
|
|
186
|
+
})), r = (a = s == null ? void 0 : s.facets) == null ? void 0 : a.find((g) => g.id === e);
|
|
187
|
+
if (!r)
|
|
185
188
|
return {
|
|
186
189
|
min: 0,
|
|
187
190
|
max: 0,
|
|
@@ -189,44 +192,44 @@ function V(e) {
|
|
|
189
192
|
updateRange: () => {
|
|
190
193
|
}
|
|
191
194
|
};
|
|
192
|
-
const l = (p = (
|
|
195
|
+
const l = (p = (f = n.products) == null ? void 0 : f.filter) == null ? void 0 : p.find((g) => g.field === r.field), i = l != null && l.range ? l.range[0] : void 0, c = typeof i == "object" && ("gte" in i || "lte" in i) ? [z(i.gte), z(i.lte)] : [void 0, void 0], d = "min" in r ? Math.floor(r.min) : 0, t = "max" in r ? Math.ceil(r.max) : 0, u = ([g, v]) => {
|
|
193
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;
|
|
194
|
-
(
|
|
197
|
+
(d === m || !F) && (t === h || !w) ? o(r.field, void 0) : (d === m || !F) && w ? o(r.field, {
|
|
195
198
|
lte: h.toString()
|
|
196
|
-
}) : (
|
|
199
|
+
}) : (t === h || !w) && F ? o(r.field, {
|
|
197
200
|
gte: m.toString()
|
|
198
|
-
}) : F && w && o(
|
|
201
|
+
}) : F && w && o(r.field, {
|
|
199
202
|
gte: m.toString(),
|
|
200
203
|
lte: h.toString()
|
|
201
204
|
});
|
|
202
205
|
};
|
|
203
206
|
return {
|
|
204
207
|
/** Min value */
|
|
205
|
-
min:
|
|
208
|
+
min: d,
|
|
206
209
|
/** Max value */
|
|
207
|
-
max:
|
|
210
|
+
max: t,
|
|
208
211
|
/** Range value */
|
|
209
|
-
range: [c[0] ??
|
|
212
|
+
range: [c[0] ?? d, c[1] ?? t],
|
|
210
213
|
/** Update range function */
|
|
211
|
-
updateRange:
|
|
214
|
+
updateRange: u
|
|
212
215
|
};
|
|
213
216
|
}
|
|
214
217
|
function ee(e, o) {
|
|
215
|
-
const { min:
|
|
218
|
+
const { min: n, max: s, range: r, updateRange: l } = V(e), { filters: i } = j(), c = b(() => {
|
|
216
219
|
var v;
|
|
217
|
-
const
|
|
220
|
+
const a = i.find((m) => {
|
|
218
221
|
var h;
|
|
219
222
|
return (h = m == null ? void 0 : m.filter) == null ? void 0 : h.range;
|
|
220
223
|
});
|
|
221
|
-
let
|
|
222
|
-
if (
|
|
223
|
-
const m = (v =
|
|
224
|
-
|
|
224
|
+
let f = null;
|
|
225
|
+
if (a) {
|
|
226
|
+
const m = (v = a.filter.range) == null ? void 0 : v[0];
|
|
227
|
+
f = [z(m == null ? void 0 : m.gte), z(m == null ? void 0 : m.lte)];
|
|
225
228
|
}
|
|
226
229
|
const p = [];
|
|
227
|
-
let g = Math.floor(
|
|
228
|
-
for (; g <
|
|
229
|
-
const m = g + o, h =
|
|
230
|
+
let g = Math.floor(n / o) * o;
|
|
231
|
+
for (; g < s; ) {
|
|
232
|
+
const m = g + o, h = f && f[0] === g && f[1] === m;
|
|
230
233
|
p.push({
|
|
231
234
|
min: g,
|
|
232
235
|
max: m,
|
|
@@ -234,32 +237,32 @@ function ee(e, o) {
|
|
|
234
237
|
}), g = m;
|
|
235
238
|
}
|
|
236
239
|
return p;
|
|
237
|
-
}, [i,
|
|
238
|
-
l([
|
|
239
|
-
},
|
|
240
|
-
l([
|
|
241
|
-
},
|
|
240
|
+
}, [i, n, s, o]), d = (a) => {
|
|
241
|
+
l([a, r[1]]);
|
|
242
|
+
}, t = (a) => {
|
|
243
|
+
l([r[0], a]);
|
|
244
|
+
}, u = n !== r[0] || s !== r[1];
|
|
242
245
|
return {
|
|
243
246
|
/** Minimum value */
|
|
244
|
-
min:
|
|
247
|
+
min: n,
|
|
245
248
|
/** Maximum value */
|
|
246
|
-
max:
|
|
249
|
+
max: s,
|
|
247
250
|
/** Range value */
|
|
248
|
-
range:
|
|
251
|
+
range: r,
|
|
249
252
|
/** Update range function */
|
|
250
253
|
updateRange: l,
|
|
251
254
|
/** Ranges */
|
|
252
255
|
ranges: c,
|
|
253
256
|
/** Handle min change */
|
|
254
|
-
handleMinChange:
|
|
257
|
+
handleMinChange: d,
|
|
255
258
|
/** Handle max change */
|
|
256
|
-
handleMaxChange:
|
|
259
|
+
handleMaxChange: t,
|
|
257
260
|
/** Is selected */
|
|
258
|
-
isSelected:
|
|
261
|
+
isSelected: u
|
|
259
262
|
};
|
|
260
263
|
}
|
|
261
264
|
function te() {
|
|
262
|
-
const { products: e, keywords: o } = y((
|
|
265
|
+
const { products: e, keywords: o } = y((n) => n.response);
|
|
263
266
|
return {
|
|
264
267
|
/** Array of products */
|
|
265
268
|
products: e ?? { hits: [], total: 0 },
|
|
@@ -268,63 +271,63 @@ function te() {
|
|
|
268
271
|
};
|
|
269
272
|
}
|
|
270
273
|
function ne() {
|
|
271
|
-
const e = y((
|
|
272
|
-
var
|
|
273
|
-
return (
|
|
274
|
+
const e = y((n) => {
|
|
275
|
+
var s;
|
|
276
|
+
return (s = n.query.products) == null ? void 0 : s.filter;
|
|
274
277
|
});
|
|
275
|
-
return b(() => e ? e.reduce((
|
|
278
|
+
return b(() => e ? e.reduce((n, s) => n + (Array.isArray(s.value) ? s.value.length : 1), 0) : 0, [e]);
|
|
276
279
|
}
|
|
277
280
|
function A(e) {
|
|
278
281
|
return e && !Number.isNaN(e) ? e : 0;
|
|
279
282
|
}
|
|
280
283
|
function re(e, o) {
|
|
281
|
-
const { from:
|
|
282
|
-
var
|
|
284
|
+
const { from: n, size: s, total: r } = y((t) => {
|
|
285
|
+
var u, a, f, p, g;
|
|
283
286
|
return {
|
|
284
|
-
from: A(((
|
|
285
|
-
size: A(((
|
|
286
|
-
total: A(((g = (p =
|
|
287
|
+
from: A(((u = t.query.products) == null ? void 0 : u.from) ?? 0),
|
|
288
|
+
size: A(((f = (a = t.response) == null ? void 0 : a.products) == null ? void 0 : f.size) ?? 0),
|
|
289
|
+
total: A(((g = (p = t.response) == null ? void 0 : p.products) == null ? void 0 : g.total) ?? 0)
|
|
287
290
|
};
|
|
288
|
-
}), { updateSearch: l } = x(), i =
|
|
291
|
+
}), { updateSearch: l } = x(), i = n + s, c = [...e].reverse().filter((t) => t + o < r);
|
|
289
292
|
return {
|
|
290
293
|
/** from value */
|
|
291
|
-
from:
|
|
294
|
+
from: n,
|
|
292
295
|
/** to value */
|
|
293
296
|
to: i,
|
|
294
297
|
/** total value */
|
|
295
|
-
total:
|
|
298
|
+
total: r,
|
|
296
299
|
/** size value */
|
|
297
|
-
size:
|
|
300
|
+
size: s,
|
|
298
301
|
/** Array of size options */
|
|
299
302
|
sizeOptions: c,
|
|
300
303
|
/** Should be called when size is changed */
|
|
301
|
-
handleSizeChange: (
|
|
304
|
+
handleSizeChange: (t) => {
|
|
302
305
|
l({
|
|
303
306
|
products: {
|
|
304
|
-
size: z(
|
|
307
|
+
size: z(t)
|
|
305
308
|
}
|
|
306
309
|
});
|
|
307
310
|
}
|
|
308
311
|
};
|
|
309
312
|
}
|
|
310
313
|
function B(e, o) {
|
|
311
|
-
return e.length !== o.length ? !1 : e.every((
|
|
314
|
+
return e.length !== o.length ? !1 : e.every((n) => o.find((s) => n.field === s.field && n.order === s.order));
|
|
312
315
|
}
|
|
313
316
|
function se(e) {
|
|
314
317
|
var l, i;
|
|
315
|
-
const o = y((c) => c.query), { updateSearch:
|
|
318
|
+
const o = y((c) => c.query), { updateSearch: n } = x();
|
|
316
319
|
return {
|
|
317
320
|
/** Active sort */
|
|
318
321
|
activeSort: ((l = e.find((c) => {
|
|
319
|
-
var
|
|
320
|
-
return B(c.value.sort, ((
|
|
322
|
+
var d;
|
|
323
|
+
return B(c.value.sort, ((d = o.products) == null ? void 0 : d.sort) || []);
|
|
321
324
|
})) == null ? void 0 : l.id) ?? ((i = e[0]) == null ? void 0 : i.id),
|
|
322
325
|
/** Set sort function */
|
|
323
326
|
setSort: (c) => {
|
|
324
|
-
const
|
|
325
|
-
|
|
327
|
+
const d = e.find((t) => t.id === c);
|
|
328
|
+
d && n({
|
|
326
329
|
products: {
|
|
327
|
-
sort:
|
|
330
|
+
sort: d.value.sort
|
|
328
331
|
}
|
|
329
332
|
});
|
|
330
333
|
}
|
|
@@ -344,22 +347,22 @@ function E({
|
|
|
344
347
|
language: e = "en-US",
|
|
345
348
|
interimResults: o = !1
|
|
346
349
|
} = {}) {
|
|
347
|
-
const [
|
|
348
|
-
({ onResult: c, onError:
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
var
|
|
352
|
-
const { transcript:
|
|
353
|
-
c(
|
|
354
|
-
},
|
|
350
|
+
const [n, s] = M(!1), r = q(null), l = S(
|
|
351
|
+
({ onResult: c, onError: d }) => {
|
|
352
|
+
const t = new P();
|
|
353
|
+
t.lang = e, t.interimResults = o, t.onstart = () => s(!0), t.onresult = (u) => {
|
|
354
|
+
var f, p;
|
|
355
|
+
const { transcript: a } = (p = (f = u.results) == null ? void 0 : f[0]) == null ? void 0 : p[0];
|
|
356
|
+
c(a);
|
|
357
|
+
}, d && (t.onerror = (u) => d(u.error)), t.onend = () => s(!1), r.current = t, t.start();
|
|
355
358
|
},
|
|
356
359
|
[e, o]
|
|
357
360
|
), i = S(() => {
|
|
358
361
|
var c;
|
|
359
|
-
(c =
|
|
360
|
-
}, [
|
|
362
|
+
(c = r.current) == null || c.stop();
|
|
363
|
+
}, [r]);
|
|
361
364
|
return {
|
|
362
|
-
listening:
|
|
365
|
+
listening: n,
|
|
363
366
|
startListening: l,
|
|
364
367
|
stopListening: i
|
|
365
368
|
};
|
|
@@ -367,16 +370,16 @@ function E({
|
|
|
367
370
|
const oe = D ? E : U;
|
|
368
371
|
function $(e, o) {
|
|
369
372
|
if (!e.length || !o.length) return [];
|
|
370
|
-
const
|
|
371
|
-
return e.forEach((
|
|
372
|
-
var
|
|
373
|
-
(
|
|
373
|
+
const n = o.reduce((s, r) => (s[r] = {}, s), {});
|
|
374
|
+
return e.forEach((s) => {
|
|
375
|
+
var r;
|
|
376
|
+
(r = s.customFields) == null || r.forEach(({ key: l, value: i }) => {
|
|
374
377
|
const c = l.toLowerCase();
|
|
375
|
-
o.includes(c) && (
|
|
378
|
+
o.includes(c) && (n[c][i] = n[c][i] || [], n[c][i].push(s));
|
|
376
379
|
});
|
|
377
|
-
}), Object.entries(
|
|
378
|
-
field:
|
|
379
|
-
options: Object.entries(
|
|
380
|
+
}), Object.entries(n).map(([s, r]) => ({
|
|
381
|
+
field: s,
|
|
382
|
+
options: Object.entries(r).map(([l, i]) => ({
|
|
380
383
|
value: l,
|
|
381
384
|
skus: i,
|
|
382
385
|
unavailable: !1,
|
|
@@ -385,16 +388,16 @@ function $(e, o) {
|
|
|
385
388
|
}));
|
|
386
389
|
}
|
|
387
390
|
function I(e, o) {
|
|
388
|
-
return e.length ? e.map(({ field:
|
|
389
|
-
field:
|
|
390
|
-
options:
|
|
391
|
+
return e.length ? e.map(({ field: n, options: s }) => ({
|
|
392
|
+
field: n,
|
|
393
|
+
options: s.map((r) => {
|
|
391
394
|
var c;
|
|
392
|
-
const l = !((c =
|
|
393
|
-
var
|
|
394
|
-
return
|
|
395
|
-
}))), i = o[
|
|
395
|
+
const l = !((c = r.skus) != null && c.some((d) => Object.entries(o).every(([t, u]) => {
|
|
396
|
+
var f, p;
|
|
397
|
+
return t === n ? !0 : ((p = (f = d.customFields) == null ? void 0 : f.find((g) => g.key.toLowerCase() === t)) == null ? void 0 : p.value) === u;
|
|
398
|
+
}))), i = o[n] === r.value;
|
|
396
399
|
return {
|
|
397
|
-
...
|
|
400
|
+
...r,
|
|
398
401
|
unavailable: l,
|
|
399
402
|
selected: i
|
|
400
403
|
};
|
|
@@ -402,16 +405,16 @@ function I(e, o) {
|
|
|
402
405
|
})) : [];
|
|
403
406
|
}
|
|
404
407
|
function ce(e = [], o = []) {
|
|
405
|
-
const [
|
|
406
|
-
|
|
407
|
-
const
|
|
408
|
-
return
|
|
408
|
+
const [n, s] = M({}), r = b(() => I($(e, o), n), [e, o, n]), l = S((c, d) => {
|
|
409
|
+
s((t) => {
|
|
410
|
+
const u = { ...t };
|
|
411
|
+
return u[c] === d ? delete u[c] : u[c] = d, u;
|
|
409
412
|
});
|
|
410
|
-
}, []), i = b(() => Object.keys(
|
|
411
|
-
const
|
|
412
|
-
return (
|
|
413
|
-
}).reduce((
|
|
414
|
-
return { swatches:
|
|
413
|
+
}, []), i = b(() => Object.keys(n).filter((t) => n[t]).length === 0 ? [] : r.filter(({ field: t }) => n[t]).map(({ field: t, options: u }) => {
|
|
414
|
+
const a = n[t], f = u.find((p) => p.value === a);
|
|
415
|
+
return (f == null ? void 0 : f.skus) ?? [];
|
|
416
|
+
}).reduce((t, u) => t.filter((a) => u.includes(a))), [r, n]);
|
|
417
|
+
return { swatches: r, toggleOption: l, matchedSkus: i };
|
|
415
418
|
}
|
|
416
419
|
export {
|
|
417
420
|
D as speechToTextSupported,
|
|
@@ -419,7 +422,7 @@ export {
|
|
|
419
422
|
Q as useDecoratedSearchResults,
|
|
420
423
|
W as useFacet,
|
|
421
424
|
X as useFacets,
|
|
422
|
-
|
|
425
|
+
ue as useLoadMore,
|
|
423
426
|
y as useNostoAppState,
|
|
424
427
|
Y as usePagination,
|
|
425
428
|
Z as usePersonalization,
|
package/dist/preact/serp.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const 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;
|
package/dist/preact/serp.es.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { s as l } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
import { u as f, c as u, S, C as m } from "../configContext-GuZOIX3o.js";
|
|
3
|
-
import { r as g } from "../renderHeadless-BteGML1G.js";
|
|
4
1
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
|
-
import {
|
|
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";
|
|
6
6
|
const h = "nosto:search:scrollPos";
|
|
7
|
-
function
|
|
7
|
+
function v() {
|
|
8
8
|
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
9
9
|
}
|
|
10
|
-
function B({ children:
|
|
11
|
-
const { pageType:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
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 });
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
...
|
|
22
|
+
const w = {
|
|
23
|
+
...d,
|
|
24
24
|
persistentSearchCache: !1,
|
|
25
25
|
preservePageScroll: !1
|
|
26
26
|
};
|
|
27
|
-
function
|
|
27
|
+
function y(o = {}) {
|
|
28
28
|
return {
|
|
29
29
|
pageType: "search",
|
|
30
|
-
...
|
|
31
|
-
...
|
|
30
|
+
...w,
|
|
31
|
+
...o
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
return
|
|
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 }) });
|
|
37
37
|
}
|
|
38
38
|
export {
|
|
39
|
-
|
|
39
|
+
E as SearchPageProvider,
|
|
40
40
|
B as SerpElement
|
|
41
41
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { ComponentChildren } from 'preact';
|
|
2
|
-
type
|
|
3
|
-
|
|
1
|
+
import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
|
|
2
|
+
type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
|
|
3
|
+
type Props<C extends AsComponent> = {
|
|
4
|
+
as?: C;
|
|
4
5
|
onSearchInput: (target: HTMLInputElement) => void;
|
|
6
|
+
children?: ComponentChildren;
|
|
7
|
+
componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
|
|
5
8
|
};
|
|
6
|
-
export declare function SearchInput({
|
|
9
|
+
export declare function SearchInput<C extends AsComponent>({ as, componentProps, onSearchInput, children }: Props<C>): JSX.Element;
|
|
7
10
|
export {};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { ComponentChildren } from 'preact';
|
|
1
|
+
import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
|
|
2
|
+
type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
|
|
2
3
|
/**
|
|
3
4
|
* @group Components
|
|
4
5
|
*/
|
|
5
|
-
export type SerpElementProps = {
|
|
6
|
-
children: ComponentChildren;
|
|
6
|
+
export type SerpElementProps<C extends AsComponent> = {
|
|
7
7
|
hit: {
|
|
8
8
|
productId: string;
|
|
9
9
|
url?: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
as?: C;
|
|
12
|
+
componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
|
|
13
|
+
children?: ComponentChildren;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
16
|
* Wrapper component that can be used to wrap any element in the search result list.
|
|
15
17
|
*
|
|
16
18
|
* @group Components
|
|
17
19
|
*/
|
|
18
|
-
export declare function SerpElement({ children, hit,
|
|
20
|
+
export declare function SerpElement<C extends AsComponent>({ as, children, hit, componentProps }: SerpElementProps<C>): JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { SearchTermsFacet } from '@nosto/nosto-js/client';
|
|
2
|
+
/**
|
|
3
|
+
* Extra options for the useFacet hook.
|
|
4
|
+
*/
|
|
5
|
+
export interface UseFacetOptions {
|
|
6
|
+
active?: boolean;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* Preact hook that provides facet state to the component.
|
|
4
10
|
* @param facet
|
|
@@ -48,7 +54,7 @@ import { SearchTermsFacet } from '@nosto/nosto-js/client';
|
|
|
48
54
|
* ```
|
|
49
55
|
* @group Hooks
|
|
50
56
|
*/
|
|
51
|
-
export declare function useFacet(facet: SearchTermsFacet): {
|
|
57
|
+
export declare function useFacet(facet: SearchTermsFacet, options?: UseFacetOptions): {
|
|
52
58
|
/** Active value */
|
|
53
59
|
active: boolean;
|
|
54
60
|
/** Selected filters count */
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ComponentChildren, VNode } from 'preact';
|
|
2
|
-
type Props = {
|
|
3
|
-
children: ComponentChildren;
|
|
4
|
-
/**
|
|
5
|
-
* Update the element with custom logic. Each vnode (valid JSX element) will be passed to this function recursively.
|
|
6
|
-
* You may either mutate the existing node, or create a new one.
|
|
7
|
-
*
|
|
8
|
-
* @param vnode Current target node
|
|
9
|
-
* @returns {VNode} if the vnode should be updated
|
|
10
|
-
* @returns {null} if the vnode should be removed
|
|
11
|
-
*/
|
|
12
|
-
updateElement: <P extends object>(vnode: VNode<P>, context: Context) => VNode<P> | null;
|
|
13
|
-
};
|
|
14
|
-
type Context = {
|
|
15
|
-
depth: number;
|
|
16
|
-
};
|
|
17
|
-
export declare function renderHeadless(props: Props, ctx?: Context): ComponentChildren;
|
|
18
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { VNode } from 'preact';
|
|
2
|
-
import { JSX } from 'preact/jsx-runtime';
|
|
3
|
-
export type UnknownVnode = VNode<any>;
|
|
4
|
-
export declare function isHTMLInput(vnode: UnknownVnode): vnode is VNode<JSX.IntrinsicElements["input"]>;
|
|
5
|
-
export declare function isVNode(child: unknown): child is VNode;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { toChildArray as o } from "preact";
|
|
2
|
-
function d(e) {
|
|
3
|
-
return e.type === "input";
|
|
4
|
-
}
|
|
5
|
-
function u(e) {
|
|
6
|
-
return !!e && typeof e == "object" && "type" in e && "props" in e;
|
|
7
|
-
}
|
|
8
|
-
function i(e, t = { depth: 0 }) {
|
|
9
|
-
const { children: p } = e;
|
|
10
|
-
return o(p).map((r) => {
|
|
11
|
-
if (!u(r))
|
|
12
|
-
return r;
|
|
13
|
-
const n = e.updateElement(r, t);
|
|
14
|
-
return n === null ? null : (n.props = {
|
|
15
|
-
...n.props,
|
|
16
|
-
children: i({ ...e, children: n.props.children }, { depth: t.depth + 1 })
|
|
17
|
-
}, n);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
d as i,
|
|
22
|
-
i as r
|
|
23
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("preact");function i(e){return e.type==="input"}function o(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function u(e,t={depth:0}){const{children:p}=e;return s.toChildArray(p).map(r=>{if(!o(r))return r;const n=e.updateElement(r,t);return n===null?null:(n.props={...n.props,children:u({...e,children:n.props.children},{depth:t.depth+1})},n)})}exports.isHTMLInput=i;exports.renderHeadless=u;
|