@nosto/search-js 3.14.0 → 3.15.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.
Files changed (53) hide show
  1. package/dist/AutocompletePageProvider-BJxsORbo.cjs +1 -0
  2. package/dist/AutocompletePageProvider-DI2PONk8.js +37 -0
  3. package/dist/{CategoryPageProvider-Clj40F3F.cjs → CategoryPageProvider-CYRnaUx1.cjs} +1 -1
  4. package/dist/{CategoryPageProvider-Bou8i9Tx.js → CategoryPageProvider-DcQlylFg.js} +2 -2
  5. package/dist/{InfiniteScrollWithObserver-CoPOQr8Q.cjs → InfiniteScrollWithObserver-BN-pDinB.cjs} +1 -1
  6. package/dist/{InfiniteScrollWithObserver-6A57AOKr.js → InfiniteScrollWithObserver-CEtMyahq.js} +1 -1
  7. package/dist/{SerpPageProvider-B-W6nCqu.js → SerpPageProvider-CsrFA6mA.js} +2 -2
  8. package/dist/{SerpPageProvider-pR-E8S6m.cjs → SerpPageProvider-s4dO49Fx.cjs} +1 -1
  9. package/dist/baseConfig-BMc1698x.js +48 -0
  10. package/dist/baseConfig-gkfFlBOL.cjs +1 -0
  11. package/dist/core/core.cjs.js +1 -1
  12. package/dist/core/core.es.js +1 -1
  13. package/dist/{bindInput-CCx0Fhsg.js → disableNativeAutocomplete-Bkta_WR2.js} +6 -6
  14. package/dist/disableNativeAutocomplete-DI6zaZII.cjs +1 -0
  15. package/dist/preact/autocomplete/autocomplete.cjs.js +1 -1
  16. package/dist/preact/autocomplete/autocomplete.es.js +1 -1
  17. package/dist/preact/category/category.cjs.js +1 -1
  18. package/dist/preact/category/category.es.js +1 -1
  19. package/dist/preact/common/common.cjs.js +1 -1
  20. package/dist/preact/common/common.es.js +3 -3
  21. package/dist/preact/hooks/hooks.cjs.js +1 -1
  22. package/dist/preact/hooks/hooks.d.ts +1 -0
  23. package/dist/preact/hooks/hooks.es.js +14 -12
  24. package/dist/preact/hooks/src/useHistory.d.ts +5 -0
  25. package/dist/preact/inject/inject.cjs.js +1 -1
  26. package/dist/preact/inject/inject.d.ts +0 -1
  27. package/dist/preact/inject/inject.es.js +183 -215
  28. package/dist/preact/inject/src/init/injectAutocomplete.d.ts +1 -1
  29. package/dist/preact/legacy/legacy.cjs.js +1 -1
  30. package/dist/preact/legacy/legacy.es.js +3 -3
  31. package/dist/preact/serp/serp.cjs.js +1 -1
  32. package/dist/preact/serp/serp.es.js +3 -3
  33. package/dist/{search-DTqo1D6Y.cjs → search-RNs4Cunh.cjs} +1 -1
  34. package/dist/{search-sC5QgJmw.js → search-mArZ2PXy.js} +14 -14
  35. package/dist/{useActions-CJ71kc2N.cjs → useActions-Drtoxcu4.cjs} +1 -1
  36. package/dist/{useActions-SEyBHGra.js → useActions-MsVW37eV.js} +3 -3
  37. package/dist/useHistory-2uGnArVO.cjs +1 -0
  38. package/dist/useHistory-W6FQSk99.js +20 -0
  39. package/dist/{useLoadMore-hrNp8P0M.js → useLoadMore-BR-vDmqW.js} +1 -1
  40. package/dist/{useLoadMore-B0JgcUfM.cjs → useLoadMore-DPYhbXHC.cjs} +1 -1
  41. package/dist/utils/src/bindInput.d.ts +0 -1
  42. package/dist/utils/src/disableNativeAutocomplete.d.ts +1 -0
  43. package/dist/utils/src/storage.d.ts +3 -0
  44. package/dist/utils/utils.cjs.js +1 -1
  45. package/dist/utils/utils.d.ts +2 -1
  46. package/dist/utils/utils.es.js +1 -1
  47. package/package.json +5 -5
  48. package/dist/AutocompletePageProvider-99syi-nl.cjs +0 -1
  49. package/dist/AutocompletePageProvider-HeGU8tjH.js +0 -29
  50. package/dist/baseConfig-CoxOyC7r.cjs +0 -1
  51. package/dist/baseConfig-DzkbWglo.js +0 -48
  52. package/dist/bindInput-BnKvCky1.cjs +0 -1
  53. package/dist/preact/inject/src/init/autocomplete/AutocompleteContext.d.ts +0 -12
