@nosto/search-js 1.8.0 → 2.1.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/README.md +50 -8
- package/dist/InfiniteScrollWithObserver-BoKdnFuB.cjs +1 -0
- package/dist/InfiniteScrollWithObserver-CkdVKocm.js +39 -0
- package/dist/baseConfig-C_tlTx1w.js +20 -0
- package/dist/baseConfig-DEAGSRSp.cjs +1 -0
- package/dist/core/core.d.ts +1 -1
- package/dist/core/src/search.d.ts +2 -2
- package/dist/core/src/searchWithRetries.d.ts +2 -2
- package/dist/core/src/types.d.ts +2 -2
- package/dist/jsxRuntime.module-B3sGoTIU.cjs +1 -0
- package/dist/jsxRuntime.module-Bzuv3cXw.js +13 -0
- package/dist/preact/autocomplete.cjs.js +1 -0
- package/dist/preact/autocomplete.d.ts +5 -0
- package/dist/preact/autocomplete.es.js +52 -0
- package/dist/preact/category.cjs.js +1 -0
- package/dist/preact/category.d.ts +3 -0
- package/dist/preact/category.es.js +22 -0
- package/dist/preact/common.cjs.js +1 -0
- package/dist/preact/common.d.ts +6 -0
- package/dist/preact/common.es.js +26 -0
- package/dist/preact/hooks.cjs.js +1 -0
- package/dist/preact/hooks.d.ts +16 -0
- package/dist/preact/hooks.es.js +356 -0
- package/dist/preact/legacy.cjs.js +1 -0
- package/dist/preact/legacy.d.ts +4 -0
- package/dist/preact/legacy.es.js +7 -0
- package/dist/preact/serp.cjs.js +1 -0
- package/dist/preact/serp.d.ts +4 -0
- package/dist/preact/serp.es.js +41 -0
- package/dist/preact/src/actions/newSearch.d.ts +2 -2
- package/dist/preact/src/actions/updateSearch.d.ts +2 -2
- package/dist/preact/src/config/base/baseConfig.d.ts +2 -2
- package/dist/preact/src/config/pages/autocomplete/config.d.ts +1 -1
- package/dist/preact/src/config/pages/category/config.d.ts +1 -1
- package/dist/preact/src/config/pages/serp/config.d.ts +1 -1
- package/dist/renderHeadless-BteGML1G.js +23 -0
- package/dist/renderHeadless-xhkLegO4.cjs +1 -0
- package/dist/storeContext-12dN1l9r.cjs +1 -0
- package/dist/storeContext-CBqmmTUC.js +99 -0
- package/dist/useLoadMore-BBrbOkyq.cjs +1 -0
- package/dist/useLoadMore-DnvHCsYl.js +281 -0
- package/dist/utils/utils.cjs.js +1 -1
- package/dist/utils/utils.es.js +1 -1
- package/package.json +42 -20
- package/dist/InfiniteScrollWithObserver-DbErxedF.cjs +0 -1
- package/dist/InfiniteScrollWithObserver-kuSGeBWr.js +0 -418
- package/dist/preact/preact.cjs.js +0 -1
- package/dist/preact/preact.es.js +0 -501
- package/dist/preact-legacy/preact-legacy.cjs.js +0 -1
- package/dist/preact-legacy/preact-legacy.d.ts +0 -4
- package/dist/preact-legacy/preact-legacy.es.js +0 -6
package/README.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
# Search JS
|
|
2
2
|
|
|
3
|
-
Search JS is
|
|
4
|
-
* Nosto currency formatting
|
|
5
|
-
* Nosto product thumbnails
|
|
6
|
-
* Retry logic
|
|
3
|
+
Nosto Search JS is an implementation of Nosto Search. In addition to the base search functionality, it also provides the following features:
|
|
7
4
|
|
|
5
|
+
* **Currency formatting**: Format prices based on Nosto settings.
|
|
6
|
+
* **Product thumbnails**: Thumbnail resizing.
|
|
7
|
+
* **Retry logic**: Retry failed search queries automatically.
|
|
8
|
+
* **Preact components**: Build modern search interfaces.
|
|
9
|
+
* **Autocomplete**: Fast and responsive autocomplete tools.
|
|
10
|
+
* **Category search**: Display and filter by categories.
|
|
11
|
+
* **SERPs**: Build search result pages with sorting and pagination.
|
|
12
|
+
* **Utilities**: Helpers for common tasks like array or object merging and equality checks.
|
|
13
|
+
* **Infinite scroll**: Loads more components upon scrolling to the end of results.
|
|
14
|
+
|
|
8
15
|
## Installation
|
|
9
|
-
|
|
10
16
|
To install the package, use your preferred package manager:
|
|
11
17
|
|
|
12
18
|
```bash
|
|
@@ -22,7 +28,43 @@ Read [Nosto Techdocs](https://docs.nosto.com/techdocs/apis/frontend/oss/search-j
|
|
|
22
28
|
[Library TypeDoc page](https://nosto.github.io/search-js/) includes detailed library helpers documentation and examples.
|
|
23
29
|
|
|
24
30
|
## Packages
|
|
25
|
-
### `preact-legacy`
|
|
26
|
-
The `preact-legacy` package is designed to provide backward compatibility for existing Search Template implementations. It serves as a bridge to support legacy functionality.
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
### `core`
|
|
33
|
+
The `core` package provides the foundational functionality for interacting with Nosto Search. It includes utilities for managing search queries, applying decorators, and handling search results.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### `currencies`
|
|
38
|
+
The `currencies` package provides utilities for formatting monetary values and decorating search results with price information.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### `preact` packages
|
|
43
|
+
|
|
44
|
+
#### `preact/autocomplete`
|
|
45
|
+
The `preact/autocomplete` package helps you add autocomplete functionality to your search interface.
|
|
46
|
+
|
|
47
|
+
#### `preact/category`
|
|
48
|
+
The `preact/category` package provides tools to show and interact with category-based search results.
|
|
49
|
+
|
|
50
|
+
#### `preact/common`
|
|
51
|
+
The `preact/common` package includes shared components that are used across other `preact` packages.
|
|
52
|
+
|
|
53
|
+
#### `preact/hooks`
|
|
54
|
+
The `preact/hooks` package offers hooks to manage state and actions in your search app.
|
|
55
|
+
|
|
56
|
+
#### `preact/serp`
|
|
57
|
+
The `preact/serp` package provides tools to create Search Engine Results Pages (SERPs) with features like pagination, sorting, and displaying results.
|
|
58
|
+
|
|
59
|
+
#### `preact/legacy`
|
|
60
|
+
The `preact/legacy` package is designed to provide backward compatibility for existing Search Template implementations.
|
|
61
|
+
|
|
62
|
+
> The components included in this package are intended solely for compatibility purposes. They are not recommended for use in new development or as active components in modern applications.
|
|
63
|
+
|
|
64
|
+
### `thumbnails`
|
|
65
|
+
The `thumbnails` package helps you resize thumbnails. It supports different formats, including Shopify and Nosto-specific ones.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### `utils`
|
|
70
|
+
The `utils` package includes handy tools for common tasks like array or object merging, checking equality, and generating unique values.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const d=require("./jsxRuntime.module-B3sGoTIU.cjs"),f=require("./useLoadMore-BBrbOkyq.cjs"),l=require("preact/hooks"),b=require("preact");function p(t,...o){return o.reduce((r,n)=>(r[n]=t[n],r),{})}function v(t,o){var c,e,s;const r=((c=o.products)==null?void 0:c.total)??0,n=((e=t.products)==null?void 0:e.from)??0,i=((s=t.products)==null?void 0:s.size)??0;return r>0&&r>n+i}function h(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function O({children:t,pageSize:o}){const r=l.useRef(null),{query:n,response:i}=f.useNostoAppState(e=>p(e,"query","response")),{loadMore:c}=f.useLoadMore(o);return l.useEffect(()=>{let e,s;return v(n,i)&&(e=r.current,s=new IntersectionObserver(a=>{const u=a[0];u!=null&&u.isIntersecting&&c()}),e&&s.observe(e)),()=>{e&&s.unobserve(e)}},[i]),d.u(b.Fragment,{children:[t,d.u("div",{ref:r,style:{height:"1px"}})]})}exports.InfiniteScrollWithObserver=O;exports.hasMoreResults=v;exports.intersectionObserverSupported=h;exports.pick=p;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
+
import { a, u as d } from "./useLoadMore-DnvHCsYl.js";
|
|
3
|
+
import { useRef as l, useEffect as m } from "preact/hooks";
|
|
4
|
+
import { Fragment as v } from "preact";
|
|
5
|
+
function b(t, ...s) {
|
|
6
|
+
return s.reduce(
|
|
7
|
+
(r, o) => (r[o] = t[o], r),
|
|
8
|
+
{}
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function w(t, s) {
|
|
12
|
+
var c, e, n;
|
|
13
|
+
const r = ((c = s.products) == null ? void 0 : c.total) ?? 0, o = ((e = t.products) == null ? void 0 : e.from) ?? 0, i = ((n = t.products) == null ? void 0 : n.size) ?? 0;
|
|
14
|
+
return r > 0 && r > o + i;
|
|
15
|
+
}
|
|
16
|
+
function R() {
|
|
17
|
+
return !!(window.IntersectionObserver && window.IntersectionObserverEntry && "intersectionRatio" in window.IntersectionObserverEntry.prototype);
|
|
18
|
+
}
|
|
19
|
+
function E({ children: t, pageSize: s }) {
|
|
20
|
+
const r = l(null), { query: o, response: i } = a((e) => b(e, "query", "response")), { loadMore: c } = d(s);
|
|
21
|
+
return m(() => {
|
|
22
|
+
let e, n;
|
|
23
|
+
return w(o, i) && (e = r.current, n = new IntersectionObserver((p) => {
|
|
24
|
+
const u = p[0];
|
|
25
|
+
u != null && u.isIntersecting && c();
|
|
26
|
+
}), e && n.observe(e)), () => {
|
|
27
|
+
e && n.unobserve(e);
|
|
28
|
+
};
|
|
29
|
+
}, [i]), /* @__PURE__ */ f(v, { children: [
|
|
30
|
+
t,
|
|
31
|
+
/* @__PURE__ */ f("div", { ref: r, style: { height: "1px" } })
|
|
32
|
+
] });
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
E as I,
|
|
36
|
+
w as h,
|
|
37
|
+
R as i,
|
|
38
|
+
b as p
|
|
39
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { s as e } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
import { useEffect as t } from "preact/hooks";
|
|
3
|
+
function r() {
|
|
4
|
+
t(() => {
|
|
5
|
+
const o = window.setTimeout(() => {
|
|
6
|
+
console.error("Nosto client script has not loaded after 3 seconds.");
|
|
7
|
+
}, 3e3);
|
|
8
|
+
e(() => {
|
|
9
|
+
window.clearTimeout(o);
|
|
10
|
+
});
|
|
11
|
+
}, []);
|
|
12
|
+
}
|
|
13
|
+
const n = {
|
|
14
|
+
defaultCurrency: "EUR",
|
|
15
|
+
queryModifications: (o) => o
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
n as d,
|
|
19
|
+
r as u
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t=require("./index.es-DlUp67LT.cjs"),o=require("preact/hooks");function s(){o.useEffect(()=>{const e=window.setTimeout(()=>{console.error("Nosto client script has not loaded after 3 seconds.")},3e3);t.s(()=>{window.clearTimeout(e)})},[])}const i={defaultCurrency:"EUR",queryModifications:e=>e};exports.defaultBaseConfig=i;exports.useCheckClientScript=s;
|
package/dist/core/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** @module ./ */
|
|
2
2
|
export { addToCart, type SearchHitWithSku } from './src/addToCart';
|
|
3
3
|
export { search } from './src/search';
|
|
4
|
-
export type { DecoratedProduct, DecoratedResult, HitDecorator,
|
|
4
|
+
export type { DecoratedProduct, DecoratedResult, HitDecorator, SearchOptions, ToIntersection } from './src/types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
2
|
-
import { HitDecorator,
|
|
2
|
+
import { HitDecorator, SearchOptions } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Performs a search operation using the provided query and options.
|
|
5
5
|
*
|
|
@@ -7,7 +7,7 @@ import { HitDecorator, Options } from './types';
|
|
|
7
7
|
* @param options - An object containing optional parameters for the search.
|
|
8
8
|
* @returns A promise that resolves to the search result.
|
|
9
9
|
*/
|
|
10
|
-
export declare function search<HD extends readonly HitDecorator[]>(query: SearchQuery, options?:
|
|
10
|
+
export declare function search<HD extends readonly HitDecorator[]>(query: SearchQuery, options?: SearchOptions<HD>): Promise<{
|
|
11
11
|
products: {
|
|
12
12
|
hits: import('./types').ToIntersection<ReturnType<HD[number]>>[];
|
|
13
13
|
categoryId?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { API, SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
-
import {
|
|
3
|
-
export declare function searchWithRetries(api: API, query: SearchQuery, options:
|
|
2
|
+
import { SearchOptions } from './types';
|
|
3
|
+
export declare function searchWithRetries(api: API, query: SearchQuery, options: SearchOptions<[]>): Promise<SearchResult>;
|
|
4
4
|
/**
|
|
5
5
|
* Should the error trigger a search retry
|
|
6
6
|
*/
|
package/dist/core/src/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SearchOptions, SearchProduct, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
-
export type
|
|
1
|
+
import { SearchOptions as BaseOptions, SearchProduct, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
+
export type SearchOptions<HD extends readonly HitDecorator[] = readonly HitDecorator[]> = BaseOptions & {
|
|
3
3
|
/**
|
|
4
4
|
* Hit decorators to apply to the search results.
|
|
5
5
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("preact");var s=0;function p(e,_,f,t,l,c){_||(_={});var n,o,r=_;if("ref"in r)for(o in r={},_)o=="ref"?n=_[o]:r[o]=_[o];var u={type:e,props:r,key:f,ref:n,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--s,__i:-1,__u:0,__source:l,__self:c};if(typeof e=="function"&&(n=e.defaultProps))for(o in n)r[o]===void 0&&(r[o]=n[o]);return i.options.vnode&&i.options.vnode(u),u}exports.u=p;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { options as i } from "preact";
|
|
2
|
+
var v = 0;
|
|
3
|
+
function t(f, _, u, c, l, p) {
|
|
4
|
+
_ || (_ = {});
|
|
5
|
+
var n, o, r = _;
|
|
6
|
+
if ("ref" in r) for (o in r = {}, _) o == "ref" ? n = _[o] : r[o] = _[o];
|
|
7
|
+
var e = { type: f, props: r, key: u, ref: n, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --v, __i: -1, __u: 0, __source: l, __self: p };
|
|
8
|
+
if (typeof f == "function" && (n = f.defaultProps)) for (o in n) r[o] === void 0 && (r[o] = n[o]);
|
|
9
|
+
return i.vnode && i.vnode(e), e;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
t as u
|
|
13
|
+
};
|
|
@@ -0,0 +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("../storeContext-12dN1l9r.cjs"),c=require("../baseConfig-DEAGSRSp.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;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** @module preact/autocomplete */
|
|
2
|
+
export { AutocompleteElement } from './src/components/Autocomplete/AutocompleteElement';
|
|
3
|
+
export { SearchInput } from './src/components/SearchInput';
|
|
4
|
+
export type { PublicAutocompleteConfig as AutocompleteConfig } from './src/config/pages/autocomplete/config';
|
|
5
|
+
export { AutocompletePageProvider } from './src/config/pages/autocomplete/provider';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { s as u } from "../index.es-B8mbAxS4.js";
|
|
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 "../storeContext-CBqmmTUC.js";
|
|
6
|
+
import { d as C, u as g } from "../baseConfig-C_tlTx1w.js";
|
|
7
|
+
function E(t) {
|
|
8
|
+
return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
|
|
9
|
+
}
|
|
10
|
+
function I({ children: t, hit: r }) {
|
|
11
|
+
var o;
|
|
12
|
+
if (!E(t))
|
|
13
|
+
throw new Error(
|
|
14
|
+
"AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
|
|
15
|
+
);
|
|
16
|
+
const e = (o = t.props) == null ? void 0 : o.onClick;
|
|
17
|
+
return a(t, {
|
|
18
|
+
onClick: (p) => {
|
|
19
|
+
r && u((i) => i.recordSearchClick("autocomplete", r)), typeof e == "function" && e(p);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
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
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const S = {
|
|
35
|
+
...C
|
|
36
|
+
};
|
|
37
|
+
function k(t) {
|
|
38
|
+
return {
|
|
39
|
+
pageType: "autocomplete",
|
|
40
|
+
...S,
|
|
41
|
+
...t
|
|
42
|
+
};
|
|
43
|
+
}
|
|
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 }) });
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
I as AutocompleteElement,
|
|
50
|
+
M as AutocompletePageProvider,
|
|
51
|
+
L as SearchInput
|
|
52
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../storeContext-12dN1l9r.cjs"),o=require("../baseConfig-DEAGSRSp.cjs"),u={...o.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function c(e){return{pageType:"category",...u,...e}}function s({config:e,store:a,children:n}){const i=a??t.createStore();return o.useCheckClientScript(),r.u(t.ConfigContext,{value:c(e),children:r.u(t.StoreContext,{value:i,children:n})})}exports.CategoryPageProvider=s;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { u as t } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
+
import { c as n, S as c, C as i } from "../storeContext-CBqmmTUC.js";
|
|
3
|
+
import { d as s, u as f } from "../baseConfig-C_tlTx1w.js";
|
|
4
|
+
const C = {
|
|
5
|
+
...s,
|
|
6
|
+
persistentSearchCache: !1,
|
|
7
|
+
preservePageScroll: !1
|
|
8
|
+
};
|
|
9
|
+
function u(e) {
|
|
10
|
+
return {
|
|
11
|
+
pageType: "category",
|
|
12
|
+
...C,
|
|
13
|
+
...e
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function m({ config: e, store: r, children: o }) {
|
|
17
|
+
const a = r ?? n();
|
|
18
|
+
return f(), /* @__PURE__ */ t(i, { value: u(e), children: /* @__PURE__ */ t(c, { value: a, children: o }) });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
m as CategoryPageProvider
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../utils/utils.cjs.js"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../useLoadMore-BBrbOkyq.cjs"),r=require("../InfiniteScrollWithObserver-BoKdnFuB.cjs"),p=require("preact"),o=require("../storeContext-12dN1l9r.cjs");function b({pageSize:n}){const{loadMore:e}=s.useLoadMore(n);return t.u("button",{onClick:e,children:"More results"})}function u({children:n,loadMoreComponent:e,pageSize:i}){const{loading:c,query:l,response:a}=s.useNostoAppState(S=>r.pick(S,"loading","query","response")),d=!c&&r.hasMoreResults(l,a);return t.u(p.Fragment,{children:[n,d&&(e?t.u(e,{pageSize:i}):t.u(b,{pageSize:i}))]})}const q=!f.isBot()&&r.intersectionObserverSupported()?r.InfiniteScrollWithObserver:u;exports.StoreContext=o.StoreContext;exports.createExtendableStore=o.createExtendableStore;exports.createStore=o.createStore;exports.defaultState=o.defaultState;exports.InfiniteScroll=q;exports.InfiniteScrollWithLink=u;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** @module preact/common */
|
|
2
|
+
export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
|
|
3
|
+
export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
|
|
4
|
+
export { createStore, defaultState, type State, type Store } from './src/store';
|
|
5
|
+
export { StoreContext } from './src/storeContext';
|
|
6
|
+
export { createExtendableStore, type ExtendedStore } from './src/storeExtensions';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isBot as l } from "../utils/utils.es.js";
|
|
2
|
+
import { u as e } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
+
import { u as p, a as u } from "../useLoadMore-DnvHCsYl.js";
|
|
4
|
+
import { h as d, p as m, i as f, I as S } from "../InfiniteScrollWithObserver-CkdVKocm.js";
|
|
5
|
+
import { Fragment as h } from "preact";
|
|
6
|
+
import { S as y, a as O, c as W, d as A } from "../storeContext-CBqmmTUC.js";
|
|
7
|
+
function M({ pageSize: r }) {
|
|
8
|
+
const { loadMore: o } = p(r);
|
|
9
|
+
return /* @__PURE__ */ e("button", { onClick: o, children: "More results" });
|
|
10
|
+
}
|
|
11
|
+
function b({ children: r, loadMoreComponent: o, pageSize: t }) {
|
|
12
|
+
const { loading: n, query: s, response: i } = u((c) => m(c, "loading", "query", "response")), a = !n && d(s, i);
|
|
13
|
+
return /* @__PURE__ */ e(h, { children: [
|
|
14
|
+
r,
|
|
15
|
+
a && (o ? /* @__PURE__ */ e(o, { pageSize: t }) : /* @__PURE__ */ e(M, { pageSize: t }))
|
|
16
|
+
] });
|
|
17
|
+
}
|
|
18
|
+
const g = !l() && f() ? S : b;
|
|
19
|
+
export {
|
|
20
|
+
g as InfiniteScroll,
|
|
21
|
+
b as InfiniteScrollWithLink,
|
|
22
|
+
y as StoreContext,
|
|
23
|
+
O as createExtendableStore,
|
|
24
|
+
W as createStore,
|
|
25
|
+
A as defaultState
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-BBrbOkyq.cjs"),C=require("../storeContext-12dN1l9r.cjs"),S=require("preact/hooks"),P=require("../index.es-DlUp67LT.cjs");function z(e){const o=m.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&C.isPlainObject(e)?e:o}function q(e){var i;const o=((i=e.data)==null?void 0:i.filter(a=>a.selected).length)??0,[t,n]=S.useState(o>0),{toggleProductFilter:u}=m.useActions();return{active:t,selectedFiltersCount:o,toggleActive:()=>{n(!t)},toggleProductFilter:u}}function x(){const{loading:e,facets:o}=m.useNostoAppState(t=>{var n,u;return{loading:t.loading,facets:((u=(n=t.response)==null?void 0:n.products)==null?void 0:u.facets)??[]}});return{loading:e,facets:o}}function k(e,o){const t=o-e;return!isNaN(t)&&t>0?new Array(o-e).fill(void 0).map((n,u)=>u+e):[]}function w(e){const{query:o,products:t}=m.useNostoAppState(n=>({query:n.query,products:n.response.products}));return S.useMemo(()=>{var F;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=o.products)==null?void 0:F.from)??0,u=(e==null?void 0:e.width)??1/0,c=Math.max(Math.floor(u-1)/2,1),i=t.size>0?Math.floor(n/t.size)+1:1,a=t.size>0?Math.ceil(t.total/t.size):0,g=A=>A>=i-c&&A<=i+c,s=n+1,l=Math.min(n+t.total,t.total),r={from:n,page:i,current:!0},p=A=>({from:(A-1)*t.size,page:A,current:A===i}),v=i>1?p(i-1):void 0,d=i<a?p(i+1):void 0,y=c===1/0||i-c-1>1?p(1):void 0,f=c===1/0||i+c+1<a?p(a):void 0,h=k(1,a+1).filter(g).map(p);return{totalPages:a,resultsFrom:s,resultsTo:l,current:r,prev:v,next:d,first:y,last:f,pages:h}},[o,t,e==null?void 0:e.width])}function T(){const[e,o]=S.useState([]),[t,n]=S.useState([]);return S.useEffect(()=>{P.s(async u=>{const{products:c,segments:i}=await u.getSearchSessionParams();o(i??[]),n((c==null?void 0:c.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function B(){const{facets:e}=m.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:o,toggleProductFilter:t}=m.useActions(),n=S.useCallback(s=>{const l=e==null?void 0:e.find(r=>r.type==="stats"&&r.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),u=S.useCallback(s=>{var l;return((l=e==null?void 0:e.find(r=>r.field===s))==null?void 0:l.name)??s},[e]),c=S.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),i=S.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(r=>({gt:r.gt?Number(r.gt):r.gt,gte:r.gte?Number(r.gte):r.gte,lt:r.lt?Number(r.lt):r.lt,lte:r.lte?Number(r.lte):r.lte}))}},[]),a=S.useCallback(s=>(s.value??[]).map(r=>({value:r,field:s.field,name:u(s.field),filter:i(s),remove:()=>{t(s.field,r,!1)}})),[i,u,t]),g=S.useCallback(s=>(s.range??[]).map(r=>{var d,y;const p=r.gte??r.gt??((d=n(s.field))==null?void 0:d.min),v=r.lte??r.lt??((y=n(s.field))==null?void 0:y.max);if(p!==void 0&&v!==void 0)return{value:`${p} - ${v}`,field:s.field,name:u(s.field),filter:i(s),remove:()=>{o(s.field,void 0)}}}).filter(Boolean),[i,n,u,o]);return{selectFilters:c,toValueFilter:a,toRangeFilter:g}}function b(){const{filter:e}=m.useNostoAppState(a=>{var g;return{filter:((g=a.query.products)==null?void 0:g.filter)??[]}}),{updateSearch:o}=m.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:u}=B(),c=S.useMemo(()=>e?e.filter(t).flatMap(a=>"value"in a?n(a):"range"in a?u(a):[]).filter(Boolean):[],[e,t,u,n]),i=S.useCallback(()=>{o({products:{filter:[]}})},[o]);return{filters:c,removeAll:i}}function N(e){if(typeof e=="number")return e;if(typeof e!="string")return;const o=Number(e);return isNaN(o)?void 0:o}function R(e){var r,p,v;const{replaceFilter:o}=m.useActions(),{query:t,products:n}=m.useNostoAppState(d=>({query:d.query,products:d.response.products})),u=(r=n==null?void 0:n.facets)==null?void 0:r.find(d=>d.id===e);if(!u)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const c=(v=(p=t.products)==null?void 0:p.filter)==null?void 0:v.find(d=>d.field===u.field),i=c!=null&&c.range?c.range[0]:void 0,a=typeof i=="object"&&("gte"in i||"lte"in i)?[N(i.gte),N(i.lte)]:[void 0,void 0],g="min"in u?Math.floor(u.min):0,s="max"in u?Math.ceil(u.max):0,l=([d,y])=>{const f=d!==void 0?Math.floor(d):void 0,h=y!==void 0?Math.ceil(y):void 0,F=f!==void 0,A=h!==void 0;(g===f||!F)&&(s===h||!A)?o(u.field,void 0):(g===f||!F)&&A?o(u.field,{lte:h.toString()}):(s===h||!A)&&F?o(u.field,{gte:f.toString()}):F&&A&&o(u.field,{gte:f.toString(),lte:h.toString()})};return{min:g,max:s,range:[a[0]??g,a[1]??s],updateRange:l}}function D(e,o){const{min:t,max:n,range:u,updateRange:c}=R(e),{filters:i}=b(),a=S.useMemo(()=>{var y;const r=i.find(f=>{var h;return(h=f==null?void 0:f.filter)==null?void 0:h.range});let p=null;if(r){const f=(y=r.filter.range)==null?void 0:y[0];p=[N(f==null?void 0:f.gte),N(f==null?void 0:f.lte)]}const v=[];let d=Math.floor(t/o)*o;for(;d<n;){const f=d+o,h=p&&p[0]===d&&p[1]===f;v.push({min:d,max:f,selected:h}),d=f}return v},[i,t,n,o]),g=r=>{c([r,u[1]])},s=r=>{c([u[0],r])},l=t!==u[0]||n!==u[1];return{min:t,max:n,range:u,updateRange:c,ranges:a,handleMinChange:g,handleMaxChange:s,isSelected:l}}function j(){const{products:e,keywords:o}=m.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:o??{hits:[],total:0}}}function I(){const e=m.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return S.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function M(e){return e&&!Number.isNaN(e)?e:0}function L(e,o){const{from:t,size:n,total:u}=m.useNostoAppState(s=>{var l,r,p,v,d;return{from:M(((l=s.query.products)==null?void 0:l.from)??0),size:M(((p=(r=s.response)==null?void 0:r.products)==null?void 0:p.size)??0),total:M(((d=(v=s.response)==null?void 0:v.products)==null?void 0:d.total)??0)}}),{updateSearch:c}=m.useActions(),i=t+n,a=[...e].reverse().filter(s=>s+o<u);return{from:t,to:i,total:u,size:n,sizeOptions:a,handleSizeChange:s=>{c({products:{size:s}})}}}function O(e,o){return e.length!==o.length?!1:e.every(t=>o.find(n=>t.field===n.field&&t.order===n.order))}function V(e){var c,i;const o=m.useNostoAppState(a=>a.query),{updateSearch:t}=m.useActions();return{activeSort:((c=e.find(a=>{var g;return O(a.value.sort,((g=o.products)==null?void 0:g.sort)||[])}))==null?void 0:c.id)??((i=e[0])==null?void 0:i.id),setSort:a=>{const g=e.find(s=>s.id===a);g&&t({products:{sort:g.value.sort}})}}}exports.useActions=m.useActions;exports.useLoadMore=m.useLoadMore;exports.useNostoAppState=m.useNostoAppState;exports.useDecoratedSearchResults=z;exports.useFacet=q;exports.useFacets=x;exports.usePagination=w;exports.usePersonalization=T;exports.useProductFilters=b;exports.useRange=R;exports.useRangeSelector=D;exports.useResponse=j;exports.useSelectedFiltersCount=I;exports.useSizeOptions=L;exports.useSort=V;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @module preact/hooks */
|
|
2
|
+
export { useActions } from './src/hooks/useActions';
|
|
3
|
+
export { useDecoratedSearchResults } from './src/hooks/useDecoratedSearchResults';
|
|
4
|
+
export { useFacet } from './src/hooks/useFacet';
|
|
5
|
+
export { useFacets } from './src/hooks/useFacets';
|
|
6
|
+
export { useLoadMore } from './src/hooks/useLoadMore/useLoadMore';
|
|
7
|
+
export { useNostoAppState } from './src/hooks/useNostoAppState';
|
|
8
|
+
export { type Page, usePagination } from './src/hooks/usePagination';
|
|
9
|
+
export { usePersonalization } from './src/hooks/usePersonalization';
|
|
10
|
+
export { useProductFilters } from './src/hooks/useProductFilters/useProductFilters';
|
|
11
|
+
export { useRange } from './src/hooks/useRange';
|
|
12
|
+
export { useRangeSelector } from './src/hooks/useRangeSelector';
|
|
13
|
+
export { useResponse } from './src/hooks/useResponse';
|
|
14
|
+
export { useSelectedFiltersCount } from './src/hooks/useSelectedFiltersCount';
|
|
15
|
+
export { useSizeOptions } from './src/hooks/useSizeOptions';
|
|
16
|
+
export { useSort } from './src/hooks/useSort/useSort';
|