@ceriousdevtech/react-cerious-scroll 1.0.1 → 1.0.2

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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to react-cerious-scroll will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.2] - 2026-06-03
9
+
10
+ ### Added
11
+ - `<CeriousScroll>` now accepts `children`. Rendered children are mounted inside the engine container alongside the engine's scrollbar strip. Combined with a user-supplied `<div data-cerious-scroll-content />`, this lets demos and apps wrap rows in custom DOM (e.g. an `overflow-x: auto` wrapper with a sticky header) without breaking the engine's mobile scrollbar pinning.
12
+
13
+ ### Dependencies
14
+ - Bumped peer dependency `@ceriousdevtech/cerious-scroll` to `^1.0.3` to pick up horizontal flick momentum and the custom scrollbar thumb.
15
+
8
16
  ## [1.0.1] - 2026-06-01
9
17
 
10
18
  ### Changed
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ReactElement, Ref } from 'react';
1
+ import { CSSProperties, ReactElement, ReactNode, Ref } from 'react';
2
2
  import { CeriousScroll as CeriousScrollEngine, MeasuredViewportRange } from '@ceriousdevtech/cerious-scroll';
3
3
  import { UseCeriousScrollOptions } from './use-cerious-scroll';
4
4
  export interface CeriousScrollProps<TItem = unknown> extends UseCeriousScrollOptions<TItem> {
@@ -11,6 +11,13 @@ export interface CeriousScrollProps<TItem = unknown> extends UseCeriousScrollOpt
11
11
  style?: CSSProperties;
12
12
  /** Forwarded to the scroll container for testing. */
13
13
  'data-testid'?: string;
14
+ /**
15
+ * Optional custom DOM rendered inside the engine container. Use this when
16
+ * you need siblings (e.g. a sticky header + horizontal-scroll wrapper) around
17
+ * the recyclable row area. Include a `<div data-cerious-scroll-content />`
18
+ * descendant to host the rendered rows; otherwise the engine creates its own.
19
+ */
20
+ children?: ReactNode;
14
21
  }
