@nosto/search-js 2.1.2 → 2.2.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-BC15p357.cjs → InfiniteScrollWithObserver-BOtsS3zB.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-DcV-Ny_9.js → InfiniteScrollWithObserver-D47sKLiT.js} +1 -1
- package/dist/preact/common.cjs.js +1 -1
- package/dist/preact/common.es.js +2 -2
- 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 +7 -7
- package/dist/preact/src/api/types.d.ts +1 -1
- package/dist/preact/src/config/pages/category/config.d.ts +0 -10
- package/dist/preact/src/config/pages/serp/config.d.ts +2 -2
- package/dist/thumbnails/thumbnails.cjs.js +1 -1
- package/dist/thumbnails/thumbnails.es.js +51 -51
- package/dist/useLoadMore-BbcvS5k5.js +261 -0
- package/dist/useLoadMore-VMNS8y7r.cjs +1 -0
- package/package.json +1 -1
- package/dist/useLoadMore-1PzDu__A.js +0 -261
- package/dist/useLoadMore-wwYzUkxk.cjs +0 -1
package/dist/{InfiniteScrollWithObserver-BC15p357.cjs → InfiniteScrollWithObserver-BOtsS3zB.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-VMNS8y7r.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-DcV-Ny_9.js → InfiniteScrollWithObserver-D47sKLiT.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-BbcvS5k5.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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-CGVAnKZy.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-CGVAnKZy.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../useLoadMore-VMNS8y7r.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-BOtsS3zB.cjs"),q=require("preact"),r=require("../storeContext-DVs7r6Qm.cjs");function b({pageSize:o}){const{loadMore:e}=s.useLoadMore(o);return t.u("button",{onClick:e,children:"More results"})}function u({children:o,loadMoreComponent:e,pageSize:i}){const{loading:c,query:l,response:a}=s.useNostoAppState(S=>p.pick(S,"loading","query","response")),d=!c&&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,8 +1,8 @@
|
|
|
1
1
|
import { i as l } from "../unique-Dwtu7vXB.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-BbcvS5k5.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-D47sKLiT.js";
|
|
6
6
|
import { Fragment as h } from "preact";
|
|
7
7
|
import { S as O, a as W, c as A, d as B } from "../storeContext-jWZFJ8Kf.js";
|
|
8
8
|
function M({ pageSize: e }) {
|
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-VMNS8y7r.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: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-BbcvS5k5.js";
|
|
2
|
+
import { a as Y } from "../useLoadMore-BbcvS5k5.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-BOtsS3zB.cjs"),r=require("../useLoadMore-VMNS8y7r.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-D47sKLiT.js";
|
|
2
|
+
import { g as s } from "../useLoadMore-BbcvS5k5.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 f=require("../index.es-DlUp67LT.cjs"),s=require("../storeContext-DVs7r6Qm.cjs"),S=require("../renderHeadless-xhkLegO4.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../index.es-DlUp67LT.cjs"),s=require("../storeContext-DVs7r6Qm.cjs"),S=require("../renderHeadless-xhkLegO4.cjs"),a=require("../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../baseConfig-DEAGSRSp.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&&f.s(p=>p.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
|
@@ -7,14 +7,14 @@ const h = "nosto:search:scrollPos";
|
|
|
7
7
|
function P() {
|
|
8
8
|
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
9
9
|
}
|
|
10
|
-
function B({ children: e, hit:
|
|
11
|
-
const { pageType:
|
|
10
|
+
function B({ children: e, hit: o, onClick: t }) {
|
|
11
|
+
const { pageType: r } = f(), a = r === "autocomplete" ? void 0 : r === "search" ? "serp" : r;
|
|
12
12
|
return g({
|
|
13
13
|
children: e,
|
|
14
14
|
updateElement: (s, c) => (c.depth > 0 || (s.props = {
|
|
15
15
|
...s.props,
|
|
16
16
|
onClick: (i) => {
|
|
17
|
-
|
|
17
|
+
o && a && l((p) => p.recordSearchClick(a, o)), P(), typeof t == "function" && t(i);
|
|
18
18
|
}
|
|
19
19
|
}), s)
|
|
20
20
|
});
|
|
@@ -26,14 +26,14 @@ const k = {
|
|
|
26
26
|
};
|
|
27
27
|
function w(e = {}) {
|
|
28
28
|
return {
|
|
29
|
-
pageType: "
|
|
29
|
+
pageType: "search",
|
|
30
30
|
...k,
|
|
31
31
|
...e
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
function H({ config: e, store:
|
|
35
|
-
const
|
|
36
|
-
return d(), /* @__PURE__ */ n(m, { value: w(e), children: /* @__PURE__ */ n(S, { value:
|
|
34
|
+
function H({ config: e, store: o, children: t }) {
|
|
35
|
+
const r = o ?? u();
|
|
36
|
+
return d(), /* @__PURE__ */ n(m, { value: w(e), children: /* @__PURE__ */ n(S, { value: r, children: t }) });
|
|
37
37
|
}
|
|
38
38
|
export {
|
|
39
39
|
H as SearchPageProvider,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
2
|
-
export type PageType = "
|
|
2
|
+
export type PageType = "search" | "category" | "autocomplete";
|
|
3
3
|
export type MaybeProvider<T> = T | (() => T);
|
|
4
4
|
export type QueryProvider = MaybeProvider<Partial<SearchQuery>>;
|
|
@@ -7,14 +7,6 @@ export declare const defaultCategoryConfig: {
|
|
|
7
7
|
};
|
|
8
8
|
export interface CategoryConfig extends BaseConfig {
|
|
9
9
|
pageType: "category";
|
|
10
|
-
/**
|
|
11
|
-
* returns current category id
|
|
12
|
-
*/
|
|
13
|
-
categoryId: () => string;
|
|
14
|
-
/**
|
|
15
|
-
* returns current category path
|
|
16
|
-
*/
|
|
17
|
-
categoryPath: () => string;
|
|
18
10
|
/**
|
|
19
11
|
* Enable persistent caching for search results.
|
|
20
12
|
*
|
|
@@ -34,8 +26,6 @@ export interface CategoryConfig extends BaseConfig {
|
|
|
34
26
|
export type PublicCategoryConfig = Omit<CategoryConfig, keyof typeof defaultCategoryConfig | "pageType"> & Partial<Pick<CategoryConfig, keyof typeof defaultCategoryConfig>>;
|
|
35
27
|
export declare function makeCategoryConfig(config: PublicCategoryConfig): {
|
|
36
28
|
search?: import('../../../../../core/src/types').SearchOptions | undefined;
|
|
37
|
-
categoryId: () => string;
|
|
38
|
-
categoryPath: () => string;
|
|
39
29
|
defaultCurrency: string;
|
|
40
30
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
|
|
41
31
|
persistentSearchCache: boolean;
|
|
@@ -6,7 +6,7 @@ export declare const defaultSerpConfig: {
|
|
|
6
6
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery) => import('@nosto/nosto-js/client').SearchQuery;
|
|
7
7
|
};
|
|
8
8
|
export interface SerpConfig extends BaseConfig {
|
|
9
|
-
pageType: "
|
|
9
|
+
pageType: "search";
|
|
10
10
|
/**
|
|
11
11
|
* Enable persistent caching for search results.
|
|
12
12
|
*
|
|
@@ -30,5 +30,5 @@ export declare function makeSerpConfig(config?: PublicSerpConfig): {
|
|
|
30
30
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
|
|
31
31
|
persistentSearchCache: boolean;
|
|
32
32
|
preservePageScroll: boolean;
|
|
33
|
-
pageType: "
|
|
33
|
+
pageType: "search";
|
|
34
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs");function s({size:e,productId:a,hash:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs");function s({size:e,productId:a,hash:c}){const u=p.i();if(!u)throw new Error("Client script settings are not yet available");return`https://${u.thumbnailHost}/${u.account}/${e}/${a}/${c}/A`}function l({size:e}){function a(i,r){if(r)return s({size:e,productId:i,hash:r})}function c(i,r){if(r)return r.map(t=>({...t,imageUrl:a(i,t.imageHash)??t.imageUrl}))}function u(i,r,t){if(!t)return r;if(r)return t.map(n=>s({size:e,productId:i,hash:n}))}return function(r){const t=r.productId;return t?{...r,imageUrl:a(t,r.imageHash)??r.imageUrl,thumbUrl:a(t,r.thumbHash)??r.thumbUrl,skus:c(t,r.skus),alternateImageUrls:u(t,r.alternateImageUrls,r.alternateImageHashes)}:r}}const g=/cdn\.shopify\.com/,m={1:"170x170",2:"100x100",3:"90x70",4:"50x50",5:"30x30",6:"100x140",7:"200x200",8:"400x400",9:"750x750"};function U(e){return e in m}function f({size:e,fallback:a=c=>c}){if(e==="orig")return a;const c=m[e]||e;function u(n){return n?new URL(n).hostname.match(g):!1}function i(n){return n?u(n)?n.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/,`_${c}$1`):n:""}function r(n){if(n)return n.map(o=>({...o,imageUrl:i(o.imageUrl)}))}function t(n){if(n)return n.map(o=>i(o))}return function(o){return u(o.imageUrl)?{...o,imageUrl:i(o.imageUrl),thumbUrl:i(o.thumbUrl),skus:r(o.skus),alternateImageUrls:t(o.alternateImageUrls)}:a(o)}}function d(){var e;return(e=window.Nosto)==null?void 0:e.shopifyScript}function b({size:e}){const a=l({size:e});return d()&&U(e)?f({size:e,fallback:a}):a}exports.generateThumbnailUrl=s;exports.nostoThumbnailDecorator=l;exports.shopifyThumbnailDecorator=f;exports.thumbnailDecorator=b;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { i as m } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
function s({ size:
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
2
|
+
function s({ size: n, productId: a, hash: c }) {
|
|
3
|
+
const i = m();
|
|
4
|
+
if (!i)
|
|
5
5
|
throw new Error("Client script settings are not yet available");
|
|
6
|
-
return `https://${
|
|
6
|
+
return `https://${i.thumbnailHost}/${i.account}/${n}/${a}/${c}/A`;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
function a(
|
|
8
|
+
function l({ size: n }) {
|
|
9
|
+
function a(u, r) {
|
|
10
10
|
if (r)
|
|
11
11
|
return s({
|
|
12
|
-
size:
|
|
13
|
-
productId:
|
|
12
|
+
size: n,
|
|
13
|
+
productId: u,
|
|
14
14
|
hash: r
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function c(u, r) {
|
|
18
18
|
if (r)
|
|
19
19
|
return r.map((t) => ({
|
|
20
20
|
...t,
|
|
21
|
-
imageUrl: a(
|
|
21
|
+
imageUrl: a(u, t.imageHash) ?? t.imageUrl
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
24
|
-
function u
|
|
24
|
+
function i(u, r, t) {
|
|
25
25
|
if (!t)
|
|
26
26
|
return r;
|
|
27
27
|
if (r)
|
|
28
28
|
return t.map(
|
|
29
|
-
(
|
|
30
|
-
size:
|
|
31
|
-
productId:
|
|
32
|
-
hash:
|
|
29
|
+
(e) => s({
|
|
30
|
+
size: n,
|
|
31
|
+
productId: u,
|
|
32
|
+
hash: e
|
|
33
33
|
})
|
|
34
34
|
);
|
|
35
35
|
}
|
|
@@ -39,67 +39,67 @@ function p({ size: e }) {
|
|
|
39
39
|
...r,
|
|
40
40
|
imageUrl: a(t, r.imageHash) ?? r.imageUrl,
|
|
41
41
|
thumbUrl: a(t, r.thumbHash) ?? r.thumbUrl,
|
|
42
|
-
skus:
|
|
43
|
-
alternateImageUrls:
|
|
42
|
+
skus: c(t, r.skus),
|
|
43
|
+
alternateImageUrls: i(t, r.alternateImageUrls, r.alternateImageHashes)
|
|
44
44
|
} : r;
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
1: "
|
|
49
|
-
2: "
|
|
50
|
-
3: "
|
|
51
|
-
4: "
|
|
52
|
-
5: "
|
|
53
|
-
6: "
|
|
54
|
-
7: "
|
|
47
|
+
const p = /cdn\.shopify\.com/, f = {
|
|
48
|
+
1: "170x170",
|
|
49
|
+
2: "100x100",
|
|
50
|
+
3: "90x70",
|
|
51
|
+
4: "50x50",
|
|
52
|
+
5: "30x30",
|
|
53
|
+
6: "100x140",
|
|
54
|
+
7: "200x200",
|
|
55
55
|
8: "400x400",
|
|
56
56
|
9: "750x750"
|
|
57
57
|
};
|
|
58
|
-
function g(
|
|
59
|
-
return
|
|
58
|
+
function g(n) {
|
|
59
|
+
return n in f;
|
|
60
60
|
}
|
|
61
|
-
function U({ size:
|
|
62
|
-
if (
|
|
61
|
+
function U({ size: n, fallback: a = (c) => c }) {
|
|
62
|
+
if (n === "orig")
|
|
63
63
|
return a;
|
|
64
|
-
const
|
|
65
|
-
function
|
|
66
|
-
return
|
|
64
|
+
const c = f[n] || n;
|
|
65
|
+
function i(e) {
|
|
66
|
+
return e ? new URL(e).hostname.match(p) : !1;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
return
|
|
68
|
+
function u(e) {
|
|
69
|
+
return e ? i(e) ? e.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/, `_${c}$1`) : e : "";
|
|
70
70
|
}
|
|
71
|
-
function r(
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
71
|
+
function r(e) {
|
|
72
|
+
if (e)
|
|
73
|
+
return e.map((o) => ({
|
|
74
74
|
...o,
|
|
75
|
-
imageUrl:
|
|
75
|
+
imageUrl: u(o.imageUrl)
|
|
76
76
|
}));
|
|
77
77
|
}
|
|
78
|
-
function t(
|
|
79
|
-
if (
|
|
80
|
-
return
|
|
78
|
+
function t(e) {
|
|
79
|
+
if (e)
|
|
80
|
+
return e.map((o) => u(o));
|
|
81
81
|
}
|
|
82
82
|
return function(o) {
|
|
83
|
-
return
|
|
83
|
+
return i(o.imageUrl) ? {
|
|
84
84
|
...o,
|
|
85
|
-
imageUrl:
|
|
86
|
-
thumbUrl:
|
|
85
|
+
imageUrl: u(o.imageUrl),
|
|
86
|
+
thumbUrl: u(o.thumbUrl),
|
|
87
87
|
skus: r(o.skus),
|
|
88
88
|
alternateImageUrls: t(o.alternateImageUrls)
|
|
89
89
|
} : a(o);
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
function d() {
|
|
93
|
-
var
|
|
94
|
-
return (
|
|
93
|
+
var n;
|
|
94
|
+
return (n = window.Nosto) == null ? void 0 : n.shopifyScript;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const a =
|
|
98
|
-
return d() && g(
|
|
96
|
+
function x({ size: n }) {
|
|
97
|
+
const a = l({ size: n });
|
|
98
|
+
return d() && g(n) ? U({ size: n, fallback: a }) : a;
|
|
99
99
|
}
|
|
100
100
|
export {
|
|
101
101
|
s as generateThumbnailUrl,
|
|
102
|
-
|
|
102
|
+
l as nostoThumbnailDecorator,
|
|
103
103
|
U as shopifyThumbnailDecorator,
|
|
104
|
-
|
|
104
|
+
x as thumbnailDecorator
|
|
105
105
|
};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { u as v, S as w } from "./storeContext-jWZFJ8Kf.js";
|
|
2
|
+
import { useContext as C, useMemo as M, useCallback as g, useState as T, useEffect as A } from "preact/hooks";
|
|
3
|
+
import { s as R } from "./search-B0-bVNMy.js";
|
|
4
|
+
import { u as N, a as f, m as Q, i as E } from "./unique-Dwtu7vXB.js";
|
|
5
|
+
import { i as b, d as p } from "./isEqual-BzZ3d1JM.js";
|
|
6
|
+
function U(e, r) {
|
|
7
|
+
return {
|
|
8
|
+
...r,
|
|
9
|
+
products: {
|
|
10
|
+
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
11
|
+
fields: V,
|
|
12
|
+
...r.products
|
|
13
|
+
},
|
|
14
|
+
...r.keywords ? {
|
|
15
|
+
keywords: {
|
|
16
|
+
...r.keywords,
|
|
17
|
+
fields: N([...K, ...r.keywords.fields ?? []]),
|
|
18
|
+
highlight: r.keywords.highlight ?? {
|
|
19
|
+
preTag: "<strong>",
|
|
20
|
+
postTag: "</strong>"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const V = [
|
|
27
|
+
"productId",
|
|
28
|
+
"url",
|
|
29
|
+
"name",
|
|
30
|
+
"imageUrl",
|
|
31
|
+
"imageHash",
|
|
32
|
+
"thumbUrl",
|
|
33
|
+
"description",
|
|
34
|
+
"brand",
|
|
35
|
+
"variantId",
|
|
36
|
+
"availability",
|
|
37
|
+
"price",
|
|
38
|
+
"priceText",
|
|
39
|
+
"categoryIds",
|
|
40
|
+
"categories",
|
|
41
|
+
"customFields.key",
|
|
42
|
+
"customFields.value",
|
|
43
|
+
"priceCurrencyCode",
|
|
44
|
+
"datePublished",
|
|
45
|
+
"listPrice",
|
|
46
|
+
"unitPricingBaseMeasure",
|
|
47
|
+
"unitPricingUnit",
|
|
48
|
+
"unitPricingMeasure",
|
|
49
|
+
"googleCategory",
|
|
50
|
+
"gtin",
|
|
51
|
+
"ageGroup",
|
|
52
|
+
"gender",
|
|
53
|
+
"condition",
|
|
54
|
+
"alternateImageUrls",
|
|
55
|
+
"ratingValue",
|
|
56
|
+
"reviewCount",
|
|
57
|
+
"inventoryLevel",
|
|
58
|
+
"skus.id",
|
|
59
|
+
"skus.name",
|
|
60
|
+
"skus.price",
|
|
61
|
+
"skus.listPrice",
|
|
62
|
+
"skus.priceText",
|
|
63
|
+
"skus.url",
|
|
64
|
+
"skus.imageUrl",
|
|
65
|
+
"skus.inventoryLevel",
|
|
66
|
+
"skus.customFields.key",
|
|
67
|
+
"skus.customFields.value",
|
|
68
|
+
"skus.availability",
|
|
69
|
+
"pid",
|
|
70
|
+
"onDiscount",
|
|
71
|
+
"extra.key",
|
|
72
|
+
"extra.value",
|
|
73
|
+
"saleable",
|
|
74
|
+
"available",
|
|
75
|
+
"tags1",
|
|
76
|
+
"tags2",
|
|
77
|
+
"tags3"
|
|
78
|
+
], K = ["keyword", "_redirect"];
|
|
79
|
+
function O(e, r, t) {
|
|
80
|
+
const s = JSON.stringify(r);
|
|
81
|
+
try {
|
|
82
|
+
console.info("Setting storage", e, s), t.setItem(e, s);
|
|
83
|
+
} catch (o) {
|
|
84
|
+
console.warn(o);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function z(e, r) {
|
|
88
|
+
try {
|
|
89
|
+
const t = r.getItem(e);
|
|
90
|
+
if (t)
|
|
91
|
+
return JSON.parse(t);
|
|
92
|
+
} catch (t) {
|
|
93
|
+
console.warn(t);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function D(e, r) {
|
|
97
|
+
O(e, r, sessionStorage);
|
|
98
|
+
}
|
|
99
|
+
function L(e) {
|
|
100
|
+
return z(e, sessionStorage);
|
|
101
|
+
}
|
|
102
|
+
const P = "nosto:search:searchResult";
|
|
103
|
+
function _(e, r, t) {
|
|
104
|
+
if (!e)
|
|
105
|
+
return;
|
|
106
|
+
D(P, { query: r, result: t });
|
|
107
|
+
}
|
|
108
|
+
function j(e, r) {
|
|
109
|
+
if (!e)
|
|
110
|
+
return null;
|
|
111
|
+
const t = L(P);
|
|
112
|
+
if (!t || !B(t))
|
|
113
|
+
return null;
|
|
114
|
+
const s = k(t.query);
|
|
115
|
+
return b(k(r), s) ? t.result : null;
|
|
116
|
+
}
|
|
117
|
+
function k(e) {
|
|
118
|
+
return {
|
|
119
|
+
accountId: e.accountId,
|
|
120
|
+
customRules: e.customRules,
|
|
121
|
+
explain: e.explain,
|
|
122
|
+
keywords: e.keywords,
|
|
123
|
+
products: e.products,
|
|
124
|
+
query: e.query,
|
|
125
|
+
redirect: e.redirect,
|
|
126
|
+
rules: e.rules,
|
|
127
|
+
segments: e.segments,
|
|
128
|
+
sessionParams: e.sessionParams
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function B(e) {
|
|
132
|
+
return typeof e == "object" && e !== null && "query" in e && "result" in e;
|
|
133
|
+
}
|
|
134
|
+
async function F(e, r, t) {
|
|
135
|
+
var u, y, h;
|
|
136
|
+
const s = f("newSearch"), o = e.config.pageType, c = o === "search" ? "serp" : o, n = p(e.store.getInitialState().query, r), a = p(e.config.search, t, {
|
|
137
|
+
track: c,
|
|
138
|
+
redirect: o !== "autocomplete",
|
|
139
|
+
isKeyword: !!(t != null && t.isKeyword)
|
|
140
|
+
});
|
|
141
|
+
e.store.updateState({
|
|
142
|
+
query: n,
|
|
143
|
+
loading: !0,
|
|
144
|
+
initialized: !0
|
|
145
|
+
});
|
|
146
|
+
const i = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
|
|
147
|
+
{
|
|
148
|
+
...n,
|
|
149
|
+
products: {
|
|
150
|
+
...n.products,
|
|
151
|
+
// Apply filter merging to avoid overwriting base filters
|
|
152
|
+
filter: Q((y = (u = e.store.getInitialState().query) == null ? void 0 : u.products) == null ? void 0 : y.filter, (h = r.products) == null ? void 0 : h.filter)
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
o
|
|
156
|
+
);
|
|
157
|
+
try {
|
|
158
|
+
let d;
|
|
159
|
+
const S = j(i, l);
|
|
160
|
+
if (S)
|
|
161
|
+
d = S;
|
|
162
|
+
else {
|
|
163
|
+
const I = U(o, l);
|
|
164
|
+
d = await R(I, a), _(i, l, d);
|
|
165
|
+
}
|
|
166
|
+
e.store.updateState({
|
|
167
|
+
response: d,
|
|
168
|
+
loading: !1
|
|
169
|
+
});
|
|
170
|
+
} catch (d) {
|
|
171
|
+
console.error("Search action failed", d);
|
|
172
|
+
}
|
|
173
|
+
s();
|
|
174
|
+
}
|
|
175
|
+
async function m(e, r, t) {
|
|
176
|
+
const s = f("updateSearch"), o = p(e.store.getState().query, { products: { from: 0 } }, r);
|
|
177
|
+
await F(e, o, t), s();
|
|
178
|
+
}
|
|
179
|
+
async function G(e, r, t) {
|
|
180
|
+
var n;
|
|
181
|
+
const s = f("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] }] : [];
|
|
182
|
+
await m(e, {
|
|
183
|
+
products: {
|
|
184
|
+
filter: [...(o == null ? void 0 : o.filter((a) => a.field !== r)) ?? [], ...c]
|
|
185
|
+
}
|
|
186
|
+
}), s();
|
|
187
|
+
}
|
|
188
|
+
async function J(e, r, t, s) {
|
|
189
|
+
var i, l;
|
|
190
|
+
const o = f("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 ? {
|
|
191
|
+
...n,
|
|
192
|
+
value: [...n.value.filter((u) => !b(u, t)), ...s ? [t] : []]
|
|
193
|
+
} : s ? {
|
|
194
|
+
field: r,
|
|
195
|
+
value: [t]
|
|
196
|
+
} : void 0;
|
|
197
|
+
await m(e, {
|
|
198
|
+
products: {
|
|
199
|
+
filter: [...(c == null ? void 0 : c.filter((u) => u !== n)) ?? [], ...(l = a == null ? void 0 : a.value) != null && l.length ? [a] : []]
|
|
200
|
+
}
|
|
201
|
+
}), o();
|
|
202
|
+
}
|
|
203
|
+
function q() {
|
|
204
|
+
const e = v(), r = C(w), t = M(
|
|
205
|
+
() => ({
|
|
206
|
+
config: e,
|
|
207
|
+
store: r
|
|
208
|
+
}),
|
|
209
|
+
[e, r]
|
|
210
|
+
), s = g(
|
|
211
|
+
(a, i) => F(t, a, i),
|
|
212
|
+
[t]
|
|
213
|
+
), o = g(
|
|
214
|
+
(a, i) => m(t, a, i),
|
|
215
|
+
[t]
|
|
216
|
+
), c = g(
|
|
217
|
+
(a, i, l) => J(t, a, i, l),
|
|
218
|
+
[t]
|
|
219
|
+
), n = g(
|
|
220
|
+
(a, i) => G(t, a, i),
|
|
221
|
+
[t]
|
|
222
|
+
);
|
|
223
|
+
return {
|
|
224
|
+
newSearch: s,
|
|
225
|
+
updateSearch: o,
|
|
226
|
+
toggleProductFilter: c,
|
|
227
|
+
replaceFilter: n
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function x(e = H) {
|
|
231
|
+
const r = C(w), [t, s] = T(e(r.getState()));
|
|
232
|
+
return r.onChange(e, s), A(() => () => r.clearOnChange(s), [r]), t;
|
|
233
|
+
}
|
|
234
|
+
const H = (e) => e;
|
|
235
|
+
function W({ from: e, size: r, pageSize: t }) {
|
|
236
|
+
return E() ? {
|
|
237
|
+
products: { from: e + t }
|
|
238
|
+
} : {
|
|
239
|
+
products: { size: r + t }
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function te(e = 24) {
|
|
243
|
+
const { from: r, size: t } = x((c) => {
|
|
244
|
+
var n, a;
|
|
245
|
+
return {
|
|
246
|
+
from: ((n = c.query.products) == null ? void 0 : n.from) ?? 0,
|
|
247
|
+
size: ((a = c.query.products) == null ? void 0 : a.size) ?? 0
|
|
248
|
+
};
|
|
249
|
+
}), { updateSearch: s } = q();
|
|
250
|
+
return {
|
|
251
|
+
loadMore: g(async () => {
|
|
252
|
+
await s(W({ from: r, size: t, pageSize: e }));
|
|
253
|
+
}, [r, t, e, s])
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export {
|
|
257
|
+
te as a,
|
|
258
|
+
q as b,
|
|
259
|
+
W as g,
|
|
260
|
+
x as u
|
|
261
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const y=require("./storeContext-DVs7r6Qm.cjs"),i=require("preact/hooks"),M=require("./search-BVJZK90N.cjs"),g=require("./unique-CGVAnKZy.cjs"),p=require("./isEqual-DQXR__da.cjs");function q(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:A,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...N,...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"],N=["keyword","_redirect"];function T(e,r,t){const s=JSON.stringify(r);try{console.info("Setting storage",e,s),t.setItem(e,s)}catch(o){console.warn(o)}}function E(e,r){try{const t=r.getItem(e);if(t)return JSON.parse(t)}catch(t){console.warn(t)}}function Q(e,r){T(e,r,sessionStorage)}function R(e){return E(e,sessionStorage)}const w="nosto:search:searchResult";function U(e,r,t){if(!e)return;Q(w,{query:r,result:t})}function V(e,r){if(!e)return null;const t=R(w);if(!t||!x(t))return null;const s=C(t.query);return p.isEqual(C(r),s)?t.result:null}function C(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 x(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function b(e,r,t){var l,S,m;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((S=(l=e.store.getInitialState().query)==null?void 0:l.products)==null?void 0:S.filter,(m=r.products)==null?void 0:m.filter)}},o);try{let f;const k=V(u,d);if(k)f=k;else{const v=q(o,d);f=await M.search(v,a),U(u,d,f)}e.store.updateState({response:f,loading:!1})}catch(f){console.error("Search action failed",f)}s()}async function h(e,r,t){const s=g.measure("updateSearch"),o=p.deepMerge(e.store.getState().query,{products:{from:0}},r);await b(e,o,t),s()}async function K(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 h(e,{products:{filter:[...(o==null?void 0:o.filter(a=>a.field!==r))??[],...c]}}),s()}async function L(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 h(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 P(){const e=y.useConfig(),r=i.useContext(y.StoreContext),t=i.useMemo(()=>({config:e,store:r}),[e,r]),s=i.useCallback((a,u)=>b(t,a,u),[t]),o=i.useCallback((a,u)=>h(t,a,u),[t]),c=i.useCallback((a,u,d)=>L(t,a,u,d),[t]),n=i.useCallback((a,u)=>K(t,a,u),[t]);return{newSearch:s,updateSearch:o,toggleProductFilter:c,replaceFilter:n}}function F(e=O){const r=i.useContext(y.StoreContext),[t,s]=i.useState(e(r.getState()));return r.onChange(e,s),i.useEffect(()=>()=>r.clearOnChange(s),[r]),t}const O=e=>e;function I({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function z(e=24){const{from:r,size:t}=F(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}=P();return{loadMore:i.useCallback(async()=>{await s(I({from:r,size:t,pageSize:e}))},[r,t,e,s])}}exports.getNextPageQuery=I;exports.useActions=P;exports.useLoadMore=z;exports.useNostoAppState=F;
|
package/package.json
CHANGED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { u as I, S as k } from "./storeContext-jWZFJ8Kf.js";
|
|
2
|
-
import { useContext as w, useMemo as v, useCallback as g, useState as M, useEffect as T } from "preact/hooks";
|
|
3
|
-
import { s as A } from "./search-B0-bVNMy.js";
|
|
4
|
-
import { u as R, a as f, m as N, i as Q } from "./unique-Dwtu7vXB.js";
|
|
5
|
-
import { i as C, d as p } from "./isEqual-BzZ3d1JM.js";
|
|
6
|
-
function E(e, r) {
|
|
7
|
-
return {
|
|
8
|
-
...r,
|
|
9
|
-
products: {
|
|
10
|
-
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
11
|
-
fields: U,
|
|
12
|
-
...r.products
|
|
13
|
-
},
|
|
14
|
-
...r.keywords ? {
|
|
15
|
-
keywords: {
|
|
16
|
-
...r.keywords,
|
|
17
|
-
fields: R([...V, ...r.keywords.fields ?? []]),
|
|
18
|
-
highlight: r.keywords.highlight ?? {
|
|
19
|
-
preTag: "<strong>",
|
|
20
|
-
postTag: "</strong>"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
} : {}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const U = [
|
|
27
|
-
"productId",
|
|
28
|
-
"url",
|
|
29
|
-
"name",
|
|
30
|
-
"imageUrl",
|
|
31
|
-
"imageHash",
|
|
32
|
-
"thumbUrl",
|
|
33
|
-
"description",
|
|
34
|
-
"brand",
|
|
35
|
-
"variantId",
|
|
36
|
-
"availability",
|
|
37
|
-
"price",
|
|
38
|
-
"priceText",
|
|
39
|
-
"categoryIds",
|
|
40
|
-
"categories",
|
|
41
|
-
"customFields.key",
|
|
42
|
-
"customFields.value",
|
|
43
|
-
"priceCurrencyCode",
|
|
44
|
-
"datePublished",
|
|
45
|
-
"listPrice",
|
|
46
|
-
"unitPricingBaseMeasure",
|
|
47
|
-
"unitPricingUnit",
|
|
48
|
-
"unitPricingMeasure",
|
|
49
|
-
"googleCategory",
|
|
50
|
-
"gtin",
|
|
51
|
-
"ageGroup",
|
|
52
|
-
"gender",
|
|
53
|
-
"condition",
|
|
54
|
-
"alternateImageUrls",
|
|
55
|
-
"ratingValue",
|
|
56
|
-
"reviewCount",
|
|
57
|
-
"inventoryLevel",
|
|
58
|
-
"skus.id",
|
|
59
|
-
"skus.name",
|
|
60
|
-
"skus.price",
|
|
61
|
-
"skus.listPrice",
|
|
62
|
-
"skus.priceText",
|
|
63
|
-
"skus.url",
|
|
64
|
-
"skus.imageUrl",
|
|
65
|
-
"skus.inventoryLevel",
|
|
66
|
-
"skus.customFields.key",
|
|
67
|
-
"skus.customFields.value",
|
|
68
|
-
"skus.availability",
|
|
69
|
-
"pid",
|
|
70
|
-
"onDiscount",
|
|
71
|
-
"extra.key",
|
|
72
|
-
"extra.value",
|
|
73
|
-
"saleable",
|
|
74
|
-
"available",
|
|
75
|
-
"tags1",
|
|
76
|
-
"tags2",
|
|
77
|
-
"tags3"
|
|
78
|
-
], V = ["keyword", "_redirect"];
|
|
79
|
-
function K(e, r, t) {
|
|
80
|
-
const s = JSON.stringify(r);
|
|
81
|
-
try {
|
|
82
|
-
console.info("Setting storage", e, s), t.setItem(e, s);
|
|
83
|
-
} catch (a) {
|
|
84
|
-
console.warn(a);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function O(e, r) {
|
|
88
|
-
try {
|
|
89
|
-
const t = r.getItem(e);
|
|
90
|
-
if (t)
|
|
91
|
-
return JSON.parse(t);
|
|
92
|
-
} catch (t) {
|
|
93
|
-
console.warn(t);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function z(e, r) {
|
|
97
|
-
K(e, r, sessionStorage);
|
|
98
|
-
}
|
|
99
|
-
function D(e) {
|
|
100
|
-
return O(e, sessionStorage);
|
|
101
|
-
}
|
|
102
|
-
const b = "nosto:search:searchResult";
|
|
103
|
-
function L(e, r, t) {
|
|
104
|
-
if (!e)
|
|
105
|
-
return;
|
|
106
|
-
z(b, { query: r, result: t });
|
|
107
|
-
}
|
|
108
|
-
function _(e, r) {
|
|
109
|
-
if (!e)
|
|
110
|
-
return null;
|
|
111
|
-
const t = D(b);
|
|
112
|
-
if (!t || !j(t))
|
|
113
|
-
return null;
|
|
114
|
-
const s = S(t.query);
|
|
115
|
-
return C(S(r), s) ? t.result : null;
|
|
116
|
-
}
|
|
117
|
-
function S(e) {
|
|
118
|
-
return {
|
|
119
|
-
accountId: e.accountId,
|
|
120
|
-
customRules: e.customRules,
|
|
121
|
-
explain: e.explain,
|
|
122
|
-
keywords: e.keywords,
|
|
123
|
-
products: e.products,
|
|
124
|
-
query: e.query,
|
|
125
|
-
redirect: e.redirect,
|
|
126
|
-
rules: e.rules,
|
|
127
|
-
segments: e.segments,
|
|
128
|
-
sessionParams: e.sessionParams
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function j(e) {
|
|
132
|
-
return typeof e == "object" && e !== null && "query" in e && "result" in e;
|
|
133
|
-
}
|
|
134
|
-
async function P(e, r, t) {
|
|
135
|
-
var l, u, y;
|
|
136
|
-
const s = f("newSearch"), a = e.config.pageType, n = p(e.store.getInitialState().query, r), c = p(e.config.search, t, {
|
|
137
|
-
track: a,
|
|
138
|
-
redirect: a !== "autocomplete",
|
|
139
|
-
isKeyword: !!(t != null && t.isKeyword)
|
|
140
|
-
});
|
|
141
|
-
e.store.updateState({
|
|
142
|
-
query: n,
|
|
143
|
-
loading: !0,
|
|
144
|
-
initialized: !0
|
|
145
|
-
});
|
|
146
|
-
const o = a !== "autocomplete" && e.config.persistentSearchCache, i = e.config.queryModifications(
|
|
147
|
-
{
|
|
148
|
-
...n,
|
|
149
|
-
products: {
|
|
150
|
-
...n.products,
|
|
151
|
-
// Apply filter merging to avoid overwriting base filters
|
|
152
|
-
filter: N((u = (l = e.store.getInitialState().query) == null ? void 0 : l.products) == null ? void 0 : u.filter, (y = r.products) == null ? void 0 : y.filter)
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
a
|
|
156
|
-
);
|
|
157
|
-
try {
|
|
158
|
-
let d;
|
|
159
|
-
const h = _(o, i);
|
|
160
|
-
if (h)
|
|
161
|
-
d = h;
|
|
162
|
-
else {
|
|
163
|
-
const F = E(a, i);
|
|
164
|
-
d = await A(F, c), L(o, i, d);
|
|
165
|
-
}
|
|
166
|
-
e.store.updateState({
|
|
167
|
-
response: d,
|
|
168
|
-
loading: !1
|
|
169
|
-
});
|
|
170
|
-
} catch (d) {
|
|
171
|
-
console.error("Search action failed", d);
|
|
172
|
-
}
|
|
173
|
-
s();
|
|
174
|
-
}
|
|
175
|
-
async function m(e, r, t) {
|
|
176
|
-
const s = f("updateSearch"), a = p(e.store.getState().query, { products: { from: 0 } }, r);
|
|
177
|
-
await P(e, a, t), s();
|
|
178
|
-
}
|
|
179
|
-
async function B(e, r, t) {
|
|
180
|
-
var c;
|
|
181
|
-
const s = f("replaceFilter"), a = (c = e.store.getState().query.products) == null ? void 0 : c.filter, n = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
182
|
-
await m(e, {
|
|
183
|
-
products: {
|
|
184
|
-
filter: [...(a == null ? void 0 : a.filter((o) => o.field !== r)) ?? [], ...n]
|
|
185
|
-
}
|
|
186
|
-
}), s();
|
|
187
|
-
}
|
|
188
|
-
async function G(e, r, t, s) {
|
|
189
|
-
var i, l;
|
|
190
|
-
const a = f("toggleProductFilter"), n = (i = e.store.getState().query.products) == null ? void 0 : i.filter, c = n == null ? void 0 : n.find((u) => u.value instanceof Array && u.field === r), o = c != null && c.value ? {
|
|
191
|
-
...c,
|
|
192
|
-
value: [...c.value.filter((u) => !C(u, t)), ...s ? [t] : []]
|
|
193
|
-
} : s ? {
|
|
194
|
-
field: r,
|
|
195
|
-
value: [t]
|
|
196
|
-
} : void 0;
|
|
197
|
-
await m(e, {
|
|
198
|
-
products: {
|
|
199
|
-
filter: [...(n == null ? void 0 : n.filter((u) => u !== c)) ?? [], ...(l = o == null ? void 0 : o.value) != null && l.length ? [o] : []]
|
|
200
|
-
}
|
|
201
|
-
}), a();
|
|
202
|
-
}
|
|
203
|
-
function J() {
|
|
204
|
-
const e = I(), r = w(k), t = v(
|
|
205
|
-
() => ({
|
|
206
|
-
config: e,
|
|
207
|
-
store: r
|
|
208
|
-
}),
|
|
209
|
-
[e, r]
|
|
210
|
-
), s = g(
|
|
211
|
-
(o, i) => P(t, o, i),
|
|
212
|
-
[t]
|
|
213
|
-
), a = g(
|
|
214
|
-
(o, i) => m(t, o, i),
|
|
215
|
-
[t]
|
|
216
|
-
), n = g(
|
|
217
|
-
(o, i, l) => G(t, o, i, l),
|
|
218
|
-
[t]
|
|
219
|
-
), c = g(
|
|
220
|
-
(o, i) => B(t, o, i),
|
|
221
|
-
[t]
|
|
222
|
-
);
|
|
223
|
-
return {
|
|
224
|
-
newSearch: s,
|
|
225
|
-
updateSearch: a,
|
|
226
|
-
toggleProductFilter: n,
|
|
227
|
-
replaceFilter: c
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function q(e = x) {
|
|
231
|
-
const r = w(k), [t, s] = M(e(r.getState()));
|
|
232
|
-
return r.onChange(e, s), T(() => () => r.clearOnChange(s), [r]), t;
|
|
233
|
-
}
|
|
234
|
-
const x = (e) => e;
|
|
235
|
-
function H({ from: e, size: r, pageSize: t }) {
|
|
236
|
-
return Q() ? {
|
|
237
|
-
products: { from: e + t }
|
|
238
|
-
} : {
|
|
239
|
-
products: { size: r + t }
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function ee(e = 24) {
|
|
243
|
-
const { from: r, size: t } = q((n) => {
|
|
244
|
-
var c, o;
|
|
245
|
-
return {
|
|
246
|
-
from: ((c = n.query.products) == null ? void 0 : c.from) ?? 0,
|
|
247
|
-
size: ((o = n.query.products) == null ? void 0 : o.size) ?? 0
|
|
248
|
-
};
|
|
249
|
-
}), { updateSearch: s } = J();
|
|
250
|
-
return {
|
|
251
|
-
loadMore: g(async () => {
|
|
252
|
-
await s(H({ from: r, size: t, pageSize: e }));
|
|
253
|
-
}, [r, t, e, s])
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
export {
|
|
257
|
-
ee as a,
|
|
258
|
-
J as b,
|
|
259
|
-
H as g,
|
|
260
|
-
q as u
|
|
261
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const y=require("./storeContext-DVs7r6Qm.cjs"),i=require("preact/hooks"),v=require("./search-BVJZK90N.cjs"),g=require("./unique-CGVAnKZy.cjs"),p=require("./isEqual-DQXR__da.cjs");function M(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:q,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...A,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const q=["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"],A=["keyword","_redirect"];function N(e,r,t){const s=JSON.stringify(r);try{console.info("Setting storage",e,s),t.setItem(e,s)}catch(a){console.warn(a)}}function T(e,r){try{const t=r.getItem(e);if(t)return JSON.parse(t)}catch(t){console.warn(t)}}function E(e,r){N(e,r,sessionStorage)}function Q(e){return T(e,sessionStorage)}const C="nosto:search:searchResult";function R(e,r,t){if(!e)return;E(C,{query:r,result:t})}function U(e,r){if(!e)return null;const t=Q(C);if(!t||!V(t))return null;const s=k(t.query);return p.isEqual(k(r),s)?t.result:null}function k(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 V(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function w(e,r,t){var d,l,S;const s=g.measure("newSearch"),a=e.config.pageType,n=p.deepMerge(e.store.getInitialState().query,r),c=p.deepMerge(e.config.search,t,{track:a,redirect:a!=="autocomplete",isKeyword:!!(t!=null&&t.isKeyword)});e.store.updateState({query:n,loading:!0,initialized:!0});const o=a!=="autocomplete"&&e.config.persistentSearchCache,u=e.config.queryModifications({...n,products:{...n.products,filter:g.mergeArrays((l=(d=e.store.getInitialState().query)==null?void 0:d.products)==null?void 0:l.filter,(S=r.products)==null?void 0:S.filter)}},a);try{let f;const m=U(o,u);if(m)f=m;else{const I=M(a,u);f=await v.search(I,c),R(o,u,f)}e.store.updateState({response:f,loading:!1})}catch(f){console.error("Search action failed",f)}s()}async function h(e,r,t){const s=g.measure("updateSearch"),a=p.deepMerge(e.store.getState().query,{products:{from:0}},r);await w(e,a,t),s()}async function x(e,r,t){var c;const s=g.measure("replaceFilter"),a=(c=e.store.getState().query.products)==null?void 0:c.filter,n=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...(a==null?void 0:a.filter(o=>o.field!==r))??[],...n]}}),s()}async function K(e,r,t,s){var u,d;const a=g.measure("toggleProductFilter"),n=(u=e.store.getState().query.products)==null?void 0:u.filter,c=n==null?void 0:n.find(l=>l.value instanceof Array&&l.field===r),o=c!=null&&c.value?{...c,value:[...c.value.filter(l=>!p.isEqual(l,t)),...s?[t]:[]]}:s?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...(n==null?void 0:n.filter(l=>l!==c))??[],...(d=o==null?void 0:o.value)!=null&&d.length?[o]:[]]}}),a()}function b(){const e=y.useConfig(),r=i.useContext(y.StoreContext),t=i.useMemo(()=>({config:e,store:r}),[e,r]),s=i.useCallback((o,u)=>w(t,o,u),[t]),a=i.useCallback((o,u)=>h(t,o,u),[t]),n=i.useCallback((o,u,d)=>K(t,o,u,d),[t]),c=i.useCallback((o,u)=>x(t,o,u),[t]);return{newSearch:s,updateSearch:a,toggleProductFilter:n,replaceFilter:c}}function P(e=L){const r=i.useContext(y.StoreContext),[t,s]=i.useState(e(r.getState()));return r.onChange(e,s),i.useEffect(()=>()=>r.clearOnChange(s),[r]),t}const L=e=>e;function F({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function O(e=24){const{from:r,size:t}=P(n=>{var c,o;return{from:((c=n.query.products)==null?void 0:c.from)??0,size:((o=n.query.products)==null?void 0:o.size)??0}}),{updateSearch:s}=b();return{loadMore:i.useCallback(async()=>{await s(F({from:r,size:t,pageSize:e}))},[r,t,e,s])}}exports.getNextPageQuery=F;exports.useActions=b;exports.useLoadMore=O;exports.useNostoAppState=P;
|