@deskpro/deskpro-ui 5.0.2 → 5.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/dist/cjs/components/Infinite/Infinite.js +58 -98
- package/dist/cjs/components/Infinite/Infinite.js.map +1 -1
- package/dist/cjs/components/Infinite/ObservedDiv.js +2 -2
- package/dist/cjs/components/Infinite/ObservedDiv.js.map +1 -1
- package/dist/cjs/components/Infinite/styles.js.map +1 -1
- package/dist/deskpro-ui.d.ts +2 -4
- package/dist/esm/components/Infinite/Infinite.js +59 -99
- package/dist/esm/components/Infinite/Infinite.js.map +1 -1
- package/dist/esm/components/Infinite/ObservedDiv.js +2 -2
- package/dist/esm/components/Infinite/ObservedDiv.js.map +1 -1
- package/dist/esm/components/Infinite/styles.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/utils/useInView.js +0 -27
- package/dist/cjs/utils/useInView.js.map +0 -1
- package/dist/esm/utils/useInView.js +0 -25
- package/dist/esm/utils/useInView.js.map +0 -1
|
@@ -5,6 +5,7 @@ const React = require("react");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const use_debounce_1 = require("use-debounce");
|
|
7
7
|
const layout_1 = require("../../layout");
|
|
8
|
+
const ObservedDiv_1 = require("./ObservedDiv");
|
|
8
9
|
const Spinner_1 = require("../Spinner");
|
|
9
10
|
const Button_1 = require("../Button");
|
|
10
11
|
const ts_pattern_1 = require("ts-pattern");
|
|
@@ -12,10 +13,10 @@ const Scrollbar_1 = require("../Scrollbar");
|
|
|
12
13
|
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
13
14
|
const styled_components_1 = require("styled-components");
|
|
14
15
|
const dpName_1 = require("../../utils/dpName");
|
|
15
|
-
const styles_1 = require("./styles");
|
|
16
|
-
const useInView_1 = require("../../utils/useInView");
|
|
17
16
|
// Controls the scroll when the data changes and for user wheel events
|
|
18
|
-
function useScrollControl(
|
|
17
|
+
function useScrollControl(children, reverse, anchor, scrollSideEffect, outerRef) {
|
|
18
|
+
const innerRef = (0, react_1.useRef)(null);
|
|
19
|
+
const ref = outerRef !== null && outerRef !== void 0 ? outerRef : innerRef;
|
|
19
20
|
const firstMount = (0, react_1.useRef)(true);
|
|
20
21
|
// Used to check if the scroll should be forced to the edges on data updates
|
|
21
22
|
const shouldAttachScroll = (0, react_1.useRef)(true);
|
|
@@ -23,50 +24,39 @@ function useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scroll
|
|
|
23
24
|
const lastKnownScrollOffset = (0, react_1.useRef)();
|
|
24
25
|
// Forces the scrollbar to the top or bottom on first render
|
|
25
26
|
(0, react_1.useEffect)(() => {
|
|
26
|
-
if (
|
|
27
|
+
if (ref.current && shouldAttachScroll.current) {
|
|
27
28
|
if (reverse) {
|
|
28
|
-
|
|
29
|
-
top: (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.clientHeight) - 4,
|
|
30
|
-
});
|
|
29
|
+
ref.current.scrollTo({ top: ref.current.scrollHeight });
|
|
31
30
|
}
|
|
32
31
|
else {
|
|
33
|
-
|
|
32
|
+
ref.current.scrollTo(0, 0);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
}, [
|
|
37
|
-
// this will update the scroll position when a fetch has been made while scrolling up
|
|
38
|
-
// this is to stop the page jumping once a request has been made
|
|
39
|
-
const setScrollTo = (0, react_1.useCallback)(() => {
|
|
40
|
-
var _a, _b, _c;
|
|
41
|
-
if (!shouldAttachScroll.current &&
|
|
42
|
-
typeof lastKnownScrollOffset.current === "number" &&
|
|
43
|
-
lastFetchDirection === "top" &&
|
|
44
|
-
topStatus !== "end" &&
|
|
45
|
-
topStatus !== "end-with-force") {
|
|
46
|
-
// set position using saved offset
|
|
47
|
-
(_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
|
|
48
|
-
top: Math.abs(lastKnownScrollOffset.current -
|
|
49
|
-
(((_b = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _b === void 0 ? void 0 : _b.scrollHeight) - ((_c = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _c === void 0 ? void 0 : _c.clientHeight))),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
// save current position offset
|
|
53
|
-
if (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) {
|
|
54
|
-
lastKnownScrollOffset.current = Math.abs((scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollTop) -
|
|
55
|
-
((scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.clientHeight)));
|
|
56
|
-
}
|
|
57
|
-
}, [lastFetchDirection, scrollRef, topStatus]);
|
|
35
|
+
}, [ref, reverse]);
|
|
58
36
|
// On render will force the scroll bar to the top or bottom, unless detached
|
|
59
37
|
(0, react_1.useLayoutEffect)(() => {
|
|
60
38
|
if (firstMount.current || !anchor) {
|
|
61
39
|
firstMount.current = false;
|
|
62
40
|
return;
|
|
63
41
|
}
|
|
64
|
-
if (!
|
|
42
|
+
if (!ref.current)
|
|
65
43
|
return;
|
|
66
|
-
|
|
44
|
+
if (shouldAttachScroll.current) {
|
|
45
|
+
if (reverse) {
|
|
46
|
+
ref.current.scrollTo({ top: ref.current.scrollHeight });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
ref.current.scrollTo({ top: 0 });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (typeof lastKnownScrollOffset.current === "number" && reverse) {
|
|
53
|
+
ref.current.scrollTo({
|
|
54
|
+
top: Math.abs(lastKnownScrollOffset.current - (ref.current.scrollHeight - ref.current.clientHeight)),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
67
57
|
});
|
|
68
58
|
const debouncedSetIsAttached = (0, use_debounce_1.useDebouncedCallback)(() => {
|
|
69
|
-
if (typeof lastKnownScrollOffset.current === "number" &&
|
|
59
|
+
if (typeof lastKnownScrollOffset.current === "number" && ref.current) {
|
|
70
60
|
if (shouldAttachScroll.current !== isAttached && lastKnownScrollOffset.current > 300) {
|
|
71
61
|
setIsAttached(shouldAttachScroll.current);
|
|
72
62
|
}
|
|
@@ -77,20 +67,16 @@ function useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scroll
|
|
|
77
67
|
}
|
|
78
68
|
}, 100, { trailing: true, leading: true });
|
|
79
69
|
// On scroll events will attach or detach the scroll position from the top or bottom
|
|
80
|
-
const handleScroll = (0, react_1.useCallback)((
|
|
81
|
-
if (
|
|
70
|
+
const handleScroll = (0, react_1.useCallback)(() => {
|
|
71
|
+
if (ref.current &&
|
|
82
72
|
!isAttached &&
|
|
83
|
-
|
|
84
|
-
(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - 2) {
|
|
73
|
+
ref.current.scrollTop + ref.current.offsetHeight > ref.current.scrollHeight - 2) {
|
|
85
74
|
setIsAttached(true);
|
|
86
75
|
}
|
|
87
|
-
if (!
|
|
88
|
-
scrollSideEffect === null || scrollSideEffect === void 0 ? void 0 : scrollSideEffect(event);
|
|
76
|
+
if (!ref.current)
|
|
89
77
|
return;
|
|
90
|
-
}
|
|
91
78
|
if (reverse) {
|
|
92
|
-
if (
|
|
93
|
-
(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.clientHeight)) {
|
|
79
|
+
if (ref.current.scrollTop < ref.current.scrollHeight - ref.current.clientHeight) {
|
|
94
80
|
shouldAttachScroll.current = false;
|
|
95
81
|
}
|
|
96
82
|
else {
|
|
@@ -98,83 +84,48 @@ function useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scroll
|
|
|
98
84
|
}
|
|
99
85
|
}
|
|
100
86
|
else {
|
|
101
|
-
if (
|
|
87
|
+
if (ref.current.scrollTop > 0) {
|
|
102
88
|
shouldAttachScroll.current = false;
|
|
103
89
|
}
|
|
104
90
|
else {
|
|
105
91
|
shouldAttachScroll.current = true;
|
|
106
92
|
}
|
|
107
93
|
}
|
|
108
|
-
|
|
94
|
+
scrollSideEffect === null || scrollSideEffect === void 0 ? void 0 : scrollSideEffect();
|
|
95
|
+
lastKnownScrollOffset.current = Math.abs(ref.current.scrollTop - (ref.current.scrollHeight - ref.current.clientHeight));
|
|
109
96
|
debouncedSetIsAttached();
|
|
110
|
-
|
|
111
|
-
}, [scrollRef, isAttached, reverse, scrollSideEffect, setScrollTo, debouncedSetIsAttached]);
|
|
97
|
+
}, [ref, isAttached, reverse, scrollSideEffect, debouncedSetIsAttached]);
|
|
112
98
|
const reAttach = (0, react_1.useCallback)(() => {
|
|
113
99
|
shouldAttachScroll.current = true;
|
|
114
100
|
setIsAttached(true);
|
|
115
|
-
if (
|
|
101
|
+
if (ref.current) {
|
|
116
102
|
if (reverse) {
|
|
117
|
-
|
|
103
|
+
ref.current.scrollTo({ top: ref.current.scrollHeight });
|
|
118
104
|
}
|
|
119
105
|
else {
|
|
120
|
-
|
|
106
|
+
ref.current.scrollTo(0, 0);
|
|
121
107
|
}
|
|
122
108
|
}
|
|
123
|
-
}, [
|
|
109
|
+
}, [ref, reverse]);
|
|
124
110
|
return {
|
|
125
|
-
ref:
|
|
126
|
-
handleScroll,
|
|
111
|
+
ref: ref,
|
|
112
|
+
onScroll: handleScroll,
|
|
127
113
|
isAttached,
|
|
128
114
|
reAttach,
|
|
129
115
|
};
|
|
130
116
|
}
|
|
131
|
-
const EndOfScroll = ({ status, fetchMoreText, fetchMore }) => (0, ts_pattern_1.match)({ status, hasFetchMore: !!fetchMore })
|
|
132
|
-
.with({ hasFetchMore: false }, () => null)
|
|
133
|
-
.with({ status: "loading" }, { status: "hasNextPage" }, () => (React.createElement(layout_1.Stack, { justify: "center", align: "center", padding: 5, style: { minHeight: 60, margin: "-1px 0" } },
|
|
134
|
-
React.createElement(Spinner_1.Spinner, null))))
|
|
135
|
-
.with({ status: "end-with-force", hasFetchMore: true }, () => (React.createElement(layout_1.Stack, { justify: "center", align: "center", padding: 5 },
|
|
136
|
-
React.createElement(Button_1.Button, { intent: "tertiary", onClick: fetchMore, text: fetchMoreText }))))
|
|
137
|
-
.otherwise(() => null);
|
|
138
117
|
/**
|
|
139
118
|
* Will render a scrollbar container that uses an intersection observer to watch for when
|
|
140
119
|
* the container has scrolled to the top or bottom.
|
|
141
120
|
* @public
|
|
142
121
|
*/
|
|
143
|
-
function Infinite({ children, reverse = false, anchor = false, onFetchMore,
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const topStatus = (0, react_1.useMemo)(() => (reverse ? status : startStatus), [reverse, startStatus, status]);
|
|
149
|
-
const bottomStatus = (0, react_1.useMemo)(() => (reverse ? startStatus : status), [reverse, startStatus, status]);
|
|
150
|
-
const { ref, isAttached, handleScroll, reAttach } = useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scrollSideEffect, topStatus);
|
|
151
|
-
const { inView: topInView, ref: topRef } = (0, useInView_1.default)();
|
|
152
|
-
const { inView: bottomInView, ref: bottomRef } = (0, useInView_1.default)();
|
|
153
|
-
(0, react_1.useEffect)(() => {
|
|
154
|
-
setLastFetchDirection("top");
|
|
155
|
-
if (topInView && topStatus !== "loading") {
|
|
156
|
-
if (topFetch && (!topStatus || topStatus !== "end")) {
|
|
157
|
-
topFetch();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}, [onFetchMore, onFetchMoreStart, reverse, startStatus, status, topFetch, topInView, topStatus]);
|
|
161
|
-
(0, react_1.useEffect)(() => {
|
|
162
|
-
setLastFetchDirection("bottom");
|
|
163
|
-
if (bottomInView && bottomStatus !== "loading") {
|
|
164
|
-
if (bottomFetch && (!bottomStatus || bottomStatus !== "end")) {
|
|
165
|
-
bottomFetch();
|
|
166
|
-
}
|
|
122
|
+
function Infinite({ children, reverse = false, anchor = false, onFetchMore, status, maxHeight = "100%", scrollSideEffect, width, fetchMoreText, autoscrollText, scrollRef, justify, }) {
|
|
123
|
+
const { ref, isAttached, onScroll, reAttach } = useScrollControl(children, reverse, anchor, scrollSideEffect, scrollRef);
|
|
124
|
+
const handleIntersect = (0, react_1.useCallback)(() => {
|
|
125
|
+
if (onFetchMore && (!status || status !== "end")) {
|
|
126
|
+
onFetchMore();
|
|
167
127
|
}
|
|
168
|
-
}, [
|
|
169
|
-
bottomFetch,
|
|
170
|
-
bottomInView,
|
|
171
|
-
bottomStatus,
|
|
172
|
-
onFetchMore,
|
|
173
|
-
onFetchMoreStart,
|
|
174
|
-
reverse,
|
|
175
|
-
topStatus,
|
|
176
|
-
status,
|
|
177
|
-
]);
|
|
128
|
+
}, [onFetchMore, status]);
|
|
178
129
|
const theme = (0, styled_components_1.useTheme)().colors;
|
|
179
130
|
return (React.createElement(layout_1.Stack, { ...(0, dpName_1.dpNameProp)("Infinite"), maxHeight: "100%", style: {
|
|
180
131
|
position: "relative",
|
|
@@ -182,12 +133,21 @@ function Infinite({ children, reverse = false, anchor = false, onFetchMore, onFe
|
|
|
182
133
|
height: "100%",
|
|
183
134
|
width,
|
|
184
135
|
}, justify: justify, align: "stretch", vertical: true },
|
|
185
|
-
React.createElement(Scrollbar_1.Scrollbar, { autoHide: true, style: { maxHeight: maxHeight }, scrollableNodeProps: { ref: ref, onScroll:
|
|
186
|
-
|
|
187
|
-
|
|
136
|
+
React.createElement(Scrollbar_1.Scrollbar, { autoHide: true, style: { maxHeight: maxHeight }, scrollableNodeProps: { ref: ref, onScroll: onScroll } },
|
|
137
|
+
reverse &&
|
|
138
|
+
status &&
|
|
139
|
+
(0, ts_pattern_1.match)(status)
|
|
140
|
+
.with("loading", "hasNextPage", () => (React.createElement(layout_1.Stack, { justify: "center", align: "center", padding: 5, style: { minHeight: 60 } },
|
|
141
|
+
React.createElement(Spinner_1.Spinner, null))))
|
|
142
|
+
.with("end", () => null)
|
|
143
|
+
.with("end-with-force", () => (React.createElement(layout_1.Stack, { justify: "center", align: "center", padding: 5 },
|
|
144
|
+
React.createElement(Button_1.Button, { intent: "tertiary", onClick: onFetchMore, text: fetchMoreText }))))
|
|
145
|
+
.exhaustive(),
|
|
146
|
+
reverse && React.createElement(ObservedDiv_1.ObservedDiv, { onIntersect: handleIntersect }),
|
|
188
147
|
children,
|
|
189
|
-
React.createElement(
|
|
190
|
-
|
|
148
|
+
!reverse && React.createElement(ObservedDiv_1.ObservedDiv, { onIntersect: handleIntersect }),
|
|
149
|
+
!reverse && (status === "loading" || status === "hasNextPage") && (React.createElement(layout_1.Stack, { justify: "center", align: "center", padding: 5, style: { minHeight: 60 } },
|
|
150
|
+
React.createElement(Spinner_1.Spinner, null)))),
|
|
191
151
|
anchor && !isAttached && (React.createElement(Button_1.OverlayButton, { placement: reverse ? "middle-bottom" : "middle-top", text: autoscrollText, onClick: reAttach, icon: { icon: free_solid_svg_icons_1.faAngleDoubleDown, size: 14 }, rightIcon: { icon: free_solid_svg_icons_1.faAngleDoubleDown, size: 14 }, style: { color: theme.brandShade100 } }))));
|
|
192
152
|
}
|
|
193
153
|
exports.Infinite = Infinite;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Infinite.js","sourceRoot":"","sources":["../../../../src/components/Infinite/Infinite.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"Infinite.js","sourceRoot":"","sources":["../../../../src/components/Infinite/Infinite.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,iCAQe;AACf,+CAAoD;AACpD,yCAAiD;AAEjD,+CAA4C;AAC5C,wCAAqC;AACrC,sCAAkD;AAClD,2CAAmC;AACnC,4CAAyC;AAEzC,4EAAsE;AACtE,yDAA6C;AAC7C,+CAAgD;AAyBhD,sEAAsE;AACtE,SAAS,gBAAgB,CACvB,QAAmB,EACnB,OAAiB,EACjB,MAAgB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AAC,YAAY,EACnD,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,EAAE,IAAI,EAAE,wCAAiB,EAAE,IAAI,EAAE,EAAE,EAAE,EAC3C,SAAS,EAAE,EAAE,IAAI,EAAE,wCAAiB,EAAE,IAAI,EAAE,EAAE,EAAE,EAChD,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,EAAE,GACrC,CACH,CACK,CACT,CAAC;AACJ,CAAC;AAxFD,4BAwFC"}
|
|
@@ -9,7 +9,7 @@ const dpName_1 = require("../../utils/dpName");
|
|
|
9
9
|
* Component that positions absolutely to the top or bottom of the container
|
|
10
10
|
* and emits an event if it intersects with the view port using `IntersectionObserver`
|
|
11
11
|
*/
|
|
12
|
-
function ObservedDiv({ onIntersect }) {
|
|
12
|
+
function ObservedDiv({ onIntersect, reverse = false }) {
|
|
13
13
|
const ref = (0, react_1.useRef)(null);
|
|
14
14
|
const callback = (0, react_1.useRef)(onIntersect);
|
|
15
15
|
(0, react_1.useLayoutEffect)(() => {
|
|
@@ -26,7 +26,7 @@ function ObservedDiv({ onIntersect }) {
|
|
|
26
26
|
observer.observe(ref.current);
|
|
27
27
|
return () => observer.disconnect();
|
|
28
28
|
}, []);
|
|
29
|
-
return React.createElement(S.Observed, { ...(0, dpName_1.dpNameProp)("ObservedDiv"), "data-testid": "observer", ref: ref });
|
|
29
|
+
return (React.createElement(S.Observed, { ...(0, dpName_1.dpNameProp)("ObservedDiv"), "data-testid": "observer", position: reverse ? "top" : "bottom", ref: ref }));
|
|
30
30
|
}
|
|
31
31
|
exports.ObservedDiv = ObservedDiv;
|
|
32
32
|
//# sourceMappingURL=ObservedDiv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservedDiv.js","sourceRoot":"","sources":["../../../../src/components/Infinite/ObservedDiv.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,iCAAgD;AAChD,8BAA8B;AAC9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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../src/components/Infinite/styles.tsx"],"names":[],"mappings":";;;AAAA,yDAAuC;AAE1B,QAAA,QAAQ,GAAG,2BAAM,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../src/components/Infinite/styles.tsx"],"names":[],"mappings":";;;AAAA,yDAAuC;AAE1B,QAAA,QAAQ,GAAG,2BAAM,CAAC,GAAG,CAAgC;;;CAGjE,CAAC"}
|
package/dist/deskpro-ui.d.ts
CHANGED
|
@@ -3471,7 +3471,7 @@ export declare interface ImageAvatarProps {
|
|
|
3471
3471
|
* the container has scrolled to the top or bottom.
|
|
3472
3472
|
* @public
|
|
3473
3473
|
*/
|
|
3474
|
-
export declare function Infinite({ children, reverse, anchor, onFetchMore,
|
|
3474
|
+
export declare function Infinite({ children, reverse, anchor, onFetchMore, status, maxHeight, scrollSideEffect, width, fetchMoreText, autoscrollText, scrollRef, justify, }: InfiniteProps): JSX.Element;
|
|
3475
3475
|
|
|
3476
3476
|
/**
|
|
3477
3477
|
* @public
|
|
@@ -3483,12 +3483,10 @@ export declare interface InfiniteProps {
|
|
|
3483
3483
|
/** Whether to render the Scroll To Start button */
|
|
3484
3484
|
anchor?: boolean;
|
|
3485
3485
|
onFetchMore?: () => void;
|
|
3486
|
-
onFetchMoreStart?: () => void;
|
|
3487
3486
|
status?: "loading" | "hasNextPage" | "end" | "end-with-force";
|
|
3488
|
-
startStatus?: "loading" | "hasNextPage" | "end" | "end-with-force";
|
|
3489
3487
|
maxHeight?: Property.MaxHeight;
|
|
3490
3488
|
/** Used in <Dropdown /> to hide suboptions on scroll */
|
|
3491
|
-
scrollSideEffect?: (
|
|
3489
|
+
scrollSideEffect?: () => void;
|
|
3492
3490
|
width?: string;
|
|
3493
3491
|
/** Align the list, you probably want flex-end if the list is reversed so it aligns to the bottom of the viewport */
|
|
3494
3492
|
justify?: StackProps["justify"];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { useCallback, useEffect, useLayoutEffect,
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
3
3
|
import { useDebouncedCallback } from "use-debounce";
|
|
4
4
|
import { Stack } from "../../layout";
|
|
5
|
+
import { ObservedDiv } from "./ObservedDiv";
|
|
5
6
|
import { Spinner } from "../Spinner";
|
|
6
7
|
import { Button, OverlayButton } from "../Button";
|
|
7
8
|
import { match } from "ts-pattern";
|
|
@@ -9,10 +10,10 @@ import { Scrollbar } from "../Scrollbar";
|
|
|
9
10
|
import { faAngleDoubleDown } from "@fortawesome/free-solid-svg-icons";
|
|
10
11
|
import { useTheme } from "styled-components";
|
|
11
12
|
import { dpNameProp } from "../../utils/dpName";
|
|
12
|
-
import { Observed } from "./styles";
|
|
13
|
-
import useInView from "../../utils/useInView";
|
|
14
13
|
// Controls the scroll when the data changes and for user wheel events
|
|
15
|
-
function useScrollControl(
|
|
14
|
+
function useScrollControl(children, reverse, anchor, scrollSideEffect, outerRef) {
|
|
15
|
+
const innerRef = useRef(null);
|
|
16
|
+
const ref = outerRef !== null && outerRef !== void 0 ? outerRef : innerRef;
|
|
16
17
|
const firstMount = useRef(true);
|
|
17
18
|
// Used to check if the scroll should be forced to the edges on data updates
|
|
18
19
|
const shouldAttachScroll = useRef(true);
|
|
@@ -20,50 +21,39 @@ function useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scroll
|
|
|
20
21
|
const lastKnownScrollOffset = useRef();
|
|
21
22
|
// Forces the scrollbar to the top or bottom on first render
|
|
22
23
|
useEffect(() => {
|
|
23
|
-
if (
|
|
24
|
+
if (ref.current && shouldAttachScroll.current) {
|
|
24
25
|
if (reverse) {
|
|
25
|
-
|
|
26
|
-
top: (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.clientHeight) - 4,
|
|
27
|
-
});
|
|
26
|
+
ref.current.scrollTo({ top: ref.current.scrollHeight });
|
|
28
27
|
}
|
|
29
28
|
else {
|
|
30
|
-
|
|
29
|
+
ref.current.scrollTo(0, 0);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
}, [
|
|
34
|
-
// this will update the scroll position when a fetch has been made while scrolling up
|
|
35
|
-
// this is to stop the page jumping once a request has been made
|
|
36
|
-
const setScrollTo = useCallback(() => {
|
|
37
|
-
var _a, _b, _c;
|
|
38
|
-
if (!shouldAttachScroll.current &&
|
|
39
|
-
typeof lastKnownScrollOffset.current === "number" &&
|
|
40
|
-
lastFetchDirection === "top" &&
|
|
41
|
-
topStatus !== "end" &&
|
|
42
|
-
topStatus !== "end-with-force") {
|
|
43
|
-
// set position using saved offset
|
|
44
|
-
(_a = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
|
|
45
|
-
top: Math.abs(lastKnownScrollOffset.current -
|
|
46
|
-
(((_b = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _b === void 0 ? void 0 : _b.scrollHeight) - ((_c = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) === null || _c === void 0 ? void 0 : _c.clientHeight))),
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// save current position offset
|
|
50
|
-
if (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current) {
|
|
51
|
-
lastKnownScrollOffset.current = Math.abs((scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollTop) -
|
|
52
|
-
((scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.clientHeight)));
|
|
53
|
-
}
|
|
54
|
-
}, [lastFetchDirection, scrollRef, topStatus]);
|
|
32
|
+
}, [ref, reverse]);
|
|
55
33
|
// On render will force the scroll bar to the top or bottom, unless detached
|
|
56
34
|
useLayoutEffect(() => {
|
|
57
35
|
if (firstMount.current || !anchor) {
|
|
58
36
|
firstMount.current = false;
|
|
59
37
|
return;
|
|
60
38
|
}
|
|
61
|
-
if (!
|
|
39
|
+
if (!ref.current)
|
|
62
40
|
return;
|
|
63
|
-
|
|
41
|
+
if (shouldAttachScroll.current) {
|
|
42
|
+
if (reverse) {
|
|
43
|
+
ref.current.scrollTo({ top: ref.current.scrollHeight });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ref.current.scrollTo({ top: 0 });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (typeof lastKnownScrollOffset.current === "number" && reverse) {
|
|
50
|
+
ref.current.scrollTo({
|
|
51
|
+
top: Math.abs(lastKnownScrollOffset.current - (ref.current.scrollHeight - ref.current.clientHeight)),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
64
54
|
});
|
|
65
55
|
const debouncedSetIsAttached = useDebouncedCallback(() => {
|
|
66
|
-
if (typeof lastKnownScrollOffset.current === "number" &&
|
|
56
|
+
if (typeof lastKnownScrollOffset.current === "number" && ref.current) {
|
|
67
57
|
if (shouldAttachScroll.current !== isAttached && lastKnownScrollOffset.current > 300) {
|
|
68
58
|
setIsAttached(shouldAttachScroll.current);
|
|
69
59
|
}
|
|
@@ -74,20 +64,16 @@ function useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scroll
|
|
|
74
64
|
}
|
|
75
65
|
}, 100, { trailing: true, leading: true });
|
|
76
66
|
// On scroll events will attach or detach the scroll position from the top or bottom
|
|
77
|
-
const handleScroll = useCallback((
|
|
78
|
-
if (
|
|
67
|
+
const handleScroll = useCallback(() => {
|
|
68
|
+
if (ref.current &&
|
|
79
69
|
!isAttached &&
|
|
80
|
-
|
|
81
|
-
(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - 2) {
|
|
70
|
+
ref.current.scrollTop + ref.current.offsetHeight > ref.current.scrollHeight - 2) {
|
|
82
71
|
setIsAttached(true);
|
|
83
72
|
}
|
|
84
|
-
if (!
|
|
85
|
-
scrollSideEffect === null || scrollSideEffect === void 0 ? void 0 : scrollSideEffect(event);
|
|
73
|
+
if (!ref.current)
|
|
86
74
|
return;
|
|
87
|
-
}
|
|
88
75
|
if (reverse) {
|
|
89
|
-
if (
|
|
90
|
-
(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.scrollHeight) - (scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.clientHeight)) {
|
|
76
|
+
if (ref.current.scrollTop < ref.current.scrollHeight - ref.current.clientHeight) {
|
|
91
77
|
shouldAttachScroll.current = false;
|
|
92
78
|
}
|
|
93
79
|
else {
|
|
@@ -95,83 +81,48 @@ function useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scroll
|
|
|
95
81
|
}
|
|
96
82
|
}
|
|
97
83
|
else {
|
|
98
|
-
if (
|
|
84
|
+
if (ref.current.scrollTop > 0) {
|
|
99
85
|
shouldAttachScroll.current = false;
|
|
100
86
|
}
|
|
101
87
|
else {
|
|
102
88
|
shouldAttachScroll.current = true;
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
|
-
|
|
91
|
+
scrollSideEffect === null || scrollSideEffect === void 0 ? void 0 : scrollSideEffect();
|
|
92
|
+
lastKnownScrollOffset.current = Math.abs(ref.current.scrollTop - (ref.current.scrollHeight - ref.current.clientHeight));
|
|
106
93
|
debouncedSetIsAttached();
|
|
107
|
-
|
|
108
|
-
}, [scrollRef, isAttached, reverse, scrollSideEffect, setScrollTo, debouncedSetIsAttached]);
|
|
94
|
+
}, [ref, isAttached, reverse, scrollSideEffect, debouncedSetIsAttached]);
|
|
109
95
|
const reAttach = useCallback(() => {
|
|
110
96
|
shouldAttachScroll.current = true;
|
|
111
97
|
setIsAttached(true);
|
|
112
|
-
if (
|
|
98
|
+
if (ref.current) {
|
|
113
99
|
if (reverse) {
|
|
114
|
-
|
|
100
|
+
ref.current.scrollTo({ top: ref.current.scrollHeight });
|
|
115
101
|
}
|
|
116
102
|
else {
|
|
117
|
-
|
|
103
|
+
ref.current.scrollTo(0, 0);
|
|
118
104
|
}
|
|
119
105
|
}
|
|
120
|
-
}, [
|
|
106
|
+
}, [ref, reverse]);
|
|
121
107
|
return {
|
|
122
|
-
ref:
|
|
123
|
-
handleScroll,
|
|
108
|
+
ref: ref,
|
|
109
|
+
onScroll: handleScroll,
|
|
124
110
|
isAttached,
|
|
125
111
|
reAttach,
|
|
126
112
|
};
|
|
127
113
|
}
|
|
128
|
-
const EndOfScroll = ({ status, fetchMoreText, fetchMore }) => match({ status, hasFetchMore: !!fetchMore })
|
|
129
|
-
.with({ hasFetchMore: false }, () => null)
|
|
130
|
-
.with({ status: "loading" }, { status: "hasNextPage" }, () => (React.createElement(Stack, { justify: "center", align: "center", padding: 5, style: { minHeight: 60, margin: "-1px 0" } },
|
|
131
|
-
React.createElement(Spinner, null))))
|
|
132
|
-
.with({ status: "end-with-force", hasFetchMore: true }, () => (React.createElement(Stack, { justify: "center", align: "center", padding: 5 },
|
|
133
|
-
React.createElement(Button, { intent: "tertiary", onClick: fetchMore, text: fetchMoreText }))))
|
|
134
|
-
.otherwise(() => null);
|
|
135
114
|
/**
|
|
136
115
|
* Will render a scrollbar container that uses an intersection observer to watch for when
|
|
137
116
|
* the container has scrolled to the top or bottom.
|
|
138
117
|
* @public
|
|
139
118
|
*/
|
|
140
|
-
export function Infinite({ children, reverse = false, anchor = false, onFetchMore,
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const topStatus = useMemo(() => (reverse ? status : startStatus), [reverse, startStatus, status]);
|
|
146
|
-
const bottomStatus = useMemo(() => (reverse ? startStatus : status), [reverse, startStatus, status]);
|
|
147
|
-
const { ref, isAttached, handleScroll, reAttach } = useScrollControl(lastFetchDirection, scrollRef, reverse, anchor, scrollSideEffect, topStatus);
|
|
148
|
-
const { inView: topInView, ref: topRef } = useInView();
|
|
149
|
-
const { inView: bottomInView, ref: bottomRef } = useInView();
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
setLastFetchDirection("top");
|
|
152
|
-
if (topInView && topStatus !== "loading") {
|
|
153
|
-
if (topFetch && (!topStatus || topStatus !== "end")) {
|
|
154
|
-
topFetch();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}, [onFetchMore, onFetchMoreStart, reverse, startStatus, status, topFetch, topInView, topStatus]);
|
|
158
|
-
useEffect(() => {
|
|
159
|
-
setLastFetchDirection("bottom");
|
|
160
|
-
if (bottomInView && bottomStatus !== "loading") {
|
|
161
|
-
if (bottomFetch && (!bottomStatus || bottomStatus !== "end")) {
|
|
162
|
-
bottomFetch();
|
|
163
|
-
}
|
|
119
|
+
export function Infinite({ children, reverse = false, anchor = false, onFetchMore, status, maxHeight = "100%", scrollSideEffect, width, fetchMoreText, autoscrollText, scrollRef, justify, }) {
|
|
120
|
+
const { ref, isAttached, onScroll, reAttach } = useScrollControl(children, reverse, anchor, scrollSideEffect, scrollRef);
|
|
121
|
+
const handleIntersect = useCallback(() => {
|
|
122
|
+
if (onFetchMore && (!status || status !== "end")) {
|
|
123
|
+
onFetchMore();
|
|
164
124
|
}
|
|
165
|
-
}, [
|
|
166
|
-
bottomFetch,
|
|
167
|
-
bottomInView,
|
|
168
|
-
bottomStatus,
|
|
169
|
-
onFetchMore,
|
|
170
|
-
onFetchMoreStart,
|
|
171
|
-
reverse,
|
|
172
|
-
topStatus,
|
|
173
|
-
status,
|
|
174
|
-
]);
|
|
125
|
+
}, [onFetchMore, status]);
|
|
175
126
|
const theme = useTheme().colors;
|
|
176
127
|
return (React.createElement(Stack, { ...dpNameProp("Infinite"), maxHeight: "100%", style: {
|
|
177
128
|
position: "relative",
|
|
@@ -179,12 +130,21 @@ export function Infinite({ children, reverse = false, anchor = false, onFetchMor
|
|
|
179
130
|
height: "100%",
|
|
180
131
|
width,
|
|
181
132
|
}, justify: justify, align: "stretch", vertical: true },
|
|
182
|
-
React.createElement(Scrollbar, { autoHide: true, style: { maxHeight: maxHeight }, scrollableNodeProps: { ref: ref, onScroll:
|
|
183
|
-
|
|
184
|
-
|
|
133
|
+
React.createElement(Scrollbar, { autoHide: true, style: { maxHeight: maxHeight }, scrollableNodeProps: { ref: ref, onScroll: onScroll } },
|
|
134
|
+
reverse &&
|
|
135
|
+
status &&
|
|
136
|
+
match(status)
|
|
137
|
+
.with("loading", "hasNextPage", () => (React.createElement(Stack, { justify: "center", align: "center", padding: 5, style: { minHeight: 60 } },
|
|
138
|
+
React.createElement(Spinner, null))))
|
|
139
|
+
.with("end", () => null)
|
|
140
|
+
.with("end-with-force", () => (React.createElement(Stack, { justify: "center", align: "center", padding: 5 },
|
|
141
|
+
React.createElement(Button, { intent: "tertiary", onClick: onFetchMore, text: fetchMoreText }))))
|
|
142
|
+
.exhaustive(),
|
|
143
|
+
reverse && React.createElement(ObservedDiv, { onIntersect: handleIntersect }),
|
|
185
144
|
children,
|
|
186
|
-
React.createElement(
|
|
187
|
-
|
|
145
|
+
!reverse && React.createElement(ObservedDiv, { onIntersect: handleIntersect }),
|
|
146
|
+
!reverse && (status === "loading" || status === "hasNextPage") && (React.createElement(Stack, { justify: "center", align: "center", padding: 5, style: { minHeight: 60 } },
|
|
147
|
+
React.createElement(Spinner, null)))),
|
|
188
148
|
anchor && !isAttached && (React.createElement(OverlayButton, { placement: reverse ? "middle-bottom" : "middle-top", text: autoscrollText, onClick: reAttach, icon: { icon: faAngleDoubleDown, size: 14 }, rightIcon: { icon: faAngleDoubleDown, size: 14 }, style: { color: theme.brandShade100 } }))));
|
|
189
149
|
}
|
|
190
150
|
//# sourceMappingURL=Infinite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Infinite.js","sourceRoot":"","sources":["../../../../src/components/Infinite/Infinite.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAGL,WAAW,EACX,SAAS,EACT,eAAe,EACf,
|
|
1
|
+
{"version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,EAAC,QAAQ,EAAC,OAAO,EAAE,CAAC;oBAC/C,oBAAC,MAAM,IAAC,MAAM,EAAC,UAAU,EAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,aAAa,GAAI,CACjE,CACT,CAAC;qBACD,UAAU,EAAE;YAChB,OAAO,IAAI,oBAAC,WAAW,IAAC,WAAW,EAAE,eAAe,GAAI;YACxD,QAAQ;YACR,CAAC,OAAO,IAAI,oBAAC,WAAW,IAAC,WAAW,EAAE,eAAe,GAAI;YACzD,CAAC,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,aAAa,CAAC,IAAI,CACjE,oBAAC,KAAK,IAAC,OAAO,EAAC,QAAQ,EAAC,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;gBACzE,oBAAC,OAAO,OAAG,CACL,CACT,CACS;QACX,MAAM,IAAI,CAAC,UAAU,IAAI,CACxB,oBAAC,aAAa,IACZ,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,EACnD,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,EAAE,EAC3C,SAAS,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,EAAE,EAChD,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,EAAE,GACrC,CACH,CACK,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { dpNameProp } from "../../utils/dpName";
|
|
|
6
6
|
* Component that positions absolutely to the top or bottom of the container
|
|
7
7
|
* and emits an event if it intersects with the view port using `IntersectionObserver`
|
|
8
8
|
*/
|
|
9
|
-
export function ObservedDiv({ onIntersect }) {
|
|
9
|
+
export function ObservedDiv({ onIntersect, reverse = false }) {
|
|
10
10
|
const ref = useRef(null);
|
|
11
11
|
const callback = useRef(onIntersect);
|
|
12
12
|
useLayoutEffect(() => {
|
|
@@ -23,6 +23,6 @@ export function ObservedDiv({ onIntersect }) {
|
|
|
23
23
|
observer.observe(ref.current);
|
|
24
24
|
return () => observer.disconnect();
|
|
25
25
|
}, []);
|
|
26
|
-
return React.createElement(S.Observed, { ...dpNameProp("ObservedDiv"), "data-testid": "observer", ref: ref });
|
|
26
|
+
return (React.createElement(S.Observed, { ...dpNameProp("ObservedDiv"), "data-testid": "observer", position: reverse ? "top" : "bottom", ref: ref }));
|
|
27
27
|
}
|
|
28
28
|
//# sourceMappingURL=ObservedDiv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservedDiv.js","sourceRoot":"","sources":["../../../../src/components/Infinite/ObservedDiv.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservedDiv.js","sourceRoot":"","sources":["../../../../src/components/Infinite/ObservedDiv.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAShD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,WAAW,EAAE,OAAO,GAAG,KAAK,EAAiB;IACzE,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAErC,eAAe,CAAC,GAAG,EAAE;QACnB,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC;IACjC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,GAAG,CAAC,OAAO;YAAE,OAAO;QAEzB,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,OAAO,EAAE,EAAE;YACpD,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;gBACjD,QAAQ,CAAC,OAAO,EAAE,CAAC;aACpB;QACH,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,oBAAC,CAAC,CAAC,QAAQ,OACL,UAAU,CAAC,aAAa,CAAC,iBACjB,UAAU,EACtB,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EACpC,GAAG,EAAE,GAAG,GACR,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../src/components/Infinite/styles.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../src/components/Infinite/styles.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAgC;;;CAGjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const react_1 = require("react");
|
|
4
|
-
// hook that detects when the provided element is within the viewport
|
|
5
|
-
const useInView = () => {
|
|
6
|
-
const [ref, setRef] = (0, react_1.useState)(null);
|
|
7
|
-
const [inView, setInView] = (0, react_1.useState)(false);
|
|
8
|
-
const visibilityOptions = (0, react_1.useMemo)(() => ({
|
|
9
|
-
root: null,
|
|
10
|
-
threshold: [0, 1],
|
|
11
|
-
}), []);
|
|
12
|
-
(0, react_1.useEffect)(() => {
|
|
13
|
-
if (!ref)
|
|
14
|
-
return;
|
|
15
|
-
const observer = new IntersectionObserver((entries) => entries.forEach((entry) => {
|
|
16
|
-
setInView(entry.isIntersecting);
|
|
17
|
-
}), visibilityOptions);
|
|
18
|
-
observer.observe(ref);
|
|
19
|
-
return () => {
|
|
20
|
-
setInView(false);
|
|
21
|
-
observer.disconnect();
|
|
22
|
-
};
|
|
23
|
-
}, [ref, visibilityOptions]);
|
|
24
|
-
return (0, react_1.useMemo)(() => ({ ref: setRef, inView }), [inView]);
|
|
25
|
-
};
|
|
26
|
-
exports.default = useInView;
|
|
27
|
-
//# sourceMappingURL=useInView.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInView.js","sourceRoot":"","sources":["../../../src/utils/useInView.ts"],"names":[],"mappings":";;AAAA,iCAAqD;AAErD,qEAAqE;AACrE,MAAM,SAAS,GAAG,GAA0B,EAAE;IAC5C,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,IAAA,gBAAQ,EAAW,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,iBAAiB,GAA6B,IAAA,eAAO,EACzD,GAAG,EAAE,CAAC,CAAC;QACL,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAClB,CAAC,EACF,EAAE,CACH,CAAC;IAEF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CACvC,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC,CAAC,EACJ,iBAAiB,CAClB,CAAC;QACF,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACtB,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,KAAK,CAAC,CAAC;YACjB,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAE7B,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useState } from "react";
|
|
2
|
-
// hook that detects when the provided element is within the viewport
|
|
3
|
-
const useInView = () => {
|
|
4
|
-
const [ref, setRef] = useState(null);
|
|
5
|
-
const [inView, setInView] = useState(false);
|
|
6
|
-
const visibilityOptions = useMemo(() => ({
|
|
7
|
-
root: null,
|
|
8
|
-
threshold: [0, 1],
|
|
9
|
-
}), []);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (!ref)
|
|
12
|
-
return;
|
|
13
|
-
const observer = new IntersectionObserver((entries) => entries.forEach((entry) => {
|
|
14
|
-
setInView(entry.isIntersecting);
|
|
15
|
-
}), visibilityOptions);
|
|
16
|
-
observer.observe(ref);
|
|
17
|
-
return () => {
|
|
18
|
-
setInView(false);
|
|
19
|
-
observer.disconnect();
|
|
20
|
-
};
|
|
21
|
-
}, [ref, visibilityOptions]);
|
|
22
|
-
return useMemo(() => ({ ref: setRef, inView }), [inView]);
|
|
23
|
-
};
|
|
24
|
-
export default useInView;
|
|
25
|
-
//# sourceMappingURL=useInView.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInView.js","sourceRoot":"","sources":["../../../src/utils/useInView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAErD,qEAAqE;AACrE,MAAM,SAAS,GAAG,GAA0B,EAAE;IAC5C,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAW,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5C,MAAM,iBAAiB,GAA6B,OAAO,CACzD,GAAG,EAAE,CAAC,CAAC;QACL,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAClB,CAAC,EACF,EAAE,CACH,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CACvC,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC,CAAC,EACJ,iBAAiB,CAClB,CAAC;QACF,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACtB,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,KAAK,CAAC,CAAC;YACjB,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAA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