@nosto/search-js 1.7.6 → 2.0.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/README.md +2 -2
- package/dist/InfiniteScrollWithObserver-BoKdnFuB.cjs +1 -0
- package/dist/InfiniteScrollWithObserver-CkdVKocm.js +39 -0
- package/dist/baseConfig-C_tlTx1w.js +20 -0
- package/dist/baseConfig-DEAGSRSp.cjs +1 -0
- package/dist/jsxRuntime.module-B3sGoTIU.cjs +1 -0
- package/dist/jsxRuntime.module-Bzuv3cXw.js +13 -0
- package/dist/preact/autocomplete.cjs.js +1 -0
- package/dist/preact/autocomplete.d.ts +5 -0
- package/dist/preact/autocomplete.es.js +52 -0
- package/dist/preact/category.cjs.js +1 -0
- package/dist/preact/category.d.ts +3 -0
- package/dist/preact/category.es.js +22 -0
- package/dist/preact/common.cjs.js +1 -0
- package/dist/preact/common.d.ts +6 -0
- package/dist/preact/common.es.js +26 -0
- package/dist/preact/hooks.cjs.js +1 -0
- package/dist/preact/hooks.d.ts +16 -0
- package/dist/preact/hooks.es.js +356 -0
- package/dist/preact/legacy.cjs.js +1 -0
- package/dist/preact/legacy.d.ts +4 -0
- package/dist/preact/legacy.es.js +7 -0
- package/dist/preact/preact.d.ts +1 -0
- package/dist/preact/serp.cjs.js +1 -0
- package/dist/preact/serp.d.ts +4 -0
- package/dist/preact/serp.es.js +41 -0
- package/dist/preact/src/components/Autocomplete/AutocompleteElement.d.ts +36 -0
- package/dist/preact/src/components/Autocomplete/utils.d.ts +5 -0
- package/dist/renderHeadless-BteGML1G.js +23 -0
- package/dist/renderHeadless-xhkLegO4.cjs +1 -0
- package/dist/storeContext-12dN1l9r.cjs +1 -0
- package/dist/storeContext-CBqmmTUC.js +99 -0
- package/dist/useLoadMore-BBrbOkyq.cjs +1 -0
- package/dist/useLoadMore-DnvHCsYl.js +281 -0
- package/dist/utils/utils.cjs.js +1 -1
- package/dist/utils/utils.es.js +1 -1
- package/package.json +43 -19
- package/dist/InfiniteScrollWithObserver-DbErxedF.cjs +0 -1
- package/dist/InfiniteScrollWithObserver-kuSGeBWr.js +0 -418
- package/dist/preact/preact.cjs.js +0 -1
- package/dist/preact/preact.es.js +0 -484
- package/dist/preact-legacy/preact-legacy.cjs.js +0 -1
- package/dist/preact-legacy/preact-legacy.d.ts +0 -4
- package/dist/preact-legacy/preact-legacy.es.js +0 -6
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { s as l } from "../index.es-B8mbAxS4.js";
|
|
2
|
+
import { u as f, c as u, S, C as m } from "../storeContext-CBqmmTUC.js";
|
|
3
|
+
import { r as g } from "../renderHeadless-BteGML1G.js";
|
|
4
|
+
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
|
+
import { d as C, u as d } from "../baseConfig-C_tlTx1w.js";
|
|
6
|
+
const h = "nosto:search:scrollPos";
|
|
7
|
+
function P() {
|
|
8
|
+
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
9
|
+
}
|
|
10
|
+
function B({ children: e, hit: r, onClick: o }) {
|
|
11
|
+
const { pageType: t } = f(), a = t === "autocomplete" ? void 0 : t;
|
|
12
|
+
return g({
|
|
13
|
+
children: e,
|
|
14
|
+
updateElement: (s, c) => (c.depth > 0 || (s.props = {
|
|
15
|
+
...s.props,
|
|
16
|
+
onClick: (i) => {
|
|
17
|
+
r && a && l((p) => p.recordSearchClick(a, r)), P(), typeof o == "function" && o(i);
|
|
18
|
+
}
|
|
19
|
+
}), s)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const k = {
|
|
23
|
+
...C,
|
|
24
|
+
persistentSearchCache: !1,
|
|
25
|
+
preservePageScroll: !1
|
|
26
|
+
};
|
|
27
|
+
function w(e = {}) {
|
|
28
|
+
return {
|
|
29
|
+
pageType: "serp",
|
|
30
|
+
...k,
|
|
31
|
+
...e
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function H({ config: e, store: r, children: o }) {
|
|
35
|
+
const t = r ?? u();
|
|
36
|
+
return d(), /* @__PURE__ */ n(m, { value: w(e), children: /* @__PURE__ */ n(S, { value: t, children: o }) });
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
H as SearchPageProvider,
|
|
40
|
+
B as SerpElement
|
|
41
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComponentChildren } from 'preact';
|
|
2
|
+
/**
|
|
3
|
+
* @group Components
|
|
4
|
+
*/
|
|
5
|
+
export type AutocompleteElementProps = {
|
|
6
|
+
/**
|
|
7
|
+
* Rendered content.
|
|
8
|
+
*/
|
|
9
|
+
children: ComponentChildren;
|
|
10
|
+
/**
|
|
11
|
+
* Get product data for analytics
|
|
12
|
+
*/
|
|
13
|
+
hit: {
|
|
14
|
+
productId: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
keyword?: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Wraps elements to interactive component that handles selection based on provided configuration.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```jsx
|
|
24
|
+
* // Render product
|
|
25
|
+
* {products?.hits?.map(hit => <AutocompleteElement hit={hit}>
|
|
26
|
+
* <a href={hit.url} class="nosto-product">
|
|
27
|
+
* <img src={hit.imageUrl} alt={hit.name} />
|
|
28
|
+
* <span>{hit.name}</span>
|
|
29
|
+
* <span>{hit.price}</span>
|
|
30
|
+
* </a>
|
|
31
|
+
* </AutocompleteElement>)}
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @group Components
|
|
35
|
+
*/
|
|
36
|
+
export declare function AutocompleteElement({ children, hit }: AutocompleteElementProps): import('preact').VNode<any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { toChildArray as o } from "preact";
|
|
2
|
+
function d(e) {
|
|
3
|
+
return e.type === "input";
|
|
4
|
+
}
|
|
5
|
+
function u(e) {
|
|
6
|
+
return !!e && typeof e == "object" && "type" in e && "props" in e;
|
|
7
|
+
}
|
|
8
|
+
function i(e, t = { depth: 0 }) {
|
|
9
|
+
const { children: p } = e;
|
|
10
|
+
return o(p).map((r) => {
|
|
11
|
+
if (!u(r))
|
|
12
|
+
return r;
|
|
13
|
+
const n = e.updateElement(r, t);
|
|
14
|
+
return n === null ? null : (n.props = {
|
|
15
|
+
...n.props,
|
|
16
|
+
children: i({ ...e, children: n.props.children }, { depth: t.depth + 1 })
|
|
17
|
+
}, n);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
d as i,
|
|
22
|
+
i as r
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("preact");function i(e){return e.type==="input"}function o(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function u(e,t={depth:0}){const{children:p}=e;return s.toChildArray(p).map(r=>{if(!o(r))return r;const n=e.updateElement(r,t);return n===null?null:(n.props={...n.props,children:u({...e,children:n.props.children},{depth:t.depth+1})},n)})}exports.isHTMLInput=i;exports.renderHeadless=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const d=require("preact"),E=require("preact/hooks"),S=d.createContext(null),b=()=>{const e=E.useContext(S);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e},g=e=>String(e)==="[object Object]";function u(e){if(!g(e))return!1;const t=e.constructor;if(t===void 0)return!0;const n=t.prototype;return!(!g(n)||!n.hasOwnProperty("isPrototypeOf"))}function m(...e){return e.reduce((t,n)=>a(t,n))}function C(...e){return e.reduce((t,n)=>a(t,n))}function a(e,t){return u(e)&&u(t)?Object.entries(t).reduce((n,[r,c])=>(n[r]=a(n[r],c),n),{...e}):u(e)?e:t}function s(e,t){if(e===t)return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((n,r)=>s(n,t[r]));if(u(e)&&u(t)){const n=Object.entries(e);return n.length!==Object.keys(t).length?!1:n.every(([r,c])=>s(c,t[r]))}return!1}function p(e,t={}){const n=new Map;let r=C(e,t??{});const c=C(e,t);function x(o){r=o(r);for(const i of n.values())i(r)}function O(o){x(i=>({...i,...o}))}function j(){return r}function P(){return structuredClone(c)}function q(o,i){let l;n.set(i,A=>{const f=o(A);s(f,l)||(l=f,i(f))})}function w(o){n.delete(o)}return{updateState:O,getState:j,getInitialState:P,onChange:q,clearOnChange:w}}const h={loading:!0,query:{},response:{},initialized:!1};function y(e={}){return p(h,e)}const M=d.createContext(y());exports.ConfigContext=S;exports.StoreContext=M;exports.createExtendableStore=p;exports.createStore=y;exports.deepMerge=m;exports.defaultState=h;exports.isEqual=s;exports.isPlainObject=u;exports.useConfig=b;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createContext as C } from "preact";
|
|
2
|
+
import { useContext as x } from "preact/hooks";
|
|
3
|
+
const w = C(null), q = () => {
|
|
4
|
+
const e = x(w);
|
|
5
|
+
if (!e)
|
|
6
|
+
throw new Error("useConfig must be used within a ConfigProvider");
|
|
7
|
+
return e;
|
|
8
|
+
}, g = (e) => String(e) === "[object Object]";
|
|
9
|
+
function s(e) {
|
|
10
|
+
if (!g(e))
|
|
11
|
+
return !1;
|
|
12
|
+
const t = e.constructor;
|
|
13
|
+
if (t === void 0)
|
|
14
|
+
return !0;
|
|
15
|
+
const n = t.prototype;
|
|
16
|
+
return !(!g(n) || !n.hasOwnProperty("isPrototypeOf"));
|
|
17
|
+
}
|
|
18
|
+
function D(...e) {
|
|
19
|
+
return e.reduce((t, n) => a(t, n));
|
|
20
|
+
}
|
|
21
|
+
function p(...e) {
|
|
22
|
+
return e.reduce((t, n) => a(t, n));
|
|
23
|
+
}
|
|
24
|
+
function a(e, t) {
|
|
25
|
+
return s(e) && s(t) ? Object.entries(t).reduce(
|
|
26
|
+
(n, [r, u]) => (n[r] = a(n[r], u), n),
|
|
27
|
+
{ ...e }
|
|
28
|
+
) : s(e) ? e : t;
|
|
29
|
+
}
|
|
30
|
+
function f(e, t) {
|
|
31
|
+
if (e === t)
|
|
32
|
+
return !0;
|
|
33
|
+
if (e instanceof Date && t instanceof Date)
|
|
34
|
+
return e.getTime() === t.getTime();
|
|
35
|
+
if (Array.isArray(e) && Array.isArray(t))
|
|
36
|
+
return e.length !== t.length ? !1 : e.every((n, r) => f(n, t[r]));
|
|
37
|
+
if (s(e) && s(t)) {
|
|
38
|
+
const n = Object.entries(e);
|
|
39
|
+
return n.length !== Object.keys(t).length ? !1 : n.every(([r, u]) => f(u, t[r]));
|
|
40
|
+
}
|
|
41
|
+
return !1;
|
|
42
|
+
}
|
|
43
|
+
function A(e, t = {}) {
|
|
44
|
+
const n = /* @__PURE__ */ new Map();
|
|
45
|
+
let r = p(e, t ?? {});
|
|
46
|
+
const u = p(e, t);
|
|
47
|
+
function d(o) {
|
|
48
|
+
r = o(r);
|
|
49
|
+
for (const i of n.values())
|
|
50
|
+
i(r);
|
|
51
|
+
}
|
|
52
|
+
function y(o) {
|
|
53
|
+
d((i) => ({ ...i, ...o }));
|
|
54
|
+
}
|
|
55
|
+
function h() {
|
|
56
|
+
return r;
|
|
57
|
+
}
|
|
58
|
+
function S() {
|
|
59
|
+
return structuredClone(u);
|
|
60
|
+
}
|
|
61
|
+
function O(o, i) {
|
|
62
|
+
let l;
|
|
63
|
+
n.set(i, (j) => {
|
|
64
|
+
const c = o(j);
|
|
65
|
+
f(c, l) || (l = c, i(c));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function m(o) {
|
|
69
|
+
n.delete(o);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
updateState: y,
|
|
73
|
+
getState: h,
|
|
74
|
+
getInitialState: S,
|
|
75
|
+
onChange: O,
|
|
76
|
+
clearOnChange: m
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const P = {
|
|
80
|
+
loading: !0,
|
|
81
|
+
query: {},
|
|
82
|
+
response: {},
|
|
83
|
+
initialized: !1
|
|
84
|
+
};
|
|
85
|
+
function b(e = {}) {
|
|
86
|
+
return A(P, e);
|
|
87
|
+
}
|
|
88
|
+
const T = C(b());
|
|
89
|
+
export {
|
|
90
|
+
w as C,
|
|
91
|
+
T as S,
|
|
92
|
+
A as a,
|
|
93
|
+
D as b,
|
|
94
|
+
b as c,
|
|
95
|
+
P as d,
|
|
96
|
+
s as e,
|
|
97
|
+
f as i,
|
|
98
|
+
q as u
|
|
99
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const d=require("./storeContext-12dN1l9r.cjs"),i=require("preact/hooks"),I=require("./search-BVJZK90N.cjs"),A=require("./utils/utils.cjs.js");function M(e){return Array.from(new Set(e))}function N(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:T,...t.products},...t.keywords?{keywords:{...t.keywords,fields:M([...$,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const T=["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"],$=["keyword","_redirect"];function Q(...e){if(!e.every(t=>t==null))return e.filter(t=>Array.isArray(t)).reduce((t,r)=>t.concat(r),[])}const k="nosto.search.";function R(e){var r;const t=`${k}${e}`;(r=window.performance)==null||r.mark(`${t}.start`)}function q(e){var r,s;const t=`${k}${e}`;(r=window.performance)==null||r.mark(`${t}.end`),(s=window.performance)==null||s.measure(t,`${t}.start`,`${t}.end`)}function p(e){return R(e),()=>q(e)}function E(e,t,r){const s=JSON.stringify(t);try{console.info("Setting storage",e,s),r.setItem(e,s)}catch(n){console.warn(n)}}function x(e,t){try{const r=t.getItem(e);if(r)return JSON.parse(r)}catch(r){console.warn(r)}}function U(e,t){E(e,t,sessionStorage)}function V(e){return x(e,sessionStorage)}const w="nosto:search:searchResult";function K(e,t,r){if(!e)return;U(w,{query:t,result:r})}function L(e,t){if(!e)return null;const r=V(w);if(!r||!O(r))return null;const s=S(r.query);return d.isEqual(S(t),s)?r.result:null}function S(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 O(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function C(e,t,r){var g,l,h;const s=p("newSearch"),n=e.config.pageType,a=d.deepMerge(e.store.getInitialState().query,t),c=d.deepMerge(e.config.search,r,{track:n,redirect:n!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword)});e.store.updateState({query:a,loading:!0,initialized:!0});const o=n!=="autocomplete"&&e.config.persistentSearchCache,u=e.config.queryModifications({...a,products:{...a.products,filter:Q((l=(g=e.store.getInitialState().query)==null?void 0:g.products)==null?void 0:l.filter,(h=t.products)==null?void 0:h.filter)}},n);try{let f;const m=L(o,u);if(m)f=m;else{const F=N(n,u);f=await I.search(F,c),K(o,u,f)}e.store.updateState({response:f,loading:!1})}catch(f){console.error("Search action failed",f)}s()}async function y(e,t,r){const s=p("updateSearch"),n=d.deepMerge(e.store.getState().query,{products:{from:0}},t);await C(e,n,r),s()}async function z(e,t,r){var c;const s=p("replaceFilter"),n=(c=e.store.getState().query.products)==null?void 0:c.filter,a=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await y(e,{products:{filter:[...(n==null?void 0:n.filter(o=>o.field!==t))??[],...a]}}),s()}async function D(e,t,r,s){var u,g;const n=p("toggleProductFilter"),a=(u=e.store.getState().query.products)==null?void 0:u.filter,c=a==null?void 0:a.find(l=>l.value instanceof Array&&l.field===t),o=c!=null&&c.value?{...c,value:[...c.value.filter(l=>!d.isEqual(l,r)),...s?[r]:[]]}:s?{field:t,value:[r]}:void 0;await y(e,{products:{filter:[...(a==null?void 0:a.filter(l=>l!==c))??[],...(g=o==null?void 0:o.value)!=null&&g.length?[o]:[]]}}),n()}function b(){const e=d.useConfig(),t=i.useContext(d.StoreContext),r=i.useMemo(()=>({config:e,store:t}),[e,t]),s=i.useCallback((o,u)=>C(r,o,u),[r]),n=i.useCallback((o,u)=>y(r,o,u),[r]),a=i.useCallback((o,u,g)=>D(r,o,u,g),[r]),c=i.useCallback((o,u)=>z(r,o,u),[r]);return{newSearch:s,updateSearch:n,toggleProductFilter:a,replaceFilter:c}}function P(e=_){const t=i.useContext(d.StoreContext),[r,s]=i.useState(e(t.getState()));return t.onChange(e,s),i.useEffect(()=>()=>t.clearOnChange(s),[t]),r}const _=e=>e;function v({from:e,size:t,pageSize:r}){return A.isBot()?{products:{from:e+r}}:{products:{size:t+r}}}function B(e=24){const{from:t,size:r}=P(a=>{var c,o;return{from:((c=a.query.products)==null?void 0:c.from)??0,size:((o=a.query.products)==null?void 0:o.size)??0}}),{updateSearch:s}=b();return{loadMore:i.useCallback(async()=>{await s(v({from:t,size:r,pageSize:e}))},[t,r,e,s])}}exports.getNextPageQuery=v;exports.useActions=b;exports.useLoadMore=B;exports.useNostoAppState=P;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { i as k, b as p, u as I, S as w } from "./storeContext-CBqmmTUC.js";
|
|
2
|
+
import { useContext as C, useMemo as A, useCallback as f, useState as M, useEffect as N } from "preact/hooks";
|
|
3
|
+
import { s as T } from "./search-B0-bVNMy.js";
|
|
4
|
+
import { isBot as $ } from "./utils/utils.es.js";
|
|
5
|
+
function R(e) {
|
|
6
|
+
return Array.from(new Set(e));
|
|
7
|
+
}
|
|
8
|
+
function Q(e, t) {
|
|
9
|
+
return {
|
|
10
|
+
...t,
|
|
11
|
+
products: {
|
|
12
|
+
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
13
|
+
fields: E,
|
|
14
|
+
...t.products
|
|
15
|
+
},
|
|
16
|
+
...t.keywords ? {
|
|
17
|
+
keywords: {
|
|
18
|
+
...t.keywords,
|
|
19
|
+
fields: R([...U, ...t.keywords.fields ?? []]),
|
|
20
|
+
highlight: t.keywords.highlight ?? {
|
|
21
|
+
preTag: "<strong>",
|
|
22
|
+
postTag: "</strong>"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} : {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const E = [
|
|
29
|
+
"productId",
|
|
30
|
+
"url",
|
|
31
|
+
"name",
|
|
32
|
+
"imageUrl",
|
|
33
|
+
"imageHash",
|
|
34
|
+
"thumbUrl",
|
|
35
|
+
"description",
|
|
36
|
+
"brand",
|
|
37
|
+
"variantId",
|
|
38
|
+
"availability",
|
|
39
|
+
"price",
|
|
40
|
+
"priceText",
|
|
41
|
+
"categoryIds",
|
|
42
|
+
"categories",
|
|
43
|
+
"customFields.key",
|
|
44
|
+
"customFields.value",
|
|
45
|
+
"priceCurrencyCode",
|
|
46
|
+
"datePublished",
|
|
47
|
+
"listPrice",
|
|
48
|
+
"unitPricingBaseMeasure",
|
|
49
|
+
"unitPricingUnit",
|
|
50
|
+
"unitPricingMeasure",
|
|
51
|
+
"googleCategory",
|
|
52
|
+
"gtin",
|
|
53
|
+
"ageGroup",
|
|
54
|
+
"gender",
|
|
55
|
+
"condition",
|
|
56
|
+
"alternateImageUrls",
|
|
57
|
+
"ratingValue",
|
|
58
|
+
"reviewCount",
|
|
59
|
+
"inventoryLevel",
|
|
60
|
+
"skus.id",
|
|
61
|
+
"skus.name",
|
|
62
|
+
"skus.price",
|
|
63
|
+
"skus.listPrice",
|
|
64
|
+
"skus.priceText",
|
|
65
|
+
"skus.url",
|
|
66
|
+
"skus.imageUrl",
|
|
67
|
+
"skus.inventoryLevel",
|
|
68
|
+
"skus.customFields.key",
|
|
69
|
+
"skus.customFields.value",
|
|
70
|
+
"skus.availability",
|
|
71
|
+
"pid",
|
|
72
|
+
"onDiscount",
|
|
73
|
+
"extra.key",
|
|
74
|
+
"extra.value",
|
|
75
|
+
"saleable",
|
|
76
|
+
"available",
|
|
77
|
+
"tags1",
|
|
78
|
+
"tags2",
|
|
79
|
+
"tags3"
|
|
80
|
+
], U = ["keyword", "_redirect"];
|
|
81
|
+
function V(...e) {
|
|
82
|
+
if (!e.every((t) => t == null))
|
|
83
|
+
return e.filter((t) => Array.isArray(t)).reduce((t, r) => t.concat(r), []);
|
|
84
|
+
}
|
|
85
|
+
const b = "nosto.search.";
|
|
86
|
+
function K(e) {
|
|
87
|
+
var r;
|
|
88
|
+
const t = `${b}${e}`;
|
|
89
|
+
(r = window.performance) == null || r.mark(`${t}.start`);
|
|
90
|
+
}
|
|
91
|
+
function O(e) {
|
|
92
|
+
var r, s;
|
|
93
|
+
const t = `${b}${e}`;
|
|
94
|
+
(r = window.performance) == null || r.mark(`${t}.end`), (s = window.performance) == null || s.measure(t, `${t}.start`, `${t}.end`);
|
|
95
|
+
}
|
|
96
|
+
function g(e) {
|
|
97
|
+
return K(e), () => O(e);
|
|
98
|
+
}
|
|
99
|
+
function z(e, t, r) {
|
|
100
|
+
const s = JSON.stringify(t);
|
|
101
|
+
try {
|
|
102
|
+
console.info("Setting storage", e, s), r.setItem(e, s);
|
|
103
|
+
} catch (n) {
|
|
104
|
+
console.warn(n);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function D(e, t) {
|
|
108
|
+
try {
|
|
109
|
+
const r = t.getItem(e);
|
|
110
|
+
if (r)
|
|
111
|
+
return JSON.parse(r);
|
|
112
|
+
} catch (r) {
|
|
113
|
+
console.warn(r);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function L(e, t) {
|
|
117
|
+
z(e, t, sessionStorage);
|
|
118
|
+
}
|
|
119
|
+
function _(e) {
|
|
120
|
+
return D(e, sessionStorage);
|
|
121
|
+
}
|
|
122
|
+
const v = "nosto:search:searchResult";
|
|
123
|
+
function x(e, t, r) {
|
|
124
|
+
if (!e)
|
|
125
|
+
return;
|
|
126
|
+
L(v, { query: t, result: r });
|
|
127
|
+
}
|
|
128
|
+
function B(e, t) {
|
|
129
|
+
if (!e)
|
|
130
|
+
return null;
|
|
131
|
+
const r = _(v);
|
|
132
|
+
if (!r || !G(r))
|
|
133
|
+
return null;
|
|
134
|
+
const s = S(r.query);
|
|
135
|
+
return k(S(t), s) ? r.result : null;
|
|
136
|
+
}
|
|
137
|
+
function S(e) {
|
|
138
|
+
return {
|
|
139
|
+
accountId: e.accountId,
|
|
140
|
+
customRules: e.customRules,
|
|
141
|
+
explain: e.explain,
|
|
142
|
+
keywords: e.keywords,
|
|
143
|
+
products: e.products,
|
|
144
|
+
query: e.query,
|
|
145
|
+
redirect: e.redirect,
|
|
146
|
+
rules: e.rules,
|
|
147
|
+
segments: e.segments,
|
|
148
|
+
sessionParams: e.sessionParams
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function G(e) {
|
|
152
|
+
return typeof e == "object" && e !== null && "query" in e && "result" in e;
|
|
153
|
+
}
|
|
154
|
+
async function P(e, t, r) {
|
|
155
|
+
var l, u, y;
|
|
156
|
+
const s = g("newSearch"), n = e.config.pageType, a = p(e.store.getInitialState().query, t), c = p(e.config.search, r, {
|
|
157
|
+
track: n,
|
|
158
|
+
redirect: n !== "autocomplete",
|
|
159
|
+
isKeyword: !!(r != null && r.isKeyword)
|
|
160
|
+
});
|
|
161
|
+
e.store.updateState({
|
|
162
|
+
query: a,
|
|
163
|
+
loading: !0,
|
|
164
|
+
initialized: !0
|
|
165
|
+
});
|
|
166
|
+
const o = n !== "autocomplete" && e.config.persistentSearchCache, i = e.config.queryModifications(
|
|
167
|
+
{
|
|
168
|
+
...a,
|
|
169
|
+
products: {
|
|
170
|
+
...a.products,
|
|
171
|
+
// Apply filter merging to avoid overwriting base filters
|
|
172
|
+
filter: V((u = (l = e.store.getInitialState().query) == null ? void 0 : l.products) == null ? void 0 : u.filter, (y = t.products) == null ? void 0 : y.filter)
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
n
|
|
176
|
+
);
|
|
177
|
+
try {
|
|
178
|
+
let d;
|
|
179
|
+
const h = B(o, i);
|
|
180
|
+
if (h)
|
|
181
|
+
d = h;
|
|
182
|
+
else {
|
|
183
|
+
const F = Q(n, i);
|
|
184
|
+
d = await T(F, c), x(o, i, d);
|
|
185
|
+
}
|
|
186
|
+
e.store.updateState({
|
|
187
|
+
response: d,
|
|
188
|
+
loading: !1
|
|
189
|
+
});
|
|
190
|
+
} catch (d) {
|
|
191
|
+
console.error("Search action failed", d);
|
|
192
|
+
}
|
|
193
|
+
s();
|
|
194
|
+
}
|
|
195
|
+
async function m(e, t, r) {
|
|
196
|
+
const s = g("updateSearch"), n = p(e.store.getState().query, { products: { from: 0 } }, t);
|
|
197
|
+
await P(e, n, r), s();
|
|
198
|
+
}
|
|
199
|
+
async function J(e, t, r) {
|
|
200
|
+
var c;
|
|
201
|
+
const s = g("replaceFilter"), n = (c = e.store.getState().query.products) == null ? void 0 : c.filter, a = r !== void 0 ? [{ field: t, [typeof r == "object" ? "range" : "value"]: [r] }] : [];
|
|
202
|
+
await m(e, {
|
|
203
|
+
products: {
|
|
204
|
+
filter: [...(n == null ? void 0 : n.filter((o) => o.field !== t)) ?? [], ...a]
|
|
205
|
+
}
|
|
206
|
+
}), s();
|
|
207
|
+
}
|
|
208
|
+
async function q(e, t, r, s) {
|
|
209
|
+
var i, l;
|
|
210
|
+
const n = g("toggleProductFilter"), a = (i = e.store.getState().query.products) == null ? void 0 : i.filter, c = a == null ? void 0 : a.find((u) => u.value instanceof Array && u.field === t), o = c != null && c.value ? {
|
|
211
|
+
...c,
|
|
212
|
+
value: [...c.value.filter((u) => !k(u, r)), ...s ? [r] : []]
|
|
213
|
+
} : s ? {
|
|
214
|
+
field: t,
|
|
215
|
+
value: [r]
|
|
216
|
+
} : void 0;
|
|
217
|
+
await m(e, {
|
|
218
|
+
products: {
|
|
219
|
+
filter: [...(a == null ? void 0 : a.filter((u) => u !== c)) ?? [], ...(l = o == null ? void 0 : o.value) != null && l.length ? [o] : []]
|
|
220
|
+
}
|
|
221
|
+
}), n();
|
|
222
|
+
}
|
|
223
|
+
function H() {
|
|
224
|
+
const e = I(), t = C(w), r = A(
|
|
225
|
+
() => ({
|
|
226
|
+
config: e,
|
|
227
|
+
store: t
|
|
228
|
+
}),
|
|
229
|
+
[e, t]
|
|
230
|
+
), s = f(
|
|
231
|
+
(o, i) => P(r, o, i),
|
|
232
|
+
[r]
|
|
233
|
+
), n = f(
|
|
234
|
+
(o, i) => m(r, o, i),
|
|
235
|
+
[r]
|
|
236
|
+
), a = f(
|
|
237
|
+
(o, i, l) => q(r, o, i, l),
|
|
238
|
+
[r]
|
|
239
|
+
), c = f(
|
|
240
|
+
(o, i) => J(r, o, i),
|
|
241
|
+
[r]
|
|
242
|
+
);
|
|
243
|
+
return {
|
|
244
|
+
newSearch: s,
|
|
245
|
+
updateSearch: n,
|
|
246
|
+
toggleProductFilter: a,
|
|
247
|
+
replaceFilter: c
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function W(e = Y) {
|
|
251
|
+
const t = C(w), [r, s] = M(e(t.getState()));
|
|
252
|
+
return t.onChange(e, s), N(() => () => t.clearOnChange(s), [t]), r;
|
|
253
|
+
}
|
|
254
|
+
const Y = (e) => e;
|
|
255
|
+
function j({ from: e, size: t, pageSize: r }) {
|
|
256
|
+
return $() ? {
|
|
257
|
+
products: { from: e + r }
|
|
258
|
+
} : {
|
|
259
|
+
products: { size: t + r }
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function re(e = 24) {
|
|
263
|
+
const { from: t, size: r } = W((a) => {
|
|
264
|
+
var c, o;
|
|
265
|
+
return {
|
|
266
|
+
from: ((c = a.query.products) == null ? void 0 : c.from) ?? 0,
|
|
267
|
+
size: ((o = a.query.products) == null ? void 0 : o.size) ?? 0
|
|
268
|
+
};
|
|
269
|
+
}), { updateSearch: s } = H();
|
|
270
|
+
return {
|
|
271
|
+
loadMore: f(async () => {
|
|
272
|
+
await s(j({ from: t, size: r, pageSize: e }));
|
|
273
|
+
}, [t, r, e, s])
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
W as a,
|
|
278
|
+
H as b,
|
|
279
|
+
j as g,
|
|
280
|
+
re as u
|
|
281
|
+
};
|
package/dist/utils/utils.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var r=" daum[ /]| deusu/| yadirectfetcher|(?:^|[^g])news(?!sapphire)|(?<! (?:channel/|google/))google(?!(app|/google| pixel))|(?<! cu)bots?(?:\\b|_)|(?<!(?:lib))http|(?<![hg]m)score|@[a-z][\\w-]+\\.|\\(\\)|\\.com\\b|\\btime/|\\||^<|^[\\w \\.\\-\\(?:\\):%]+(?:/v?\\d+(?:\\.\\d+)?(?:\\.\\d{1,10})*?)?(?:,|$)|^[^ ]{50,}$|^\\d+\\b|^\\w*search\\b|^\\w+/[\\w\\(\\)]*$|^active|^ad muncher|^amaya|^avsdevicesdk/|^biglotron|^bot|^bw/|^clamav[ /]|^client/|^cobweb/|^custom|^ddg[_-]android|^discourse|^dispatch/\\d|^downcast/|^duckduckgo|^email|^facebook|^getright/|^gozilla/|^hobbit|^hotzonu|^hwcdn/|^igetter/|^jeode/|^jetty/|^jigsaw|^microsoft bits|^movabletype|^mozilla/\\d\\.\\d\\s[\\w\\.-]+$|^mozilla/\\d\\.\\d\\s\\(compatible;?(?:\\s\\w+\\/\\d+\\.\\d+)?\\)$|^navermailapp|^netsurf|^offline|^openai/|^owler|^php|^postman|^python|^rank|^read|^reed|^rest|^rss|^snapchat|^space bison|^svn|^swcd |^taringa|^thumbor/|^track|^w3c|^webbandit/|^webcopier|^wget|^whatsapp|^wordpress|^xenu link sleuth|^yahoo|^yandex|^zdm/\\d|^zoom marketplace/|^{{.*}}$|adscanner/|analyzer|archive|ask jeeves/teoma|audit|bit\\.ly/|bluecoat drtr|browsex|burpcollaborator|capture|catch|check\\b|checker|chrome-lighthouse|chromeframe|classifier|cloudflare|convertify|cookiehubscan|crawl|cypress/|dareboost|datanyze|dejaclick|detect|dmbrowser|download|evc-batch/|exaleadcloudview|feed|firephp|functionize|gomezagent|headless|httrack|hubspot marketing grader|hydra|ibisbrowser|infrawatch|insight|inspect|iplabel|ips-agent|java(?!;)|jsjcw_scanner|library|linkcheck|mail\\.ru/|manager|measure|neustar wpm|node|nutch|offbyone|optimize|pageburst|pagespeed|parser|perl|phantomjs|pingdom|powermarks|preview|proxy|ptst[ /]\\d|retriever|rexx;|rigor|rss\\b|scanner\\.|scrape|server|sogou|sparkler/|speedcurve|spider|splash|statuscake|supercleaner|synapse|synthetic|tools|torrent|transcoder|url|validator|virtuoso|wappalyzer|webglance|webkit2png|whatcms/|zgrab",t=/bot|crawl|http|lighthouse|scan|search|spider/i,e;function o(){if(e instanceof RegExp)return e;try{e=new RegExp(r,"i")}catch{e=t}return e}function s(a){return!!a&&o().test(a)}function c(){return s(navigator.userAgent)}exports.isBot=c;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var r=" daum[ /]| deusu/| yadirectfetcher|(?:^|[^g])news(?!sapphire)|(?<! (?:channel/|google/))google(?!(app|/google| pixel))|(?<! cu)bots?(?:\\b|_)|(?<!(?:lib))http|(?<![hg]m)score|@[a-z][\\w-]+\\.|\\(\\)|\\.com\\b|\\btime/|\\||^<|^[\\w \\.\\-\\(?:\\):%]+(?:/v?\\d+(?:\\.\\d+)?(?:\\.\\d{1,10})*?)?(?:,|$)|^[^ ]{50,}$|^\\d+\\b|^\\w*search\\b|^\\w+/[\\w\\(\\)]*$|^active|^ad muncher|^amaya|^avsdevicesdk/|^biglotron|^bot|^bw/|^clamav[ /]|^client/|^cobweb/|^custom|^ddg[_-]android|^discourse|^dispatch/\\d|^downcast/|^duckduckgo|^email|^facebook|^getright/|^gozilla/|^hobbit|^hotzonu|^hwcdn/|^igetter/|^jeode/|^jetty/|^jigsaw|^microsoft bits|^movabletype|^mozilla/\\d\\.\\d\\s[\\w\\.-]+$|^mozilla/\\d\\.\\d\\s\\(compatible;?(?:\\s\\w+\\/\\d+\\.\\d+)?\\)$|^navermailapp|^netsurf|^offline|^openai/|^owler|^php|^postman|^python|^rank|^read|^reed|^rest|^rss|^snapchat|^space bison|^svn|^swcd |^taringa|^thumbor/|^track|^w3c|^webbandit/|^webcopier|^wget|^whatsapp|^wordpress|^xenu link sleuth|^yahoo|^yandex|^zdm/\\d|^zoom marketplace/|^{{.*}}$|adscanner/|analyzer|archive|ask jeeves/teoma|audit|bit\\.ly/|bluecoat drtr|browsex|burpcollaborator|capture|catch|check\\b|checker|chrome-lighthouse|chromeframe|classifier|cloudflare|convertify|cookiehubscan|crawl|cypress/|dareboost|datanyze|dejaclick|detect|dmbrowser|download|evc-batch/|exaleadcloudview|feed|firephp|functionize|gomezagent|headless|httrack|hubspot marketing grader|hydra|ibisbrowser|infrawatch|insight|inspect|iplabel|ips-agent|java(?!;)|jsjcw_scanner|library|linkcheck|mail\\.ru/|manager|measure|neustar wpm|node|nutch|offbyone|onetrust|optimize|pageburst|pagespeed|parser|perl|phantomjs|pingdom|powermarks|preview|proxy|ptst[ /]\\d|retriever|rexx;|rigor|rss\\b|scanner\\.|scrape|server|sogou|sparkler/|speedcurve|spider|splash|statuscake|supercleaner|synapse|synthetic|tools|torrent|transcoder|url|validator|virtuoso|wappalyzer|webglance|webkit2png|whatcms/|zgrab",t=/bot|crawl|http|lighthouse|scan|search|spider/i,e;function o(){if(e instanceof RegExp)return e;try{e=new RegExp(r,"i")}catch{e=t}return e}function s(a){return!!a&&o().test(a)}function c(){return s(navigator.userAgent)}exports.isBot=c;
|
package/dist/utils/utils.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var r = " daum[ /]| deusu/| yadirectfetcher|(?:^|[^g])news(?!sapphire)|(?<! (?:channel/|google/))google(?!(app|/google| pixel))|(?<! cu)bots?(?:\\b|_)|(?<!(?:lib))http|(?<![hg]m)score|@[a-z][\\w-]+\\.|\\(\\)|\\.com\\b|\\btime/|\\||^<|^[\\w \\.\\-\\(?:\\):%]+(?:/v?\\d+(?:\\.\\d+)?(?:\\.\\d{1,10})*?)?(?:,|$)|^[^ ]{50,}$|^\\d+\\b|^\\w*search\\b|^\\w+/[\\w\\(\\)]*$|^active|^ad muncher|^amaya|^avsdevicesdk/|^biglotron|^bot|^bw/|^clamav[ /]|^client/|^cobweb/|^custom|^ddg[_-]android|^discourse|^dispatch/\\d|^downcast/|^duckduckgo|^email|^facebook|^getright/|^gozilla/|^hobbit|^hotzonu|^hwcdn/|^igetter/|^jeode/|^jetty/|^jigsaw|^microsoft bits|^movabletype|^mozilla/\\d\\.\\d\\s[\\w\\.-]+$|^mozilla/\\d\\.\\d\\s\\(compatible;?(?:\\s\\w+\\/\\d+\\.\\d+)?\\)$|^navermailapp|^netsurf|^offline|^openai/|^owler|^php|^postman|^python|^rank|^read|^reed|^rest|^rss|^snapchat|^space bison|^svn|^swcd |^taringa|^thumbor/|^track|^w3c|^webbandit/|^webcopier|^wget|^whatsapp|^wordpress|^xenu link sleuth|^yahoo|^yandex|^zdm/\\d|^zoom marketplace/|^{{.*}}$|adscanner/|analyzer|archive|ask jeeves/teoma|audit|bit\\.ly/|bluecoat drtr|browsex|burpcollaborator|capture|catch|check\\b|checker|chrome-lighthouse|chromeframe|classifier|cloudflare|convertify|cookiehubscan|crawl|cypress/|dareboost|datanyze|dejaclick|detect|dmbrowser|download|evc-batch/|exaleadcloudview|feed|firephp|functionize|gomezagent|headless|httrack|hubspot marketing grader|hydra|ibisbrowser|infrawatch|insight|inspect|iplabel|ips-agent|java(?!;)|jsjcw_scanner|library|linkcheck|mail\\.ru/|manager|measure|neustar wpm|node|nutch|offbyone|optimize|pageburst|pagespeed|parser|perl|phantomjs|pingdom|powermarks|preview|proxy|ptst[ /]\\d|retriever|rexx;|rigor|rss\\b|scanner\\.|scrape|server|sogou|sparkler/|speedcurve|spider|splash|statuscake|supercleaner|synapse|synthetic|tools|torrent|transcoder|url|validator|virtuoso|wappalyzer|webglance|webkit2png|whatcms/|zgrab", t = /bot|crawl|http|lighthouse|scan|search|spider/i, e;
|
|
1
|
+
var r = " daum[ /]| deusu/| yadirectfetcher|(?:^|[^g])news(?!sapphire)|(?<! (?:channel/|google/))google(?!(app|/google| pixel))|(?<! cu)bots?(?:\\b|_)|(?<!(?:lib))http|(?<![hg]m)score|@[a-z][\\w-]+\\.|\\(\\)|\\.com\\b|\\btime/|\\||^<|^[\\w \\.\\-\\(?:\\):%]+(?:/v?\\d+(?:\\.\\d+)?(?:\\.\\d{1,10})*?)?(?:,|$)|^[^ ]{50,}$|^\\d+\\b|^\\w*search\\b|^\\w+/[\\w\\(\\)]*$|^active|^ad muncher|^amaya|^avsdevicesdk/|^biglotron|^bot|^bw/|^clamav[ /]|^client/|^cobweb/|^custom|^ddg[_-]android|^discourse|^dispatch/\\d|^downcast/|^duckduckgo|^email|^facebook|^getright/|^gozilla/|^hobbit|^hotzonu|^hwcdn/|^igetter/|^jeode/|^jetty/|^jigsaw|^microsoft bits|^movabletype|^mozilla/\\d\\.\\d\\s[\\w\\.-]+$|^mozilla/\\d\\.\\d\\s\\(compatible;?(?:\\s\\w+\\/\\d+\\.\\d+)?\\)$|^navermailapp|^netsurf|^offline|^openai/|^owler|^php|^postman|^python|^rank|^read|^reed|^rest|^rss|^snapchat|^space bison|^svn|^swcd |^taringa|^thumbor/|^track|^w3c|^webbandit/|^webcopier|^wget|^whatsapp|^wordpress|^xenu link sleuth|^yahoo|^yandex|^zdm/\\d|^zoom marketplace/|^{{.*}}$|adscanner/|analyzer|archive|ask jeeves/teoma|audit|bit\\.ly/|bluecoat drtr|browsex|burpcollaborator|capture|catch|check\\b|checker|chrome-lighthouse|chromeframe|classifier|cloudflare|convertify|cookiehubscan|crawl|cypress/|dareboost|datanyze|dejaclick|detect|dmbrowser|download|evc-batch/|exaleadcloudview|feed|firephp|functionize|gomezagent|headless|httrack|hubspot marketing grader|hydra|ibisbrowser|infrawatch|insight|inspect|iplabel|ips-agent|java(?!;)|jsjcw_scanner|library|linkcheck|mail\\.ru/|manager|measure|neustar wpm|node|nutch|offbyone|onetrust|optimize|pageburst|pagespeed|parser|perl|phantomjs|pingdom|powermarks|preview|proxy|ptst[ /]\\d|retriever|rexx;|rigor|rss\\b|scanner\\.|scrape|server|sogou|sparkler/|speedcurve|spider|splash|statuscake|supercleaner|synapse|synthetic|tools|torrent|transcoder|url|validator|virtuoso|wappalyzer|webglance|webkit2png|whatcms/|zgrab", t = /bot|crawl|http|lighthouse|scan|search|spider/i, e;
|
|
2
2
|
function o() {
|
|
3
3
|
if (e instanceof RegExp)
|
|
4
4
|
return e;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -32,20 +32,40 @@
|
|
|
32
32
|
"import": "./dist/thumbnails/thumbnails.es.js",
|
|
33
33
|
"require": "./dist/thumbnails/thumbnails.cjs.js"
|
|
34
34
|
},
|
|
35
|
-
"./preact": {
|
|
36
|
-
"types": "./dist/preact/
|
|
37
|
-
"import": "./dist/preact/
|
|
38
|
-
"require": "./dist/preact/
|
|
39
|
-
},
|
|
40
|
-
"./preact-legacy": {
|
|
41
|
-
"types": "./dist/preact-legacy/preact-legacy.d.ts",
|
|
42
|
-
"import": "./dist/preact-legacy/preact-legacy.es.js",
|
|
43
|
-
"require": "./dist/preact-legacy/preact-legacy.cjs.js"
|
|
35
|
+
"./preact/legacy": {
|
|
36
|
+
"types": "./dist/preact/legacy.d.ts",
|
|
37
|
+
"import": "./dist/preact/legacy.es.js",
|
|
38
|
+
"require": "./dist/preact/legacy.cjs.js"
|
|
44
39
|
},
|
|
45
40
|
"./utils": {
|
|
46
41
|
"types": "./dist/utils/utils.d.ts",
|
|
47
42
|
"import": "./dist/utils/utils.es.js",
|
|
48
43
|
"require": "./dist/utils/utils.cjs.js"
|
|
44
|
+
},
|
|
45
|
+
"./preact/common": {
|
|
46
|
+
"types": "./dist/preact/common.d.ts",
|
|
47
|
+
"import": "./dist/preact/common.es.js",
|
|
48
|
+
"require": "./dist/preact/common.cjs.js"
|
|
49
|
+
},
|
|
50
|
+
"./preact/serp": {
|
|
51
|
+
"types": "./dist/preact/serp.d.ts",
|
|
52
|
+
"import": "./dist/preact/serp.es.js",
|
|
53
|
+
"require": "./dist/preact/serp.cjs.js"
|
|
54
|
+
},
|
|
55
|
+
"./preact/category": {
|
|
56
|
+
"types": "./dist/preact/category.d.ts",
|
|
57
|
+
"import": "./dist/preact/category.es.js",
|
|
58
|
+
"require": "./dist/preact/category.cjs.js"
|
|
59
|
+
},
|
|
60
|
+
"./preact/autocomplete": {
|
|
61
|
+
"types": "./dist/preact/autocomplete.d.ts",
|
|
62
|
+
"import": "./dist/preact/autocomplete.es.js",
|
|
63
|
+
"require": "./dist/preact/autocomplete.cjs.js"
|
|
64
|
+
},
|
|
65
|
+
"./preact/hooks": {
|
|
66
|
+
"types": "./dist/preact/hooks.d.ts",
|
|
67
|
+
"import": "./dist/preact/hooks.es.js",
|
|
68
|
+
"require": "./dist/preact/hooks.cjs.js"
|
|
49
69
|
}
|
|
50
70
|
},
|
|
51
71
|
"keywords": [],
|
|
@@ -60,32 +80,36 @@
|
|
|
60
80
|
"test:watch": "vitest",
|
|
61
81
|
"lint": "eslint",
|
|
62
82
|
"lint-fix": "eslint --fix",
|
|
63
|
-
"install:dev": "(cd dev/preact && npm i --ignore-scripts)"
|
|
83
|
+
"install:dev": "(cd dev/preact && npm i --ignore-scripts)",
|
|
84
|
+
"prepare": "husky"
|
|
64
85
|
},
|
|
65
86
|
"devDependencies": {
|
|
66
87
|
"@nosto/nosto-js": "^1.7.0",
|
|
67
88
|
"@testing-library/dom": "^10.4.0",
|
|
68
89
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
69
|
-
"@types/node": "^22.14.
|
|
90
|
+
"@types/node": "^22.14.1",
|
|
70
91
|
"concurrently": "^9.1.2",
|
|
71
92
|
"copyfiles": "^2.4.1",
|
|
72
93
|
"eslint": "^9.24.0",
|
|
73
|
-
"eslint-config-prettier": "^10.1.
|
|
94
|
+
"eslint-config-prettier": "^10.1.2",
|
|
74
95
|
"eslint-plugin-barrel-files": "^3.0.1",
|
|
75
96
|
"eslint-plugin-prettier": "^5.2.6",
|
|
76
97
|
"eslint-plugin-react": "^7.37.5",
|
|
77
98
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
78
99
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
79
100
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
80
|
-
"
|
|
81
|
-
"
|
|
101
|
+
"husky": "^9.1.7",
|
|
102
|
+
"isbot": "^5.1.26",
|
|
103
|
+
"jsdom": "^26.1.0",
|
|
82
104
|
"prettier": "^3.5.3",
|
|
83
|
-
"typedoc": "^0.
|
|
105
|
+
"typedoc": "^0.28.2",
|
|
84
106
|
"typescript": "^5.8.3",
|
|
85
|
-
"typescript-eslint": "^8.
|
|
86
|
-
"vite": "^6.2.
|
|
107
|
+
"typescript-eslint": "^8.30.0",
|
|
108
|
+
"vite": "^6.2.6",
|
|
87
109
|
"vite-plugin-dts": "^4.5.3",
|
|
88
|
-
"vitest": "^3.1.1"
|
|
110
|
+
"vitest": "^3.1.1",
|
|
111
|
+
"@commitlint/cli": "^19.8.0",
|
|
112
|
+
"@commitlint/config-conventional": "^19.8.0"
|
|
89
113
|
},
|
|
90
114
|
"publishConfig": {
|
|
91
115
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h=require("preact"),f=require("preact/hooks"),U=require("./search-BVJZK90N.cjs"),K=require("./utils/utils.cjs.js");var L=0;function C(e,t,r,n,c,i){t||(t={});var s,o,u=t;if("ref"in u)for(o in u={},t)o=="ref"?s=t[o]:u[o]=t[o];var a={type:e,props:u,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--L,__i:-1,__u:0,__source:c,__self:i};if(typeof e=="function"&&(s=e.defaultProps))for(o in s)u[o]===void 0&&(u[o]=s[o]);return h.options.vnode&&h.options.vnode(a),a}const I=e=>String(e)==="[object Object]";function p(e){if(!I(e))return!1;const t=e.constructor;if(t===void 0)return!0;const r=t.prototype;return!(!I(r)||!r.hasOwnProperty("isPrototypeOf"))}function v(...e){return e.reduce((t,r)=>b(t,r))}function A(...e){return e.reduce((t,r)=>b(t,r))}function b(e,t){return p(e)&&p(t)?Object.entries(t).reduce((r,[n,c])=>(r[n]=b(r[n],c),r),{...e}):p(e)?e:t}function S(e,t){if(e===t)return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((r,n)=>S(r,t[n]));if(p(e)&&p(t)){const r=Object.entries(e);return r.length!==Object.keys(t).length?!1:r.every(([n,c])=>S(c,t[n]))}return!1}function F(e,t={}){const r=new Map;let n=A(e,t??{});const c=A(e,t);function i(g){n=g(n);for(const l of r.values())l(n)}function s(g){i(l=>({...l,...g}))}function o(){return n}function u(){return structuredClone(c)}function a(g,l){let y;r.set(l,w=>{const k=g(w);S(k,y)||(y=k,l(k))})}function d(g){r.delete(g)}return{updateState:s,getState:o,getInitialState:u,onChange:a,clearOnChange:d}}const R={loading:!0,query:{},response:{},initialized:!1};function x(e={}){return F(R,e)}const P=h.createContext(x());function _(e=W){const t=f.useContext(P),[r,n]=f.useState(e(t.getState()));return t.onChange(e,n),f.useEffect(()=>()=>t.clearOnChange(n),[t]),r}const W=e=>e;function E(e,...t){return t.reduce((r,n)=>(r[n]=e[n],r),{})}const N=h.createContext(null),T=()=>{const e=f.useContext(N);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};function B(e){return Array.from(new Set(e))}function G(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:J,...t.products},...t.keywords?{keywords:{...t.keywords,fields:B([...H,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const J=["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"],H=["keyword","_redirect"];function Y(...e){if(!e.every(t=>t==null))return e.filter(t=>Array.isArray(t)).reduce((t,r)=>t.concat(r),[])}const j="nosto.search.";function X(e){var r;const t=`${j}${e}`;(r=window.performance)==null||r.mark(`${t}.start`)}function Z(e){var r,n;const t=`${j}${e}`;(r=window.performance)==null||r.mark(`${t}.end`),(n=window.performance)==null||n.measure(t,`${t}.start`,`${t}.end`)}function m(e){return X(e),()=>Z(e)}function ee(e,t,r){const n=JSON.stringify(t);try{console.info("Setting storage",e,n),r.setItem(e,n)}catch(c){console.warn(c)}}function te(e,t){try{const r=t.getItem(e);if(r)return JSON.parse(r)}catch(r){console.warn(r)}}function re(e,t){ee(e,t,sessionStorage)}function ne(e){return te(e,sessionStorage)}const $="nosto:search:searchResult";function oe(e,t,r){if(!e)return;re($,{query:t,result:r})}function se(e,t){if(!e)return null;const r=ne($);if(!r||!ce(r))return null;const n=M(r.query);return S(M(t),n)?r.result:null}function M(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 ce(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function q(e,t,r){var a,d,g;const n=m("newSearch"),c=e.config.pageType,i=v(e.store.getInitialState().query,t),s=v(e.config.search,r,{track:c,redirect:c!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword)});e.store.updateState({query:i,loading:!0,initialized:!0});const o=c!=="autocomplete"&&e.config.persistentSearchCache,u=e.config.queryModifications({...i,products:{...i.products,filter:Y((d=(a=e.store.getInitialState().query)==null?void 0:a.products)==null?void 0:d.filter,(g=t.products)==null?void 0:g.filter)}},c);try{let l;const y=se(o,u);if(y)l=y;else{const w=G(c,u);l=await U.search(w,s),oe(o,u,l)}e.store.updateState({response:l,loading:!1})}catch(l){console.error("Search action failed",l)}n()}async function O(e,t,r){const n=m("updateSearch"),c=v(e.store.getState().query,{products:{from:0}},t);await q(e,c,r),n()}async function ie(e,t,r){var s;const n=m("replaceFilter"),c=(s=e.store.getState().query.products)==null?void 0:s.filter,i=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await O(e,{products:{filter:[...(c==null?void 0:c.filter(o=>o.field!==t))??[],...i]}}),n()}async function ue(e,t,r,n){var u,a;const c=m("toggleProductFilter"),i=(u=e.store.getState().query.products)==null?void 0:u.filter,s=i==null?void 0:i.find(d=>d.value instanceof Array&&d.field===t),o=s!=null&&s.value?{...s,value:[...s.value.filter(d=>!S(d,r)),...n?[r]:[]]}:n?{field:t,value:[r]}:void 0;await O(e,{products:{filter:[...(i==null?void 0:i.filter(d=>d!==s))??[],...(a=o==null?void 0:o.value)!=null&&a.length?[o]:[]]}}),c()}function Q(){const e=T(),t=f.useContext(P),r=f.useMemo(()=>({config:e,store:t}),[e,t]),n=f.useCallback((o,u)=>q(r,o,u),[r]),c=f.useCallback((o,u)=>O(r,o,u),[r]),i=f.useCallback((o,u,a)=>ue(r,o,u,a),[r]),s=f.useCallback((o,u)=>ie(r,o,u),[r]);return{newSearch:n,updateSearch:c,toggleProductFilter:i,replaceFilter:s}}function z({from:e,size:t,pageSize:r}){return K.isBot()?{products:{from:e+r}}:{products:{size:t+r}}}function V(e=24){const{from:t,size:r}=_(i=>{var s,o;return{from:((s=i.query.products)==null?void 0:s.from)??0,size:((o=i.query.products)==null?void 0:o.size)??0}}),{updateSearch:n}=Q();return{loadMore:f.useCallback(async()=>{await n(z({from:t,size:r,pageSize:e}))},[t,r,e,n])}}function D(e,t){var i,s,o;const r=((i=t.products)==null?void 0:i.total)??0,n=((s=e.products)==null?void 0:s.from)??0,c=((o=e.products)==null?void 0:o.size)??0;return r>0&&r>n+c}function ae(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function le({children:e,pageSize:t}){const r=f.useRef(null),{query:n,response:c}=_(s=>E(s,"query","response")),{loadMore:i}=V(t);return f.useEffect(()=>{let s,o;return D(n,c)&&(s=r.current,o=new IntersectionObserver(u=>{const a=u[0];a!=null&&a.isIntersecting&&i()}),s&&o.observe(s)),()=>{s&&o.unobserve(s)}},[c]),C(h.Fragment,{children:[e,C("div",{ref:r,style:{height:"1px"}})]})}exports.ConfigContext=N;exports.InfiniteScrollWithObserver=le;exports.StoreContext=P;exports.createExtendableStore=F;exports.createStore=x;exports.defaultState=R;exports.getNextPageQuery=z;exports.hasMoreResults=D;exports.intersectionObserverSupported=ae;exports.isPlainObject=p;exports.pick=E;exports.u=C;exports.useActions=Q;exports.useConfig=T;exports.useLoadMore=V;exports.useNostoAppState=_;
|