@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.
- package/dist/BaseElement-8qy-gSKp.cjs +1 -0
- package/dist/BaseElement-Df1Kv7sB.js +17 -0
- package/dist/preact/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete.d.ts +1 -1
- package/dist/preact/autocomplete.es.js +31 -35
- package/dist/preact/preact.d.ts +1 -1
- package/dist/preact/serp.cjs.js +1 -1
- package/dist/preact/serp.es.js +21 -26
- package/dist/preact/src/components/AutocompleteElement.d.ts +12 -0
- package/dist/preact/src/components/BaseElement.d.ts +17 -0
- package/dist/preact/src/components/SerpElement.d.ts +3 -8
- package/package.json +1 -1
- package/dist/preact/src/components/Autocomplete/AutocompleteElement.d.ts +0 -36
- package/dist/preact/src/components/Autocomplete/utils.d.ts +0 -5
|
@@ -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"),
|
|
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/
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
10
|
-
|
|
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: (
|
|
26
|
-
o(
|
|
21
|
+
onInput: (a) => {
|
|
22
|
+
o(a.target);
|
|
27
23
|
}
|
|
28
|
-
},
|
|
29
|
-
return t || (
|
|
24
|
+
}, u = t ?? "input";
|
|
25
|
+
return t || (n.type = "search"), /* @__PURE__ */ c(u, { ...n, children: r });
|
|
30
26
|
}
|
|
31
|
-
const
|
|
32
|
-
...
|
|
27
|
+
const g = {
|
|
28
|
+
...C
|
|
33
29
|
};
|
|
34
30
|
function S(t) {
|
|
35
31
|
return {
|
|
36
32
|
pageType: "autocomplete",
|
|
37
|
-
...
|
|
33
|
+
...g,
|
|
38
34
|
...t
|
|
39
35
|
};
|
|
40
36
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
43
|
-
return
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
P as AutocompleteElement,
|
|
43
|
+
y as AutocompletePageProvider,
|
|
44
|
+
h as SearchInput
|
|
49
45
|
};
|
package/dist/preact/preact.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @module preact */
|
|
2
|
-
export { AutocompleteElement } from './src/components/
|
|
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';
|
package/dist/preact/serp.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
package/dist/preact/serp.es.js
CHANGED
|
@@ -1,41 +1,36 @@
|
|
|
1
1
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { s as
|
|
3
|
-
import { u as
|
|
4
|
-
import { useCallback as
|
|
5
|
-
import {
|
|
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
|
|
8
|
+
function k() {
|
|
8
9
|
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
const { pageType:
|
|
12
|
-
(
|
|
13
|
-
|
|
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
|
|
23
|
-
...
|
|
17
|
+
const v = {
|
|
18
|
+
...g,
|
|
24
19
|
persistentSearchCache: !1,
|
|
25
20
|
preservePageScroll: !1
|
|
26
21
|
};
|
|
27
|
-
function
|
|
22
|
+
function P(e = {}) {
|
|
28
23
|
return {
|
|
29
24
|
pageType: "search",
|
|
30
|
-
...
|
|
31
|
-
...
|
|
25
|
+
...v,
|
|
26
|
+
...e
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
return
|
|
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
|
-
|
|
40
|
-
|
|
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 {
|
|
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>({
|
|
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,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>;
|