@nosto/search-js 2.12.0 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../index.es-DlUp67LT.cjs"),a=require("preact"),u=require("../renderHeadless-xhkLegO4.cjs"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),r=require("../configContext-BR7w4VlU.cjs"),c=require("../baseConfig-BFFqFSg5.cjs");function f(e){return e!==null&&typeof e=="object"&&"props"in e&&typeof e.type=="string"}function m({children:e,hit:n}){var o;if(!f(e))throw new Error("AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported.");const t=(o=e.props)==null?void 0:o.onClick;return a.cloneElement(e,{onClick:p=>{n&&l.s(s=>s.recordSearchClick("autocomplete",n)),typeof t=="function"&&t(p)}})}function g({children:e,onSearchInput:n}){return u.renderHeadless({children:e,updateElement:t=>(!u.isHTMLInput(t)||t.props.type!=="search"||(t.props={...t.props,onInput:o=>{o.target instanceof HTMLInputElement&&n(o.target)}}),t)})}const C={...c.defaultBaseConfig};function d(e){return{pageType:"autocomplete",...C,...e}}function S({config:e,store:n,children:t}){const o=n??r.createStore();return c.useCheckClientScript(),i.u(r.ConfigContext,{value:d(e),children:i.u(r.StoreContext,{value:o,children:t})})}exports.AutocompleteElement=m;exports.AutocompletePageProvider=S;exports.SearchInput=g;
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,52 +1,49 @@
1
- import { s as u } from "../index.es-B8mbAxS4.js";
1
+ import { s as c } from "../index.es-B8mbAxS4.js";
2
2
  import { cloneElement as a } from "preact";
3
- import { r as s, i as c } from "../renderHeadless-BteGML1G.js";
4
- import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
5
- import { c as l, S as m, C as f } from "../configContext-GuZOIX3o.js";
6
- import { d as C, u as g } from "../baseConfig-Bafl02NY.js";
7
- function E(t) {
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) {
8
7
  return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
9
8
  }
10
- function I({ children: t, hit: r }) {
11
- var o;
12
- if (!E(t))
9
+ function x({ children: t, hit: e }) {
10
+ var n;
11
+ if (!g(t))
13
12
  throw new Error(
14
13
  "AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
15
14
  );
16
- const e = (o = t.props) == null ? void 0 : o.onClick;
15
+ const o = (n = t.props) == null ? void 0 : n.onClick;
17
16
  return a(t, {
18
- onClick: (p) => {
19
- r && u((i) => i.recordSearchClick("autocomplete", r)), typeof e == "function" && e(p);
17
+ onClick: (r) => {
18
+ e && c((p) => p.recordSearchClick("autocomplete", e)), typeof o == "function" && o(r);
20
19
  }
21
20
  });
22
21
  }
23
- function L({ children: t, onSearchInput: r }) {
24
- return s({
25
- children: t,
26
- updateElement: (e) => (!c(e) || e.props.type !== "search" || (e.props = {
27
- ...e.props,
28
- onInput: (o) => {
29
- o.target instanceof HTMLInputElement && r(o.target);
30
- }
31
- }), e)
32
- });
22
+ function P({ as: t, componentProps: e, onSearchInput: o, children: n }) {
23
+ const r = {
24
+ ...e,
25
+ onInput: (u) => {
26
+ o(u.target);
27
+ }
28
+ }, p = t ?? "input";
29
+ return t || (r.type = "search"), /* @__PURE__ */ i(p, { ...r, children: n });
33
30
  }
34
- const S = {
35
- ...C
31
+ const d = {
32
+ ...f
36
33
  };
37
- function k(t) {
34
+ function S(t) {
38
35
  return {
39
36
  pageType: "autocomplete",
40
- ...S,
37
+ ...d,
41
38
  ...t
42
39
  };
43
40
  }
44
- function M({ config: t, store: r, children: e }) {
45
- const o = r ?? l();
46
- return g(), /* @__PURE__ */ n(f, { value: k(t), children: /* @__PURE__ */ n(m, { value: o, children: e }) });
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 }) });
47
44
  }
48
45
  export {
49
- I as AutocompleteElement,
50
- M as AutocompletePageProvider,
51
- L as SearchInput
46
+ x as AutocompleteElement,
47
+ T as AutocompletePageProvider,
48
+ P as SearchInput
52
49
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs"),s=require("../configContext-BR7w4VlU.cjs"),S=require("../renderHeadless-xhkLegO4.cjs"),a=require("../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../baseConfig-BFFqFSg5.cjs"),g="nosto:search:scrollPos";function d(){window.sessionStorage.setItem(g,window.scrollY.toString())}function C({children:e,hit:t,onClick:o}){const{pageType:r}=s.useConfig(),c=r==="autocomplete"?void 0:r==="search"?"serp":r;return S.renderHeadless({children:e,updateElement:(n,u)=>(u.depth>0||(n.props={...n.props,onClick:l=>{t&&c&&p.s(f=>f.recordSearchClick(c,t)),d(),typeof o=="function"&&o(l)}}),n)})}const h={...i.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function m(e={}){return{pageType:"search",...h,...e}}function P({config:e,store:t,children:o}){const r=t??s.createStore();return i.useCheckClientScript(),a.u(s.ConfigContext,{value:m(e),children:a.u(s.StoreContext,{value:r,children:o})})}exports.SearchPageProvider=P;exports.SerpElement=C;
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,41 +1,41 @@
1
- import { s as l } from "../index.es-B8mbAxS4.js";
2
- import { u as f, c as u, S, C as m } from "../configContext-GuZOIX3o.js";
3
- import { r as g } from "../renderHeadless-BteGML1G.js";
4
1
  import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
5
- import { d as C, u as d } from "../baseConfig-Bafl02NY.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";
6
6
  const h = "nosto:search:scrollPos";
7
- function P() {
7
+ function v() {
8
8
  window.sessionStorage.setItem(h, window.scrollY.toString());
9
9
  }
10
- function B({ children: e, hit: o, onClick: t }) {
11
- const { pageType: r } = f(), a = r === "autocomplete" ? void 0 : r === "search" ? "serp" : r;
12
- return g({
13
- children: e,
14
- updateElement: (s, c) => (c.depth > 0 || (s.props = {
15
- ...s.props,
16
- onClick: (i) => {
17
- o && a && l((p) => p.recordSearchClick(a, o)), P(), typeof t == "function" && t(i);
18
- }
19
- }), s)
20
- });
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 });
21
21
  }
22
- const k = {
23
- ...C,
22
+ const w = {
23
+ ...d,
24
24
  persistentSearchCache: !1,
25
25
  preservePageScroll: !1
26
26
  };
27
- function w(e = {}) {
27
+ function y(o = {}) {
28
28
  return {
29
29
  pageType: "search",
30
- ...k,
31
- ...e
30
+ ...w,
31
+ ...o
32
32
  };
33
33
  }
34
- function H({ config: e, store: o, children: t }) {
35
- const r = o ?? u();
36
- return d(), /* @__PURE__ */ n(m, { value: w(e), children: /* @__PURE__ */ n(S, { value: r, children: t }) });
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 }) });
37
37
  }
