@nosto/search-js 1.5.1 → 1.6.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.
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-BVJZK90N.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;
@@ -1,3 +1,4 @@
1
1
  /** @module ./ */
2
+ export { addToCart, type SearchHitWithSku } from './src/addToCart';
2
3
  export { search } from './src/search';
3
4
  export type { DecoratedProduct, DecoratedResult, HitDecorator, Options, ToIntersection } from './src/types';
@@ -1,43 +1,9 @@
1
- import { s as a } from "../index.es-Bcd5IQh9.js";
2
- function s(t, r) {
3
- if (!t.products || !(r != null && r.length))
4
- return t;
5
- const e = (i) => r.reduce((u, n) => n(u), i);
6
- return {
7
- ...t,
8
- products: {
9
- ...t.products,
10
- hits: t.products.hits.map(e)
11
- }
12
- };
13
- }
14
- function o(t) {
15
- return new Promise((r) => setTimeout(r, t));
16
- }
17
- async function f(t, r, e) {
18
- const { maxRetries: i = 0, retryInterval: u = 1e3 } = e;
19
- let n = 0;
20
- for (; ; )
21
- try {
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);
29
- }
30
- }
31
- function h(t) {
32
- return !t || typeof t != "object" ? !1 : !("status" in t) || l(t.status);
33
- }
34
- function l(t) {
35
- return typeof t == "number" && (t < 400 || t >= 500);
36
- }
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);
1
+ import { L as c, s as d } from "../index.es-B8mbAxS4.js";
2
+ import { s as f } from "../search-B0-bVNMy.js";
3
+ async function e(r, a, o = 1) {
4
+ await c(a, void 0, o), await d(async (t) => await t.recordSearchAddToCart(r, a));
40
5
  }
41
6
  export {
42
- p as search
7
+ e as addToCart,
8
+ f as search
43
9
  };
