@nosto/search-js 2.14.0 → 2.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.
@@ -0,0 +1 @@
1
+ "use strict";const C=require("./jsxRuntime.module-B3sGoTIU.cjs"),a=require("preact/hooks");function k({onClick:i,as:n,children:t,componentProps:e}){const u=a.useCallback(s=>{i(),e&&"onClick"in e&&typeof e.onClick=="function"&&e.onClick(s)},[i,e]),c={...e,onClick:u},l=n??"a";return C.u(l,{...c,children:t})}exports.BaseElement=k;
@@ -0,0 +1,17 @@
1
+ import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
2
+ import { useCallback as o } from "preact/hooks";
3
+ function r({ onClick: t, as: C, children: l, componentProps: i }) {
4
+ const n = o(
5
+ (c) => {
6
+ t(), i && "onClick" in i && typeof i.onClick == "function" && i.onClick(c);
7
+ },
8
+ [t, i]
9
+ ), a = {
10
+ ...i,
11
+ onClick: n
12
+ };
13
+ return /* @__PURE__ */ f(C ?? "a", { ...a, children: l });
14
+ }
15
+ export {
16
+ r as B
17
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../index.es-DlUp67LT.cjs"),a=require("preact"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../configContext-BR7w4VlU.cjs"),p=require("../baseConfig-BFFqFSg5.cjs");function m(e){return e!==null&&typeof e=="object"&&"props"in e&&typeof e.type=="string"}function f({children:e,hit:t}){var n;if(!m(e))throw new Error("AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported.");const o=(n=e.props)==null?void 0:n.onClick;return a.cloneElement(e,{onClick:r=>{t&&s.s(u=>u.recordSearchClick("autocomplete",t)),typeof o=="function"&&o(r)}})}function C({as:e,componentProps:t,onSearchInput:o,children:n}){const r={...t,onInput:l=>{o(l.target)}},u=e??"input";return e||(r.type="search"),i.u(u,{...r,children:n})}const g={...p.defaultBaseConfig};function d(e){return{pageType:"autocomplete",...g,...e}}function S({config:e,store:t,children:o}){const n=t??c.createStore();return p.useCheckClientScript(),i.u(c.ConfigContext,{value:d(e),children:i.u(c.StoreContext,{value:n,children:o})})}exports.AutocompleteElement=f;exports.AutocompletePageProvider=S;exports.SearchInput=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../index.es-DlUp67LT.cjs"),p=require("preact/hooks"),m=require("../BaseElement-8qy-gSKp.cjs"),i=require("../configContext-BR7w4VlU.cjs"),l=require("../baseConfig-BFFqFSg5.cjs");function f({children:e,hit:t,as:o,componentProps:n}){const u=p.useCallback(()=>{t&&"productId"in t&&s.s(c=>c.recordSearchClick("autocomplete",t))},[t]);return r.u(m.BaseElement,{onClick:u,as:o,componentProps:n,children:e})}function C({as:e,componentProps:t,onSearchInput:o,children:n}){const u={...t,onInput:a=>{o(a.target)}},c=e??"input";return e||(u.type="search"),r.u(c,{...u,children:n})}const d={...l.defaultBaseConfig};function g(e){return{pageType:"autocomplete",...d,...e}}function S({config:e,store:t,children:o}){const n=t??i.createStore();return l.useCheckClientScript(),r.u(i.ConfigContext,{value:g(e),children:r.u(i.StoreContext,{value:n,children:o})})}exports.AutocompleteElement=f;exports.AutocompletePageProvider=S;exports.SearchInput=C;
@@ -1,5 +1,5 @@
1
1
  /** @module preact/autocomplete */
2
- export { AutocompleteElement } from './src/components/Autocomplete/AutocompleteElement';
2
+ export { AutocompleteElement, type AutocompleteElementProps } from './src/components/AutocompleteElement';
3
3
  export { SearchInput } from './src/components/SearchInput';
4
4
  export type { PublicAutocompleteConfig as AutocompleteConfig } from './src/config/pages/autocomplete/config';
5
5
  export { AutocompletePageProvider } from './src/config/pages/autocomplete/provider';
