@nosto/search-js 2.3.0 → 2.4.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.
- package/dist/{InfiniteScrollWithObserver-B4qGyAhS.cjs → InfiniteScrollWithObserver-C3ILy8X_.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-BXwW2XGJ.js → InfiniteScrollWithObserver-DGZxUITY.js} +1 -1
- package/dist/{storeContext-jWZFJ8Kf.js → configContext-CDTtcin_.js} +19 -20
- package/dist/configContext-CGXeJcqj.cjs +1 -0
- package/dist/preact/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete.es.js +1 -1
- package/dist/preact/category.cjs.js +1 -1
- package/dist/preact/category.es.js +1 -1
- package/dist/preact/common.cjs.js +1 -1
- package/dist/preact/common.es.js +3 -3
- package/dist/preact/hooks.cjs.js +1 -1
- package/dist/preact/hooks.es.js +2 -2
- package/dist/preact/legacy.cjs.js +1 -1
- package/dist/preact/legacy.es.js +2 -2
- package/dist/preact/serp.cjs.js +1 -1
- package/dist/preact/serp.es.js +1 -1
- package/dist/preact/src/hooks/useLoadMore/getNextPageQuery.d.ts +7 -5
- package/dist/preact/src/search/resultCaching.d.ts +8 -1
- package/dist/preact/src/search/searchWithCache.d.ts +4 -0
- package/dist/useLoadMore-CHLvVMm8.js +293 -0
- package/dist/useLoadMore-Co6PDmam.cjs +1 -0
- package/dist/utils/src/bindInput.d.ts +14 -0
- package/package.json +1 -1
- package/dist/storeContext-DVs7r6Qm.cjs +0 -1
- package/dist/useLoadMore-CAy4DIRA.js +0 -262
- package/dist/useLoadMore-CUkl79S_.cjs +0 -1
package/dist/{InfiniteScrollWithObserver-B4qGyAhS.cjs → InfiniteScrollWithObserver-C3ILy8X_.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-
|
|
1
|
+
"use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-Co6PDmam.cjs"),a=require("./pick-rYi1lc2m.cjs"),d=require("preact/hooks"),b=require("preact");function f(s,i){var o,e,r;const t=((o=i.products)==null?void 0:o.total)??0,c=((e=s.products)==null?void 0:e.from)??0,n=((r=s.products)==null?void 0:r.size)??0;return t>0&&t>c+n}function h(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function O({children:s,pageSize:i}){const t=d.useRef(null),{query:c,response:n}=p.useNostoAppState(e=>a.pick(e,"query","response")),{loadMore:o}=p.useLoadMore(i);return d.useEffect(()=>{let e,r;return f(c,n)&&(e=t.current,r=new IntersectionObserver(v=>{const u=v[0];u!=null&&u.isIntersecting&&o()}),e&&r.observe(e)),()=>{e&&r.unobserve(e)}},[n]),l.u(b.Fragment,{children:[s,l.u("div",{ref:t,style:{height:"1px"}})]})}exports.InfiniteScrollWithObserver=O;exports.hasMoreResults=f;exports.intersectionObserverSupported=h;
|
package/dist/{InfiniteScrollWithObserver-BXwW2XGJ.js → InfiniteScrollWithObserver-DGZxUITY.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { u as a, a as l } from "./useLoadMore-
|
|
2
|
+
import { u as a, a as l } from "./useLoadMore-CHLvVMm8.js";
|
|
3
3
|
import { p as d } from "./pick-DReBictn.js";
|
|
4
4
|
import { useRef as m, useEffect as v } from "preact/hooks";
|
|
5
5
|
import { Fragment as b } from "preact";
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { createContext as c } from "preact";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const t = x(b);
|
|
6
|
-
if (!t)
|
|
7
|
-
throw new Error("useConfig must be used within a ConfigProvider");
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
function w(t, i = {}) {
|
|
2
|
+
import { b as u, i as x } from "./isEqual-BzZ3d1JM.js";
|
|
3
|
+
import { useContext as h } from "preact/hooks";
|
|
4
|
+
function b(t, i = {}) {
|
|
11
5
|
const a = /* @__PURE__ */ new Map();
|
|
12
6
|
let o = u(t, i ?? {});
|
|
13
7
|
const f = u(t, i);
|
|
@@ -29,7 +23,7 @@ function w(t, i = {}) {
|
|
|
29
23
|
let s;
|
|
30
24
|
a.set(n, (m) => {
|
|
31
25
|
const r = e(m);
|
|
32
|
-
|
|
26
|
+
x(r, s) || (s = r, n(r));
|
|
33
27
|
});
|
|
34
28
|
}
|
|
35
29
|
function S(e) {
|
|
@@ -43,21 +37,26 @@ function w(t, i = {}) {
|
|
|
43
37
|
clearOnChange: S
|
|
44
38
|
};
|
|
45
39
|
}
|
|
46
|
-
const
|
|
40
|
+
const w = {
|
|
47
41
|
loading: !0,
|
|
48
42
|
query: {},
|
|
49
43
|
response: {},
|
|
50
44
|
initialized: !1
|
|
51
45
|
};
|
|
52
|
-
function
|
|
53
|
-
return w
|
|
46
|
+
function E(t = {}) {
|
|
47
|
+
return b(w, t);
|
|
54
48
|
}
|
|
55
|
-
const
|
|
49
|
+
const v = c(E()), q = c(null), y = () => {
|
|
50
|
+
const t = h(q);
|
|
51
|
+
if (!t)
|
|
52
|
+
throw new Error("useConfig must be used within a ConfigProvider");
|
|
53
|
+
return t;
|
|
54
|
+
};
|
|
56
55
|
export {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
q as C,
|
|
57
|
+
v as S,
|
|
58
|
+
b as a,
|
|
59
|
+
E as c,
|
|
60
|
+
w as d,
|
|
61
|
+
y as u
|
|
63
62
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("preact"),i=require("./isEqual-DQXR__da.cjs"),w=require("preact/hooks");function l(e,u={}){const r=new Map;let o=i.deepMergePlain(e,u??{});const S=i.deepMergePlain(e,u);function d(t){o=t(o);for(const n of r.values())n(o)}function x(t){d(n=>({...n,...t}))}function p(){return o}function h(){return structuredClone(S)}function q(t,n){let c;r.set(n,b=>{const a=t(b);i.isEqual(a,c)||(c=a,n(a))})}function E(t){r.delete(t)}return{updateState:x,getState:p,getInitialState:h,onChange:q,clearOnChange:E}}const f={loading:!0,query:{},response:{},initialized:!1};function C(e={}){return l(f,e)}const M=s.createContext(C()),g=s.createContext(null),P=()=>{const e=w.useContext(g);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};exports.ConfigContext=g;exports.StoreContext=M;exports.createExtendableStore=l;exports.createStore=C;exports.defaultState=f;exports.useConfig=P;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../index.es-DlUp67LT.cjs"),a=require("preact"),u=require("../renderHeadless-xhkLegO4.cjs"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),r=require("../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../index.es-DlUp67LT.cjs"),a=require("preact"),u=require("../renderHeadless-xhkLegO4.cjs"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),r=require("../configContext-CGXeJcqj.cjs"),c=require("../baseConfig-BlLNh6Jn.cjs");function f(e){return e!==null&&typeof e=="object"&&"props"in e&&typeof e.type=="string"}function m({children:e,hit:n}){var o;if(!f(e))throw new Error("AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported.");const t=(o=e.props)==null?void 0:o.onClick;return a.cloneElement(e,{onClick:p=>{n&&l.s(s=>s.recordSearchClick("autocomplete",n)),typeof t=="function"&&t(p)}})}function g({children:e,onSearchInput:n}){return u.renderHeadless({children:e,updateElement:t=>(!u.isHTMLInput(t)||t.props.type!=="search"||(t.props={...t.props,onInput:o=>{o.target instanceof HTMLInputElement&&n(o.target)}}),t)})}const C={...c.defaultBaseConfig};function d(e){return{pageType:"autocomplete",...C,...e}}function S({config:e,store:n,children:t}){const o=n??r.createStore();return c.useCheckClientScript(),i.u(r.ConfigContext,{value:d(e),children:i.u(r.StoreContext,{value:o,children:t})})}exports.AutocompleteElement=m;exports.AutocompletePageProvider=S;exports.SearchInput=g;
|
|
@@ -2,7 +2,7 @@ import { s as u } from "../index.es-B8mbAxS4.js";
|
|
|
2
2
|
import { cloneElement as a } from "preact";
|
|
3
3
|
import { r as s, i as c } from "../renderHeadless-BteGML1G.js";
|
|
4
4
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
|
-
import { c as l, S as m, C as f } from "../
|
|
5
|
+
import { c as l, S as m, C as f } from "../configContext-CDTtcin_.js";
|
|
6
6
|
import { d as C, u as g } from "../baseConfig-XyA_9NDR.js";
|
|
7
7
|
function E(t) {
|
|
8
8
|
return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../configContext-CGXeJcqj.cjs"),o=require("../baseConfig-BlLNh6Jn.cjs"),u={...o.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function c(e){return{pageType:"category",...u,...e}}function g({config:e,store:n,children:a}){const i=n??t.createStore();return o.useCheckClientScript(),r.u(t.ConfigContext,{value:c(e),children:r.u(t.StoreContext,{value:i,children:a})})}exports.CategoryPageProvider=g;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as t } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as c, C as i } from "../
|
|
2
|
+
import { c as n, S as c, C as i } from "../configContext-CDTtcin_.js";
|
|
3
3
|
import { d as s, u as f } from "../baseConfig-XyA_9NDR.js";
|
|
4
4
|
const C = {
|
|
5
5
|
...s,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-BCAEb4ek.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-BCAEb4ek.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-Co6PDmam.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-C3ILy8X_.cjs"),q=require("preact"),r=require("../configContext-CGXeJcqj.cjs");function b({pageSize:o}){const{loadMore:e}=c.useLoadMore(o);return t.u("button",{onClick:e,children:"More results"})}function u({children:o,loadMoreComponent:e,pageSize:i}){const{loading:s,query:l,response:a}=c.useNostoAppState(S=>p.pick(S,"loading","query","response")),d=!s&&n.hasMoreResults(l,a);return t.u(q.Fragment,{children:[o,d&&(e?t.u(e,{pageSize:i}):t.u(b,{pageSize:i}))]})}const M=!f.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=r.StoreContext;exports.createExtendableStore=r.createExtendableStore;exports.createStore=r.createStore;exports.defaultState=r.defaultState;exports.InfiniteScroll=M;exports.InfiniteScrollWithLink=u;
|
package/dist/preact/common.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { i as l } from "../unique-CyAMhegX.js";
|
|
2
2
|
import { u as r } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
-
import { a as p, u as m } from "../useLoadMore-
|
|
3
|
+
import { a as p, u as m } from "../useLoadMore-CHLvVMm8.js";
|
|
4
4
|
import { p as u } from "../pick-DReBictn.js";
|
|
5
|
-
import { h as d, i as f, I as S } from "../InfiniteScrollWithObserver-
|
|
5
|
+
import { h as d, i as f, I as S } from "../InfiniteScrollWithObserver-DGZxUITY.js";
|
|
6
6
|
import { Fragment as h } from "preact";
|
|
7
|
-
import { S as O, a as W, c as A, d as B } from "../
|
|
7
|
+
import { S as O, a as W, c as A, d as B } from "../configContext-CDTtcin_.js";
|
|
8
8
|
function M({ pageSize: e }) {
|
|
9
9
|
const { loadMore: o } = p(e);
|
|
10
10
|
return /* @__PURE__ */ r("button", { onClick: o, children: "More results" });
|
package/dist/preact/hooks.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-Co6PDmam.cjs"),P=require("../isEqual-DQXR__da.cjs"),v=require("preact/hooks"),q=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function C(e){const o=m.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&P.isPlainObject(e)?e:o}function z(e){var a;const o=((a=e.data)==null?void 0:a.filter(c=>c.selected).length)??0,[t,n]=v.useState(o>0),{toggleProductFilter:u}=m.useActions();return{active:t,selectedFiltersCount:o,toggleActive:()=>{n(!t)},toggleProductFilter:u}}function x(){const{loading:e,facets:o}=m.useNostoAppState(t=>{var n,u;return{loading:t.loading,facets:((u=(n=t.response)==null?void 0:n.products)==null?void 0:u.facets)??[]}});return{loading:e,facets:o}}function k(e,o){const t=o-e;return!isNaN(t)&&t>0?new Array(o-e).fill(void 0).map((n,u)=>u+e):[]}function w(e){const{query:o,products:t}=m.useNostoAppState(n=>({query:n.query,products:n.response.products}));return v.useMemo(()=>{var F;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=o.products)==null?void 0:F.from)??0,u=(e==null?void 0:e.width)??1/0,i=Math.max(Math.floor(u-1)/2,1),a=t.size>0?Math.floor(n/t.size)+1:1,c=t.size>0?Math.ceil(t.total/t.size):0,g=A=>A>=a-i&&A<=a+i,s=n+1,l=Math.min(n+t.total,t.total),r={from:n,page:a,current:!0},p=A=>({from:(A-1)*t.size,page:A,current:A===a}),S=a>1?p(a-1):void 0,d=a<c?p(a+1):void 0,y=i===1/0||a-i-1>1?p(1):void 0,f=i===1/0||a+i+1<c?p(c):void 0,h=k(1,c+1).filter(g).map(p);return{totalPages:c,resultsFrom:s,resultsTo:l,current:r,prev:S,next:d,first:y,last:f,pages:h}},[o,t,e==null?void 0:e.width])}function T(){const[e,o]=v.useState([]),[t,n]=v.useState([]);return v.useEffect(()=>{q.s(async u=>{const{products:i,segments:a}=await u.getSearchSessionParams();o(a??[]),n((i==null?void 0:i.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function B(){const{facets:e}=m.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:o,toggleProductFilter:t}=m.useActions(),n=v.useCallback(s=>{const l=e==null?void 0:e.find(r=>r.type==="stats"&&r.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),u=v.useCallback(s=>{var l;return((l=e==null?void 0:e.find(r=>r.field===s))==null?void 0:l.name)??s},[e]),i=v.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),a=v.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(r=>({gt:r.gt?Number(r.gt):r.gt,gte:r.gte?Number(r.gte):r.gte,lt:r.lt?Number(r.lt):r.lt,lte:r.lte?Number(r.lte):r.lte}))}},[]),c=v.useCallback(s=>(s.value??[]).map(r=>({value:r,field:s.field,name:u(s.field),filter:a(s),remove:()=>{t(s.field,r,!1)}})),[a,u,t]),g=v.useCallback(s=>(s.range??[]).map(r=>{var d,y;const p=r.gte??r.gt??((d=n(s.field))==null?void 0:d.min),S=r.lte??r.lt??((y=n(s.field))==null?void 0:y.max);if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:s.field,name:u(s.field),filter:a(s),remove:()=>{o(s.field,void 0)}}}).filter(Boolean),[a,n,u,o]);return{selectFilters:i,toValueFilter:c,toRangeFilter:g}}function M(){const{filter:e}=m.useNostoAppState(c=>{var g;return{filter:((g=c.query.products)==null?void 0:g.filter)??[]}}),{updateSearch:o}=m.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:u}=B(),i=v.useMemo(()=>e?e.filter(t).flatMap(c=>"value"in c?n(c):"range"in c?u(c):[]).filter(Boolean):[],[e,t,u,n]),a=v.useCallback(()=>{o({products:{filter:[]}})},[o]);return{filters:i,removeAll:a}}function R(e){var r,p,S;const{replaceFilter:o}=m.useActions(),{query:t,products:n}=m.useNostoAppState(d=>({query:d.query,products:d.response.products})),u=(r=n==null?void 0:n.facets)==null?void 0:r.find(d=>d.id===e);if(!u)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const i=(S=(p=t.products)==null?void 0:p.filter)==null?void 0:S.find(d=>d.field===u.field),a=i!=null&&i.range?i.range[0]:void 0,c=typeof a=="object"&&("gte"in a||"lte"in a)?[N.parseNumber(a.gte),N.parseNumber(a.lte)]:[void 0,void 0],g="min"in u?Math.floor(u.min):0,s="max"in u?Math.ceil(u.max):0,l=([d,y])=>{const f=d!==void 0?Math.floor(d):void 0,h=y!==void 0?Math.ceil(y):void 0,F=f!==void 0,A=h!==void 0;(g===f||!F)&&(s===h||!A)?o(u.field,void 0):(g===f||!F)&&A?o(u.field,{lte:h.toString()}):(s===h||!A)&&F?o(u.field,{gte:f.toString()}):F&&A&&o(u.field,{gte:f.toString(),lte:h.toString()})};return{min:g,max:s,range:[c[0]??g,c[1]??s],updateRange:l}}function D(e,o){const{min:t,max:n,range:u,updateRange:i}=R(e),{filters:a}=M(),c=v.useMemo(()=>{var y;const r=a.find(f=>{var h;return(h=f==null?void 0:f.filter)==null?void 0:h.range});let p=null;if(r){const f=(y=r.filter.range)==null?void 0:y[0];p=[N.parseNumber(f==null?void 0:f.gte),N.parseNumber(f==null?void 0:f.lte)]}const S=[];let d=Math.floor(t/o)*o;for(;d<n;){const f=d+o,h=p&&p[0]===d&&p[1]===f;S.push({min:d,max:f,selected:h}),d=f}return S},[a,t,n,o]),g=r=>{i([r,u[1]])},s=r=>{i([u[0],r])},l=t!==u[0]||n!==u[1];return{min:t,max:n,range:u,updateRange:i,ranges:c,handleMinChange:g,handleMaxChange:s,isSelected:l}}function j(){const{products:e,keywords:o}=m.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:o??{hits:[],total:0}}}function I(){const e=m.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return v.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function b(e){return e&&!Number.isNaN(e)?e:0}function L(e,o){const{from:t,size:n,total:u}=m.useNostoAppState(s=>{var l,r,p,S,d;return{from:b(((l=s.query.products)==null?void 0:l.from)??0),size:b(((p=(r=s.response)==null?void 0:r.products)==null?void 0:p.size)??0),total:b(((d=(S=s.response)==null?void 0:S.products)==null?void 0:d.total)??0)}}),{updateSearch:i}=m.useActions(),a=t+n,c=[...e].reverse().filter(s=>s+o<u);return{from:t,to:a,total:u,size:n,sizeOptions:c,handleSizeChange:s=>{i({products:{size:N.parseNumber(s)}})}}}function O(e,o){return e.length!==o.length?!1:e.every(t=>o.find(n=>t.field===n.field&&t.order===n.order))}function V(e){var i,a;const o=m.useNostoAppState(c=>c.query),{updateSearch:t}=m.useActions();return{activeSort:((i=e.find(c=>{var g;return O(c.value.sort,((g=o.products)==null?void 0:g.sort)||[])}))==null?void 0:i.id)??((a=e[0])==null?void 0:a.id),setSort:c=>{const g=e.find(s=>s.id===c);g&&t({products:{sort:g.value.sort}})}}}exports.useActions=m.useActions;exports.useLoadMore=m.useLoadMore;exports.useNostoAppState=m.useNostoAppState;exports.useDecoratedSearchResults=C;exports.useFacet=z;exports.useFacets=x;exports.usePagination=w;exports.usePersonalization=T;exports.useProductFilters=M;exports.useRange=R;exports.useRangeSelector=D;exports.useResponse=j;exports.useSelectedFiltersCount=I;exports.useSizeOptions=L;exports.useSort=V;
|
package/dist/preact/hooks.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u as F, b as R } from "../useLoadMore-
|
|
2
|
-
import { a as Y } from "../useLoadMore-
|
|
1
|
+
import { u as F, b as R } from "../useLoadMore-CHLvVMm8.js";
|
|
2
|
+
import { a as Y } from "../useLoadMore-CHLvVMm8.js";
|
|
3
3
|
import { a as N } from "../isEqual-BzZ3d1JM.js";
|
|
4
4
|
import { useState as P, useMemo as z, useEffect as b, useCallback as M } from "preact/hooks";
|
|
5
5
|
import { s as q } from "../index.es-B8mbAxS4.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../InfiniteScrollWithObserver-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../InfiniteScrollWithObserver-C3ILy8X_.cjs"),r=require("../useLoadMore-Co6PDmam.cjs");exports.InfiniteScrollWithObserver=e.InfiniteScrollWithObserver;exports.intersectionObserverSupported=e.intersectionObserverSupported;exports.getNextPageQuery=r.getNextPageQuery;
|
package/dist/preact/legacy.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as t, i as o } from "../InfiniteScrollWithObserver-
|
|
2
|
-
import { g as s } from "../useLoadMore-
|
|
1
|
+
import { I as t, i as o } from "../InfiniteScrollWithObserver-DGZxUITY.js";
|
|
2
|
+
import { g as s } from "../useLoadMore-CHLvVMm8.js";
|
|
3
3
|
export {
|
|
4
4
|
t as InfiniteScrollWithObserver,
|
|
5
5
|
s as getNextPageQuery,
|
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 p=require("../index.es-DlUp67LT.cjs"),s=require("../configContext-CGXeJcqj.cjs"),S=require("../renderHeadless-xhkLegO4.cjs"),a=require("../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../baseConfig-BlLNh6Jn.cjs"),g="nosto:search:scrollPos";function d(){window.sessionStorage.setItem(g,window.scrollY.toString())}function C({children:e,hit:t,onClick:o}){const{pageType:r}=s.useConfig(),c=r==="autocomplete"?void 0:r==="search"?"serp":r;return S.renderHeadless({children:e,updateElement:(n,u)=>(u.depth>0||(n.props={...n.props,onClick:l=>{t&&c&&p.s(f=>f.recordSearchClick(c,t)),d(),typeof o=="function"&&o(l)}}),n)})}const h={...i.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function m(e={}){return{pageType:"search",...h,...e}}function P({config:e,store:t,children:o}){const r=t??s.createStore();return i.useCheckClientScript(),a.u(s.ConfigContext,{value:m(e),children:a.u(s.StoreContext,{value:r,children:o})})}exports.SearchPageProvider=P;exports.SerpElement=C;
|
package/dist/preact/serp.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { s as l } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
import { u as f, c as u, S, C as m } from "../
|
|
2
|
+
import { u as f, c as u, S, C as m } from "../configContext-CDTtcin_.js";
|
|
3
3
|
import { r as g } from "../renderHeadless-BteGML1G.js";
|
|
4
4
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
5
|
import { d as C, u as d } from "../baseConfig-XyA_9NDR.js";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
* Function to calculate the new query values for loading more products
|
|
3
|
-
*/
|
|
4
|
-
export declare function getNextPageQuery({ from, size, pageSize }: {
|
|
1
|
+
type NextPageQueryProps = {
|
|
5
2
|
from: number;
|
|
6
3
|
size: number;
|
|
7
4
|
pageSize: number;
|
|
8
|
-
}
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Function to calculate the new query values for loading more products
|
|
8
|
+
*/
|
|
9
|
+
export declare function getNextPageQuery({ from, size, pageSize }: NextPageQueryProps): {
|
|
9
10
|
products: {
|
|
10
11
|
from: number;
|
|
11
12
|
size?: undefined;
|
|
@@ -16,3 +17,4 @@ export declare function getNextPageQuery({ from, size, pageSize }: {
|
|
|
16
17
|
from?: undefined;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
20
|
+
export {};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
2
|
export declare const STORAGE_ENTRY_NAME = "nosto:search:searchResult";
|
|
3
|
+
export type SearchResultDto = {
|
|
4
|
+
query: ReturnType<typeof getCacheKey>;
|
|
5
|
+
result: SearchResult;
|
|
6
|
+
};
|
|
3
7
|
export declare function cacheSearchResult(usePersistentCache: boolean, query: SearchQuery, result: SearchResult): void;
|
|
4
|
-
export declare function loadCachedResultIfApplicable(usePersistentCache: boolean, query: SearchQuery):
|
|
8
|
+
export declare function loadCachedResultIfApplicable(usePersistentCache: boolean, query: SearchQuery): SearchResultDto | null;
|
|
9
|
+
declare function getCacheKey(query: SearchQuery): SearchQuery;
|
|
10
|
+
export declare function isValueShapeCorrect(value: unknown): value is SearchResultDto;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SearchOptions } from '../../../core/src/types';
|
|
2
|
+
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
3
|
+
import { Config } from '../config/config';
|
|
4
|
+
export declare function searchWithCache(config: Config, searchQuery: SearchQuery, options: SearchOptions): Promise<import('@nosto/nosto-js/client').SearchResult>;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { S as v, u as M } from "./configContext-CDTtcin_.js";
|
|
2
|
+
import { useContext as F, useState as N, useEffect as z, useMemo as A, useCallback as f } from "preact/hooks";
|
|
3
|
+
import { u as R, a as h, m as q, i as O } from "./unique-CyAMhegX.js";
|
|
4
|
+
import { s as y } from "./search-DaZVHDP9.js";
|
|
5
|
+
import { i as P, d as m } from "./isEqual-BzZ3d1JM.js";
|
|
6
|
+
import { l as p } from "./logger-DW5RVLX8.js";
|
|
7
|
+
function E(e = U) {
|
|
8
|
+
const r = F(v), [t, s] = N(e(r.getState()));
|
|
9
|
+
return r.onChange(e, s), z(() => () => r.clearOnChange(s), [r]), t;
|
|
10
|
+
}
|
|
11
|
+
const U = (e) => e;
|
|
12
|
+
function J(e, r) {
|
|
13
|
+
return {
|
|
14
|
+
...r,
|
|
15
|
+
products: {
|
|
16
|
+
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
17
|
+
fields: K,
|
|
18
|
+
...r.products
|
|
19
|
+
},
|
|
20
|
+
...r.keywords ? {
|
|
21
|
+
keywords: {
|
|
22
|
+
...r.keywords,
|
|
23
|
+
fields: R([...V, ...r.keywords.fields ?? []]),
|
|
24
|
+
highlight: r.keywords.highlight ?? {
|
|
25
|
+
preTag: "<strong>",
|
|
26
|
+
postTag: "</strong>"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} : {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const K = [
|
|
33
|
+
"productId",
|
|
34
|
+
"url",
|
|
35
|
+
"name",
|
|
36
|
+
"imageUrl",
|
|
37
|
+
"imageHash",
|
|
38
|
+
"thumbUrl",
|
|
39
|
+
"description",
|
|
40
|
+
"brand",
|
|
41
|
+
"variantId",
|
|
42
|
+
"availability",
|
|
43
|
+
"price",
|
|
44
|
+
"priceText",
|
|
45
|
+
"categoryIds",
|
|
46
|
+
"categories",
|
|
47
|
+
"customFields.key",
|
|
48
|
+
"customFields.value",
|
|
49
|
+
"priceCurrencyCode",
|
|
50
|
+
"datePublished",
|
|
51
|
+
"listPrice",
|
|
52
|
+
"unitPricingBaseMeasure",
|
|
53
|
+
"unitPricingUnit",
|
|
54
|
+
"unitPricingMeasure",
|
|
55
|
+
"googleCategory",
|
|
56
|
+
"gtin",
|
|
57
|
+
"ageGroup",
|
|
58
|
+
"gender",
|
|
59
|
+
"condition",
|
|
60
|
+
"alternateImageUrls",
|
|
61
|
+
"ratingValue",
|
|
62
|
+
"reviewCount",
|
|
63
|
+
"inventoryLevel",
|
|
64
|
+
"skus.id",
|
|
65
|
+
"skus.name",
|
|
66
|
+
"skus.price",
|
|
67
|
+
"skus.listPrice",
|
|
68
|
+
"skus.priceText",
|
|
69
|
+
"skus.url",
|
|
70
|
+
"skus.imageUrl",
|
|
71
|
+
"skus.inventoryLevel",
|
|
72
|
+
"skus.customFields.key",
|
|
73
|
+
"skus.customFields.value",
|
|
74
|
+
"skus.availability",
|
|
75
|
+
"pid",
|
|
76
|
+
"onDiscount",
|
|
77
|
+
"extra.key",
|
|
78
|
+
"extra.value",
|
|
79
|
+
"saleable",
|
|
80
|
+
"available",
|
|
81
|
+
"tags1",
|
|
82
|
+
"tags2",
|
|
83
|
+
"tags3"
|
|
84
|
+
], V = ["keyword", "_redirect"];
|
|
85
|
+
function L(e, r, t) {
|
|
86
|
+
const s = JSON.stringify(r);
|
|
87
|
+
try {
|
|
88
|
+
p.info("Setting storage", e, s), t.setItem(e, s);
|
|
89
|
+
} catch (a) {
|
|
90
|
+
p.warn(a);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function _(e, r) {
|
|
94
|
+
try {
|
|
95
|
+
const t = r.getItem(e);
|
|
96
|
+
if (t)
|
|
97
|
+
return JSON.parse(t);
|
|
98
|
+
} catch (t) {
|
|
99
|
+
p.warn(t);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function j(e, r) {
|
|
103
|
+
L(e, r, sessionStorage);
|
|
104
|
+
}
|
|
105
|
+
function B(e) {
|
|
106
|
+
return _(e, sessionStorage);
|
|
107
|
+
}
|
|
108
|
+
const I = "nosto:search:searchResult";
|
|
109
|
+
function D(e, r, t) {
|
|
110
|
+
if (!e)
|
|
111
|
+
return;
|
|
112
|
+
j(I, { query: r, result: t });
|
|
113
|
+
}
|
|
114
|
+
function G(e, r) {
|
|
115
|
+
if (!e)
|
|
116
|
+
return null;
|
|
117
|
+
const t = B(I);
|
|
118
|
+
if (!t || !H(t))
|
|
119
|
+
return null;
|
|
120
|
+
const s = b(t.query);
|
|
121
|
+
return P(b(r), s) ? t : null;
|
|
122
|
+
}
|
|
123
|
+
function b(e) {
|
|
124
|
+
const r = {
|
|
125
|
+
...e,
|
|
126
|
+
time: void 0,
|
|
127
|
+
products: {
|
|
128
|
+
...e.products,
|
|
129
|
+
size: void 0
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
return JSON.parse(JSON.stringify(r));
|
|
133
|
+
}
|
|
134
|
+
function H(e) {
|
|
135
|
+
return typeof e == "object" && e !== null && "query" in e && "result" in e;
|
|
136
|
+
}
|
|
137
|
+
async function W(e, r, t) {
|
|
138
|
+
const s = e.pageType !== "autocomplete" && e.persistentSearchCache, a = s ? await Q(r, t, s) : await y(r, t);
|
|
139
|
+
return D(s, r, a), a;
|
|
140
|
+
}
|
|
141
|
+
async function Q(e, r, t) {
|
|
142
|
+
var g, d, k, w, C;
|
|
143
|
+
const { from: s = 0, size: a = 0 } = e.products || {}, { result: o } = G(t, e) || {}, n = ((g = o == null ? void 0 : o.products) == null ? void 0 : g.hits) || [];
|
|
144
|
+
if (!o)
|
|
145
|
+
return await y(e, r);
|
|
146
|
+
if (a === n.length)
|
|
147
|
+
return o;
|
|
148
|
+
if (a < n.length)
|
|
149
|
+
return {
|
|
150
|
+
...o,
|
|
151
|
+
products: {
|
|
152
|
+
...o.products,
|
|
153
|
+
hits: n.slice(0, a),
|
|
154
|
+
total: ((d = o.products) == null ? void 0 : d.total) || 0
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const c = a - n.length, i = s > 0 ? s + 1 : a - c, l = {
|
|
158
|
+
...e,
|
|
159
|
+
products: {
|
|
160
|
+
...e.products,
|
|
161
|
+
from: i,
|
|
162
|
+
size: c
|
|
163
|
+
}
|
|
164
|
+
}, u = await y(l, r);
|
|
165
|
+
return {
|
|
166
|
+
...o,
|
|
167
|
+
products: {
|
|
168
|
+
...o.products,
|
|
169
|
+
hits: [...((k = o.products) == null ? void 0 : k.hits) || [], ...((w = u.products) == null ? void 0 : w.hits) || []],
|
|
170
|
+
total: (C = u.products) == null ? void 0 : C.total
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async function T(e, r, t) {
|
|
175
|
+
var l, u, g;
|
|
176
|
+
const s = h("newSearch"), a = e.config.pageType, o = a === "search" ? "serp" : a, n = m(e.store.getInitialState().query, r), c = m(e.config.search, t, {
|
|
177
|
+
track: o,
|
|
178
|
+
redirect: a !== "autocomplete",
|
|
179
|
+
isKeyword: !!(t != null && t.isKeyword)
|
|
180
|
+
});
|
|
181
|
+
e.store.updateState({
|
|
182
|
+
query: n,
|
|
183
|
+
loading: !0,
|
|
184
|
+
initialized: !0
|
|
185
|
+
});
|
|
186
|
+
const i = e.config.queryModifications(
|
|
187
|
+
{
|
|
188
|
+
...n,
|
|
189
|
+
products: {
|
|
190
|
+
...n.products,
|
|
191
|
+
// Apply filter merging to avoid overwriting base filters
|
|
192
|
+
filter: q((u = (l = e.store.getInitialState().query) == null ? void 0 : l.products) == null ? void 0 : u.filter, (g = r.products) == null ? void 0 : g.filter)
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
a
|
|
196
|
+
);
|
|
197
|
+
try {
|
|
198
|
+
const d = await W(
|
|
199
|
+
e.config,
|
|
200
|
+
J(e.config.pageType, i),
|
|
201
|
+
c
|
|
202
|
+
);
|
|
203
|
+
e.store.updateState({
|
|
204
|
+
response: d,
|
|
205
|
+
loading: !1
|
|
206
|
+
});
|
|
207
|
+
} catch (d) {
|
|
208
|
+
p.error("Search action failed", d);
|
|
209
|
+
}
|
|
210
|
+
s();
|
|
211
|
+
}
|
|
212
|
+
async function S(e, r, t) {
|
|
213
|
+
const s = h("updateSearch"), a = m(e.store.getState().query, { products: { from: 0 } }, r);
|
|
214
|
+
await T(e, a, t), s();
|
|
215
|
+
}
|
|
216
|
+
async function Y(e, r, t) {
|
|
217
|
+
var n;
|
|
218
|
+
const s = h("replaceFilter"), a = (n = e.store.getState().query.products) == null ? void 0 : n.filter, o = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
219
|
+
await S(e, {
|
|
220
|
+
products: {
|
|
221
|
+
filter: [...(a == null ? void 0 : a.filter((c) => c.field !== r)) ?? [], ...o]
|
|
222
|
+
}
|
|
223
|
+
}), s();
|
|
224
|
+
}
|
|
225
|
+
async function X(e, r, t, s) {
|
|
226
|
+
var i, l;
|
|
227
|
+
const a = h("toggleProductFilter"), o = (i = e.store.getState().query.products) == null ? void 0 : i.filter, n = o == null ? void 0 : o.find((u) => u.value instanceof Array && u.field === r), c = n != null && n.value ? {
|
|
228
|
+
...n,
|
|
229
|
+
value: [...n.value.filter((u) => !P(u, t)), ...s ? [t] : []]
|
|
230
|
+
} : s ? {
|
|
231
|
+
field: r,
|
|
232
|
+
value: [t]
|
|
233
|
+
} : void 0;
|
|
234
|
+
await S(e, {
|
|
235
|
+
products: {
|
|
236
|
+
filter: [...(o == null ? void 0 : o.filter((u) => u !== n)) ?? [], ...(l = c == null ? void 0 : c.value) != null && l.length ? [c] : []]
|
|
237
|
+
}
|
|
238
|
+
}), a();
|
|
239
|
+
}
|
|
240
|
+
function Z() {
|
|
241
|
+
const e = M(), r = F(v), t = A(
|
|
242
|
+
() => ({
|
|
243
|
+
config: e,
|
|
244
|
+
store: r
|
|
245
|
+
}),
|
|
246
|
+
[e, r]
|
|
247
|
+
), s = f(
|
|
248
|
+
(c, i) => T(t, c, i),
|
|
249
|
+
[t]
|
|
250
|
+
), a = f(
|
|
251
|
+
(c, i) => S(t, c, i),
|
|
252
|
+
[t]
|
|
253
|
+
), o = f(
|
|
254
|
+
(c, i, l) => X(t, c, i, l),
|
|
255
|
+
[t]
|
|
256
|
+
), n = f(
|
|
257
|
+
(c, i) => Y(t, c, i),
|
|
258
|
+
[t]
|
|
259
|
+
);
|
|
260
|
+
return {
|
|
261
|
+
newSearch: s,
|
|
262
|
+
updateSearch: a,
|
|
263
|
+
toggleProductFilter: o,
|
|
264
|
+
replaceFilter: n
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function $({ from: e, size: r, pageSize: t }) {
|
|
268
|
+
return O() ? {
|
|
269
|
+
products: { from: e + t }
|
|
270
|
+
} : {
|
|
271
|
+
products: { size: r + t }
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function ae(e = 24) {
|
|
275
|
+
const { from: r, size: t } = E((o) => {
|
|
276
|
+
var n, c;
|
|
277
|
+
return {
|
|
278
|
+
from: ((n = o.query.products) == null ? void 0 : n.from) ?? 0,
|
|
279
|
+
size: ((c = o.query.products) == null ? void 0 : c.size) ?? 0
|
|
280
|
+
};
|
|
281
|
+
}), { updateSearch: s } = Z();
|
|
282
|
+
return {
|
|
283
|
+
loadMore: f(async () => {
|
|
284
|
+
await s($({ from: r, size: t, pageSize: e }));
|
|
285
|
+
}, [r, t, e, s])
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
export {
|
|
289
|
+
ae as a,
|
|
290
|
+
Z as b,
|
|
291
|
+
$ as g,
|
|
292
|
+
E as u
|
|
293
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const S=require("./configContext-CGXeJcqj.cjs"),l=require("preact/hooks"),g=require("./unique-BCAEb4ek.cjs"),k=require("./search-DJ_ktWg-.cjs"),h=require("./isEqual-DQXR__da.cjs"),y=require("./logger-DbHGgDgO.cjs");function v(e=N){const r=l.useContext(S.StoreContext),[t,s]=l.useState(e(r.getState()));return r.onChange(e,s),l.useEffect(()=>()=>r.clearOnChange(s),[r]),t}const N=e=>e;function T(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:A,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...z,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const A=["productId","url","name","imageUrl","imageHash","thumbUrl","description","brand","variantId","availability","price","priceText","categoryIds","categories","customFields.key","customFields.value","priceCurrencyCode","datePublished","listPrice","unitPricingBaseMeasure","unitPricingUnit","unitPricingMeasure","googleCategory","gtin","ageGroup","gender","condition","alternateImageUrls","ratingValue","reviewCount","inventoryLevel","skus.id","skus.name","skus.price","skus.listPrice","skus.priceText","skus.url","skus.imageUrl","skus.inventoryLevel","skus.customFields.key","skus.customFields.value","skus.availability","pid","onDiscount","extra.key","extra.value","saleable","available","tags1","tags2","tags3"],z=["keyword","_redirect"];function E(e,r,t){const s=JSON.stringify(r);try{y.logger.info("Setting storage",e,s),t.setItem(e,s)}catch(a){y.logger.warn(a)}}function R(e,r){try{const t=r.getItem(e);if(t)return JSON.parse(t)}catch(t){y.logger.warn(t)}}function O(e,r){E(e,r,sessionStorage)}function U(e){return R(e,sessionStorage)}const F="nosto:search:searchResult";function J(e,r,t){if(!e)return;O(F,{query:r,result:t})}function K(e,r){if(!e)return null;const t=U(F);if(!t||!L(t))return null;const s=q(t.query);return h.isEqual(q(r),s)?t:null}function q(e){const r={...e,time:void 0,products:{...e.products,size:void 0}};return JSON.parse(JSON.stringify(r))}function L(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function V(e,r,t){const s=e.pageType!=="autocomplete"&&e.persistentSearchCache,a=s?await _(r,t,s):await k.search(r,t);return J(s,r,a),a}async function _(e,r,t){var p,f,C,w,b;const{from:s=0,size:a=0}=e.products||{},{result:o}=K(t,e)||{},n=((p=o==null?void 0:o.products)==null?void 0:p.hits)||[];if(!o)return await k.search(e,r);if(a===n.length)return o;if(a<n.length)return{...o,products:{...o.products,hits:n.slice(0,a),total:((f=o.products)==null?void 0:f.total)||0}};const c=a-n.length,i=s>0?s+1:a-c,d={...e,products:{...e.products,from:i,size:c}},u=await k.search(d,r);return{...o,products:{...o.products,hits:[...((C=o.products)==null?void 0:C.hits)||[],...((w=u.products)==null?void 0:w.hits)||[]],total:(b=u.products)==null?void 0:b.total}}}async function P(e,r,t){var d,u,p;const s=g.measure("newSearch"),a=e.config.pageType,o=a==="search"?"serp":a,n=h.deepMerge(e.store.getInitialState().query,r),c=h.deepMerge(e.config.search,t,{track:o,redirect:a!=="autocomplete",isKeyword:!!(t!=null&&t.isKeyword)});e.store.updateState({query:n,loading:!0,initialized:!0});const i=e.config.queryModifications({...n,products:{...n.products,filter:g.mergeArrays((u=(d=e.store.getInitialState().query)==null?void 0:d.products)==null?void 0:u.filter,(p=r.products)==null?void 0:p.filter)}},a);try{const f=await V(e.config,T(e.config.pageType,i),c);e.store.updateState({response:f,loading:!1})}catch(f){y.logger.error("Search action failed",f)}s()}async function m(e,r,t){const s=g.measure("updateSearch"),a=h.deepMerge(e.store.getState().query,{products:{from:0}},r);await P(e,a,t),s()}async function j(e,r,t){var n;const s=g.measure("replaceFilter"),a=(n=e.store.getState().query.products)==null?void 0:n.filter,o=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await m(e,{products:{filter:[...(a==null?void 0:a.filter(c=>c.field!==r))??[],...o]}}),s()}async function B(e,r,t,s){var i,d;const a=g.measure("toggleProductFilter"),o=(i=e.store.getState().query.products)==null?void 0:i.filter,n=o==null?void 0:o.find(u=>u.value instanceof Array&&u.field===r),c=n!=null&&n.value?{...n,value:[...n.value.filter(u=>!h.isEqual(u,t)),...s?[t]:[]]}:s?{field:r,value:[t]}:void 0;await m(e,{products:{filter:[...(o==null?void 0:o.filter(u=>u!==n))??[],...(d=c==null?void 0:c.value)!=null&&d.length?[c]:[]]}}),a()}function M(){const e=S.useConfig(),r=l.useContext(S.StoreContext),t=l.useMemo(()=>({config:e,store:r}),[e,r]),s=l.useCallback((c,i)=>P(t,c,i),[t]),a=l.useCallback((c,i)=>m(t,c,i),[t]),o=l.useCallback((c,i,d)=>B(t,c,i,d),[t]),n=l.useCallback((c,i)=>j(t,c,i),[t]);return{newSearch:s,updateSearch:a,toggleProductFilter:o,replaceFilter:n}}function I({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function D(e=24){const{from:r,size:t}=v(o=>{var n,c;return{from:((n=o.query.products)==null?void 0:n.from)??0,size:((c=o.query.products)==null?void 0:c.size)??0}}),{updateSearch:s}=M();return{loadMore:l.useCallback(async()=>{await s(I({from:r,size:t,pageSize:e}))},[r,t,e,s])}}exports.getNextPageQuery=I;exports.useActions=M;exports.useLoadMore=D;exports.useNostoAppState=v;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type InputBindingCallbacks = {
|
|
2
|
+
onSubmit?: (value: string) => void;
|
|
3
|
+
onInput?: (value: string) => void;
|
|
4
|
+
onFocus?: (value: string) => void;
|
|
5
|
+
onKeyDown?: (value: string, key: string) => void;
|
|
6
|
+
onClick?: (value: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export interface BindElementOptions {
|
|
9
|
+
form?: HTMLFormElement;
|
|
10
|
+
}
|
|
11
|
+
export declare function disableNativeAutocomplete(target: HTMLInputElement): void;
|
|
12
|
+
export declare function bindInput(target: HTMLInputElement, { onClick, onFocus, onInput, onKeyDown, onSubmit }: InputBindingCallbacks, { form }?: BindElementOptions): {
|
|
13
|
+
destroy: () => void;
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("preact"),w=require("preact/hooks"),i=require("./isEqual-DQXR__da.cjs"),l=s.createContext(null),M=()=>{const e=w.useContext(l);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};function f(e,u={}){const r=new Map;let o=i.deepMergePlain(e,u??{});const S=i.deepMergePlain(e,u);function d(t){o=t(o);for(const n of r.values())n(o)}function x(t){d(n=>({...n,...t}))}function p(){return o}function h(){return structuredClone(S)}function q(t,n){let c;r.set(n,b=>{const a=t(b);i.isEqual(a,c)||(c=a,n(a))})}function E(t){r.delete(t)}return{updateState:x,getState:p,getInitialState:h,onChange:q,clearOnChange:E}}const C={loading:!0,query:{},response:{},initialized:!1};function g(e={}){return f(C,e)}const P=s.createContext(g());exports.ConfigContext=l;exports.StoreContext=P;exports.createExtendableStore=f;exports.createStore=g;exports.defaultState=C;exports.useConfig=M;
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { u as M, S as C } from "./storeContext-jWZFJ8Kf.js";
|
|
2
|
-
import { useContext as b, useMemo as T, useCallback as g, useState as A, useEffect as R } from "preact/hooks";
|
|
3
|
-
import { s as N } from "./search-DaZVHDP9.js";
|
|
4
|
-
import { u as Q, a as p, m as E, i as U } from "./unique-CyAMhegX.js";
|
|
5
|
-
import { i as P, d as m } from "./isEqual-BzZ3d1JM.js";
|
|
6
|
-
import { l as f } from "./logger-DW5RVLX8.js";
|
|
7
|
-
function V(e, r) {
|
|
8
|
-
return {
|
|
9
|
-
...r,
|
|
10
|
-
products: {
|
|
11
|
-
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
12
|
-
fields: K,
|
|
13
|
-
...r.products
|
|
14
|
-
},
|
|
15
|
-
...r.keywords ? {
|
|
16
|
-
keywords: {
|
|
17
|
-
...r.keywords,
|
|
18
|
-
fields: Q([...O, ...r.keywords.fields ?? []]),
|
|
19
|
-
highlight: r.keywords.highlight ?? {
|
|
20
|
-
preTag: "<strong>",
|
|
21
|
-
postTag: "</strong>"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} : {}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const K = [
|
|
28
|
-
"productId",
|
|
29
|
-
"url",
|
|
30
|
-
"name",
|
|
31
|
-
"imageUrl",
|
|
32
|
-
"imageHash",
|
|
33
|
-
"thumbUrl",
|
|
34
|
-
"description",
|
|
35
|
-
"brand",
|
|
36
|
-
"variantId",
|
|
37
|
-
"availability",
|
|
38
|
-
"price",
|
|
39
|
-
"priceText",
|
|
40
|
-
"categoryIds",
|
|
41
|
-
"categories",
|
|
42
|
-
"customFields.key",
|
|
43
|
-
"customFields.value",
|
|
44
|
-
"priceCurrencyCode",
|
|
45
|
-
"datePublished",
|
|
46
|
-
"listPrice",
|
|
47
|
-
"unitPricingBaseMeasure",
|
|
48
|
-
"unitPricingUnit",
|
|
49
|
-
"unitPricingMeasure",
|
|
50
|
-
"googleCategory",
|
|
51
|
-
"gtin",
|
|
52
|
-
"ageGroup",
|
|
53
|
-
"gender",
|
|
54
|
-
"condition",
|
|
55
|
-
"alternateImageUrls",
|
|
56
|
-
"ratingValue",
|
|
57
|
-
"reviewCount",
|
|
58
|
-
"inventoryLevel",
|
|
59
|
-
"skus.id",
|
|
60
|
-
"skus.name",
|
|
61
|
-
"skus.price",
|
|
62
|
-
"skus.listPrice",
|
|
63
|
-
"skus.priceText",
|
|
64
|
-
"skus.url",
|
|
65
|
-
"skus.imageUrl",
|
|
66
|
-
"skus.inventoryLevel",
|
|
67
|
-
"skus.customFields.key",
|
|
68
|
-
"skus.customFields.value",
|
|
69
|
-
"skus.availability",
|
|
70
|
-
"pid",
|
|
71
|
-
"onDiscount",
|
|
72
|
-
"extra.key",
|
|
73
|
-
"extra.value",
|
|
74
|
-
"saleable",
|
|
75
|
-
"available",
|
|
76
|
-
"tags1",
|
|
77
|
-
"tags2",
|
|
78
|
-
"tags3"
|
|
79
|
-
], O = ["keyword", "_redirect"];
|
|
80
|
-
function z(e, r, t) {
|
|
81
|
-
const s = JSON.stringify(r);
|
|
82
|
-
try {
|
|
83
|
-
f.info("Setting storage", e, s), t.setItem(e, s);
|
|
84
|
-
} catch (o) {
|
|
85
|
-
f.warn(o);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function D(e, r) {
|
|
89
|
-
try {
|
|
90
|
-
const t = r.getItem(e);
|
|
91
|
-
if (t)
|
|
92
|
-
return JSON.parse(t);
|
|
93
|
-
} catch (t) {
|
|
94
|
-
f.warn(t);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function L(e, r) {
|
|
98
|
-
z(e, r, sessionStorage);
|
|
99
|
-
}
|
|
100
|
-
function _(e) {
|
|
101
|
-
return D(e, sessionStorage);
|
|
102
|
-
}
|
|
103
|
-
const F = "nosto:search:searchResult";
|
|
104
|
-
function j(e, r, t) {
|
|
105
|
-
if (!e)
|
|
106
|
-
return;
|
|
107
|
-
L(F, { query: r, result: t });
|
|
108
|
-
}
|
|
109
|
-
function B(e, r) {
|
|
110
|
-
if (!e)
|
|
111
|
-
return null;
|
|
112
|
-
const t = _(F);
|
|
113
|
-
if (!t || !G(t))
|
|
114
|
-
return null;
|
|
115
|
-
const s = w(t.query);
|
|
116
|
-
return P(w(r), s) ? t.result : null;
|
|
117
|
-
}
|
|
118
|
-
function w(e) {
|
|
119
|
-
return {
|
|
120
|
-
accountId: e.accountId,
|
|
121
|
-
customRules: e.customRules,
|
|
122
|
-
explain: e.explain,
|
|
123
|
-
keywords: e.keywords,
|
|
124
|
-
products: e.products,
|
|
125
|
-
query: e.query,
|
|
126
|
-
redirect: e.redirect,
|
|
127
|
-
rules: e.rules,
|
|
128
|
-
segments: e.segments,
|
|
129
|
-
sessionParams: e.sessionParams
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
function G(e) {
|
|
133
|
-
return typeof e == "object" && e !== null && "query" in e && "result" in e;
|
|
134
|
-
}
|
|
135
|
-
async function I(e, r, t) {
|
|
136
|
-
var u, h, S;
|
|
137
|
-
const s = p("newSearch"), o = e.config.pageType, c = o === "search" ? "serp" : o, n = m(e.store.getInitialState().query, r), a = m(e.config.search, t, {
|
|
138
|
-
track: c,
|
|
139
|
-
redirect: o !== "autocomplete",
|
|
140
|
-
isKeyword: !!(t != null && t.isKeyword)
|
|
141
|
-
});
|
|
142
|
-
e.store.updateState({
|
|
143
|
-
query: n,
|
|
144
|
-
loading: !0,
|
|
145
|
-
initialized: !0
|
|
146
|
-
});
|
|
147
|
-
const i = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
|
|
148
|
-
{
|
|
149
|
-
...n,
|
|
150
|
-
products: {
|
|
151
|
-
...n.products,
|
|
152
|
-
// Apply filter merging to avoid overwriting base filters
|
|
153
|
-
filter: E((h = (u = e.store.getInitialState().query) == null ? void 0 : u.products) == null ? void 0 : h.filter, (S = r.products) == null ? void 0 : S.filter)
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
o
|
|
157
|
-
);
|
|
158
|
-
try {
|
|
159
|
-
let d;
|
|
160
|
-
const k = B(i, l);
|
|
161
|
-
if (k)
|
|
162
|
-
d = k;
|
|
163
|
-
else {
|
|
164
|
-
const v = V(o, l);
|
|
165
|
-
d = await N(v, a), j(i, l, d);
|
|
166
|
-
}
|
|
167
|
-
e.store.updateState({
|
|
168
|
-
response: d,
|
|
169
|
-
loading: !1
|
|
170
|
-
});
|
|
171
|
-
} catch (d) {
|
|
172
|
-
f.error("Search action failed", d);
|
|
173
|
-
}
|
|
174
|
-
s();
|
|
175
|
-
}
|
|
176
|
-
async function y(e, r, t) {
|
|
177
|
-
const s = p("updateSearch"), o = m(e.store.getState().query, { products: { from: 0 } }, r);
|
|
178
|
-
await I(e, o, t), s();
|
|
179
|
-
}
|
|
180
|
-
async function J(e, r, t) {
|
|
181
|
-
var n;
|
|
182
|
-
const s = p("replaceFilter"), o = (n = e.store.getState().query.products) == null ? void 0 : n.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
183
|
-
await y(e, {
|
|
184
|
-
products: {
|
|
185
|
-
filter: [...(o == null ? void 0 : o.filter((a) => a.field !== r)) ?? [], ...c]
|
|
186
|
-
}
|
|
187
|
-
}), s();
|
|
188
|
-
}
|
|
189
|
-
async function q(e, r, t, s) {
|
|
190
|
-
var i, l;
|
|
191
|
-
const o = p("toggleProductFilter"), c = (i = e.store.getState().query.products) == null ? void 0 : i.filter, n = c == null ? void 0 : c.find((u) => u.value instanceof Array && u.field === r), a = n != null && n.value ? {
|
|
192
|
-
...n,
|
|
193
|
-
value: [...n.value.filter((u) => !P(u, t)), ...s ? [t] : []]
|
|
194
|
-
} : s ? {
|
|
195
|
-
field: r,
|
|
196
|
-
value: [t]
|
|
197
|
-
} : void 0;
|
|
198
|
-
await y(e, {
|
|
199
|
-
products: {
|
|
200
|
-
filter: [...(c == null ? void 0 : c.filter((u) => u !== n)) ?? [], ...(l = a == null ? void 0 : a.value) != null && l.length ? [a] : []]
|
|
201
|
-
}
|
|
202
|
-
}), o();
|
|
203
|
-
}
|
|
204
|
-
function x() {
|
|
205
|
-
const e = M(), r = b(C), t = T(
|
|
206
|
-
() => ({
|
|
207
|
-
config: e,
|
|
208
|
-
store: r
|
|
209
|
-
}),
|
|
210
|
-
[e, r]
|
|
211
|
-
), s = g(
|
|
212
|
-
(a, i) => I(t, a, i),
|
|
213
|
-
[t]
|
|
214
|
-
), o = g(
|
|
215
|
-
(a, i) => y(t, a, i),
|
|
216
|
-
[t]
|
|
217
|
-
), c = g(
|
|
218
|
-
(a, i, l) => q(t, a, i, l),
|
|
219
|
-
[t]
|
|
220
|
-
), n = g(
|
|
221
|
-
(a, i) => J(t, a, i),
|
|
222
|
-
[t]
|
|
223
|
-
);
|
|
224
|
-
return {
|
|
225
|
-
newSearch: s,
|
|
226
|
-
updateSearch: o,
|
|
227
|
-
toggleProductFilter: c,
|
|
228
|
-
replaceFilter: n
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function H(e = W) {
|
|
232
|
-
const r = b(C), [t, s] = A(e(r.getState()));
|
|
233
|
-
return r.onChange(e, s), R(() => () => r.clearOnChange(s), [r]), t;
|
|
234
|
-
}
|
|
235
|
-
const W = (e) => e;
|
|
236
|
-
function Y({ from: e, size: r, pageSize: t }) {
|
|
237
|
-
return U() ? {
|
|
238
|
-
products: { from: e + t }
|
|
239
|
-
} : {
|
|
240
|
-
products: { size: r + t }
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
function se(e = 24) {
|
|
244
|
-
const { from: r, size: t } = H((c) => {
|
|
245
|
-
var n, a;
|
|
246
|
-
return {
|
|
247
|
-
from: ((n = c.query.products) == null ? void 0 : n.from) ?? 0,
|
|
248
|
-
size: ((a = c.query.products) == null ? void 0 : a.size) ?? 0
|
|
249
|
-
};
|
|
250
|
-
}), { updateSearch: s } = x();
|
|
251
|
-
return {
|
|
252
|
-
loadMore: g(async () => {
|
|
253
|
-
await s(Y({ from: r, size: t, pageSize: e }));
|
|
254
|
-
}, [r, t, e, s])
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
export {
|
|
258
|
-
se as a,
|
|
259
|
-
x as b,
|
|
260
|
-
Y as g,
|
|
261
|
-
H as u
|
|
262
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h=require("./storeContext-DVs7r6Qm.cjs"),i=require("preact/hooks"),q=require("./search-DJ_ktWg-.cjs"),g=require("./unique-BCAEb4ek.cjs"),p=require("./isEqual-DQXR__da.cjs"),y=require("./logger-DbHGgDgO.cjs");function A(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:N,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...T,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const N=["productId","url","name","imageUrl","imageHash","thumbUrl","description","brand","variantId","availability","price","priceText","categoryIds","categories","customFields.key","customFields.value","priceCurrencyCode","datePublished","listPrice","unitPricingBaseMeasure","unitPricingUnit","unitPricingMeasure","googleCategory","gtin","ageGroup","gender","condition","alternateImageUrls","ratingValue","reviewCount","inventoryLevel","skus.id","skus.name","skus.price","skus.listPrice","skus.priceText","skus.url","skus.imageUrl","skus.inventoryLevel","skus.customFields.key","skus.customFields.value","skus.availability","pid","onDiscount","extra.key","extra.value","saleable","available","tags1","tags2","tags3"],T=["keyword","_redirect"];function E(e,r,t){const s=JSON.stringify(r);try{y.logger.info("Setting storage",e,s),t.setItem(e,s)}catch(o){y.logger.warn(o)}}function Q(e,r){try{const t=r.getItem(e);if(t)return JSON.parse(t)}catch(t){y.logger.warn(t)}}function R(e,r){E(e,r,sessionStorage)}function U(e){return Q(e,sessionStorage)}const b="nosto:search:searchResult";function V(e,r,t){if(!e)return;R(b,{query:r,result:t})}function x(e,r){if(!e)return null;const t=U(b);if(!t||!K(t))return null;const s=w(t.query);return p.isEqual(w(r),s)?t.result:null}function w(e){return{accountId:e.accountId,customRules:e.customRules,explain:e.explain,keywords:e.keywords,products:e.products,query:e.query,redirect:e.redirect,rules:e.rules,segments:e.segments,sessionParams:e.sessionParams}}function K(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function P(e,r,t){var l,m,k;const s=g.measure("newSearch"),o=e.config.pageType,c=o==="search"?"serp":o,n=p.deepMerge(e.store.getInitialState().query,r),a=p.deepMerge(e.config.search,t,{track:c,redirect:o!=="autocomplete",isKeyword:!!(t!=null&&t.isKeyword)});e.store.updateState({query:n,loading:!0,initialized:!0});const u=o!=="autocomplete"&&e.config.persistentSearchCache,d=e.config.queryModifications({...n,products:{...n.products,filter:g.mergeArrays((m=(l=e.store.getInitialState().query)==null?void 0:l.products)==null?void 0:m.filter,(k=r.products)==null?void 0:k.filter)}},o);try{let f;const C=x(u,d);if(C)f=C;else{const M=A(o,d);f=await q.search(M,a),V(u,d,f)}e.store.updateState({response:f,loading:!1})}catch(f){y.logger.error("Search action failed",f)}s()}async function S(e,r,t){const s=g.measure("updateSearch"),o=p.deepMerge(e.store.getState().query,{products:{from:0}},r);await P(e,o,t),s()}async function L(e,r,t){var n;const s=g.measure("replaceFilter"),o=(n=e.store.getState().query.products)==null?void 0:n.filter,c=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await S(e,{products:{filter:[...(o==null?void 0:o.filter(a=>a.field!==r))??[],...c]}}),s()}async function O(e,r,t,s){var u,d;const o=g.measure("toggleProductFilter"),c=(u=e.store.getState().query.products)==null?void 0:u.filter,n=c==null?void 0:c.find(l=>l.value instanceof Array&&l.field===r),a=n!=null&&n.value?{...n,value:[...n.value.filter(l=>!p.isEqual(l,t)),...s?[t]:[]]}:s?{field:r,value:[t]}:void 0;await S(e,{products:{filter:[...(c==null?void 0:c.filter(l=>l!==n))??[],...(d=a==null?void 0:a.value)!=null&&d.length?[a]:[]]}}),o()}function F(){const e=h.useConfig(),r=i.useContext(h.StoreContext),t=i.useMemo(()=>({config:e,store:r}),[e,r]),s=i.useCallback((a,u)=>P(t,a,u),[t]),o=i.useCallback((a,u)=>S(t,a,u),[t]),c=i.useCallback((a,u,d)=>O(t,a,u,d),[t]),n=i.useCallback((a,u)=>L(t,a,u),[t]);return{newSearch:s,updateSearch:o,toggleProductFilter:c,replaceFilter:n}}function I(e=z){const r=i.useContext(h.StoreContext),[t,s]=i.useState(e(r.getState()));return r.onChange(e,s),i.useEffect(()=>()=>r.clearOnChange(s),[r]),t}const z=e=>e;function v({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function D(e=24){const{from:r,size:t}=I(c=>{var n,a;return{from:((n=c.query.products)==null?void 0:n.from)??0,size:((a=c.query.products)==null?void 0:a.size)??0}}),{updateSearch:s}=F();return{loadMore:i.useCallback(async()=>{await s(v({from:r,size:t,pageSize:e}))},[r,t,e,s])}}exports.getNextPageQuery=v;exports.useActions=F;exports.useLoadMore=D;exports.useNostoAppState=I;
|