38
38
  export {
39
- H as SearchPageProvider,
39
+ E as SearchPageProvider,
40
40
  B as SerpElement
41
41
  };
@@ -1,7 +1,10 @@
1
- import { ComponentChildren } from 'preact';
2
- type Props = {
3
- children: ComponentChildren;
1
+ import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
2
+ type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
3
+ type Props<C extends AsComponent> = {
4
+ as?: C;
4
5
  onSearchInput: (target: HTMLInputElement) => void;
6
+ children?: ComponentChildren;
7
+ componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
5
8
  };
6
- export declare function SearchInput({ children, onSearchInput }: Props): ComponentChildren;
9
+ export declare function SearchInput<C extends AsComponent>({ as, componentProps, onSearchInput, children }: Props<C>): JSX.Element;
7
10
  export {};
@@ -1,18 +1,21 @@
1
- import { ComponentChildren } from 'preact';
1
+ import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
2
+ type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
2
3
  /**
3
4
  * @group Components
4
5
  */
5
- export type SerpElementProps = {
6
- children: ComponentChildren;
6
+ export type SerpElementProps<C extends AsComponent> = {
7
7
  hit: {
8
8
  productId: string;
9
9
  url?: string;
10
10
  };
11
- onClick?: (event: Event) => void;
11
+ as?: C;
12
+ componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
13
+ children?: ComponentChildren;
12
14
  };
13
15
  /**
14
16
  * Wrapper component that can be used to wrap any element in the search result list.
15
17
  *
16
18
  * @group Components
17
19
  */
18
- export declare function SerpElement({ children, hit, onClick }: SerpElementProps): ComponentChildren;
20
+ export declare function SerpElement<C extends AsComponent>({ as, children, hit, componentProps }: SerpElementProps<C>): JSX.Element;
21
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "2.12.0",
3
+ "version": "2.12.1",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,18 +0,0 @@
1
- import { ComponentChildren, VNode } from 'preact';
2
- type Props = {
3
- children: ComponentChildren;
4
- /**
5
- * Update the element with custom logic. Each vnode (valid JSX element) will be passed to this function recursively.
6
- * You may either mutate the existing node, or create a new one.
7
- *
8
- * @param vnode Current target node
9
- * @returns {VNode} if the vnode should be updated
10
- * @returns {null} if the vnode should be removed
11
- */
12
- updateElement: <P extends object>(vnode: VNode<P>, context: Context) => VNode<P> | null;
13
- };
14
- type Context = {
15
- depth: number;
16
- };
17
- export declare function renderHeadless(props: Props, ctx?: Context): ComponentChildren;
18
- export {};
@@ -1,5 +0,0 @@
1
- import { VNode } from 'preact';
2
- import { JSX } from 'preact/jsx-runtime';
3
- export type UnknownVnode = VNode<any>;
4
- export declare function isHTMLInput(vnode: UnknownVnode): vnode is VNode<JSX.IntrinsicElements["input"]>;
5
- export declare function isVNode(child: unknown): child is VNode;
@@ -1,23 +0,0 @@
1
- import { toChildArray as o } from "preact";
2
- function d(e) {
3
- return e.type === "input";
4
- }
5
- function u(e) {
6
- return !!e && typeof e == "object" && "type" in e && "props" in e;
7
- }
8
- function i(e, t = { depth: 0 }) {
9
- const { children: p } = e;
10
- return o(p).map((r) => {
11
- if (!u(r))
12
- return r;
13
- const n = e.updateElement(r, t);
14
- return n === null ? null : (n.props = {
15
- ...n.props,
16
- children: i({ ...e, children: n.props.children }, { depth: t.depth + 1 })
17
- }, n);
18
- });
19
- }
20
- export {
21
- d as i,
22
- i as r
23
- };
@@ -1 +0,0 @@
1
- "use strict";const s=require("preact");function i(e){return e.type==="input"}function o(e){return!!e&&typeof e=="object"&&"type"in e&&"props"in e}function u(e,t={depth:0}){const{children:p}=e;return s.toChildArray(p).map(r=>{if(!o(r))return r;const n=e.updateElement(r,t);return n===null?null:(n.props={...n.props,children:u({...e,children:n.props.children},{depth:t.depth+1})},n)})}exports.isHTMLInput=i;exports.renderHeadless=u;