@nosto/search-js 3.6.0 → 3.7.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 (27) hide show
  1. package/dist/{AutocompletePageProvider-BoV4iLil.js → AutocompletePageProvider-B5fknz_F.js} +1 -1
  2. package/dist/{AutocompletePageProvider-DPTHPXyz.cjs → AutocompletePageProvider-yFydWINa.cjs} +1 -1
  3. package/dist/{CategoryPageProvider-CkeR1heA.cjs → CategoryPageProvider-Cv2clyeT.cjs} +1 -1
  4. package/dist/{CategoryPageProvider-Dzcbnz1W.js → CategoryPageProvider-aGaznOx0.js} +1 -1
  5. package/dist/{SerpPageProvider-CCPCHjKU.cjs → SerpPageProvider-1jG3MP2M.cjs} +1 -1
  6. package/dist/{SerpPageProvider-Ca6ZoAOq.js → SerpPageProvider-UgSIPtNb.js} +1 -1
  7. package/dist/{baseConfig-CvAG6x_p.js → baseConfig-CvJ08LBP.js} +1 -1
  8. package/dist/{baseConfig-0GdMC5Qa.cjs → baseConfig-dsYHpa9W.cjs} +1 -1
  9. package/dist/eventBusSubscribe-CzlS132j.js +26 -0
  10. package/dist/eventBusSubscribe-oONOUGH8.cjs +1 -0
  11. package/dist/preact/autocomplete/autocomplete.cjs.js +1 -1
  12. package/dist/preact/autocomplete/autocomplete.es.js +1 -1
  13. package/dist/preact/category/category.cjs.js +1 -1
  14. package/dist/preact/category/category.es.js +1 -1
  15. package/dist/preact/events/events.cjs.js +1 -1
  16. package/dist/preact/events/events.es.js +14 -14
  17. package/dist/preact/events/src/eventBusDispatch.d.ts +3 -3
  18. package/dist/preact/events/src/eventBusSubscribe.d.ts +2 -2
  19. package/dist/preact/inject/inject.cjs.js +1 -1
  20. package/dist/preact/inject/inject.es.js +85 -85
  21. package/dist/preact/inject/src/init.d.ts +1 -1
  22. package/dist/preact/serp/serp.cjs.js +1 -1
  23. package/dist/preact/serp/serp.es.js +1 -1
  24. package/dist/utils/src/deepFreeze.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/dist/eventBusSubscribe-B75y7otR.cjs +0 -1
  27. package/dist/eventBusSubscribe-Cxw0xUAm.js +0 -25
@@ -1,6 +1,6 @@
1
1
  import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
2
2
  import { c as n, S as i, C as u } from "./useActions-Cd7V2qfb.js";
