@ceriousdevtech/react-cerious-scroll 1.0.1 → 1.0.3
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 +16 -0
- package/dist/cerious-scroll.d.ts +8 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +50 -47
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ 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.3] - 2026-06-03
|
|
9
|
+
|
|
10
|
+
### Dependencies
|
|
11
|
+
- Bumped peer dependency `@ceriousdevtech/cerious-scroll` to `^1.0.4`. Consumers get smooth wheel scrolling (eased over ~150ms, configurable via `wheel: { smooth }`) and the engine now reads viewport height from `[data-cerious-scroll-content]` so wrappers that put a horizontal scrollbar on the inner element get the last row clearance for free.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- The inner content element is now styled `overflow-y: clip; overflow-x: auto` so consumers can opt into a horizontal scrollbar on the rows axis without a stray vertical bar appearing.
|
|
15
|
+
|
|
16
|
+
## [1.0.2] - 2026-06-03
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- `<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.
|
|
20
|
+
|
|
21
|
+
### Dependencies
|
|
22
|
+
- Bumped peer dependency `@ceriousdevtech/cerious-scroll` to `^1.0.3` to pick up horizontal flick momentum and the custom scrollbar thumb.
|
|
23
|
+
|
|
8
24
|
## [1.0.1] - 2026-06-01
|
|
9
25
|
|
|
10
26
|
### 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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),r=require("react"),H=require("react-dom"),G=require("react-dom/server"),_=require("@ceriousdevtech/cerious-scroll"),V="data-cerious-scroll-content",J="data-cerious-scroll-row";function K(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.overflowY="clip",n.style.overflowX="auto",e.appendChild(n),n}function Q(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 U(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(J,String(f)),m.innerHTML=G.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=K(t),R=p.current??{},C=R.onScroll,j={...R,onScroll:()=>{C==null||C(),h.current&&s()}},w=U(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=Q(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]),X=r.useCallback(t=>{const c=n.current;return c?(c.scroller.handleScrollPercentage(t),s()):null},[s]),Y=r.useCallback(()=>{const t=n.current;return t?(t.scroller.reset(),s()):null},[s]),$=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:X,reset:Y,recalculate:$}}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]),z.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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRef as s, useReducer as
|
|
1
|
+
import { jsxs as Y } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useReducer as z, useState as G, useCallback as R, useEffect as _, createElement as J, Fragment as K, forwardRef as Q, useImperativeHandle as U } from "react";
|
|
3
3
|
import { flushSync as Z, createPortal as x } from "react-dom";
|
|
4
4
|
import { renderToStaticMarkup as ee } from "react-dom/server";
|
|
5
5
|
import { CeriousScroll as te } from "@ceriousdevtech/cerious-scroll";
|
|
@@ -9,7 +9,7 @@ function ne(e) {
|
|
|
9
9
|
const c = e.querySelector(`[${k}]`);
|
|
10
10
|
if (c) return c;
|
|
11
11
|
const r = document.createElement("div");
|
|
12
|
-
return r.setAttribute(k, ""), r.style.position = "relative", r.style.width = "100%", r.style.height = "100%", r.style.
|
|
12
|
+
return r.setAttribute(k, ""), r.style.position = "relative", r.style.width = "100%", r.style.height = "100%", r.style.overflowY = "clip", r.style.overflowX = "auto", e.appendChild(r), r;
|
|
13
13
|
}
|
|
14
14
|
function oe(e, c) {
|
|
15
15
|
const r = (u) => {
|
|
@@ -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] =
|
|
45
|
-
|
|
46
|
-
const P =
|
|
44
|
+
const c = s(null), r = s(null), a = s(/* @__PURE__ */ new Map()), u = s(null), [, o] = z((t) => t + 1, 0), [L, O] = G(null), S = 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), b = s(e.onMeasuredViewport), A = s(e.onReady);
|
|
45
|
+
S.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, b.current = e.onMeasuredViewport, A.current = e.onReady;
|
|
46
|
+
const P = R((t) => {
|
|
47
47
|
const n = v.current;
|
|
48
48
|
if (n) return n(t);
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
}, []), l =
|
|
49
|
+
const E = d.current;
|
|
50
|
+
return E ? E[t] : void 0;
|
|
51
|
+
}, []), l = R(() => {
|
|
52
52
|
var I;
|
|
53
53
|
const t = r.current;
|
|
54
54
|
if (!t) return null;
|
|
55
|
-
const { scroller: n, contentEl:
|
|
55
|
+
const { scroller: n, contentEl: E, container: w } = t, N = w.clientHeight || w.offsetHeight || 0, y = [], i = (f, p) => {
|
|
56
56
|
const m = document.createElement("div");
|
|
57
57
|
m.setAttribute(re, String(f)), m.innerHTML = ee(
|
|
58
|
-
|
|
59
|
-
),
|
|
60
|
-
}, M = n.renderViewport(N,
|
|
61
|
-
return a.current.forEach((f,
|
|
62
|
-
F.has(
|
|
63
|
-
}),
|
|
58
|
+
J(K, null, S.current(P(f), f))
|
|
59
|
+
), p.appendChild(m), a.current.set(f, { el: p, mount: m }), y.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
|
+
}), y.forEach((f) => {
|
|
64
64
|
f.textContent = "";
|
|
65
|
-
}), Z(o), (I =
|
|
65
|
+
}), Z(o), (I = b.current) == null || I.call(b, M), M;
|
|
66
66
|
}, []), $ = e.totalElements ?? ((q = e.items) == null ? void 0 : q.length) ?? null;
|
|
67
67
|
_(() => {
|
|
68
68
|
var I, 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 ?? {}, w = E.onScroll, N = {
|
|
72
|
+
...E,
|
|
73
73
|
onScroll: () => {
|
|
74
|
-
|
|
74
|
+
w == null || w(), h.current && l();
|
|
75
75
|
}
|
|
76
|
-
},
|
|
77
|
-
u.current && (i.currentElement = Math.min(u.current.currentElement,
|
|
78
|
-
const M = oe(t, (
|
|
76
|
+
}, y = ce(T.current, ((I = d.current) == null ? void 0 : I.length) ?? null), i = new te(t, y, N);
|
|
77
|
+
u.current && (i.currentElement = Math.min(u.current.currentElement, y - 1), i.scrollOffset = u.current.scrollOffset, u.current = null), r.current = { scroller: i, contentEl: n, container: t }, O(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;
|
|
@@ -92,28 +92,28 @@ function le(e) {
|
|
|
92
92
|
const t = requestAnimationFrame(() => l());
|
|
93
93
|
return () => cancelAnimationFrame(t);
|
|
94
94
|
}, [e.items, e.getItem]);
|
|
95
|
-
const B =
|
|
95
|
+
const B = R(
|
|
96
96
|
(t) => {
|
|
97
97
|
const n = r.current;
|
|
98
98
|
return n ? (n.scroller.jumpToElement(t), l()) : null;
|
|
99
99
|
},
|
|
100
100
|
[l]
|
|
101
|
-
), D =
|
|
101
|
+
), D = R(
|
|
102
102
|
(t) => {
|
|
103
103
|
const n = r.current;
|
|
104
104
|
return n ? (n.scroller.handleScrollPercentage(t), l()) : null;
|
|
105
105
|
},
|
|
106
106
|
[l]
|
|
107
|
-
), W =
|
|
107
|
+
), W = R(() => {
|
|
108
108
|
const t = r.current;
|
|
109
109
|
return t ? (t.scroller.reset(), l()) : null;
|
|
110
|
-
}, [l]),
|
|
110
|
+
}, [l]), X = R(() => {
|
|
111
111
|
const t = r.current;
|
|
112
112
|
return t ? (t.scroller.clearAllCaches(), l()) : null;
|
|
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(S.current(P(n), n), t.mount, String(n))
|
|
117
117
|
);
|
|
118
118
|
}), {
|
|
119
119
|
containerRef: c,
|
|
@@ -123,36 +123,39 @@ function le(e) {
|
|
|
123
123
|
jumpToElement: B,
|
|
124
124
|
scrollToPercentage: D,
|
|
125
125
|
reset: W,
|
|
126
|
-
recalculate:
|
|
126
|
+
recalculate: X
|
|
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(
|
|
140
|
-
return
|
|
130
|
+
const { className: r, style: a, "data-testid": u, children: o, ...L } = e, {
|
|
131
|
+
containerRef: O,
|
|
132
|
+
portals: S,
|
|
133
|
+
scroller: d,
|
|
134
|
+
render: v,
|
|
135
|
+
jumpToElement: C,
|
|
136
|
+
scrollToPercentage: h,
|
|
137
|
+
reset: T,
|
|
138
|
+
recalculate: g
|
|
139
|
+
} = le(L);
|
|
140
|
+
return U(
|
|
141
141
|
c,
|
|
142
|
-
() => ({ scroller:
|
|
143
|
-
[
|
|
144
|
-
), /* @__PURE__ */
|
|
142
|
+
() => ({ scroller: d, render: v, jumpToElement: C, scrollToPercentage: h, reset: T, recalculate: g }),
|
|
143
|
+
[d, v, C, h, T, g]
|
|
144
|
+
), /* @__PURE__ */ Y(
|
|
145
145
|
"div",
|
|
146
146
|
{
|
|
147
|
-
ref:
|
|
147
|
+
ref: O,
|
|
148
148
|
className: r,
|
|
149
149
|
"data-testid": u,
|
|
150
150
|
style: { position: "relative", overflow: "hidden", ...a },
|
|
151
|
-
children:
|
|
151
|
+
children: [
|
|
152
|
+
o,
|
|
153
|
+
S
|
|
154
|
+
]
|
|
152
155
|
}
|
|
153
156
|
);
|
|
154
157
|
}
|
|
155
|
-
const de =
|
|
158
|
+
const de = Q(se);
|
|
156
159
|
export {
|
|
157
160
|
de as CeriousScroll,
|
|
158
161
|
Ee as CeriousScrollEngine,
|
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.3",
|
|
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",
|
|
@@ -55,8 +55,10 @@
|
|
|
55
55
|
"demo": "vite --config demo/vite.config.ts",
|
|
56
56
|
"demo:build": "vite build --config demo/vite.config.ts"
|
|
57
57
|
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@ceriousdevtech/cerious-scroll": "^1.0.4"
|
|
60
|
+
},
|
|
58
61
|
"peerDependencies": {
|
|
59
|
-
"@ceriousdevtech/cerious-scroll": "^1.0.1",
|
|
60
62
|
"react": ">=18 <20",
|
|
61
63
|
"react-dom": ">=18 <20"
|
|
62
64
|
},
|
|
@@ -66,11 +68,13 @@
|
|
|
66
68
|
"@types/node": "^22.10.2",
|
|
67
69
|
"@types/react": "^18.3.12",
|
|
68
70
|
"@types/react-dom": "^18.3.1",
|
|
71
|
+
"@types/react-window": "^1.8.8",
|
|
69
72
|
"@vitejs/plugin-react": "^4.3.4",
|
|
70
73
|
"jsdom": "^25.0.1",
|
|
71
74
|
"react": "^18.3.1",
|
|
72
75
|
"react-dom": "^18.3.1",
|
|
73
76
|
"react-router-dom": "^6.30.4",
|
|
77
|
+
"react-window": "^1.8.10",
|
|
74
78
|
"typescript": "^5.6.3",
|
|
75
79
|
"vite": "^5.4.11",
|
|
76
80
|
"vite-plugin-dts": "^4.3.0",
|