@cntrl-site/sdk-nextjs 0.7.0 → 0.7.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.
|
Binary file
|
|
@@ -25,6 +25,11 @@ const useCurrentLayout = () => {
|
|
|
25
25
|
return layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end).layoutId;
|
|
26
26
|
}, [layoutRanges]);
|
|
27
27
|
const [layoutId, setLayoutId] = (0, react_1.useState)(getCurrentLayout(0));
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
if (typeof window !== 'undefined') {
|
|
30
|
+
getCurrentLayout(window.innerWidth);
|
|
31
|
+
}
|
|
32
|
+
}, []);
|
|
28
33
|
(0, react_1.useEffect)(() => {
|
|
29
34
|
if (!articleRectObserver)
|
|
30
35
|
return;
|
|
@@ -12,11 +12,17 @@ const useItemSticky = (top, parentOffsetTop, item) => {
|
|
|
12
12
|
const articleRectObserver = (0, react_1.useContext)(ArticleRectContext_1.ArticleRectContext);
|
|
13
13
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
14
14
|
const sticky = (0, react_1.useMemo)(() => item.layoutParams[layoutId].sticky, [layoutId]);
|
|
15
|
-
const stickyManager = (0, react_1.useMemo)(() => new StickyManager_1.StickyManager(sticky), []);
|
|
15
|
+
const stickyManager = (0, react_1.useMemo)(() => new StickyManager_1.StickyManager(sticky), [sticky]);
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
setAdjustedTop(top);
|
|
18
|
+
}, [layoutId, top]);
|
|
16
19
|
const handleSticky = (0, react_1.useCallback)((scroll) => {
|
|
17
20
|
setIsFixed(stickyManager.getIsSticky(scroll));
|
|
18
21
|
setAdjustedTop(stickyManager.getPosition(scroll, top, parentOffsetTop));
|
|
19
22
|
}, [top, stickyManager, parentOffsetTop]);
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
setAdjustedTop(top);
|
|
25
|
+
}, [top]);
|
|
20
26
|
(0, react_1.useEffect)(() => {
|
|
21
27
|
if (!articleRectObserver || !sticky)
|
|
22
28
|
return;
|
package/package.json
CHANGED
|
@@ -30,6 +30,12 @@ export const useCurrentLayout = () => {
|
|
|
30
30
|
}, [layoutRanges]);
|
|
31
31
|
const [layoutId, setLayoutId] = useState<string>(getCurrentLayout(0));
|
|
32
32
|
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (typeof window !== 'undefined') {
|
|
35
|
+
getCurrentLayout(window.innerWidth);
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
33
39
|
useEffect(() => {
|
|
34
40
|
if (!articleRectObserver) return;
|
|
35
41
|
return articleRectObserver.on('resize', () => {
|
|
@@ -10,7 +10,11 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
|
|
|
10
10
|
const articleRectObserver = useContext(ArticleRectContext);
|
|
11
11
|
const layoutId = useCurrentLayout();
|
|
12
12
|
const sticky = useMemo(() => item.layoutParams[layoutId].sticky, [layoutId]);
|
|
13
|
-
const stickyManager = useMemo(() => new StickyManager(sticky), []);
|
|
13
|
+
const stickyManager = useMemo(() => new StickyManager(sticky), [sticky]);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
setAdjustedTop(top);
|
|
17
|
+
}, [layoutId, top]);
|
|
14
18
|
|
|
15
19
|
const handleSticky = useCallback((scroll: number) => {
|
|
16
20
|
setIsFixed(stickyManager.getIsSticky(scroll));
|
|
@@ -21,6 +25,10 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
|
|
|
21
25
|
));
|
|
22
26
|
}, [top, stickyManager, parentOffsetTop]);
|
|
23
27
|
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setAdjustedTop(top);
|
|
30
|
+
}, [top]);
|
|
31
|
+
|
|
24
32
|
useEffect(() => {
|
|
25
33
|
if (!articleRectObserver || !sticky) return;
|
|
26
34
|
return articleRectObserver.on('scroll', () => {
|