15
22
  export interface CeriousScrollHandle {
16
23
  /** The underlying engine instance (`null` before mount). */
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("react/jsx-runtime"),r=require("react"),H=require("react-dom"),K=require("react-dom/server"),_=require("@ceriousdevtech/cerious-scroll"),V="data-cerious-scroll-content",Q="data-cerious-scroll-row";function U(e){const l=e.querySelector(`[${V}]`);if(l)return l;const n=document.createElement("div");return n.setAttribute(V,""),n.style.position="relative",n.style.width="100%",n.style.height="100%",n.style.overflow="hidden",e.appendChild(n),n}function X(e,l){const n=u=>{const o=u.detail;o&&l({percentage:o.percentage,currentElement:o.currentElement,scrollOffset:o.scrollOffset,result:{element:o.result.element,offset:o.result.offset}})},a=u=>{const o=u.detail;o&&l({percentage:o.percentage,currentElement:o.element,scrollOffset:o.scrollOffset,result:{element:o.element,offset:o.scrollOffset}})};return e.addEventListener("cerious-viewport-change",n),e.addEventListener("viewport-change",a),()=>{e.removeEventListener("cerious-viewport-change",n),e.removeEventListener("viewport-change",a)}}function Y(e,l){const n=typeof e=="number"?e:typeof l=="number"?l:void 0;if(n===void 0||Number.isNaN(n))throw new Error("useCeriousScroll: provide `totalElements` or `items`.");return Math.max(1,Math.floor(n))}function D(e){var N;const l=r.useRef(null),n=r.useRef(null),a=r.useRef(new Map),u=r.useRef(null),[,o]=r.useReducer(t=>t+1,0),[q,y]=r.useState(null),E=r.useRef(e.renderItem),d=r.useRef(e.items??null),v=r.useRef(e.getItem),S=r.useRef(e.options),h=r.useRef(e.autoRender??!0),p=r.useRef(e.totalElements??null),O=r.useRef(e.onViewportChange),T=r.useRef(e.onMeasuredViewport),I=r.useRef(e.onReady);E.current=e.renderItem,d.current=e.items??null,v.current=e.getItem,S.current=e.options,h.current=e.autoRender??!0,p.current=e.totalElements??null,O.current=e.onViewportChange,T.current=e.onMeasuredViewport,I.current=e.onReady;const k=r.useCallback(t=>{const c=v.current;if(c)return c(t);const g=d.current;return g?g[t]:void 0},[]),s=r.useCallback(()=>{var w;const t=n.current;if(!t)return null;const{scroller:c,contentEl:g,container:C}=t,j=C.clientHeight||C.offsetHeight||0,b=[],i=(f,R)=>{const m=document.createElement("div");m.setAttribute(Q,String(f)),m.innerHTML=K.renderToStaticMarkup(r.createElement(r.Fragment,null,E.current(k(f),f))),R.appendChild(m),a.current.set(f,{el:R,mount:m}),b.push(m)},A=c.renderViewport(j,g,i),M=new Set(c.getRenderedIndices());return a.current.forEach((f,R)=>{M.has(R)||a.current.delete(R)}),b.forEach(f=>{f.textContent=""}),H.flushSync(o),(w=T.current)==null||w.call(T,A),A},[]),B=e.totalElements??((N=e.items)==null?void 0:N.length)??null;r.useEffect(()=>{var w,f;const t=l.current;if(!t)return;const c=U(t),g=S.current??{},C=g.onScroll,j={...g,onScroll:()=>{C==null||C(),h.current&&s()}},b=Y(p.current,((w=d.current)==null?void 0:w.length)??null),i=new _.CeriousScroll(t,b,j);u.current&&(i.currentElement=Math.min(u.current.currentElement,b-1),i.scrollOffset=u.current.scrollOffset,u.current=null),n.current={scroller:i,contentEl:c,container:t},y(i);const A=X(t,R=>{var m;(m=O.current)==null||m.call(O,R)});(f=I.current)==null||f.call(I,i);let M=0;return h.current&&(M=requestAnimationFrame(()=>s())),()=>{cancelAnimationFrame(M),A(),u.current={currentElement:i.currentElement,scrollOffset:i.scrollOffset},a.current.clear(),c.textContent="",i.detachScrollbar(t),i.dispose(),n.current=null,y(null)}},[B,s]),r.useEffect(()=>{if(!n.current||!h.current)return;const t=requestAnimationFrame(()=>s());return()=>cancelAnimationFrame(t)},[e.items,e.getItem]);const W=r.useCallback(t=>{const c=n.current;return c?(c.scroller.jumpToElement(t),s()):null},[s]),$=r.useCallback(t=>{const c=n.current;return c?(c.scroller.handleScrollPercentage(t),s()):null},[s]),z=r.useCallback(()=>{const t=n.current;return t?(t.scroller.reset(),s()):null},[s]),G=r.useCallback(()=>{const t=n.current;return t?(t.scroller.clearAllCaches(),s()):null},[s]),P=d.current,F=!v.current&&P!=null?P.length:null,L=[];return a.current.forEach((t,c)=>{F!==null&&c>=F||L.push(H.createPortal(E.current(k(c),c),t.mount,String(c)))}),{containerRef:l,portals:L,scroller:q,render:s,jumpToElement:W,scrollToPercentage:$,reset:z,recalculate:G}}function Z(e,l){const{className:n,style:a,"data-testid":u,...o}=e,{containerRef:q,portals:y,scroller:E,render:d,jumpToElement:v,scrollToPercentage:S,reset:h,recalculate:p}=D(o);return r.useImperativeHandle(l,()=>({scroller:E,render:d,jumpToElement:v,scrollToPercentage:S,reset:h,recalculate:p}),[E,d,v,S,h,p]),J.jsx("div",{ref:q,className:n,"data-testid":u,style:{position:"relative",overflow:"hidden",...a},children:y})}const x=r.forwardRef(Z);Object.defineProperty(exports,"CeriousScrollEngine",{enumerable:!0,get:()=>_.CeriousScroll});exports.CeriousScroll=x;exports.useCeriousScroll=D;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("react/jsx-runtime"),r=require("react"),H=require("react-dom"),K=require("react-dom/server"),_=require("@ceriousdevtech/cerious-scroll"),V="data-cerious-scroll-content",Q="data-cerious-scroll-row";function U(e){const l=e.querySelector(`[${V}]`);if(l)return l;const n=document.createElement("div");return n.setAttribute(V,""),n.style.position="relative",n.style.width="100%",n.style.height="100%",n.style.overflow="hidden",e.appendChild(n),n}function X(e,l){const n=u=>{const o=u.detail;o&&l({percentage:o.percentage,currentElement:o.currentElement,scrollOffset:o.scrollOffset,result:{element:o.result.element,offset:o.result.offset}})},a=u=>{const o=u.detail;o&&l({percentage:o.percentage,currentElement:o.element,scrollOffset:o.scrollOffset,result:{element:o.element,offset:o.scrollOffset}})};return e.addEventListener("cerious-viewport-change",n),e.addEventListener("viewport-change",a),()=>{e.removeEventListener("cerious-viewport-change",n),e.removeEventListener("viewport-change",a)}}function Y(e,l){const n=typeof e=="number"?e:typeof l=="number"?l:void 0;if(n===void 0||Number.isNaN(n))throw new Error("useCeriousScroll: provide `totalElements` or `items`.");return Math.max(1,Math.floor(n))}function D(e){var N;const l=r.useRef(null),n=r.useRef(null),a=r.useRef(new Map),u=r.useRef(null),[,o]=r.useReducer(t=>t+1,0),[q,O]=r.useState(null),S=r.useRef(e.renderItem),d=r.useRef(e.items??null),v=r.useRef(e.getItem),p=r.useRef(e.options),h=r.useRef(e.autoRender??!0),b=r.useRef(e.totalElements??null),g=r.useRef(e.onViewportChange),T=r.useRef(e.onMeasuredViewport),I=r.useRef(e.onReady);S.current=e.renderItem,d.current=e.items??null,v.current=e.getItem,p.current=e.options,h.current=e.autoRender??!0,b.current=e.totalElements??null,g.current=e.onViewportChange,T.current=e.onMeasuredViewport,I.current=e.onReady;const k=r.useCallback(t=>{const c=v.current;if(c)return c(t);const R=d.current;return R?R[t]:void 0},[]),s=r.useCallback(()=>{var y;const t=n.current;if(!t)return null;const{scroller:c,contentEl:R,container:C}=t,j=C.clientHeight||C.offsetHeight||0,w=[],i=(f,E)=>{const m=document.createElement("div");m.setAttribute(Q,String(f)),m.innerHTML=K.renderToStaticMarkup(r.createElement(r.Fragment,null,S.current(k(f),f))),E.appendChild(m),a.current.set(f,{el:E,mount:m}),w.push(m)},A=c.renderViewport(j,R,i),M=new Set(c.getRenderedIndices());return a.current.forEach((f,E)=>{M.has(E)||a.current.delete(E)}),w.forEach(f=>{f.textContent=""}),H.flushSync(o),(y=T.current)==null||y.call(T,A),A},[]),B=e.totalElements??((N=e.items)==null?void 0:N.length)??null;r.useEffect(()=>{var y,f;const t=l.current;if(!t)return;const c=U(t),R=p.current??{},C=R.onScroll,j={...R,onScroll:()=>{C==null||C(),h.current&&s()}},w=Y(b.current,((y=d.current)==null?void 0:y.length)??null),i=new _.CeriousScroll(t,w,j);u.current&&(i.currentElement=Math.min(u.current.currentElement,w-1),i.scrollOffset=u.current.scrollOffset,u.current=null),n.current={scroller:i,contentEl:c,container:t},O(i);const A=X(t,E=>{var m;(m=g.current)==null||m.call(g,E)});(f=I.current)==null||f.call(I,i);let M=0;return h.current&&(M=requestAnimationFrame(()=>s())),()=>{cancelAnimationFrame(M),A(),u.current={currentElement:i.currentElement,scrollOffset:i.scrollOffset},a.current.clear(),c.textContent="",i.detachScrollbar(t),i.dispose(),n.current=null,O(null)}},[B,s]),r.useEffect(()=>{if(!n.current||!h.current)return;const t=requestAnimationFrame(()=>s());return()=>cancelAnimationFrame(t)},[e.items,e.getItem]);const W=r.useCallback(t=>{const c=n.current;return c?(c.scroller.jumpToElement(t),s()):null},[s]),$=r.useCallback(t=>{const c=n.current;return c?(c.scroller.handleScrollPercentage(t),s()):null},[s]),z=r.useCallback(()=>{const t=n.current;return t?(t.scroller.reset(),s()):null},[s]),G=r.useCallback(()=>{const t=n.current;return t?(t.scroller.clearAllCaches(),s()):null},[s]),P=d.current,F=!v.current&&P!=null?P.length:null,L=[];return a.current.forEach((t,c)=>{F!==null&&c>=F||L.push(H.createPortal(S.current(k(c),c),t.mount,String(c)))}),{containerRef:l,portals:L,scroller:q,render:s,jumpToElement:W,scrollToPercentage:$,reset:z,recalculate:G}}function Z(e,l){const{className:n,style:a,"data-testid":u,children:o,...q}=e,{containerRef:O,portals:S,scroller:d,render:v,jumpToElement:p,scrollToPercentage:h,reset:b,recalculate:g}=D(q);return r.useImperativeHandle(l,()=>({scroller:d,render:v,jumpToElement:p,scrollToPercentage:h,reset:b,recalculate:g}),[d,v,p,h,b,g]),J.jsxs("div",{ref:O,className:n,"data-testid":u,style:{position:"relative",overflow:"hidden",...a},children:[o,S]})}const x=r.forwardRef(Z);Object.defineProperty(exports,"CeriousScrollEngine",{enumerable:!0,get:()=>_.CeriousScroll});exports.CeriousScroll=x;exports.useCeriousScroll=D;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx as G } from "react/jsx-runtime";
1
+ import { jsxs as G } from "react/jsx-runtime";
2
2
  import { useRef as s, useReducer as J, useState as K, useCallback as S, useEffect as _, createElement as Q, Fragment as U, forwardRef as X, useImperativeHandle as Y } from "react";
