@nosto/search-js 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/core.d.ts +3 -0
- package/dist/core/core.es.js +21 -32
- package/dist/currencies/currencies.cjs.js +1 -1
- package/dist/currencies/currencies.d.ts +3 -0
- package/dist/currencies/currencies.es.js +34 -45
- package/dist/index.es-Bcd5IQh9.js +20 -0
- package/dist/index.es-D_7T9vdv.cjs +1 -0
- package/dist/preact/preact.cjs.js +1 -1
- package/dist/preact/preact.d.ts +6 -0
- package/dist/preact/preact.es.js +125 -20
- package/dist/preact/src/hooks/useNostoAppState.d.ts +41 -0
- package/dist/preact/src/store.d.ts +1421 -0
- package/dist/preact/src/storeContext.d.ts +1391 -0
- package/dist/preact/test/mocks/mocks.d.ts +1384 -0
- package/dist/thumbnails/thumbnails.cjs.js +1 -1
- package/dist/thumbnails/{index.d.ts → thumbnails.d.ts} +2 -2
- package/dist/thumbnails/thumbnails.es.js +77 -92
- package/dist/utils/src/deepFreeze.d.ts +27 -0
- package/dist/utils/src/deepMerge.d.ts +40 -0
- package/dist/utils/src/isEqual.d.ts +1 -0
- package/dist/utils/src/isPlainObject.d.ts +1 -0
- package/dist/utils/src/mergeArrays.d.ts +1 -0
- package/dist/utils/src/simplify.d.ts +14 -0
- package/dist/utils/src/types.d.ts +3 -0
- package/package.json +11 -9
- package/dist/core/index.d.ts +0 -3
- package/dist/currencies/index.d.ts +0 -3
- package/dist/preact/index.d.ts +0 -2
package/dist/core/core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../index.es-D_7T9vdv.cjs");function a(t,e){if(!t.products||!(e!=null&&e.length))return t;const r=i=>e.reduce((u,n)=>n(u),i);return{...t,products:{...t.products,hits:t.products.hits.map(r)}}}function o(t){return new Promise(e=>setTimeout(e,t))}async function l(t,e,r){const{maxRetries:i=0,retryInterval:u=1e3}=r;let n=0;for(;;)try{return await t.search(e,r)}catch(c){if(!f(c))throw console.info("Skipping retry logic for",c),c;if(n>=i)throw c;n++,await o(u)}}function f(t){return!t||typeof t!="object"?!1:!("status"in t)||h(t.status)}function h(t){return typeof t=="number"&&(t<400||t>=500)}async function y(t,e={}){const{hitDecorators:r,...i}=e,u=await new Promise(s.s),n=await l(u,t,i);return a(n,r)}exports.search=y;
|
package/dist/core/core.es.js
CHANGED
|
@@ -1,42 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
async function c(t) {
|
|
7
|
-
return window.nostojs(t);
|
|
8
|
-
}
|
|
9
|
-
typeof window < "u" && (s(), c((t) => {
|
|
10
|
-
t.internal.getSettings();
|
|
11
|
-
}));
|
|
12
|
-
typeof window < "u" && s();
|
|
13
|
-
function a(t, n) {
|
|
14
|
-
if (!t.products || !(n != null && n.length))
|
|
1
|
+
import { s as a } from "../index.es-Bcd5IQh9.js";
|
|
2
|
+
function s(t, r) {
|
|
3
|
+
if (!t.products || !(r != null && r.length))
|
|
15
4
|
return t;
|
|
16
|
-
const
|
|
5
|
+
const e = (i) => r.reduce((u, n) => n(u), i);
|
|
17
6
|
return {
|
|
18
7
|
...t,
|
|
19
8
|
products: {
|
|
20
9
|
...t.products,
|
|
21
|
-
hits: t.products.hits.map(
|
|
10
|
+
hits: t.products.hits.map(e)
|
|
22
11
|
}
|
|
23
12
|
};
|
|
24
13
|
}
|
|
25
|
-
function
|
|
26
|
-
return new Promise((
|
|
14
|
+
function o(t) {
|
|
15
|
+
return new Promise((r) => setTimeout(r, t));
|
|
27
16
|
}
|
|
28
|
-
async function f(t,
|
|
29
|
-
const { maxRetries:
|
|
30
|
-
let
|
|
17
|
+
async function f(t, r, e) {
|
|
18
|
+
const { maxRetries: i = 0, retryInterval: u = 1e3 } = e;
|
|
19
|
+
let n = 0;
|
|
31
20
|
for (; ; )
|
|
32
21
|
try {
|
|
33
|
-
return await t.search(
|
|
34
|
-
} catch (
|
|
35
|
-
if (!h(
|
|
36
|
-
throw console.info("Skipping retry logic for",
|
|
37
|
-
if (
|
|
38
|
-
throw
|
|
39
|
-
|
|
22
|
+
return await t.search(r, e);
|
|
23
|
+
} catch (c) {
|
|
24
|
+
if (!h(c))
|
|
25
|
+
throw console.info("Skipping retry logic for", c), c;
|
|
26
|
+
if (n >= i)
|
|
27
|
+
throw c;
|
|
28
|
+
n++, await o(u);
|
|
40
29
|
}
|
|
41
30
|
}
|
|
42
31
|
function h(t) {
|
|
@@ -45,10 +34,10 @@ function h(t) {
|
|
|
45
34
|
function l(t) {
|
|
46
35
|
return typeof t == "number" && (t < 400 || t >= 500);
|
|
47
36
|
}
|
|
48
|
-
async function
|
|
49
|
-
const { hitDecorators:
|
|
50
|
-
return
|
|
37
|
+
async function p(t, r = {}) {
|
|
38
|
+
const { hitDecorators: e, ...i } = r, u = await new Promise(a), n = await f(u, t, i);
|
|
39
|
+
return s(n, e);
|
|
51
40
|
}
|
|
52
41
|
export {
|
|
53
|
-
|
|
42
|
+
p as search
|
|
54
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../index.es-D_7T9vdv.cjs"),g={defaultCurrency:"EUR",defaultLocale:"en-US",currencySettings:{}},p={EUR:"de-DE",GBP:"en-GB",USD:"en-US",AUD:"en-AU",CAD:"en-CA",INR:"en-IN",AFN:"en-IN",BDT:"en-IN",BTN:"en-IN",MMK:"en-IN",NPR:"en-IN",PKR:"en-IN"};function y(u={}){const o={...g,...u};u.currencySettings||d.s(c=>{o.currencySettings=c.internal.getSettings().currencySettings??{}});function a(c,n){const{defaultCurrency:t,currencySettings:r,defaultLocale:i}=o,s=n??t,f=p[s]??i;if(s in r){const e=r[s],l=new Intl.NumberFormat(f,{useGrouping:!!e.groupingSeparator,minimumFractionDigits:e.decimalPlaces,maximumFractionDigits:e.decimalPlaces}).formatToParts(c).map(m=>m.type==="group"?e.groupingSeparator:m.type==="decimal"?e.decimalCharacter:m.value).join("");return e!=null&&e.currencyBeforeAmount?`${e.currencyToken}${l}`:`${l}${e==null?void 0:e.currencyToken}`}return new Intl.NumberFormat(f,{style:"currency",currency:s}).format(c)}return{formatCurrency:a}}function C(u){const{formatCurrency:o}=y(u);function a(n,t){const r={};return n.price!==void 0&&(r.priceText=o(n.price,t)),n.listPrice!==void 0&&(r.listPriceText=o(n.listPrice,t)),Object.assign({},n,r)}function c(n){return n.price!==void 0||n.listPrice!==void 0}return function(t){if(!c(t))return t;const r=a(t,t.priceCurrencyCode);return r.skus&&r.skus.some(c)&&(r.skus=r.skus.map(i=>c(i)?a(i,t.priceCurrencyCode):i)),r}}exports.getCurrencyFormatting=y;exports.priceDecorator=C;
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
window.nostojs = window.nostojs ?? function(t) {
|
|
3
|
-
(window.nostojs.q = window.nostojs.q ?? []).push(t);
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
async function y(t) {
|
|
7
|
-
return window.nostojs(t);
|
|
8
|
-
}
|
|
9
|
-
typeof window < "u" && (d(), y((t) => {
|
|
10
|
-
t.internal.getSettings();
|
|
11
|
-
}));
|
|
12
|
-
typeof window < "u" && d();
|
|
1
|
+
import { s as y } from "../index.es-Bcd5IQh9.js";
|
|
13
2
|
const p = {
|
|
14
3
|
defaultCurrency: "EUR",
|
|
15
4
|
defaultLocale: "en-US",
|
|
16
5
|
/** @hidden */
|
|
17
6
|
currencySettings: {}
|
|
18
|
-
},
|
|
7
|
+
}, d = {
|
|
19
8
|
EUR: "de-DE",
|
|
20
9
|
GBP: "en-GB",
|
|
21
10
|
USD: "en-US",
|
|
@@ -30,50 +19,50 @@ const p = {
|
|
|
30
19
|
NPR: "en-IN",
|
|
31
20
|
PKR: "en-IN"
|
|
32
21
|
};
|
|
33
|
-
function
|
|
34
|
-
const
|
|
22
|
+
function g(i = {}) {
|
|
23
|
+
const o = {
|
|
35
24
|
...p,
|
|
36
|
-
...
|
|
25
|
+
...i
|
|
37
26
|
};
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
i.currencySettings || y((c) => {
|
|
28
|
+
o.currencySettings = c.internal.getSettings().currencySettings ?? {};
|
|
40
29
|
});
|
|
41
|
-
function
|
|
42
|
-
const { defaultCurrency:
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
useGrouping: !!
|
|
46
|
-
minimumFractionDigits:
|
|
47
|
-
maximumFractionDigits:
|
|
48
|
-
}).formatToParts(
|
|
49
|
-
return
|
|
30
|
+
function a(c, n) {
|
|
31
|
+
const { defaultCurrency: t, currencySettings: r, defaultLocale: u } = o, s = n ?? t, f = d[s] ?? u;
|
|
32
|
+
if (s in r) {
|
|
33
|
+
const e = r[s], l = new Intl.NumberFormat(f, {
|
|
34
|
+
useGrouping: !!e.groupingSeparator,
|
|
35
|
+
minimumFractionDigits: e.decimalPlaces,
|
|
36
|
+
maximumFractionDigits: e.decimalPlaces
|
|
37
|
+
}).formatToParts(c).map((m) => m.type === "group" ? e.groupingSeparator : m.type === "decimal" ? e.decimalCharacter : m.value).join("");
|
|
38
|
+
return e != null && e.currencyBeforeAmount ? `${e.currencyToken}${l}` : `${l}${e == null ? void 0 : e.currencyToken}`;
|
|
50
39
|
}
|
|
51
|
-
return new Intl.NumberFormat(
|
|
40
|
+
return new Intl.NumberFormat(f, {
|
|
52
41
|
style: "currency",
|
|
53
|
-
currency:
|
|
54
|
-
}).format(
|
|
42
|
+
currency: s
|
|
43
|
+
}).format(c);
|
|
55
44
|
}
|
|
56
45
|
return {
|
|
57
|
-
formatCurrency:
|
|
46
|
+
formatCurrency: a
|
|
58
47
|
};
|
|
59
48
|
}
|
|
60
|
-
function
|
|
61
|
-
const { formatCurrency:
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
return
|
|
49
|
+
function S(i) {
|
|
50
|
+
const { formatCurrency: o } = g(i);
|
|
51
|
+
function a(n, t) {
|
|
52
|
+
const r = {};
|
|
53
|
+
return n.price !== void 0 && (r.priceText = o(n.price, t)), n.listPrice !== void 0 && (r.listPriceText = o(n.listPrice, t)), Object.assign({}, n, r);
|
|
65
54
|
}
|
|
66
|
-
function
|
|
67
|
-
return
|
|
55
|
+
function c(n) {
|
|
56
|
+
return n.price !== void 0 || n.listPrice !== void 0;
|
|
68
57
|
}
|
|
69
|
-
return function(
|
|
70
|
-
if (!
|
|
71
|
-
return
|
|
72
|
-
const
|
|
73
|
-
return
|
|
58
|
+
return function(t) {
|
|
59
|
+
if (!c(t))
|
|
60
|
+
return t;
|
|
61
|
+
const r = a(t, t.priceCurrencyCode);
|
|
62
|
+
return r.skus && r.skus.some(c) && (r.skus = r.skus.map((u) => c(u) ? a(u, t.priceCurrencyCode) : u)), r;
|
|
74
63
|
};
|
|
75
64
|
}
|
|
76
65
|
export {
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
g as getCurrencyFormatting,
|
|
67
|
+
S as priceDecorator
|
|
79
68
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function o() {
|
|
2
|
+
window.nostojs = window.nostojs ?? function(n) {
|
|
3
|
+
(window.nostojs.q = window.nostojs.q ?? []).push(n);
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
async function i(n) {
|
|
7
|
+
return window.nostojs(n);
|
|
8
|
+
}
|
|
9
|
+
let t = null;
|
|
10
|
+
typeof window < "u" && (o(), i((n) => {
|
|
11
|
+
t = n.internal.getSettings();
|
|
12
|
+
}));
|
|
13
|
+
function s() {
|
|
14
|
+
return t;
|
|
15
|
+
}
|
|
16
|
+
typeof window < "u" && o();
|
|
17
|
+
export {
|
|
18
|
+
s as i,
|
|
19
|
+
i as s
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function o(){window.nostojs=window.nostojs??function(n){(window.nostojs.q=window.nostojs.q??[]).push(n)}}async function t(n){return window.nostojs(n)}let s=null;typeof window<"u"&&(o(),t(n=>{s=n.internal.getSettings()}));function i(){return s}typeof window<"u"&&o();exports.i=i;exports.s=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("preact"),l=require("preact/hooks"),C=require("../index.es-D_7T9vdv.cjs");var b=0;function q(t,e,n,r,o,u){e||(e={});var i,s,c=e;if("ref"in c)for(s in c={},e)s=="ref"?i=e[s]:c[s]=e[s];var p={type:t,props:c,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--b,__i:-1,__u:0,__source:o,__self:u};if(typeof t=="function"&&(i=t.defaultProps))for(s in i)c[s]===void 0&&(c[s]=i[s]);return _.options.vnode&&_.options.vnode(p),p}const m=t=>String(t)==="[object Object]";function S(t){if(!m(t))return!1;const e=t.constructor;if(e===void 0)return!0;const n=e.prototype;return!(!m(n)||!n.hasOwnProperty("isPrototypeOf"))}const j=t=>{const e=Object.entries(t).reduce((n,[r,o])=>{const u=S(o)?j(o):Object.freeze(o);return{...n,[r]:u}},{});return Object.freeze(e)};function A(...t){return t.reduce((e,n)=>P(e,n))}function P(t,e){return S(t)&&S(e)?Object.entries(e).reduce((n,[r,o])=>(n[r]=P(n[r],o),n),{...t}):e}function y(t,e){if(t===e)return!0;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)&&Array.isArray(e))return t.length!==e.length?!1:t.every((n,r)=>y(n,e[r]));if(S(t)&&S(e)){const n=Object.entries(t);return n.length!==Object.keys(e).length?!1:n.every(([r,o])=>y(o,e[r]))}return!1}const h={loading:!0,pageType:void 0,query:{query:""},response:{query:""},initialized:!1,customParams:{}};function v(t){const e=new Map;let n=t?A(h,t):h;const r=j(n);function o(a){n=a(n);for(const f of e.values())f(n)}function u(a){o(f=>({...f,...a}))}function i(){return n}function s(){return r}function c(a,f){let O;e.set(f,z=>{const g=a(z);y(g,O)||(O=g,f(g))})}function p(a){e.delete(a)}return{updateState:u,getState:i,getInitialState:s,onChange:c,clearOnChange:p}}const d=_.createContext(v({}));function k({store:t,children:e}){return q(d,{value:t,children:e})}function x(t=T){const e=l.useContext(d),[n,r]=l.useState(t(e.getState()));return e.onChange(t,r),l.useEffect(()=>()=>e.clearOnChange(r),[e]),n}const T=t=>t;function w(){const[t,e]=l.useState([]),[n,r]=l.useState([]);return l.useEffect(()=>{C.s(async o=>{const{products:u,segments:i}=await o.getSearchSessionParams();e(i??[]),r((u==null?void 0:u.personalizationBoost)??[])})},[]),{segments:t,boost:n}}function E(t){return v(t)}exports.StoreContext=d;exports.StoreProvider=k;exports.mockStore=E;exports.useNostoAppState=x;exports.usePersonalization=w;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** @module preact */
|
|
2
|
+
export { useNostoAppState } from "./src/hooks/useNostoAppState";
|
|
3
|
+
export { usePersonalization } from "./src/hooks/usePersonalization";
|
|
4
|
+
export { type State, type Store } from "./src/store";
|
|
5
|
+
export { StoreContext, StoreProvider } from "./src/storeContext";
|
|
6
|
+
export { mockStore } from "./test/mocks/mocks";
|
package/dist/preact/preact.es.js
CHANGED
|
@@ -1,28 +1,133 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { options as m, createContext as b } from "preact";
|
|
2
|
+
import { useContext as A, useState as S, useEffect as h } from "preact/hooks";
|
|
3
|
+
import { s as k } from "../index.es-Bcd5IQh9.js";
|
|
4
|
+
var q = 0;
|
|
5
|
+
function x(t, e, n, r, o, i) {
|
|
6
|
+
e || (e = {});
|
|
7
|
+
var u, s, c = e;
|
|
8
|
+
if ("ref" in c) for (s in c = {}, e) s == "ref" ? u = e[s] : c[s] = e[s];
|
|
9
|
+
var p = { type: t, props: c, key: n, ref: u, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --q, __i: -1, __u: 0, __source: o, __self: i };
|
|
10
|
+
if (typeof t == "function" && (u = t.defaultProps)) for (s in u) c[s] === void 0 && (c[s] = u[s]);
|
|
11
|
+
return m.vnode && m.vnode(p), p;
|
|
12
|
+
}
|
|
13
|
+
const d = (t) => String(t) === "[object Object]";
|
|
14
|
+
function l(t) {
|
|
15
|
+
if (!d(t))
|
|
16
|
+
return !1;
|
|
17
|
+
const e = t.constructor;
|
|
18
|
+
if (e === void 0)
|
|
19
|
+
return !0;
|
|
20
|
+
const n = e.prototype;
|
|
21
|
+
return !(!d(n) || !n.hasOwnProperty("isPrototypeOf"));
|
|
22
|
+
}
|
|
23
|
+
const j = (t) => {
|
|
24
|
+
const e = Object.entries(t).reduce((n, [r, o]) => {
|
|
25
|
+
const i = l(o) ? j(o) : Object.freeze(o);
|
|
26
|
+
return {
|
|
27
|
+
...n,
|
|
28
|
+
[r]: i
|
|
29
|
+
};
|
|
30
|
+
}, {});
|
|
31
|
+
return Object.freeze(e);
|
|
32
|
+
};
|
|
33
|
+
function w(...t) {
|
|
34
|
+
return t.reduce((e, n) => v(e, n));
|
|
35
|
+
}
|
|
36
|
+
function v(t, e) {
|
|
37
|
+
return l(t) && l(e) ? Object.entries(e).reduce(
|
|
38
|
+
(n, [r, o]) => (n[r] = v(n[r], o), n),
|
|
39
|
+
{ ...t }
|
|
40
|
+
) : e;
|
|
41
|
+
}
|
|
42
|
+
function _(t, e) {
|
|
43
|
+
if (t === e)
|
|
44
|
+
return !0;
|
|
45
|
+
if (t instanceof Date && e instanceof Date)
|
|
46
|
+
return t.getTime() === e.getTime();
|
|
47
|
+
if (Array.isArray(t) && Array.isArray(e))
|
|
48
|
+
return t.length !== e.length ? !1 : t.every((n, r) => _(n, e[r]));
|
|
49
|
+
if (l(t) && l(e)) {
|
|
50
|
+
const n = Object.entries(t);
|
|
51
|
+
return n.length !== Object.keys(e).length ? !1 : n.every(([r, o]) => _(o, e[r]));
|
|
52
|
+
}
|
|
53
|
+
return !1;
|
|
54
|
+
}
|
|
55
|
+
const O = {
|
|
56
|
+
loading: !0,
|
|
57
|
+
pageType: void 0,
|
|
58
|
+
query: {
|
|
59
|
+
query: ""
|
|
60
|
+
},
|
|
61
|
+
response: {
|
|
62
|
+
query: ""
|
|
63
|
+
},
|
|
64
|
+
initialized: !1,
|
|
65
|
+
customParams: {}
|
|
66
|
+
};
|
|
67
|
+
function z(t) {
|
|
68
|
+
const e = /* @__PURE__ */ new Map();
|
|
69
|
+
let n = t ? w(O, t) : O;
|
|
70
|
+
const r = j(n);
|
|
71
|
+
function o(f) {
|
|
72
|
+
n = f(n);
|
|
73
|
+
for (const a of e.values())
|
|
74
|
+
a(n);
|
|
75
|
+
}
|
|
76
|
+
function i(f) {
|
|
77
|
+
o((a) => ({ ...a, ...f }));
|
|
78
|
+
}
|
|
79
|
+
function u() {
|
|
80
|
+
return n;
|
|
81
|
+
}
|
|
82
|
+
function s() {
|
|
83
|
+
return r;
|
|
84
|
+
}
|
|
85
|
+
function c(f, a) {
|
|
86
|
+
let y;
|
|
87
|
+
e.set(a, (P) => {
|
|
88
|
+
const g = f(P);
|
|
89
|
+
_(g, y) || (y = g, a(g));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function p(f) {
|
|
93
|
+
e.delete(f);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
updateState: i,
|
|
97
|
+
getState: u,
|
|
98
|
+
getInitialState: s,
|
|
99
|
+
onChange: c,
|
|
100
|
+
clearOnChange: p
|
|
5
101
|
};
|
|
6
102
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
103
|
+
const C = b(z({}));
|
|
104
|
+
function M({ store: t, children: e }) {
|
|
105
|
+
return /* @__PURE__ */ x(C, { value: t, children: e });
|
|
106
|
+
}
|
|
107
|
+
function V(t = T) {
|
|
108
|
+
const e = A(C), [n, r] = S(t(e.getState()));
|
|
109
|
+
return e.onChange(t, r), h(() => () => e.clearOnChange(r), [e]), n;
|
|
110
|
+
}
|
|
111
|
+
const T = (t) => t;
|
|
112
|
+
function F() {
|
|
113
|
+
const [t, e] = S([]), [n, r] = S([]);
|
|
114
|
+
return h(() => {
|
|
115
|
+
k(async (o) => {
|
|
116
|
+
const { products: i, segments: u } = await o.getSearchSessionParams();
|
|
117
|
+
e(u ?? []), r((i == null ? void 0 : i.personalizationBoost) ?? []);
|
|
20
118
|
});
|
|
21
119
|
}, []), {
|
|
22
|
-
segments:
|
|
23
|
-
boost:
|
|
120
|
+
segments: t,
|
|
121
|
+
boost: n
|
|
24
122
|
};
|
|
25
123
|
}
|
|
124
|
+
function I(t) {
|
|
125
|
+
return z(t);
|
|
126
|
+
}
|
|
26
127
|
export {
|
|
27
|
-
|
|
128
|
+
C as StoreContext,
|
|
129
|
+
M as StoreProvider,
|
|
130
|
+
I as mockStore,
|
|
131
|
+
V as useNostoAppState,
|
|
132
|
+
F as usePersonalization
|
|
28
133
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { State } from "@preact/store";
|
|
2
|
+
/**
|
|
3
|
+
* Imports a part of the Nosto state to the component.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```jsx
|
|
7
|
+
* import { useNostoAppState } from '@nosto/search-js/preact'
|
|
8
|
+
*
|
|
9
|
+
* export default () => {
|
|
10
|
+
* const pageType = useNostoAppState(state => state.pageType)
|
|
11
|
+
*
|
|
12
|
+
* return (
|
|
13
|
+
* <div>
|
|
14
|
+
* Page type is {pageType}
|
|
15
|
+
* </div>
|
|
16
|
+
* )
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* If the selector parameter is not provided, the full state is returned.
|
|
21
|
+
* Be mindful of the unnecessary rerenders it may cause.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```jsx
|
|
25
|
+
* import { useNostoAppState } from '@nosto/search-js/preact'
|
|
26
|
+
*
|
|
27
|
+
* export default () => {
|
|
28
|
+
* const state = useNostoAppState()
|
|
29
|
+
*
|
|
30
|
+
* return (
|
|
31
|
+
* <div>
|
|
32
|
+
* Page type is {state.pageType}
|
|
33
|
+
* </div>
|
|
34
|
+
* )
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @group Hooks
|
|
39
|
+
*/
|
|
40
|
+
export declare function useNostoAppState(): State;
|
|
41
|
+
export declare function useNostoAppState<Selected>(selector: (state: State) => Selected): Selected;
|