@nosto/search-js 1.7.5 → 1.8.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,566 +1,187 @@
1
+ import { s as b } from "../index.es-B8mbAxS4.js";
2
+ import { cloneElement as L, Fragment as B, toChildArray as j } from "preact";
1
3
  import { isBot as H } from "../utils/utils.es.js";
2
- import { options as B, createContext as W, Fragment as G, toChildArray as ne } from "preact";
3
- import { useContext as q, useState as I, useEffect as N, useMemo as M, useCallback as v, useRef as oe } from "preact/hooks";
4
- import { s as se } from "../search-B0-bVNMy.js";
5
- import { s as E } from "../index.es-B8mbAxS4.js";
6
- var ie = 0;
7
- function w(e, r, t, n, o, c) {
8
- r || (r = {});
9
- var s, i, l = r;
10
- if ("ref" in l) for (i in l = {}, r) i == "ref" ? s = r[i] : l[i] = r[i];
11
- var u = { type: e, props: l, key: t, ref: s, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --ie, __i: -1, __u: 0, __source: o, __self: c };
12
- if (typeof e == "function" && (s = e.defaultProps)) for (i in s) l[i] === void 0 && (l[i] = s[i]);
13
- return B.vnode && B.vnode(u), u;
14
- }
15
- const U = (e) => String(e) === "[object Object]";
16
- function F(e) {
17
- if (!U(e))
18
- return !1;
19
- const r = e.constructor;
20
- if (r === void 0)
21
- return !0;
22
- const t = r.prototype;
23
- return !(!U(t) || !t.hasOwnProperty("isPrototypeOf"));
24
- }
25
- function x(...e) {
26
- return e.reduce((r, t) => V(r, t));
27
- }
28
- function Q(...e) {
29
- return e.reduce((r, t) => V(r, t));
30
- }
31
- function V(e, r) {
32
- return F(e) && F(r) ? Object.entries(r).reduce(
33
- (t, [n, o]) => (t[n] = V(t[n], o), t),
34
- { ...e }
35
- ) : F(e) ? e : r;
36
- }
37
- function b(e, r) {
38
- if (e === r)
39
- return !0;
40
- if (e instanceof Date && r instanceof Date)
41
- return e.getTime() === r.getTime();
42
- if (Array.isArray(e) && Array.isArray(r))
43
- return e.length !== r.length ? !1 : e.every((t, n) => b(t, r[n]));
44
- if (F(e) && F(r)) {
45
- const t = Object.entries(e);
46
- return t.length !== Object.keys(r).length ? !1 : t.every(([n, o]) => b(o, r[n]));
47
- }
48
- return !1;
49
- }
50
- function ce(e, r = {}) {
51
- const t = /* @__PURE__ */ new Map();
52
- let n = Q(e, r ?? {});
53
- const o = Q(e, r);
54
- function c(a) {
55
- n = a(n);
56
- for (const d of t.values())
57
- d(n);
58
- }
59
- function s(a) {
60
- c((d) => ({ ...d, ...a }));
61
- }
62
- function i() {
63
- return n;
64
- }
65
- function l() {
66
- return structuredClone(o);
67
- }
68
- function u(a, d) {
69
- let m;
70
- t.set(d, (g) => {
71
- const h = a(g);
72
- b(h, m) || (m = h, d(h));
73
- });
74
- }
75
- function f(a) {
76
- t.delete(a);
77
- }
78
- return {
79
- updateState: s,
80
- getState: i,
81
- getInitialState: l,
82
- onChange: u,
83
- clearOnChange: f
84
- };
85
- }
86
- const ue = {
87
- loading: !0,
88
- query: {},
89
- response: {},
90
- initialized: !1
91
- };
92
- function _(e = {}) {
93
- return ce(ue, e);
94
- }
95
- const A = W(_());
96
- function y(e = ae) {
97
- const r = q(A), [t, n] = I(e(r.getState()));
98
- return r.onChange(e, n), N(() => () => r.clearOnChange(n), [r]), t;
99
- }
100
- const ae = (e) => e;
101
- function J(e, ...r) {
102
- return r.reduce(
103
- (t, n) => (t[n] = e[n], t),
104
- {}
105
- );
106
- }
107
- const T = W(null), Y = () => {
108
- const e = q(T);
109
- if (!e)
110
- throw new Error("useConfig must be used within a ConfigProvider");
111
- return e;
112
- };
113
- function le(e) {
114
- return Array.from(new Set(e));
115
- }
116
- function fe(e, r) {
117
- return {
118
- ...r,
119
- products: {
120
- facets: e === "autocomplete" ? void 0 : ["*"],
121
- fields: de,
122
- ...r.products
123
- },
124
- ...r.keywords ? {
125
- keywords: {
126
- ...r.keywords,
127
- fields: le([...ge, ...r.keywords.fields ?? []]),
128
- highlight: r.keywords.highlight ?? {
129
- preTag: "<strong>",
130
- postTag: "</strong>"
131
- }
132
- }
133
- } : {}
134
- };
135
- }
136
- const de = [
137
- "productId",
138
- "url",
139
- "name",
140
- "imageUrl",
141
- "imageHash",
142
- "thumbUrl",
143
- "description",
144
- "brand",
145
- "variantId",
146
- "availability",
147
- "price",
148
- "priceText",
149
- "categoryIds",
150
- "categories",
151
- "customFields.key",
152
- "customFields.value",
153
- "priceCurrencyCode",
154
- "datePublished",
155
- "listPrice",
156
- "unitPricingBaseMeasure",
157
- "unitPricingUnit",
158
- "unitPricingMeasure",
159
- "googleCategory",
160
- "gtin",
161
- "ageGroup",
162
- "gender",
163
- "condition",
164
- "alternateImageUrls",
165
- "ratingValue",
166
- "reviewCount",
167
- "inventoryLevel",
168
- "skus.id",
169
- "skus.name",
170
- "skus.price",
171
- "skus.listPrice",
172
- "skus.priceText",
173
- "skus.url",
174
- "skus.imageUrl",
175
- "skus.inventoryLevel",
176
- "skus.customFields.key",
177
- "skus.customFields.value",
178
- "skus.availability",
179
- "pid",
180
- "onDiscount",
181
- "extra.key",
182
- "extra.value",
183
- "saleable",
184
- "available",
185
- "tags1",
186
- "tags2",
187
- "tags3"
188
- ], ge = ["keyword", "_redirect"];
189
- function pe(...e) {
190
- if (!e.every((r) => r == null))
191
- return e.filter((r) => Array.isArray(r)).reduce((r, t) => r.concat(t), []);
192
- }
193
- const X = "nosto.search.";
194
- function me(e) {
195
- var t;
196
- const r = `${X}${e}`;
197
- (t = window.performance) == null || t.mark(`${r}.start`);
198
- }
199
- function he(e) {
200
- var t, n;
201
- const r = `${X}${e}`;
202
- (t = window.performance) == null || t.mark(`${r}.end`), (n = window.performance) == null || n.measure(r, `${r}.start`, `${r}.end`);
203
- }
204
- function O(e) {
205
- return me(e), () => he(e);
206
- }
207
- function ye(e, r, t) {
208
- const n = JSON.stringify(r);
209
- try {
210
- console.info("Setting storage", e, n), t.setItem(e, n);
211
- } catch (o) {
212
- console.warn(o);
213
- }
214
- }
215
- function Se(e, r) {
216
- try {
217
- const t = r.getItem(e);
218
- if (t)
219
- return JSON.parse(t);
220
- } catch (t) {
221
- console.warn(t);
222
- }
223
- }
224
- function ve(e, r) {
225
- ye(e, r, sessionStorage);
226
- }
227
- function we(e) {
228
- return Se(e, sessionStorage);
229
- }
230
- const Z = "nosto:search:searchResult";
231
- function Ce(e, r, t) {
232
- if (!e)
233
- return;
234
- ve(Z, { query: r, result: t });
235
- }
236
- function ke(e, r) {
237
- if (!e)
238
- return null;
239
- const t = we(Z);
240
- if (!t || !Pe(t))
241
- return null;
242
- const n = K(t.query);
243
- return b(K(r), n) ? t.result : null;
244
- }
245
- function K(e) {
246
- return {
247
- accountId: e.accountId,
248
- customRules: e.customRules,
249
- explain: e.explain,
250
- keywords: e.keywords,
251
- products: e.products,
252
- query: e.query,
253
- redirect: e.redirect,
254
- rules: e.rules,
255
- segments: e.segments,
256
- sessionParams: e.sessionParams
257
- };
258
- }
259
- function Pe(e) {
260
- return typeof e == "object" && e !== null && "query" in e && "result" in e;
261
- }
262
- async function ee(e, r, t) {
263
- var u, f, a;
264
- const n = O("newSearch"), o = e.config.pageType, c = x(e.store.getInitialState().query, r), s = x(e.config.search, t, {
265
- track: o,
266
- redirect: o !== "autocomplete",
267
- isKeyword: !!(t != null && t.isKeyword)
268
- });
269
- e.store.updateState({
270
- query: c,
271
- loading: !0,
272
- initialized: !0
273
- });
274
- const i = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
275
- {
276
- ...c,
277
- products: {
278
- ...c.products,
279
- // Apply filter merging to avoid overwriting base filters
280
- filter: pe((f = (u = e.store.getInitialState().query) == null ? void 0 : u.products) == null ? void 0 : f.filter, (a = r.products) == null ? void 0 : a.filter)
281
- }
282
- },
283
- o
284
- );
285
- try {
286
- let d;
287
- const m = ke(i, l);
288
- if (m)
289
- d = m;
290
- else {
291
- const g = fe(o, l);
292
- d = await se(g, s), Ce(i, l, d);
4
+ import { u as V, a as C, b as v, h as O, p as D, i as U, I as W, c as $, d as x, S as R, C as T, e as K, f as P } from "../InfiniteScrollWithObserver-kuSGeBWr.js";
5
+ import { k as Ie, j as Le } from "../InfiniteScrollWithObserver-kuSGeBWr.js";
6
+ import { useEffect as I, useState as N, useMemo as A, useCallback as F } from "preact/hooks";
7
+ function Y(e) {
8
+ return e !== null && typeof e == "object" && "props" in e && typeof e.type == "string";
9
+ }
10
+ function he({ children: e, hit: n }) {
11
+ var r;
12
+ if (!Y(e))
13
+ throw new Error(
14
+ "AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
15
+ );
16
+ const t = (r = e.props) == null ? void 0 : r.onClick;
17
+ return L(e, {
18
+ onClick: (o) => {
19
+ n && b((a) => a.recordSearchClick("autocomplete", n)), typeof t == "function" && t(o);
293
20
  }
294
- e.store.updateState({
295
- response: d,
296
- loading: !1
297
- });
298
- } catch (d) {
299
- console.error("Search action failed", d);
300
- }
301
- n();
302
- }
303
- async function $(e, r, t) {
304
- const n = O("updateSearch"), o = x(e.store.getState().query, { products: { from: 0 } }, r);
305
- await ee(e, o, t), n();
306
- }
307
- async function Fe(e, r, t) {
308
- var s;
309
- const n = O("replaceFilter"), o = (s = e.store.getState().query.products) == null ? void 0 : s.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
310
- await $(e, {
311
- products: {
312
- filter: [...(o == null ? void 0 : o.filter((i) => i.field !== r)) ?? [], ...c]
313
- }
314
- }), n();
315
- }
316
- async function be(e, r, t, n) {
317
- var l, u;
318
- const o = O("toggleProductFilter"), c = (l = e.store.getState().query.products) == null ? void 0 : l.filter, s = c == null ? void 0 : c.find((f) => f.value instanceof Array && f.field === r), i = s != null && s.value ? {
319
- ...s,
320
- value: [...s.value.filter((f) => !b(f, t)), ...n ? [t] : []]
321
- } : n ? {
322
- field: r,
323
- value: [t]
324
- } : void 0;
325
- await $(e, {
326
- products: {
327
- filter: [...(c == null ? void 0 : c.filter((f) => f !== s)) ?? [], ...(u = i == null ? void 0 : i.value) != null && u.length ? [i] : []]
328
- }
329
- }), o();
330
- }
331
- function P() {
332
- const e = Y(), r = q(A), t = M(
333
- () => ({
334
- config: e,
335
- store: r
336
- }),
337
- [e, r]
338
- ), n = v(
339
- (i, l) => ee(t, i, l),
340
- [t]
341
- ), o = v(
342
- (i, l) => $(t, i, l),
343
- [t]
344
- ), c = v(
345
- (i, l, u) => be(t, i, l, u),
346
- [t]
347
- ), s = v(
348
- (i, l) => Fe(t, i, l),
349
- [t]
350
- );
351
- return {
352
- newSearch: n,
353
- updateSearch: o,
354
- toggleProductFilter: c,
355
- replaceFilter: s
356
- };
357
- }
358
- function Me({ from: e, size: r, pageSize: t }) {
359
- return H() ? {
360
- products: { from: e + t }
361
- } : {
362
- products: { size: r + t }
363
- };
364
- }
365
- function te(e = 24) {
366
- const { from: r, size: t } = y((c) => {
367
- var s, i;
368
- return {
369
- from: ((s = c.query.products) == null ? void 0 : s.from) ?? 0,
370
- size: ((i = c.query.products) == null ? void 0 : i.size) ?? 0
371
- };
372
- }), { updateSearch: n } = P();
373
- return {
374
- loadMore: v(async () => {
375
- await n(Me({ from: r, size: t, pageSize: e }));
376
- }, [r, t, e, n])
377
- };
378
- }
379
- function Ae({ pageSize: e }) {
380
- const { loadMore: r } = te(e);
381
- return /* @__PURE__ */ w("button", { onClick: r, children: "More results" });
382
- }
383
- function re(e, r) {
384
- var c, s, i;
385
- const t = ((c = r.products) == null ? void 0 : c.total) ?? 0, n = ((s = e.products) == null ? void 0 : s.from) ?? 0, o = ((i = e.products) == null ? void 0 : i.size) ?? 0;
386
- return t > 0 && t > n + o;
21
+ });
387
22
  }
388
- function Ie() {
389
- return !!(window.IntersectionObserver && window.IntersectionObserverEntry && "intersectionRatio" in window.IntersectionObserverEntry.prototype);
23
+ function _({ pageSize: e }) {
24
+ const { loadMore: n } = V(e);
25
+ return /* @__PURE__ */ C("button", { onClick: n, children: "More results" });
390
26
  }
391
- function Re({ children: e, loadMoreComponent: r, pageSize: t }) {
392
- const { loading: n, query: o, response: c } = y((i) => J(i, "loading", "query", "response")), s = !n && re(o, c);
393
- return /* @__PURE__ */ w(G, { children: [
27
+ function G({ children: e, loadMoreComponent: n, pageSize: t }) {
28
+ const { loading: r, query: o, response: a } = v((u) => D(u, "loading", "query", "response")), i = !r && O(o, a);
29
+ return /* @__PURE__ */ C(B, { children: [
394
30
  e,
395
- s && (r ? /* @__PURE__ */ w(r, { pageSize: t }) : /* @__PURE__ */ w(Ae, { pageSize: t }))
31
+ i && (n ? /* @__PURE__ */ C(n, { pageSize: t }) : /* @__PURE__ */ C(_, { pageSize: t }))
396
32
  ] });
397
33
  }
398
- function Ne({ children: e, pageSize: r }) {
399
- const t = oe(null), { query: n, response: o } = y((s) => J(s, "query", "response")), { loadMore: c } = te(r);
400
- return N(() => {
401
- let s, i;
402
- return re(n, o) && (s = t.current, i = new IntersectionObserver((l) => {
403
- const u = l[0];
404
- u != null && u.isIntersecting && c();
405
- }), s && i.observe(s)), () => {
406
- s && i.unobserve(s);
407
- };
408
- }, [o]), /* @__PURE__ */ w(G, { children: [
409
- e,
410
- /* @__PURE__ */ w("div", { ref: t, style: { height: "1px" } })
411
- ] });
412
- }
413
- const Ye = !H() && Ie() ? Ne : Re;
414
- function _e(e) {
34
+ const ye = !H() && U() ? W : G;
35
+ function J(e) {
415
36
  return e.type === "input";
416
37
  }
417
- function Te(e) {
38
+ function Q(e) {
418
39
  return !!e && typeof e == "object" && "type" in e && "props" in e;
419
40
  }
420
- function j(e, r = { depth: 0 }) {
41
+ function q(e, n = { depth: 0 }) {
421
42
  const { children: t } = e;
422
- return ne(t).map((n) => {
423
- if (!Te(n))
424
- return n;
425
- const o = e.updateElement(n, r);
43
+ return j(t).map((r) => {
44
+ if (!Q(r))
45
+ return r;
46
+ const o = e.updateElement(r, n);
426
47
  return o === null ? null : (o.props = {
427
48
  ...o.props,
428
- children: j({ ...e, children: o.props.children }, { depth: r.depth + 1 })
49
+ children: q({ ...e, children: o.props.children }, { depth: n.depth + 1 })
429
50
  }, o);
430
51
  });
431
52
  }
432
- function Xe({ children: e, onSearchInput: r }) {
433
- return j({
53
+ function ve({ children: e, onSearchInput: n }) {
54
+ return q({
434
55
  children: e,
435
- updateElement: (t) => (!_e(t) || t.props.type !== "search" || (t.props = {
56
+ updateElement: (t) => (!J(t) || t.props.type !== "search" || (t.props = {
436
57
  ...t.props,
437
- onInput: (n) => {
438
- n.target instanceof HTMLInputElement && r(n.target);
58
+ onInput: (r) => {
59
+ r.target instanceof HTMLInputElement && n(r.target);
439
60
  }
440
61
  }), t)
441
62
  });
442
63
  }
443
- const Oe = "nosto:search:scrollPos";
444
- function ze() {
445
- window.sessionStorage.setItem(Oe, window.scrollY.toString());
64
+ const X = "nosto:search:scrollPos";
65
+ function Z() {
66
+ window.sessionStorage.setItem(X, window.scrollY.toString());
446
67
  }
447
- function Ze({ children: e, hit: r, onClick: t }) {
448
- const { pageType: n } = Y(), o = n === "autocomplete" ? void 0 : n;
449
- return j({
68
+ function Se({ children: e, hit: n, onClick: t }) {
69
+ const { pageType: r } = $(), o = r === "autocomplete" ? void 0 : r;
70
+ return q({
450
71
  children: e,
451
- updateElement: (c, s) => (s.depth > 0 || (c.props = {
452
- ...c.props,
453
- onClick: (i) => {
454
- r && o && E((l) => l.recordSearchClick(o, r)), ze(), typeof t == "function" && t(i);
72
+ updateElement: (a, i) => (i.depth > 0 || (a.props = {
73
+ ...a.props,
74
+ onClick: (u) => {
75
+ n && o && b((d) => d.recordSearchClick(o, n)), Z(), typeof t == "function" && t(u);
455
76
  }
456
- }), c)
77
+ }), a)
457
78
  });
458
79
  }
459
- function D() {
460
- N(() => {
80
+ function E() {
81
+ I(() => {
461
82
  const e = window.setTimeout(() => {
462
83
  console.error("Nosto client script has not loaded after 3 seconds.");
463
84
  }, 3e3);
464
- E(() => {
85
+ b(() => {
465
86
  window.clearTimeout(e);
466
87
  });
467
88
  }, []);
468
89
  }
469
- const L = {
90
+ const z = {
470
91
  defaultCurrency: "EUR",
471
92
  queryModifications: (e) => e
472
- }, xe = {
473
- ...L
93
+ }, ee = {
94
+ ...z
474
95
  };
475
- function qe(e) {
96
+ function te(e) {
476
97
  return {
477
98
  pageType: "autocomplete",
478
- ...xe,
99
+ ...ee,
479
100
  ...e
480
101
  };
481
102
  }
482
- function et({ config: e, store: r, children: t }) {
483
- const n = r ?? _();
484
- return D(), /* @__PURE__ */ w(T, { value: qe(e), children: /* @__PURE__ */ w(A, { value: n, children: t }) });
103
+ function Ce({ config: e, store: n, children: t }) {
104
+ const r = n ?? x();
105
+ return E(), /* @__PURE__ */ C(T, { value: te(e), children: /* @__PURE__ */ C(R, { value: r, children: t }) });
485
106
  }
486
- const Ee = {
487
- ...L,
107
+ const ne = {
108
+ ...z,
488
109
  persistentSearchCache: !1,
489
110
  preservePageScroll: !1
490
111
  };
491
- function Ve(e) {
112
+ function re(e) {
492
113
  return {
493
114
  pageType: "category",
494
- ...Ee,
115
+ ...ne,
495
116
  ...e
496
117
  };
497
118
  }
498
- function tt({ config: e, store: r, children: t }) {
499
- const n = r ?? _();
500
- return D(), /* @__PURE__ */ w(T, { value: Ve(e), children: /* @__PURE__ */ w(A, { value: n, children: t }) });
119
+ function Me({ config: e, store: n, children: t }) {
120
+ const r = n ?? x();
121
+ return E(), /* @__PURE__ */ C(T, { value: re(e), children: /* @__PURE__ */ C(R, { value: r, children: t }) });
501
122
  }
502
- const $e = {
503
- ...L,
123
+ const oe = {
124
+ ...z,
504
125
  persistentSearchCache: !1,
505
126
  preservePageScroll: !1
506
127
  };
507
- function je(e = {}) {
128
+ function se(e = {}) {
508
129
  return {
509
130
  pageType: "serp",
510
- ...$e,
131
+ ...oe,
511
132
  ...e
512
133
  };
513
134
  }
514
- function rt({ config: e, store: r, children: t }) {
515
- const n = r ?? _();
516
- return D(), /* @__PURE__ */ w(T, { value: je(e), children: /* @__PURE__ */ w(A, { value: n, children: t }) });
135
+ function Fe({ config: e, store: n, children: t }) {
136
+ const r = n ?? x();
137
+ return E(), /* @__PURE__ */ C(T, { value: se(e), children: /* @__PURE__ */ C(R, { value: r, children: t }) });
517
138
  }
518
- function nt(e) {
519
- const r = y((t) => t.response);
520
- return e && Array.isArray(e) || e && F(e) ? e : r;
139
+ function Pe(e) {
140
+ const n = v((t) => t.response);
141
+ return e && Array.isArray(e) || e && K(e) ? e : n;
521
142
  }
522
- function ot(e) {
523
- var s;
524
- const r = ((s = e.data) == null ? void 0 : s.filter((i) => i.selected).length) ?? 0, [t, n] = I(r > 0), { toggleProductFilter: o } = P();
143
+ function we(e) {
144
+ var i;
145
+ const n = ((i = e.data) == null ? void 0 : i.filter((u) => u.selected).length) ?? 0, [t, r] = N(n > 0), { toggleProductFilter: o } = P();
525
146
  return {
526
147
  /** Active value */
527
148
  active: t,
528
149
  /** Selected filters count */
529
- selectedFiltersCount: r,
150
+ selectedFiltersCount: n,
530
151
  /** Toggle active function */
531
152
  toggleActive: () => {
532
- n(!t);
153
+ r(!t);
533
154
  },
534
155
  /** Toggle product filter function */
535
156
  toggleProductFilter: o
536
157
  };
537
158
  }
538
- function st() {
539
- const { loading: e, facets: r } = y((t) => {
540
- var n, o;
159
+ function be() {
160
+ const { loading: e, facets: n } = v((t) => {
161
+ var r, o;
541
162
  return {
542
163
  loading: t.loading,
543
- facets: ((o = (n = t.response) == null ? void 0 : n.products) == null ? void 0 : o.facets) ?? []
164
+ facets: ((o = (r = t.response) == null ? void 0 : r.products) == null ? void 0 : o.facets) ?? []
544
165
  };
545
166
  });
546
167
  return {
547
168
  /** Loading state */
548
169
  loading: e,
549
170
  /** Array of facets*/
550
- facets: r
171
+ facets: n
551
172
  };
552
173
  }
553
- function De(e, r) {
554
- const t = r - e;
555
- return !isNaN(t) && t > 0 ? new Array(r - e).fill(void 0).map((n, o) => o + e) : [];
174
+ function ie(e, n) {
175
+ const t = n - e;
176
+ return !isNaN(t) && t > 0 ? new Array(n - e).fill(void 0).map((r, o) => o + e) : [];
556
177
  }
557
- function it(e) {
558
- const { query: r, products: t } = y((n) => ({
559
- query: n.query,
560
- products: n.response.products
178
+ function Ae(e) {
179
+ const { query: n, products: t } = v((r) => ({
180
+ query: r.query,
181
+ products: r.response.products
561
182
  }));
562
- return M(() => {
563
- var k;
183
+ return A(() => {
184
+ var M;
564
185
  if (!t)
565
186
  return {
566
187
  totalPages: 0,
@@ -568,138 +189,138 @@ function it(e) {
568
189
  resultsTo: 0,
569
190
  pages: []
570
191
  };
571
- const n = ((k = r.products) == null ? void 0 : k.from) ?? 0, o = (e == null ? void 0 : e.width) ?? 1 / 0, c = Math.max(Math.floor(o - 1) / 2, 1), s = t.size > 0 ? Math.floor(n / t.size) + 1 : 1, i = t.size > 0 ? Math.ceil(t.total / t.size) : 0, l = (C) => C >= s - c && C <= s + c, u = n + 1, f = Math.min(n + t.total, t.total), a = {
572
- from: n,
573
- page: s,
192
+ const r = ((M = n.products) == null ? void 0 : M.from) ?? 0, o = (e == null ? void 0 : e.width) ?? 1 / 0, a = Math.max(Math.floor(o - 1) / 2, 1), i = t.size > 0 ? Math.floor(r / t.size) + 1 : 1, u = t.size > 0 ? Math.ceil(t.total / t.size) : 0, d = (y) => y >= i - a && y <= i + a, s = r + 1, l = Math.min(r + t.total, t.total), c = {
193
+ from: r,
194
+ page: i,
574
195
  current: !0
575
- }, d = (C) => ({
576
- from: (C - 1) * t.size,
577
- page: C,
578
- current: C === s
579
- }), m = s > 1 ? d(s - 1) : void 0, g = s < i ? d(s + 1) : void 0, h = c === 1 / 0 || s - c - 1 > 1 ? d(1) : void 0, p = c === 1 / 0 || s + c + 1 < i ? d(i) : void 0, S = De(1, i + 1).filter(l).map(d);
196
+ }, g = (y) => ({
197
+ from: (y - 1) * t.size,
198
+ page: y,
199
+ current: y === i
200
+ }), m = i > 1 ? g(i - 1) : void 0, f = i < u ? g(i + 1) : void 0, S = a === 1 / 0 || i - a - 1 > 1 ? g(1) : void 0, p = a === 1 / 0 || i + a + 1 < u ? g(u) : void 0, h = ie(1, u + 1).filter(d).map(g);
580
201
  return {
581
- totalPages: i,
582
- resultsFrom: u,
583
- resultsTo: f,
584
- current: a,
202
+ totalPages: u,
203
+ resultsFrom: s,
204
+ resultsTo: l,
205
+ current: c,
585
206
  prev: m,
586
- next: g,
587
- first: h,
207
+ next: f,
208
+ first: S,
588
209
  last: p,
589
- pages: S
210
+ pages: h
590
211
  };
591
- }, [r, t, e == null ? void 0 : e.width]);
592
- }
593
- function ct() {
594
- const [e, r] = I([]), [t, n] = I([]);
595
- return N(() => {
596
- E(async (o) => {
597
- const { products: c, segments: s } = await o.getSearchSessionParams();
598
- r(s ?? []), n((c == null ? void 0 : c.personalizationBoost) ?? []);
212
+ }, [n, t, e == null ? void 0 : e.width]);
213
+ }
214
+ function ke() {
215
+ const [e, n] = N([]), [t, r] = N([]);
216
+ return I(() => {
217
+ b(async (o) => {
218
+ const { products: a, segments: i } = await o.getSearchSessionParams();
219
+ n(i ?? []), r((a == null ? void 0 : a.personalizationBoost) ?? []);
599
220
  });
600
221
  }, []), {
601
222
  segments: e,
602
223
  boost: t
603
224
  };
604
225
  }
605
- function Le() {
606
- const { facets: e } = y((u) => {
607
- var f;
226
+ function ce() {
227
+ const { facets: e } = v((s) => {
228
+ var l;
608
229
  return {
609
- facets: ((f = u.response.products) == null ? void 0 : f.facets) ?? []
230
+ facets: ((l = s.response.products) == null ? void 0 : l.facets) ?? []
610
231
  };
611
- }), { replaceFilter: r, toggleProductFilter: t } = P(), n = v(
612
- (u) => {
613
- const f = e == null ? void 0 : e.find((a) => a.type === "stats" && a.field === u);
614
- if (f && "min" in f && "max" in f)
615
- return f;
232
+ }), { replaceFilter: n, toggleProductFilter: t } = P(), r = F(
233
+ (s) => {
234
+ const l = e == null ? void 0 : e.find((c) => c.type === "stats" && c.field === s);
235
+ if (l && "min" in l && "max" in l)
236
+ return l;
616
237
  },
617
238
  [e]
618
- ), o = v(
619
- (u) => {
620
- var f;
621
- return ((f = e == null ? void 0 : e.find((a) => a.field === u)) == null ? void 0 : f.name) ?? u;
239
+ ), o = F(
240
+ (s) => {
241
+ var l;
242
+ return ((l = e == null ? void 0 : e.find((c) => c.field === s)) == null ? void 0 : l.name) ?? s;
622
243
  },
623
244
  [e]
624
- ), c = v((u) => "field" in u && (u.value instanceof Array || u.range instanceof Array), []), s = v((u) => {
625
- var f;
245
+ ), a = F((s) => "field" in s && (s.value instanceof Array || s.range instanceof Array), []), i = F((s) => {
246
+ var l;
626
247
  return {
627
- ...u,
628
- range: (f = u.range) == null ? void 0 : f.map((a) => ({
629
- gt: a.gt ? Number(a.gt) : a.gt,
630
- gte: a.gte ? Number(a.gte) : a.gte,
631
- lt: a.lt ? Number(a.lt) : a.lt,
632
- lte: a.lte ? Number(a.lte) : a.lte
248
+ ...s,
249
+ range: (l = s.range) == null ? void 0 : l.map((c) => ({
250
+ gt: c.gt ? Number(c.gt) : c.gt,
251
+ gte: c.gte ? Number(c.gte) : c.gte,
252
+ lt: c.lt ? Number(c.lt) : c.lt,
253
+ lte: c.lte ? Number(c.lte) : c.lte
633
254
  }))
634
255
  };
635
- }, []), i = v(
636
- (u) => (u.value ?? []).map((a) => ({
637
- value: a,
638
- field: u.field,
639
- name: o(u.field),
640
- filter: s(u),
256
+ }, []), u = F(
257
+ (s) => (s.value ?? []).map((c) => ({
258
+ value: c,
259
+ field: s.field,
260
+ name: o(s.field),
261
+ filter: i(s),
641
262
  remove: () => {
642
- t(u.field, a, !1);
263
+ t(s.field, c, !1);
643
264
  }
644
265
  })),
645
- [s, o, t]
646
- ), l = v(
647
- (u) => (u.range ?? []).map((a) => {
648
- var g, h;
649
- const d = a.gte ?? a.gt ?? ((g = n(u.field)) == null ? void 0 : g.min), m = a.lte ?? a.lt ?? ((h = n(u.field)) == null ? void 0 : h.max);
650
- if (d !== void 0 && m !== void 0)
266
+ [i, o, t]
267
+ ), d = F(
268
+ (s) => (s.range ?? []).map((c) => {
269
+ var f, S;
270
+ const g = c.gte ?? c.gt ?? ((f = r(s.field)) == null ? void 0 : f.min), m = c.lte ?? c.lt ?? ((S = r(s.field)) == null ? void 0 : S.max);
271
+ if (g !== void 0 && m !== void 0)
651
272
  return {
652
- value: `${d} - ${m}`,
653
- field: u.field,
654
- name: o(u.field),
655
- filter: s(u),
273
+ value: `${g} - ${m}`,
274
+ field: s.field,
275
+ name: o(s.field),
276
+ filter: i(s),
656
277
  remove: () => {
657
- r(u.field, void 0);
278
+ n(s.field, void 0);
658
279
  }
659
280
  };
660
281
  }).filter(Boolean),
661
- [s, n, o, r]
282
+ [i, r, o, n]
662
283
  );
663
284
  return {
664
- selectFilters: c,
665
- toValueFilter: i,
666
- toRangeFilter: l
285
+ selectFilters: a,
286
+ toValueFilter: u,
287
+ toRangeFilter: d
667
288
  };
668
289
  }
669
- function Be() {
670
- const { filter: e } = y((i) => {
671
- var l;
290
+ function ae() {
291
+ const { filter: e } = v((u) => {
292
+ var d;
672
293
  return {
673
- filter: ((l = i.query.products) == null ? void 0 : l.filter) ?? []
294
+ filter: ((d = u.query.products) == null ? void 0 : d.filter) ?? []
674
295
  };
675
- }), { updateSearch: r } = P(), { selectFilters: t, toValueFilter: n, toRangeFilter: o } = Le(), c = M(() => e ? e.filter(t).flatMap((i) => "value" in i ? n(i) : "range" in i ? o(i) : []).filter(Boolean) : [], [e, t, o, n]), s = v(() => {
676
- r({
296
+ }), { updateSearch: n } = P(), { selectFilters: t, toValueFilter: r, toRangeFilter: o } = ce(), a = A(() => e ? e.filter(t).flatMap((u) => "value" in u ? r(u) : "range" in u ? o(u) : []).filter(Boolean) : [], [e, t, o, r]), i = F(() => {
297
+ n({
677
298
  products: {
678
299
  filter: []
679
300
  }
680
301
  });
681
- }, [r]);
302
+ }, [n]);
682
303
  return {
683
304
  /** Selected filters array. */
684
- filters: c,
305
+ filters: a,
685
306
  /** Should remove all selected filters. */
686
- removeAll: s
307
+ removeAll: i
687
308
  };
688
309
  }
689
- function R(e) {
310
+ function w(e) {
690
311
  if (typeof e == "number")
691
312
  return e;
692
313
  if (typeof e != "string")
693
314
  return;
694
- const r = Number(e);
695
- return isNaN(r) ? void 0 : r;
696
- }
697
- function Ue(e) {
698
- var a, d, m;
699
- const { replaceFilter: r } = P(), { query: t, products: n } = y((g) => ({
700
- query: g.query,
701
- products: g.response.products
702
- })), o = (a = n == null ? void 0 : n.facets) == null ? void 0 : a.find((g) => g.id === e);
315
+ const n = Number(e);
316
+ return isNaN(n) ? void 0 : n;
317
+ }
318
+ function ue(e) {
319
+ var c, g, m;
320
+ const { replaceFilter: n } = P(), { query: t, products: r } = v((f) => ({
321
+ query: f.query,
322
+ products: f.response.products
323
+ })), o = (c = r == null ? void 0 : r.facets) == null ? void 0 : c.find((f) => f.id === e);
703
324
  if (!o)
704
325
  return {
705
326
  min: 0,
@@ -708,173 +329,173 @@ function Ue(e) {
708
329
  updateRange: () => {
709
330
  }
710
331
  };
711
- const c = (m = (d = t.products) == null ? void 0 : d.filter) == null ? void 0 : m.find((g) => g.field === o.field), s = c != null && c.range ? c.range[0] : void 0, i = typeof s == "object" && ("gte" in s || "lte" in s) ? [R(s.gte), R(s.lte)] : [void 0, void 0], l = "min" in o ? Math.floor(o.min) : 0, u = "max" in o ? Math.ceil(o.max) : 0, f = ([g, h]) => {
712
- const p = g !== void 0 ? Math.floor(g) : void 0, S = h !== void 0 ? Math.ceil(h) : void 0, k = p !== void 0, C = S !== void 0;
713
- (l === p || !k) && (u === S || !C) ? r(o.field, void 0) : (l === p || !k) && C ? r(o.field, {
714
- lte: S.toString()
715
- }) : (u === S || !C) && k ? r(o.field, {
332
+ const a = (m = (g = t.products) == null ? void 0 : g.filter) == null ? void 0 : m.find((f) => f.field === o.field), i = a != null && a.range ? a.range[0] : void 0, u = typeof i == "object" && ("gte" in i || "lte" in i) ? [w(i.gte), w(i.lte)] : [void 0, void 0], d = "min" in o ? Math.floor(o.min) : 0, s = "max" in o ? Math.ceil(o.max) : 0, l = ([f, S]) => {
333
+ const p = f !== void 0 ? Math.floor(f) : void 0, h = S !== void 0 ? Math.ceil(S) : void 0, M = p !== void 0, y = h !== void 0;
334
+ (d === p || !M) && (s === h || !y) ? n(o.field, void 0) : (d === p || !M) && y ? n(o.field, {
335
+ lte: h.toString()
336
+ }) : (s === h || !y) && M ? n(o.field, {
716
337
  gte: p.toString()
717
- }) : k && C && r(o.field, {
338
+ }) : M && y && n(o.field, {
718
339
  gte: p.toString(),
719
- lte: S.toString()
340
+ lte: h.toString()
720
341
  });
721
342
  };
722
343
  return {
723
344
  /** Min value */
724
- min: l,
345
+ min: d,
725
346
  /** Max value */
726
- max: u,
347
+ max: s,
727
348
  /** Range value */
728
- range: [i[0] ?? l, i[1] ?? u],
349
+ range: [u[0] ?? d, u[1] ?? s],
729
350
  /** Update range function */
730
- updateRange: f
351
+ updateRange: l
731
352
  };
732
353
  }
733
- function ut(e, r) {
734
- const { min: t, max: n, range: o, updateRange: c } = Ue(e), { filters: s } = Be(), i = M(() => {
735
- var h;
736
- const a = s.find((p) => {
737
- var S;
738
- return (S = p == null ? void 0 : p.filter) == null ? void 0 : S.range;
354
+ function Ne(e, n) {
355
+ const { min: t, max: r, range: o, updateRange: a } = ue(e), { filters: i } = ae(), u = A(() => {
356
+ var S;
357
+ const c = i.find((p) => {
358
+ var h;
359
+ return (h = p == null ? void 0 : p.filter) == null ? void 0 : h.range;
739
360
  });
740
- let d = null;
741
- if (a) {
742
- const p = (h = a.filter.range) == null ? void 0 : h[0];
743
- d = [R(p == null ? void 0 : p.gte), R(p == null ? void 0 : p.lte)];
361
+ let g = null;
362
+ if (c) {
363
+ const p = (S = c.filter.range) == null ? void 0 : S[0];
364
+ g = [w(p == null ? void 0 : p.gte), w(p == null ? void 0 : p.lte)];
744
365
  }
745
366
  const m = [];
746
- let g = Math.floor(t / r) * r;
747
- for (; g < n; ) {
748
- const p = g + r, S = d && d[0] === g && d[1] === p;
367
+ let f = Math.floor(t / n) * n;
368
+ for (; f < r; ) {
369
+ const p = f + n, h = g && g[0] === f && g[1] === p;
749
370
  m.push({
750
- min: g,
371
+ min: f,
751
372
  max: p,
752
- selected: S
753
- }), g = p;
373
+ selected: h
374
+ }), f = p;
754
375
  }
755
376
  return m;
756
- }, [s, t, n, r]), l = (a) => {
757
- c([a, o[1]]);
758
- }, u = (a) => {
759
- c([o[0], a]);
760
- }, f = t !== o[0] || n !== o[1];
377
+ }, [i, t, r, n]), d = (c) => {
378
+ a([c, o[1]]);
379
+ }, s = (c) => {
380
+ a([o[0], c]);
381
+ }, l = t !== o[0] || r !== o[1];
761
382
  return {
762
383
  /** Minimum value */
763
384
  min: t,
764
385
  /** Maximum value */
765
- max: n,
386
+ max: r,
766
387
  /** Range value */
767
388
  range: o,
768
389
  /** Update range function */
769
- updateRange: c,
390
+ updateRange: a,
770
391
  /** Ranges */
771
- ranges: i,
392
+ ranges: u,
772
393
  /** Handle min change */
773
- handleMinChange: l,
394
+ handleMinChange: d,
774
395
  /** Handle max change */
775
- handleMaxChange: u,
396
+ handleMaxChange: s,
776
397
  /** Is selected */
777
- isSelected: f
398
+ isSelected: l
778
399
  };
779
400
  }
780
- function at() {
781
- const { products: e, keywords: r } = y((t) => t.response);
401
+ function xe() {
402
+ const { products: e, keywords: n } = v((t) => t.response);
782
403
  return {
783
404
  /** Array of products */
784
405
  products: e ?? { hits: [], total: 0 },
785
406
  /** Array of keywords */
786
- keywords: r ?? { hits: [], total: 0 }
407
+ keywords: n ?? { hits: [], total: 0 }
787
408
  };
788
409
  }
789
- function lt() {
790
- const e = y((t) => {
791
- var n;
792
- return (n = t.query.products) == null ? void 0 : n.filter;
410
+ function Re() {
411
+ const e = v((t) => {
412
+ var r;
413
+ return (r = t.query.products) == null ? void 0 : r.filter;
793
414
  });
794
- return M(() => e ? e.reduce((t, n) => t + (Array.isArray(n.value) ? n.value.length : 1), 0) : 0, [e]);
415
+ return A(() => e ? e.reduce((t, r) => t + (Array.isArray(r.value) ? r.value.length : 1), 0) : 0, [e]);
795
416
  }
796
- function z(e) {
417
+ function k(e) {
797
418
  return e && !Number.isNaN(e) ? e : 0;
798
419
  }
799
- function ft(e, r) {
800
- const { from: t, size: n, total: o } = y((u) => {
801
- var f, a, d, m, g;
420
+ function Te(e, n) {
421
+ const { from: t, size: r, total: o } = v((s) => {
422
+ var l, c, g, m, f;
802
423
  return {
803
- from: z(((f = u.query.products) == null ? void 0 : f.from) ?? 0),
804
- size: z(((d = (a = u.response) == null ? void 0 : a.products) == null ? void 0 : d.size) ?? 0),
805
- total: z(((g = (m = u.response) == null ? void 0 : m.products) == null ? void 0 : g.total) ?? 0)
424
+ from: k(((l = s.query.products) == null ? void 0 : l.from) ?? 0),
425
+ size: k(((g = (c = s.response) == null ? void 0 : c.products) == null ? void 0 : g.size) ?? 0),
426
+ total: k(((f = (m = s.response) == null ? void 0 : m.products) == null ? void 0 : f.total) ?? 0)
806
427
  };
807
- }), { updateSearch: c } = P(), s = t + n, i = [...e].reverse().filter((u) => u + r < o);
428
+ }), { updateSearch: a } = P(), i = t + r, u = [...e].reverse().filter((s) => s + n < o);
808
429
  return {
809
430
  /** from value */
810
431
  from: t,
811
432
  /** to value */
812
- to: s,
433
+ to: i,
813
434
  /** total value */
814
435
  total: o,
815
436
  /** size value */
816
- size: n,
437
+ size: r,
817
438
  /** Array of size options */
818
- sizeOptions: i,
439
+ sizeOptions: u,
819
440
  /** Should be called when size is changed */
820
- handleSizeChange: (u) => {
821
- c({
441
+ handleSizeChange: (s) => {
442
+ a({
822
443
  products: {
823
- size: u
444
+ size: s
824
445
  }
825
446
  });
826
447
  }
827
448
  };
828
449
  }
829
- function Qe(e, r) {
830
- return e.length !== r.length ? !1 : e.every((t) => r.find((n) => t.field === n.field && t.order === n.order));
450
+ function le(e, n) {
451
+ return e.length !== n.length ? !1 : e.every((t) => n.find((r) => t.field === r.field && t.order === r.order));
831
452
  }
832
- function dt(e) {
833
- var c, s;
834
- const r = y((i) => i.query), { updateSearch: t } = P();
453
+ function qe(e) {
454
+ var a, i;
455
+ const n = v((u) => u.query), { updateSearch: t } = P();
835
456
  return {
836
457
  /** Active sort */
837
- activeSort: ((c = e.find((i) => {
838
- var l;
839
- return Qe(i.value.sort, ((l = r.products) == null ? void 0 : l.sort) || []);
840
- })) == null ? void 0 : c.id) ?? ((s = e[0]) == null ? void 0 : s.id),
458
+ activeSort: ((a = e.find((u) => {
459
+ var d;
460
+ return le(u.value.sort, ((d = n.products) == null ? void 0 : d.sort) || []);
461
+ })) == null ? void 0 : a.id) ?? ((i = e[0]) == null ? void 0 : i.id),
841
462
  /** Set sort function */
842
- setSort: (i) => {
843
- const l = e.find((u) => u.id === i);
844
- l && t({
463
+ setSort: (u) => {
464
+ const d = e.find((s) => s.id === u);
465
+ d && t({
845
466
  products: {
846
- sort: l.value.sort
467
+ sort: d.value.sort
847
468
  }
848
469
  });
849
470
  }
850
471
  };
851
472
  }
852
473
  export {
853
- et as AutocompletePageProvider,
854
- tt as CategoryPageProvider,
855
- Ye as InfiniteScroll,
856
- Re as InfiniteScrollWithLink,
857
- Xe as SearchInput,
858
- rt as SearchPageProvider,
859
- Ze as SerpElement,
860
- A as StoreContext,
861
- ce as createExtendableStore,
862
- _ as createStore,
863
- ue as defaultState,
864
- Me as getNextPageQuery,
474
+ he as AutocompleteElement,
475
+ Ce as AutocompletePageProvider,
476
+ Me as CategoryPageProvider,
477
+ ye as InfiniteScroll,
478
+ G as InfiniteScrollWithLink,
479
+ ve as SearchInput,
480
+ Fe as SearchPageProvider,
481
+ Se as SerpElement,
482
+ R as StoreContext,
483
+ Ie as createExtendableStore,
484
+ x as createStore,
485
+ Le as defaultState,
865
486
  P as useActions,
866
- nt as useDecoratedSearchResults,
867
- ot as useFacet,
868
- st as useFacets,
869
- te as useLoadMore,
870
- y as useNostoAppState,
871
- it as usePagination,
872
- ct as usePersonalization,
873
- Be as useProductFilters,
874
- Ue as useRange,
875
- ut as useRangeSelector,
876
- at as useResponse,
877
- lt as useSelectedFiltersCount,
878
- ft as useSizeOptions,
879
- dt as useSort
487
+ Pe as useDecoratedSearchResults,
488
+ we as useFacet,
489
+ be as useFacets,
490
+ V as useLoadMore,
491
+ v as useNostoAppState,
492
+ Ae as usePagination,
493
+ ke as usePersonalization,
494
+ ae as useProductFilters,
495
+ ue as useRange,
496
+ Ne as useRangeSelector,
497
+ xe as useResponse,
498
+ Re as useSelectedFiltersCount,
499
+ Te as useSizeOptions,
500
+ qe as useSort
880
501
  };