3
3
  import { flushSync as Z, createPortal as x } from "react-dom";
4
4
  import { renderToStaticMarkup as ee } from "react-dom/server";
@@ -41,43 +41,43 @@ function ce(e, c) {
41
41
  }
42
42
  function le(e) {
43
43
  var q;
44
- const c = s(null), r = s(null), a = s(/* @__PURE__ */ new Map()), u = s(null), [, o] = J((t) => t + 1, 0), [L, O] = K(null), p = s(e.renderItem), d = s(e.items ?? null), v = s(e.getItem), w = s(e.options), h = s(e.autoRender ?? !0), C = s(e.totalElements ?? null), b = s(e.onViewportChange), y = s(e.onMeasuredViewport), A = s(e.onReady);
45
- p.current = e.renderItem, d.current = e.items ?? null, v.current = e.getItem, w.current = e.options, h.current = e.autoRender ?? !0, C.current = e.totalElements ?? null, b.current = e.onViewportChange, y.current = e.onMeasuredViewport, A.current = e.onReady;
44
+ const c = s(null), r = s(null), a = s(/* @__PURE__ */ new Map()), u = s(null), [, o] = J((t) => t + 1, 0), [L, b] = K(null), w = s(e.renderItem), d = s(e.items ?? null), v = s(e.getItem), C = s(e.options), h = s(e.autoRender ?? !0), T = s(e.totalElements ?? null), g = s(e.onViewportChange), y = s(e.onMeasuredViewport), A = s(e.onReady);
45
+ w.current = e.renderItem, d.current = e.items ?? null, v.current = e.getItem, C.current = e.options, h.current = e.autoRender ?? !0, T.current = e.totalElements ?? null, g.current = e.onViewportChange, y.current = e.onMeasuredViewport, A.current = e.onReady;
46
46
  const P = S((t) => {
47
47
  const n = v.current;
48
48
  if (n) return n(t);
49
- const g = d.current;
50
- return g ? g[t] : void 0;
49
+ const E = d.current;
50
+ return E ? E[t] : void 0;
51
51
  }, []), l = S(() => {
52
- var I;
52
+ var O;
53
53
  const t = r.current;
54
54
  if (!t) return null;
55
- const { scroller: n, contentEl: g, container: R } = t, N = R.clientHeight || R.offsetHeight || 0, T = [], i = (f, E) => {
55
+ const { scroller: n, contentEl: E, container: R } = t, N = R.clientHeight || R.offsetHeight || 0, I = [], i = (f, p) => {
56
56
  const m = document.createElement("div");
57
57
  m.setAttribute(re, String(f)), m.innerHTML = ee(
58
- Q(U, null, p.current(P(f), f))
59
- ), E.appendChild(m), a.current.set(f, { el: E, mount: m }), T.push(m);
60
- }, M = n.renderViewport(N, g, i), F = new Set(n.getRenderedIndices());
61
- return a.current.forEach((f, E) => {
62
- F.has(E) || a.current.delete(E);
63
- }), T.forEach((f) => {
58
+ Q(U, null, w.current(P(f), f))
59
+ ), p.appendChild(m), a.current.set(f, { el: p, mount: m }), I.push(m);
60
+ }, M = n.renderViewport(N, E, i), F = new Set(n.getRenderedIndices());
61
+ return a.current.forEach((f, p) => {
62
+ F.has(p) || a.current.delete(p);
63
+ }), I.forEach((f) => {
64
64
  f.textContent = "";
65
- }), Z(o), (I = y.current) == null || I.call(y, M), M;
65
+ }), Z(o), (O = y.current) == null || O.call(y, M), M;
66
66
  }, []), $ = e.totalElements ?? ((q = e.items) == null ? void 0 : q.length) ?? null;
