@nosto/search-js 3.19.0 → 3.19.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/{AutocompletePageProvider-DMtA79nZ.js → AutocompletePageProvider-DsUoIbbx.js} +1 -1
- package/dist/{AutocompletePageProvider-CjNvOYZz.cjs → AutocompletePageProvider-Xg9H1y3f.cjs} +1 -1
- package/dist/preact/autocomplete/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete/autocomplete.es.js +1 -1
- package/dist/preact/hooks/hooks.cjs.js +1 -1
- package/dist/preact/hooks/hooks.d.ts +1 -1
- package/dist/preact/hooks/hooks.es.js +82 -80
- package/dist/preact/hooks/src/useHistory.d.ts +9 -1
- package/dist/preact/inject/inject.cjs.js +1 -1
- package/dist/preact/inject/inject.es.js +1 -1
- package/dist/useHistory-joVBx1r2.js +27 -0
- package/dist/useHistory-rc2PvSkv.cjs +1 -0
- package/package.json +1 -1
- package/dist/useHistory-CJSGam5n.cjs +0 -1
- package/dist/useHistory-DeIqqw-P.js +0 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { u as o } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
2
|
import { c as i, S as n, C as s } from "./useActions-CSNwQtT1.js";
|
|
3
3
|
import { d as u, u as m, S as c } from "./baseConfig-DeHr2N1l.js";
|
|
4
|
-
import { g as f } from "./useHistory-
|
|
4
|
+
import { g as f } from "./useHistory-joVBx1r2.js";
|
|
5
5
|
import { useEffect as l } from "preact/hooks";
|
|
6
6
|
const p = {
|
|
7
7
|
...u,
|
package/dist/{AutocompletePageProvider-CjNvOYZz.cjs → AutocompletePageProvider-Xg9H1y3f.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-CY9uts_o.cjs"),u=require("./baseConfig-CaRa_-zN.cjs"),s=require("./useHistory-
|
|
1
|
+
"use strict";const o=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-CY9uts_o.cjs"),u=require("./baseConfig-CaRa_-zN.cjs"),s=require("./useHistory-rc2PvSkv.cjs"),a=require("preact/hooks"),l={...u.defaultBaseConfig,memoryCache:!1,historyEnabled:!0,historySize:5,debounceDelay:500,minQueryLength:2};function n(e={}){return{pageType:"autocomplete",...l,...e}}function m({config:e,store:i,children:c}){const t=i??r.createStore();return u.useCheckClientScript(),a.useEffect(()=>{t.updateState({historyItems:s.getSavedHistory()})},[t]),o.u(r.ConfigContext,{value:n(e),children:o.u(r.StoreContext,{value:t,children:[o.u(u.StoreActionsListener,{}),c]})})}exports.AutocompletePageProvider=m;exports.makeAutocompleteConfig=n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../AutocompletePageProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../AutocompletePageProvider-Xg9H1y3f.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../../index.es-Dp6Iaxz3.cjs"),a=require("../../BaseElement-CIHACCWd.cjs"),m=require("preact/hooks"),p=require("../../cl-B00bZ7jc.cjs");function d({children:t,hit:e,as:o,componentProps:n}){const r=m.useCallback(()=>{e&&"productId"in e&&i.s(c=>c.recordSearchClick("autocomplete",e))},[e]);return u.u(a.BaseElement,{onClick:r,as:o,componentProps:n,className:"ns-autocomplete-element",children:t})}function P({children:t,class:e,onSubmit:o}){return u.u("div",{className:p.cl("ns-autocomplete-element",e),onClick:o,onKeyDown:n=>{n.key==="Enter"&&o()},children:t})}function f({as:t,componentProps:e,onSearchInput:o,children:n}){const r={...e,onInput:l=>{o(l.target)}},c=t??"input";return t||(r.type="search"),u.u(c,{...r,children:n})}exports.AutocompletePageProvider=s.AutocompletePageProvider;exports.AutocompleteElement=d;exports.HistoryElement=P;exports.SearchInput=f;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as g } from "../../AutocompletePageProvider-
|
|
1
|
+
import { A as g } from "../../AutocompletePageProvider-DsUoIbbx.js";
|
|
2
2
|
import { u as m } from "../../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
3
|
import { s } from "../../index.es-XNBESE3P.js";
|
|
4
4
|
import { B as a } from "../../BaseElement-DD_4UwDm.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../useActions-CY9uts_o.cjs"),q=require("../../logger-Boh_C6Bz.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../../useActions-CY9uts_o.cjs"),q=require("../../logger-Boh_C6Bz.cjs"),S=require("../../useLoadMore-CBshMpps.cjs"),R=require("../../eventBusSubscribe-oONOUGH8.cjs"),d=require("preact/hooks"),M=require("../../useHistory-rc2PvSkv.cjs"),L=require("../../index.es-Dp6Iaxz3.cjs"),z=require("../../eventBusDispatch-BKQcSHAB.cjs"),A=require("../../parseNumber-FsZ8w61u.cjs");function O(e){const s=S.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&q.isPlainObject(e)?e:s}function X(e,s){const t=e.data?.filter(f=>f.selected).length??0,{active:o}={active:t>0,...s},[n,c]=d.useState(o),{toggleProductFilter:u}=v.useActions(),a=d.useCallback(()=>{c(!n)},[n]);return R.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{c(!1)}}),{active:n,selectedFiltersCount:t,toggleActive:a,toggleProductFilter:u}}function j(){const{loading:e,facets:s}=S.useNostoAppState(t=>({loading:t.loading,facets:t.response?.products?.facets??[]}));return{loading:e,facets:s}}function E(e,s){const t=s-e;return!isNaN(t)&&t>0?new Array(s-e).fill(void 0).map((o,n)=>n+e):[]}function B(e){const{query:s,products:t}=S.useNostoAppState(o=>({query:o.query,products:o.response.products}));return d.useMemo(()=>{if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const o=s.products?.from??0,n=e?.width??1/0,c=Math.max(Math.floor(n-1)/2,1),u=t.size>0?Math.floor(o/t.size)+1:1,a=t.size>0?Math.ceil(t.total/t.size):0,f=F=>F>=u-c&&F<=u+c,r=o+1,i=Math.min(o+t.total,t.total),l={from:o,page:u,current:!0},p=F=>({from:(F-1)*t.size,page:F,current:F===u}),h=u>1?p(u-1):void 0,g=u<a?p(u+1):void 0,m=u-c-1>1?p(1):void 0,b=u+c+1<a?p(a):void 0,y=E(1,a+1).filter(f).map(p);return!m&&y[0]?.page===2&&y.unshift(p(1)),!b&&y[y.length-1]?.page===a-1&&y.push(p(a)),{totalPages:a,resultsFrom:r,resultsTo:i,current:l,prev:h,next:g,first:m,last:b,pages:y}},[s,t,e?.width])}function D(){const[e,s]=d.useState([]),[t,o]=d.useState([]);return d.useEffect(()=>{L.s(async n=>{const{products:c,segments:u}=await n.getSearchSessionParams();s(u??[]),o(c?.personalizationBoost??[])})},[]),{segments:e,boost:t}}function V(){const{facets:e}=S.useNostoAppState(r=>({facets:r.response.products?.facets??[]})),{replaceFilter:s,toggleProductFilter:t}=v.useActions(),o=d.useCallback(r=>{const i=e?.find(l=>l.type==="stats"&&l.field===r);if(i&&"min"in i&&"max"in i)return i},[e]),n=d.useCallback(r=>e?.find(i=>i.field===r)?.name??r,[e]),c=d.useCallback(r=>"field"in r&&(r.value instanceof Array||r.range instanceof Array),[]),u=d.useCallback(r=>({...r,range:r.range?.map(i=>({gt:i.gt?Number(i.gt):i.gt,gte:i.gte?Number(i.gte):i.gte,lt:i.lt?Number(i.lt):i.lt,lte:i.lte?Number(i.lte):i.lte}))}),[]),a=d.useCallback(r=>(r.value??[]).map(l=>({value:l,field:r.field,name:n(r.field),filter:u(r),remove:()=>{t(r.field,l,!1)}})),[u,n,t]),f=d.useCallback(r=>(r.range??[]).map(l=>{const p=l.gte??l.gt??o(r.field)?.min,h=l.lte??l.lt??o(r.field)?.max;if(p!==void 0&&h!==void 0)return{value:`${p} - ${h}`,field:r.field,name:n(r.field),filter:u(r),remove:()=>{s(r.field,void 0)}}}).filter(Boolean),[u,o,n,s]);return{selectFilters:c,toValueFilter:a,toRangeFilter:f}}function T(){const{filter:e}=S.useNostoAppState(a=>({filter:a.query.products?.filter??[]})),{updateSearch:s}=v.useActions(),{selectFilters:t,toValueFilter:o,toRangeFilter:n}=V(),c=d.useMemo(()=>e?e.filter(t).flatMap(a=>"value"in a?o(a):"range"in a?n(a):[]).filter(Boolean):[],[e,t,n,o]),u=d.useCallback(()=>{s({products:{filter:[]}}),z.dispatchNostoEvent({event:"events/removeAllFilters",params:null})},[s]);return{filters:c,removeAll:u}}function x(e){const{replaceFilter:s}=v.useActions(),{query:t,products:o}=S.useNostoAppState(g=>({query:g.query,products:g.response.products})),n=o?.facets?.find(g=>g.id===e),c=t.products?.filter?.find(g=>g.field===n?.field),u=H(c),a=n&&"min"in n?Math.floor(n.min??0):0,f=n&&"max"in n?Math.ceil(n.max??0):0,r=u[0]!==void 0||u[1]!==void 0,[i,l]=d.useState(r),p=d.useCallback(()=>{l(g=>!g)},[]),h=d.useCallback(([g,m])=>{if(!n)return;const b=$(g,m,a,f);s(n.field,b)},[a,f,s,n]);return R.useEventBusSubscribe({event:"events/removeAllFilters",callback:()=>{l(!1)}}),n?{min:a,max:f,range:[u[0]??a,u[1]??f],updateRange:h,active:i,toggleActive:p}:{min:0,max:0,range:[0,0],active:!1,toggleActive:()=>{},updateRange:()=>{}}}function H(e){const s=e?.range?.[0];return typeof s=="object"&&("gte"in s||"lte"in s)?[A.parseNumber(s.gte),A.parseNumber(s.lte)]:[void 0,void 0]}function $(e,s,t,o){const n=e!==void 0?Math.floor(e):void 0,c=s!==void 0?Math.ceil(s):void 0,u=n!==void 0,a=c!==void 0;if((t===n||!u)&&(o===c||!a))return;const f={};return u&&n!==t&&(f.gte=n.toString()),a&&c!==o&&(f.lte=c.toString()),Object.keys(f).length>0?f:void 0}function _(e,s){const{min:t,max:o,range:n,updateRange:c}=x(e),{filters:u}=T(),a=d.useMemo(()=>{const l=u.find(m=>m?.filter?.range);let p=null;if(l){const m=l.filter.range?.[0];p=[A.parseNumber(m?.gte),A.parseNumber(m?.lte)]}const h=[];let g=Math.floor(t/s)*s;for(;g<o;){const m=g+s,b=p&&p[0]===g&&p[1]===m;h.push({min:g,max:m,selected:b}),g=m}return h},[u,t,o,s]),f=l=>{c([l,n[1]])},r=l=>{c([n[0],l])},i=t!==n[0]||o!==n[1];return{min:t,max:o,range:n,updateRange:c,ranges:a,handleMinChange:f,handleMaxChange:r,isSelected:i}}function U(){const{products:e,keywords:s}=S.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:s??{hits:[],total:0}}}function I(){const e=S.useNostoAppState(t=>t.query.products?.filter);return d.useMemo(()=>e?e.reduce((t,o)=>t+(Array.isArray(o.value)?o.value.length:1),0):0,[e])}const Z=5*60*1e3,w=new Map;function G(e){const[s,t]=d.useState({product:null,loading:!0,error:null});return d.useEffect(()=>{if(!e){t({product:null,loading:!1,error:"Product handle is required"});return}t(n=>({...n,loading:!0,error:null}));const o=K(e);if(o){t({product:o,loading:!1,error:null});return}J(e).then(n=>{Q(e,n),t({product:n,loading:!1,error:null})}).catch(n=>{t({product:null,loading:!1,error:n.message||"Failed to fetch product"})})},[e]),s}async function J(e){const s=await fetch(`/products/${e}.js`);if(!s.ok)throw new Error(`Failed to fetch product: ${s.status} ${s.statusText}`);return s.json()}function K(e){const s=w.get(e);return s?Date.now()-s.created>Z?(w.delete(e),null):s.product:null}function Q(e,s){w.set(e,{product:s,created:Date.now()})}function N(e){return e&&!Number.isNaN(e)?e:0}function W(e,s){const{from:t,size:o,total:n}=S.useNostoAppState(r=>({from:N(r.query.products?.from??0),size:N(r.response?.products?.size??s),total:N(r.response?.products?.total??0)})),{updateSearch:c}=v.useActions(),u=t+o,a=d.useMemo(()=>[...e].reverse().filter(r=>r<n),[e,n]),f=d.useCallback(r=>{c({products:{size:A.parseNumber(r)}})},[c]);return{from:t,to:u,total:n,size:o,sizeOptions:a,handleSizeChange:f}}function Y(e,s){return e.length!==s.length?!1:e.every(t=>s.find(o=>t.field===o.field&&t.order===o.order))}function ee(e){const s=S.useNostoAppState(c=>c.query),{updateSearch:t}=v.useActions();return{activeSort:e.find(c=>Y(c.value.sort,s.products?.sort||[]))?.id??e[0]?.id,setSort:c=>{const u=e.find(a=>a.id===c);u&&t({products:{sort:u.value.sort}})}}}const k=window.SpeechRecognition||window.webkitSpeechRecognition,P=!!(k&&typeof k=="function");function te(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function se({language:e="en-US",interimResults:s=!1,onResult:t,onError:o}={}){const[n,c]=d.useState(!1),u=d.useRef(null),a=d.useCallback(()=>{const r=new k;r.lang=e,r.interimResults=s,r.onstart=()=>c(!0),t&&(r.onresult=i=>{const{transcript:l}=i.results?.[0]?.[0];t(l)}),o&&(r.onerror=i=>o(i.error)),r.onend=()=>c(!1),u.current=r,r.start()},[e,s,o,t]),f=d.useCallback(()=>{u.current?.stop()},[u]);return{listening:n,startListening:a,stopListening:f}}const ne=P?se:te;function oe(e,s){if(!e.length||!s.length)return[];const t=s.reduce((o,n)=>(o[n]={},o),{});return e.forEach(o=>{o.customFields?.forEach(({key:n,value:c})=>{const u=n.toLowerCase();s.includes(u)&&(t[u][c]=t[u][c]||[],t[u][c].push(o))})}),Object.entries(t).filter(o=>Object.keys(o[1]).length).map(([o,n])=>({field:o,options:Object.entries(n).map(([c,u])=>({value:c,skus:u,unavailable:!1,selected:!1}))}))}function re(e,s){return e.length?e.map(({field:t,options:o})=>({field:t,options:o.map(n=>{const c=!n.skus?.some(a=>Object.entries(s).every(([f,r])=>f===t?!0:a.customFields?.find(l=>l.key.toLowerCase()===f)?.value===r)),u=s[t]===n.value;return{...n,unavailable:c,selected:u}})})):[]}const C=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function ue(e){if(C.includes(e))return 1e3+C.indexOf(e);const s=parseFloat(e);return isNaN(s)?e:s}function ce(e,s){return[...s].sort((t,o)=>{const[n,c]=[t.value,o.value].map(ue);return n<c?-1:1})}function ie(e=[],s=[]){const[t,o]=d.useState({}),n=d.useMemo(()=>oe(e,s).map(({field:r,options:i})=>({field:r,options:ce(r,i)})),[e,s]),c=d.useMemo(()=>re(n,t),[n,t]),u=d.useCallback((f,r)=>{o(i=>{const l={...i};return l[f]===r?delete l[f]:l[f]=r,l})},[]),a=d.useMemo(()=>Object.keys(t).filter(i=>t[i]).length===0?[]:c.filter(({field:i})=>t[i]).map(({field:i,options:l})=>{const p=t[i];return l.find(g=>g.value===p)?.skus??[]}).reduce((i,l)=>i.filter(p=>l.includes(p))),[c,t]);return{swatches:c,toggleOption:u,matchedSkus:a}}exports.useActions=v.useActions;exports.useLoadMore=S.useLoadMore;exports.useNostoAppState=S.useNostoAppState;exports.addToHistory=M.addToHistory;exports.getSavedHistory=M.getSavedHistory;exports.useHistory=M.useHistory;exports.speechToTextSupported=P;exports.useDecoratedSearchResults=O;exports.useFacet=X;exports.useFacets=j;exports.usePagination=B;exports.usePersonalization=D;exports.useProductFilters=T;exports.useRange=x;exports.useRangeSelector=_;exports.useResponse=U;exports.useSelectedFiltersCount=I;exports.useShopifyProduct=G;exports.useSizeOptions=W;exports.useSort=ee;exports.useSpeechToText=ne;exports.useSwatches=ie;
|
|
@@ -4,7 +4,7 @@ export { useActions } from './src/useActions';
|
|
|
4
4
|
export { useDecoratedSearchResults } from './src/useDecoratedSearchResults';
|
|
5
5
|
export { useFacet, type UseFacetOptions } from './src/useFacet';
|
|
6
6
|
export { useFacets } from './src/useFacets';
|
|
7
|
-
export { useHistory } from './src/useHistory';
|
|
7
|
+
export { addToHistory, getSavedHistory, useHistory } from './src/useHistory';
|
|
8
8
|
export { useLoadMore } from './src/useLoadMore/useLoadMore';
|
|
9
9
|
export { useNostoAppState } from './src/useNostoAppState';
|
|
10
10
|
export { type Page, usePagination } from './src/usePagination';
|
|
@@ -2,9 +2,9 @@ import { h as x } from "../../useActions-CSNwQtT1.js";
|
|
|
2
2
|
import { a as X } from "../../logger-_fg_Za9y.js";
|
|
3
3
|
import { a as v } from "../../useLoadMore-2OmOqicJ.js";
|
|
4
4
|
import { u as be } from "../../useLoadMore-2OmOqicJ.js";
|
|
5
|
-
import { u as
|
|
6
|
-
import { useState as
|
|
7
|
-
import {
|
|
5
|
+
import { u as T } from "../../eventBusSubscribe-CzlS132j.js";
|
|
6
|
+
import { useState as y, useCallback as p, useMemo as S, useEffect as N, useRef as k } from "preact/hooks";
|
|
7
|
+
import { a as Ae, g as Re, u as Le } from "../../useHistory-joVBx1r2.js";
|
|
8
8
|
import { s as z } from "../../index.es-XNBESE3P.js";
|
|
9
9
|
import { d as O } from "../../eventBusDispatch-DPR2Vwd4.js";
|
|
10
10
|
import { p as A } from "../../parseNumber-QA48nJLp.js";
|
|
@@ -12,14 +12,14 @@ function ie(e) {
|
|
|
12
12
|
const n = v((t) => t.response);
|
|
13
13
|
return e && Array.isArray(e) || e && X(e) ? e : n;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function ae(e, n) {
|
|
16
16
|
const t = e.data?.filter((d) => d.selected).length ?? 0, { active: o } = {
|
|
17
17
|
active: t > 0,
|
|
18
18
|
...n
|
|
19
|
-
}, [r, i] =
|
|
19
|
+
}, [r, i] = y(o), { toggleProductFilter: c } = x(), u = p(() => {
|
|
20
20
|
i(!r);
|
|
21
21
|
}, [r]);
|
|
22
|
-
return
|
|
22
|
+
return T({
|
|
23
23
|
event: "events/removeAllFilters",
|
|
24
24
|
callback: () => {
|
|
25
25
|
i(!1);
|
|
@@ -30,12 +30,12 @@ function ue(e, n) {
|
|
|
30
30
|
/** Selected filters count */
|
|
31
31
|
selectedFiltersCount: t,
|
|
32
32
|
/** Toggle active function */
|
|
33
|
-
toggleActive:
|
|
33
|
+
toggleActive: u,
|
|
34
34
|
/** Toggle product filter function */
|
|
35
35
|
toggleProductFilter: c
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function ue() {
|
|
39
39
|
const { loading: e, facets: n } = v((t) => ({
|
|
40
40
|
loading: t.loading,
|
|
41
41
|
facets: t.response?.products?.facets ?? []
|
|
@@ -64,7 +64,7 @@ function le(e) {
|
|
|
64
64
|
resultsTo: 0,
|
|
65
65
|
pages: []
|
|
66
66
|
};
|
|
67
|
-
const o = n.products?.from ?? 0, r = e?.width ?? 1 / 0, i = Math.max(Math.floor(r - 1) / 2, 1), c = t.size > 0 ? Math.floor(o / t.size) + 1 : 1,
|
|
67
|
+
const o = n.products?.from ?? 0, r = e?.width ?? 1 / 0, i = Math.max(Math.floor(r - 1) / 2, 1), c = t.size > 0 ? Math.floor(o / t.size) + 1 : 1, u = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (b) => b >= c - i && b <= c + i, s = o + 1, a = Math.min(o + t.total, t.total), l = {
|
|
68
68
|
from: o,
|
|
69
69
|
page: c,
|
|
70
70
|
current: !0
|
|
@@ -72,23 +72,23 @@ function le(e) {
|
|
|
72
72
|
from: (b - 1) * t.size,
|
|
73
73
|
page: b,
|
|
74
74
|
current: b === c
|
|
75
|
-
}), h = c > 1 ? f(c - 1) : void 0, g = c <
|
|
76
|
-
return !m && w[0]?.page === 2 && w.unshift(f(1)), !
|
|
77
|
-
totalPages:
|
|
75
|
+
}), h = c > 1 ? f(c - 1) : void 0, g = c < u ? f(c + 1) : void 0, m = c - i - 1 > 1 ? f(1) : void 0, F = c + i + 1 < u ? f(u) : void 0, w = C(1, u + 1).filter(d).map(f);
|
|
76
|
+
return !m && w[0]?.page === 2 && w.unshift(f(1)), !F && w[w.length - 1]?.page === u - 1 && w.push(f(u)), {
|
|
77
|
+
totalPages: u,
|
|
78
78
|
resultsFrom: s,
|
|
79
|
-
resultsTo:
|
|
79
|
+
resultsTo: a,
|
|
80
80
|
current: l,
|
|
81
81
|
prev: h,
|
|
82
82
|
next: g,
|
|
83
83
|
first: m,
|
|
84
|
-
last:
|
|
84
|
+
last: F,
|
|
85
85
|
pages: w
|
|
86
86
|
};
|
|
87
87
|
}, [n, t, e?.width]);
|
|
88
88
|
}
|
|
89
89
|
function de() {
|
|
90
|
-
const [e, n] =
|
|
91
|
-
return
|
|
90
|
+
const [e, n] = y([]), [t, o] = y([]);
|
|
91
|
+
return N(() => {
|
|
92
92
|
z(async (r) => {
|
|
93
93
|
const { products: i, segments: c } = await r.getSearchSessionParams();
|
|
94
94
|
n(c ?? []), o(i?.personalizationBoost ?? []);
|
|
@@ -103,23 +103,23 @@ function j() {
|
|
|
103
103
|
facets: s.response.products?.facets ?? []
|
|
104
104
|
})), { replaceFilter: n, toggleProductFilter: t } = x(), o = p(
|
|
105
105
|
(s) => {
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
return
|
|
106
|
+
const a = e?.find((l) => l.type === "stats" && l.field === s);
|
|
107
|
+
if (a && "min" in a && "max" in a)
|
|
108
|
+
return a;
|
|
109
109
|
},
|
|
110
110
|
[e]
|
|
111
111
|
), r = p(
|
|
112
|
-
(s) => e?.find((
|
|
112
|
+
(s) => e?.find((a) => a.field === s)?.name ?? s,
|
|
113
113
|
[e]
|
|
114
114
|
), i = p((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), c = p((s) => ({
|
|
115
115
|
...s,
|
|
116
|
-
range: s.range?.map((
|
|
117
|
-
gt:
|
|
118
|
-
gte:
|
|
119
|
-
lt:
|
|
120
|
-
lte:
|
|
116
|
+
range: s.range?.map((a) => ({
|
|
117
|
+
gt: a.gt ? Number(a.gt) : a.gt,
|
|
118
|
+
gte: a.gte ? Number(a.gte) : a.gte,
|
|
119
|
+
lt: a.lt ? Number(a.lt) : a.lt,
|
|
120
|
+
lte: a.lte ? Number(a.lte) : a.lte
|
|
121
121
|
}))
|
|
122
|
-
}), []),
|
|
122
|
+
}), []), u = p(
|
|
123
123
|
(s) => (s.value ?? []).map((l) => ({
|
|
124
124
|
value: l,
|
|
125
125
|
field: s.field,
|
|
@@ -148,14 +148,14 @@ function j() {
|
|
|
148
148
|
);
|
|
149
149
|
return {
|
|
150
150
|
selectFilters: i,
|
|
151
|
-
toValueFilter:
|
|
151
|
+
toValueFilter: u,
|
|
152
152
|
toRangeFilter: d
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
function q() {
|
|
156
|
-
const { filter: e } = v((
|
|
157
|
-
filter:
|
|
158
|
-
})), { updateSearch: n } = x(), { selectFilters: t, toValueFilter: o, toRangeFilter: r } = j(), i = S(() => e ? e.filter(t).flatMap((
|
|
156
|
+
const { filter: e } = v((u) => ({
|
|
157
|
+
filter: u.query.products?.filter ?? []
|
|
158
|
+
})), { updateSearch: n } = x(), { selectFilters: t, toValueFilter: o, toRangeFilter: r } = j(), i = S(() => e ? e.filter(t).flatMap((u) => "value" in u ? o(u) : "range" in u ? r(u) : []).filter(Boolean) : [], [e, t, r, o]), c = p(() => {
|
|
159
159
|
n({
|
|
160
160
|
products: {
|
|
161
161
|
filter: []
|
|
@@ -176,33 +176,33 @@ function E(e) {
|
|
|
176
176
|
const { replaceFilter: n } = x(), { query: t, products: o } = v((g) => ({
|
|
177
177
|
query: g.query,
|
|
178
178
|
products: g.response.products
|
|
179
|
-
})), r = o?.facets?.find((g) => g.id === e), i = t.products?.filter?.find((g) => g.field === r?.field), c = V(i),
|
|
179
|
+
})), r = o?.facets?.find((g) => g.id === e), i = t.products?.filter?.find((g) => g.field === r?.field), c = V(i), u = r && "min" in r ? Math.floor(r.min ?? 0) : 0, d = r && "max" in r ? Math.ceil(r.max ?? 0) : 0, s = c[0] !== void 0 || c[1] !== void 0, [a, l] = y(s), f = p(() => {
|
|
180
180
|
l((g) => !g);
|
|
181
181
|
}, []), h = p(
|
|
182
182
|
([g, m]) => {
|
|
183
183
|
if (!r)
|
|
184
184
|
return;
|
|
185
|
-
const
|
|
186
|
-
n(r.field,
|
|
185
|
+
const F = D(g, m, u, d);
|
|
186
|
+
n(r.field, F);
|
|
187
187
|
},
|
|
188
|
-
[
|
|
188
|
+
[u, d, n, r]
|
|
189
189
|
);
|
|
190
|
-
return
|
|
190
|
+
return T({
|
|
191
191
|
event: "events/removeAllFilters",
|
|
192
192
|
callback: () => {
|
|
193
193
|
l(!1);
|
|
194
194
|
}
|
|
195
195
|
}), r ? {
|
|
196
196
|
/** Min value */
|
|
197
|
-
min:
|
|
197
|
+
min: u,
|
|
198
198
|
/** Max value */
|
|
199
199
|
max: d,
|
|
200
200
|
/** Range value */
|
|
201
|
-
range: [c[0] ??
|
|
201
|
+
range: [c[0] ?? u, c[1] ?? d],
|
|
202
202
|
/** Update range function */
|
|
203
203
|
updateRange: h,
|
|
204
204
|
/** Is the range filter active */
|
|
205
|
-
active:
|
|
205
|
+
active: a,
|
|
206
206
|
/** Toggle active state function */
|
|
207
207
|
toggleActive: f
|
|
208
208
|
} : {
|
|
@@ -221,14 +221,14 @@ function V(e) {
|
|
|
221
221
|
return typeof n == "object" && ("gte" in n || "lte" in n) ? [A(n.gte), A(n.lte)] : [void 0, void 0];
|
|
222
222
|
}
|
|
223
223
|
function D(e, n, t, o) {
|
|
224
|
-
const r = e !== void 0 ? Math.floor(e) : void 0, i = n !== void 0 ? Math.ceil(n) : void 0, c = r !== void 0,
|
|
225
|
-
if ((t === r || !c) && (o === i || !
|
|
224
|
+
const r = e !== void 0 ? Math.floor(e) : void 0, i = n !== void 0 ? Math.ceil(n) : void 0, c = r !== void 0, u = i !== void 0;
|
|
225
|
+
if ((t === r || !c) && (o === i || !u))
|
|
226
226
|
return;
|
|
227
227
|
const d = {};
|
|
228
|
-
return c && r !== t && (d.gte = r.toString()),
|
|
228
|
+
return c && r !== t && (d.gte = r.toString()), u && i !== o && (d.lte = i.toString()), Object.keys(d).length > 0 ? d : void 0;
|
|
229
229
|
}
|
|
230
230
|
function fe(e, n) {
|
|
231
|
-
const { min: t, max: o, range: r, updateRange: i } = E(e), { filters: c } = q(),
|
|
231
|
+
const { min: t, max: o, range: r, updateRange: i } = E(e), { filters: c } = q(), u = S(() => {
|
|
232
232
|
const l = c.find((m) => m?.filter?.range);
|
|
233
233
|
let f = null;
|
|
234
234
|
if (l) {
|
|
@@ -238,11 +238,11 @@ function fe(e, n) {
|
|
|
238
238
|
const h = [];
|
|
239
239
|
let g = Math.floor(t / n) * n;
|
|
240
240
|
for (; g < o; ) {
|
|
241
|
-
const m = g + n,
|
|
241
|
+
const m = g + n, F = f && f[0] === g && f[1] === m;
|
|
242
242
|
h.push({
|
|
243
243
|
min: g,
|
|
244
244
|
max: m,
|
|
245
|
-
selected:
|
|
245
|
+
selected: F
|
|
246
246
|
}), g = m;
|
|
247
247
|
}
|
|
248
248
|
return h;
|
|
@@ -250,7 +250,7 @@ function fe(e, n) {
|
|
|
250
250
|
i([l, r[1]]);
|
|
251
251
|
}, s = (l) => {
|
|
252
252
|
i([r[0], l]);
|
|
253
|
-
},
|
|
253
|
+
}, a = t !== r[0] || o !== r[1];
|
|
254
254
|
return {
|
|
255
255
|
/** Minimum value */
|
|
256
256
|
min: t,
|
|
@@ -261,13 +261,13 @@ function fe(e, n) {
|
|
|
261
261
|
/** Update range function */
|
|
262
262
|
updateRange: i,
|
|
263
263
|
/** Ranges */
|
|
264
|
-
ranges:
|
|
264
|
+
ranges: u,
|
|
265
265
|
/** Handle min change */
|
|
266
266
|
handleMinChange: d,
|
|
267
267
|
/** Handle max change */
|
|
268
268
|
handleMaxChange: s,
|
|
269
269
|
/** Is selected */
|
|
270
|
-
isSelected:
|
|
270
|
+
isSelected: a
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
273
|
function ge() {
|
|
@@ -285,12 +285,12 @@ function pe() {
|
|
|
285
285
|
}
|
|
286
286
|
const $ = 5 * 60 * 1e3, L = /* @__PURE__ */ new Map();
|
|
287
287
|
function me(e) {
|
|
288
|
-
const [n, t] =
|
|
288
|
+
const [n, t] = y({
|
|
289
289
|
product: null,
|
|
290
290
|
loading: !0,
|
|
291
291
|
error: null
|
|
292
292
|
});
|
|
293
|
-
return
|
|
293
|
+
return N(() => {
|
|
294
294
|
if (!e) {
|
|
295
295
|
t({
|
|
296
296
|
product: null,
|
|
@@ -304,7 +304,7 @@ function me(e) {
|
|
|
304
304
|
loading: !0,
|
|
305
305
|
error: null
|
|
306
306
|
}));
|
|
307
|
-
const o =
|
|
307
|
+
const o = H(e);
|
|
308
308
|
if (o) {
|
|
309
309
|
t({
|
|
310
310
|
product: o,
|
|
@@ -314,7 +314,7 @@ function me(e) {
|
|
|
314
314
|
return;
|
|
315
315
|
}
|
|
316
316
|
B(e).then((r) => {
|
|
317
|
-
|
|
317
|
+
U(e, r), t({
|
|
318
318
|
product: r,
|
|
319
319
|
loading: !1,
|
|
320
320
|
error: null
|
|
@@ -334,11 +334,11 @@ async function B(e) {
|
|
|
334
334
|
throw new Error(`Failed to fetch product: ${n.status} ${n.statusText}`);
|
|
335
335
|
return n.json();
|
|
336
336
|
}
|
|
337
|
-
function
|
|
337
|
+
function H(e) {
|
|
338
338
|
const n = L.get(e);
|
|
339
339
|
return n ? Date.now() - n.created > $ ? (L.delete(e), null) : n.product : null;
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function U(e, n) {
|
|
342
342
|
L.set(e, {
|
|
343
343
|
product: n,
|
|
344
344
|
created: Date.now()
|
|
@@ -352,7 +352,7 @@ function he(e, n) {
|
|
|
352
352
|
from: R(s.query.products?.from ?? 0),
|
|
353
353
|
size: R(s.response?.products?.size ?? n),
|
|
354
354
|
total: R(s.response?.products?.total ?? 0)
|
|
355
|
-
})), { updateSearch: i } = x(), c = t + o,
|
|
355
|
+
})), { updateSearch: i } = x(), c = t + o, u = S(() => [...e].reverse().filter((s) => s < r), [e, r]), d = p(
|
|
356
356
|
(s) => {
|
|
357
357
|
i({
|
|
358
358
|
products: {
|
|
@@ -372,22 +372,22 @@ function he(e, n) {
|
|
|
372
372
|
/** size value */
|
|
373
373
|
size: o,
|
|
374
374
|
/** Array of size options */
|
|
375
|
-
sizeOptions:
|
|
375
|
+
sizeOptions: u,
|
|
376
376
|
/** Should be called when size is changed */
|
|
377
377
|
handleSizeChange: d
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
|
-
function
|
|
380
|
+
function _(e, n) {
|
|
381
381
|
return e.length !== n.length ? !1 : e.every((t) => n.find((o) => t.field === o.field && t.order === o.order));
|
|
382
382
|
}
|
|
383
383
|
function ve(e) {
|
|
384
384
|
const n = v((i) => i.query), { updateSearch: t } = x();
|
|
385
385
|
return {
|
|
386
386
|
/** Active sort */
|
|
387
|
-
activeSort: e.find((i) =>
|
|
387
|
+
activeSort: e.find((i) => _(i.value.sort, n.products?.sort || []))?.id ?? e[0]?.id,
|
|
388
388
|
/** Set sort function */
|
|
389
389
|
setSort: (i) => {
|
|
390
|
-
const c = e.find((
|
|
390
|
+
const c = e.find((u) => u.id === i);
|
|
391
391
|
c && t({
|
|
392
392
|
products: {
|
|
393
393
|
sort: c.value.sort
|
|
@@ -396,7 +396,7 @@ function ve(e) {
|
|
|
396
396
|
}
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
|
-
const M = window.SpeechRecognition || window.webkitSpeechRecognition,
|
|
399
|
+
const M = window.SpeechRecognition || window.webkitSpeechRecognition, I = !!(M && typeof M == "function");
|
|
400
400
|
function Z() {
|
|
401
401
|
return {
|
|
402
402
|
listening: !1,
|
|
@@ -412,22 +412,22 @@ function G({
|
|
|
412
412
|
onResult: t,
|
|
413
413
|
onError: o
|
|
414
414
|
} = {}) {
|
|
415
|
-
const [r, i] =
|
|
415
|
+
const [r, i] = y(!1), c = k(null), u = p(() => {
|
|
416
416
|
const s = new M();
|
|
417
|
-
s.lang = e, s.interimResults = n, s.onstart = () => i(!0), t && (s.onresult = (
|
|
418
|
-
const { transcript: l } =
|
|
417
|
+
s.lang = e, s.interimResults = n, s.onstart = () => i(!0), t && (s.onresult = (a) => {
|
|
418
|
+
const { transcript: l } = a.results?.[0]?.[0];
|
|
419
419
|
t(l);
|
|
420
|
-
}), o && (s.onerror = (
|
|
420
|
+
}), o && (s.onerror = (a) => o(a.error)), s.onend = () => i(!1), c.current = s, s.start();
|
|
421
421
|
}, [e, n, o, t]), d = p(() => {
|
|
422
422
|
c.current?.stop();
|
|
423
423
|
}, [c]);
|
|
424
424
|
return {
|
|
425
425
|
listening: r,
|
|
426
|
-
startListening:
|
|
426
|
+
startListening: u,
|
|
427
427
|
stopListening: d
|
|
428
428
|
};
|
|
429
429
|
}
|
|
430
|
-
const Se =
|
|
430
|
+
const Se = I ? G : Z;
|
|
431
431
|
function J(e, n) {
|
|
432
432
|
if (!e.length || !n.length) return [];
|
|
433
433
|
const t = n.reduce((o, r) => (o[r] = {}, o), {});
|
|
@@ -450,7 +450,7 @@ function K(e, n) {
|
|
|
450
450
|
return e.length ? e.map(({ field: t, options: o }) => ({
|
|
451
451
|
field: t,
|
|
452
452
|
options: o.map((r) => {
|
|
453
|
-
const i = !r.skus?.some((
|
|
453
|
+
const i = !r.skus?.some((u) => Object.entries(n).every(([d, s]) => d === t ? !0 : u.customFields?.find((l) => l.key.toLowerCase() === d)?.value === s)), c = n[t] === r.value;
|
|
454
454
|
return {
|
|
455
455
|
...r,
|
|
456
456
|
unavailable: i,
|
|
@@ -472,28 +472,30 @@ function W(e, n) {
|
|
|
472
472
|
return r < i ? -1 : 1;
|
|
473
473
|
});
|
|
474
474
|
}
|
|
475
|
-
function
|
|
476
|
-
const [t, o] =
|
|
475
|
+
function ye(e = [], n = []) {
|
|
476
|
+
const [t, o] = y({}), r = S(() => J(e, n).map(({ field: s, options: a }) => ({
|
|
477
477
|
field: s,
|
|
478
|
-
options: W(s,
|
|
478
|
+
options: W(s, a)
|
|
479
479
|
})), [e, n]), i = S(() => K(r, t), [r, t]), c = p((d, s) => {
|
|
480
|
-
o((
|
|
481
|
-
const l = { ...
|
|
480
|
+
o((a) => {
|
|
481
|
+
const l = { ...a };
|
|
482
482
|
return l[d] === s ? delete l[d] : l[d] = s, l;
|
|
483
483
|
});
|
|
484
|
-
}, []),
|
|
485
|
-
const f = t[
|
|
484
|
+
}, []), u = S(() => Object.keys(t).filter((a) => t[a]).length === 0 ? [] : i.filter(({ field: a }) => t[a]).map(({ field: a, options: l }) => {
|
|
485
|
+
const f = t[a];
|
|
486
486
|
return l.find((g) => g.value === f)?.skus ?? [];
|
|
487
|
-
}).reduce((
|
|
488
|
-
return { swatches: i, toggleOption: c, matchedSkus:
|
|
487
|
+
}).reduce((a, l) => a.filter((f) => l.includes(f))), [i, t]);
|
|
488
|
+
return { swatches: i, toggleOption: c, matchedSkus: u };
|
|
489
489
|
}
|
|
490
490
|
export {
|
|
491
|
-
|
|
491
|
+
Ae as addToHistory,
|
|
492
|
+
Re as getSavedHistory,
|
|
493
|
+
I as speechToTextSupported,
|
|
492
494
|
x as useActions,
|
|
493
495
|
ie as useDecoratedSearchResults,
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
496
|
+
ae as useFacet,
|
|
497
|
+
ue as useFacets,
|
|
498
|
+
Le as useHistory,
|
|
497
499
|
be as useLoadMore,
|
|
498
500
|
v as useNostoAppState,
|
|
499
501
|
le as usePagination,
|
|
@@ -507,5 +509,5 @@ export {
|
|
|
507
509
|
he as useSizeOptions,
|
|
508
510
|
ve as useSort,
|
|
509
511
|
Se as useSpeechToText,
|
|
510
|
-
|
|
512
|
+
ye as useSwatches
|
|
511
513
|
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { Store } from '../../common/src/store/store';
|
|
1
2
|
export declare const historyKey = "nosto:search-js:history";
|
|
2
|
-
|
|
3
|
+
type HistoryEntry = {
|
|
4
|
+
value: string;
|
|
5
|
+
store: Store;
|
|
6
|
+
historySize: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function addToHistory({ value, historySize, store }: HistoryEntry): void;
|
|
9
|
+
export declare function getSavedHistory(): string[];
|
|
3
10
|
export declare function useHistory(): {
|
|
4
11
|
addQuery: (value: string) => void;
|
|
5
12
|
};
|
|
13
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-Xg9H1y3f.cjs"),T=require("../../CategoryPageProvider-2ZmajAxh.cjs"),h=require("../../useActions-CY9uts_o.cjs"),I=require("../../SerpPageProvider-Dn6PSZoF.cjs"),d=require("../../jsxRuntime.module-B3sGoTIU.cjs"),g=require("../../ErrorBoundary-CKn3Ecpu.cjs"),b=require("../../disableNativeAutocomplete-DI6zaZII.cjs"),P=require("../../unique-BXXNictB.cjs"),C=require("preact"),N=require("../../logger-Boh_C6Bz.cjs"),p=require("../../search-RNs4Cunh.cjs");function O(e){let n;return t=>{n&&clearTimeout(n),n=setTimeout(t,e)}}function q(e){return Array.from(document.querySelectorAll(e))}function R(e){const n=[];let t=e.parentNode;for(;t&&t!==document&&t instanceof Element;)n.push(t),t=t.parentNode;return n}function E([e,n],t){const o=r=>{const s=r.target;s instanceof HTMLElement&&e&&s!==e&&s!==n&&!R(s).includes(e)&&t()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function A(e,n){e.tabIndex=0,e.addEventListener("blur",n)}function S(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function H({selector:e,timeout:n=500}){return new Promise(t=>{const o=q(e);if(o.length>0)return t(o);const r=new MutationObserver(()=>{const i=q(e);i.length>0&&(r.disconnect(),clearTimeout(s),t(i))}),s=setTimeout(()=>{r.disconnect(),N.logger.warn(`Timed out (${n}) while waiting for element ${e}`),t([])},n);r.observe(document.body,{childList:!0,subtree:!0})})}function x(e,n,t){n.style.display="none";const o=(()=>{if(e.parentElement&&e.parentElement.classList.contains("nosto-autocomplete-wrapper"))return e.parentElement;const a=document.createElement("div");return a.className="nosto-autocomplete-wrapper",e.parentNode?.insertBefore(a,e.nextSibling),a.appendChild(e),a})(),r=S(t),s=r&&document.querySelector(r.selector);if(s){const a=document.createElement("form");a.className="nosto-dropdown-form",a.appendChild(n),r.position==="first"?s.prepend(a):s.appendChild(a)}else o.appendChild(n);const i={index:-1,onChangeListeners:[]},c=(a,u)=>{const f=a.length;f===0&&(u=-1),i.index=u>=0?u%f:f-1,i.onChangeListeners.forEach(D=>D())},l=()=>{i.index=-1,i.onChangeListeners.forEach(a=>a())},m=()=>i.index;return{element:n,hide:()=>{n.style.display="none",l()},show:()=>{n.style.display="inherit"},isOpen:()=>n.style.display!=="none",goDown:()=>{const a=Array.from(n.getElementsByClassName("ns-autocomplete-element")),u=m();c(a,u+1)},goUp:()=>{const a=Array.from(n.getElementsByClassName("ns-autocomplete-element")),u=m();c(a,u-1)},highlight:c,highlightedIndex:m,submitHighlightedItem:a=>{Array.from(n.querySelectorAll(".ns-autocomplete-element"))[a]?.click()},onHighlightChange:a=>{i.onChangeListeners.push(a)}}}function $(e,n){const t=document.createElement("div");return t.className="nosto-autocomplete-dropdown",{...x(e,t,n),element:t}}const y="nosto:search-js:history";function v(e,n,t){const o=document.createElement("div");return o.className="nosto-autocomplete-history",{...x(e,o,n),element:o,add:s=>{const c=(p.getLocalStorageItem(y)??[]).filter(l=>l!==s).slice(t?-t:0);c.push(s),p.setLocalStorageItem(y,c)},get:()=>(p.getLocalStorageItem(y)??[]).reverse().filter(i=>!!i)}}async function F(e,{config:n,dropdown:t,history:o,renderHistory:r,store:s}){const{historyEnabled:i,minQueryLength:c}=n;if(e.length<c&&i&&r&&!o.isOpen()){o.show();return}if(e.length<c)return;t.hide();const l=s.getState()?.query?.query;l&&l!==e&&await h.newSearch({config:n,store:s},{query:e}),t.show()}async function k(e,n){const{config:t,renderHistory:o,history:r}=n,{historyEnabled:s,minQueryLength:i}=t;if(!o||e.length>=i||!s||r.isOpen())return;const c=j(n);r.onHighlightChange(()=>{c(o,r.element)}),r.show();const l=P.measure("renderHistory");c(o,r.element),l()}async function Q(e,{config:n,dropdown:t,history:o,store:r,debouncer:s}){const{minQueryLength:i,historyEnabled:c}=n;if(e.length<i&&!c){t.hide(),o.hide();return}if(e.length<i&&c){t.hide(),o.show();return}o.hide(),s(async()=>{h.newSearch({config:n,store:r},{query:e}),t.show()})}function M(e,n,t){const{config:o,debouncer:r}=t;if(r(()=>{}),e.length>=o.minQueryLength)return L(n,t.dropdown,t.history);if(o.historyEnabled)return L(n,t.history,t.dropdown)}function L(e,n,t){if(!n.isOpen()&&e==="ArrowDown"){n.show(),t.hide();return}if(e==="Escape"&&n.hide(),!!n.isOpen()){if(e==="ArrowDown")n.goDown();else if(e==="ArrowUp")n.goUp();else if(e==="Enter"){const o=n.highlightedIndex();return o>=0&&n.submitHighlightedItem(o),n.hide(),o>=0}}}function U(e,{config:n,dropdown:t,history:o,onNavigateToSearch:r,store:s}){t.hide(),o.hide(),!(e.length<n.minQueryLength)&&(o.add(e),s.updateState({historyItems:o.get()}),r?.({query:e}))}async function K(e,n){const{inputCssSelector:t,timeout:o}=e,r=S(t).selector,s=await H({selector:r,timeout:o});if(s.length===0)throw new Error(`No elements found for selector: ${r}`);s.forEach(i=>{_(i,e,n)})}async function _(e,n,t){const{config:o,dropdownCssSelector:r}=n,s=$(e,r),i=v(e,r,o.historySize),c={...n,input:e,dropdown:s,history:i,store:t,debouncer:O(o.debounceDelay)};G(c),e.setAttribute("data-nosto-element","search-input"),t.updateState({historyItems:i.get()}),b.disableNativeAutocomplete(e),t.onInit(()=>{z(c)}),b.bindInput(e,{onInput:l=>Q(l,c),onFocus:l=>k(l,c),onClick:l=>F(l,c),onSubmit:l=>U(l,c),onKeyDown:(l,m)=>M(l,m,c)}),A(i.element,i.hide),A(s.element,s.hide),E([i.element,e],i.hide),E([s.element,e],s.hide)}function z(e){const{dropdown:n,renderAutocomplete:t}=e;if(!t)return;const o=j(e);n.onHighlightChange(()=>{o(t,n.element)});const r=P.measure("renderAutocomplete");o(t,n.element),r()}async function G(e){const{input:n,renderSpeechToText:t,config:o,store:r}=e;if(!t)return;const s="ns-autocomplete-voice-position";if(!!n.parentElement?.querySelector(`.${s}`))return;const c=document.createElement("div");c.className=s,n.insertAdjacentElement("afterend",c);const l=await t();C.render(d.u(g.ErrorBoundary,{children:d.u(w.AutocompletePageProvider,{config:o,store:r,children:l})}),c)}function j(e){const{config:n,store:t}=e;return(o,r)=>C.render(d.u(g.ErrorBoundary,{children:d.u(w.AutocompletePageProvider,{config:n,store:t,children:o()})}),r)}async function B({cssSelector:e,timeout:n,renderComponent:t}){const o=S(e).selector,r=await H({selector:o,timeout:n??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&N.logger.warn(`Multiple (${r.length}) elements found for selector: ${o}`),C.render(t(),r[0])}async function J(e,n){const{render:t}=e,o=await t();B({...e,renderComponent:()=>d.u(g.ErrorBoundary,{children:d.u(T.CategoryPageProvider,{store:n,config:e.config,children:o})})})}async function V(e,n){const{render:t}=e,o=await t();B({...e,renderComponent:()=>d.u(g.ErrorBoundary,{children:d.u(I.SearchPageProvider,{store:n,config:e.config,children:o})})})}async function W({autocomplete:e,category:n,serp:t}){const o={};if(e){const r=h.createStore({query:e.query});await K({...e,config:w.makeAutocompleteConfig(e.config)},r),o.autocomplete={store:r}}if(n){const r=h.createStore({query:n.query});await J({...n,config:T.makeCategoryConfig(n.config)},r),o.category={store:r}}if(t){const r=h.createStore({query:t.query});await V({...t,config:I.makeSerpConfig(t.config)},r),o.serp={store:r}}return o}exports.init=W;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as L, m as j } from "../../AutocompletePageProvider-
|
|
1
|
+
import { A as L, m as j } from "../../AutocompletePageProvider-DsUoIbbx.js";
|
|
2
2
|
import { C as O, m as R } from "../../CategoryPageProvider-DU3DjmnJ.js";
|
|
3
3
|
import { n as T, c as p } from "../../useActions-CSNwQtT1.js";
|
|
4
4
|
import { S as $, m as F } from "../../SerpPageProvider-DshgTNpM.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { S as l, a as m } from "./useActions-CSNwQtT1.js";
|
|
2
|
+
import { g as c, a as u } from "./search-mArZ2PXy.js";
|
|
3
|
+
import { useContext as y, useCallback as f } from "preact/hooks";
|
|
4
|
+
const e = "nosto:search-js:history";
|
|
5
|
+
function g({ value: o, historySize: t, store: s }) {
|
|
6
|
+
const n = (c(e) ?? []).filter((i) => i !== o).concat(o), a = t ? n.slice(-t) : [];
|
|
7
|
+
u(e, a), s.updateState({ historyItems: a.reverse() });
|
|
8
|
+
}
|
|
9
|
+
function p() {
|
|
10
|
+
return (c(e) ?? []).slice().reverse().filter((t) => !!t);
|
|
11
|
+
}
|
|
12
|
+
function I() {
|
|
13
|
+
const o = y(l), { historySize: t } = m();
|
|
14
|
+
return {
|
|
15
|
+
addQuery: f(
|
|
16
|
+
(r) => {
|
|
17
|
+
g({ value: r, historySize: t, store: o });
|
|
18
|
+
},
|
|
19
|
+
[t, o]
|
|
20
|
+
)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
g as a,
|
|
25
|
+
p as g,
|
|
26
|
+
I as u
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const a=require("./useActions-CY9uts_o.cjs"),o=require("./search-RNs4Cunh.cjs"),i=require("preact/hooks"),s="nosto:search-js:history";function u({value:e,historySize:t,store:r}){const l=(o.getLocalStorageItem(s)??[]).filter(y=>y!==e).concat(e),n=t?l.slice(-t):[];o.setLocalStorageItem(s,n),r.updateState({historyItems:n.reverse()})}function d(){return(o.getLocalStorageItem(s)??[]).slice().reverse().filter(t=>!!t)}function g(){const e=i.useContext(a.StoreContext),{historySize:t}=a.useAutocompleteConfig();return{addQuery:i.useCallback(c=>{u({value:c,historySize:t,store:e})},[t,e])}}exports.addToHistory=u;exports.getSavedHistory=d;exports.useHistory=g;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const n=require("./useActions-CY9uts_o.cjs"),o=require("./search-RNs4Cunh.cjs"),a=require("preact/hooks"),s="nosto:search-js:history";function l(){return(o.getLocalStorageItem(s)??[]).slice().reverse().filter(e=>!!e)}function y(){const{updateState:t}=a.useContext(n.StoreContext),{historySize:e}=n.useAutocompleteConfig();return{addQuery:a.useCallback(r=>{const i=(o.getLocalStorageItem(s)??[]).filter(u=>u!==r).concat(r),c=e?i.slice(-e):[];o.setLocalStorageItem(s,c),t({historyItems:c.reverse()})},[e,t])}}exports.getSaved=l;exports.useHistory=y;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { S as i, a as l } from "./useActions-CSNwQtT1.js";
|
|
2
|
-
import { g as a, a as m } from "./search-mArZ2PXy.js";
|
|
3
|
-
import { useContext as u, useCallback as y } from "preact/hooks";
|
|
4
|
-
const o = "nosto:search-js:history";
|
|
5
|
-
function p() {
|
|
6
|
-
return (a(o) ?? []).slice().reverse().filter((t) => !!t);
|
|
7
|
-
}
|
|
8
|
-
function I() {
|
|
9
|
-
const { updateState: e } = u(i), { historySize: t } = l();
|
|
10
|
-
return {
|
|
11
|
-
addQuery: y(
|
|
12
|
-
(s) => {
|
|
13
|
-
const c = (a(o) ?? []).filter((n) => n !== s).concat(s), r = t ? c.slice(-t) : [];
|
|
14
|
-
m(o, r), e({ historyItems: r.reverse() });
|
|
15
|
-
},
|
|
16
|
-
[t, e]
|
|
17
|
-
)
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
p as g,
|
|
22
|
-
I as u
|
|
23
|
-
};
|