@1771technologies/lytenyte-pro 2.2.0 → 2.2.1
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.
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ServerData } from "../server-data";
|
|
2
2
|
import type { DataRequest } from "../types";
|
|
3
|
-
export declare function useOnViewChange<T>(source: ServerData, requestsForView: DataRequest[], setRequestsForView: (v: DataRequest[]) => void): (view: import("@1771technologies/lytenyte-shared").SpanLayout) => void;
|
|
3
|
+
export declare function useOnViewChange<T>(source: ServerData, requestsForView: DataRequest[], setRequestsForView: (v: DataRequest[]) => void, debounceDuration: number): (view: import("@1771technologies/lytenyte-shared").SpanLayout) => void;
|
|
@@ -1,13 +1,37 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
1
2
|
import { useEvent } from "@1771technologies/lytenyte-core/internal";
|
|
2
3
|
import { equal } from "@1771technologies/js-utils";
|
|
3
|
-
export function useOnViewChange(source, requestsForView, setRequestsForView) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export function useOnViewChange(source, requestsForView, setRequestsForView, debounceDuration) {
|
|
5
|
+
const timerRef = useRef(null);
|
|
6
|
+
const pendingBoundsRef = useRef(null);
|
|
7
|
+
// Reads latest requestsForView/setRequestsForView at call time (via useEvent), so the
|
|
8
|
+
// timer always flushes against the current state even if renders occurred while pending.
|
|
9
|
+
const flush = useEvent(() => {
|
|
10
|
+
const bounds = pendingBoundsRef.current;
|
|
11
|
+
if (!bounds)
|
|
12
|
+
return;
|
|
13
|
+
pendingBoundsRef.current = null;
|
|
14
|
+
source.rowViewBounds = bounds;
|
|
7
15
|
const requests = source.requestsForView();
|
|
8
|
-
if (equal(requests, requestsForView))
|
|
16
|
+
if (!equal(requests, requestsForView))
|
|
17
|
+
setRequestsForView(requests);
|
|
18
|
+
});
|
|
19
|
+
const onViewChange = useEvent((bounds) => {
|
|
20
|
+
if (debounceDuration <= 0) {
|
|
21
|
+
source.rowViewBounds = [bounds.rowCenterStart, bounds.rowCenterEnd];
|
|
22
|
+
const requests = source.requestsForView();
|
|
23
|
+
if (!equal(requests, requestsForView))
|
|
24
|
+
setRequestsForView(requests);
|
|
9
25
|
return;
|
|
10
|
-
|
|
26
|
+
}
|
|
27
|
+
// Store the latest bounds so the timer always flushes with the final scroll position, not an intermediate one.
|
|
28
|
+
pendingBoundsRef.current = [bounds.rowCenterStart, bounds.rowCenterEnd];
|
|
29
|
+
if (timerRef.current !== null)
|
|
30
|
+
clearTimeout(timerRef.current);
|
|
31
|
+
timerRef.current = setTimeout(() => {
|
|
32
|
+
timerRef.current = null;
|
|
33
|
+
flush();
|
|
34
|
+
}, debounceDuration);
|
|
11
35
|
});
|
|
12
36
|
return onViewChange;
|
|
13
37
|
}
|
|
@@ -34,7 +34,8 @@ export function useServerDataSource(props) {
|
|
|
34
34
|
const rowParents = useRowParents(source);
|
|
35
35
|
const rowsBetween = useRowsBetween(source);
|
|
36
36
|
const rowChildren = useRowChildren(source);
|
|
37
|
-
|
|
37
|
+
// TODO @Lee expose a scroll debounce prop.
|
|
38
|
+
const onViewChange = useOnViewChange(source, state.requestsForView, state.setRequestsForView, 200);
|
|
38
39
|
const idSpec = useEvent((id) => {
|
|
39
40
|
const node = source.tree.rowIdToNode.get(id);
|
|
40
41
|
if (!node || node.kind === "leaf")
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1771technologies/lytenyte-pro",
|
|
3
3
|
"description": "Blazingly fast headless React data grid with 100s of features.",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "COMMERCIAL",
|
|
7
7
|
"files": [
|
|
@@ -85,14 +85,14 @@
|
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@1771technologies/
|
|
89
|
-
"@1771technologies/
|
|
90
|
-
"@1771technologies/lytenyte-
|
|
91
|
-
"@1771technologies/js-utils": "2.2.
|
|
92
|
-
"@1771technologies/lytenyte-
|
|
88
|
+
"@1771technologies/lytenyte-shared": "2.2.1",
|
|
89
|
+
"@1771technologies/dom-utils": "2.2.1",
|
|
90
|
+
"@1771technologies/lytenyte-core": "2.2.1",
|
|
91
|
+
"@1771technologies/js-utils": "2.2.1",
|
|
92
|
+
"@1771technologies/lytenyte-design": "2.2.1"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@1771technologies/grid-sample-data": "2.2.
|
|
95
|
+
"@1771technologies/grid-sample-data": "2.2.1"
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
98
98
|
"react": "18.0.0 || ^19.0.0",
|