@@ -1,35 +1,34 @@
1
- import { A as I, m as D } from "../../AutocompletePageProvider-HeGU8tjH.js";
2
- import { C as R, m as O } from "../../CategoryPageProvider-Bou8i9Tx.js";
3
- import { n as L, c as p } from "../../useActions-SEyBHGra.js";
4
- import { S as $, m as j } from "../../SerpPageProvider-B-W6nCqu.js";
1
+ import { A as L, m as j } from "../../AutocompletePageProvider-DI2PONk8.js";
2
+ import { C as O, m as R } from "../../CategoryPageProvider-DcQlylFg.js";
3
+ import { n as T, c as p } from "../../useActions-MsVW37eV.js";
4
+ import { S as $, m as F } from "../../SerpPageProvider-CsrFA6mA.js";
5
5
  import { u as d } from "../../jsxRuntime.module-Bzuv3cXw.js";
6
- import { E as u } from "../../ErrorBoundary-DTRm_60r.js";
7
- import { d as F, b as B } from "../../bindInput-CCx0Fhsg.js";
8
- import { a as T } from "../../unique-Cv2g464w.js";
9
- import { createContext as K, render as y } from "preact";
10
- import { l as x } from "../../logger-_fg_Za9y.js";
11
- import { s as Q } from "../../index.es-XNBESE3P.js";
12
- import { g as w, a as U } from "../../search-sC5QgJmw.js";
13
- function v(e) {
14
- let t;
15
- return (n) => {
16
- t && clearTimeout(t), t = setTimeout(n, e);
6
+ import { E as h } from "../../ErrorBoundary-DTRm_60r.js";
7
+ import { d as k, b as B } from "../../disableNativeAutocomplete-Bkta_WR2.js";
8
+ import { a as I } from "../../unique-Cv2g464w.js";
9
+ import { render as y } from "preact";
10
+ import { l as q } from "../../logger-_fg_Za9y.js";
11
+ import { g as w, a as Q } from "../../search-mArZ2PXy.js";
12
+ function U(e) {
13
+ let n;
14
+ return (t) => {
15
+ n && clearTimeout(n), n = setTimeout(t, e);
17
16
  };
18
17
  }
19
- function S(e) {
18
+ function b(e) {
20
19
  return Array.from(document.querySelectorAll(e));
21
20
  }
22
- function M(e) {
23
- const t = [];
24
- let n = e.parentNode;
25
- for (; n && n !== document && n instanceof Element; )
26
- t.push(n), n = n.parentNode;
27
- return t;
21
+ function K(e) {
22
+ const n = [];
23
+ let t = e.parentNode;
24
+ for (; t && t !== document && t instanceof Element; )
25
+ n.push(t), t = t.parentNode;
26
+ return n;
28
27
  }
29
- function b([e, t], n) {
28
+ function S([e, n], t) {
30
29
  const o = (r) => {
31
- const i = r.target;
32
- i instanceof HTMLElement && e && i !== e && i !== t && !M(i).includes(e) && n();
30
+ const s = r.target;
31
+ s instanceof HTMLElement && e && s !== e && s !== n && !K(s).includes(e) && t();
33
32
  };
34
33
  return document.addEventListener("click", o), {
35
34
  destroy: () => {
@@ -37,8 +36,8 @@ function b([e, t], n) {
37
36
  }
38
37
  };
39
38
  }
40
- function E(e, t) {
41
- e.tabIndex = 0, e.addEventListener("blur", t);
39
+ function E(e, n) {
40
+ e.tabIndex = 0, e.addEventListener("blur", n);
42
41
  }
43
42
  function C(e) {
44
43
  return typeof e == "string" ? {
@@ -49,304 +48,274 @@ function C(e) {
49
48
  ...e
50
49
  };
51
50
  }
52
- function H({ selector: e, timeout: t = 500 }) {
53
- return new Promise((n) => {
54
- const o = S(e);
51
+ function N({ selector: e, timeout: n = 500 }) {
52
+ return new Promise((t) => {
53
+ const o = b(e);
55
54
  if (o.length > 0)
56
- return n(o);
55
+ return t(o);
57
56
  const r = new MutationObserver(() => {
58
- const s = S(e);
59
- s.length > 0 && (r.disconnect(), clearTimeout(i), n(s));
60
- }), i = setTimeout(() => {
61
- r.disconnect(), x.warn(`Timed out (${t}) while waiting for element ${e}`), n([]);
62
- }, t);
57
+ const i = b(e);
58
+ i.length > 0 && (r.disconnect(), clearTimeout(s), t(i));
59
+ }), s = setTimeout(() => {
60
+ r.disconnect(), q.warn(`Timed out (${n}) while waiting for element ${e}`), t([]);
61
+ }, n);
63
62
  r.observe(document.body, {
64
63
  childList: !0,
65
64
  subtree: !0
66
65
  });
67
66
  });
68
67
  }
69
- const z = K({
70
- reportProductClick: () => {
71
- },
72
- reportKeywordClick: () => {
73
- },
74
- handleSubmit: () => {
75
- },
76
- highlightedElementIndex: -1
77
- });
78
- function G(e, t) {
79
- const { dropdown: n, history: o, store: r, input: i, onNavigateToSearch: s } = e, a = (c, h) => {
80
- n.hide(), o.hide(), c && (o.add(c), r.updateState({
81
- historyItems: o.get()
82
- }), h && Q((l) => l.recordSearchSubmit(c)), i.value = c);
83
- };
84
- return {
85
- reportProductClick: (c) => {
86
- a(c.name, !1);
87
- },
88
- reportKeywordClick: (c) => {
89
- a(c.keyword, !0);
90
- },
91
- handleSubmit: (c) => {
92
- a(c.query, !1), s?.(c);
93
- },
94
- highlightedElementIndex: t.highlightedIndex()
95
- };
96
- }
97
- function N(e, t, n) {
98
- t.style.display = "none";
68
+ function H(e, n, t) {
69
+ n.style.display = "none";
99
70
  const o = (() => {
100
71
  if (e.parentElement && e.parentElement.classList.contains("nosto-autocomplete-wrapper"))
101
72
  return e.parentElement;
102
- const l = document.createElement("div");
103
- return l.className = "nosto-autocomplete-wrapper", e.parentNode?.insertBefore(l, e.nextSibling), l.appendChild(e), l;
104
- })(), r = C(n), i = r && document.querySelector(r.selector);
105
- if (i) {
106
- const l = document.createElement("form");
107
- l.className = "nosto-dropdown-form", l.appendChild(t), r.position === "first" ? i.prepend(l) : i.appendChild(l);
73
+ const a = document.createElement("div");
74
+ return a.className = "nosto-autocomplete-wrapper", e.parentNode?.insertBefore(a, e.nextSibling), a.appendChild(e), a;
75
+ })(), r = C(t), s = r && document.querySelector(r.selector);
76
+ if (s) {
77
+ const a = document.createElement("form");
78
+ a.className = "nosto-dropdown-form", a.appendChild(n), r.position === "first" ? s.prepend(a) : s.appendChild(a);
108
79
  } else
109
- o.appendChild(t);
110
- const s = {
80
+ o.appendChild(n);
81
+ const i = {
111
82
  index: -1,
112
83
  onChangeListeners: []
113
- }, a = (l, m) => {
114
- const f = l.length;
115
- f === 0 && (m = -1), s.index = m >= 0 ? m % f : f - 1, s.onChangeListeners.forEach((P) => P());
116
- }, c = () => {
117
- s.index = -1, s.onChangeListeners.forEach((l) => l());
118
- }, h = () => s.index;
84
+ }, c = (a, m) => {
85
+ const f = a.length;
86
+ f === 0 && (m = -1), i.index = m >= 0 ? m % f : f - 1, i.onChangeListeners.forEach((D) => D());
87
+ }, l = () => {
88
+ i.index = -1, i.onChangeListeners.forEach((a) => a());
89
+ }, u = () => i.index;
119
90
  return {
120
- element: t,
91
+ element: n,
121
92
  hide: () => {
122
- t.style.display = "none", c();
93
+ n.style.display = "none", l();
123
94
  },
124
95
  show: () => {
125
- t.style.display = "inherit";
96
+ n.style.display = "inherit";
126
97
  },
127
- isOpen: () => t.style.display !== "none",
98
+ isOpen: () => n.style.display !== "none",
128
99
  goDown: () => {
129
- const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
130
- a(l, m + 1);
100
+ const a = Array.from(n.getElementsByClassName("ns-autocomplete-element")), m = u();
101
+ c(a, m + 1);
131
102
  },
132
103
  goUp: () => {
133
- const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
134
- a(l, m - 1);
104
+ const a = Array.from(n.getElementsByClassName("ns-autocomplete-element")), m = u();
105
+ c(a, m - 1);
135
106
  },
136
- highlight: a,
137
- highlightedIndex: h,
138
- submitHighlightedItem: (l) => {
139
- Array.from(t.querySelectorAll(".ns-autocomplete-element"))[l]?.click();
107
+ highlight: c,
108
+ highlightedIndex: u,
109
+ submitHighlightedItem: (a) => {
110
+ Array.from(n.querySelectorAll(".ns-autocomplete-element"))[a]?.click();
140
111
  },
141
- onHighlightChange: (l) => {
142
- s.onChangeListeners.push(l);
112
+ onHighlightChange: (a) => {
113
+ i.onChangeListeners.push(a);
143
114
  }
144
115
  };
145
116
  }
146
- function J(e, t) {
147
- const n = document.createElement("div");
148
- return n.className = "nosto-autocomplete-dropdown", {
149
- ...N(e, n, t),
150
- element: n
117
+ function M(e, n) {
118
+ const t = document.createElement("div");
119
+ return t.className = "nosto-autocomplete-dropdown", {
120
+ ...H(e, t, n),
121
+ element: t
151
122
  };
152
123
  }
153
124
  const g = "nosto:search-js:history";
154
- function V(e, t, n) {
125
+ function v(e, n, t) {
155
126
  const o = document.createElement("div");
156
127
  return o.className = "nosto-autocomplete-history", {
157
- ...N(e, o, t),
128
+ ...H(e, o, n),
158
129
  element: o,
159
- add: (i) => {
160
- const a = (w(g) ?? []).filter((c) => c !== i).slice(n ? -n : 0);
161
- a.push(i), U(g, a);
130
+ add: (s) => {
131
+ const c = (w(g) ?? []).filter((l) => l !== s).slice(t ? -t : 0);
132
+ c.push(s), Q(g, c);
162
133
  },
163
- get: () => (w(g) ?? []).reverse().filter((s) => !!s)
134
+ get: () => (w(g) ?? []).reverse().filter((i) => !!i)
164
135
  };
165
136
  }
166
- async function W(e, { config: t, dropdown: n, history: o, renderHistory: r, store: i }) {
167
- const { historyEnabled: s, minQueryLength: a } = t;
168
- if (e.length < a && s && r && !o.isOpen()) {
137
+ async function z(e, { config: n, dropdown: t, history: o, renderHistory: r, store: s }) {
138
+ const { historyEnabled: i, minQueryLength: c } = n;
139
+ if (e.length < c && i && r && !o.isOpen()) {
169
140
  o.show();
170
141
  return;
171
142
  }
172
- if (e.length < a)
143
+ if (e.length < c)
173
144
  return;
174
- n.hide();
175
- const c = i.getState()?.query?.query;
176
- c && c !== e && await L({ config: t, store: i }, { query: e }), n.show();
145
+ t.hide();
146
+ const l = s.getState()?.query?.query;
147
+ l && l !== e && await T({ config: n, store: s }, { query: e }), t.show();
177
148
  }
178
- async function X(e, t) {
179
- const { config: n, renderHistory: o, history: r } = t, { historyEnabled: i, minQueryLength: s } = n;
180
- if (!o || e.length >= s || !i || r.isOpen())
149
+ async function G(e, n) {
150
+ const { config: t, renderHistory: o, history: r } = n, { historyEnabled: s, minQueryLength: i } = t;
151
+ if (!o || e.length >= i || !s || r.isOpen())
181
152
  return;
182
- const a = q(t, r);
153
+ const c = x(n);
183
154
  r.onHighlightChange(() => {
184
- a(o, r.element);
155
+ c(o, r.element);
185
156
  }), r.show();
186
- const c = T("renderHistory");
187
- a(o, r.element), c();
157
+ const l = I("renderHistory");
158
+ c(o, r.element), l();
188
159
  }
189
- async function Y(e, { config: t, dropdown: n, history: o, store: r, debouncer: i }) {
190
- const { minQueryLength: s, historyEnabled: a } = t;
191
- if (e.length < s && !a) {
192
- n.hide(), o.hide();
160
+ async function J(e, { config: n, dropdown: t, history: o, store: r, debouncer: s }) {
161
+ const { minQueryLength: i, historyEnabled: c } = n;
162
+ if (e.length < i && !c) {
163
+ t.hide(), o.hide();
193
164
  return;
194
165
  }
195
- if (e.length < s && a) {
196
- n.hide(), o.show();
166
+ if (e.length < i && c) {
167
+ t.hide(), o.show();
197
168
  return;
198
169
  }
199
- o.hide(), i(async () => {
200
- L({ config: t, store: r }, { query: e }), n.show();
170
+ o.hide(), s(async () => {
171
+ T({ config: n, store: r }, { query: e }), t.show();
201
172
  });
202
173
  }
203
- function Z(e, t, n) {
204
- const { config: o, debouncer: r } = n;
174
+ function V(e, n, t) {
175
+ const { config: o, debouncer: r } = t;
205
176
  if (r(() => {
206
177
  }), e.length >= o.minQueryLength)
207
- return A(t, n.dropdown, n.history);
178
+ return A(n, t.dropdown, t.history);
208
179
  if (o.historyEnabled)
209
- return A(t, n.history, n.dropdown);
180
+ return A(n, t.history, t.dropdown);
210
181
  }
211
- function A(e, t, n) {
212
- if (!t.isOpen() && e === "ArrowDown") {
213
- t.show(), n.hide();
182
+ function A(e, n, t) {
183
+ if (!n.isOpen() && e === "ArrowDown") {
184
+ n.show(), t.hide();
214
185
  return;
215
186
  }
216
- if (e === "Escape" && t.hide(), !!t.isOpen()) {
187
+ if (e === "Escape" && n.hide(), !!n.isOpen()) {
217
188
  if (e === "ArrowDown")
218
- t.goDown();
189
+ n.goDown();
219
190
  else if (e === "ArrowUp")
220
- t.goUp();
191
+ n.goUp();
221
192
  else if (e === "Enter") {
222
- const o = t.highlightedIndex();
223
- return o >= 0 && t.submitHighlightedItem(o), t.hide(), o >= 0;
193
+ const o = n.highlightedIndex();
194
+ return o >= 0 && n.submitHighlightedItem(o), n.hide(), o >= 0;
224
195
  }
225
196
  }
226
197
  }
227
- function _(e, { config: t, dropdown: n, history: o, onNavigateToSearch: r, store: i }) {
228
- n.hide(), o.hide(), !(e.length < t.minQueryLength) && (o.add(e), i.updateState({
198
+ function W(e, { config: n, dropdown: t, history: o, onNavigateToSearch: r, store: s }) {
199
+ t.hide(), o.hide(), !(e.length < n.minQueryLength) && (o.add(e), s.updateState({
229
200
  historyItems: o.get()
230
201
  }), r?.({
231
202
  query: e
232
203
  }));
233
204
  }
234
- async function ee(e, t) {
235
- const { inputCssSelector: n, timeout: o } = e, r = C(n).selector, i = await H({
205
+ async function X(e, n) {
206
+ const { inputCssSelector: t, timeout: o } = e, r = C(t).selector, s = await N({
236
207
  selector: r,
237
208
  timeout: o
238
209
  });
239
- if (i.length === 0)
210
+ if (s.length === 0)
240
211
  throw new Error(`No elements found for selector: ${r}`);
241
- i.forEach((s) => {
242
- te(s, e, t);
212
+ s.forEach((i) => {
213
+ Y(i, e, n);
243
214
  });
244
215
  }
245
- async function te(e, t, n) {
246
- const { config: o, dropdownCssSelector: r } = t, i = J(e, r), s = V(e, r, o.historySize), a = {
247
- ...t,
216
+ async function Y(e, n, t) {
217
+ const { config: o, dropdownCssSelector: r } = n, s = M(e, r), i = v(e, r, o.historySize), c = {
218
+ ...n,
248
219
  input: e,
249
- dropdown: i,
250
- history: s,
251
- store: n,
252
- debouncer: v(o.debounceDelay)
220
+ dropdown: s,
221
+ history: i,
222
+ store: t,
223
+ debouncer: U(o.debounceDelay)
253
224
  };
254
- oe(a), e.setAttribute("data-nosto-element", "search-input"), n.updateState({
255
- historyItems: s.get()
256
- }), F(e), n.onInit(() => {
257
- ne(a);
225
+ _(c), e.setAttribute("data-nosto-element", "search-input"), t.updateState({
226
+ historyItems: i.get()
227
+ }), k(e), t.onInit(() => {
228
+ Z(c);
258
229
  }), B(e, {
259
- onInput: (c) => Y(c, a),
260
- onFocus: (c) => X(c, a),
261
- onClick: (c) => W(c, a),
262
- onSubmit: (c) => _(c, a),
263
- onKeyDown: (c, h) => Z(c, h, a)
264
- }), E(s.element, s.hide), E(i.element, i.hide), b([s.element, e], s.hide), b([i.element, e], i.hide);
230
+ onInput: (l) => J(l, c),
231
+ onFocus: (l) => G(l, c),
232
+ onClick: (l) => z(l, c),
233
+ onSubmit: (l) => W(l, c),
234
+ onKeyDown: (l, u) => V(l, u, c)
235
+ }), E(i.element, i.hide), E(s.element, s.hide), S([i.element, e], i.hide), S([s.element, e], s.hide);
265
236
  }
266
- function ne(e) {
267
- const { dropdown: t, renderAutocomplete: n } = e;
268
- if (!n)
237
+ function Z(e) {
238
+ const { dropdown: n, renderAutocomplete: t } = e;
239
+ if (!t)
269
240
  return;
270
- const o = q(e, t);
271
- t.onHighlightChange(() => {
272
- o(n, t.element);
241
+ const o = x(e);
242
+ n.onHighlightChange(() => {
243
+ o(t, n.element);
273
244
  });
274
- const r = T("renderAutocomplete");
275
- o(n, t.element), r();
245
+ const r = I("renderAutocomplete");
246
+ o(t, n.element), r();
276
247
  }
277
- async function oe(e) {
278
- const { input: t, renderSpeechToText: n, config: o, store: r } = e;
279
- if (!n) return;
280
- const i = "ns-autocomplete-voice-position";
281
- if (!!t.parentElement?.querySelector(`.${i}`)) return;
282
- const a = document.createElement("div");
283
- a.className = i, t.insertAdjacentElement("afterend", a);
284
- const c = await n();
248
+ async function _(e) {
249
+ const { input: n, renderSpeechToText: t, config: o, store: r } = e;
250
+ if (!t) return;
251
+ const s = "ns-autocomplete-voice-position";
252
+ if (!!n.parentElement?.querySelector(`.${s}`)) return;
253
+ const c = document.createElement("div");
254
+ c.className = s, n.insertAdjacentElement("afterend", c);
255
+ const l = await t();
285
256
  y(
286
- /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(I, { config: o, store: r, children: c }) }),
287
- a
257
+ /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(L, { config: o, store: r, children: l }) }),
258
+ c
288
259
  );
289
260
  }
290
- function q(e, t) {
291
- const { config: n, store: o } = e, r = G(e, t);
292
- return t.onHighlightChange(() => {
293
- r.highlightedElementIndex = t.highlightedIndex();
294
- }), (i, s) => y(
295
- /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(I, { config: n, store: o, children: /* @__PURE__ */ d(z, { value: r, children: i() }) }) }),
296
- s
261
+ function x(e) {
262
+ const { config: n, store: t } = e;
263
+ return (o, r) => y(
264
+ /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(L, { config: n, store: t, children: o() }) }),
265
+ r
297
266
  );
298
267
  }
299
- async function k({ cssSelector: e, timeout: t, renderComponent: n }) {
300
- const o = C(e).selector, r = await H({
268
+ async function P({ cssSelector: e, timeout: n, renderComponent: t }) {
269
+ const o = C(e).selector, r = await N({
301
270
  selector: o,
302
- timeout: t ?? 100
271
+ timeout: n ?? 100
303
272
  });
304
273
  if (r.length === 0)
305
274
  throw new Error(`No elements found for selector: ${o}`);
306
- r.length > 1 && x.warn(`Multiple (${r.length}) elements found for selector: ${o}`), y(n(), r[0]);
275
+ r.length > 1 && q.warn(`Multiple (${r.length}) elements found for selector: ${o}`), y(t(), r[0]);
307
276
  }
308
- async function re(e, t) {
309
- const { render: n } = e, o = await n();
310
- k({
277
+ async function ee(e, n) {
278
+ const { render: t } = e, o = await t();
279
+ P({
311
280
  ...e,
312
- renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(R, { store: t, config: e.config, children: o }) })
281
+ renderComponent: () => /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(O, { store: n, config: e.config, children: o }) })
313
282
  });
314
283
  }
315
- async function ie(e, t) {
316
- const { render: n } = e, o = await n();
317
- k({
284
+ async function ne(e, n) {
285
+ const { render: t } = e, o = await t();
286
+ P({
318
287
  ...e,
319
- renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d($, { store: t, config: e.config, children: o }) })
288
+ renderComponent: () => /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d($, { store: n, config: e.config, children: o }) })
320
289
  });
321
290
  }
322
- async function Ce({ autocomplete: e, category: t, serp: n }) {
291
+ async function he({ autocomplete: e, category: n, serp: t }) {
323
292
  const o = {};
324
293
  if (e) {
325
294
  const r = p({ query: e.query });
326
- await ee(
295
+ await X(
327
296
  {
328
297
  ...e,
329
- config: D(e.config)
298
+ config: j(e.config)
330
299
  },
331
300
  r
332
301
  ), o.autocomplete = { store: r };
333
302
  }
334
- if (t) {
335
- const r = p({ query: t.query });
336
- await re(
303
+ if (n) {
304
+ const r = p({ query: n.query });
305
+ await ee(
337
306
  {
338
- ...t,
339
- config: O(t.config)
307
+ ...n,
308
+ config: R(n.config)
340
309
  },
341
310
  r
342
311
  ), o.category = { store: r };
343
312
  }
344
- if (n) {
345
- const r = p({ query: n.query });
346
- await ie(
313
+ if (t) {
314
+ const r = p({ query: t.query });
315
+ await ne(
347
316
  {
348
- ...n,
349
- config: j(n.config)
317
+ ...t,
318
+ config: F(t.config)
350
319
  },
351
320
  r
352
321
  ), o.serp = { store: r };
@@ -354,6 +323,5 @@ async function Ce({ autocomplete: e, category: t, serp: n }) {
354
323
  return o;
355
324
  }
356
325
  export {
357
- z as AutocompleteContext,
358
- Ce as init
326
+ he as init
359
327
  };
@@ -12,4 +12,4 @@ export type AutocompleteInjectContext = AutocompleteInjectConfig & {
12
12
  store: Store;
13
13
  debouncer: ReturnType<typeof debounce>;
14
14
  };
15
- export declare function createUserComponentRenderer(injectContext: AutocompleteInjectContext, element: AutocompleteDropdown | AutocompleteHistory): (renderer: () => VNode | Promise<VNode>, target: HTMLDivElement) => void;
15
+ export declare function createUserComponentRenderer(injectContext: AutocompleteInjectContext): (renderer: () => VNode | Promise<VNode>, target: HTMLDivElement) => void;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../useActions-CJ71kc2N.cjs"),r=require("../../InfiniteScrollWithObserver-CoPOQr8Q.cjs"),t=require("../../useLoadMore-B0JgcUfM.cjs");exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;exports.getNextPageQuery=t.getNextPageQuery;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../useActions-Drtoxcu4.cjs"),r=require("../../InfiniteScrollWithObserver-BN-pDinB.cjs"),t=require("../../useLoadMore-DPYhbXHC.cjs");exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;exports.getNextPageQuery=t.getNextPageQuery;
@@ -1,6 +1,6 @@
1
- import { n as t, u as a } from "../../useActions-SEyBHGra.js";
2
- import { I as s, i } from "../../InfiniteScrollWithObserver-6A57AOKr.js";
3
- import { g as p } from "../../useLoadMore-hrNp8P0M.js";
1
+ import { n as t, u as a } from "../../useActions-MsVW37eV.js";
2
+ import { I as s, i } from "../../InfiniteScrollWithObserver-CEtMyahq.js";
3
+ import { g as p } from "../../useLoadMore-BR-vDmqW.js";
4
4
  export {
5
5
  s as InfiniteScrollWithObserver,
6
6
  p as getNextPageQuery,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../jsxRuntime.module-B3sGoTIU.cjs"),l=require("../../index.es-Dp6Iaxz3.cjs"),u=require("../../BaseElement-CIHACCWd.cjs"),S=require("../../useActions-CJ71kc2N.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-pR-E8S6m.cjs"),P="nosto:search-js:scrollPos";function m(){window.sessionStorage.setItem(P,window.scrollY.toString())}function p({children:s,hit:e,componentProps:t,as:n}){const{pageType:o}=S.useConfig(),r=o==="autocomplete"?void 0:o==="search"?"serp":o,c=d.useCallback(()=>{e&&r&&l.s(i=>i.recordSearchClick(r,e)),m()},[e,r]);return a.u(u.BaseElement,{as:n,onClick:c,componentProps:t,children:s})}exports.SearchPageProvider=g.SearchPageProvider;exports.SerpElement=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../../jsxRuntime.module-B3sGoTIU.cjs"),l=require("../../index.es-Dp6Iaxz3.cjs"),u=require("../../BaseElement-CIHACCWd.cjs"),S=require("../../useActions-Drtoxcu4.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-s4dO49Fx.cjs"),P="nosto:search-js:scrollPos";function m(){window.sessionStorage.setItem(P,window.scrollY.toString())}function p({children:s,hit:e,componentProps:t,as:n}){const{pageType:o}=S.useConfig(),r=o==="autocomplete"?void 0:o==="search"?"serp":o,c=d.useCallback(()=>{e&&r&&l.s(i=>i.recordSearchClick(r,e)),m()},[e,r]);return a.u(u.BaseElement,{as:n,onClick:c,componentProps:t,children:s})}exports.SearchPageProvider=g.SearchPageProvider;exports.SerpElement=p;
@@ -1,9 +1,9 @@
1
1
  import { u as i } from "../../jsxRuntime.module-Bzuv3cXw.js";
2
2
  import { s as l } from "../../index.es-XNBESE3P.js";
3
3
  import { B as m } from "../../BaseElement-DD_4UwDm.js";
4
- import { a as p } from "../../useActions-SEyBHGra.js";
4
+ import { b as p } from "../../useActions-MsVW37eV.js";
5
5
  import { useCallback as f } from "preact/hooks";
6
- import { S as x } from "../../SerpPageProvider-B-W6nCqu.js";
6
+ import { S as h } from "../../SerpPageProvider-CsrFA6mA.js";
7
7
  const S = "nosto:search-js:scrollPos";
8
8
  function g() {
9
9
  window.sessionStorage.setItem(S, window.scrollY.toString());
@@ -15,6 +15,6 @@ function C({ children: s, hit: o, componentProps: t, as: c }) {
15
15
  return /* @__PURE__ */ i(m, { as: c, onClick: a, componentProps: t, children: s });
16
16
  }
17
17
  export {
18
- x as SearchPageProvider,
18
+ h as SearchPageProvider,
19
19
  C as SerpElement
20
20
  };
@@ -1 +1 @@
1
- "use strict";const w=require("./index.es-Dp6Iaxz3.cjs"),i=require("./logger-Boh_C6Bz.cjs");async function y(t,{hitDecorators:e,...r},o){const n=await o(t,r);if(!n.products?.hits?.length||!e?.length)return n;const c=s=>e.reduce((a,u)=>u(a),s);return{...n,products:{...n.products,hits:n.products.hits.map(c)}}}function h(t,e,r){const o=JSON.stringify(e);try{r.setItem(t,o)}catch(n){i.logger.warn(n)}}function g(t,e){try{const r=e.getItem(t);if(r)return JSON.parse(r)}catch(r){i.logger.warn(r)}}function C(t,e){h(t,e,localStorage)}function I(t,e){h(t,e,sessionStorage)}function R(t){return g(t,localStorage)}function b(t){return g(t,sessionStorage)}const p="nosto:search-js:cache",N=60*1e3;function T(t,e){I(p,{query:t,result:e,created:Date.now()})}function z(t){const e=b(p);if(!e||!E(e))return null;const r=d(e.query);return!i.isEqual(d(t),r)||Date.now()-e.created>N?null:e.result}function d(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function E(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t&&"created"in t}async function L(t,{usePersistentCache:e,...r},o){if(!e)return o(t,r);const n=await O(t,r,o);return T(t,n),n}async function O(t,e,r){const{from:o=0,size:n=0}=t.products||{},c=z(t);if(!c)return await r(t,e);const s=c?.products?.size??0,a=c?.products?.hits??[];if(n===s)return c;if(n<s)return{...c,products:{...c.products,size:n,hits:a.slice(0,n),total:c.products?.total||0}};const u=n-a.length,S=o>0?o+1:n-u,m={...t,products:{...t.products,from:S,size:u}},f=await r(m,e);return{...c,products:{...c.products,size:n,hits:[...c.products?.hits||[],...f.products?.hits||[]],total:f.products?.total||0}}}const J=3e4,l=new Map;function k(t,e){const r=l.get(t);if(!r)return;const o=Date.now()-r.created>J,n=i.isEqual(e,r.query);if(o||!n){l.delete(t);return}return r.result}function D(t,e,r){l.set(t,{query:e,result:r,created:Date.now()})}async function M(t,e,r){if(!e.useMemoryCache)return r(t,e);const o=JSON.stringify(t),n=k(o,t);if(n)return n;const c=await r(t,e);return D(o,t,c),c}function V(t){return new Promise(e=>setTimeout(e,t))}async function W(t,{maxRetries:e=0,retryInterval:r=0,...o},n){let c=0;for(;;)try{return await n(t,o)}catch(s){if(c>=e)throw s;if(!j(s))throw i.logger.info("Skipping retry logic for",s),s;c++,await V(r)}}function j(t){return!t||typeof t!="object"?!1:!("status"in t)||_(t.status)}function _(t){return typeof t=="number"&&(t<400||t>=500)}async function x(t,e={}){const r=await new Promise(w.s);return A(r.search,W,M,L,y)(t,e)}function A(t,...e){return e.reduce((r,o)=>(n,c)=>o(n,c,r),t)}exports.getLocalStorageItem=R;exports.search=x;exports.setLocalStorageItem=C;
1
+ "use strict";const w=require("./index.es-Dp6Iaxz3.cjs"),i=require("./logger-Boh_C6Bz.cjs");async function y(t,{hitDecorators:e,...r},o){const n=await o(t,r);if(!n.products?.hits?.length||!e?.length)return n;const c=s=>e.reduce((a,u)=>u(a),s);return{...n,products:{...n.products,hits:n.products.hits.map(c)}}}function h(t,e,r){const o=JSON.stringify(e);try{r.setItem(t,o)}catch(n){i.logger.warn(n)}}function g(t,e){try{const r=e.getItem(t);if(r)return JSON.parse(r)}catch(r){i.logger.warn(r)}}function I(t,e){h(t,e,localStorage)}function C(t,e){h(t,e,sessionStorage)}function R(t){return g(t,localStorage)}function b(t){return g(t,sessionStorage)}const p="nosto:search-js:cache",N=60*1e3;function T(t,e){C(p,{query:t,result:e,created:Date.now()})}function z(t){const e=b(p);if(!e||!E(e))return null;const r=d(e.query);return!i.isEqual(d(t),r)||Date.now()-e.created>N?null:e.result}function d(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function E(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t&&"created"in t}async function L(t,{usePersistentCache:e,...r},o){if(!e)return o(t,r);const n=await O(t,r,o);return T(t,n),n}async function O(t,e,r){const{from:o=0,size:n=0}=t.products||{},c=z(t);if(!c)return await r(t,e);const s=c?.products?.size??0,a=c?.products?.hits??[];if(n===s)return c;if(n<s)return{...c,products:{...c.products,size:n,hits:a.slice(0,n),total:c.products?.total||0}};const u=n-a.length,S=o>0?o+1:n-u,m={...t,products:{...t.products,from:S,size:u}},f=await r(m,e);return{...c,products:{...c.products,size:n,hits:[...c.products?.hits||[],...f.products?.hits||[]],total:f.products?.total||0}}}const J=3e4,l=new Map;function k(t,e){const r=l.get(t);if(!r)return;const o=Date.now()-r.created>J,n=i.isEqual(e,r.query);if(o||!n){l.delete(t);return}return r.result}function D(t,e,r){l.set(t,{query:e,result:r,created:Date.now()})}async function M(t,e,r){if(!e.useMemoryCache)return r(t,e);const o=JSON.stringify(t),n=k(o,t);if(n)return n;const c=await r(t,e);return D(o,t,c),c}function V(t){return new Promise(e=>setTimeout(e,t))}async function W(t,{maxRetries:e=0,retryInterval:r=0,...o},n){let c=0;for(;;)try{return await n(t,o)}catch(s){if(c>=e)throw s;if(!j(s))throw i.logger.info("Skipping retry logic for",s),s;c++,await V(r)}}function j(t){return!t||typeof t!="object"?!1:!("status"in t)||_(t.status)}function _(t){return typeof t=="number"&&(t<400||t>=500)}async function x(t,e={}){const r=await new Promise(w.s);return A(r.search,W,M,L,y)(t,e)}function A(t,...e){return e.reduce((r,o)=>(n,c)=>o(n,c,r),t)}exports.getLocalStorageItem=R;exports.search=x;exports.setLocalStorageItem=I;