@nosto/search-js 1.6.0 → 1.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.
- package/dist/preact/preact.cjs.js +1 -1
- package/dist/preact/preact.d.ts +2 -0
- package/dist/preact/preact.es.js +546 -463
- package/dist/preact/src/components/InfiniteScroll/InfiniteScroll.d.ts +51 -0
- package/dist/preact/src/components/InfiniteScroll/InfiniteScrollWithLink.d.ts +6 -0
- package/dist/preact/src/components/InfiniteScroll/InfiniteScrollWithObserver.d.ts +7 -0
- package/dist/preact/src/components/InfiniteScroll/LoadMoreLink.d.ts +7 -0
- package/dist/preact/src/components/InfiniteScroll/utils.d.ts +9 -0
- package/dist/preact/src/hooks/useLoadMore/getNextPageQuery.d.ts +18 -0
- package/dist/preact/src/hooks/useLoadMore/useLoadMore.d.ts +24 -0
- package/dist/utils/src/isBot.d.ts +4 -0
- package/dist/utils/src/pick.d.ts +6 -0
- package/package.json +4 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ComponentChildren, ComponentType } from 'preact';
|
|
2
|
+
import { InfiniteScrollWithObserver } from './InfiniteScrollWithObserver';
|
|
3
|
+
/**
|
|
4
|
+
* Infinite scroll component props
|
|
5
|
+
* @param children - The children to render
|
|
6
|
+
* @param loadMoreComponent - The component to render when more results are available
|
|
7
|
+
* @param pageSize - The page size to use when loading more results
|
|
8
|
+
*/
|
|
9
|
+
export interface InfiniteScrollProps {
|
|
10
|
+
children: ComponentChildren;
|
|
11
|
+
loadMoreComponent?: ComponentType<{
|
|
12
|
+
pageSize?: number;
|
|
13
|
+
}>;
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Infinite scroll component that loads more results when user scrolls to the end of the page.
|
|
18
|
+
* If the browser does not support IntersectionObserver, a load more button is shown instead.
|
|
19
|
+
* @param props
|
|
20
|
+
* @example
|
|
21
|
+
* ```jsx
|
|
22
|
+
* import { InfiniteScroll } from "@nosto/search-js/preact"
|
|
23
|
+
*
|
|
24
|
+
* <InfiniteScroll pageSize={defaultConfig.pageSize}>
|
|
25
|
+
* {products?.hits?.map(hit => <Product hit={hit} />)}
|
|
26
|
+
* </InfiniteScroll>
|
|
27
|
+
*
|
|
28
|
+
* <InfiniteScroll pageSize={defaultConfig.pageSize}>
|
|
29
|
+
* <Products />
|
|
30
|
+
* </InfiniteScroll>
|
|
31
|
+
*
|
|
32
|
+
* // With custom load more button
|
|
33
|
+
* function LoadMoreButton({ pageSize }) {
|
|
34
|
+
* const { loadMore } = useLoadMore(pageSize)
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <button
|
|
38
|
+
* onClick={loadMore}
|
|
39
|
+
* >
|
|
40
|
+
* More results
|
|
41
|
+
* </button>
|
|
42
|
+
* )
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* <InfiniteScroll loadMoreComponent={LoadMoreButton} pageSize={defaultConfig.pageSize}>
|
|
46
|
+
* {products?.hits?.map(hit => <Product hit={hit} />)}
|
|
47
|
+
* </InfiniteScroll>
|
|
48
|
+
* ```
|
|
49
|
+
* @group Components
|
|
50
|
+
*/
|
|
51
|
+
export declare const InfiniteScroll: typeof InfiniteScrollWithObserver;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InfiniteScrollProps } from './InfiniteScroll';
|
|
2
|
+
/**
|
|
3
|
+
* Infinite scroll component that loads more results when user clicks a link.
|
|
4
|
+
* @group Components
|
|
5
|
+
*/
|
|
6
|
+
export declare function InfiniteScrollWithLink({ children, loadMoreComponent: LoadMore, pageSize }: InfiniteScrollProps): import("preact").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JSX } from 'preact';
|
|
2
|
+
import { InfiniteScrollProps } from './InfiniteScroll';
|
|
3
|
+
/**
|
|
4
|
+
* Infinite scroll component that loads more results when user scrolls to the end of the page.
|
|
5
|
+
* @group Components
|
|
6
|
+
*/
|
|
7
|
+
export declare function InfiniteScrollWithObserver({ children, pageSize }: InfiniteScrollProps): JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
+
/**
|
|
3
|
+
* Function to check if there are more results to fetch.
|
|
4
|
+
*/
|
|
5
|
+
export declare function hasMoreResults(query: SearchQuery, result: SearchResult): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Function to check if IntersectionObserver is supported in the browser.
|
|
8
|
+
*/
|
|
9
|
+
export declare function intersectionObserverSupported(): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to calculate the new query values for loading more products
|
|
3
|
+
*/
|
|
4
|
+
export declare function getNextPageQuery({ from, size, pageSize }: {
|
|
5
|
+
from: number;
|
|
6
|
+
size: number;
|
|
7
|
+
pageSize: number;
|
|
8
|
+
}): {
|
|
9
|
+
products: {
|
|
10
|
+
from: number;
|
|
11
|
+
size?: undefined;
|
|
12
|
+
};
|
|
13
|
+
} | {
|
|
14
|
+
products: {
|
|
15
|
+
size: number;
|
|
16
|
+
from?: undefined;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for loading more results by specified pageSize value
|
|
3
|
+
* @example
|
|
4
|
+
* ```jsx
|
|
5
|
+
* import { useLoadMore } from '@nosto/search-js/preact'
|
|
6
|
+
*
|
|
7
|
+
* function LoadMoreButton({ pageSize }) {
|
|
8
|
+
* const { loadMore } = useLoadMore(pageSize)
|
|
9
|
+
*
|
|
10
|
+
* return (
|
|
11
|
+
* <a
|
|
12
|
+
* onClick={loadMore}
|
|
13
|
+
* >
|
|
14
|
+
* More results
|
|
15
|
+
* </a>
|
|
16
|
+
* )
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
* @param pageSize - number of additional products to load (default=24)
|
|
20
|
+
* @group Hooks
|
|
21
|
+
*/
|
|
22
|
+
export declare function useLoadMore(pageSize?: number): {
|
|
23
|
+
loadMore: () => Promise<void>;
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -63,10 +63,11 @@
|
|
|
63
63
|
"eslint-config-prettier": "^10.1.1",
|
|
64
64
|
"eslint-plugin-barrel-files": "^3.0.1",
|
|
65
65
|
"eslint-plugin-prettier": "^5.2.4",
|
|
66
|
-
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
67
|
-
"eslint-plugin-unused-imports": "^4.1.4",
|
|
68
66
|
"eslint-plugin-react": "^7.37.4",
|
|
69
67
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
68
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
69
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
70
|
+
"isbot": "^5.1.25",
|
|
70
71
|
"jsdom": "^26.0.0",
|
|
71
72
|
"prettier": "^3.5.3",
|
|
72
73
|
"typedoc": "^0.27.9",
|