@@ -1,49 +1,45 @@
1
- import { s as c } from "../index.es-B8mbAxS4.js";
2
- import { cloneElement as a } from "preact";
3
- import { u as i } from "../jsxRuntime.module-Bzuv3cXw.js";
4
- import { c as m, S as l, C as s } from "../configContext-GuZOIX3o.js";
5
- import { d as f, u as C } from "../baseConfig-Bafl02NY.js";
6
- function g(t) {
7
- return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
1
+ import { u as c } from "../jsxRuntime.module-Bzuv3cXw.js";
2
+ import { s as p } from "../index.es-B8mbAxS4.js";
3
+ import { useCallback as m } from "preact/hooks";
4
+ import { B as i } from "../BaseElement-Df1Kv7sB.js";
5
+ import { c as l, S as f, C as s } from "../configContext-GuZOIX3o.js";
6
+ import { d as C, u as d } from "../baseConfig-Bafl02NY.js";
7
+ function P({
8
+ children: t,
9
+ hit: e,
10
+ as: o,
11
+ componentProps: r
12
+ }) {
13
+ const n = m(() => {
14
+ e && "productId" in e && p((u) => u.recordSearchClick("autocomplete", e));
15
+ }, [e]);
16
+ return /* @__PURE__ */ c(i, { onClick: n, as: o, componentProps: r, children: t });
8
17
  }
9
- function x({ children: t, hit: e }) {
10
- var n;
11
- if (!g(t))
12
- throw new Error(
13
- "AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
14
- );
15
- const o = (n = t.props) == null ? void 0 : n.onClick;
16
- return a(t, {
17
- onClick: (r) => {
18
- e && c((p) => p.recordSearchClick("autocomplete", e)), typeof o == "function" && o(r);
19
- }
20
- });
21
- }
22
- function P({ as: t, componentProps: e, onSearchInput: o, children: n }) {
23
- const r = {
18
+ function h({ as: t, componentProps: e, onSearchInput: o, children: r }) {
19
+ const n = {
24
20
  ...e,
25
- onInput: (u) => {
26
- o(u.target);
21
+ onInput: (a) => {
22
+ o(a.target);
27
23
  }
28
- }, p = t ?? "input";
29
- return t || (r.type = "search"), /* @__PURE__ */ i(p, { ...r, children: n });
24
+ }, u = t ?? "input";
25
+ return t || (n.type = "search"), /* @__PURE__ */ c(u, { ...n, children: r });
30
26
  }
31
- const d = {
32
- ...f
27
+ const g = {
28
+ ...C
33
29
  };
34
30
  function S(t) {
35
31
  return {
36
32
  pageType: "autocomplete",
37
- ...d,
33
+ ...g,
38
34
  ...t
39
35
  };
40
36
  }
41
- function T({ config: t, store: e, children: o }) {
42
- const n = e ?? m();
43
- return C(), /* @__PURE__ */ i(s, { value: S(t), children: /* @__PURE__ */ i(l, { value: n, children: o }) });
37
+ function y({ config: t, store: e, children: o }) {
38
+ const r = e ?? l();
39
+ return d(), /* @__PURE__ */ c(s, { value: S(t), children: /* @__PURE__ */ c(f, { value: r, children: o }) });
44
40
  }
45
41
  export {
46
- x as AutocompleteElement,
47
- T as AutocompletePageProvider,
48
- P as SearchInput
42
+ P as AutocompleteElement,
43
+ y as AutocompletePageProvider,
44
+ h as SearchInput
49
45
  };
@@ -1,5 +1,5 @@
1
1
  /** @module preact */
2
- export { AutocompleteElement } from './src/components/Autocomplete/AutocompleteElement';
2
+ export { AutocompleteElement, type AutocompleteElementProps } from './src/components/AutocompleteElement';
3
3
  export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
4
4
  export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
5
5
  export { SearchInput } from './src/components/SearchInput';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../jsxRuntime.module-B3sGoTIU.cjs"),g=require("../index.es-DlUp67LT.cjs"),t=require("../configContext-BR7w4VlU.cjs"),d=require("preact/hooks"),a=require("../baseConfig-BFFqFSg5.cjs"),k="nosto:search:scrollPos";function h(){window.sessionStorage.setItem(k,window.scrollY.toString())}function p({as:o,children:n,hit:r,componentProps:e}){const{pageType:c}=t.useConfig(),s=c==="autocomplete"?void 0:c==="search"?"serp":c,l=d.useCallback(f=>{r&&s&&g.s(S=>S.recordSearchClick(s,r)),h(),e&&"onClick"in e&&typeof e.onClick=="function"&&e.onClick(f)},[r,e,s]),u={...e,onClick:l},C=o??"a";return i.u(C,{...u,children:n})}const v={...a.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function y(o={}){return{pageType:"search",...v,...o}}function m({config:o,store:n,children:r}){const e=n??t.createStore();return a.useCheckClientScript(),i.u(t.ConfigContext,{value:y(o),children:i.u(t.StoreContext,{value:e,children:r})})}exports.SearchPageProvider=m;exports.SerpElement=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../jsxRuntime.module-B3sGoTIU.cjs"),S=require("../index.es-DlUp67LT.cjs"),r=require("../configContext-BR7w4VlU.cjs"),g=require("preact/hooks"),f=require("../BaseElement-8qy-gSKp.cjs"),i=require("../baseConfig-BFFqFSg5.cjs"),C="nosto:search:scrollPos";function p(){window.sessionStorage.setItem(C,window.scrollY.toString())}function d({children:e,hit:o,componentProps:t,as:n}){const{pageType:s}=r.useConfig(),c=s==="autocomplete"?void 0:s==="search"?"serp":s,l=g.useCallback(()=>{o&&c&&S.s(u=>u.recordSearchClick(c,o)),p()},[o,c]);return a.u(f.BaseElement,{as:n,onClick:l,componentProps:t,children:e})}const m={...i.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function h(e={}){return{pageType:"search",...m,...e}}function P({config:e,store:o,children:t}){const n=o??r.createStore();return i.useCheckClientScript(),a.u(r.ConfigContext,{value:h(e),children:a.u(r.StoreContext,{value:n,children:t})})}exports.SearchPageProvider=P;exports.SerpElement=d;
@@ -1,41 +1,36 @@
1
1
  import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
2
- import { s as u } from "../index.es-B8mbAxS4.js";
3
- import { u as C, c as S, S as g, C as p } from "../configContext-GuZOIX3o.js";
4
- import { useCallback as m } from "preact/hooks";
5
- import { d, u as k } from "../baseConfig-Bafl02NY.js";
2
+ import { s as l } from "../index.es-B8mbAxS4.js";
3
+ import { u as f, c as p, S as u, C as m } from "../configContext-GuZOIX3o.js";
4
+ import { useCallback as S } from "preact/hooks";
5
+ import { B as C } from "../BaseElement-Df1Kv7sB.js";
6
+ import { d as g, u as d } from "../baseConfig-Bafl02NY.js";
6
7
  const h = "nosto:search:scrollPos";
7
- function v() {
8
+ function k() {
8
9
  window.sessionStorage.setItem(h, window.scrollY.toString());
9
10
  }
10
- function B({ as: o, children: t, hit: r, componentProps: e }) {
11
- const { pageType: a } = C(), c = a === "autocomplete" ? void 0 : a === "search" ? "serp" : a, s = m(
12
- (l) => {
13
- r && c && u((f) => f.recordSearchClick(c, r)), v(), e && "onClick" in e && typeof e.onClick == "function" && e.onClick(l);
14
- },
15
- [r, e, c]
16
- ), i = {
17
- ...e,
18
- onClick: s
19
- };
20
- return /* @__PURE__ */ n(o ?? "a", { ...i, children: t });
11
+ function b({ children: e, hit: o, componentProps: r, as: t }) {
12
+ const { pageType: s } = f(), a = s === "autocomplete" ? void 0 : s === "search" ? "serp" : s, c = S(() => {
13
+ o && a && l((i) => i.recordSearchClick(a, o)), k();
14
+ }, [o, a]);
15
+ return /* @__PURE__ */ n(C, { as: t, onClick: c, componentProps: r, children: e });
21
16
  }
22
- const w = {
23
- ...d,
17
+ const v = {
18
+ ...g,
24
19
  persistentSearchCache: !1,
25
20
  preservePageScroll: !1
26
21
  };
27
- function y(o = {}) {
22
+ function P(e = {}) {
28
23
  return {
29
24
  pageType: "search",
30
- ...w,
31
- ...o
25
+ ...v,
26
+ ...e
32
27
  };
33
28
  }
34
- function E({ config: o, store: t, children: r }) {
35
- const e = t ?? S();
36
- return k(), /* @__PURE__ */ n(p, { value: y(o), children: /* @__PURE__ */ n(g, { value: e, children: r }) });
29
+ function I({ config: e, store: o, children: r }) {
30
+ const t = o ?? p();
31
+ return d(), /* @__PURE__ */ n(m, { value: P(e), children: /* @__PURE__ */ n(u, { value: t, children: r }) });
37
32
  }
38
33
  export {
39
- E as SearchPageProvider,
40
- B as SerpElement
34
+ I as SearchPageProvider,
35
+ b as SerpElement
41
36
  };
@@ -0,0 +1,12 @@
1
+ import { AsComponent, BaseElementProps } from './BaseElement';
2
+ type AutocompleteHit = {
3
+ productId: string;
4
+ url?: string;
5
+ } | {
6
+ keyword: string;
7
+ };
8
+ export type AutocompleteElementProps<C extends AsComponent> = Omit<BaseElementProps<C>, "onClick"> & {
9
+ hit: AutocompleteHit;
10
+ };
11
+ export declare function AutocompleteElement<C extends AsComponent>({ children, hit, as, componentProps }: AutocompleteElementProps<C>): import("preact").JSX.Element;
12
+ export {};
@@ -0,0 +1,17 @@
1
+ import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
2
+ export type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
3
+ /**
4
+ * @group Components
5
+ */
6
+ export type BaseElementProps<C extends AsComponent> = {
7
+ onClick: () => void;
8
+ as?: C;
9
+ componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
10
+ children?: ComponentChildren;
11
+ };
12
+ /**
13
+ * Wrapper component that can be used to wrap any element in the search result list.
14
+ *
15
+ * @group Components
16
+ */
17
+ export declare function BaseElement<C extends AsComponent>({ onClick, as, children, componentProps }: BaseElementProps<C>): JSX.Element;
@@ -1,21 +1,16 @@
1
- import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
2
- type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
1
+ import { AsComponent, BaseElementProps } from './BaseElement';
3
2
  /**
4
3
  * @group Components
5
4
  */
6
- export type SerpElementProps<C extends AsComponent> = {
5
+ export type SerpElementProps<C extends AsComponent> = Omit<BaseElementProps<C>, "onClick"> & {
7
6
  hit: {
8
7
  productId: string;
9
8
  url?: string;
10
9
  };
11
- as?: C;
12
- componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
13
- children?: ComponentChildren;
14
10
  };
15
11
  /**
16
12
  * Wrapper component that can be used to wrap any element in the search result list.
17
13
  *
18
14
  * @group Components
19
15
  */
20
- export declare function SerpElement<C extends AsComponent>({ as, children, hit, componentProps }: SerpElementProps<C>): JSX.Element;
21
- export {};
16
+ export declare function SerpElement<C extends AsComponent>({ children, hit, componentProps, as }: SerpElementProps<C>): import("preact").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,36 +0,0 @@
1
- import { ComponentChildren } from 'preact';
2
- /**
3
- * @group Components
4
- */
5
- export type AutocompleteElementProps = {
6
- /**
7
- * Rendered content.
8
- */
9
- children: ComponentChildren;
10
- /**
11
- * Get product data for analytics
12
- */
13
- hit: {
14
- productId: string;
15
- url?: string;
16
- keyword?: string;
17
- };
18
- };
19
- /**
20
- * Wraps elements to interactive component that handles selection based on provided configuration.
21
- *
22
- * @example
23
- * ```jsx
24
- * // Render product
25
- * {products?.hits?.map(hit => <AutocompleteElement hit={hit}>
26
- * <a href={hit.url} class="nosto-product">
27
- * <img src={hit.imageUrl} alt={hit.name} />
28
- * <span>{hit.name}</span>
29
- * <span>{hit.price}</span>
30
- * </a>
31
- * </AutocompleteElement>)}
32
- * ```
33
- *
34
- * @group Components
35
- */
36
- export declare function AutocompleteElement({ children, hit }: AutocompleteElementProps): import('preact').VNode<any>;
@@ -1,5 +0,0 @@
1
- import { ComponentChildren, JSX } from 'preact';
2
- /**
3
- * Check if the provided children is a valid HTML element (div/anchor/etc).
4
- */
5
- export declare function isValidHTMLElement(children: ComponentChildren): children is JSX.Element;