@nosto/search-js 3.13.1 → 3.14.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.
@@ -0,0 +1 @@
1
+ "use strict";const e=require("./jsxRuntime.module-B3sGoTIU.cjs"),u=require("./logger-Boh_C6Bz.cjs"),n=require("preact"),t=require("preact/hooks");function s({children:o}){const[r]=t.useErrorBoundary();return r&&u.logger.error("Error caught in ErrorBoundary",r),e.u(n.Fragment,{children:o})}exports.ErrorBoundary=s;
@@ -0,0 +1,11 @@
1
+ import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
2
+ import { l as m } from "./logger-_fg_Za9y.js";
3
+ import { Fragment as n } from "preact";
4
+ import { useErrorBoundary as u } from "preact/hooks";
5
+ function p({ children: o }) {
6
+ const [r] = u();
7
+ return r && m.error("Error caught in ErrorBoundary", r), /* @__PURE__ */ t(n, { children: o });
8
+ }
9
+ export {
10
+ p as E
11
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../../isBot-iyBlT_oq.cjs"),o=require("../../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../../useLoadMore-B0JgcUfM.cjs"),g=require("../../pick-rYi1lc2m.cjs"),n=require("../../InfiniteScrollWithObserver-CoPOQr8Q.cjs"),p=require("preact"),e=require("../../useActions-CJ71kc2N.cjs");function C({pageSize:r}){const{loadMore:t}=s.useLoadMore(r);return o.u("button",{onClick:t,children:"More results"})}function u({children:r,loadMoreComponent:t,pageSize:i}){const{loading:c,query:l,response:a}=s.useNostoAppState(S=>g.pick(S,"loading","query","response")),f=!c&&n.hasMoreResults(l,a);return o.u(p.Fragment,{children:[r,f&&(t?o.u(t,{pageSize:i}):o.u(C,{pageSize:i}))]})}const q=!d.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=e.StoreContext;exports.createExtendableStore=e.createExtendableStore;exports.createStore=e.createStore;exports.defaultState=e.defaultState;exports.useAutocompleteConfig=e.useAutocompleteConfig;exports.useCategoryConfig=e.useCategoryConfig;exports.useConfig=e.useConfig;exports.useSerpConfig=e.useSerpConfig;exports.InfiniteScroll=q;exports.InfiniteScrollWithLink=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../../ErrorBoundary-CKn3Ecpu.cjs"),g=require("../../isBot-iyBlT_oq.cjs"),o=require("../../jsxRuntime.module-B3sGoTIU.cjs"),u=require("../../useLoadMore-B0JgcUfM.cjs"),p=require("../../pick-rYi1lc2m.cjs"),n=require("../../InfiniteScrollWithObserver-CoPOQr8Q.cjs"),C=require("preact"),e=require("../../useActions-CJ71kc2N.cjs");function q({pageSize:t}){const{loadMore:r}=u.useLoadMore(t);return o.u("button",{onClick:r,children:"More results"})}function s({children:t,loadMoreComponent:r,pageSize:i}){const{loading:c,query:l,response:a}=u.useNostoAppState(f=>p.pick(f,"loading","query","response")),d=!c&&n.hasMoreResults(l,a);return o.u(C.Fragment,{children:[t,d&&(r?o.u(r,{pageSize:i}):o.u(q,{pageSize:i}))]})}const y=!g.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:s;exports.ErrorBoundary=S.ErrorBoundary;exports.StoreContext=e.StoreContext;exports.createExtendableStore=e.createExtendableStore;exports.createStore=e.createStore;exports.defaultState=e.defaultState;exports.useAutocompleteConfig=e.useAutocompleteConfig;exports.useCategoryConfig=e.useCategoryConfig;exports.useConfig=e.useConfig;exports.useSerpConfig=e.useSerpConfig;exports.InfiniteScroll=y;exports.InfiniteScrollWithLink=s;
@@ -1,4 +1,5 @@
1
1
  /** @module preact/common */
2
+ export { ErrorBoundary } from './src/components/ErrorBoundary';
2
3
  export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
3
4
  export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
4
5
  export { useAutocompleteConfig, useCategoryConfig, useConfig, useSerpConfig } from './src/config/configContext';
@@ -1,31 +1,33 @@
1
- import { i as c } from "../../isBot-Lnmft0Z0.js";
1
+ import { E as v } from "../../ErrorBoundary-DTRm_60r.js";
2
+ import { i as f } from "../../isBot-Lnmft0Z0.js";
2
3
  import { u as e } from "../../jsxRuntime.module-Bzuv3cXw.js";
3
- import { u as f, a as l } from "../../useLoadMore-hrNp8P0M.js";
4
- import { p } from "../../pick-DReBictn.js";
4
+ import { u as p, a as c } from "../../useLoadMore-hrNp8P0M.js";
5
+ import { p as l } from "../../pick-DReBictn.js";
5
6
  import { h as m, i as d, I as S } from "../../InfiniteScrollWithObserver-6A57AOKr.js";
6
7
  import { Fragment as g } from "preact";
7
- import { S as A, g as O, c as W, f as B, b as E, d as F, a as N, e as R } from "../../useActions-SEyBHGra.js";
8
+ import { S as B, g as O, c as W, f as F, b as N, d as R, a as j, e as w } from "../../useActions-SEyBHGra.js";
8
9
  function C({ pageSize: r }) {
9
- const { loadMore: o } = f(r);
10
+ const { loadMore: o } = p(r);
10
11
  return /* @__PURE__ */ e("button", { onClick: o, children: "More results" });
11
12
  }