@@ -0,0 +1,12 @@
1
+ import { SearchHit, SearchTrackOptions } from '@nosto/nosto-js/client';
2
+ export type SearchHitWithSku = SearchHit & {
3
+ skuId: string;
4
+ };
5
+ /**
6
+ * Adds a search hit to the cart.
7
+ *
8
+ * @param type - The type of search that the hit belongs to.
9
+ * @param hit - The search hit to add to the cart.
10
+ * @param quantity - The quantity of the hit to add to the cart.
11
+ */
12
+ export declare function addToCart(type: SearchTrackOptions, hit: SearchHitWithSku, quantity?: number): Promise<void>;
@@ -1 +1 @@
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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../index.es-DlUp67LT.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,4 +1,4 @@
1
- import { s as y } from "../index.es-Bcd5IQh9.js";
1
+ import { s as y } from "../index.es-B8mbAxS4.js";
2
2
  const p = {
3
3
  defaultCurrency: "EUR",
4
4
  defaultLocale: "en-US",
@@ -0,0 +1,27 @@
1
+ function t() {
2
+ window.nostojs = window.nostojs ?? function(o) {
3
+ (window.nostojs.q = window.nostojs.q ?? []).push(o);
4
+ };
5
+ }
6
+ async function u(o) {
7
+ return window.nostojs(o);
8
+ }
9
+ let i = null;
10
+ typeof window < "u" && (t(), u((o) => {
11
+ i = o.internal.getSettings();
12
+ }));
13
+ function a() {
14
+ return i;
15
+ }
16
+ async function d(o, w, s) {
17
+ var n;
18
+ if (!((n = window.Nosto) != null && n.addSkuToCart))
19
+ throw new Error("Nosto addSkuToCart function is not available");
20
+ await window.Nosto.addSkuToCart(o, w, s);
21
+ }
22
+ typeof window < "u" && t();
23
+ export {
24
+ d as L,
25
+ a as i,
26
+ u as s
27
+ };
@@ -0,0 +1 @@
1
+ "use strict";function t(){window.nostojs=window.nostojs??function(o){(window.nostojs.q=window.nostojs.q??[]).push(o)}}async function i(o){return window.nostojs(o)}let s=null;typeof window<"u"&&(t(),i(o=>{s=o.internal.getSettings()}));function a(){return s}async function d(o,w,u){var n;if(!((n=window.Nosto)!=null&&n.addSkuToCart))throw new Error("Nosto addSkuToCart function is not available");await window.Nosto.addSkuToCart(o,w,u)}typeof window<"u"&&t();exports.L=d;exports.i=a;exports.s=i;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("preact"),E=require("../index.es-D_7T9vdv.cjs"),p=require("preact/hooks"),W=require("../core/core.cjs.js");function X(e){return e.type==="input"}function Z(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function O(e,t={depth:0}){const{children:r}=e;return b.toChildArray(r).map(n=>{if(!Z(n))return n;const o=e.updateElement(n,t);return o===null?null:(o.props={...o.props,children:O({...e,children:o.props.children},{depth:t.depth+1})},o)})}function ee({children:e,onSearchInput:t}){return O({children:e,updateElement:r=>(!X(r)||r.props.type!=="search"||(r.props={...r.props,onInput:n=>{n.target instanceof HTMLInputElement&&t(n.target)}}),r)})}const N=b.createContext(null),B=()=>{const e=p.useContext(N);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e},te="nosto:search:scrollPos";function re(){window.sessionStorage.setItem(te,window.scrollY.toString())}function ne({children:e,hit:t,onClick:r}){const{pageType:n}=B(),o=n==="autocomplete"?void 0:n;return O({children:e,updateElement:(u,a)=>(a.depth>0||(u.props={...u.props,onClick:c=>{t&&o&&E.s(l=>l.recordSearchClick(o,t)),re(),typeof r=="function"&&r(c)}}),u)})}var oe=0;function w(e,t,r,n,o,u){t||(t={});var a,c,l=t;if("ref"in l)for(c in l={},t)c=="ref"?a=t[c]:l[c]=t[c];var s={type:e,props:l,key:r,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--oe,__i:-1,__u:0,__source:o,__self:u};if(typeof e=="function"&&(a=e.defaultProps))for(c in a)l[c]===void 0&&(l[c]=a[c]);return b.options.vnode&&b.options.vnode(s),s}function q(){p.useEffect(()=>{const e=window.setTimeout(()=>{console.error("Nosto client script has not loaded after 3 seconds.")},3e3);E.s(()=>{window.clearTimeout(e)})},[])}const $=e=>String(e)==="[object Object]";function k(e){if(!$(e))return!1;const t=e.constructor;if(t===void 0)return!0;const r=t.prototype;return!(!$(r)||!r.hasOwnProperty("isPrototypeOf"))}function x(...e){return e.reduce((t,r)=>z(t,r))}function D(...e){return e.reduce((t,r)=>z(t,r))}function z(e,t){return k(e)&&k(t)?Object.entries(t).reduce((r,[n,o])=>(r[n]=z(r[n],o),r),{...e}):k(e)?e:t}function F(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)=>F(r,t[n]));if(k(e)&&k(t)){const r=Object.entries(e);return r.length!==Object.keys(t).length?!1:r.every(([n,o])=>F(o,t[n]))}return!1}function K(e,t={}){const r=new Map;let n=D(e,t??{});const o=D(e,t);function u(i){n=i(n);for(const f of r.values())f(n)}function a(i){u(f=>({...f,...i}))}function c(){return n}function l(){return structuredClone(o)}function s(i,f){let S;r.set(f,g=>{const y=i(g);F(y,S)||(S=y,f(y))})}function d(i){r.delete(i)}return{updateState:a,getState:c,getInitialState:l,onChange:s,clearOnChange:d}}const Q={loading:!0,query:{query:""},response:{query:""},initialized:!1};function A(e={}){return K(Q,e)}const P=b.createContext(A()),j={defaultCurrency:"EUR",queryModifications:e=>e},se={...j};function ce(e){return{pageType:"autocomplete",...se,...e}}function ae({config:e,store:t,children:r}){const n=t??A();return q(),w(N,{value:ce(e),children:w(P,{value:n,children:r})})}const ie={...j,persistentSearchCache:!1,preservePageScroll:!1};function ue(e){return{pageType:"category",...ie,...e}}function le({config:e,store:t,children:r}){const n=t??A();return q(),w(N,{value:ue(e),children:w(P,{value:n,children:r})})}const de={...j,persistentSearchCache:!1,preservePageScroll:!1};function fe(e={}){return{pageType:"serp",...de,...e}}function ge({config:e,store:t,children:r}){const n=t??A();return q(),w(N,{value:fe(e),children:w(P,{value:n,children:r})})}function pe(e){return Array.from(new Set(e))}function me(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:Se,...t.products},...t.keywords?{keywords:{...t.keywords,fields:pe([...ye,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const Se=["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"],ye=["keyword","_redirect"];function he(...e){if(!e.every(t=>t==null))return e.filter(t=>Array.isArray(t)).reduce((t,r)=>t.concat(r),[])}const H="nosto.search.";function Ce(e){var r;const t=`${H}${e}`;(r=window.performance)==null||r.mark(`${t}.start`)}function ve(e){var r,n;const t=`${H}${e}`;(r=window.performance)==null||r.mark(`${t}.end`),(n=window.performance)==null||n.measure(t,`${t}.start`,`${t}.end`)}function I(e){return Ce(e),()=>ve(e)}function ke(e,t,r){const n=JSON.stringify(t);try{console.info("Setting storage",e,n),r.setItem(e,n)}catch(o){console.warn(o)}}function we(e,t){try{const r=t.getItem(e);if(r)return JSON.parse(r)}catch(r){console.warn(r)}}function Pe(e,t){ke(e,t,sessionStorage)}function be(e){return we(e,sessionStorage)}const L="nosto:search:searchResult";function Fe(e,t,r){if(!e)return;Pe(L,{query:t,result:r})}function Ae(e,t){if(!e)return null;const r=be(L);if(!r||!Re(r))return null;const n=U(r.query);return F(U(t),n)?r.result:null}function U(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 Re(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function G(e,t,r){var s,d,i;const n=I("newSearch"),o=e.config.pageType,u=x(e.store.getInitialState().query,t),a=x(e.config.search,r,{track:o,redirect:o!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword)});e.store.updateState({query:u,loading:!0,initialized:!0});const c=o!=="autocomplete"&&e.config.persistentSearchCache,l=e.config.queryModifications({...u,products:{...u.products,filter:he((d=(s=e.store.getInitialState().query)==null?void 0:s.products)==null?void 0:d.filter,(i=t.products)==null?void 0:i.filter)}},o);try{let f;const S=Ae(c,l);if(S)f=S;else{const g=me(o,l);f=await W.search(g,a),Fe(c,l,f)}e.store.updateState({response:f,loading:!1})}catch(f){console.error("Search action failed",f)}n()}async function V(e,t,r){const n=I("updateSearch"),o=x(e.store.getState().query,{products:{from:0}},t);await G(e,o,r),n()}async function Me(e,t,r){var a;const n=I("replaceFilter"),o=(a=e.store.getState().query.products)==null?void 0:a.filter,u=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await V(e,{products:{filter:[...(o==null?void 0:o.filter(c=>c.field!==t))??[],...u]}}),n()}async function _e(e,t,r,n){var l,s;const o=I("toggleProductFilter"),u=(l=e.store.getState().query.products)==null?void 0:l.filter,a=u==null?void 0:u.find(d=>d.value instanceof Array&&d.field===t),c=a!=null&&a.value?{...a,value:[...a.value.filter(d=>!F(d,r)),...n?[r]:[]]}:n?{field:t,value:[r]}:void 0;await V(e,{products:{filter:[...(u==null?void 0:u.filter(d=>d!==a))??[],...(s=c==null?void 0:c.value)!=null&&s.length?[c]:[]]}}),o()}function v(){const e=B(),t=p.useContext(P),r=p.useMemo(()=>({config:e,store:t}),[e,t]),n=p.useCallback((c,l)=>G(r,c,l),[r]),o=p.useCallback((c,l)=>V(r,c,l),[r]),u=p.useCallback((c,l,s)=>_e(r,c,l,s),[r]),a=p.useCallback((c,l)=>Me(r,c,l),[r]);return{newSearch:n,updateSearch:o,toggleProductFilter:u,replaceFilter:a}}function C(e=Ne){const t=p.useContext(P),[r,n]=p.useState(e(t.getState()));return t.onChange(e,n),p.useEffect(()=>()=>t.clearOnChange(n),[t]),r}const Ne=e=>e;function Ie(e){const t=C(r=>r.response);return e&&Array.isArray(e)||e&&k(e)?e:t}function Te(e){var a;const t=((a=e.data)==null?void 0:a.filter(c=>c.selected).length)??0,[r,n]=p.useState(t>0),{toggleProductFilter:o}=v();return{active:r,selectedFiltersCount:t,toggleActive:()=>{n(!r)},toggleProductFilter:o}}function xe(){const{loading:e,facets:t}=C(r=>{var n,o;return{loading:r.loading,facets:((o=(n=r.response)==null?void 0:n.products)==null?void 0:o.facets)??[]}});return{loading:e,facets:t}}function Ee(){const[e,t]=p.useState([]),[r,n]=p.useState([]);return p.useEffect(()=>{E.s(async o=>{const{products:u,segments:a}=await o.getSearchSessionParams();t(a??[]),n((u==null?void 0:u.personalizationBoost)??[])})},[]),{segments:e,boost:r}}function Oe(){const{facets:e}=C(s=>{var d;return{facets:((d=s.response.products)==null?void 0:d.facets)??[]}}),{replaceFilter:t,toggleProductFilter:r}=v(),n=p.useCallback(s=>{const d=e==null?void 0:e.find(i=>i.type==="stats"&&i.field===s);if(d&&"min"in d&&"max"in d)return d},[e]),o=p.useCallback(s=>{var d;return((d=e==null?void 0:e.find(i=>i.field===s))==null?void 0:d.name)??s},[e]),u=p.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),a=p.useCallback(s=>{var d;return{...s,range:(d=s.range)==null?void 0:d.map(i=>({gt:i.gt?Number(i.gt):i.gt,gte:i.gte?Number(i.gte):i.gte,lt:i.lt?Number(i.lt):i.lt,lte:i.lte?Number(i.lte):i.lte}))}},[]),c=p.useCallback(s=>(s.value??[]).map(i=>({value:i,field:s.field,name:o(s.field),filter:a(s),remove:()=>{r(s.field,i,!1)}})),[a,o,r]),l=p.useCallback(s=>(s.range??[]).map(i=>{var g,y;const f=i.gte??i.gt??((g=n(s.field))==null?void 0:g.min),S=i.lte??i.lt??((y=n(s.field))==null?void 0:y.max);if(f!==void 0&&S!==void 0)return{value:`${f} - ${S}`,field:s.field,name:o(s.field),filter:a(s),remove:()=>{t(s.field,void 0)}}}).filter(Boolean),[a,n,o,t]);return{selectFilters:u,toValueFilter:c,toRangeFilter:l}}function J(){const{filter:e}=C(c=>{var l;return{filter:((l=c.query.products)==null?void 0:l.filter)??[]}}),{updateSearch:t}=v(),{selectFilters:r,toValueFilter:n,toRangeFilter:o}=Oe(),u=p.useMemo(()=>e?e.filter(r).flatMap(c=>"value"in c?n(c):"range"in c?o(c):[]).filter(Boolean):[],[e,r,o,n]),a=p.useCallback(()=>{t({products:{filter:[]}})},[t]);return{filters:u,removeAll:a}}function _(e){if(typeof e=="number")return e;if(typeof e!="string")return;const t=Number(e);return isNaN(t)?void 0:t}function Y(e){var i,f,S;const{replaceFilter:t}=v(),{query:r,products:n}=C(g=>({query:g.query,products:g.response.products})),o=(i=n==null?void 0:n.facets)==null?void 0:i.find(g=>g.id===e);if(!o)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const u=(S=(f=r.products)==null?void 0:f.filter)==null?void 0:S.find(g=>g.field===o.field),a=u!=null&&u.range?u.range[0]:void 0,c=typeof a=="object"&&("gte"in a||"lte"in a)?[_(a.gte),_(a.lte)]:[void 0,void 0],l="min"in o?Math.floor(o.min):0,s="max"in o?Math.ceil(o.max):0,d=([g,y])=>{const m=g!==void 0?Math.floor(g):void 0,h=y!==void 0?Math.ceil(y):void 0,R=m!==void 0,M=h!==void 0;(l===m||!R)&&(s===h||!M)?t(o.field,void 0):(l===m||!R)&&M?t(o.field,{lte:h.toString()}):(s===h||!M)&&R?t(o.field,{gte:m.toString()}):R&&M&&t(o.field,{gte:m.toString(),lte:h.toString()})};return{min:l,max:s,range:[c[0]??l,c[1]??s],updateRange:d}}function qe(e,t){const{min:r,max:n,range:o,updateRange:u}=Y(e),{filters:a}=J(),c=p.useMemo(()=>{var y;const i=a.find(m=>{var h;return(h=m==null?void 0:m.filter)==null?void 0:h.range});let f=null;if(i){const m=(y=i.filter.range)==null?void 0:y[0];f=[_(m==null?void 0:m.gte),_(m==null?void 0:m.lte)]}const S=[];let g=Math.floor(r/t)*t;for(;g<n;){const m=g+t,h=f&&f[0]===g&&f[1]===m;S.push({min:g,max:m,selected:h}),g=m}return S},[a,r,n,t]),l=i=>{u([i,o[1]])},s=i=>{u([o[0],i])},d=r!==o[0]||n!==o[1];return{min:r,max:n,range:o,updateRange:u,ranges:c,handleMinChange:l,handleMaxChange:s,isSelected:d}}function ze(){const{products:e,keywords:t}=C(r=>r.response);return{products:e??{hits:[],total:0},keywords:t??{hits:[],total:0}}}function je(){const e=C(r=>{var n;return(n=r.query.products)==null?void 0:n.filter});return p.useMemo(()=>e?e.reduce((r,n)=>r+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function T(e){return e&&!Number.isNaN(e)?e:0}function Ve(e,t){const{from:r,size:n,total:o}=C(s=>{var d,i,f,S,g;return{from:T(((d=s.query.products)==null?void 0:d.from)??0),size:T(((f=(i=s.response)==null?void 0:i.products)==null?void 0:f.size)??0),total:T(((g=(S=s.response)==null?void 0:S.products)==null?void 0:g.total)??0)}}),{updateSearch:u}=v(),a=r+n,c=[...e].reverse().filter(s=>s+t<o);return{from:r,to:a,total:o,size:n,sizeOptions:c,handleSizeChange:s=>{u({products:{size:s}})}}}function $e(e,t){return e.length!==t.length?!1:e.every(r=>t.find(n=>r.field===n.field&&r.order===n.order))}function De(e){var u,a;const t=C(c=>c.query),{updateSearch:r}=v();return{activeSort:((u=e.find(c=>{var l;return $e(c.value.sort,((l=t.products)==null?void 0:l.sort)||[])}))==null?void 0:u.id)??((a=e[0])==null?void 0:a.id),setSort:c=>{const l=e.find(s=>s.id===c);l&&r({products:{sort:l.value.sort}})}}}exports.AutocompletePageProvider=ae;exports.CategoryPageProvider=le;exports.SearchInput=ee;exports.SearchPageProvider=ge;exports.SerpElement=ne;exports.StoreContext=P;exports.createExtendableStore=K;exports.createStore=A;exports.defaultState=Q;exports.useActions=v;exports.useDecoratedSearchResults=Ie;exports.useFacet=Te;exports.useFacets=xe;exports.useNostoAppState=C;exports.usePersonalization=Ee;exports.useProductFilters=J;exports.useRange=Y;exports.useRangeSelector=qe;exports.useResponse=ze;exports.useSelectedFiltersCount=je;exports.useSizeOptions=Ve;exports.useSort=De;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("preact"),q=require("../index.es-DlUp67LT.cjs"),p=require("preact/hooks"),W=require("../search-BVJZK90N.cjs");function X(e){return e.type==="input"}function Z(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function z(e,t={depth:0}){const{children:r}=e;return A.toChildArray(r).map(n=>{if(!Z(n))return n;const o=e.updateElement(n,t);return o===null?null:(o.props={...o.props,children:z({...e,children:o.props.children},{depth:t.depth+1})},o)})}function ee({children:e,onSearchInput:t}){return z({children:e,updateElement:r=>(!X(r)||r.props.type!=="search"||(r.props={...r.props,onInput:n=>{n.target instanceof HTMLInputElement&&t(n.target)}}),r)})}const N=A.createContext(null),B=()=>{const e=p.useContext(N);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e},te="nosto:search:scrollPos";function re(){window.sessionStorage.setItem(te,window.scrollY.toString())}function ne({children:e,hit:t,onClick:r}){const{pageType:n}=B(),o=n==="autocomplete"?void 0:n;return z({children:e,updateElement:(a,c)=>(c.depth>0||(a.props={...a.props,onClick:s=>{t&&o&&q.s(l=>l.recordSearchClick(o,t)),re(),typeof r=="function"&&r(s)}}),a)})}var oe=0;function F(e,t,r,n,o,a){t||(t={});var c,s,l=t;if("ref"in l)for(s in l={},t)s=="ref"?c=t[s]:l[s]=t[s];var i={type:e,props:l,key:r,ref:c,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--oe,__i:-1,__u:0,__source:o,__self:a};if(typeof e=="function"&&(c=e.defaultProps))for(s in c)l[s]===void 0&&(l[s]=c[s]);return A.options.vnode&&A.options.vnode(i),i}function E(){p.useEffect(()=>{const e=window.setTimeout(()=>{console.error("Nosto client script has not loaded after 3 seconds.")},3e3);q.s(()=>{window.clearTimeout(e)})},[])}const $=e=>String(e)==="[object Object]";function w(e){if(!$(e))return!1;const t=e.constructor;if(t===void 0)return!0;const r=t.prototype;return!(!$(r)||!r.hasOwnProperty("isPrototypeOf"))}function x(...e){return e.reduce((t,r)=>O(t,r))}function D(...e){return e.reduce((t,r)=>O(t,r))}function O(e,t){return w(e)&&w(t)?Object.entries(t).reduce((r,[n,o])=>(r[n]=O(r[n],o),r),{...e}):w(e)?e:t}function M(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)=>M(r,t[n]));if(w(e)&&w(t)){const r=Object.entries(e);return r.length!==Object.keys(t).length?!1:r.every(([n,o])=>M(o,t[n]))}return!1}function K(e,t={}){const r=new Map;let n=D(e,t??{});const o=D(e,t);function a(u){n=u(n);for(const d of r.values())d(n)}function c(u){a(d=>({...d,...u}))}function s(){return n}function l(){return structuredClone(o)}function i(u,d){let h;r.set(d,g=>{const y=u(g);M(y,h)||(h=y,d(y))})}function f(u){r.delete(u)}return{updateState:c,getState:s,getInitialState:l,onChange:i,clearOnChange:f}}const Q={loading:!0,query:{query:""},response:{query:""},initialized:!1};function R(e={}){return K(Q,e)}const b=A.createContext(R()),j={defaultCurrency:"EUR",queryModifications:e=>e},se={...j};function ce(e){return{pageType:"autocomplete",...se,...e}}function ie({config:e,store:t,children:r}){const n=t??R();return E(),F(N,{value:ce(e),children:F(b,{value:n,children:r})})}const ae={...j,persistentSearchCache:!1,preservePageScroll:!1};function ue(e){return{pageType:"category",...ae,...e}}function le({config:e,store:t,children:r}){const n=t??R();return E(),F(N,{value:ue(e),children:F(b,{value:n,children:r})})}const fe={...j,persistentSearchCache:!1,preservePageScroll:!1};function de(e={}){return{pageType:"serp",...fe,...e}}function ge({config:e,store:t,children:r}){const n=t??R();return E(),F(N,{value:de(e),children:F(b,{value:n,children:r})})}function pe(e){return Array.from(new Set(e))}function me(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:he,...t.products},...t.keywords?{keywords:{...t.keywords,fields:pe([...ye,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const he=["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"],ye=["keyword","_redirect"];function Se(...e){if(!e.every(t=>t==null))return e.filter(t=>Array.isArray(t)).reduce((t,r)=>t.concat(r),[])}const H="nosto.search.";function ve(e){var r;const t=`${H}${e}`;(r=window.performance)==null||r.mark(`${t}.start`)}function Ce(e){var r,n;const t=`${H}${e}`;(r=window.performance)==null||r.mark(`${t}.end`),(n=window.performance)==null||n.measure(t,`${t}.start`,`${t}.end`)}function I(e){return ve(e),()=>Ce(e)}function Pe(e,t,r){const n=JSON.stringify(t);try{console.info("Setting storage",e,n),r.setItem(e,n)}catch(o){console.warn(o)}}function ke(e,t){try{const r=t.getItem(e);if(r)return JSON.parse(r)}catch(r){console.warn(r)}}function we(e,t){Pe(e,t,sessionStorage)}function Fe(e){return ke(e,sessionStorage)}const L="nosto:search:searchResult";function be(e,t,r){if(!e)return;we(L,{query:t,result:r})}function Ae(e,t){if(!e)return null;const r=Fe(L);if(!r||!Me(r))return null;const n=U(r.query);return M(U(t),n)?r.result:null}function U(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 Me(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function G(e,t,r){var i,f,u;const n=I("newSearch"),o=e.config.pageType,a=x(e.store.getInitialState().query,t),c=x(e.config.search,r,{track:o,redirect:o!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword)});e.store.updateState({query:a,loading:!0,initialized:!0});const s=o!=="autocomplete"&&e.config.persistentSearchCache,l=e.config.queryModifications({...a,products:{...a.products,filter:Se((f=(i=e.store.getInitialState().query)==null?void 0:i.products)==null?void 0:f.filter,(u=t.products)==null?void 0:u.filter)}},o);try{let d;const h=Ae(s,l);if(h)d=h;else{const g=me(o,l);d=await W.search(g,c),be(s,l,d)}e.store.updateState({response:d,loading:!1})}catch(d){console.error("Search action failed",d)}n()}async function V(e,t,r){const n=I("updateSearch"),o=x(e.store.getState().query,{products:{from:0}},t);await G(e,o,r),n()}async function Re(e,t,r){var c;const n=I("replaceFilter"),o=(c=e.store.getState().query.products)==null?void 0:c.filter,a=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await V(e,{products:{filter:[...(o==null?void 0:o.filter(s=>s.field!==t))??[],...a]}}),n()}async function _e(e,t,r,n){var l,i;const o=I("toggleProductFilter"),a=(l=e.store.getState().query.products)==null?void 0:l.filter,c=a==null?void 0:a.find(f=>f.value instanceof Array&&f.field===t),s=c!=null&&c.value?{...c,value:[...c.value.filter(f=>!M(f,r)),...n?[r]:[]]}:n?{field:t,value:[r]}:void 0;await V(e,{products:{filter:[...(a==null?void 0:a.filter(f=>f!==c))??[],...(i=s==null?void 0:s.value)!=null&&i.length?[s]:[]]}}),o()}function k(){const e=B(),t=p.useContext(b),r=p.useMemo(()=>({config:e,store:t}),[e,t]),n=p.useCallback((s,l)=>G(r,s,l),[r]),o=p.useCallback((s,l)=>V(r,s,l),[r]),a=p.useCallback((s,l,i)=>_e(r,s,l,i),[r]),c=p.useCallback((s,l)=>Re(r,s,l),[r]);return{newSearch:n,updateSearch:o,toggleProductFilter:a,replaceFilter:c}}function C(e=Ne){const t=p.useContext(b),[r,n]=p.useState(e(t.getState()));return t.onChange(e,n),p.useEffect(()=>()=>t.clearOnChange(n),[t]),r}const Ne=e=>e;function Ie(e){const t=C(r=>r.response);return e&&Array.isArray(e)||e&&w(e)?e:t}function Te(e){var c;const t=((c=e.data)==null?void 0:c.filter(s=>s.selected).length)??0,[r,n]=p.useState(t>0),{toggleProductFilter:o}=k();return{active:r,selectedFiltersCount:t,toggleActive:()=>{n(!r)},toggleProductFilter:o}}function xe(){const{loading:e,facets:t}=C(r=>{var n,o;return{loading:r.loading,facets:((o=(n=r.response)==null?void 0:n.products)==null?void 0:o.facets)??[]}});return{loading:e,facets:t}}function qe(e,t){const r=t-e;return!isNaN(r)&&r>0?new Array(t-e).fill(void 0).map((n,o)=>o+e):[]}function ze(e){const{query:t,products:r}=C(n=>({query:n.query,products:n.response.products}));return p.useMemo(()=>{var P;if(!r)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((P=t.products)==null?void 0:P.from)??0,o=(e==null?void 0:e.width)??1/0,a=Math.max(Math.floor(o-1)/2,1),c=r.size>0?Math.floor(n/r.size)+1:1,s=r.size>0?Math.ceil(r.total/r.size):0,l=v=>v>=c-a&&v<=c+a,i=n+1,f=Math.min(n+r.total,r.total),u={from:n,page:c,current:!0},d=v=>({from:(v-1)*r.size,page:v,current:v===c}),h=c>1?d(c-1):void 0,g=c<s?d(c+1):void 0,y=a===1/0||c-a-1>1?d(1):void 0,m=a===1/0||c+a+1<s?d(s):void 0,S=qe(1,s+1).filter(l).map(d);return{totalPages:s,resultsFrom:i,resultsTo:f,current:u,prev:h,next:g,first:y,last:m,pages:S}},[t,r,e==null?void 0:e.width])}function Ee(){const[e,t]=p.useState([]),[r,n]=p.useState([]);return p.useEffect(()=>{q.s(async o=>{const{products:a,segments:c}=await o.getSearchSessionParams();t(c??[]),n((a==null?void 0:a.personalizationBoost)??[])})},[]),{segments:e,boost:r}}function Oe(){const{facets:e}=C(i=>{var f;return{facets:((f=i.response.products)==null?void 0:f.facets)??[]}}),{replaceFilter:t,toggleProductFilter:r}=k(),n=p.useCallback(i=>{const f=e==null?void 0:e.find(u=>u.type==="stats"&&u.field===i);if(f&&"min"in f&&"max"in f)return f},[e]),o=p.useCallback(i=>{var f;return((f=e==null?void 0:e.find(u=>u.field===i))==null?void 0:f.name)??i},[e]),a=p.useCallback(i=>"field"in i&&(i.value instanceof Array||i.range instanceof Array),[]),c=p.useCallback(i=>{var f;return{...i,range:(f=i.range)==null?void 0:f.map(u=>({gt:u.gt?Number(u.gt):u.gt,gte:u.gte?Number(u.gte):u.gte,lt:u.lt?Number(u.lt):u.lt,lte:u.lte?Number(u.lte):u.lte}))}},[]),s=p.useCallback(i=>(i.value??[]).map(u=>({value:u,field:i.field,name:o(i.field),filter:c(i),remove:()=>{r(i.field,u,!1)}})),[c,o,r]),l=p.useCallback(i=>(i.range??[]).map(u=>{var g,y;const d=u.gte??u.gt??((g=n(i.field))==null?void 0:g.min),h=u.lte??u.lt??((y=n(i.field))==null?void 0:y.max);if(d!==void 0&&h!==void 0)return{value:`${d} - ${h}`,field:i.field,name:o(i.field),filter:c(i),remove:()=>{t(i.field,void 0)}}}).filter(Boolean),[c,n,o,t]);return{selectFilters:a,toValueFilter:s,toRangeFilter:l}}function J(){const{filter:e}=C(s=>{var l;return{filter:((l=s.query.products)==null?void 0:l.filter)??[]}}),{updateSearch:t}=k(),{selectFilters:r,toValueFilter:n,toRangeFilter:o}=Oe(),a=p.useMemo(()=>e?e.filter(r).flatMap(s=>"value"in s?n(s):"range"in s?o(s):[]).filter(Boolean):[],[e,r,o,n]),c=p.useCallback(()=>{t({products:{filter:[]}})},[t]);return{filters:a,removeAll:c}}function _(e){if(typeof e=="number")return e;if(typeof e!="string")return;const t=Number(e);return isNaN(t)?void 0:t}function Y(e){var u,d,h;const{replaceFilter:t}=k(),{query:r,products:n}=C(g=>({query:g.query,products:g.response.products})),o=(u=n==null?void 0:n.facets)==null?void 0:u.find(g=>g.id===e);if(!o)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const a=(h=(d=r.products)==null?void 0:d.filter)==null?void 0:h.find(g=>g.field===o.field),c=a!=null&&a.range?a.range[0]:void 0,s=typeof c=="object"&&("gte"in c||"lte"in c)?[_(c.gte),_(c.lte)]:[void 0,void 0],l="min"in o?Math.floor(o.min):0,i="max"in o?Math.ceil(o.max):0,f=([g,y])=>{const m=g!==void 0?Math.floor(g):void 0,S=y!==void 0?Math.ceil(y):void 0,P=m!==void 0,v=S!==void 0;(l===m||!P)&&(i===S||!v)?t(o.field,void 0):(l===m||!P)&&v?t(o.field,{lte:S.toString()}):(i===S||!v)&&P?t(o.field,{gte:m.toString()}):P&&v&&t(o.field,{gte:m.toString(),lte:S.toString()})};return{min:l,max:i,range:[s[0]??l,s[1]??i],updateRange:f}}function je(e,t){const{min:r,max:n,range:o,updateRange:a}=Y(e),{filters:c}=J(),s=p.useMemo(()=>{var y;const u=c.find(m=>{var S;return(S=m==null?void 0:m.filter)==null?void 0:S.range});let d=null;if(u){const m=(y=u.filter.range)==null?void 0:y[0];d=[_(m==null?void 0:m.gte),_(m==null?void 0:m.lte)]}const h=[];let g=Math.floor(r/t)*t;for(;g<n;){const m=g+t,S=d&&d[0]===g&&d[1]===m;h.push({min:g,max:m,selected:S}),g=m}return h},[c,r,n,t]),l=u=>{a([u,o[1]])},i=u=>{a([o[0],u])},f=r!==o[0]||n!==o[1];return{min:r,max:n,range:o,updateRange:a,ranges:s,handleMinChange:l,handleMaxChange:i,isSelected:f}}function Ve(){const{products:e,keywords:t}=C(r=>r.response);return{products:e??{hits:[],total:0},keywords:t??{hits:[],total:0}}}function $e(){const e=C(r=>{var n;return(n=r.query.products)==null?void 0:n.filter});return p.useMemo(()=>e?e.reduce((r,n)=>r+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function T(e){return e&&!Number.isNaN(e)?e:0}function De(e,t){const{from:r,size:n,total:o}=C(i=>{var f,u,d,h,g;return{from:T(((f=i.query.products)==null?void 0:f.from)??0),size:T(((d=(u=i.response)==null?void 0:u.products)==null?void 0:d.size)??0),total:T(((g=(h=i.response)==null?void 0:h.products)==null?void 0:g.total)??0)}}),{updateSearch:a}=k(),c=r+n,s=[...e].reverse().filter(i=>i+t<o);return{from:r,to:c,total:o,size:n,sizeOptions:s,handleSizeChange:i=>{a({products:{size:i}})}}}function Ue(e,t){return e.length!==t.length?!1:e.every(r=>t.find(n=>r.field===n.field&&r.order===n.order))}function Be(e){var a,c;const t=C(s=>s.query),{updateSearch:r}=k();return{activeSort:((a=e.find(s=>{var l;return Ue(s.value.sort,((l=t.products)==null?void 0:l.sort)||[])}))==null?void 0:a.id)??((c=e[0])==null?void 0:c.id),setSort:s=>{const l=e.find(i=>i.id===s);l&&r({products:{sort:l.value.sort}})}}}exports.AutocompletePageProvider=ie;exports.CategoryPageProvider=le;exports.SearchInput=ee;exports.SearchPageProvider=ge;exports.SerpElement=ne;exports.StoreContext=b;exports.createExtendableStore=K;exports.createStore=R;exports.defaultState=Q;exports.useActions=k;exports.useDecoratedSearchResults=Ie;exports.useFacet=Te;exports.useFacets=xe;exports.useNostoAppState=C;exports.usePagination=ze;exports.usePersonalization=Ee;exports.useProductFilters=J;exports.useRange=Y;exports.useRangeSelector=je;exports.useResponse=Ve;exports.useSelectedFiltersCount=$e;exports.useSizeOptions=De;exports.useSort=Be;
@@ -12,6 +12,7 @@ export { useDecoratedSearchResults } from './src/hooks/useDecoratedSearchResults
12
12
  export { useFacet } from './src/hooks/useFacet';
13
13
  export { useFacets } from './src/hooks/useFacets';
14
14
  export { useNostoAppState } from './src/hooks/useNostoAppState';
15
+ export { type Page, usePagination } from './src/hooks/usePagination';
15
16
  export { usePersonalization } from './src/hooks/usePersonalization';
16
17
  export { useProductFilters } from './src/hooks/useProductFilters/useProductFilters';
17
18
  export { useRange } from './src/hooks/useRange';
@@ -1,7 +1,7 @@
1
1
  import { toChildArray as X, createContext as L, options as B } from "preact";
2
- import { s as O } from "../index.es-Bcd5IQh9.js";
3
- import { useContext as q, useEffect as z, useMemo as N, useCallback as h, useState as R } from "preact/hooks";
4
- import { search as Z } from "../core/core.es.js";
2
+ import { s as q } from "../index.es-B8mbAxS4.js";
3
+ import { useContext as E, useEffect as O, useMemo as b, useCallback as v, useState as _ } from "preact/hooks";
4
+ import { s as Z } from "../search-B0-bVNMy.js";
5
5
  function ee(e) {
6
6
  return e.type === "input";
7
7
  }
@@ -20,7 +20,7 @@ function V(e, t = { depth: 0 }) {
20
20
  }, o);
21
21
  });
22
22
  }
23
- function Ve({ children: e, onSearchInput: t }) {
23
+ function $e({ children: e, onSearchInput: t }) {
24
24
  return V({
25
25
  children: e,
26
26
  updateElement: (r) => (!ee(r) || r.props.type !== "search" || (r.props = {
@@ -31,8 +31,8 @@ function Ve({ children: e, onSearchInput: t }) {
31
31
  }), r)
32
32
  });
33
33
  }
34
- const M = L(null), G = () => {
35
- const e = q(M);
34
+ const R = L(null), G = () => {
35
+ const e = E(R);
36
36
  if (!e)
37
37
  throw new Error("useConfig must be used within a ConfigProvider");
38
38
  return e;
@@ -40,39 +40,39 @@ const M = L(null), G = () => {
40
40
  function ne() {
41
41
  window.sessionStorage.setItem(re, window.scrollY.toString());
42
42
  }
43
- function $e({ children: e, hit: t, onClick: r }) {
43
+ function je({ children: e, hit: t, onClick: r }) {
44
44
  const { pageType: n } = G(), o = n === "autocomplete" ? void 0 : n;
45
45
  return V({
46
46
  children: e,
47
- updateElement: (u, c) => (c.depth > 0 || (u.props = {
47
+ updateElement: (u, i) => (i.depth > 0 || (u.props = {
48
48
  ...u.props,
49
- onClick: (i) => {
50
- t && o && O((l) => l.recordSearchClick(o, t)), ne(), typeof r == "function" && r(i);
49
+ onClick: (s) => {
50
+ t && o && q((l) => l.recordSearchClick(o, t)), ne(), typeof r == "function" && r(s);
51
51
  }
52
52
  }), u)
53
53
  });
54
54
  }
55
55
  var oe = 0;
56
- function w(e, t, r, n, o, u) {
56
+ function k(e, t, r, n, o, u) {
57
57
  t || (t = {});
58
- var c, i, l = t;
59
- if ("ref" in l) for (i in l = {}, t) i == "ref" ? c = t[i] : l[i] = t[i];
60
- var s = { type: e, props: l, key: r, ref: c, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --oe, __i: -1, __u: 0, __source: o, __self: u };
61
- if (typeof e == "function" && (c = e.defaultProps)) for (i in c) l[i] === void 0 && (l[i] = c[i]);
62
- return B.vnode && B.vnode(s), s;
58
+ var i, s, l = t;
59
+ if ("ref" in l) for (s in l = {}, t) s == "ref" ? i = t[s] : l[s] = t[s];
60
+ var c = { type: e, props: l, key: r, ref: i, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --oe, __i: -1, __u: 0, __source: o, __self: u };
61
+ if (typeof e == "function" && (i = e.defaultProps)) for (s in i) l[s] === void 0 && (l[s] = i[s]);
62
+ return B.vnode && B.vnode(c), c;
63
63
  }
64
64
  function $() {
65
- z(() => {
65
+ O(() => {
66
66
  const e = window.setTimeout(() => {
67
67
  console.error("Nosto client script has not loaded after 3 seconds.");
68
68
  }, 3e3);
69
- O(() => {
69
+ q(() => {
70
70
  window.clearTimeout(e);
71
71
  });
72
72
  }, []);
73
73
  }
74
74
  const K = (e) => String(e) === "[object Object]";
75
- function C(e) {
75
+ function P(e) {
76
76
  if (!K(e))
77
77
  return !1;
78
78
  const t = e.constructor;
@@ -81,28 +81,28 @@ function C(e) {
81
81
  const r = t.prototype;
82
82
  return !(!K(r) || !r.hasOwnProperty("isPrototypeOf"));
83
83
  }
84
- function E(...e) {
84
+ function z(...e) {
85
85
  return e.reduce((t, r) => j(t, r));
86
86
  }
87
87
  function Q(...e) {
88
88
  return e.reduce((t, r) => j(t, r));
89
89
  }
90
90
  function j(e, t) {
91
- return C(e) && C(t) ? Object.entries(t).reduce(
91
+ return P(e) && P(t) ? Object.entries(t).reduce(
92
92
  (r, [n, o]) => (r[n] = j(r[n], o), r),
93
93
  { ...e }
94
- ) : C(e) ? e : t;
94
+ ) : P(e) ? e : t;
95
95
  }
96
- function P(e, t) {
96
+ function A(e, t) {
97
97
  if (e === t)
98
98
  return !0;
99
99
  if (e instanceof Date && t instanceof Date)
100
100
  return e.getTime() === t.getTime();
101
101
  if (Array.isArray(e) && Array.isArray(t))
102
- return e.length !== t.length ? !1 : e.every((r, n) => P(r, t[n]));
103
- if (C(e) && C(t)) {
102
+ return e.length !== t.length ? !1 : e.every((r, n) => A(r, t[n]));
103
+ if (P(e) && P(t)) {
104
104
  const r = Object.entries(e);
105
- return r.length !== Object.keys(t).length ? !1 : r.every(([n, o]) => P(o, t[n]));
105
+ return r.length !== Object.keys(t).length ? !1 : r.every(([n, o]) => A(o, t[n]));
106
106
  }
107
107
  return !1;
108
108
  }
@@ -115,30 +115,30 @@ function se(e, t = {}) {
115
115
  for (const d of r.values())
116
116
  d(n);
117
117
  }
118
- function c(a) {
118
+ function i(a) {
119
119
  u((d) => ({ ...d, ...a }));
120
120
  }
121
- function i() {
121
+ function s() {
122
122
  return n;
123
123
  }
124
124
  function l() {
125
125
  return structuredClone(o);
126
126
  }
127
- function s(a, d) {
127
+ function c(a, d) {
128
128
  let m;
129
129
  r.set(d, (g) => {
130
- const y = a(g);
131
- P(y, m) || (m = y, d(y));
130
+ const h = a(g);
131
+ A(h, m) || (m = h, d(h));
132
132
  });
133
133
  }
134
134
  function f(a) {
135
135
  r.delete(a);
136
136
  }
137
137
  return {
138
- updateState: c,
139
- getState: i,
138
+ updateState: i,
139
+ getState: s,
140
140
  getInitialState: l,
141
- onChange: s,
141
+ onChange: c,
142
142
  clearOnChange: f
143
143
  };
144
144
  }
@@ -155,24 +155,24 @@ const ie = {
155
155
  function I(e = {}) {
156
156
  return se(ie, e);
157
157
  }
158
- const F = L(I()), D = {
158
+ const M = L(I()), D = {
159
159
  defaultCurrency: "EUR",
160
160
  queryModifications: (e) => e
161
161
  }, ce = {
162
162
  ...D
163
163
  };
164
- function ae(e) {
164
+ function ue(e) {
165
165
  return {
166
166
  pageType: "autocomplete",
167
167
  ...ce,
168
168
  ...e
169
169
  };
170
170
  }
171
- function je({ config: e, store: t, children: r }) {
171
+ function De({ config: e, store: t, children: r }) {
172
172
  const n = t ?? I();
173
- return $(), /* @__PURE__ */ w(M, { value: ae(e), children: /* @__PURE__ */ w(F, { value: n, children: r }) });
173
+ return $(), /* @__PURE__ */ k(R, { value: ue(e), children: /* @__PURE__ */ k(M, { value: n, children: r }) });
174
174
  }
175
- const ue = {
175
+ const ae = {
176
176
  ...D,
177
177
  persistentSearchCache: !1,
178
178
  preservePageScroll: !1
@@ -180,13 +180,13 @@ const ue = {
180
180
  function le(e) {
181
181
  return {
182
182
  pageType: "category",
183
- ...ue,
183
+ ...ae,
184
184
  ...e
185
185
  };
186
186
  }
187
- function De({ config: e, store: t, children: r }) {
187
+ function Ue({ config: e, store: t, children: r }) {
188
188
  const n = t ?? I();
189
- return $(), /* @__PURE__ */ w(M, { value: le(e), children: /* @__PURE__ */ w(F, { value: n, children: r }) });
189
+ return $(), /* @__PURE__ */ k(R, { value: le(e), children: /* @__PURE__ */ k(M, { value: n, children: r }) });
190
190
  }
191
191
  const fe = {
192
192
  ...D,
@@ -200,9 +200,9 @@ function de(e = {}) {
200
200
  ...e
201
201
  };
202
202
  }
203
- function Ue({ config: e, store: t, children: r }) {
203
+ function Be({ config: e, store: t, children: r }) {
204
204
  const n = t ?? I();
205
- return $(), /* @__PURE__ */ w(M, { value: de(e), children: /* @__PURE__ */ w(F, { value: n, children: r }) });
205
+ return $(), /* @__PURE__ */ k(R, { value: de(e), children: /* @__PURE__ */ k(M, { value: n, children: r }) });
206
206
  }
207
207
  function ge(e) {
208
208
  return Array.from(new Set(e));
@@ -218,7 +218,7 @@ function pe(e, t) {
218
218
  ...t.keywords ? {
219
219
  keywords: {
220
220
  ...t.keywords,
221
- fields: ge([...ye, ...t.keywords.fields ?? []]),
221
+ fields: ge([...he, ...t.keywords.fields ?? []]),
222
222
  highlight: t.keywords.highlight ?? {
223
223
  preTag: "<strong>",
224
224
  postTag: "</strong>"
@@ -279,8 +279,8 @@ const me = [
279
279
  "tags1",
280
280
  "tags2",
281
281
  "tags3"
282
- ], ye = ["keyword", "_redirect"];
283
- function he(...e) {
282
+ ], he = ["keyword", "_redirect"];
283
+ function ye(...e) {
284
284
  if (!e.every((t) => t == null))
285
285
  return e.filter((t) => Array.isArray(t)).reduce((t, r) => t.concat(r), []);
286
286
  }
@@ -315,26 +315,26 @@ function we(e, t) {
315
315
  console.warn(r);
316
316
  }
317
317
  }
318
- function ke(e, t) {
318
+ function Pe(e, t) {
319
319
  Ce(e, t, sessionStorage);
320
320
  }
321
- function Pe(e) {
321
+ function ke(e) {
322
322
  return we(e, sessionStorage);
323
323
  }
324
324
  const Y = "nosto:search:searchResult";
325
325
  function Fe(e, t, r) {
326
326
  if (!e)
327
327
  return;
328
- ke(Y, { query: t, result: r });
328
+ Pe(Y, { query: t, result: r });
329
329
  }
330
330
  function Ae(e, t) {
331
331
  if (!e)
332
332
  return null;
333
- const r = Pe(Y);
333
+ const r = ke(Y);
334
334
  if (!r || !be(r))
335
335
  return null;
336
336
  const n = H(r.query);
337
- return P(H(t), n) ? r.result : null;
337
+ return A(H(t), n) ? r.result : null;
338
338
  }
339
339
  function H(e) {
340
340
  return {
@@ -354,8 +354,8 @@ function be(e) {
354
354
  return typeof e == "object" && e !== null && "query" in e && "result" in e;
355
355
  }
356
356
  async function W(e, t, r) {
357
- var s, f, a;
358
- const n = T("newSearch"), o = e.config.pageType, u = E(e.store.getInitialState().query, t), c = E(e.config.search, r, {
357
+ var c, f, a;
358
+ const n = T("newSearch"), o = e.config.pageType, u = z(e.store.getInitialState().query, t), i = z(e.config.search, r, {
359
359
  track: o,
360
360
  redirect: o !== "autocomplete",
361
361
  isKeyword: !!(r != null && r.isKeyword)
@@ -365,25 +365,25 @@ async function W(e, t, r) {
365
365
  loading: !0,
366
366
  initialized: !0
367
367
  });
368
- const i = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
368
+ const s = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
369
369
  {
370
370
  ...u,
371
371
  products: {
372
372
  ...u.products,
373
373
  // Apply filter merging to avoid overwriting base filters
374
- filter: he((f = (s = e.store.getInitialState().query) == null ? void 0 : s.products) == null ? void 0 : f.filter, (a = t.products) == null ? void 0 : a.filter)
374
+ filter: ye((f = (c = e.store.getInitialState().query) == null ? void 0 : c.products) == null ? void 0 : f.filter, (a = t.products) == null ? void 0 : a.filter)
375
375
  }
376
376
  },
377
377
  o
378
378
  );
379
379
  try {
380
380
  let d;
381
- const m = Ae(i, l);
381
+ const m = Ae(s, l);
382
382
  if (m)
383
383
  d = m;
384
384
  else {
385
385
  const g = pe(o, l);
386
- d = await Z(g, c), Fe(i, l, d);
386
+ d = await Z(g, i), Fe(s, l, d);
387
387
  }
388
388
  e.store.updateState({
389
389
  response: d,
@@ -395,72 +395,72 @@ async function W(e, t, r) {
395
395
  n();
396
396
  }
397
397
  async function U(e, t, r) {
398
- const n = T("updateSearch"), o = E(e.store.getState().query, { products: { from: 0 } }, t);
398
+ const n = T("updateSearch"), o = z(e.store.getState().query, { products: { from: 0 } }, t);
399
399
  await W(e, o, r), n();
400
400
  }
401
- async function Re(e, t, r) {
402
- var c;
403
- const n = T("replaceFilter"), o = (c = e.store.getState().query.products) == null ? void 0 : c.filter, u = r !== void 0 ? [{ field: t, [typeof r == "object" ? "range" : "value"]: [r] }] : [];
401
+ async function Me(e, t, r) {
402
+ var i;
403
+ const n = T("replaceFilter"), o = (i = e.store.getState().query.products) == null ? void 0 : i.filter, u = r !== void 0 ? [{ field: t, [typeof r == "object" ? "range" : "value"]: [r] }] : [];
404
404
  await U(e, {
405
405
  products: {
406
- filter: [...(o == null ? void 0 : o.filter((i) => i.field !== t)) ?? [], ...u]
406
+ filter: [...(o == null ? void 0 : o.filter((s) => s.field !== t)) ?? [], ...u]
407
407
  }
408
408
  }), n();
409
409
  }
410
410
  async function _e(e, t, r, n) {
411
- var l, s;
412
- const o = T("toggleProductFilter"), u = (l = e.store.getState().query.products) == null ? void 0 : l.filter, c = u == null ? void 0 : u.find((f) => f.value instanceof Array && f.field === t), i = c != null && c.value ? {
413
- ...c,
414
- value: [...c.value.filter((f) => !P(f, r)), ...n ? [r] : []]
411
+ var l, c;
412
+ const o = T("toggleProductFilter"), u = (l = e.store.getState().query.products) == null ? void 0 : l.filter, i = u == null ? void 0 : u.find((f) => f.value instanceof Array && f.field === t), s = i != null && i.value ? {
413
+ ...i,
414
+ value: [...i.value.filter((f) => !A(f, r)), ...n ? [r] : []]
415
415
  } : n ? {
416
416
  field: t,
417
417
  value: [r]
418
418
  } : void 0;
419
419
  await U(e, {
420
420
  products: {
421
- filter: [...(u == null ? void 0 : u.filter((f) => f !== c)) ?? [], ...(s = i == null ? void 0 : i.value) != null && s.length ? [i] : []]
421
+ filter: [...(u == null ? void 0 : u.filter((f) => f !== i)) ?? [], ...(c = s == null ? void 0 : s.value) != null && c.length ? [s] : []]
422
422
  }
423
423
  }), o();
424
424
  }
425
- function k() {
426
- const e = G(), t = q(F), r = N(
425
+ function F() {
426
+ const e = G(), t = E(M), r = b(
427
427
  () => ({
428
428
  config: e,
429
429
  store: t
430
430
  }),
431
431
  [e, t]
432
- ), n = h(
433
- (i, l) => W(r, i, l),
432
+ ), n = v(
433
+ (s, l) => W(r, s, l),
434
434
  [r]
435
- ), o = h(
436
- (i, l) => U(r, i, l),
435
+ ), o = v(
436
+ (s, l) => U(r, s, l),
437
437
  [r]
438
- ), u = h(
439
- (i, l, s) => _e(r, i, l, s),
438
+ ), u = v(
439
+ (s, l, c) => _e(r, s, l, c),
440
440
  [r]
441
- ), c = h(
442
- (i, l) => Re(r, i, l),
441
+ ), i = v(
442
+ (s, l) => Me(r, s, l),
443
443
  [r]
444
444
  );
445
445
  return {
446
446
  newSearch: n,
447
447
  updateSearch: o,
448
448
  toggleProductFilter: u,
449
- replaceFilter: c
449
+ replaceFilter: i
450
450
  };
451
451
  }
452
- function v(e = Ne) {
453
- const t = q(F), [r, n] = R(e(t.getState()));
454
- return t.onChange(e, n), z(() => () => t.clearOnChange(n), [t]), r;
452
+ function C(e = Ne) {
453
+ const t = E(M), [r, n] = _(e(t.getState()));
454
+ return t.onChange(e, n), O(() => () => t.clearOnChange(n), [t]), r;
455
455
  }
456
456
  const Ne = (e) => e;
457
- function Be(e) {
458
- const t = v((r) => r.response);
459
- return e && Array.isArray(e) || e && C(e) ? e : t;
460
- }
461
457
  function Ke(e) {
462
- var c;
463
- const t = ((c = e.data) == null ? void 0 : c.filter((i) => i.selected).length) ?? 0, [r, n] = R(t > 0), { toggleProductFilter: o } = k();
458
+ const t = C((r) => r.response);
459
+ return e && Array.isArray(e) || e && P(e) ? e : t;
460
+ }
461
+ function Qe(e) {
462
+ var i;
463
+ const t = ((i = e.data) == null ? void 0 : i.filter((s) => s.selected).length) ?? 0, [r, n] = _(t > 0), { toggleProductFilter: o } = F();
464
464
  return {
465
465
  /** Active value */
466
466
  active: r,
@@ -474,8 +474,8 @@ function Ke(e) {
474
474
  toggleProductFilter: o
475
475
  };
476
476
  }
477
- function Qe() {
478
- const { loading: e, facets: t } = v((r) => {
477
+ function He() {
478
+ const { loading: e, facets: t } = C((r) => {
479
479
  var n, o;
480
480
  return {
481
481
  loading: r.loading,
@@ -489,89 +489,129 @@ function Qe() {
489
489
  facets: t
490
490
  };
491
491
  }
492
- function He() {
493
- const [e, t] = R([]), [r, n] = R([]);
494
- return z(() => {
495
- O(async (o) => {
496
- const { products: u, segments: c } = await o.getSearchSessionParams();
497
- t(c ?? []), n((u == null ? void 0 : u.personalizationBoost) ?? []);
492
+ function Re(e, t) {
493
+ const r = t - e;
494
+ return !isNaN(r) && r > 0 ? new Array(t - e).fill(void 0).map((n, o) => o + e) : [];
495
+ }
496
+ function Le(e) {
497
+ const { query: t, products: r } = C((n) => ({
498
+ query: n.query,
499
+ products: n.response.products
500
+ }));
501
+ return b(() => {
502
+ var w;
503
+ if (!r)
504
+ return {
505
+ totalPages: 0,
506
+ resultsFrom: 0,
507
+ resultsTo: 0,
508
+ pages: []
509
+ };
510
+ const n = ((w = t.products) == null ? void 0 : w.from) ?? 0, o = (e == null ? void 0 : e.width) ?? 1 / 0, u = Math.max(Math.floor(o - 1) / 2, 1), i = r.size > 0 ? Math.floor(n / r.size) + 1 : 1, s = r.size > 0 ? Math.ceil(r.total / r.size) : 0, l = (S) => S >= i - u && S <= i + u, c = n + 1, f = Math.min(n + r.total, r.total), a = {
511
+ from: n,
512
+ page: i,
513
+ current: !0
514
+ }, d = (S) => ({
515
+ from: (S - 1) * r.size,
516
+ page: S,
517
+ current: S === i
518
+ }), m = i > 1 ? d(i - 1) : void 0, g = i < s ? d(i + 1) : void 0, h = u === 1 / 0 || i - u - 1 > 1 ? d(1) : void 0, p = u === 1 / 0 || i + u + 1 < s ? d(s) : void 0, y = Re(1, s + 1).filter(l).map(d);
519
+ return {
520
+ totalPages: s,
521
+ resultsFrom: c,
522
+ resultsTo: f,
523
+ current: a,
524
+ prev: m,
525
+ next: g,
526
+ first: h,
527
+ last: p,
528
+ pages: y
529
+ };
530
+ }, [t, r, e == null ? void 0 : e.width]);
531
+ }
532
+ function Ge() {
533
+ const [e, t] = _([]), [r, n] = _([]);
534
+ return O(() => {
535
+ q(async (o) => {
536
+ const { products: u, segments: i } = await o.getSearchSessionParams();
537
+ t(i ?? []), n((u == null ? void 0 : u.personalizationBoost) ?? []);
498
538
  });
499
539
  }, []), {
500
540
  segments: e,
501
541
  boost: r
502
542
  };
503
543
  }
504
- function Me() {
505
- const { facets: e } = v((s) => {
544
+ function Ie() {
545
+ const { facets: e } = C((c) => {
506
546
  var f;
507
547
  return {
508
- facets: ((f = s.response.products) == null ? void 0 : f.facets) ?? []
548
+ facets: ((f = c.response.products) == null ? void 0 : f.facets) ?? []
509
549
  };
510
- }), { replaceFilter: t, toggleProductFilter: r } = k(), n = h(
511
- (s) => {
512
- const f = e == null ? void 0 : e.find((a) => a.type === "stats" && a.field === s);
550
+ }), { replaceFilter: t, toggleProductFilter: r } = F(), n = v(
551
+ (c) => {
552
+ const f = e == null ? void 0 : e.find((a) => a.type === "stats" && a.field === c);
513
553
  if (f && "min" in f && "max" in f)
514
554
  return f;
515
555
  },
516
556
  [e]
517
- ), o = h(
518
- (s) => {
557
+ ), o = v(
558
+ (c) => {
519
559
  var f;
520
- return ((f = e == null ? void 0 : e.find((a) => a.field === s)) == null ? void 0 : f.name) ?? s;
560
+ return ((f = e == null ? void 0 : e.find((a) => a.field === c)) == null ? void 0 : f.name) ?? c;
521
561
  },
522
562
  [e]
523
- ), u = h((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), c = h((s) => {
563
+ ), u = v((c) => "field" in c && (c.value instanceof Array || c.range instanceof Array), []), i = v((c) => {
524
564
  var f;
525
565
  return {
526
- ...s,
527
- range: (f = s.range) == null ? void 0 : f.map((a) => ({
566
+ ...c,
567
+ range: (f = c.range) == null ? void 0 : f.map((a) => ({
528
568
  gt: a.gt ? Number(a.gt) : a.gt,
529
569
  gte: a.gte ? Number(a.gte) : a.gte,
530
570
  lt: a.lt ? Number(a.lt) : a.lt,
531
571
  lte: a.lte ? Number(a.lte) : a.lte
532
572
  }))
533
573
  };
534
- }, []), i = h(
535
- (s) => (s.value ?? []).map((a) => ({
574
+ }, []), s = v(
575
+ (c) => (c.value ?? []).map((a) => ({
536
576
  value: a,
537
- field: s.field,
538
- name: o(s.field),
539
- filter: c(s),
577
+ field: c.field,
578
+ name: o(c.field),
579
+ filter: i(c),
540
580
  remove: () => {
541
- r(s.field, a, !1);
581
+ r(c.field, a, !1);
542
582
  }
543
583
  })),
544
- [c, o, r]
545
- ), l = h(
546
- (s) => (s.range ?? []).map((a) => {
547
- var g, y;
548
- const d = a.gte ?? a.gt ?? ((g = n(s.field)) == null ? void 0 : g.min), m = a.lte ?? a.lt ?? ((y = n(s.field)) == null ? void 0 : y.max);
584
+ [i, o, r]
585
+ ), l = v(
586
+ (c) => (c.range ?? []).map((a) => {
587
+ var g, h;
588
+ const d = a.gte ?? a.gt ?? ((g = n(c.field)) == null ? void 0 : g.min), m = a.lte ?? a.lt ?? ((h = n(c.field)) == null ? void 0 : h.max);
549
589
  if (d !== void 0 && m !== void 0)
550
590
  return {
551
591
  value: `${d} - ${m}`,
552
- field: s.field,
553
- name: o(s.field),
554
- filter: c(s),
592
+ field: c.field,
593
+ name: o(c.field),
594
+ filter: i(c),
555
595
  remove: () => {
556
- t(s.field, void 0);
596
+ t(c.field, void 0);
557
597
  }
558
598
  };
559
599
  }).filter(Boolean),
560
- [c, n, o, t]
600
+ [i, n, o, t]
561
601
  );
562
602
  return {
563
603
  selectFilters: u,
564
- toValueFilter: i,
604
+ toValueFilter: s,
565
605
  toRangeFilter: l
566
606
  };
567
607
  }
568
- function Ie() {
569
- const { filter: e } = v((i) => {
608
+ function Te() {
609
+ const { filter: e } = C((s) => {
570
610
  var l;
571
611
  return {
572
- filter: ((l = i.query.products) == null ? void 0 : l.filter) ?? []
612
+ filter: ((l = s.query.products) == null ? void 0 : l.filter) ?? []
573
613
  };
574
- }), { updateSearch: t } = k(), { selectFilters: r, toValueFilter: n, toRangeFilter: o } = Me(), u = N(() => e ? e.filter(r).flatMap((i) => "value" in i ? n(i) : "range" in i ? o(i) : []).filter(Boolean) : [], [e, r, o, n]), c = h(() => {
614
+ }), { updateSearch: t } = F(), { selectFilters: r, toValueFilter: n, toRangeFilter: o } = Ie(), u = b(() => e ? e.filter(r).flatMap((s) => "value" in s ? n(s) : "range" in s ? o(s) : []).filter(Boolean) : [], [e, r, o, n]), i = v(() => {
575
615
  t({
576
616
  products: {
577
617
  filter: []
@@ -582,10 +622,10 @@ function Ie() {
582
622
  /** Selected filters array. */
583
623
  filters: u,
584
624
  /** Should remove all selected filters. */
585
- removeAll: c
625
+ removeAll: i
586
626
  };
587
627
  }
588
- function _(e) {
628
+ function N(e) {
589
629
  if (typeof e == "number")
590
630
  return e;
591
631
  if (typeof e != "string")
@@ -593,9 +633,9 @@ function _(e) {
593
633
  const t = Number(e);
594
634
  return isNaN(t) ? void 0 : t;
595
635
  }
596
- function Te(e) {
636
+ function xe(e) {
597
637
  var a, d, m;
598
- const { replaceFilter: t } = k(), { query: r, products: n } = v((g) => ({
638
+ const { replaceFilter: t } = F(), { query: r, products: n } = C((g) => ({
599
639
  query: g.query,
600
640
  products: g.response.products
601
641
  })), o = (a = n == null ? void 0 : n.facets) == null ? void 0 : a.find((g) => g.id === e);
@@ -607,54 +647,54 @@ function Te(e) {
607
647
  updateRange: () => {
608
648
  }
609
649
  };
610
- const u = (m = (d = r.products) == null ? void 0 : d.filter) == null ? void 0 : m.find((g) => g.field === o.field), c = u != null && u.range ? u.range[0] : void 0, i = typeof c == "object" && ("gte" in c || "lte" in c) ? [_(c.gte), _(c.lte)] : [void 0, void 0], l = "min" in o ? Math.floor(o.min) : 0, s = "max" in o ? Math.ceil(o.max) : 0, f = ([g, y]) => {
611
- const p = g !== void 0 ? Math.floor(g) : void 0, S = y !== void 0 ? Math.ceil(y) : void 0, A = p !== void 0, b = S !== void 0;
612
- (l === p || !A) && (s === S || !b) ? t(o.field, void 0) : (l === p || !A) && b ? t(o.field, {
613
- lte: S.toString()
614
- }) : (s === S || !b) && A ? t(o.field, {
650
+ const u = (m = (d = r.products) == null ? void 0 : d.filter) == null ? void 0 : m.find((g) => g.field === o.field), i = u != null && u.range ? u.range[0] : void 0, s = typeof i == "object" && ("gte" in i || "lte" in i) ? [N(i.gte), N(i.lte)] : [void 0, void 0], l = "min" in o ? Math.floor(o.min) : 0, c = "max" in o ? Math.ceil(o.max) : 0, f = ([g, h]) => {
651
+ const p = g !== void 0 ? Math.floor(g) : void 0, y = h !== void 0 ? Math.ceil(h) : void 0, w = p !== void 0, S = y !== void 0;
652
+ (l === p || !w) && (c === y || !S) ? t(o.field, void 0) : (l === p || !w) && S ? t(o.field, {
653
+ lte: y.toString()
654
+ }) : (c === y || !S) && w ? t(o.field, {
615
655
  gte: p.toString()
616
- }) : A && b && t(o.field, {
656
+ }) : w && S && t(o.field, {
617
657
  gte: p.toString(),
618
- lte: S.toString()
658
+ lte: y.toString()
619
659
  });
620
660
  };
621
661
  return {
622
662
  /** Min value */
623
663
  min: l,
624
664
  /** Max value */
625
- max: s,
665
+ max: c,
626
666
  /** Range value */
627
- range: [i[0] ?? l, i[1] ?? s],
667
+ range: [s[0] ?? l, s[1] ?? c],
628
668
  /** Update range function */
629
669
  updateRange: f
630
670
  };
631
671
  }
632
- function Le(e, t) {
633
- const { min: r, max: n, range: o, updateRange: u } = Te(e), { filters: c } = Ie(), i = N(() => {
634
- var y;
635
- const a = c.find((p) => {
636
- var S;
637
- return (S = p == null ? void 0 : p.filter) == null ? void 0 : S.range;
672
+ function Je(e, t) {
673
+ const { min: r, max: n, range: o, updateRange: u } = xe(e), { filters: i } = Te(), s = b(() => {
674
+ var h;
675
+ const a = i.find((p) => {
676
+ var y;
677
+ return (y = p == null ? void 0 : p.filter) == null ? void 0 : y.range;
638
678
  });
639
679
  let d = null;
640
680
  if (a) {
641
- const p = (y = a.filter.range) == null ? void 0 : y[0];
642
- d = [_(p == null ? void 0 : p.gte), _(p == null ? void 0 : p.lte)];
681
+ const p = (h = a.filter.range) == null ? void 0 : h[0];
682
+ d = [N(p == null ? void 0 : p.gte), N(p == null ? void 0 : p.lte)];
643
683
  }
644
684
  const m = [];
645
685
  let g = Math.floor(r / t) * t;
646
686
  for (; g < n; ) {
647
- const p = g + t, S = d && d[0] === g && d[1] === p;
687
+ const p = g + t, y = d && d[0] === g && d[1] === p;
648
688
  m.push({
649
689
  min: g,
650
690
  max: p,
651
- selected: S
691
+ selected: y
652
692
  }), g = p;
653
693
  }
654
694
  return m;
655
- }, [c, r, n, t]), l = (a) => {
695
+ }, [i, r, n, t]), l = (a) => {
656
696
  u([a, o[1]]);
657
- }, s = (a) => {
697
+ }, c = (a) => {
658
698
  u([o[0], a]);
659
699
  }, f = r !== o[0] || n !== o[1];
660
700
  return {
@@ -667,17 +707,17 @@ function Le(e, t) {
667
707
  /** Update range function */
668
708
  updateRange: u,
669
709
  /** Ranges */
670
- ranges: i,
710
+ ranges: s,
671
711
  /** Handle min change */
672
712
  handleMinChange: l,
673
713
  /** Handle max change */
674
- handleMaxChange: s,
714
+ handleMaxChange: c,
675
715
  /** Is selected */
676
716
  isSelected: f
677
717
  };
678
718
  }
679
- function Ge() {
680
- const { products: e, keywords: t } = v((r) => r.response);
719
+ function Ye() {
720
+ const { products: e, keywords: t } = C((r) => r.response);
681
721
  return {
682
722
  /** Array of products */
683
723
  products: e ?? { hits: [], total: 0 },
@@ -685,61 +725,61 @@ function Ge() {
685
725
  keywords: t ?? { hits: [], total: 0 }
686
726
  };
687
727
  }
688
- function Je() {
689
- const e = v((r) => {
728
+ function We() {
729
+ const e = C((r) => {
690
730
  var n;
691
731
  return (n = r.query.products) == null ? void 0 : n.filter;
692
732
  });
693
- return N(() => e ? e.reduce((r, n) => r + (Array.isArray(n.value) ? n.value.length : 1), 0) : 0, [e]);
733
+ return b(() => e ? e.reduce((r, n) => r + (Array.isArray(n.value) ? n.value.length : 1), 0) : 0, [e]);
694
734
  }
695
735
  function x(e) {
696
736
  return e && !Number.isNaN(e) ? e : 0;
697
737
  }
698
- function Ye(e, t) {
699
- const { from: r, size: n, total: o } = v((s) => {
738
+ function Xe(e, t) {
739
+ const { from: r, size: n, total: o } = C((c) => {
700
740
  var f, a, d, m, g;
701
741
  return {
702
- from: x(((f = s.query.products) == null ? void 0 : f.from) ?? 0),
703
- size: x(((d = (a = s.response) == null ? void 0 : a.products) == null ? void 0 : d.size) ?? 0),
704
- total: x(((g = (m = s.response) == null ? void 0 : m.products) == null ? void 0 : g.total) ?? 0)
742
+ from: x(((f = c.query.products) == null ? void 0 : f.from) ?? 0),
743
+ size: x(((d = (a = c.response) == null ? void 0 : a.products) == null ? void 0 : d.size) ?? 0),
744
+ total: x(((g = (m = c.response) == null ? void 0 : m.products) == null ? void 0 : g.total) ?? 0)
705
745
  };
706
- }), { updateSearch: u } = k(), c = r + n, i = [...e].reverse().filter((s) => s + t < o);
746
+ }), { updateSearch: u } = F(), i = r + n, s = [...e].reverse().filter((c) => c + t < o);
707
747
  return {
708
748
  /** from value */
709
749
  from: r,
710
750
  /** to value */
711
- to: c,
751
+ to: i,
712
752
  /** total value */
713
753
  total: o,
714
754
  /** size value */
715
755
  size: n,
716
756
  /** Array of size options */
717
- sizeOptions: i,
757
+ sizeOptions: s,
718
758
  /** Should be called when size is changed */
719
- handleSizeChange: (s) => {
759
+ handleSizeChange: (c) => {
720
760
  u({
721
761
  products: {
722
- size: s
762
+ size: c
723
763
  }
724
764
  });
725
765
  }
726
766
  };
727
767
  }
728
- function xe(e, t) {
768
+ function ze(e, t) {
729
769
  return e.length !== t.length ? !1 : e.every((r) => t.find((n) => r.field === n.field && r.order === n.order));
730
770
  }
731
- function We(e) {
732
- var u, c;
733
- const t = v((i) => i.query), { updateSearch: r } = k();
771
+ function Ze(e) {
772
+ var u, i;
773
+ const t = C((s) => s.query), { updateSearch: r } = F();
734
774
  return {
735
775
  /** Active sort */
736
- activeSort: ((u = e.find((i) => {
776
+ activeSort: ((u = e.find((s) => {
737
777
  var l;
738
- return xe(i.value.sort, ((l = t.products) == null ? void 0 : l.sort) || []);
739
- })) == null ? void 0 : u.id) ?? ((c = e[0]) == null ? void 0 : c.id),
778
+ return ze(s.value.sort, ((l = t.products) == null ? void 0 : l.sort) || []);
779
+ })) == null ? void 0 : u.id) ?? ((i = e[0]) == null ? void 0 : i.id),
740
780
  /** Set sort function */
741
- setSort: (i) => {
742
- const l = e.find((s) => s.id === i);
781
+ setSort: (s) => {
782
+ const l = e.find((c) => c.id === s);
743
783
  l && r({
744
784
  products: {
745
785
  sort: l.value.sort
@@ -749,26 +789,27 @@ function We(e) {
749
789
  };
750
790
  }
751
791
  export {
752
- je as AutocompletePageProvider,
753
- De as CategoryPageProvider,
754
- Ve as SearchInput,
755
- Ue as SearchPageProvider,
756
- $e as SerpElement,
757
- F as StoreContext,
792
+ De as AutocompletePageProvider,
793
+ Ue as CategoryPageProvider,
794
+ $e as SearchInput,
795
+ Be as SearchPageProvider,
796
+ je as SerpElement,
797
+ M as StoreContext,
758
798
  se as createExtendableStore,
759
799
  I as createStore,
760
800
  ie as defaultState,
761
- k as useActions,
762
- Be as useDecoratedSearchResults,
763
- Ke as useFacet,
764
- Qe as useFacets,
765
- v as useNostoAppState,
766
- He as usePersonalization,
767
- Ie as useProductFilters,
768
- Te as useRange,
769
- Le as useRangeSelector,
770
- Ge as useResponse,
771
- Je as useSelectedFiltersCount,
772
- Ye as useSizeOptions,
773
- We as useSort
801
+ F as useActions,
802
+ Ke as useDecoratedSearchResults,
803
+ Qe as useFacet,
804
+ He as useFacets,
805
+ C as useNostoAppState,
806
+ Le as usePagination,
807
+ Ge as usePersonalization,
808
+ Te as useProductFilters,
809
+ xe as useRange,
810
+ Je as useRangeSelector,
811
+ Ye as useResponse,
812
+ We as useSelectedFiltersCount,
813
+ Xe as useSizeOptions,
814
+ Ze as useSort
774
815
  };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Pagination page type.
3
+ */
4
+ export type Page = {
5
+ from: number;
6
+ page: number;
7
+ current: boolean;
8
+ };
9
+ /**
10
+ * Preact hook that import pagination state to the component.
11
+ *
12
+ * **Should always be at the top of the component!**
13
+ *
14
+ * @example
15
+ * ```jsx
16
+ * import { usePagination } from '@nosto/search-js/preact'
17
+ *
18
+ * export default () => {
19
+ * const { pages } = usePagination()
20
+ *
21
+ * return pages.map((page) => <li>
22
+ * {page.current ? <span>{page.page}</span> : <a>
23
+ * {page.page}
24
+ * </a>}
25
+ * </li>)
26
+ * }
27
+ * ```
28
+ *
29
+ * @group Hooks
30
+ */
31
+ export declare function usePagination(options?: {
32
+ width?: number;
33
+ }): {
34
+ totalPages: number;
35
+ resultsFrom: number;
36
+ resultsTo: number;
37
+ current?: Page;
38
+ prev?: Page;
39
+ next?: Page;
40
+ first?: Page;
41
+ last?: Page;
42
+ pages: Page[];
43
+ };
@@ -0,0 +1,43 @@
1
+ import { s } from "./index.es-B8mbAxS4.js";
2
+ function a(t, r) {
3
+ if (!t.products || !(r != null && r.length))
4
+ return t;
5
+ const e = (i) => r.reduce((u, n) => n(u), i);
6
+ return {
7
+ ...t,
8
+ products: {
9
+ ...t.products,
10
+ hits: t.products.hits.map(e)
11
+ }
12
+ };
13
+ }
14
+ function o(t) {
15
+ return new Promise((r) => setTimeout(r, t));
16
+ }
17
+ async function f(t, r, e) {
18
+ const { maxRetries: i = 0, retryInterval: u = 1e3 } = e;
19
+ let n = 0;
20
+ for (; ; )
21
+ try {
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);
29
+ }
30
+ }
31
+ function h(t) {
32
+ return !t || typeof t != "object" ? !1 : !("status" in t) || l(t.status);
33
+ }
34
+ function l(t) {
35
+ return typeof t == "number" && (t < 400 || t >= 500);
36
+ }
37
+ async function p(t, r = {}) {
38
+ const { hitDecorators: e, ...i } = r, u = await new Promise(s), n = await f(u, t, i);
39
+ return a(n, e);
40
+ }
41
+ export {
42
+ p as s
43
+ };
@@ -0,0 +1 @@
1
+ "use strict";const s=require("./index.es-DlUp67LT.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 f(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(!h(c))throw console.info("Skipping retry logic for",c),c;if(n>=i)throw c;n++,await o(u)}}function h(t){return!t||typeof t!="object"?!1:!("status"in t)||l(t.status)}function l(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 f(u,t,i);return a(n,r)}exports.search=y;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-D_7T9vdv.cjs");function s({size:e,productId:a,hash:u}){const i=p.i();if(!i)throw new Error("Client script settings are not yet available");return`https://${i.thumbnailHost}/${i.account}/${e}/${a}/${u}/A`}function l({size:e}){function a(c,r){if(r)return s({size:e,productId:c,hash:r})}function u(c,r){if(r)return r.map(t=>({...t,imageUrl:a(c,t.imageHash)??t.imageUrl}))}function i(c,r,t){if(!t)return r;if(r)return t.map(n=>s({size:e,productId:c,hash:n}))}return function(r){const t=r.productId;return t?{...r,imageUrl:a(t,r.imageHash)??r.imageUrl,thumbUrl:a(t,r.thumbHash)??r.thumbUrl,skus:u(t,r.skus),alternateImageUrls:i(t,r.alternateImageUrls,r.alternateImageHashes)}:r}}const g=/cdn\.shopify\.com/,m={1:"170x170_crop_center",2:"100x100_crop_center",3:"90x70_crop_center",4:"50x50_crop_center",5:"30x30_crop_center",6:"100x140_crop_center",7:"200x200_crop_center",8:"400x400",9:"750x750"};function U(e){return e in m}function f({size:e,fallback:a=u=>u}){if(e==="orig")return a;const u=m[e]||e;function i(n){return n?new URL(n).hostname.match(g):!1}function c(n){return n?i(n)?n.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/,`_${u}$1`):n:""}function r(n){if(n)return n.map(o=>({...o,imageUrl:c(o.imageUrl)}))}function t(n){if(n)return n.map(o=>c(o))}return function(o){return i(o.imageUrl)?{...o,imageUrl:c(o.imageUrl),thumbUrl:c(o.thumbUrl),skus:r(o.skus),alternateImageUrls:t(o.alternateImageUrls)}:a(o)}}function d(){var e;return(e=window.Nosto)==null?void 0:e.shopifyScript}function b({size:e}){const a=l({size:e});return d()&&U(e)?f({size:e,fallback:a}):a}exports.generateThumbnailUrl=s;exports.nostoThumbnailDecorator=l;exports.shopifyThumbnailDecorator=f;exports.thumbnailDecorator=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs");function s({size:e,productId:a,hash:u}){const i=p.i();if(!i)throw new Error("Client script settings are not yet available");return`https://${i.thumbnailHost}/${i.account}/${e}/${a}/${u}/A`}function l({size:e}){function a(c,r){if(r)return s({size:e,productId:c,hash:r})}function u(c,r){if(r)return r.map(t=>({...t,imageUrl:a(c,t.imageHash)??t.imageUrl}))}function i(c,r,t){if(!t)return r;if(r)return t.map(n=>s({size:e,productId:c,hash:n}))}return function(r){const t=r.productId;return t?{...r,imageUrl:a(t,r.imageHash)??r.imageUrl,thumbUrl:a(t,r.thumbHash)??r.thumbUrl,skus:u(t,r.skus),alternateImageUrls:i(t,r.alternateImageUrls,r.alternateImageHashes)}:r}}const g=/cdn\.shopify\.com/,m={1:"170x170_crop_center",2:"100x100_crop_center",3:"90x70_crop_center",4:"50x50_crop_center",5:"30x30_crop_center",6:"100x140_crop_center",7:"200x200_crop_center",8:"400x400",9:"750x750"};function U(e){return e in m}function f({size:e,fallback:a=u=>u}){if(e==="orig")return a;const u=m[e]||e;function i(n){return n?new URL(n).hostname.match(g):!1}function c(n){return n?i(n)?n.replace(/(\.jpg|\.png|\.jpeg|\.gif|\.webp)/,`_${u}$1`):n:""}function r(n){if(n)return n.map(o=>({...o,imageUrl:c(o.imageUrl)}))}function t(n){if(n)return n.map(o=>c(o))}return function(o){return i(o.imageUrl)?{...o,imageUrl:c(o.imageUrl),thumbUrl:c(o.thumbUrl),skus:r(o.skus),alternateImageUrls:t(o.alternateImageUrls)}:a(o)}}function d(){var e;return(e=window.Nosto)==null?void 0:e.shopifyScript}function b({size:e}){const a=l({size:e});return d()&&U(e)?f({size:e,fallback:a}):a}exports.generateThumbnailUrl=s;exports.nostoThumbnailDecorator=l;exports.shopifyThumbnailDecorator=f;exports.thumbnailDecorator=b;
@@ -1,4 +1,4 @@
1
- import { i as m } from "../index.es-Bcd5IQh9.js";
1
+ import { i as m } from "../index.es-B8mbAxS4.js";
2
2
  function s({ size: e, productId: a, hash: i }) {
3
3
  const u = m();
4
4
  if (!u)
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generate an array of numbers from start to exlusive end
3
+ * @param start number of array range start
4
+ * @param end number of array range end
5
+ * @returns an array of numbers from start to exlusive end
6
+ * @example
7
+ * ```ts
8
+ * range(1, 5) // [1, 2, 3, 4]
9
+ * ```
10
+ */
11
+ export declare function range(start: number, end: number): number[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -53,16 +53,16 @@
53
53
  "install:dev": "(cd dev/preact && npm i --ignore-scripts)"
54
54
  },
55
55
  "devDependencies": {
56
- "@nosto/nosto-js": "^1.5.0",
56
+ "@nosto/nosto-js": "^1.7.0",
57
57
  "@testing-library/dom": "^10.4.0",
58
58
  "@types/eslint-config-prettier": "^6.11.3",
59
- "@types/node": "^22.13.10",
59
+ "@types/node": "^22.13.13",
60
60
  "concurrently": "^9.1.2",
61
61
  "copyfiles": "^2.4.1",
62
- "eslint": "^9.22.0",
62
+ "eslint": "^9.23.0",
63
63
  "eslint-config-prettier": "^10.1.1",
64
64
  "eslint-plugin-barrel-files": "^3.0.1",
65
- "eslint-plugin-prettier": "^5.2.3",
65
+ "eslint-plugin-prettier": "^5.2.4",
66
66
  "eslint-plugin-simple-import-sort": "^12.1.1",
67
67
  "eslint-plugin-unused-imports": "^4.1.4",
68
68
  "eslint-plugin-react": "^7.37.4",
@@ -71,10 +71,10 @@
71
71
  "prettier": "^3.5.3",
72
72
  "typedoc": "^0.27.9",
73
73
  "typescript": "^5.8.2",
74
- "typescript-eslint": "^8.26.0",
75
- "vite": "^6.2.1",
74
+ "typescript-eslint": "^8.28.0",
75
+ "vite": "^6.2.3",
76
76
  "vite-plugin-dts": "^4.5.3",
77
- "vitest": "^3.0.8"
77
+ "vitest": "^3.0.9"
78
78
  },
79
79
  "publishConfig": {
80
80
  "access": "public"
@@ -1,20 +0,0 @@
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
- };
@@ -1 +0,0 @@
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;