@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 +8 -0
- package/dist/cerious-scroll.d.ts +8 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +40 -37
- package/package.json +2 -2
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
|
package/dist/cerious-scroll.d.ts
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,
|
|
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 {
|
|
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,
|
|
45
|
-
|
|
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
|
|
50
|
-
return
|
|
49
|
+
const E = d.current;
|
|
50
|
+
return E ? E[t] : void 0;
|
|
51
51
|
}, []), l = S(() => {
|
|
52
|
-
var
|
|
52
|
+
var O;
|
|
53
53
|
const t = r.current;
|
|
54
54
|
if (!t) return null;
|
|
55
|
-
const { scroller: n, contentEl:
|
|
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,
|
|
59
|
-
),
|
|
60
|
-
}, M = n.renderViewport(N,
|
|
61
|
-
return a.current.forEach((f,
|
|
62
|
-
F.has(
|
|
63
|
-
}),
|
|
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), (
|
|
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
|
|
68
|
+
var O, f;
|
|
69
69
|
const t = c.current;
|
|
70
70
|
if (!t) return;
|
|
71
|
-
const n = ne(t),
|
|
72
|
-
...
|
|
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
|
-
},
|
|
77
|
-
u.current && (i.currentElement = Math.min(u.current.currentElement,
|
|
78
|
-
const M = oe(t, (
|
|
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 =
|
|
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,
|
|
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(
|
|
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,
|
|
131
|
-
containerRef:
|
|
132
|
-
portals:
|
|
133
|
-
scroller:
|
|
134
|
-
render:
|
|
135
|
-
jumpToElement:
|
|
136
|
-
scrollToPercentage:
|
|
137
|
-
reset:
|
|
138
|
-
recalculate:
|
|
139
|
-
} = le(
|
|
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:
|
|
143
|
-
[
|
|
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:
|
|
147
|
+
ref: b,
|
|
148
148
|
className: r,
|
|
149
149
|
"data-testid": u,
|
|
150
150
|
style: { position: "relative", overflow: "hidden", ...a },
|
|
151
|
-
children:
|
|
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.
|
|
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.
|
|
59
|
+
"@ceriousdevtech/cerious-scroll": "^1.0.3",
|
|
60
60
|
"react": ">=18 <20",
|
|
61
61
|
"react-dom": ">=18 <20"
|
|
62
62
|
},
|