12
13
  function h({ children: r, loadMoreComponent: o, pageSize: t }) {
13
- const { loading: s, query: n, response: i } = l((u) => p(u, "loading", "query", "response")), a = !s && m(n, i);
14
+ const { loading: s, query: n, response: a } = c((u) => l(u, "loading", "query", "response")), i = !s && m(n, a);
14
15
  return /* @__PURE__ */ e(g, { children: [
15
16
  r,
16
- a && (o ? /* @__PURE__ */ e(o, { pageSize: t }) : /* @__PURE__ */ e(C, { pageSize: t }))
17
+ i && (o ? /* @__PURE__ */ e(o, { pageSize: t }) : /* @__PURE__ */ e(C, { pageSize: t }))
17
18
  ] });
18
19
  }
19
- const y = !c() && d() ? S : h;
20
+ const L = !f() && d() ? S : h;
20
21
  export {
21
- y as InfiniteScroll,
22
+ v as ErrorBoundary,
23
+ L as InfiniteScroll,
22
24
  h as InfiniteScrollWithLink,
23
- A as StoreContext,
25
+ B as StoreContext,
24
26
  O as createExtendableStore,
25
27
  W as createStore,
26
- B as defaultState,
27
- E as useAutocompleteConfig,
28
- F as useCategoryConfig,
29
- N as useConfig,
30
- R as useSerpConfig
28
+ F as defaultState,
29
+ N as useAutocompleteConfig,
30
+ R as useCategoryConfig,
31
+ j as useConfig,
32
+ w as useSerpConfig
31
33
  };
@@ -3,6 +3,6 @@ import { ComponentChildren } from 'preact';
3
3
  * Error boundary component to log UI level errors
4
4
  * @group Components
5
5
  */