3
- import { d as c, u as s, S as l } from "./baseConfig-CvAG6x_p.js";
3
+ import { d as c, u as s, S as l } from "./baseConfig-CvJ08LBP.js";
4
4
  const m = {
5
5
  ...c,
6
6
  memoryCache: !1,
@@ -1 +1 @@
1
- "use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),o=require("./useActions-yB4RkNMW.cjs"),n=require("./baseConfig-0GdMC5Qa.cjs"),a={...n.defaultBaseConfig,memoryCache:!1,historyEnabled:!0,historySize:5,debounceDelay:500,minQueryLength:2};function r(e={}){return{pageType:"autocomplete",...a,...e}}function l({config:e,store:u,children:i}){const c=u??o.createStore();return n.useCheckClientScript(),t.u(o.ConfigContext,{value:r(e),children:t.u(o.StoreContext,{value:c,children:[t.u(n.StoreActionsListener,{}),i]})})}exports.AutocompletePageProvider=l;exports.makeAutocompleteConfig=r;
1
+ "use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),o=require("./useActions-yB4RkNMW.cjs"),n=require("./baseConfig-dsYHpa9W.cjs"),a={...n.defaultBaseConfig,memoryCache:!1,historyEnabled:!0,historySize:5,debounceDelay:500,minQueryLength:2};function r(e={}){return{pageType:"autocomplete",...a,...e}}function l({config:e,store:u,children:i}){const c=u??o.createStore();return n.useCheckClientScript(),t.u(o.ConfigContext,{value:r(e),children:t.u(o.StoreContext,{value:c,children:[t.u(n.StoreActionsListener,{}),i]})})}exports.AutocompletePageProvider=l;exports.makeAutocompleteConfig=r;
@@ -1 +1 @@
1
- "use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-yB4RkNMW.cjs"),o=require("./baseConfig-0GdMC5Qa.cjs"),s={...o.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function n(e){return{pageType:"category",...s,...e}}function u({config:e,store:a,children:i}){const c=a??r.createStore();return o.useCheckClientScript(),t.u(r.ConfigContext,{value:n(e),children:t.u(r.StoreContext,{value:c,children:[t.u(o.StoreActionsListener,{}),i]})})}exports.CategoryPageProvider=u;exports.makeCategoryConfig=n;
1
+ "use strict";const t=require("./jsxRuntime.module-B3sGoTIU.cjs"),r=require("./useActions-yB4RkNMW.cjs"),o=require("./baseConfig-dsYHpa9W.cjs"),s={...o.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function n(e){return{pageType:"category",...s,...e}}function u({config:e,store:a,children:i}){const c=a??r.createStore();return o.useCheckClientScript(),t.u(r.ConfigContext,{value:n(e),children:t.u(r.StoreContext,{value:c,children:[t.u(o.StoreActionsListener,{}),i]})})}exports.CategoryPageProvider=u;exports.makeCategoryConfig=n;
@@ -1,6 +1,6 @@
1
1
  import { u as t } from "./jsxRuntime.module-Bzuv3cXw.js";
2
2
  import { c as n, S as s, C as i } from "./useActions-Cd7V2qfb.js";
3
- import { d as c, u as C, S as f } from "./baseConfig-CvAG6x_p.js";
3
+ import { d as c, u as C, S as f } from "./baseConfig-CvJ08LBP.js";
4
4
  const l = {
5
5
  ...c,
6
6
  persistentSearchCache: !1,
@@ -1 +1 @@
1
- "use strict";const r=require("./jsxRuntime.module-B3sGoTIU.cjs"),t=require("./useActions-yB4RkNMW.cjs"),n=require("./baseConfig-0GdMC5Qa.cjs"),s={...n.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function o(e={}){return{pageType:"search",...s,...e}}function u({config:e,store:i,children:a}){const c=i??t.createStore();return n.useCheckClientScript(),r.u(t.ConfigContext,{value:o(e),children:r.u(t.StoreContext,{value:c,children:[r.u(n.StoreActionsListener,{}),a]})})}exports.SearchPageProvider=u;exports.makeSerpConfig=o;
1
+ "use strict";const r=require("./jsxRuntime.module-B3sGoTIU.cjs"),t=require("./useActions-yB4RkNMW.cjs"),n=require("./baseConfig-dsYHpa9W.cjs"),s={...n.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function o(e={}){return{pageType:"search",...s,...e}}function u({config:e,store:i,children:a}){const c=i??t.createStore();return n.useCheckClientScript(),r.u(t.ConfigContext,{value:o(e),children:r.u(t.StoreContext,{value:c,children:[r.u(n.StoreActionsListener,{}),a]})})}exports.SearchPageProvider=u;exports.makeSerpConfig=o;
@@ -1,6 +1,6 @@
1
1
  import { u as r } from "./jsxRuntime.module-Bzuv3cXw.js";
2
2
  import { c as n, S as s, C as c } from "./useActions-Cd7V2qfb.js";
3
- import { d as i, u as f, S } from "./baseConfig-CvAG6x_p.js";
3
+ import { d as i, u as f, S } from "./baseConfig-CvJ08LBP.js";
4
4
  const l = {
5
5
  ...i,
6
6
  persistentSearchCache: !1,
@@ -1,5 +1,5 @@
1
1
  import { a as i, e as n } from "./useActions-Cd7V2qfb.js";
2
- import { u as r } from "./eventBusSubscribe-Cxw0xUAm.js";
2
+ import { u as r } from "./eventBusSubscribe-CzlS132j.js";
3
3
  import { s as c } from "./index.es-XNBESE3P.js";
4
4
  import { l as u } from "./logger-_fg_Za9y.js";
5
5
  import { useEffect as l } from "preact/hooks";
@@ -1 +1 @@
1
- "use strict";const i=require("./useActions-yB4RkNMW.cjs"),r=require("./eventBusSubscribe-B75y7otR.cjs"),c=require("./index.es-Dp6Iaxz3.cjs"),o=require("./logger-Boh_C6Bz.cjs"),u=require("preact/hooks");function s(){const{pageType:t}=i.useConfig(),n=i.useActions();return r.useEventBusSubscribe({event:"actions/newSearch",callback:e=>{t===e.targetStore&&n.newSearch(e.query,e.options)}}),r.useEventBusSubscribe({event:"actions/updateSearch",callback:e=>{t===e.targetStore&&n.updateSearch(e.query,e.options)}}),r.useEventBusSubscribe({event:"actions/replaceFilter",callback:e=>{t===e.targetStore&&n.replaceFilter(e.field,e.value)}}),r.useEventBusSubscribe({event:"actions/toggleProductFilter",callback:e=>{t===e.targetStore&&n.toggleProductFilter(e.field,e.value,e.active)}}),null}function l(){u.useEffect(()=>{const t=window.setTimeout(()=>{o.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);c.s(()=>{window.clearTimeout(t)})},[])}const a={defaultCurrency:"EUR",queryModifications:t=>t};exports.StoreActionsListener=s;exports.defaultBaseConfig=a;exports.useCheckClientScript=l;
1
+ "use strict";const i=require("./useActions-yB4RkNMW.cjs"),r=require("./eventBusSubscribe-oONOUGH8.cjs"),c=require("./index.es-Dp6Iaxz3.cjs"),o=require("./logger-Boh_C6Bz.cjs"),u=require("preact/hooks");function s(){const{pageType:t}=i.useConfig(),n=i.useActions();return r.useEventBusSubscribe({event:"actions/newSearch",callback:e=>{t===e.targetStore&&n.newSearch(e.query,e.options)}}),r.useEventBusSubscribe({event:"actions/updateSearch",callback:e=>{t===e.targetStore&&n.updateSearch(e.query,e.options)}}),r.useEventBusSubscribe({event:"actions/replaceFilter",callback:e=>{t===e.targetStore&&n.replaceFilter(e.field,e.value)}}),r.useEventBusSubscribe({event:"actions/toggleProductFilter",callback:e=>{t===e.targetStore&&n.toggleProductFilter(e.field,e.value,e.active)}}),null}function l(){u.useEffect(()=>{const t=window.setTimeout(()=>{o.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);c.s(()=>{window.clearTimeout(t)})},[])}const a={defaultCurrency:"EUR",queryModifications:t=>t};exports.StoreActionsListener=s;exports.defaultBaseConfig=a;exports.useCheckClientScript=l;
@@ -0,0 +1,26 @@
1
+ import { useCallback as r, useEffect as i } from "preact/hooks";
2
+ function c({ event: s, callback: n }) {
3
+ const e = (o) => {
4
+ const t = o.detail;
5
+ n(t);
6
+ };
7
+ return window.addEventListener(`@nosto/search-js/${s}`, e), () => {
8
+ window.removeEventListener(`@nosto/search-js/${s}`, e);
9
+ };
10
+ }
11
+ function u({ event: s, callback: n }) {
12
+ const e = r(
13
+ (o) => {
14
+ const t = o.detail;
15
+ n(t);
16
+ },
17
+ [n]
18
+ );
19
+ i(() => (window.addEventListener(`@nosto/search-js/${s}`, e), () => {
20
+ window.removeEventListener(`@nosto/search-js/${s}`, e);
21
+ }), [s, e]);
22
+ }
23
+ export {
24
+ c as s,
25
+ u
26
+ };
@@ -0,0 +1 @@
1
+ "use strict";const r=require("preact/hooks");function i({event:s,callback:n}){const e=o=>{const t=o.detail;n(t)};return window.addEventListener(`@nosto/search-js/${s}`,e),()=>{window.removeEventListener(`@nosto/search-js/${s}`,e)}}function c({event:s,callback:n}){const e=r.useCallback(o=>{const t=o.detail;n(t)},[n]);r.useEffect(()=>(window.addEventListener(`@nosto/search-js/${s}`,e),()=>{window.removeEventListener(`@nosto/search-js/${s}`,e)}),[s,e])}exports.subscribeToNostoEvent=i;exports.useEventBusSubscribe=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../AutocompletePageProvider-DPTHPXyz.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../../index.es-Dp6Iaxz3.cjs"),a=require("../../BaseElement-DgwqyaY8.cjs"),m=require("preact/hooks");function p({children:t,hit:e,as:o,componentProps:n}){const r=m.useCallback(()=>{e&&"productId"in e&&i.s(c=>c.recordSearchClick("autocomplete",e))},[e]);return u.u(a.BaseElement,{onClick:r,as:o,componentProps:n,className:"ns-autocomplete-element",children:t})}function d({children:t,class:e,onSubmit:o}){return u.u("div",{className:`ns-autocomplete-element ${e||""}`,onClick:o,onKeyDown:n=>{n.key==="Enter"&&o()},children:t})}function P({as:t,componentProps:e,onSearchInput:o,children:n}){const r={...e,onInput:s=>{o(s.target)}},c=t??"input";return t||(r.type="search"),u.u(c,{...r,children:n})}exports.AutocompletePageProvider=l.AutocompletePageProvider;exports.AutocompleteElement=p;exports.HistoryElement=d;exports.SearchInput=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../AutocompletePageProvider-yFydWINa.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../../index.es-Dp6Iaxz3.cjs"),a=require("../../BaseElement-DgwqyaY8.cjs"),m=require("preact/hooks");function p({children:t,hit:e,as:o,componentProps:n}){const r=m.useCallback(()=>{e&&"productId"in e&&i.s(c=>c.recordSearchClick("autocomplete",e))},[e]);return u.u(a.BaseElement,{onClick:r,as:o,componentProps:n,className:"ns-autocomplete-element",children:t})}function d({children:t,class:e,onSubmit:o}){return u.u("div",{className:`ns-autocomplete-element ${e||""}`,onClick:o,onKeyDown:n=>{n.key==="Enter"&&o()},children:t})}function P({as:t,componentProps:e,onSearchInput:o,children:n}){const r={...e,onInput:s=>{o(s.target)}},c=t??"input";return t||(r.type="search"),u.u(c,{...r,children:n})}exports.AutocompletePageProvider=l.AutocompletePageProvider;exports.AutocompleteElement=p;exports.HistoryElement=d;exports.SearchInput=P;
@@ -1,4 +1,4 @@
1
- import { A as I } from "../../AutocompletePageProvider-BoV4iLil.js";
1
+ import { A as I } from "../../AutocompletePageProvider-B5fknz_F.js";
2
2
  import { u as m } from "../../jsxRuntime.module-Bzuv3cXw.js";
3
3
  import { s } from "../../index.es-XNBESE3P.js";
4
4
  import { B as a } from "../../BaseElement-iXMoOyxY.js";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../CategoryPageProvider-CkeR1heA.cjs");exports.CategoryPageProvider=e.CategoryPageProvider;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../CategoryPageProvider-Cv2clyeT.cjs");exports.CategoryPageProvider=e.CategoryPageProvider;
@@ -1,4 +1,4 @@
1
- import { C as o } from "../../CategoryPageProvider-Dzcbnz1W.js";
1
+ import { C as o } from "../../CategoryPageProvider-aGaznOx0.js";
2
2
  export {
3
3
  o as CategoryPageProvider
4
4
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("preact/hooks"),t=require("../../eventBusSubscribe-B75y7otR.cjs"),o=({event:s,params:e})=>{window.dispatchEvent(new CustomEvent(`@nosto/search-js/${s}`,{detail:e}))},n=({event:s})=>u.useCallback(e=>{o({event:s,params:e})},[s]);exports.subscribeToNostoEvent=t.subscribeToNostoEvent;exports.useEventBusSubscribe=t.useEventBusSubscribe;exports.dispatchNostoEvent=o;exports.useEventBusDispatch=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("preact/hooks"),t=require("../../eventBusSubscribe-oONOUGH8.cjs");function o({event:e,params:s}){window.dispatchEvent(new CustomEvent(`@nosto/search-js/${e}`,{detail:s}))}function n({event:e}){return u.useCallback(s=>{o({event:e,params:s})},[e])}exports.subscribeToNostoEvent=t.subscribeToNostoEvent;exports.useEventBusSubscribe=t.useEventBusSubscribe;exports.dispatchNostoEvent=o;exports.useEventBusDispatch=n;
@@ -1,23 +1,23 @@
1
1
  import { useCallback as o } from "preact/hooks";
2
- import { s as c, u as i } from "../../eventBusSubscribe-Cxw0xUAm.js";
3
- const e = ({
4
- event: s,
5
- params: t
6
- }) => {
2
+ import { s as a, u as c } from "../../eventBusSubscribe-CzlS132j.js";
3
+ function e({ event: s, params: t }) {
7
4
  window.dispatchEvent(
8
5
  new CustomEvent(`@nosto/search-js/${s}`, {
9
6
  detail: t
10
7
  })
11
8
  );
12
- }, r = ({ event: s }) => o(
13
- (t) => {
14
- e({ event: s, params: t });
15
- },
16
- [s]
17
- );
9
+ }
10
+ function u({ event: s }) {
11
+ return o(
12
+ (t) => {
13
+ e({ event: s, params: t });
14
+ },
15
+ [s]
16
+ );
17
+ }
18
18
  export {
19
19
  e as dispatchNostoEvent,
20
- c as subscribeToNostoEvent,
21
- r as useEventBusDispatch,
22
- i as useEventBusSubscribe
20
+ a as subscribeToNostoEvent,
21
+ u as useEventBusDispatch,
22
+ c as useEventBusSubscribe
23
23
  };
@@ -2,9 +2,9 @@ import { AllowedEvents, EventParams } from './types';
2
2
  type Props<T extends AllowedEvents> = {
3
3
  event: T;
4
4
  };
5
- export declare const dispatchNostoEvent: <T extends AllowedEvents>({ event, params }: {
5
+ export declare function dispatchNostoEvent<T extends AllowedEvents>({ event, params }: {
6
6
  event: T;
7
7
  params: EventParams[T];
8
- }) => void;
9
- export declare const useEventBusDispatch: <T extends AllowedEvents>({ event }: Props<T>) => (params: EventParams[T]) => void;
8
+ }): void;
9
+ export declare function useEventBusDispatch<T extends AllowedEvents>({ event }: Props<T>): (params: EventParams[T]) => void;
10
10
  export {};
@@ -3,6 +3,6 @@ type Props<T extends AllowedEvents> = {
3
3
  event: T;
4
4
  callback: (params: EventParams[T]) => void;
5
5
  };
6
- export declare const subscribeToNostoEvent: <T extends AllowedEvents>({ event, callback }: Props<T>) => () => void;
7
- export declare const useEventBusSubscribe: <T extends AllowedEvents>({ event, callback }: Props<T>) => void;
6
+ export declare function subscribeToNostoEvent<T extends AllowedEvents>({ event, callback }: Props<T>): () => void;
7
+ export declare function useEventBusSubscribe<T extends AllowedEvents>({ event, callback }: Props<T>): void;
8
8
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../../AutocompletePageProvider-DPTHPXyz.cjs"),L=require("../../CategoryPageProvider-CkeR1heA.cjs"),m=require("../../useActions-yB4RkNMW.cjs"),x=require("../../SerpPageProvider-CCPCHjKU.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),A=require("../../bindInput-BnKvCky1.cjs"),P=require("../../unique-BXXNictB.cjs"),g=require("preact"),b=require("../../logger-Boh_C6Bz.cjs"),O=require("preact/hooks"),B=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../search-DTqo1D6Y.cjs");function F(e){let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function p({children:e}){const[t]=O.useErrorBoundary();return t&&b.logger.error("Error caught in ErrorBoundary",t),u.u(g.Fragment,{children:e})}function C(e,t){return(typeof e=="string"?Array.from(document.querySelectorAll(e)):[e]).filter(o=>!0)}function H(e,t){let n=[];return C(e).forEach(o=>{const r=o.parentNode;r!==document&&r instanceof Element&&(n.push(r),n=n.concat(H(r)))}),n.filter(o=>t===void 0)}function I([e,t],n){const o=r=>{const s=r.target;s instanceof HTMLElement&&e&&s!==e&&s!==t&&!H(s).includes(e)&&n()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function T(e,t){e.tabIndex=0,e.addEventListener("blur",t)}function E(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function N({selector:e,timeout:t=500}){return new Promise(n=>{const o=C(e);if(o.length>0)return n(o);const r=new MutationObserver(()=>{const i=C(e);i.length>0&&(r.disconnect(),clearTimeout(s),n(i))}),s=setTimeout(()=>{r.disconnect(),b.logger.warn(`Timed out (${t}) while waiting for element ${e}`),n([])},t);r.observe(document.body,{childList:!0,subtree:!0})})}const k=g.createContext({reportProductClick:()=>{},reportKeywordClick:()=>{},handleSubmit:()=>{},highlightedElementIndex:-1});function $(e,t){const{dropdown:n,history:o,store:r,input:s,onNavigateToSearch:i}=e,a=(c,h)=>{n.hide(),o.hide(),c&&(o.add(c),r.updateState({historyItems:o.get()}),h&&B.s(l=>l.recordSearchSubmit(c)),s.value=c)};return{reportProductClick:c=>{a(c.name,!1)},reportKeywordClick:c=>{a(c.keyword,!0)},handleSubmit:c=>{a(c.query,!1),i?.(c)},highlightedElementIndex:t.highlightedIndex()}}function v(e,t,n){t.style.display="none";const o=(()=>{if(e.parentElement&&e.parentElement.classList.contains("nosto-autocomplete-wrapper"))return e.parentElement;const l=document.createElement("div");return l.className="nosto-autocomplete-wrapper",e.parentNode?.insertBefore(l,e.nextSibling),l.appendChild(e),l})(),r=E(n),s=r&&document.querySelector(r.selector);if(s){const l=document.createElement("form");l.className="nosto-dropdown-form",l.appendChild(t),r.position==="first"?s.prepend(l):s.appendChild(l)}else o.appendChild(t);const i={index:-1,onChangeListeners:[]},a=(l,d)=>{const f=l.length;f===0&&(d=-1),i.index=d>=0?d%f:f-1,i.onChangeListeners.forEach(D=>D())},c=()=>{i.index=-1,i.onChangeListeners.forEach(l=>l())},h=()=>i.index;return{element:t,hide:()=>{t.style.display="none",c()},show:()=>{t.style.display="inherit"},isOpen:()=>t.style.display!=="none",goDown:()=>{const l=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();a(l,d+1)},goUp:()=>{const l=Array.from(t.getElementsByClassName("ns-autocomplete-element")),d=h();a(l,d-1)},highlight:a,highlightedIndex:h,submitHighlightedItem:l=>{Array.from(t.querySelectorAll(".ns-autocomplete-element"))[l]?.click()},onHighlightChange:l=>{i.onChangeListeners.push(l)}}}function K(e,t){const n=document.createElement("div");return n.className="nosto-autocomplete-dropdown",{...v(e,n,t),element:n}}const w="nosto:search-js:history";function Q(e,t,n){const o=document.createElement("div");return o.className="nosto-autocomplete-history",{...v(e,o,t),element:o,add:s=>{const a=(y.getLocalStorageItem(w)??[]).filter(c=>c!==s).slice(n?-n:0);a.push(s),y.setLocalStorageItem(w,a)},get:()=>(y.getLocalStorageItem(w)??[]).reverse().filter(i=>!!i)}}async function M(e,{config:t,dropdown:n,history:o,renderHistory:r,store:s}){const{historyEnabled:i,minQueryLength:a}=t;if(e.length<a&&i&&r&&!o.isOpen()){o.show();return}if(e.length<a)return;n.hide();const c=s.getState()?.query?.query;c&&c!==e&&await m.newSearch({config:t,store:s},{query:e}),n.show()}async function U(e,t){const{config:n,renderHistory:o,history:r}=t,{historyEnabled:s,minQueryLength:i}=n;if(!o||e.length>=i||!s||r.isOpen())return;const a=R(t,r);r.onHighlightChange(()=>{a(o,r.element)}),r.show();const c=P.measure("renderHistory");a(o,r.element),c()}async function _(e,{config:t,dropdown:n,history:o,store:r,debouncer:s}){const{minQueryLength:i,historyEnabled:a}=t;if(e.length<i&&!a){n.hide(),o.hide();return}if(e.length<i&&a){n.hide(),o.show();return}o.hide(),s(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 q(t,n.dropdown,n.history);if(o.historyEnabled)return q(t,n.history,n.dropdown)}function q(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:s}){n.hide(),o.hide(),!(e.length<t.minQueryLength)&&(o.add(e),s.updateState({historyItems:o.get()}),r?.({query:e}))}async function J(e,t){const{inputCssSelector:n,timeout:o}=e,r=E(n).selector,s=await N({selector:r,timeout:o});if(s.length===0)throw new Error(`No elements found for selector: ${r}`);s.forEach(i=>{V(i,e,t)})}async function V(e,t,n){const{config:o,dropdownCssSelector:r}=t,s=K(e,r),i=Q(e,r,o.historySize),a={...t,input:e,dropdown:s,history:i,store:n,debouncer:F(o.debounceDelay)};X(a),e.setAttribute("data-nosto-element","search-input"),n.updateState({historyItems:i.get()}),A.disableNativeAutocomplete(e),n.onInit(()=>{W(a)}),A.bindInput(e,{onInput:c=>_(c,a),onFocus:c=>U(c,a),onClick:c=>M(c,a),onSubmit:c=>G(c,a),onKeyDown:(c,h)=>z(c,h,a)}),T(i.element,i.hide),T(s.element,s.hide),I([i.element,e],i.hide),I([s.element,e],s.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 s="ns-autocomplete-voice-position";if(!!t.parentElement?.querySelector(`.${s}`))return;const a=document.createElement("div");a.className=s,t.insertAdjacentElement("afterend",a);const c=await n();g.render(u.u(p,{children:u.u(S.AutocompletePageProvider,{config:o,store:r,children:c})}),a)}function R(e,t){const{config:n,store:o}=e,r=$(e,t);return t.onHighlightChange(()=>{r.highlightedElementIndex=t.highlightedIndex()}),(s,i)=>g.render(u.u(p,{children:u.u(S.AutocompletePageProvider,{config:n,store:o,children:u.u(k,{value:r,children:s()})})}),i)}async function j({cssSelector:e,timeout:t,renderComponent:n}){const o=E(e).selector,r=await N({selector:o,timeout:t??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&b.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(p,{children:u.u(L.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(p,{children:u.u(x.SearchPageProvider,{store:t,config:e.config,children:o})})})}async function ee(e){e.autocomplete&&await J({...e.autocomplete,config:S.makeAutocompleteConfig(e.autocomplete.config)},m.createStore({query:e.autocomplete.query})),e.category&&await Y({...e.category,config:L.makeCategoryConfig(e.category.config)},m.createStore()),e.serp&&await Z({...e.serp,config:x.makeSerpConfig(e.serp.config)},m.createStore())}exports.AutocompleteContext=k;exports.init=ee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../../AutocompletePageProvider-yFydWINa.cjs"),L=require("../../CategoryPageProvider-Cv2clyeT.cjs"),m=require("../../useActions-yB4RkNMW.cjs"),x=require("../../SerpPageProvider-1jG3MP2M.cjs"),u=require("../../jsxRuntime.module-B3sGoTIU.cjs"),A=require("../../bindInput-BnKvCky1.cjs"),P=require("../../unique-BXXNictB.cjs"),g=require("preact"),b=require("../../logger-Boh_C6Bz.cjs"),O=require("preact/hooks"),B=require("../../index.es-Dp6Iaxz3.cjs"),y=require("../../search-DTqo1D6Y.cjs");function F(e){let t;return n=>{t&&clearTimeout(t),t=setTimeout(n,e)}}function f({children:e}){const[t]=O.useErrorBoundary();return t&&b.logger.error("Error caught in ErrorBoundary",t),u.u(g.Fragment,{children:e})}function w(e,t){return(typeof e=="string"?Array.from(document.querySelectorAll(e)):[e]).filter(o=>!0)}function H(e,t){let n=[];return w(e).forEach(o=>{const r=o.parentNode;r!==document&&r instanceof Element&&(n.push(r),n=n.concat(H(r)))}),n.filter(o=>t===void 0)}function I([e,t],n){const o=r=>{const i=r.target;i instanceof HTMLElement&&e&&i!==e&&i!==t&&!H(i).includes(e)&&n()};return document.addEventListener("click",o),{destroy:()=>{document.removeEventListener("click",o)}}}function T(e,t){e.tabIndex=0,e.addEventListener("blur",t)}function E(e){return typeof e=="string"?{selector:e,position:"last"}:{position:"last",...e}}function N({selector:e,timeout:t=500}){return new Promise(n=>{const o=w(e);if(o.length>0)return n(o);const r=new MutationObserver(()=>{const s=w(e);s.length>0&&(r.disconnect(),clearTimeout(i),n(s))}),i=setTimeout(()=>{r.disconnect(),b.logger.warn(`Timed out (${t}) while waiting for element ${e}`),n([])},t);r.observe(document.body,{childList:!0,subtree:!0})})}const k=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&&B.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 v(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=E(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(D=>D())},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",{...v(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",{...v(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 q(t,n.dropdown,n.history);if(o.historyEnabled)return q(t,n.history,n.dropdown)}function q(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=E(n).selector,i=await N({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:F(o.debounceDelay)};X(l),e.setAttribute("data-nosto-element","search-input"),n.updateState({historyItems:s.get()}),A.disableNativeAutocomplete(e),n.onInit(()=>{W(l)}),A.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)}),T(s.element,s.hide),T(i.element,i.hide),I([s.element,e],s.hide),I([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(S.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(S.AutocompletePageProvider,{config:n,store:o,children:u.u(k,{value:r,children:i()})})}),s)}async function j({cssSelector:e,timeout:t,renderComponent:n}){const o=E(e).selector,r=await N({selector:o,timeout:t??100});if(r.length===0)throw new Error(`No elements found for selector: ${o}`);r.length>1&&b.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(L.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}){e&&await J({...e,config:S.makeAutocompleteConfig(e.config)},m.createStore({query:e.query})),t&&await Y({...t,config:L.makeCategoryConfig(t.config)},m.createStore()),n&&await Z({...n,config:x.makeSerpConfig(n.config)},m.createStore())}exports.AutocompleteContext=k;exports.init=ee;
@@ -1,12 +1,12 @@
1
- import { A as T, m as R } from "../../AutocompletePageProvider-BoV4iLil.js";
2
- import { C as B, m as F } from "../../CategoryPageProvider-Dzcbnz1W.js";
3
- import { n as L, c as f } from "../../useActions-Cd7V2qfb.js";
4
- import { S as O, m as $ } from "../../SerpPageProvider-Ca6ZoAOq.js";
1
+ import { A as T, m as R } from "../../AutocompletePageProvider-B5fknz_F.js";
2
+ import { C as B, m as F } from "../../CategoryPageProvider-aGaznOx0.js";
3
+ import { n as L, c as g } from "../../useActions-Cd7V2qfb.js";
4
+ import { S as O, m as $ } from "../../SerpPageProvider-UgSIPtNb.js";
5
5
  import { u as d } from "../../jsxRuntime.module-Bzuv3cXw.js";
6
6
  import { d as j, b as v } from "../../bindInput-CCx0Fhsg.js";
7
7
  import { a as x } from "../../unique-Cv2g464w.js";
8
- import { Fragment as K, createContext as Q, render as w } from "preact";
9
- import { l as C } from "../../logger-_fg_Za9y.js";
8
+ import { Fragment as K, createContext as Q, render as C } from "preact";
9
+ import { l as w } from "../../logger-_fg_Za9y.js";
10
10
  import { useErrorBoundary as U } from "preact/hooks";
11
11
  import { s as M } from "../../index.es-XNBESE3P.js";
12
12
  import { g as b, a as z } from "../../search-sC5QgJmw.js";
@@ -16,9 +16,9 @@ function G(e) {
16
16
  t && clearTimeout(t), t = setTimeout(n, e);
17
17
  };
18
18
  }
19
- function h({ children: e }) {
19
+ function u({ children: e }) {
20
20
  const [t] = U();
21
- return t && C.error("Error caught in ErrorBoundary", t), /* @__PURE__ */ d(K, { children: e });
21
+ return t && w.error("Error caught in ErrorBoundary", t), /* @__PURE__ */ d(K, { children: e });
22
22
  }
23
23
  function y(e, t) {
24
24
  return (typeof e == "string" ? Array.from(document.querySelectorAll(e)) : [e]).filter((o) => !0);
@@ -32,8 +32,8 @@ function H(e, t) {
32
32
  }
33
33
  function E([e, t], n) {
34
34
  const o = (r) => {
35
- const s = r.target;
36
- s instanceof HTMLElement && e && s !== e && s !== t && !H(s).includes(e) && n();
35
+ const i = r.target;
36
+ i instanceof HTMLElement && e && i !== e && i !== t && !H(i).includes(e) && n();
37
37
  };
38
38
  return document.addEventListener("click", o), {
39
39
  destroy: () => {
@@ -59,10 +59,10 @@ function N({ selector: e, timeout: t = 500 }) {
59
59
  if (o.length > 0)
60
60
  return n(o);
61
61
  const r = new MutationObserver(() => {
62
- const i = y(e);
63
- i.length > 0 && (r.disconnect(), clearTimeout(s), n(i));
64
- }), s = setTimeout(() => {
65
- r.disconnect(), C.warn(`Timed out (${t}) while waiting for element ${e}`), n([]);
62
+ const s = y(e);
63
+ s.length > 0 && (r.disconnect(), clearTimeout(i), n(s));
64
+ }), i = setTimeout(() => {
65
+ r.disconnect(), w.warn(`Timed out (${t}) while waiting for element ${e}`), n([]);
66
66
  }, t);
67
67
  r.observe(document.body, {
68
68
  childList: !0,
@@ -80,10 +80,10 @@ const J = Q({
80
80
  highlightedElementIndex: -1
81
81
  });
82
82
  function V(e, t) {
83
- const { dropdown: n, history: o, store: r, input: s, onNavigateToSearch: i } = e, a = (c, u) => {
83
+ const { dropdown: n, history: o, store: r, input: i, onNavigateToSearch: s } = e, a = (c, h) => {
84
84
  n.hide(), o.hide(), c && (o.add(c), r.updateState({
85
85
  historyItems: o.get()
86
- }), u && M((l) => l.recordSearchSubmit(c)), s.value = c);
86
+ }), h && M((l) => l.recordSearchSubmit(c)), i.value = c);
87
87
  };
88
88
  return {
89
89
  reportProductClick: (c) => {
@@ -93,7 +93,7 @@ function V(e, t) {
93
93
  a(c.keyword, !0);
94
94
  },
95
95
  handleSubmit: (c) => {
96
- a(c.query, !1), i?.(c);
96
+ a(c.query, !1), s?.(c);
97
97
  },
98
98
  highlightedElementIndex: t.highlightedIndex()
99
99
  };
@@ -105,21 +105,21 @@ function k(e, t, n) {
105
105
  return e.parentElement;
106
106
  const l = document.createElement("div");
107
107
  return l.className = "nosto-autocomplete-wrapper", e.parentNode?.insertBefore(l, e.nextSibling), l.appendChild(e), l;
108
- })(), r = S(n), s = r && document.querySelector(r.selector);
109
- if (s) {
108
+ })(), r = S(n), i = r && document.querySelector(r.selector);
109
+ if (i) {
110
110
  const l = document.createElement("form");
111
- l.className = "nosto-dropdown-form", l.appendChild(t), r.position === "first" ? s.prepend(l) : s.appendChild(l);
111
+ l.className = "nosto-dropdown-form", l.appendChild(t), r.position === "first" ? i.prepend(l) : i.appendChild(l);
112
112
  } else
113
113
  o.appendChild(t);
114
- const i = {
114
+ const s = {
115
115
  index: -1,
116
116
  onChangeListeners: []
117
117
  }, a = (l, m) => {
118
- const p = l.length;
119
- p === 0 && (m = -1), i.index = m >= 0 ? m % p : p - 1, i.onChangeListeners.forEach((D) => D());
118
+ const f = l.length;
119
+ f === 0 && (m = -1), s.index = m >= 0 ? m % f : f - 1, s.onChangeListeners.forEach((D) => D());
120
120
  }, c = () => {
121
- i.index = -1, i.onChangeListeners.forEach((l) => l());
122
- }, u = () => i.index;
121
+ s.index = -1, s.onChangeListeners.forEach((l) => l());
122
+ }, h = () => s.index;
123
123
  return {
124
124
  element: t,
125
125
  hide: () => {
@@ -130,20 +130,20 @@ function k(e, t, n) {
130
130
  },
131
131
  isOpen: () => t.style.display !== "none",
132
132
  goDown: () => {
133
- const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = u();
133
+ const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
134
134
  a(l, m + 1);
135
135
  },
136
136
  goUp: () => {
137
- const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = u();
137
+ const l = Array.from(t.getElementsByClassName("ns-autocomplete-element")), m = h();
138
138
  a(l, m - 1);
139
139
  },
140
140
  highlight: a,
141
- highlightedIndex: u,
141
+ highlightedIndex: h,
142
142
  submitHighlightedItem: (l) => {
143
143
  Array.from(t.querySelectorAll(".ns-autocomplete-element"))[l]?.click();
144
144
  },
145
145
  onHighlightChange: (l) => {
146
- i.onChangeListeners.push(l);
146
+ s.onChangeListeners.push(l);
147
147
  }
148
148
  };
149
149
  }
@@ -154,34 +154,34 @@ function W(e, t) {
154
154
  element: n
155
155
  };
156
156
  }
157
- const g = "nosto:search-js:history";
157
+ const p = "nosto:search-js:history";
158
158
  function X(e, t, n) {
159
159
  const o = document.createElement("div");
160
160
  return o.className = "nosto-autocomplete-history", {
161
161
  ...k(e, o, t),
162
162
  element: o,
163
- add: (s) => {
164
- const a = (b(g) ?? []).filter((c) => c !== s).slice(n ? -n : 0);
165
- a.push(s), z(g, a);
163
+ add: (i) => {
164
+ const a = (b(p) ?? []).filter((c) => c !== i).slice(n ? -n : 0);
165
+ a.push(i), z(p, a);
166
166
  },
167
- get: () => (b(g) ?? []).reverse().filter((i) => !!i)
167
+ get: () => (b(p) ?? []).reverse().filter((s) => !!s)
168
168
  };
169
169
  }
170
- async function Y(e, { config: t, dropdown: n, history: o, renderHistory: r, store: s }) {
171
- const { historyEnabled: i, minQueryLength: a } = t;
172
- if (e.length < a && i && r && !o.isOpen()) {
170
+ async function Y(e, { config: t, dropdown: n, history: o, renderHistory: r, store: i }) {
171
+ const { historyEnabled: s, minQueryLength: a } = t;
172
+ if (e.length < a && s && r && !o.isOpen()) {
173
173
  o.show();
174
174
  return;
175
175
  }
176
176
  if (e.length < a)
177
177
  return;
178
178
  n.hide();
179
- const c = s.getState()?.query?.query;
180
- c && c !== e && await L({ config: t, store: s }, { query: e }), n.show();
179
+ const c = i.getState()?.query?.query;
180
+ c && c !== e && await L({ config: t, store: i }, { query: e }), n.show();
181
181
  }
182
182
  async function Z(e, t) {
183
- const { config: n, renderHistory: o, history: r } = t, { historyEnabled: s, minQueryLength: i } = n;
184
- if (!o || e.length >= i || !s || r.isOpen())
183
+ const { config: n, renderHistory: o, history: r } = t, { historyEnabled: i, minQueryLength: s } = n;
184
+ if (!o || e.length >= s || !i || r.isOpen())
185
185
  return;
186
186
  const a = P(t, r);
187
187
  r.onHighlightChange(() => {
@@ -190,17 +190,17 @@ async function Z(e, t) {
190
190
  const c = x("renderHistory");
191
191
  a(o, r.element), c();
192
192
  }
193
- async function _(e, { config: t, dropdown: n, history: o, store: r, debouncer: s }) {
194
- const { minQueryLength: i, historyEnabled: a } = t;
195
- if (e.length < i && !a) {
193
+ async function _(e, { config: t, dropdown: n, history: o, store: r, debouncer: i }) {
194
+ const { minQueryLength: s, historyEnabled: a } = t;
195
+ if (e.length < s && !a) {
196
196
  n.hide(), o.hide();
197
197
  return;
198
198
  }
199
- if (e.length < i && a) {
199
+ if (e.length < s && a) {
200
200
  n.hide(), o.show();
201
201
  return;
202
202
  }
203
- o.hide(), s(async () => {
203
+ o.hide(), i(async () => {
204
204
  L({ config: t, store: r }, { query: e }), n.show();
205
205
  });
206
206
  }
@@ -228,35 +228,35 @@ function I(e, t, n) {
228
228
  }
229
229
  }
230
230
  }
231
- function te(e, { config: t, dropdown: n, history: o, onNavigateToSearch: r, store: s }) {
232
- n.hide(), o.hide(), !(e.length < t.minQueryLength) && (o.add(e), s.updateState({
231
+ function te(e, { config: t, dropdown: n, history: o, onNavigateToSearch: r, store: i }) {
232
+ n.hide(), o.hide(), !(e.length < t.minQueryLength) && (o.add(e), i.updateState({
233
233
  historyItems: o.get()
234
234
  }), r?.({
235
235
  query: e
236
236
  }));
237
237
  }
238
238
  async function ne(e, t) {
239
- const { inputCssSelector: n, timeout: o } = e, r = S(n).selector, s = await N({
239
+ const { inputCssSelector: n, timeout: o } = e, r = S(n).selector, i = await N({
240
240
  selector: r,
241
241
  timeout: o
242
242
  });
243
- if (s.length === 0)
243
+ if (i.length === 0)
244
244
  throw new Error(`No elements found for selector: ${r}`);
245
- s.forEach((i) => {
246
- oe(i, e, t);
245
+ i.forEach((s) => {
246
+ oe(s, e, t);
247
247
  });
248
248
  }
249
249
  async function oe(e, t, n) {
250
- const { config: o, dropdownCssSelector: r } = t, s = W(e, r), i = X(e, r, o.historySize), a = {
250
+ const { config: o, dropdownCssSelector: r } = t, i = W(e, r), s = X(e, r, o.historySize), a = {
251
251
  ...t,
252
252
  input: e,
253
- dropdown: s,
254
- history: i,
253
+ dropdown: i,
254
+ history: s,
255
255
  store: n,
256
256
  debouncer: G(o.debounceDelay)
257
257
  };
258
- se(a), e.setAttribute("data-nosto-element", "search-input"), n.updateState({
259
- historyItems: i.get()
258
+ ie(a), e.setAttribute("data-nosto-element", "search-input"), n.updateState({
259
+ historyItems: s.get()
260
260
  }), j(e), n.onInit(() => {
261
261
  re(a);
262
262
  }), v(e, {
@@ -264,8 +264,8 @@ async function oe(e, t, n) {
264
264
  onFocus: (c) => Z(c, a),
265
265
  onClick: (c) => Y(c, a),
266
266
  onSubmit: (c) => te(c, a),
267
- onKeyDown: (c, u) => ee(c, u, a)
268
- }), A(i.element, i.hide), A(s.element, s.hide), E([i.element, e], i.hide), E([s.element, e], s.hide);
267
+ onKeyDown: (c, h) => ee(c, h, a)
268
+ }), A(s.element, s.hide), A(i.element, i.hide), E([s.element, e], s.hide), E([i.element, e], i.hide);
269
269
  }
270
270
  function re(e) {
271
271
  const { dropdown: t, renderAutocomplete: n } = e;
@@ -278,16 +278,16 @@ function re(e) {
278
278
  const r = x("renderAutocomplete");
279
279
  o(n, t.element), r();
280
280
  }
281
- async function se(e) {
281
+ async function ie(e) {
282
282
  const { input: t, renderSpeechToText: n, config: o, store: r } = e;
283
283
  if (!n) return;
284
- const s = "ns-autocomplete-voice-position";
285
- if (!!t.parentElement?.querySelector(`.${s}`)) return;
284
+ const i = "ns-autocomplete-voice-position";
285
+ if (!!t.parentElement?.querySelector(`.${i}`)) return;
286
286
  const a = document.createElement("div");
287
- a.className = s, t.insertAdjacentElement("afterend", a);
287
+ a.className = i, t.insertAdjacentElement("afterend", a);
288
288
  const c = await n();
289
- w(
290
- /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(T, { config: o, store: r, children: c }) }),
289
+ C(
290
+ /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(T, { config: o, store: r, children: c }) }),
291
291
  a
292
292
  );
293
293
  }
@@ -295,9 +295,9 @@ function P(e, t) {
295
295
  const { config: n, store: o } = e, r = V(e, t);
296
296
  return t.onHighlightChange(() => {
297
297
  r.highlightedElementIndex = t.highlightedIndex();
298
- }), (s, i) => w(
299
- /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(T, { config: n, store: o, children: /* @__PURE__ */ d(J, { value: r, children: s() }) }) }),
300
- i
298
+ }), (i, s) => C(
299
+ /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(T, { config: n, store: o, children: /* @__PURE__ */ d(J, { value: r, children: i() }) }) }),
300
+ s
301
301
  );
302
302
  }
303
303
  async function q({ cssSelector: e, timeout: t, renderComponent: n }) {
@@ -307,41 +307,41 @@ async function q({ cssSelector: e, timeout: t, renderComponent: n }) {
307
307
  });
308
308
  if (r.length === 0)
309
309
  throw new Error(`No elements found for selector: ${o}`);
310
- r.length > 1 && C.warn(`Multiple (${r.length}) elements found for selector: ${o}`), w(n(), r[0]);
310
+ r.length > 1 && w.warn(`Multiple (${r.length}) elements found for selector: ${o}`), C(n(), r[0]);
311
311
  }
312
- async function ie(e, t) {
312
+ async function se(e, t) {
313
313
  const { render: n } = e, o = await n();
314
314
  q({
315
315
  ...e,
316
- renderComponent: () => /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(B, { store: t, config: e.config, children: o }) })
316
+ renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(B, { store: t, config: e.config, children: o }) })
317
317
  });
318
318
  }
319
319
  async function ce(e, t) {
320
320
  const { render: n } = e, o = await n();
321
321
  q({
322
322
  ...e,
323
- renderComponent: () => /* @__PURE__ */ d(h, { children: /* @__PURE__ */ d(O, { store: t, config: e.config, children: o }) })
323
+ renderComponent: () => /* @__PURE__ */ d(u, { children: /* @__PURE__ */ d(O, { store: t, config: e.config, children: o }) })
324
324
  });
325
325
  }
326
- async function Se(e) {
327
- e.autocomplete && await ne(
326
+ async function Se({ autocomplete: e, category: t, serp: n }) {
327
+ e && await ne(
328
328
  {
329
- ...e.autocomplete,
330
- config: R(e.autocomplete.config)
329
+ ...e,
330
+ config: R(e.config)
331
331
  },
332
- f({ query: e.autocomplete.query })
333
- ), e.category && await ie(
332
+ g({ query: e.query })
333
+ ), t && await se(
334
334
  {
335
- ...e.category,
336
- config: F(e.category.config)
335
+ ...t,
336
+ config: F(t.config)
337
337
  },
338
- f()
339
- ), e.serp && await ce(
338
+ g()
339
+ ), n && await ce(
340
340
  {
341
- ...e.serp,
342
- config: $(e.serp.config)
341
+ ...n,
342
+ config: $(n.config)
343
343
  },
344
- f()
344
+ g()
345
345
  );
346
346
  }
347
347
  export {
@@ -1,2 +1,2 @@
1
1
  import { InitConfig } from './config';
2
- export declare function init(initConfig: InitConfig): Promise<void>;
2
+ export declare function init({ autocomplete, category, serp }: InitConfig): Promise<void>;
@@ -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-DgwqyaY8.cjs"),S=require("../../useActions-yB4RkNMW.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-CCPCHjKU.cjs"),P="nosto:search: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-DgwqyaY8.cjs"),S=require("../../useActions-yB4RkNMW.cjs"),d=require("preact/hooks"),g=require("../../SerpPageProvider-1jG3MP2M.cjs"),P="nosto:search: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;
@@ -3,7 +3,7 @@ import { s as l } from "../../index.es-XNBESE3P.js";
3
3
  import { B as m } from "../../BaseElement-iXMoOyxY.js";
4
4
  import { a as p } from "../../useActions-Cd7V2qfb.js";
5
5
  import { useCallback as f } from "preact/hooks";
6
- import { S as x } from "../../SerpPageProvider-Ca6ZoAOq.js";
6
+ import { S as x } from "../../SerpPageProvider-UgSIPtNb.js";
7
7
  const S = "nosto:search:scrollPos";
8
8
  function g() {
9
9
  window.sessionStorage.setItem(S, window.scrollY.toString());
@@ -1,5 +1,5 @@
1
1
  import { Equals, Expect } from './types';
2
- export declare const deepFreeze: <T extends object>(obj: T) => Readonly<Freeze<T>>;
2
+ export declare function deepFreeze<T extends object>(obj: T): Readonly<Freeze<T>>;
3
3
  type Freeze<T> = T extends object ? Readonly<{
4
4
  [K in keyof T]: Freeze<T[K]>;
5
5
  }> : T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -1 +0,0 @@
1
- "use strict";const r=require("preact/hooks"),c=({event:s,callback:o})=>{const e=t=>{const n=t.detail;o(n)};return window.addEventListener(`@nosto/search-js/${s}`,e),()=>{window.removeEventListener(`@nosto/search-js/${s}`,e)}},i=({event:s,callback:o})=>{const e=r.useCallback(t=>{const n=t.detail;o(n)},[o]);r.useEffect(()=>(window.addEventListener(`@nosto/search-js/${s}`,e),()=>{window.removeEventListener(`@nosto/search-js/${s}`,e)}),[s,e])};exports.subscribeToNostoEvent=c;exports.useEventBusSubscribe=i;
@@ -1,25 +0,0 @@
1
- import { useCallback as r, useEffect as a } from "preact/hooks";
2
- const c = ({ event: s, callback: o }) => {
3
- const e = (n) => {
4
- const t = n.detail;
5
- o(t);
6
- };
7
- return window.addEventListener(`@nosto/search-js/${s}`, e), () => {
8
- window.removeEventListener(`@nosto/search-js/${s}`, e);
9
- };
10
- }, d = ({ event: s, callback: o }) => {
11
- const e = r(
12
- (n) => {
13
- const t = n.detail;
14
- o(t);
15
- },
16
- [o]
17
- );
18
- a(() => (window.addEventListener(`@nosto/search-js/${s}`, e), () => {
19
- window.removeEventListener(`@nosto/search-js/${s}`, e);
20
- }), [s, e]);
21
- };
22
- export {
23
- c as s,
24
- d as u
25
- };