@cntrl-site/sdk-nextjs 0.7.0 → 0.7.2

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,14 @@ 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
16
  const handleSticky = (0, react_1.useCallback)((scroll) => {
17
17
  setIsFixed(stickyManager.getIsSticky(scroll));
18
18
  setAdjustedTop(stickyManager.getPosition(scroll, top, parentOffsetTop));
19
19
  }, [top, stickyManager, parentOffsetTop]);
20
+ (0, react_1.useEffect)(() => {
21
+ setAdjustedTop(top);
22
+ }, [top]);
20
23
  (0, react_1.useEffect)(() => {
21
24
  if (!articleRectObserver || !sticky)
22
25
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.js",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
23
23
  "dependencies": {
24
- "@cntrl-site/sdk": "^0.6.2",
24
+ "@cntrl-site/sdk": "^0.6.3",
25
25
  "html-react-parser": "^3.0.1",
26
26
  "styled-jsx": "^5.0.2"
27
27
  },
@@ -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,7 @@ 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
14
 
15
15
  const handleSticky = useCallback((scroll: number) => {
16
16
  setIsFixed(stickyManager.getIsSticky(scroll));
@@ -21,6 +21,10 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
21
21
  ));
22
22
  }, [top, stickyManager, parentOffsetTop]);
23
23
 
24
+ useEffect(() => {
25
+ setAdjustedTop(top);
26
+ }, [top]);
27
+
24
28
  useEffect(() => {
25
29
  if (!articleRectObserver || !sticky) return;
26
30
  return articleRectObserver.on('scroll', () => {
@@ -1,15 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
5
- <option name="myValues">
6
- <value>
7
- <list size="1">
8
- <item index="0" class="java.lang.String" itemvalue="jsx" />
9
- </list>
10
- </value>
11
- </option>
12
- <option name="myCustomValuesEnabled" value="true" />
13
- </inspection_tool>
14
- </profile>
15
- </component>
Binary file
Binary file