@cntrl-site/sdk-nextjs 0.5.0 → 0.5.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.
@@ -31,7 +31,7 @@ const Item = ({ item }) => {
31
31
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
32
32
  const angle = (0, useItemAngle_1.useItemAngle)(item);
33
33
  const position = (0, useItemPosition_1.useItemPosition)(item);
34
- const ref = (0, react_1.useRef)(null);
34
+ const [ref, setRef] = (0, react_1.useState)(null);
35
35
  const [parentOffsetTop, setParentOffsetTop] = (0, react_1.useState)(0);
36
36
  const { top, isFixed } = (0, useItemSticky_1.useItemSticky)(position.top, parentOffsetTop, item);
37
37
  const { width, height } = (0, useItemDimensions_1.useItemDimensions)(item);
@@ -46,11 +46,11 @@ const Item = ({ item }) => {
46
46
  isInitialRef.current = false;
47
47
  }, []);
48
48
  (0, react_1.useEffect)(() => {
49
- if (!ref.current)
49
+ if (!ref)
50
50
  return;
51
- const offsetParent = (0, castObject_1.castObject)(ref.current.offsetParent, HTMLElement);
51
+ const offsetParent = (0, castObject_1.castObject)(ref.offsetParent, HTMLElement);
52
52
  setParentOffsetTop(offsetParent.offsetTop / window.innerWidth);
53
- }, []);
53
+ }, [ref]);
54
54
  const styles = {
55
55
  transform: `rotate(${angle}deg)`,
56
56
  left: `${position.left * 100}vw`,
@@ -58,7 +58,7 @@ const Item = ({ item }) => {
58
58
  height: `${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${height * 100}vw` : 'unset'}`,
59
59
  top
60
60
  };
61
- return ((0, jsx_runtime_1.jsxs)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, ref: ref, style: isInitialRef.current ? {} : { ...styles, position: isFixed ? 'fixed' : 'absolute' }, children: [(0, jsx_runtime_1.jsx)(ItemComponent, { item: item }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
61
+ return ((0, jsx_runtime_1.jsxs)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, ref: setRef, style: isInitialRef.current ? {} : { ...styles, position: isFixed ? 'fixed' : 'absolute' }, children: [(0, jsx_runtime_1.jsx)(ItemComponent, { item: item }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
62
62
  ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area]) => (`
63
63
  .item-${item.id} {
64
64
  position: absolute;
@@ -16,7 +16,7 @@ const useItemSticky = (top, parentOffsetTop, item) => {
16
16
  const handleSticky = (0, react_1.useCallback)((scroll) => {
17
17
  setIsFixed(stickyManager.getIsSticky(scroll));
18
18
  setAdjustedTop(stickyManager.getPosition(scroll, top, parentOffsetTop));
19
- }, [top, stickyManager]);
19
+ }, [top, stickyManager, parentOffsetTop]);
20
20
  (0, react_1.useEffect)(() => {
21
21
  if (!articleRectObserver || !sticky)
22
22
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.js",
@@ -39,7 +39,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
39
39
  const { layouts } = useCntrlContext();
40
40
  const angle = useItemAngle(item);
41
41
  const position = useItemPosition(item);
42
- const ref = useRef<HTMLDivElement | null>(null);
42
+ const [ref, setRef] = useState<HTMLDivElement | null>(null);
43
43
  const [parentOffsetTop, setParentOffsetTop] = useState(0);
44
44
  const { top, isFixed } = useItemSticky(position.top, parentOffsetTop, item);
45
45
  const { width, height } = useItemDimensions(item);
@@ -57,10 +57,10 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
57
57
  }, []);
58
58
 
59
59
  useEffect(() => {
60
- if (!ref.current) return;
61
- const offsetParent = castObject(ref.current.offsetParent, HTMLElement);
60
+ if (!ref) return;
61
+ const offsetParent = castObject(ref.offsetParent, HTMLElement);
62
62
  setParentOffsetTop(offsetParent.offsetTop / window.innerWidth);
63
- }, []);
63
+ }, [ref]);
64
64
 
65
65
  const styles = {
66
66
  transform: `rotate(${angle}deg)`,
@@ -74,7 +74,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
74
74
  <div
75
75
  suppressHydrationWarning={true}
76
76
  className={`item-${item.id}`}
77
- ref={ref}
77
+ ref={setRef}
78
78
  style={isInitialRef.current ? {} : { ...styles, position: isFixed ? 'fixed': 'absolute' } }
79
79
  >
80
80
  <ItemComponent item={item} />
@@ -19,7 +19,7 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
19
19
  top,
20
20
  parentOffsetTop
21
21
  ));
22
- }, [top, stickyManager]);
22
+ }, [top, stickyManager, parentOffsetTop]);
23
23
 
24
24
  useEffect(() => {
25
25
  if (!articleRectObserver || !sticky) return;