@cntrl-site/sdk-nextjs 0.26.0 → 0.26.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
@@ -55,7 +55,7 @@ const Item = ({ item, sectionId, articleHeight }) => {
55
55
  const [wrapperHeight, setWrapperHeight] = (0, react_1.useState)(undefined);
56
56
  const [itemHeight, setItemHeight] = (0, react_1.useState)(undefined);
57
57
  const { scale, scaleAnchor } = (0, useItemScale_1.useItemScale)(item, sectionId);
58
- const { top, left } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
58
+ const { top, left, bottom } = (0, useItemPosition_1.useItemPosition)(item, sectionId);
59
59
  const sectionHeight = (0, useSectionHeightMap_1.useSectionHeightData)(sectionId);
60
60
  const stickyTop = (0, useStickyItemTop_1.useStickyItemTop)(item, sectionHeight, sectionId);
61
61
  const { width, height } = (0, useItemDimensions_1.useItemDimensions)(item, sectionId);
@@ -99,7 +99,7 @@ const Item = ({ item, sectionId, articleHeight }) => {
99
99
  top: `${stickyTop * 100}vw`,
100
100
  height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
101
101
  };
102
- return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, ref: itemWrapperRef, style: isInitialRef.current ? {} : Object.assign({ top, left }, (wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {})), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles, children: (0, jsx_runtime_1.jsx)(RichTextWrapper, { isRichText: isRichText, children: (0, jsx_runtime_1.jsx)("div", { className: `item-${item.id}-inner`, style: {
102
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `item-wrapper-${item.id}`, ref: itemWrapperRef, style: isInitialRef.current ? {} : Object.assign({ top, left, bottom }, (wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {})), children: [(0, jsx_runtime_1.jsx)("div", { suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles, children: (0, jsx_runtime_1.jsx)(RichTextWrapper, { isRichText: isRichText, children: (0, jsx_runtime_1.jsx)("div", { className: `item-${item.id}-inner`, style: {
103
103
  width: `${sizingAxis.x === 'manual'
104
104
  ? isRichText
105
105
  ? `${width * exemplary}px`
@@ -111,12 +111,12 @@ const Item = ({ item, sectionId, articleHeight }) => {
111
111
  }, children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize, articleHeight: articleHeight }) }) }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
112
112
  ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
113
113
  const sizingAxis = parseSizing(layoutParams.sizing);
114
+ const isScreenBasedBottom = area.positionType === sdk_1.PositionType.ScreenBased && area.anchorSide === sdk_1.AnchorSide.Bottom;
114
115
  return (`
115
116
  .item-${item.id} {
116
117
  position: ${sticky ? 'sticky' : 'absolute'};
117
118
  top: ${sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(area.top - sticky.from, sectionHeight, area.anchorSide)}` : 0};
118
119
  pointer-events: auto;
119
- cursor: ${hoverParams ? 'pointer' : 'default'};
120
120
  display: ${hidden ? 'none' : 'block'};
121
121
  height: fit-content;
122
122
  }
@@ -134,7 +134,8 @@ const Item = ({ item, sectionId, articleHeight }) => {
134
134
  -webkit-transform: translate3d(0, 0, 0);
135
135
  transform: translate3d(0, 0, 0);
136
136
  pointer-events: none;
137
- top: ${(0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
137
+ bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
138
+ top: ${isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(area.top, area.anchorSide)};
138
139
  left: ${area.left * 100}vw;
139
140
  transition: ${(0, HoverStyles_1.getTransitions)(['left', 'top'], hoverParams)};
140
141
  }
@@ -13,8 +13,12 @@ const useItemPosition = (item, sectionId) => {
13
13
  return item.area[layoutId];
14
14
  }, (animator, scroll, value) => animator.getPositions(value, scroll), sectionId, [layoutId]);
15
15
  const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
16
+ const positionType = layoutId ? item.area[layoutId].positionType : sdk_1.PositionType.ScreenBased;
17
+ // tp prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
18
+ const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
16
19
  return {
17
- top: (0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide),
20
+ bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset',
21
+ top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide),
18
22
  left: `${left * 100}vw`
19
23
  };
20
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -1,6 +1,7 @@
1
1
  import { ComponentType, FC, PropsWithChildren, useContext, useEffect, useId, useRef, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
3
  import {
4
+ AnchorSide,
4
5
  ArticleItemType,
5
6
  getLayoutStyles,
6
7
  Item as TItem,
@@ -76,7 +77,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
76
77
  const [wrapperHeight, setWrapperHeight] = useState<undefined | number>(undefined);
77
78
  const [itemHeight, setItemHeight] = useState<undefined | number>(undefined);
78
79
  const { scale, scaleAnchor } = useItemScale(item, sectionId);
79
- const { top, left } = useItemPosition(item, sectionId);
80
+ const { top, left, bottom } = useItemPosition(item, sectionId);
80
81
  const sectionHeight = useSectionHeightData(sectionId);
81
82
  const stickyTop = useStickyItemTop(item, sectionHeight, sectionId);
82
83
  const { width, height } = useItemDimensions(item, sectionId);
@@ -128,7 +129,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
128
129
  <div
129
130
  className={`item-wrapper-${item.id}`}
130
131
  ref={itemWrapperRef}
131
- style={isInitialRef.current ? {} : { top, left, ...(wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {}) }}
132
+ style={isInitialRef.current ? {} : { top, left, bottom, ...(wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {}) }}
132
133
  >
133
134
  <div
134
135
  suppressHydrationWarning={true}
@@ -156,12 +157,12 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
156
157
  <JSXStyle id={id}>{`
157
158
  ${getLayoutStyles(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
158
159
  const sizingAxis = parseSizing(layoutParams.sizing);
160
+ const isScreenBasedBottom = area.positionType === PositionType.ScreenBased && area.anchorSide === AnchorSide.Bottom;
159
161
  return (`
160
162
  .item-${item.id} {
161
163
  position: ${sticky ? 'sticky' : 'absolute'};
162
164
  top: ${sticky ? `${getAnchoredItemTop(area.top - sticky.from, sectionHeight, area.anchorSide)}` : 0};
163
165
  pointer-events: auto;
164
- cursor: ${hoverParams ? 'pointer' : 'default'};
165
166
  display: ${hidden ? 'none' : 'block'};
166
167
  height: fit-content;
167
168
  }
@@ -179,7 +180,8 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
179
180
  -webkit-transform: translate3d(0, 0, 0);
180
181
  transform: translate3d(0, 0, 0);
181
182
  pointer-events: none;
182
- top: ${getItemTopStyle(area.top, area.anchorSide)};
183
+ bottom: ${isScreenBasedBottom ? `${-area.top * 100}vw` : 'unset'};
184
+ top: ${isScreenBasedBottom ? 'unset' : getItemTopStyle(area.top, area.anchorSide)};
183
185
  left: ${area.left * 100}vw;
184
186
  transition: ${getTransitions(['left', 'top'], hoverParams)};
185
187
  }
@@ -1,4 +1,4 @@
1
- import { AnchorSide, ItemAny } from '@cntrl-site/sdk';
1
+ import { AnchorSide, ItemAny, PositionType } from '@cntrl-site/sdk';
2
2
  import { useKeyframeValue } from '../common/useKeyframeValue';
3
3
  import { getItemTopStyle } from '../utils/getItemTopStyle';
4
4
  import { useLayoutContext } from './useLayoutContext';
@@ -16,8 +16,12 @@ export const useItemPosition = (item: ItemAny, sectionId: string) => {
16
16
  [layoutId]
17
17
  );
18
18
  const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
19
+ const positionType = layoutId ? item.area[layoutId].positionType : PositionType.ScreenBased;
20
+ // tp prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
21
+ const isScreenBasedBottom = positionType === PositionType.ScreenBased && anchorSide === AnchorSide.Bottom;
19
22
  return {
20
- top: getItemTopStyle(top, anchorSide),
23
+ bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset',
24
+ top: isScreenBasedBottom ? 'unset' : getItemTopStyle(top, anchorSide),
21
25
  left: `${left * 100}vw`
22
26
  };
23
27
  };
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>