@nosto/search-js 2.6.0 → 2.7.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-BHFWoMdk.cjs → InfiniteScrollWithObserver-D906VaKk.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-YEBEJ5Tf.js → InfiniteScrollWithObserver-DHIVa8bY.js} +1 -1
- package/dist/{baseConfig-BlLNh6Jn.cjs → baseConfig-BFFqFSg5.cjs} +1 -1
- package/dist/{baseConfig-XyA_9NDR.js → baseConfig-Bafl02NY.js} +1 -1
- package/dist/configContext-BR7w4VlU.cjs +1 -0
- package/dist/{configContext-CDTtcin_.js → configContext-GuZOIX3o.js} +18 -17
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/core.es.js +1 -1
- package/dist/{preact/src/search → core/src}/resultCaching.d.ts +2 -2
- package/dist/core/src/types.d.ts +4 -0
- package/dist/core/src/withCache.d.ts +3 -0
- package/dist/deepMerge-CZwCJzEe.js +17 -0
- package/dist/deepMerge-lDscDfII.cjs +1 -0
- package/dist/logger-BcHMZObS.cjs +1 -0
- package/dist/logger-DVwg4Wor.js +42 -0
- package/dist/preact/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete.es.js +2 -2
- package/dist/preact/category.cjs.js +1 -1
- package/dist/preact/category.es.js +2 -2
- 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 +3 -3
- 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 +2 -2
- package/dist/search-BgrZ1cY8.js +136 -0
- package/dist/search-Di9DRn5H.cjs +1 -0
- package/dist/useLoadMore-3isftdTM.cjs +1 -0
- package/dist/useLoadMore-4uB1MmI6.js +201 -0
- package/dist/utils/utils.cjs.js +1 -1
- package/dist/utils/utils.es.js +9 -9
- package/package.json +1 -1
- package/dist/configContext-CGXeJcqj.cjs +0 -1
- package/dist/isEqual-BzZ3d1JM.js +0 -41
- package/dist/isEqual-DQXR__da.cjs +0 -1
- package/dist/logger-DW5RVLX8.js +0 -17
- package/dist/logger-DbHGgDgO.cjs +0 -1
- package/dist/preact/src/search/searchWithCache.d.ts +0 -4
- package/dist/search-B4Q7sbkO.js +0 -48
- package/dist/search-DotpTruC.cjs +0 -1
- package/dist/useLoadMore-BqoEHRgQ.cjs +0 -1
- package/dist/useLoadMore-Dox3w1A5.js +0 -293
package/dist/{InfiniteScrollWithObserver-BHFWoMdk.cjs → InfiniteScrollWithObserver-D906VaKk.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-3isftdTM.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-YEBEJ5Tf.js → InfiniteScrollWithObserver-DHIVa8bY.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-4uB1MmI6.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";const t=require("./index.es-DlUp67LT.cjs"),o=require("./logger-
|
|
1
|
+
"use strict";const t=require("./index.es-DlUp67LT.cjs"),o=require("./logger-BcHMZObS.cjs"),i=require("preact/hooks");function s(){i.useEffect(()=>{const e=window.setTimeout(()=>{o.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);t.s(()=>{window.clearTimeout(e)})},[])}const r={defaultCurrency:"EUR",queryModifications:e=>e};exports.defaultBaseConfig=r;exports.useCheckClientScript=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("preact"),u=require("./deepMerge-lDscDfII.cjs"),E=require("./logger-BcHMZObS.cjs"),M=require("preact/hooks");function l(e,i={}){const r=new Map;let o=u.deepMergePlain(e,i??{});const d=u.deepMergePlain(e,i);function S(t){o=t(o);for(const n of r.values())n(o)}function x(t){S(n=>({...n,...t}))}function p(){return o}function h(){return structuredClone(d)}function q(t,n){let c;r.set(n,w=>{const a=t(w);E.isEqual(a,c)||(c=a,n(a))})}function b(t){r.delete(t)}return{updateState:x,getState:p,getInitialState:h,onChange:q,clearOnChange:b}}const f={loading:!0,query:{},response:{},initialized:!1};function g(e={}){return l(f,e)}const P=s.createContext(g()),C=s.createContext(null),k=()=>{const e=M.useContext(C);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};exports.ConfigContext=C;exports.StoreContext=P;exports.createExtendableStore=l;exports.createStore=g;exports.defaultState=f;exports.useConfig=k;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext as c } from "preact";
|
|
2
|
-
import {
|
|
2
|
+
import { a as u } from "./deepMerge-CZwCJzEe.js";
|
|
3
|
+
import { i as x } from "./logger-DVwg4Wor.js";
|
|
3
4
|
import { useContext as h } from "preact/hooks";
|
|
4
|
-
function
|
|
5
|
+
function w(t, i = {}) {
|
|
5
6
|
const a = /* @__PURE__ */ new Map();
|
|
6
7
|
let o = u(t, i ?? {});
|
|
7
8
|
const f = u(t, i);
|
|
@@ -16,37 +17,37 @@ function b(t, i = {}) {
|
|
|
16
17
|
function g() {
|
|
17
18
|
return o;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function p() {
|
|
20
21
|
return structuredClone(f);
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function d(e, n) {
|
|
23
24
|
let s;
|
|
24
|
-
a.set(n, (
|
|
25
|
-
const r = e(
|
|
25
|
+
a.set(n, (S) => {
|
|
26
|
+
const r = e(S);
|
|
26
27
|
x(r, s) || (s = r, n(r));
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
+
function m(e) {
|
|
30
31
|
a.delete(e);
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
34
|
updateState: C,
|
|
34
35
|
getState: g,
|
|
35
|
-
getInitialState:
|
|
36
|
-
onChange:
|
|
37
|
-
clearOnChange:
|
|
36
|
+
getInitialState: p,
|
|
37
|
+
onChange: d,
|
|
38
|
+
clearOnChange: m
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
const
|
|
41
|
+
const b = {
|
|
41
42
|
loading: !0,
|
|
42
43
|
query: {},
|
|
43
44
|
response: {},
|
|
44
45
|
initialized: !1
|
|
45
46
|
};
|
|
46
47
|
function E(t = {}) {
|
|
47
|
-
return b
|
|
48
|
+
return w(b, t);
|
|
48
49
|
}
|
|
49
|
-
const
|
|
50
|
+
const y = c(E()), q = c(null), z = () => {
|
|
50
51
|
const t = h(q);
|
|
51
52
|
if (!t)
|
|
52
53
|
throw new Error("useConfig must be used within a ConfigProvider");
|
|
@@ -54,9 +55,9 @@ const v = c(E()), q = c(null), y = () => {
|
|
|
54
55
|
};
|
|
55
56
|
export {
|
|
56
57
|
q as C,
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
y as S,
|
|
59
|
+
w as a,
|
|
59
60
|
E as c,
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
b as d,
|
|
62
|
+
z as u
|
|
62
63
|
};
|
package/dist/core/core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-Di9DRn5H.cjs");async function d(r,a,t=1){await e.L(a,void 0,t),await e.s(async c=>await c.recordSearchAddToCart(r,a))}exports.search=o.search;exports.addToCart=d;
|
package/dist/core/core.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as c, s as d } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
import { s as f } from "../search-
|
|
2
|
+
import { s as f } from "../search-BgrZ1cY8.js";
|
|
3
3
|
async function e(r, a, o = 1) {
|
|
4
4
|
await c(a, void 0, o), await d(async (t) => await t.recordSearchAddToCart(r, a));
|
|
5
5
|
}
|
|
@@ -4,8 +4,8 @@ export type SearchResultDto = {
|
|
|
4
4
|
query: ReturnType<typeof getCacheKey>;
|
|
5
5
|
result: SearchResult;
|
|
6
6
|
};
|
|
7
|
-
export declare function cacheSearchResult(
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function cacheSearchResult(query: SearchQuery, result: SearchResult): void;
|
|
8
|
+
export declare function loadCachedResult(query: SearchQuery): SearchResult | null;
|
|
9
9
|
declare function getCacheKey(query: SearchQuery): SearchQuery;
|
|
10
10
|
export declare function isValueShapeCorrect(value: unknown): value is SearchResultDto;
|
|
11
11
|
export {};
|
package/dist/core/src/types.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export type SearchOptions<HD extends readonly HitDecorator[] = readonly HitDecor
|
|
|
12
12
|
* Interval (in ms) between retry attempts. Default: 1000 ms.
|
|
13
13
|
*/
|
|
14
14
|
retryInterval?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to use a persistent cache for the search results. Default: false.
|
|
17
|
+
*/
|
|
18
|
+
usePersistentCache?: boolean;
|
|
15
19
|
};
|
|
16
20
|
export type SearchFn<HD extends readonly HitDecorator[]> = (query: SearchQuery, options: SearchOptions<HD>) => Promise<SearchResult>;
|
|
17
21
|
export type SearchWithNext<HD extends readonly HitDecorator[]> = (query: SearchQuery, options: SearchOptions<HD>, searchFn: SearchFn<HD>) => Promise<SearchResult>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { HitDecorator, SearchFn, SearchOptions } from './types';
|
|
2
|
+
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
3
|
+
export declare function searchWithCache<HD extends readonly HitDecorator[]>(query: SearchQuery, { usePersistentCache, ...options }: SearchOptions<HD>, searchFn: SearchFn<HD>): Promise<SearchResult>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { a as u } from "./logger-DVwg4Wor.js";
|
|
2
|
+
function o(...e) {
|
|
3
|
+
return f(...e);
|
|
4
|
+
}
|
|
5
|
+
function f(...e) {
|
|
6
|
+
return e.reduce((n, r) => c(n, r));
|
|
7
|
+
}
|
|
8
|
+
function c(e, n) {
|
|
9
|
+
return u(e) && u(n) ? Object.entries(n).reduce(
|
|
10
|
+
(r, [i, t]) => (r[i] = c(r[i], t), r),
|
|
11
|
+
{ ...e }
|
|
12
|
+
) : u(e) ? e : n;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
f as a,
|
|
16
|
+
o as d
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("./logger-BcHMZObS.cjs");function s(...e){return c(...e)}function c(...e){return e.reduce((n,r)=>t(n,r))}function t(e,n){return i.isPlainObject(e)&&i.isPlainObject(n)?Object.entries(n).reduce((r,[u,l])=>(r[u]=t(r[u],l),r),{...e}):i.isPlainObject(e)?e:n}exports.deepMerge=s;exports.deepMergePlain=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const f=require("./index.es-DlUp67LT.cjs"),c=e=>String(e)==="[object Object]";function o(e){if(!c(e))return!1;const r=e.constructor;if(r===void 0)return!0;const t=r.prototype;return!(!c(t)||!t.hasOwnProperty("isPrototypeOf"))}function s(e,r){if(e===r)return!0;if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((t,n)=>s(t,r[n]));if(o(e)&&o(r)){const t=Object.entries(e);return t.length!==Object.keys(r).length?!1:t.every(([n,u])=>s(u,r[n]))}return!1}function i(e){return(...r)=>{f.s(t=>{(t.internal.context.mode.isPreview()?console[e]:t.internal.logger[e])(...r)})}}const g={debug:i("debug"),info:i("info"),warn:i("warn"),error:i("error")};exports.isEqual=s;exports.isPlainObject=o;exports.logger=g;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { s as u } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
const i = (r) => String(r) === "[object Object]";
|
|
3
|
+
function s(r) {
|
|
4
|
+
if (!i(r))
|
|
5
|
+
return !1;
|
|
6
|
+
const e = r.constructor;
|
|
7
|
+
if (e === void 0)
|
|
8
|
+
return !0;
|
|
9
|
+
const t = e.prototype;
|
|
10
|
+
return !(!i(t) || !t.hasOwnProperty("isPrototypeOf"));
|
|
11
|
+
}
|
|
12
|
+
function f(r, e) {
|
|
13
|
+
if (r === e)
|
|
14
|
+
return !0;
|
|
15
|
+
if (r instanceof Date && e instanceof Date)
|
|
16
|
+
return r.getTime() === e.getTime();
|
|
17
|
+
if (Array.isArray(r) && Array.isArray(e))
|
|
18
|
+
return r.length !== e.length ? !1 : r.every((t, n) => f(t, e[n]));
|
|
19
|
+
if (s(r) && s(e)) {
|
|
20
|
+
const t = Object.entries(r);
|
|
21
|
+
return t.length !== Object.keys(e).length ? !1 : t.every(([n, c]) => f(c, e[n]));
|
|
22
|
+
}
|
|
23
|
+
return !1;
|
|
24
|
+
}
|
|
25
|
+
function o(r) {
|
|
26
|
+
return (...e) => {
|
|
27
|
+
u((t) => {
|
|
28
|
+
(t.internal.context.mode.isPreview() ? console[r] : t.internal.logger[r])(...e);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const a = {
|
|
33
|
+
debug: o("debug"),
|
|
34
|
+
info: o("info"),
|
|
35
|
+
warn: o("warn"),
|
|
36
|
+
error: o("error")
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
s as a,
|
|
40
|
+
f as i,
|
|
41
|
+
a as l
|
|
42
|
+
};
|
|
@@ -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("../configContext-
|
|
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-BR7w4VlU.cjs"),c=require("../baseConfig-BFFqFSg5.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,8 +2,8 @@ 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 "../configContext-
|
|
6
|
-
import { d as C, u as g } from "../baseConfig-
|
|
5
|
+
import { c as l, S as m, C as f } from "../configContext-GuZOIX3o.js";
|
|
6
|
+
import { d as C, u as g } from "../baseConfig-Bafl02NY.js";
|
|
7
7
|
function E(t) {
|
|
8
8
|
return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../configContext-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../configContext-BR7w4VlU.cjs"),o=require("../baseConfig-BFFqFSg5.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,6 +1,6 @@
|
|
|
1
1
|
import { u as t } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as c, C as i } from "../configContext-
|
|
3
|
-
import { d as s, u as f } from "../baseConfig-
|
|
2
|
+
import { c as n, S as c, C as i } from "../configContext-GuZOIX3o.js";
|
|
3
|
+
import { d as s, u as f } from "../baseConfig-Bafl02NY.js";
|
|
4
4
|
const C = {
|
|
5
5
|
...s,
|
|
6
6
|
persistentSearchCache: !1,
|
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-3isftdTM.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-D906VaKk.cjs"),q=require("preact"),r=require("../configContext-BR7w4VlU.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-4uB1MmI6.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-DHIVa8bY.js";
|
|
6
6
|
import { Fragment as h } from "preact";
|
|
7
|
-
import { S as O, a as W, c as A, d as B } from "../configContext-
|
|
7
|
+
import { S as O, a as W, c as A, d as B } from "../configContext-GuZOIX3o.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-3isftdTM.cjs"),P=require("../logger-BcHMZObS.cjs"),v=require("preact/hooks"),C=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function q(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(()=>{C.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=q;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,6 +1,6 @@
|
|
|
1
|
-
import { u as F, b as R } from "../useLoadMore-
|
|
2
|
-
import { a as Y } from "../useLoadMore-
|
|
3
|
-
import { a as N } from "../
|
|
1
|
+
import { u as F, b as R } from "../useLoadMore-4uB1MmI6.js";
|
|
2
|
+
import { a as Y } from "../useLoadMore-4uB1MmI6.js";
|
|
3
|
+
import { a as N } from "../logger-DVwg4Wor.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";
|
|
6
6
|
import { p as x } from "../parseNumber-QA48nJLp.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-D906VaKk.cjs"),r=require("../useLoadMore-3isftdTM.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-DHIVa8bY.js";
|
|
2
|
+
import { g as s } from "../useLoadMore-4uB1MmI6.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 p=require("../index.es-DlUp67LT.cjs"),s=require("../configContext-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs"),s=require("../configContext-BR7w4VlU.cjs"),S=require("../renderHeadless-xhkLegO4.cjs"),a=require("../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../baseConfig-BFFqFSg5.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,8 +1,8 @@
|
|
|
1
1
|
import { s as l } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
import { u as f, c as u, S, C as m } from "../configContext-
|
|
2
|
+
import { u as f, c as u, S, C as m } from "../configContext-GuZOIX3o.js";
|
|
3
3
|
import { r as g } from "../renderHeadless-BteGML1G.js";
|
|
4
4
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
|
-
import { d as C, u as d } from "../baseConfig-
|
|
5
|
+
import { d as C, u as d } from "../baseConfig-Bafl02NY.js";
|
|
6
6
|
const h = "nosto:search:scrollPos";
|
|
7
7
|
function P() {
|
|
8
8
|
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { s as y } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
import { l as f, i as R } from "./logger-DVwg4Wor.js";
|
|
3
|
+
async function b(t, { hitDecorators: r, ...e }, s) {
|
|
4
|
+
var c, i;
|
|
5
|
+
const n = await s(t, e);
|
|
6
|
+
if (!((i = (c = n.products) == null ? void 0 : c.hits) != null && i.length) || !(r != null && r.length))
|
|
7
|
+
return n;
|
|
8
|
+
const o = (l) => r.reduce((u, a) => a(u), l);
|
|
9
|
+
return {
|
|
10
|
+
...n,
|
|
11
|
+
products: {
|
|
12
|
+
...n.products,
|
|
13
|
+
hits: n.products.hits.map(o)
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function N(t, r, e) {
|
|
18
|
+
const s = JSON.stringify(r);
|
|
19
|
+
try {
|
|
20
|
+
f.info("Setting storage", t, s), e.setItem(t, s);
|
|
21
|
+
} catch (n) {
|
|
22
|
+
f.warn(n);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function k(t, r) {
|
|
26
|
+
try {
|
|
27
|
+
const e = r.getItem(t);
|
|
28
|
+
if (e)
|
|
29
|
+
return JSON.parse(e);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
f.warn(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function C(t, r) {
|
|
35
|
+
N(t, r, sessionStorage);
|
|
36
|
+
}
|
|
37
|
+
function O(t) {
|
|
38
|
+
return k(t, sessionStorage);
|
|
39
|
+
}
|
|
40
|
+
const w = "nosto:search:searchResult";
|
|
41
|
+
function z(t, r) {
|
|
42
|
+
C(w, { query: t, result: r });
|
|
43
|
+
}
|
|
44
|
+
function E(t) {
|
|
45
|
+
const r = O(w);
|
|
46
|
+
if (!r || !I(r))
|
|
47
|
+
return null;
|
|
48
|
+
const e = S(r.query);
|
|
49
|
+
return R(S(t), e) ? r.result : null;
|
|
50
|
+
}
|
|
51
|
+
function S(t) {
|
|
52
|
+
const r = {
|
|
53
|
+
...t,
|
|
54
|
+
time: void 0,
|
|
55
|
+
products: {
|
|
56
|
+
...t.products,
|
|
57
|
+
size: void 0
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return JSON.parse(JSON.stringify(r));
|
|
61
|
+
}
|
|
62
|
+
function I(t) {
|
|
63
|
+
return typeof t == "object" && t !== null && "query" in t && "result" in t;
|
|
64
|
+
}
|
|
65
|
+
async function J(t, { usePersistentCache: r, ...e }, s) {
|
|
66
|
+
if (!r)
|
|
67
|
+
return s(t, e);
|
|
68
|
+
const n = await V(t, e);
|
|
69
|
+
return z(t, n), n;
|
|
70
|
+
}
|
|
71
|
+
async function V(t, r) {
|
|
72
|
+
var a, p, d, h, g;
|
|
73
|
+
const { from: e = 0, size: s = 0 } = t.products || {}, n = E(t);
|
|
74
|
+
if (!n)
|
|
75
|
+
return await m(t, r);
|
|
76
|
+
const o = ((a = n == null ? void 0 : n.products) == null ? void 0 : a.hits) || [];
|
|
77
|
+
if (s === o.length)
|
|
78
|
+
return n;
|
|
79
|
+
if (s < o.length)
|
|
80
|
+
return {
|
|
81
|
+
...n,
|
|
82
|
+
products: {
|
|
83
|
+
...n.products,
|
|
84
|
+
hits: o.slice(0, s),
|
|
85
|
+
total: ((p = n.products) == null ? void 0 : p.total) || 0
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const c = s - o.length, i = e > 0 ? e + 1 : s - c, l = {
|
|
89
|
+
...t,
|
|
90
|
+
products: {
|
|
91
|
+
...t.products,
|
|
92
|
+
from: i,
|
|
93
|
+
size: c
|
|
94
|
+
}
|
|
95
|
+
}, u = await m(l, r);
|
|
96
|
+
return {
|
|
97
|
+
...n,
|
|
98
|
+
products: {
|
|
99
|
+
...n.products,
|
|
100
|
+
hits: [...((d = n.products) == null ? void 0 : d.hits) || [], ...((h = u.products) == null ? void 0 : h.hits) || []],
|
|
101
|
+
total: (g = u.products) == null ? void 0 : g.total
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function F(t) {
|
|
106
|
+
return new Promise((r) => setTimeout(r, t));
|
|
107
|
+
}
|
|
108
|
+
async function T(t, { maxRetries: r = 0, retryInterval: e = 0, ...s }, n) {
|
|
109
|
+
let o = 0;
|
|
110
|
+
for (; ; )
|
|
111
|
+
try {
|
|
112
|
+
return await n(t, s);
|
|
113
|
+
} catch (c) {
|
|
114
|
+
if (o >= r)
|
|
115
|
+
throw c;
|
|
116
|
+
if (!W(c))
|
|
117
|
+
throw f.info("Skipping retry logic for", c), c;
|
|
118
|
+
o++, await F(e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function W(t) {
|
|
122
|
+
return !t || typeof t != "object" ? !1 : !("status" in t) || j(t.status);
|
|
123
|
+
}
|
|
124
|
+
function j(t) {
|
|
125
|
+
return typeof t == "number" && (t < 400 || t >= 500);
|
|
126
|
+
}
|
|
127
|
+
async function m(t, r = {}) {
|
|
128
|
+
const e = await new Promise(y);
|
|
129
|
+
return A(e.search, T, J, b)(t, r);
|
|
130
|
+
}
|
|
131
|
+
function A(t, ...r) {
|
|
132
|
+
return r.reduce((e, s) => (n, o) => s(n, o, e), t);
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
m as s
|
|
136
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("./index.es-DlUp67LT.cjs"),i=require("./logger-BcHMZObS.cjs");async function R(t,{hitDecorators:e,...n},s){var c,u;const r=await s(t,n);if(!((u=(c=r.products)==null?void 0:c.hits)!=null&&u.length)||!(e!=null&&e.length))return r;const o=f=>e.reduce((a,l)=>l(a),f);return{...r,products:{...r.products,hits:r.products.hits.map(o)}}}function b(t,e,n){const s=JSON.stringify(e);try{i.logger.info("Setting storage",t,s),n.setItem(t,s)}catch(r){i.logger.warn(r)}}function N(t,e){try{const n=e.getItem(t);if(n)return JSON.parse(n)}catch(n){i.logger.warn(n)}}function k(t,e){b(t,e,sessionStorage)}function C(t){return N(t,sessionStorage)}const y="nosto:search:searchResult";function O(t,e){k(y,{query:t,result:e})}function z(t){const e=C(y);if(!e||!E(e))return null;const n=w(e.query);return i.isEqual(w(t),n)?e.result:null}function w(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function E(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t}async function I(t,{usePersistentCache:e,...n},s){if(!e)return s(t,n);const r=await J(t,n);return O(t,r),r}async function J(t,e){var l,d,h,p,S;const{from:n=0,size:s=0}=t.products||{},r=z(t);if(!r)return await g(t,e);const o=((l=r==null?void 0:r.products)==null?void 0:l.hits)||[];if(s===o.length)return r;if(s<o.length)return{...r,products:{...r.products,hits:o.slice(0,s),total:((d=r.products)==null?void 0:d.total)||0}};const c=s-o.length,u=n>0?n+1:s-c,f={...t,products:{...t.products,from:u,size:c}},a=await g(f,e);return{...r,products:{...r.products,hits:[...((h=r.products)==null?void 0:h.hits)||[],...((p=a.products)==null?void 0:p.hits)||[]],total:(S=a.products)==null?void 0:S.total}}}function V(t){return new Promise(e=>setTimeout(e,t))}async function F(t,{maxRetries:e=0,retryInterval:n=0,...s},r){let o=0;for(;;)try{return await r(t,s)}catch(c){if(o>=e)throw c;if(!T(c))throw i.logger.info("Skipping retry logic for",c),c;o++,await V(n)}}function T(t){return!t||typeof t!="object"?!1:!("status"in t)||W(t.status)}function W(t){return typeof t=="number"&&(t<400||t>=500)}async function g(t,e={}){const n=await new Promise(m.s);return _(n.search,F,I,R)(t,e)}function _(t,...e){return e.reduce((n,s)=>(r,o)=>s(r,o,n),t)}exports.search=g;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const f=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),v=require("./search-Di9DRn5H.cjs"),g=require("./unique-BCAEb4ek.cjs"),y=require("./deepMerge-lDscDfII.cjs"),m=require("./logger-BcHMZObS.cjs");function S(e=P){const r=n.useContext(f.StoreContext),[t,o]=n.useState(e(r.getState()));return r.onChange(e,o),n.useEffect(()=>()=>r.clearOnChange(o),[r]),t}const P=e=>e;function F(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:q,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...M,...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"],M=["keyword","_redirect"];async function C(e,r,t){var d,l,k;const o=g.measure("newSearch"),u=e.config.pageType,c=u==="search"?"serp":u,a=y.deepMerge(e.store.getInitialState().query,r),s=y.deepMerge(e.config.search,t,{track:c,redirect:u!=="autocomplete",isKeyword:!!(t!=null&&t.isKeyword),usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache});e.store.updateState({query:a,loading:!0,initialized:!0});const i=e.config.queryModifications({...a,products:{...a.products,filter:g.mergeArrays((l=(d=e.store.getInitialState().query)==null?void 0:d.products)==null?void 0:l.filter,(k=r.products)==null?void 0:k.filter)}},u);try{const p=await v.search(F(e.config.pageType,i),s);e.store.updateState({response:p,loading:!1})}catch(p){m.logger.error("Search action failed",p)}o()}async function h(e,r,t){const o=g.measure("updateSearch"),u=y.deepMerge(e.store.getState().query,{products:{from:0}},r);await C(e,u,t),o()}async function T(e,r,t){var a;const o=g.measure("replaceFilter"),u=(a=e.store.getState().query.products)==null?void 0:a.filter,c=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...(u==null?void 0:u.filter(s=>s.field!==r))??[],...c]}}),o()}async function A(e,r,t,o){var i,d;const u=g.measure("toggleProductFilter"),c=(i=e.store.getState().query.products)==null?void 0:i.filter,a=c==null?void 0:c.find(l=>l.value instanceof Array&&l.field===r),s=a!=null&&a.value?{...a,value:[...a.value.filter(l=>!m.isEqual(l,t)),...o?[t]:[]]}:o?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...(c==null?void 0:c.filter(l=>l!==a))??[],...(d=s==null?void 0:s.value)!=null&&d.length?[s]:[]]}}),u()}function w(){const e=f.useConfig(),r=n.useContext(f.StoreContext),t=n.useMemo(()=>({config:e,store:r}),[e,r]),o=n.useCallback((s,i)=>C(t,s,i),[t]),u=n.useCallback((s,i)=>h(t,s,i),[t]),c=n.useCallback((s,i,d)=>A(t,s,i,d),[t]),a=n.useCallback((s,i)=>T(t,s,i),[t]);return{newSearch:o,updateSearch:u,toggleProductFilter:c,replaceFilter:a}}function b({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function I(e=24){const{from:r,size:t}=S(c=>{var a,s;return{from:((a=c.query.products)==null?void 0:a.from)??0,size:((s=c.query.products)==null?void 0:s.size)??0}}),{updateSearch:o}=w();return{loadMore:n.useCallback(async()=>{await o(b({from:r,size:t,pageSize:e}))},[r,t,e,o])}}exports.getNextPageQuery=b;exports.useActions=w;exports.useLoadMore=I;exports.useNostoAppState=S;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { S as h, u as w } from "./configContext-GuZOIX3o.js";
|
|
2
|
+
import { useContext as k, useState as C, useEffect as v, useMemo as b, useCallback as d } from "preact/hooks";
|
|
3
|
+
import { s as F } from "./search-BgrZ1cY8.js";
|
|
4
|
+
import { u as P, a as g, m as M, i as T } from "./unique-CyAMhegX.js";
|
|
5
|
+
import { d as f } from "./deepMerge-CZwCJzEe.js";
|
|
6
|
+
import { l as I, i as q } from "./logger-DVwg4Wor.js";
|
|
7
|
+
function Q(e = U) {
|
|
8
|
+
const r = k(h), [t, o] = C(e(r.getState()));
|
|
9
|
+
return r.onChange(e, o), v(() => () => r.clearOnChange(o), [r]), t;
|
|
10
|
+
}
|
|
11
|
+
const U = (e) => e;
|
|
12
|
+
function A(e, r) {
|
|
13
|
+
return {
|
|
14
|
+
...r,
|
|
15
|
+
products: {
|
|
16
|
+
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
17
|
+
fields: z,
|
|
18
|
+
...r.products
|
|
19
|
+
},
|
|
20
|
+
...r.keywords ? {
|
|
21
|
+
keywords: {
|
|
22
|
+
...r.keywords,
|
|
23
|
+
fields: P([...K, ...r.keywords.fields ?? []]),
|
|
24
|
+
highlight: r.keywords.highlight ?? {
|
|
25
|
+
preTag: "<strong>",
|
|
26
|
+
postTag: "</strong>"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} : {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const z = [
|
|
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
|
+
], K = ["keyword", "_redirect"];
|
|
85
|
+
async function S(e, r, t) {
|
|
86
|
+
var l, n, m;
|
|
87
|
+
const o = g("newSearch"), i = e.config.pageType, c = i === "search" ? "serp" : i, a = f(e.store.getInitialState().query, r), s = f(e.config.search, t, {
|
|
88
|
+
track: c,
|
|
89
|
+
redirect: i !== "autocomplete",
|
|
90
|
+
isKeyword: !!(t != null && t.isKeyword),
|
|
91
|
+
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache
|
|
92
|
+
});
|
|
93
|
+
e.store.updateState({
|
|
94
|
+
query: a,
|
|
95
|
+
loading: !0,
|
|
96
|
+
initialized: !0
|
|
97
|
+
});
|
|
98
|
+
const u = e.config.queryModifications(
|
|
99
|
+
{
|
|
100
|
+
...a,
|
|
101
|
+
products: {
|
|
102
|
+
...a.products,
|
|
103
|
+
// Apply filter merging to avoid overwriting base filters
|
|
104
|
+
filter: M((n = (l = e.store.getInitialState().query) == null ? void 0 : l.products) == null ? void 0 : n.filter, (m = r.products) == null ? void 0 : m.filter)
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
i
|
|
108
|
+
);
|
|
109
|
+
try {
|
|
110
|
+
const p = await F(A(e.config.pageType, u), s);
|
|
111
|
+
e.store.updateState({
|
|
112
|
+
response: p,
|
|
113
|
+
loading: !1
|
|
114
|
+
});
|
|
115
|
+
} catch (p) {
|
|
116
|
+
I.error("Search action failed", p);
|
|
117
|
+
}
|
|
118
|
+
o();
|
|
119
|
+
}
|
|
120
|
+
async function y(e, r, t) {
|
|
121
|
+
const o = g("updateSearch"), i = f(e.store.getState().query, { products: { from: 0 } }, r);
|
|
122
|
+
await S(e, i, t), o();
|
|
123
|
+
}
|
|
124
|
+
async function L(e, r, t) {
|
|
125
|
+
var a;
|
|
126
|
+
const o = g("replaceFilter"), i = (a = e.store.getState().query.products) == null ? void 0 : a.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
127
|
+
await y(e, {
|
|
128
|
+
products: {
|
|
129
|
+
filter: [...(i == null ? void 0 : i.filter((s) => s.field !== r)) ?? [], ...c]
|
|
130
|
+
}
|
|
131
|
+
}), o();
|
|
132
|
+
}
|
|
133
|
+
async function B(e, r, t, o) {
|
|
134
|
+
var u, l;
|
|
135
|
+
const i = g("toggleProductFilter"), c = (u = e.store.getState().query.products) == null ? void 0 : u.filter, a = c == null ? void 0 : c.find((n) => n.value instanceof Array && n.field === r), s = a != null && a.value ? {
|
|
136
|
+
...a,
|
|
137
|
+
value: [...a.value.filter((n) => !q(n, t)), ...o ? [t] : []]
|
|
138
|
+
} : o ? {
|
|
139
|
+
field: r,
|
|
140
|
+
value: [t]
|
|
141
|
+
} : void 0;
|
|
142
|
+
await y(e, {
|
|
143
|
+
products: {
|
|
144
|
+
filter: [...(c == null ? void 0 : c.filter((n) => n !== a)) ?? [], ...(l = s == null ? void 0 : s.value) != null && l.length ? [s] : []]
|
|
145
|
+
}
|
|
146
|
+
}), i();
|
|
147
|
+
}
|
|
148
|
+
function D() {
|
|
149
|
+
const e = w(), r = k(h), t = b(
|
|
150
|
+
() => ({
|
|
151
|
+
config: e,
|
|
152
|
+
store: r
|
|
153
|
+
}),
|
|
154
|
+
[e, r]
|
|
155
|
+
), o = d(
|
|
156
|
+
(s, u) => S(t, s, u),
|
|
157
|
+
[t]
|
|
158
|
+
), i = d(
|
|
159
|
+
(s, u) => y(t, s, u),
|
|
160
|
+
[t]
|
|
161
|
+
), c = d(
|
|
162
|
+
(s, u, l) => B(t, s, u, l),
|
|
163
|
+
[t]
|
|
164
|
+
), a = d(
|
|
165
|
+
(s, u) => L(t, s, u),
|
|
166
|
+
[t]
|
|
167
|
+
);
|
|
168
|
+
return {
|
|
169
|
+
newSearch: o,
|
|
170
|
+
updateSearch: i,
|
|
171
|
+
toggleProductFilter: c,
|
|
172
|
+
replaceFilter: a
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function E({ from: e, size: r, pageSize: t }) {
|
|
176
|
+
return T() ? {
|
|
177
|
+
products: { from: e + t }
|
|
178
|
+
} : {
|
|
179
|
+
products: { size: r + t }
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function _(e = 24) {
|
|
183
|
+
const { from: r, size: t } = Q((c) => {
|
|
184
|
+
var a, s;
|
|
185
|
+
return {
|
|
186
|
+
from: ((a = c.query.products) == null ? void 0 : a.from) ?? 0,
|
|
187
|
+
size: ((s = c.query.products) == null ? void 0 : s.size) ?? 0
|
|
188
|
+
};
|
|
189
|
+
}), { updateSearch: o } = D();
|
|
190
|
+
return {
|
|
191
|
+
loadMore: d(async () => {
|
|
192
|
+
await o(E({ from: r, size: t, pageSize: e }));
|
|
193
|
+
}, [r, t, e, o])
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
_ as a,
|
|
198
|
+
D as b,
|
|
199
|
+
E as g,
|
|
200
|
+
Q as u
|
|
201
|
+
};
|
package/dist/utils/utils.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 q=require("../deepMerge-lDscDfII.cjs"),c=require("../unique-BCAEb4ek.cjs"),a=require("../logger-BcHMZObS.cjs"),b=require("../parseNumber-FsZ8w61u.cjs"),k=require("../pick-rYi1lc2m.cjs");function n(i){i.setAttribute("autocomplete","off")}function m(i,{onClick:f,onFocus:t,onInput:d,onKeyDown:s,onSubmit:u},{form:p=i.form??void 0}={}){const o=[];function r(e,l,v){e.addEventListener(l,v),o.push(()=>e.removeEventListener(l,v))}return(s||u)&&r(i,"keydown",e=>{s==null||s(i.value,e.key),s&&(e.key==="ArrowDown"||e.key==="ArrowUp")?e.preventDefault():u&&e.key==="Enter"&&(i.value!==""&&!e.repeat&&u(i.value),e.preventDefault())}),u&&p&&(r(p,"submit",e=>{e.preventDefault(),u(i.value)}),p.querySelectorAll("[type=submit]").forEach(e=>{r(e,"click",l=>{l.preventDefault(),u(i.value)})})),f&&r(i,"click",()=>f(i.value)),t&&r(i,"focus",()=>t(i.value)),d&&r(i,"input",()=>d(i.value)),{destroy(){o.forEach(e=>e())}}}exports.deepMerge=q.deepMerge;exports.isBot=c.isBot;exports.measure=c.measure;exports.mergeArrays=c.mergeArrays;exports.unique=c.unique;exports.isEqual=a.isEqual;exports.isPlainObject=a.isPlainObject;exports.logger=a.logger;exports.parseNumber=b.parseNumber;exports.pick=k.pick;exports.bindInput=m;exports.disableNativeAutocomplete=n;
|
package/dist/utils/utils.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { d as t
|
|
2
|
-
import { i as
|
|
3
|
-
import { l as j } from "../logger-
|
|
1
|
+
import { d as t } from "../deepMerge-CZwCJzEe.js";
|
|
2
|
+
import { i as A, a as b, m as q, u as y } from "../unique-CyAMhegX.js";
|
|
3
|
+
import { i as h, a as N, l as j } from "../logger-DVwg4Wor.js";
|
|
4
4
|
import { p as M } from "../parseNumber-QA48nJLp.js";
|
|
5
5
|
import { p as P } from "../pick-DReBictn.js";
|
|
6
6
|
function d(s) {
|
|
@@ -29,13 +29,13 @@ export {
|
|
|
29
29
|
m as bindInput,
|
|
30
30
|
t as deepMerge,
|
|
31
31
|
d as disableNativeAutocomplete,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
A as isBot,
|
|
33
|
+
h as isEqual,
|
|
34
|
+
N as isPlainObject,
|
|
35
35
|
j as logger,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
b as measure,
|
|
37
|
+
q as mergeArrays,
|
|
38
38
|
M as parseNumber,
|
|
39
39
|
P as pick,
|
|
40
|
-
|
|
40
|
+
y as unique
|
|
41
41
|
};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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;
|
package/dist/isEqual-BzZ3d1JM.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const s = (e) => String(e) === "[object Object]";
|
|
2
|
-
function i(e) {
|
|
3
|
-
if (!s(e))
|
|
4
|
-
return !1;
|
|
5
|
-
const r = e.constructor;
|
|
6
|
-
if (r === void 0)
|
|
7
|
-
return !0;
|
|
8
|
-
const t = r.prototype;
|
|
9
|
-
return !(!s(t) || !t.hasOwnProperty("isPrototypeOf"));
|
|
10
|
-
}
|
|
11
|
-
function a(...e) {
|
|
12
|
-
return o(...e);
|
|
13
|
-
}
|
|
14
|
-
function o(...e) {
|
|
15
|
-
return e.reduce((r, t) => c(r, t));
|
|
16
|
-
}
|
|
17
|
-
function c(e, r) {
|
|
18
|
-
return i(e) && i(r) ? Object.entries(r).reduce(
|
|
19
|
-
(t, [n, u]) => (t[n] = c(t[n], u), t),
|
|
20
|
-
{ ...e }
|
|
21
|
-
) : i(e) ? e : r;
|
|
22
|
-
}
|
|
23
|
-
function f(e, r) {
|
|
24
|
-
if (e === r)
|
|
25
|
-
return !0;
|
|
26
|
-
if (e instanceof Date && r instanceof Date)
|
|
27
|
-
return e.getTime() === r.getTime();
|
|
28
|
-
if (Array.isArray(e) && Array.isArray(r))
|
|
29
|
-
return e.length !== r.length ? !1 : e.every((t, n) => f(t, r[n]));
|
|
30
|
-
if (i(e) && i(r)) {
|
|
31
|
-
const t = Object.entries(e);
|
|
32
|
-
return t.length !== Object.keys(r).length ? !1 : t.every(([n, u]) => f(u, r[n]));
|
|
33
|
-
}
|
|
34
|
-
return !1;
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
i as a,
|
|
38
|
-
o as b,
|
|
39
|
-
a as d,
|
|
40
|
-
f as i
|
|
41
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const c=e=>String(e)==="[object Object]";function i(e){if(!c(e))return!1;const r=e.constructor;if(r===void 0)return!0;const t=r.prototype;return!(!c(t)||!t.hasOwnProperty("isPrototypeOf"))}function l(...e){return f(...e)}function f(...e){return e.reduce((r,t)=>o(r,t))}function o(e,r){return i(e)&&i(r)?Object.entries(r).reduce((t,[n,u])=>(t[n]=o(t[n],u),t),{...e}):i(e)?e:r}function s(e,r){if(e===r)return!0;if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((t,n)=>s(t,r[n]));if(i(e)&&i(r)){const t=Object.entries(e);return t.length!==Object.keys(r).length?!1:t.every(([n,u])=>s(u,r[n]))}return!1}exports.deepMerge=l;exports.deepMergePlain=f;exports.isEqual=s;exports.isPlainObject=i;
|
package/dist/logger-DW5RVLX8.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { s as g } from "./index.es-B8mbAxS4.js";
|
|
2
|
-
function r(o) {
|
|
3
|
-
return (...n) => {
|
|
4
|
-
g((e) => {
|
|
5
|
-
(e.internal.context.mode.isPreview() ? console[o] : e.internal.logger[o])(...n);
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
const c = {
|
|
10
|
-
debug: r("debug"),
|
|
11
|
-
info: r("info"),
|
|
12
|
-
warn: r("warn"),
|
|
13
|
-
error: r("error")
|
|
14
|
-
};
|
|
15
|
-
export {
|
|
16
|
-
c as l
|
|
17
|
-
};
|
package/dist/logger-DbHGgDgO.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const g=require("./index.es-DlUp67LT.cjs");function e(r){return(...n)=>{g.s(o=>{(o.internal.context.mode.isPreview()?console[r]:o.internal.logger[r])(...n)})}}const t={debug:e("debug"),info:e("info"),warn:e("warn"),error:e("error")};exports.logger=t;
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|
package/dist/search-B4Q7sbkO.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { s as p } from "./index.es-B8mbAxS4.js";
|
|
2
|
-
import { l } from "./logger-DW5RVLX8.js";
|
|
3
|
-
async function h(t, { hitDecorators: r, ...e }, s) {
|
|
4
|
-
var i, c;
|
|
5
|
-
const n = await s(t, e);
|
|
6
|
-
if (!((c = (i = n.products) == null ? void 0 : i.hits) != null && c.length) || !(r != null && r.length))
|
|
7
|
-
return n;
|
|
8
|
-
const u = (o) => r.reduce((a, f) => f(a), o);
|
|
9
|
-
return {
|
|
10
|
-
...n,
|
|
11
|
-
products: {
|
|
12
|
-
...n.products,
|
|
13
|
-
hits: n.products.hits.map(u)
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function d(t) {
|
|
18
|
-
return new Promise((r) => setTimeout(r, t));
|
|
19
|
-
}
|
|
20
|
-
async function w(t, { maxRetries: r = 0, retryInterval: e = 0, ...s }, n) {
|
|
21
|
-
let u = 0;
|
|
22
|
-
for (; ; )
|
|
23
|
-
try {
|
|
24
|
-
return await n(t, s);
|
|
25
|
-
} catch (i) {
|
|
26
|
-
if (u >= r)
|
|
27
|
-
throw i;
|
|
28
|
-
if (!y(i))
|
|
29
|
-
throw l.info("Skipping retry logic for", i), i;
|
|
30
|
-
u++, await d(e);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function y(t) {
|
|
34
|
-
return !t || typeof t != "object" ? !1 : !("status" in t) || m(t.status);
|
|
35
|
-
}
|
|
36
|
-
function m(t) {
|
|
37
|
-
return typeof t == "number" && (t < 400 || t >= 500);
|
|
38
|
-
}
|
|
39
|
-
async function P(t, r = {}) {
|
|
40
|
-
const e = await new Promise(p);
|
|
41
|
-
return g(e.search, w, h)(t, r);
|
|
42
|
-
}
|
|
43
|
-
function g(t, ...r) {
|
|
44
|
-
return r.reduce((e, s) => (n, u) => s(n, u, e), t);
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
P as s
|
|
48
|
-
};
|
package/dist/search-DotpTruC.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const p=require("./index.es-DlUp67LT.cjs"),h=require("./logger-DbHGgDgO.cjs");async function l(e,{hitDecorators:t,...r},u){var s,c;const n=await u(e,r);if(!((c=(s=n.products)==null?void 0:s.hits)!=null&&c.length)||!(t!=null&&t.length))return n;const i=o=>t.reduce((a,f)=>f(a),o);return{...n,products:{...n.products,hits:n.products.hits.map(i)}}}function d(e){return new Promise(t=>setTimeout(t,e))}async function w(e,{maxRetries:t=0,retryInterval:r=0,...u},n){let i=0;for(;;)try{return await n(e,u)}catch(s){if(i>=t)throw s;if(!y(s))throw h.logger.info("Skipping retry logic for",s),s;i++,await d(r)}}function y(e){return!e||typeof e!="object"?!1:!("status"in e)||g(e.status)}function g(e){return typeof e=="number"&&(e<400||e>=500)}async function m(e,t={}){const r=await new Promise(p.s);return b(r.search,w,l)(e,t)}function b(e,...t){return t.reduce((r,u)=>(n,i)=>u(n,i,r),e)}exports.search=m;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const S=require("./configContext-CGXeJcqj.cjs"),l=require("preact/hooks"),g=require("./unique-BCAEb4ek.cjs"),k=require("./search-DotpTruC.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;
|
|
@@ -1,293 +0,0 @@
|
|
|
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-B4Q7sbkO.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
|
-
};
|