67
67
  _(() => {
68
- var I, f;
68
+ var O, f;
69
69
  const t = c.current;
70
70
  if (!t) return;
71
- const n = ne(t), g = w.current ?? {}, R = g.onScroll, N = {
72
- ...g,
71
+ const n = ne(t), E = C.current ?? {}, R = E.onScroll, N = {
72
+ ...E,
73
73
  onScroll: () => {
74
74
  R == null || R(), h.current && l();
75
75
  }
76
- }, T = ce(C.current, ((I = d.current) == null ? void 0 : I.length) ?? null), i = new te(t, T, N);
77
- u.current && (i.currentElement = Math.min(u.current.currentElement, T - 1), i.scrollOffset = u.current.scrollOffset, u.current = null), r.current = { scroller: i, contentEl: n, container: t }, O(i);
78
- const M = oe(t, (E) => {
76
+ }, I = ce(T.current, ((O = d.current) == null ? void 0 : O.length) ?? null), i = new te(t, I, N);
77
+ u.current && (i.currentElement = Math.min(u.current.currentElement, I - 1), i.scrollOffset = u.current.scrollOffset, u.current = null), r.current = { scroller: i, contentEl: n, container: t }, b(i);
78
+ const M = oe(t, (p) => {
79
79
  var m;
80
- (m = b.current) == null || m.call(b, E);
80
+ (m = g.current) == null || m.call(g, p);
81
81
  });
82
82
  (f = A.current) == null || f.call(A, i);
83
83
  let F = 0;
@@ -85,7 +85,7 @@ function le(e) {
85
85
  cancelAnimationFrame(F), M(), u.current = {
86
86
  currentElement: i.currentElement,
87
87
  scrollOffset: i.scrollOffset
88
- }, a.current.clear(), n.textContent = "", i.detachScrollbar(t), i.dispose(), r.current = null, O(null);
88
+ }, a.current.clear(), n.textContent = "", i.detachScrollbar(t), i.dispose(), r.current = null, b(null);
89
89
  };
90
90
  }, [$, l]), _(() => {
91
91
  if (!r.current || !h.current) return;
@@ -113,7 +113,7 @@ function le(e) {
113
113
  }, [l]), j = d.current, H = !v.current && j != null ? j.length : null, V = [];
114
114
  return a.current.forEach((t, n) => {
115
115
  H !== null && n >= H || V.push(
116
- x(p.current(P(n), n), t.mount, String(n))
116
+ x(w.current(P(n), n), t.mount, String(n))
117
117
  );
118
118
  }), {
119
119
  containerRef: c,
@@ -127,28 +127,31 @@ function le(e) {
127
127
  };
128
128
  }
129
129
  function se(e, c) {
130
- const { className: r, style: a, "data-testid": u, ...o } = e, {
131
- containerRef: L,
132
- portals: O,
133
- scroller: p,
134
- render: d,
135
- jumpToElement: v,
136
- scrollToPercentage: w,
137
- reset: h,
138
- recalculate: C
139
- } = le(o);
130
+ const { className: r, style: a, "data-testid": u, children: o, ...L } = e, {
131
+ containerRef: b,
132
+ portals: w,
133
+ scroller: d,
134
+ render: v,
135
+ jumpToElement: C,
136
+ scrollToPercentage: h,
137
+ reset: T,
138
+ recalculate: g
139
+ } = le(L);
140
140
  return Y(
141
141
  c,
142
- () => ({ scroller: p, render: d, jumpToElement: v, scrollToPercentage: w, reset: h, recalculate: C }),
143
- [p, d, v, w, h, C]
142
+ () => ({ scroller: d, render: v, jumpToElement: C, scrollToPercentage: h, reset: T, recalculate: g }),
143
+ [d, v, C, h, T, g]
144
144
  ), /* @__PURE__ */ G(
145
145
  "div",
146
146
  {
147
- ref: L,
147
+ ref: b,
148
148
  className: r,
149
149
  "data-testid": u,
150
150
  style: { position: "relative", overflow: "hidden", ...a },
151
- children: O
151
+ children: [
152
+ o,
153
+ w
154
+ ]
152
155
  }
153
156
  );
154
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ceriousdevtech/react-cerious-scroll",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "React bindings for CeriousScroll — high-performance virtual scrolling with O(1) memory and no height estimation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -56,7 +56,7 @@
56
56
  "demo:build": "vite build --config demo/vite.config.ts"
57
57
  },
58
58
  "peerDependencies": {
59
- "@ceriousdevtech/cerious-scroll": "^1.0.1",
59
+ "@ceriousdevtech/cerious-scroll": "^1.0.3",
60
60
  "react": ">=18 <20",
61
61
  "react-dom": ">=18 <20"
62
62
  },