@once-ui-system/core 1.4.25 → 1.4.26
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/dist/components/InfiniteScroll.d.ts +4 -1
- package/dist/components/InfiniteScroll.d.ts.map +1 -1
- package/dist/components/InfiniteScroll.js +17 -27
- package/dist/components/InfiniteScroll.js.map +1 -1
- package/dist/data/emoji-data.json +10 -0
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
|
-
import { Row } from "
|
|
2
|
+
import { Row } from ".";
|
|
3
3
|
export interface InfiniteScrollProps<T> extends React.ComponentProps<typeof Row> {
|
|
4
4
|
items: T[];
|
|
5
5
|
renderItem: (item: T, index: number) => ReactNode;
|
|
@@ -9,5 +9,8 @@ export interface InfiniteScrollProps<T> extends React.ComponentProps<typeof Row>
|
|
|
9
9
|
className?: string;
|
|
10
10
|
}
|
|
11
11
|
declare function InfiniteScroll<T>({ items, renderItem, loadMore, loading, threshold, ...flex }: InfiniteScrollProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
declare namespace InfiniteScroll {
|
|
13
|
+
var displayName: string;
|
|
14
|
+
}
|
|
12
15
|
export { InfiniteScroll };
|
|
13
16
|
//# sourceMappingURL=InfiniteScroll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfiniteScroll.d.ts","sourceRoot":"","sources":["../../src/components/InfiniteScroll.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"InfiniteScroll.d.ts","sourceRoot":"","sources":["../../src/components/InfiniteScroll.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AACtE,OAAO,EAAU,GAAG,EAAW,MAAM,GAAG,CAAC;AAEzC,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC;IAC9E,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAClD,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,iBAAS,cAAc,CAAC,CAAC,EAAE,EACzB,KAAK,EACL,UAAU,EACV,QAAQ,EACR,OAAe,EACf,SAAe,EACf,GAAG,IAAI,EACR,EAAE,mBAAmB,CAAC,CAAC,CAAC,2CAoExB;kBA3EQ,cAAc;;;AA8EvB,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React, { useEffect, useRef, useState } from "react";
|
|
4
|
-
import { Spinner } from "
|
|
5
|
-
import { Column } from "./Column";
|
|
6
|
-
import { Row } from "./Row";
|
|
4
|
+
import { Column, Row, Spinner } from ".";
|
|
7
5
|
function InfiniteScroll({ items, renderItem, loadMore, loading = false, threshold = 200, ...flex }) {
|
|
8
6
|
const [hasMore, setHasMore] = useState(true);
|
|
9
7
|
const [isLoading, setIsLoading] = useState(loading);
|
|
10
8
|
const observerRef = useRef(null);
|
|
11
|
-
const
|
|
9
|
+
const sentinelRef = useRef(null);
|
|
10
|
+
// Keep internal loading in sync with prop
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setIsLoading(loading);
|
|
13
|
+
}, [loading]);
|
|
12
14
|
const handleLoadMore = async () => {
|
|
13
15
|
if (isLoading || !hasMore)
|
|
14
16
|
return;
|
|
15
17
|
setIsLoading(true);
|
|
16
18
|
try {
|
|
17
|
-
const
|
|
18
|
-
setHasMore(
|
|
19
|
+
const more = await loadMore();
|
|
20
|
+
setHasMore(more);
|
|
19
21
|
}
|
|
20
22
|
catch (error) {
|
|
21
23
|
console.error("Error loading more items:", error);
|
|
@@ -28,35 +30,23 @@ function InfiniteScroll({ items, renderItem, loadMore, loading = false, threshol
|
|
|
28
30
|
useEffect(() => {
|
|
29
31
|
if (!hasMore || isLoading)
|
|
30
32
|
return;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
observerRef.current = new IntersectionObserver((entries) => {
|
|
35
|
-
const [entry] = entries;
|
|
33
|
+
observerRef.current?.disconnect();
|
|
34
|
+
observerRef.current = new IntersectionObserver(([entry]) => {
|
|
36
35
|
if (entry.isIntersecting) {
|
|
37
36
|
handleLoadMore();
|
|
38
37
|
}
|
|
39
38
|
}, {
|
|
40
39
|
root: null,
|
|
41
40
|
rootMargin: `0px 0px ${threshold}px 0px`,
|
|
42
|
-
threshold: 0
|
|
41
|
+
threshold: 0,
|
|
43
42
|
});
|
|
44
|
-
if (
|
|
45
|
-
observerRef.current.observe(
|
|
43
|
+
if (sentinelRef.current) {
|
|
44
|
+
observerRef.current.observe(sentinelRef.current);
|
|
46
45
|
}
|
|
47
|
-
return () =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}, [items, hasMore, isLoading]);
|
|
53
|
-
return (_jsxs(_Fragment, { children: [items.map((item, index) => {
|
|
54
|
-
// If this is the last item, attach the ref
|
|
55
|
-
if (index === items.length - 1) {
|
|
56
|
-
return (_jsx(Row, { ref: lastItemRef, ...flex, children: renderItem(item, index) }, index));
|
|
57
|
-
}
|
|
58
|
-
return _jsx(React.Fragment, { children: renderItem(item, index) }, index);
|
|
59
|
-
}), isLoading && (_jsx(Column, { fillWidth: true, horizontal: "center", padding: "24", children: _jsx(Spinner, { size: "m" }) }))] }));
|
|
46
|
+
return () => observerRef.current?.disconnect();
|
|
47
|
+
}, [items.length, hasMore, isLoading, threshold]);
|
|
48
|
+
return (_jsxs(_Fragment, { children: [items.map((item, index) => (_jsx(React.Fragment, { children: renderItem(item, index) }, index))), _jsx(Row, { ...flex, children: _jsx("div", { ref: sentinelRef, style: { height: 1, width: 1 } }) }), isLoading && (_jsx(Column, { fillWidth: true, horizontal: "center", padding: "24", children: _jsx(Spinner, { size: "m" }) }))] }));
|
|
60
49
|
}
|
|
50
|
+
InfiniteScroll.displayName = "InfiniteScroll";
|
|
61
51
|
export { InfiniteScroll };
|
|
62
52
|
//# sourceMappingURL=InfiniteScroll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfiniteScroll.js","sourceRoot":"","sources":["../../src/components/InfiniteScroll.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,EAAE,EAAa,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"InfiniteScroll.js","sourceRoot":"","sources":["../../src/components/InfiniteScroll.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,EAAE,EAAa,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC;AAWzC,SAAS,cAAc,CAAI,EACzB,KAAK,EACL,UAAU,EACV,QAAQ,EACR,OAAO,GAAG,KAAK,EACf,SAAS,GAAG,GAAG,EACf,GAAG,IAAI,EACgB;IACvB,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,WAA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