@nosto/search-js 3.0.0 → 3.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.
@@ -0,0 +1 @@
1
+ "use strict";const d=require("./jsxRuntime.module-B3sGoTIU.cjs"),f=require("./useLoadMore-CeqFdxt1.cjs"),b=require("./pick-rYi1lc2m.cjs"),p=require("preact/hooks"),h=require("preact");function a(s,i){var t,o,e;const r=((t=i.products)==null?void 0:t.total)??0,n=((o=s.products)==null?void 0:o.from)??0,c=((e=s.products)==null?void 0:e.size)??0;return r>0&&r>n+c}function w(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function I({children:s,pageSize:i,observerOptions:r={}}){const n=p.useRef(null),{query:c,response:t}=f.useNostoAppState(e=>b.pick(e,"query","response")),{loadMore:o}=f.useLoadMore(i);return p.useEffect(()=>{let e,u;return a(c,t)&&(e=n.current,u=new IntersectionObserver(v=>{const l=v[0];l!=null&&l.isIntersecting&&o()},r),e&&u.observe(e)),()=>{e&&u.unobserve(e)}},[t,r]),d.u(h.Fragment,{children:[s,d.u("div",{ref:n,style:{height:"1px"}})]})}exports.InfiniteScrollWithObserver=I;exports.hasMoreResults=a;exports.intersectionObserverSupported=w;
@@ -0,0 +1,37 @@
1
+ import { u as p } from "./jsxRuntime.module-Bzuv3cXw.js";
2
+ import { a as l, b as d } from "./useLoadMore-Der8Cglb.js";
3
+ import { p as m } from "./pick-DReBictn.js";
4
+ import { useRef as b, useEffect as v } from "preact/hooks";
5
+ import { Fragment as w } from "preact";
6
+ function I(o, i) {
7
+ var t, n, e;
8
+ const r = ((t = i.products) == null ? void 0 : t.total) ?? 0, s = ((n = o.products) == null ? void 0 : n.from) ?? 0, c = ((e = o.products) == null ? void 0 : e.size) ?? 0;
9
+ return r > 0 && r > s + c;
10
+ }
11
+ function M() {
12
+ return !!(window.IntersectionObserver && window.IntersectionObserverEntry && "intersectionRatio" in window.IntersectionObserverEntry.prototype);
13
+ }
14
+ function S({
15
+ children: o,
16
+ pageSize: i,
17
+ observerOptions: r = {}
18
+ }) {
19
+ const s = b(null), { query: c, response: t } = l((e) => m(e, "query", "response")), { loadMore: n } = d(i);
20
+ return v(() => {
21
+ let e, u;
22
+ return I(c, t) && (e = s.current, u = new IntersectionObserver((a) => {
23
+ const f = a[0];
24
+ f != null && f.isIntersecting && n();
25
+ }, r), e && u.observe(e)), () => {
26
+ e && u.unobserve(e);
27
+ };
28
+ }, [t, r]), /* @__PURE__ */ p(w, { children: [
29
+ o,
30
+ /* @__PURE__ */ p("div", { ref: s, style: { height: "1px" } })
31
+ ] });
32
+ }
33
+ export {
34
+ S as I,
35
+ I as h,
36
+ M as i
37
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-Blp-K9zG.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-CeqFdxt1.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-BZeSt2TI.cjs"),q=require("preact"),r=require("../configContext-BR7w4VlU.cjs");function b({pageSize:o}){const{loadMore:e}=c.useLoadMore(o);return t.u("button",{onClick:e,children:"More results"})}function u({children:o,loadMoreComponent:e,pageSize:i}){const{loading:s,query:l,response:a}=c.useNostoAppState(S=>p.pick(S,"loading","query","response")),d=!s&&n.hasMoreResults(l,a);return t.u(q.Fragment,{children:[o,d&&(e?t.u(e,{pageSize:i}):t.u(b,{pageSize:i}))]})}const M=!f.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=r.StoreContext;exports.createExtendableStore=r.createExtendableStore;exports.createStore=r.createStore;exports.defaultState=r.defaultState;exports.InfiniteScroll=M;exports.InfiniteScrollWithLink=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-Blp-K9zG.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-CeqFdxt1.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-C1NKm8WG.cjs"),q=require("preact"),r=require("../configContext-BR7w4VlU.cjs");function b({pageSize:o}){const{loadMore:e}=c.useLoadMore(o);return t.u("button",{onClick:e,children:"More results"})}function u({children:o,loadMoreComponent:e,pageSize:i}){const{loading:s,query:l,response:a}=c.useNostoAppState(S=>p.pick(S,"loading","query","response")),d=!s&&n.hasMoreResults(l,a);return t.u(q.Fragment,{children:[o,d&&(e?t.u(e,{pageSize:i}):t.u(b,{pageSize:i}))]})}const M=!f.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=r.StoreContext;exports.createExtendableStore=r.createExtendableStore;exports.createStore=r.createStore;exports.defaultState=r.defaultState;exports.InfiniteScroll=M;exports.InfiniteScrollWithLink=u;
@@ -2,7 +2,7 @@ import { i as l } from "../unique-m1TIDWdl.js";
2
2
  import { u as r } from "../jsxRuntime.module-Bzuv3cXw.js";
3
3
  import { b as p, a as m } from "../useLoadMore-Der8Cglb.js";
4
4
  import { p as u } from "../pick-DReBictn.js";
5
- import { h as d, i as f, I as S } from "../InfiniteScrollWithObserver-DYKAh87P.js";
5
+ import { h as d, i as f, I as S } from "../InfiniteScrollWithObserver-C4YMu07G.js";
6
6
  import { Fragment as h } from "preact";
7
7
  import { S as O, a as W, c as A, d as B } from "../configContext-GuZOIX3o.js";
8
8
  function M({ pageSize: e }) {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-CeqFdxt1.cjs"),r=require("../InfiniteScrollWithObserver-BZeSt2TI.cjs");exports.getNextPageQuery=e.getNextPageQuery;exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-CeqFdxt1.cjs"),r=require("../InfiniteScrollWithObserver-C1NKm8WG.cjs");exports.getNextPageQuery=e.getNextPageQuery;exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;
@@ -1,5 +1,5 @@
1
1
  import { g as t, n as a, u as s } from "../useLoadMore-Der8Cglb.js";
2
- import { I as i, i as n } from "../InfiniteScrollWithObserver-DYKAh87P.js";
2
+ import { I as i, i as n } from "../InfiniteScrollWithObserver-C4YMu07G.js";
3
3
  export {
4
4
  i as InfiniteScrollWithObserver,
5
5
  t as getNextPageQuery,
@@ -12,6 +12,13 @@ export interface InfiniteScrollProps {
12
12
  pageSize?: number;
13
13
  }>;
14
14
  pageSize?: number;
15
+ /**
16
+ * Options for the IntersectionObserver.
17
+ * This can be used to adjust the root margin, threshold, etc.
18
+ * For example, to trigger the observer when the user scrolls to the bottom of the page, you can set `rootMargin: "100% 0"`.
19
+ * @default { rootMargin: "0px", threshold: 0 }
20
+ */
21
+ observerOptions?: IntersectionObserverInit;
15
22
  }
16
23
  /**
17
24
  * Infinite scroll component that loads more results when user scrolls to the end of the page.
@@ -4,4 +4,4 @@ import { InfiniteScrollProps } from './InfiniteScroll';
4
4
  * Infinite scroll component that loads more results when user scrolls to the end of the page.
5
5
  * @group Components
6
6
  */
7
- export declare function InfiniteScrollWithObserver({ children, pageSize }: InfiniteScrollProps): JSX.Element;
7
+ export declare function InfiniteScrollWithObserver({ children, pageSize, observerOptions }: InfiniteScrollProps): JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [
@@ -86,12 +86,12 @@
86
86
  "devDependencies": {
87
87
  "@commitlint/cli": "^19.8.1",
88
88
  "@commitlint/config-conventional": "^19.8.1",
89
- "@nosto/nosto-js": "^2.1.0",
89
+ "@nosto/nosto-js": "^2.2.0",
90
90
  "@testing-library/dom": "^10.4.0",
91
91
  "@types/dom-speech-recognition": "^0.0.6",
92
92
  "@types/eslint-config-prettier": "^6.11.3",
93
- "@types/node": "^22.15.29",
94
- "@vitest/coverage-v8": "^3.2.0",
93
+ "@types/node": "^22.15.30",
94
+ "@vitest/coverage-v8": "^3.2.3",
95
95
  "concurrently": "^9.1.2",
96
96
  "copyfiles": "^2.4.1",
97
97
  "eslint": "^9.28.0",
@@ -108,7 +108,7 @@
108
108
  "prettier": "^3.5.3",
109
109
  "typedoc": "^0.28.5",
110
110
  "typescript": "^5.8.3",
111
- "typescript-eslint": "^8.33.0",
111
+ "typescript-eslint": "^8.33.1",
112
112
  "vite": "^6.3.5",
113
113
  "vite-plugin-dts": "^4.5.4",
114
114
  "vitest": "^3.1.3"
@@ -1 +0,0 @@
1
- "use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-CeqFdxt1.cjs"),a=require("./pick-rYi1lc2m.cjs"),d=require("preact/hooks"),b=require("preact");function f(s,i){var o,e,r;const t=((o=i.products)==null?void 0:o.total)??0,c=((e=s.products)==null?void 0:e.from)??0,n=((r=s.products)==null?void 0:r.size)??0;return t>0&&t>c+n}function h(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function O({children:s,pageSize:i}){const t=d.useRef(null),{query:c,response:n}=p.useNostoAppState(e=>a.pick(e,"query","response")),{loadMore:o}=p.useLoadMore(i);return d.useEffect(()=>{let e,r;return f(c,n)&&(e=t.current,r=new IntersectionObserver(v=>{const u=v[0];u!=null&&u.isIntersecting&&o()}),e&&r.observe(e)),()=>{e&&r.unobserve(e)}},[n]),l.u(b.Fragment,{children:[s,l.u("div",{ref:t,style:{height:"1px"}})]})}exports.InfiniteScrollWithObserver=O;exports.hasMoreResults=f;exports.intersectionObserverSupported=h;
@@ -1,33 +0,0 @@
1
- import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
2
- import { a, b as l } from "./useLoadMore-Der8Cglb.js";
3
- import { p as d } from "./pick-DReBictn.js";
4
- import { useRef as m, useEffect as b } from "preact/hooks";
5
- import { Fragment as v } from "preact";
6
- function w(o, i) {
7
- var n, e, r;
8
- const t = ((n = i.products) == null ? void 0 : n.total) ?? 0, c = ((e = o.products) == null ? void 0 : e.from) ?? 0, s = ((r = o.products) == null ? void 0 : r.size) ?? 0;
9
- return t > 0 && t > c + s;
10
- }
11
- function E() {
12
- return !!(window.IntersectionObserver && window.IntersectionObserverEntry && "intersectionRatio" in window.IntersectionObserverEntry.prototype);
13
- }
14
- function M({ children: o, pageSize: i }) {
15
- const t = m(null), { query: c, response: s } = a((e) => d(e, "query", "response")), { loadMore: n } = l(i);
16
- return b(() => {
17
- let e, r;
18
- return w(c, s) && (e = t.current, r = new IntersectionObserver((p) => {
19
- const u = p[0];
20
- u != null && u.isIntersecting && n();
21
- }), e && r.observe(e)), () => {
22
- e && r.unobserve(e);
23
- };
24
- }, [s]), /* @__PURE__ */ f(v, { children: [
25
- o,
26
- /* @__PURE__ */ f("div", { ref: t, style: { height: "1px" } })
27
- ] });
28
- }
29
- export {
30
- M as I,
31
- w as h,
32
- E as i
33
- };