6
- export default function ErrorBoundary({ children }: {
6
+ export declare function ErrorBoundary({ children }: {
7
7
  children: ComponentChildren;
8
8
  }): import("preact").JSX.Element;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-99syi-nl.cjs"),T=require("../../CategoryPageProvider-Clj40F3F.cjs"),m=require("../../useActions-CJ71kc2N.cjs"),x=require("../../SerpPageProvider-pR-E8S6m.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),E=require("../../bindInput-BnKvCky1.cjs"),P=require("../../unique-BXXNictB.cjs"),g=require("preact"),S=require("../../logger-Boh_C6Bz.cjs"),D=require("preact/hooks"),O=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../search-DTqo1D6Y.cjs");function B(e){let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function f({children:e}){const[t]=D.useErrorBoundary();return t&&S.logger.error("Error caught in ErrorBoundary",t),u.u(g.Fragment,{children:e})}function A(e){return Array.from(document.querySelectorAll(e))}function F(e){const t=[];let n=e.parentNode;for(;n&&n!==document&&n instanceof Element;)t.push(n),n=n.parentNode;return t}function q([e,t],n){const o=r=>{const i=r.target;i instanceof HTMLElement&&e&&i!==e&&i!==t&&!F(i).includes(e)&&n()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function I(e,t){e.tabIndex=0,e.addEventListener("blur",t)}function b(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function H({selector:e,timeout:t=500}){return new Promise(n=>{const o=A(e);if(o.length>0)return n(o);const r=new MutationObserver(()=>{const s=A(e);s.length>0&&(r.disconnect(),clearTimeout(i),n(s))}),i=setTimeout(()=>{r.disconnect(),S.logger.warn(`Timed out (${t}) while waiting for element ${e}`),n([])},t);r.observe(document.body,{childList:!0,subtree:!0})})}const N=g.createContext({reportProductClick:()=>{},reportKeywordClick:()=>{},handleSubmit:()=>{},highlightedElementIndex:-1});function $(e,t){const{dropdown:n,history:o,store:r,input:i,onNavigateToSearch:s}=e,l=(c,h)=>{n.hide(),o.hide(),c&&(o.add(c),r.updateState({historyItems:o.get()}),h&&O.s(a=>a.recordSearchSubmit(c)),i.value=c)};return{reportProductClick:c=>{l(c.name,!1)},reportKeywordClick:c=>{l(c.keyword,!0)},handleSubmit:c=>{l(c.query,!1),s?.(c)},highlightedElementIndex:t.highlightedIndex()}}function k(e,t,n){t.style.display="none";const o=(()=>{if(e.parentElement&&e.parentElement.classList.contains("nosto-autocomplete-wrapper"))return e.parentElement;const a=document.createElement("div");return a.className="nosto-autocomplete-wrapper",e.parentNode?.insertBefore(a,e.nextSibling),a.appendChild(e),a})(),r=b(n),i=r&&document.querySelector(r.selector);if(i){const a=document.createElement("form");a.className="nosto-dropdown-form",a.appendChild(t),r.position==="first"?i.prepend(a):i.appendChild(a)}else o.appendChild(t);const s={index:-1,onChangeListeners:[]},l=(a,d)=>{const p=a.length;p===0&&(d=-1),s.index=d>=0?d%p:p-1,s.onChangeListeners.forEach(v=>v())},c=()=>{s.index=-1,s.onChangeListeners.forEach(a=>a())},h=()=>s.index;return{element:t,hide:()=>{t.style.display="none",c()},show:()=>{t.style.display="inherit"},isOpen:()=>t.style.display!=="none",goDown:()=>{const a=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();l(a,d+1)},goUp:()=>{const a=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();l(a,d-1)},highlight:l,highlightedIndex:h,submitHighlightedItem:a=>{Array.from(t.querySelectorAll(".ns-autocomplete-element"))[a]?.click()},onHighlightChange:a=>{s.onChangeListeners.push(a)}}}function K(e,t){const n=document.createElement("div");return n.className="nosto-autocomplete-dropdown",{...k(e,n,t),element:n}}const C="nosto:search-js:history";function Q(e,t,n){const o=document.createElement("div");return o.className="nosto-autocomplete-history",{...k(e,o,t),element:o,add:i=>{const l=(y.getLocalStorageItem(C)??[]).filter(c=>c!==i).slice(n?-n:0);l.push(i),y.setLocalStorageItem(C,l)},get:()=>(y.getLocalStorageItem(C)??[]).reverse().filter(s=>!!s)}}async function M(e,{config:t,dropdown:n,history:o,renderHistory:r,store:i}){const{historyEnabled:s,minQueryLength:l}=t;if(e.length<l&&s&&r&&!o.isOpen()){o.show();return}if(e.length<l)return;n.hide();const c=i.getState()?.query?.query;c&&c!==e&&await m.newSearch({config:t,store:i},{query:e}),n.show()}async function U(e,t){const{config:n,renderHistory:o,history:r}=t,{historyEnabled:i,minQueryLength:s}=n;if(!o||e.length>=s||!i||r.isOpen())return;const l=R(t,r);r.onHighlightChange(()=>{l(o,r.element)}),r.show();const c=P.measure("renderHistory");l(o,r.element),c()}async function _(e,{config:t,dropdown:n,history:o,store:r,debouncer:i}){const{minQueryLength:s,historyEnabled:l}=t;if(e.length<s&&!l){n.hide(),o.hide();return}if(e.length<s&&l){n.hide(),o.show();return}o.hide(),i(async()=>{m.newSearch({config:t,store:r},{query:e}),n.show()})}function z(e,t,n){const{config:o,debouncer:r}=n;if(r(()=>{}),e.length>=o.minQueryLength)return L(t,n.dropdown,n.history);if(o.historyEnabled)return L(t,n.history,n.dropdown)}function L(e,t,n){if(!t.isOpen()&&e==="ArrowDown"){t.show(),n.hide();return}if(e==="Escape"&&t.hide(),!!t.isOpen()){if(e==="ArrowDown")t.goDown();else if(e==="ArrowUp")t.goUp();else if(e==="Enter"){const o=t.highlightedIndex();return o>=0&&t.submitHighlightedItem(o),t.hide(),o>=0}}}function G(e,{config:t,dropdown:n,history:o,onNavigateToSearch:r,store:i}){n.hide(),o.hide(),!(e.length<t.minQueryLength)&&(o.add(e),i.updateState({historyItems:o.get()}),r?.({query:e}))}async function J(e,t){const{inputCssSelector:n,timeout:o}=e,r=b(n).selector,i=await H({selector:r,timeout:o});if(i.length===0)throw new Error(`No elements found for selector: ${r}`);i.forEach(s=>{V(s,e,t)})}async function V(e,t,n){const{config:o,dropdownCssSelector:r}=t,i=K(e,r),s=Q(e,r,o.historySize),l={...t,input:e,dropdown:i,history:s,store:n,debouncer:B(o.debounceDelay)};X(l),e.setAttribute("data-nosto-element","search-input"),n.updateState({historyItems:s.get()}),E.disableNativeAutocomplete(e),n.onInit(()=>{W(l)}),E.bindInput(e,{onInput:c=>_(c,l),onFocus:c=>U(c,l),onClick:c=>M(c,l),onSubmit:c=>G(c,l),onKeyDown:(c,h)=>z(c,h,l)}),I(s.element,s.hide),I(i.element,i.hide),q([s.element,e],s.hide),q([i.element,e],i.hide)}function W(e){const{dropdown:t,renderAutocomplete:n}=e;if(!n)return;const o=R(e,t);t.onHighlightChange(()=>{o(n,t.element)});const r=P.measure("renderAutocomplete");o(n,t.element),r()}async function X(e){const{input:t,renderSpeechToText:n,config:o,store:r}=e;if(!n)return;const i="ns-autocomplete-voice-position";if(!!t.parentElement?.querySelector(`.${i}`))return;const l=document.createElement("div");l.className=i,t.insertAdjacentElement("afterend",l);const c=await n();g.render(u.u(f,{children:u.u(w.AutocompletePageProvider,{config:o,store:r,children:c})}),l)}function R(e,t){const{config:n,store:o}=e,r=$(e,t);return t.onHighlightChange(()=>{r.highlightedElementIndex=t.highlightedIndex()}),(i,s)=>g.render(u.u(f,{children:u.u(w.AutocompletePageProvider,{config:n,store:o,children:u.u(N,{value:r,children:i()})})}),s)}async function j({cssSelector:e,timeout:t,renderComponent:n}){const o=b(e).selector,r=await H({selector:o,timeout:t??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&S.logger.warn(`Multiple (${r.length}) elements found for selector: ${o}`),g.render(n(),r[0])}async function Y(e,t){const{render:n}=e,o=await n();j({...e,renderComponent:()=>u.u(f,{children:u.u(T.CategoryPageProvider,{store:t,config:e.config,children:o})})})}async function Z(e,t){const{render:n}=e,o=await n();j({...e,renderComponent:()=>u.u(f,{children:u.u(x.SearchPageProvider,{store:t,config:e.config,children:o})})})}async function ee({autocomplete:e,category:t,serp:n}){const o={};if(e){const r=m.createStore({query:e.query});await J({...e,config:w.makeAutocompleteConfig(e.config)},r),o.autocomplete={store:r}}if(t){const r=m.createStore({query:t.query});await Y({...t,config:T.makeCategoryConfig(t.config)},r),o.category={store:r}}if(n){const r=m.createStore({query:n.query});await Z({...n,config:x.makeSerpConfig(n.config)},r),o.serp={store:r}}return o}exports.AutocompleteContext=N;exports.init=ee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../AutocompletePageProvider-99syi-nl.cjs"),L=require("../../CategoryPageProvider-Clj40F3F.cjs"),m=require("../../useActions-CJ71kc2N.cjs"),T=require("../../SerpPageProvider-pR-E8S6m.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),g=require("../../ErrorBoundary-CKn3Ecpu.cjs"),b=require("../../bindInput-BnKvCky1.cjs"),x=require("../../unique-BXXNictB.cjs"),f=require("preact"),P=require("../../logger-Boh_C6Bz.cjs"),v=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../search-DTqo1D6Y.cjs");function D(e){let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function E(e){return Array.from(document.querySelectorAll(e))}function O(e){const t=[];let n=e.parentNode;for(;n&&n!==document&&n instanceof Element;)t.push(n),n=n.parentNode;return t}function A([e,t],n){const o=r=>{const i=r.target;i instanceof HTMLElement&&e&&i!==e&&i!==t&&!O(i).includes(e)&&n()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function q(e,t){e.tabIndex=0,e.addEventListener("blur",t)}function S(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function H({selector:e,timeout:t=500}){return new Promise(n=>{const o=E(e);if(o.length>0)return n(o);const r=new MutationObserver(()=>{const s=E(e);s.length>0&&(r.disconnect(),clearTimeout(i),n(s))}),i=setTimeout(()=>{r.disconnect(),P.logger.warn(`Timed out (${t}) while waiting for element ${e}`),n([])},t);r.observe(document.body,{childList:!0,subtree:!0})})}const N=f.createContext({reportProductClick:()=>{},reportKeywordClick:()=>{},handleSubmit:()=>{},highlightedElementIndex:-1});function $(e,t){const{dropdown:n,history:o,store:r,input:i,onNavigateToSearch:s}=e,l=(c,h)=>{n.hide(),o.hide(),c&&(o.add(c),r.updateState({historyItems:o.get()}),h&&v.s(a=>a.recordSearchSubmit(c)),i.value=c)};return{reportProductClick:c=>{l(c.name,!1)},reportKeywordClick:c=>{l(c.keyword,!0)},handleSubmit:c=>{l(c.query,!1),s?.(c)},highlightedElementIndex:t.highlightedIndex()}}function k(e,t,n){t.style.display="none";const o=(()=>{if(e.parentElement&&e.parentElement.classList.contains("nosto-autocomplete-wrapper"))return e.parentElement;const a=document.createElement("div");return a.className="nosto-autocomplete-wrapper",e.parentNode?.insertBefore(a,e.nextSibling),a.appendChild(e),a})(),r=S(n),i=r&&document.querySelector(r.selector);if(i){const a=document.createElement("form");a.className="nosto-dropdown-form",a.appendChild(t),r.position==="first"?i.prepend(a):i.appendChild(a)}else o.appendChild(t);const s={index:-1,onChangeListeners:[]},l=(a,d)=>{const p=a.length;p===0&&(d=-1),s.index=d>=0?d%p:p-1,s.onChangeListeners.forEach(j=>j())},c=()=>{s.index=-1,s.onChangeListeners.forEach(a=>a())},h=()=>s.index;return{element:t,hide:()=>{t.style.display="none",c()},show:()=>{t.style.display="inherit"},isOpen:()=>t.style.display!=="none",goDown:()=>{const a=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();l(a,d+1)},goUp:()=>{const a=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();l(a,d-1)},highlight:l,highlightedIndex:h,submitHighlightedItem:a=>{Array.from(t.querySelectorAll(".ns-autocomplete-element"))[a]?.click()},onHighlightChange:a=>{s.onChangeListeners.push(a)}}}function F(e,t){const n=document.createElement("div");return n.className="nosto-autocomplete-dropdown",{...k(e,n,t),element:n}}const C="nosto:search-js:history";function K(e,t,n){const o=document.createElement("div");return o.className="nosto-autocomplete-history",{...k(e,o,t),element:o,add:i=>{const l=(y.getLocalStorageItem(C)??[]).filter(c=>c!==i).slice(n?-n:0);l.push(i),y.setLocalStorageItem(C,l)},get:()=>(y.getLocalStorageItem(C)??[]).reverse().filter(s=>!!s)}}async function Q(e,{config:t,dropdown:n,history:o,renderHistory:r,store:i}){const{historyEnabled:s,minQueryLength:l}=t;if(e.length<l&&s&&r&&!o.isOpen()){o.show();return}if(e.length<l)return;n.hide();const c=i.getState()?.query?.query;c&&c!==e&&await m.newSearch({config:t,store:i},{query:e}),n.show()}async function M(e,t){const{config:n,renderHistory:o,history:r}=t,{historyEnabled:i,minQueryLength:s}=n;if(!o||e.length>=s||!i||r.isOpen())return;const l=B(t,r);r.onHighlightChange(()=>{l(o,r.element)}),r.show();const c=x.measure("renderHistory");l(o,r.element),c()}async function U(e,{config:t,dropdown:n,history:o,store:r,debouncer:i}){const{minQueryLength:s,historyEnabled:l}=t;if(e.length<s&&!l){n.hide(),o.hide();return}if(e.length<s&&l){n.hide(),o.show();return}o.hide(),i(async()=>{m.newSearch({config:t,store:r},{query:e}),n.show()})}function _(e,t,n){const{config:o,debouncer:r}=n;if(r(()=>{}),e.length>=o.minQueryLength)return I(t,n.dropdown,n.history);if(o.historyEnabled)return I(t,n.history,n.dropdown)}function I(e,t,n){if(!t.isOpen()&&e==="ArrowDown"){t.show(),n.hide();return}if(e==="Escape"&&t.hide(),!!t.isOpen()){if(e==="ArrowDown")t.goDown();else if(e==="ArrowUp")t.goUp();else if(e==="Enter"){const o=t.highlightedIndex();return o>=0&&t.submitHighlightedItem(o),t.hide(),o>=0}}}function z(e,{config:t,dropdown:n,history:o,onNavigateToSearch:r,store:i}){n.hide(),o.hide(),!(e.length<t.minQueryLength)&&(o.add(e),i.updateState({historyItems:o.get()}),r?.({query:e}))}async function G(e,t){const{inputCssSelector:n,timeout:o}=e,r=S(n).selector,i=await H({selector:r,timeout:o});if(i.length===0)throw new Error(`No elements found for selector: ${r}`);i.forEach(s=>{J(s,e,t)})}async function J(e,t,n){const{config:o,dropdownCssSelector:r}=t,i=F(e,r),s=K(e,r,o.historySize),l={...t,input:e,dropdown:i,history:s,store:n,debouncer:D(o.debounceDelay)};W(l),e.setAttribute("data-nosto-element","search-input"),n.updateState({historyItems:s.get()}),b.disableNativeAutocomplete(e),n.onInit(()=>{V(l)}),b.bindInput(e,{onInput:c=>U(c,l),onFocus:c=>M(c,l),onClick:c=>Q(c,l),onSubmit:c=>z(c,l),onKeyDown:(c,h)=>_(c,h,l)}),q(s.element,s.hide),q(i.element,i.hide),A([s.element,e],s.hide),A([i.element,e],i.hide)}function V(e){const{dropdown:t,renderAutocomplete:n}=e;if(!n)return;const o=B(e,t);t.onHighlightChange(()=>{o(n,t.element)});const r=x.measure("renderAutocomplete");o(n,t.element),r()}async function W(e){const{input:t,renderSpeechToText:n,config:o,store:r}=e;if(!n)return;const i="ns-autocomplete-voice-position";if(!!t.parentElement?.querySelector(`.${i}`))return;const l=document.createElement("div");l.className=i,t.insertAdjacentElement("afterend",l);const c=await n();f.render(u.u(g.ErrorBoundary,{children:u.u(w.AutocompletePageProvider,{config:o,store:r,children:c})}),l)}function B(e,t){const{config:n,store:o}=e,r=$(e,t);return t.onHighlightChange(()=>{r.highlightedElementIndex=t.highlightedIndex()}),(i,s)=>f.render(u.u(g.ErrorBoundary,{children:u.u(w.AutocompletePageProvider,{config:n,store:o,children:u.u(N,{value:r,children:i()})})}),s)}async function R({cssSelector:e,timeout:t,renderComponent:n}){const o=S(e).selector,r=await H({selector:o,timeout:t??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&P.logger.warn(`Multiple (${r.length}) elements found for selector: ${o}`),f.render(n(),r[0])}async function X(e,t){const{render:n}=e,o=await n();R({...e,renderComponent:()=>u.u(g.ErrorBoundary,{children:u.u(L.CategoryPageProvider,{store:t,config:e.config,children:o})})})}async function Y(e,t){const{render:n}=e,o=await n();R({...e,renderComponent:()=>u.u(g.ErrorBoundary,{children:u.u(T.SearchPageProvider,{store:t,config:e.config,children:o})})})}async function Z({autocomplete:e,category:t,serp:n}){const o={};if(e){const r=m.createStore({query:e.query});await G({...e,config:w.makeAutocompleteConfig(e.config)},r),o.autocomplete={store:r}}if(t){const r=m.createStore({query:t.query});await X({...t,config:L.makeCategoryConfig(t.config)},r),o.category={store:r}}if(n){const r=m.createStore({query:n.query});await Y({...n,config:T.makeSerpConfig(n.config)},r),o.serp={store:r}}return o}exports.AutocompleteContext=N;exports.init=Z;
@@ -1,39 +1,35 @@
1
- import { A as L, m as D } from "../../AutocompletePageProvider-HeGU8tjH.js";
2
- import { C as R, m as B } from "../../CategoryPageProvider-Bou8i9Tx.js";
3
- import { n as T, c as g } from "../../useActions-SEyBHGra.js";
4
- import { S as F, m as O } from "../../SerpPageProvider-B-W6nCqu.js";
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";
5
5
  import { u as d } from "../../jsxRuntime.module-Bzuv3cXw.js";
6
- import { d as $, b as j } from "../../bindInput-CCx0Fhsg.js";
7
- import { a as x } from "../../unique-Cv2g464w.js";
8
- import { Fragment as K, createContext as Q, render as y } from "preact";
9
- import { l as C } from "../../logger-_fg_Za9y.js";
10
- import { useErrorBoundary as U } from "preact/hooks";
11
- import { s as v } from "../../index.es-XNBESE3P.js";
12
- import { g as S, a as M } from "../../search-sC5QgJmw.js";
13
- function z(e) {
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
14
  let t;
15
15
  return (n) => {
16
16
  t && clearTimeout(t), t = setTimeout(n, e);
17
17
  };
18
18
  }
19
- function h({ children: e }) {
20
- const [t] = U();
21
- return t && C.error("Error caught in ErrorBoundary", t), /* @__PURE__ */ d(K, { children: e });
22
- }
23
- function b(e) {
19
+ function S(e) {
24
20
  return Array.from(document.querySelectorAll(e));
25
21
  }
26
- function G(e) {
22
+ function M(e) {
27
23
  const t = [];
28
24
  let n = e.parentNode;
29
25
  for (; n && n !== document && n instanceof Element; )
30
26
  t.push(n), n = n.parentNode;
31
27
  return t;
32
28
  }
33
- function E([e, t], n) {
29
+ function b([e, t], n) {
34
30
  const o = (r) => {
35
31
  const i = r.target;
36
- i instanceof HTMLElement && e && i !== e && i !== t && !G(i).includes(e) && n();
32
+ i instanceof HTMLElement && e && i !== e && i !== t && !M(i).includes(e) && n();
37
33
  };
38
34
  return document.addEventListener("click", o), {
39
35
  destroy: () => {
@@ -41,10 +37,10 @@ function E([e, t], n) {
41
37
  }
42
38
  };
43
39
  }
44
- function A(e, t) {
40
+ function E(e, t) {
45
41
  e.tabIndex = 0, e.addEventListener("blur", t);
46
42
  }
47
- function w(e) {
43
+ function C(e) {
48
44
  return typeof e == "string" ? {
49
45
  selector: e,
50
46
  position: "last"
@@ -55,14 +51,14 @@ function w(e) {
55
51
  }
56
52
  function H({ selector: e, timeout: t = 500 }) {
57
53
  return new Promise((n) => {
58
- const o = b(e);
54
+ const o = S(e);
59
55
  if (o.length > 0)
60
56
  return n(o);
61
57
  const r = new MutationObserver(() => {
62
- const s = b(e);
58
+ const s = S(e);
63
59
  s.length > 0 && (r.disconnect(), clearTimeout(i), n(s));
64
60
  }), i = setTimeout(() => {
65
- r.disconnect(), C.warn(`Timed out (${t}) while waiting for element ${e}`), n([]);
61
+ r.disconnect(), x.warn(`Timed out (${t}) while waiting for element ${e}`), n([]);
66
62
  }, t);
67
63
  r.observe(document.body, {
68
64
  childList: !0,
@@ -70,7 +66,7 @@ function H({ selector: e, timeout: t = 500 }) {
70
66
  });
71
67
  });
72
68
  }
73
- const J = Q({
69
+ const z = K({
74
70
  reportProductClick: () => {
75
71
  },
76
72
  reportKeywordClick: () => {
@@ -79,11 +75,11 @@ const J = Q({
79
75
  },
80
76
  highlightedElementIndex: -1
81
77
  });
82
- function V(e, t) {
83
- const { dropdown: n, history: o, store: r, input: i, onNavigateToSearch: s } = e, a = (c, u) => {
78
+ function G(e, t) {
79
+ const { dropdown: n, history: o, store: r, input: i, onNavigateToSearch: s } = e, a = (c, h) => {
84
80
  n.hide(), o.hide(), c && (o.add(c), r.updateState({
85
81
  historyItems: o.get()
86
- }), u && v((l) => l.recordSearchSubmit(c)), i.value = c);
82
+ }), h && Q((l) => l.recordSearchSubmit(c)), i.value = c);
87
83
  };
88
84
  return {
89
85
  reportProductClick: (c) => {
@@ -105,7 +101,7 @@ function N(e, t, n) {
105
101
  return e.parentElement;
106
102
  const l = document.createElement("div");
107
103
  return l.className = "nosto-autocomplete-wrapper", e.parentNode?.insertBefore(l, e.nextSibling), l.appendChild(e), l;
108
- })(), r = w(n), i = r && document.querySelector(r.selector);
104
+ })(), r = C(n), i = r && document.querySelector(r.selector);
109
105
  if (i) {
110
106
  const l = document.createElement("form");
111
107
  l.className = "nosto-dropdown-form", l.appendChild(t), r.position === "first" ? i.prepend(l) : i.appendChild(l);
@@ -119,7 +115,7 @@ function N(e, t, n) {
119
115
  f === 0 && (m = -1), s.index = m >= 0 ? m % f : f - 1, s.onChangeListeners.forEach((P) => P());
120
116
  }, c = () => {
121
117
  s.index = -1, s.onChangeListeners.forEach((l) => l());
122
- }, u = () => s.index;
118
+ }, h = () => s.index;
123
119
  return {
124
120
  element: t,
125
121
  hide: () => {
@@ -130,15 +126,15 @@ function N(e, t, n) {
130
126
  },
131
127
  isOpen: () => t.style.display !== "none",
132
128
  goDown: () => {
133
- const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = u();
129
+ const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
134
130
  a(l, m + 1);
135
131
  },
136
132
  goUp: () => {
137
- const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = u();
133
+ const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
138
134
  a(l, m - 1);
139
135
  },
140
136
  highlight: a,
141
- highlightedIndex: u,
137
+ highlightedIndex: h,
142
138
  submitHighlightedItem: (l) => {
143
139
  Array.from(t.querySelectorAll(".ns-autocomplete-element"))[l]?.click();
144
140
  },
@@ -147,27 +143,27 @@ function N(e, t, n) {
147
143
  }
148
144
  };
149
145
  }
150
- function W(e, t) {
146
+ function J(e, t) {
151
147
  const n = document.createElement("div");
152
148
  return n.className = "nosto-autocomplete-dropdown", {
153
149
  ...N(e, n, t),
154
150
  element: n
155
151
  };
156
152
  }
157
- const p = "nosto:search-js:history";
158
- function X(e, t, n) {
153
+ const g = "nosto:search-js:history";
154
+ function V(e, t, n) {
159
155
  const o = document.createElement("div");
160
156
  return o.className = "nosto-autocomplete-history", {
161
157
  ...N(e, o, t),
162
158
  element: o,
163
159
  add: (i) => {
164
- const a = (S(p) ?? []).filter((c) => c !== i).slice(n ? -n : 0);
165
- a.push(i), M(p, a);
160
+ const a = (w(g) ?? []).filter((c) => c !== i).slice(n ? -n : 0);
161
+ a.push(i), U(g, a);
166
162
  },
167
- get: () => (S(p) ?? []).reverse().filter((s) => !!s)
163
+ get: () => (w(g) ?? []).reverse().filter((s) => !!s)
168
164
  };
169
165
  }
170
- async function Y(e, { config: t, dropdown: n, history: o, renderHistory: r, store: i }) {
166
+ async function W(e, { config: t, dropdown: n, history: o, renderHistory: r, store: i }) {
171
167
  const { historyEnabled: s, minQueryLength: a } = t;
172
168
  if (e.length < a && s && r && !o.isOpen()) {
173
169
  o.show();
@@ -177,9 +173,9 @@ async function Y(e, { config: t, dropdown: n, history: o, renderHistory: r, stor
177
173
  return;
178
174
  n.hide();
179
175
  const c = i.getState()?.query?.query;
180
- c && c !== e && await T({ config: t, store: i }, { query: e }), n.show();
176
+ c && c !== e && await L({ config: t, store: i }, { query: e }), n.show();
181
177
  }
182
- async function Z(e, t) {
178
+ async function X(e, t) {
183
179
  const { config: n, renderHistory: o, history: r } = t, { historyEnabled: i, minQueryLength: s } = n;
184
180
  if (!o || e.length >= s || !i || r.isOpen())
185
181
  return;
@@ -187,10 +183,10 @@ async function Z(e, t) {
187
183
  r.onHighlightChange(() => {
188
184
  a(o, r.element);
189
185
  }), r.show();
190
- const c = x("renderHistory");
186
+ const c = T("renderHistory");
191
187
  a(o, r.element), c();
192
188
  }
193
- async function _(e, { config: t, dropdown: n, history: o, store: r, debouncer: i }) {
189
+ async function Y(e, { config: t, dropdown: n, history: o, store: r, debouncer: i }) {
194
190
  const { minQueryLength: s, historyEnabled: a } = t;
195
191
  if (e.length < s && !a) {
196
192
  n.hide(), o.hide();
@@ -201,18 +197,18 @@ async function _(e, { config: t, dropdown: n, history: o, store: r, debouncer: i
201
197
  return;
202
198
  }
203
199
  o.hide(), i(async () => {
204
- T({ config: t, store: r }, { query: e }), n.show();
200
+ L({ config: t, store: r }, { query: e }), n.show();
205
201
  });
206
202
  }
207
- function ee(e, t, n) {
203
+ function Z(e, t, n) {
208
204
  const { config: o, debouncer: r } = n;
209
205
  if (r(() => {
210
206
  }), e.length >= o.minQueryLength)
211
- return I(t, n.dropdown, n.history);
207
+ return A(t, n.dropdown, n.history);
212
208
  if (o.historyEnabled)
213
- return I(t, n.history, n.dropdown);
209
+ return A(t, n.history, n.dropdown);
214
210
  }
215
- function I(e, t, n) {
211
+ function A(e, t, n) {
216
212
  if (!t.isOpen() && e === "ArrowDown") {
217
213
  t.show(), n.hide();
218
214
  return;
@@ -228,46 +224,46 @@ function I(e, t, n) {
228
224
  }
229
225
  }
230
226
  }
231
- function te(e, { config: t, dropdown: n, history: o, onNavigateToSearch: r, store: i }) {
227
+ function _(e, { config: t, dropdown: n, history: o, onNavigateToSearch: r, store: i }) {
232
228
  n.hide(), o.hide(), !(e.length < t.minQueryLength) && (o.add(e), i.updateState({
233
229
  historyItems: o.get()
234
230
  }), r?.({
235
231
  query: e
236
232
  }));
237
233
  }
238
- async function ne(e, t) {
239
- const { inputCssSelector: n, timeout: o } = e, r = w(n).selector, i = await H({
234
+ async function ee(e, t) {
235
+ const { inputCssSelector: n, timeout: o } = e, r = C(n).selector, i = await H({
240
236
  selector: r,
241
237
  timeout: o
242
238
  });
243
239
  if (i.length === 0)
244
240
  throw new Error(`No elements found for selector: ${r}`);
245
241
  i.forEach((s) => {
246
- oe(s, e, t);
242
+ te(s, e, t);
247
243
  });
248
244
  }
249
- async function oe(e, t, n) {
250
- const { config: o, dropdownCssSelector: r } = t, i = W(e, r), s = X(e, r, o.historySize), a = {
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 = {
251
247
  ...t,
252
248
  input: e,
253
249
  dropdown: i,
254
250
  history: s,
255
251
  store: n,
256
- debouncer: z(o.debounceDelay)
252
+ debouncer: v(o.debounceDelay)
257
253
  };
258
- ie(a), e.setAttribute("data-nosto-element", "search-input"), n.updateState({
254
+ oe(a), e.setAttribute("data-nosto-element", "search-input"), n.updateState({
259
255
  historyItems: s.get()
260
- }), $(e), n.onInit(() => {
261
- re(a);
262
- }), j(e, {
263
- onInput: (c) => _(c, a),
264
- onFocus: (c) => Z(c, a),
265
- onClick: (c) => Y(c, a),
266
- onSubmit: (c) => te(c, a),
267
- onKeyDown: (c, u) => ee(c, u, a)
268
- }), A(s.element, s.hide), A(i.element, i.hide), E([s.element, e], s.hide), E([i.element, e], i.hide);
256
+ }), F(e), n.onInit(() => {
257
+ ne(a);
258
+ }), 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);
269
265
  }
270
- function re(e) {
266
+ function ne(e) {
271
267
  const { dropdown: t, renderAutocomplete: n } = e;
272
268
  if (!n)
273
269
  return;
@@ -275,10 +271,10 @@ function re(e) {
275
271
  t.onHighlightChange(() => {
276
272
  o(n, t.element);
277
273
  });
278
- const r = x("renderAutocomplete");
274
+ const r = T("renderAutocomplete");
279
275
  o(n, t.element), r();
280
276
  }
281
- async function ie(e) {
277
+ async function oe(e) {
282
278
  const { input: t, renderSpeechToText: n, config: o, store: r } = e;
283
279
  if (!n) return;
284
280
  const i = "ns-autocomplete-voice-position";
@@ -287,47 +283,47 @@ async function ie(e) {
287
283
  a.className = i, t.insertAdjacentElement("afterend", a);
288
284
  const c = await n();
289
285
  y(
290
- /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(L, { config: o, store: r, children: c }) }),
286
+ /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(I, { config: o, store: r, children: c }) }),
291
287
  a
292
288
  );
293
289
  }
294
290
  function q(e, t) {
295
- const { config: n, store: o } = e, r = V(e, t);
291
+ const { config: n, store: o } = e, r = G(e, t);
296
292
  return t.onHighlightChange(() => {
297
293
  r.highlightedElementIndex = t.highlightedIndex();
298
294
  }), (i, s) => y(
299
- /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(L, { config: n, store: o, children: /* @__PURE__ */ d(J, { value: r, children: i() }) }) }),
295
+ /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(I, { config: n, store: o, children: /* @__PURE__ */ d(z, { value: r, children: i() }) }) }),
300
296
  s
301
297
  );
302
298
  }
303
299
  async function k({ cssSelector: e, timeout: t, renderComponent: n }) {
304
- const o = w(e).selector, r = await H({
300
+ const o = C(e).selector, r = await H({
305
301
  selector: o,
306
302
  timeout: t ?? 100
307
303
  });
308
304
  if (r.length === 0)
309
305
  throw new Error(`No elements found for selector: ${o}`);
310
- r.length > 1 && C.warn(`Multiple (${r.length}) elements found for selector: ${o}`), y(n(), r[0]);
306
+ r.length > 1 && x.warn(`Multiple (${r.length}) elements found for selector: ${o}`), y(n(), r[0]);
311
307
  }
312
- async function se(e, t) {
308
+ async function re(e, t) {
313
309
  const { render: n } = e, o = await n();
314
310
  k({
315
311
  ...e,
316
- renderComponent: () => /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(R, { store: t, config: e.config, children: o }) })
312
+ renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(R, { store: t, config: e.config, children: o }) })
317
313
  });
318
314
  }
319
- async function ce(e, t) {
315
+ async function ie(e, t) {
320
316
  const { render: n } = e, o = await n();
321
317
  k({
322
318
  ...e,
323
- renderComponent: () => /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(F, { store: t, config: e.config, children: o }) })
319
+ renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d($, { store: t, config: e.config, children: o }) })
324
320
  });
325
321
  }
326
- async function Se({ autocomplete: e, category: t, serp: n }) {
322
+ async function Ce({ autocomplete: e, category: t, serp: n }) {
327
323
  const o = {};
328
324
  if (e) {
329
- const r = g({ query: e.query });
330
- await ne(
325
+ const r = p({ query: e.query });
326
+ await ee(
331
327
  {
332
328
  ...e,
333
329
  config: D(e.config)
@@ -336,21 +332,21 @@ async function Se({ autocomplete: e, category: t, serp: n }) {
336
332
  ), o.autocomplete = { store: r };
337
333
  }
338
334
  if (t) {
339
- const r = g({ query: t.query });
340
- await se(
335
+ const r = p({ query: t.query });
336
+ await re(
341
337
  {
342
338
  ...t,
343
- config: B(t.config)
339
+ config: O(t.config)
344
340
  },
345
341
  r
346
342
  ), o.category = { store: r };
347
343
  }
348
344
  if (n) {
349
- const r = g({ query: n.query });
350
- await ce(
345
+ const r = p({ query: n.query });
346
+ await ie(
351
347
  {
352
348
  ...n,
353
- config: O(n.config)
349
+ config: j(n.config)
354
350
  },
355
351
  r
356
352
  ), o.serp = { store: r };
@@ -358,6 +354,6 @@ async function Se({ autocomplete: e, category: t, serp: n }) {
358
354
  return o;
359
355
  }
360
356
  export {
361
- J as AutocompleteContext,
362
- Se as init
357
+ z as AutocompleteContext,
358
+ Ce as init
363
359
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "3.13.1",
3
+ "version": "3.14.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -103,7 +103,7 @@
103
103
  "@testing-library/dom": "^10.4.1",
104
104
  "@types/dom-speech-recognition": "^0.0.6",
105
105
  "@types/eslint-config-prettier": "^6.11.3",
106
- "@types/node": "^24.3.1",
106
+ "@types/node": "^24.4.0",
107
107
  "@vitest/coverage-v8": "^3.2.4",
108
108
  "concurrently": "^9.2.1",
109
109
  "copyfiles": "^2.4.1",
@@ -117,9 +117,9 @@
117
117
  "eslint-plugin-unused-imports": "^4.2.0",
118
118
  "husky": "^9.1.7",
119
119
  "isbot": "^5.1.30",
120
- "jsdom": "^26.1.0",
120
+ "jsdom": "^27.0.0",
121
121
  "prettier": "^3.6.2",
122
- "typedoc": "^0.28.12",
122
+ "typedoc": "^0.28.13",
123
123
  "typescript": "^5.9.2",
124
124
  "typescript-eslint": "^8.43.0",
125
125
  "vite": "^7.1.5",