@cntrl-site/sdk-nextjs 0.27.1 → 0.27.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.
@@ -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
  };
@@ -167,17 +167,19 @@ class RichTextConverter {
167
167
  }
168
168
  return styleGroups;
169
169
  }
170
- groupEntities(entitiesList, styleGroups) {
171
- var _a, _b, _c, _d;
170
+ groupEntities(entities, styleGroups) {
171
+ var _a, _b, _c, _d, _e, _f, _g, _h;
172
172
  const entitiesGroups = [];
173
- // some entities may have no data, need to filter them out (case with deleting a section/page that was linked to)
174
- const entities = entitiesList.filter(e => e.hasOwnProperty('data'));
175
173
  if (!entities.length && !styleGroups)
176
174
  return;
177
175
  if (!styleGroups || styleGroups.length === 0) {
178
- const dividersSet = entities.reduce((ds, s) => {
179
- ds.add(s.start);
180
- ds.add(s.end);
176
+ const dividersSet = entities.reduce((ds, e) => {
177
+ // some entities may have no data, need to filter them out
178
+ // (case with deleting a section/page that was linked to)
179
+ if (!e.hasOwnProperty('data'))
180
+ return ds;
181
+ ds.add(e.start);
182
+ ds.add(e.end);
181
183
  return ds;
182
184
  }, new Set([entities[0].start, entities[entities.length - 1].end]));
183
185
  const dividers = Array.from(dividersSet).sort((a, b) => a - b);
@@ -200,9 +202,11 @@ class RichTextConverter {
200
202
  }
201
203
  const start = entities[0].start < styleGroups[0].start ? entities[0].start : styleGroups[0].start;
202
204
  const end = entities[entities.length - 1].end > styleGroups[styleGroups.length - 1].end ? entities[entities.length - 1].end : styleGroups[styleGroups.length - 1].end;
203
- const entitiesDividers = entities.reduce((ds, s) => {
204
- ds.add(s.start);
205
- ds.add(s.end);
205
+ const entitiesDividers = entities.reduce((ds, e) => {
206
+ if (!e.hasOwnProperty('data'))
207
+ return ds;
208
+ ds.add(e.start);
209
+ ds.add(e.end);
206
210
  return ds;
207
211
  }, new Set([start, end]));
208
212
  const entityDividers = Array.from(entitiesDividers).sort((a, b) => a - b);
@@ -211,7 +215,7 @@ class RichTextConverter {
211
215
  const end = entityDividers[i + 1];
212
216
  const entity = entities.find(e => e.start === start);
213
217
  entitiesGroups.push(Object.assign({ stylesGroup: styleGroups.filter(s => s.start >= start && s.end <= end), start,
214
- end }, (entity && { link: entity.data.url, target: entity.data.target })));
218
+ end }, (entity && { link: (_f = (_e = entity.data) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : '', target: (_h = (_g = entity.data) === null || _g === void 0 ? void 0 : _g.target) !== null && _h !== void 0 ? _h : '_self' })));
215
219
  }
216
220
  return entitiesGroups;
217
221
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.27.1",
3
+ "version": "0.27.2",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -22,9 +22,8 @@
22
22
  "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
23
23
  "dependencies": {
24
24
  "@cntrl-site/color": "^1.0.0",
25
- "@cntrl-site/effects": "^1.0.5",
25
+ "@cntrl-site/effects": "^1.1.0",
26
26
  "@cntrl-site/sdk": "^1.9.1",
27
- "@types/ua-parser-js": "^0.7.39",
28
27
  "@types/vimeo__player": "^2.18.0",
29
28
  "@vimeo/player": "^2.20.1",
30
29
  "html-react-parser": "^3.0.1",
@@ -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
  };
@@ -199,15 +199,16 @@ export class RichTextConverter {
199
199
  return styleGroups;
200
200
  }
201
201
 
202
- private groupEntities(entitiesList: RichTextEntity[], styleGroups?: StyleGroup[]): EntitiesGroup[] | undefined {
202
+ private groupEntities(entities: RichTextEntity[], styleGroups?: StyleGroup[]): EntitiesGroup[] | undefined {
203
203
  const entitiesGroups: EntitiesGroup[] = [];
204
- // some entities may have no data, need to filter them out (case with deleting a section/page that was linked to)
205
- const entities = entitiesList.filter(e => e.hasOwnProperty('data'));
206
204
  if (!entities.length && !styleGroups) return;
207
205
  if (!styleGroups || styleGroups.length === 0) {
208
- const dividersSet = entities.reduce((ds, s) => {
209
- ds.add(s.start);
210
- ds.add(s.end);
206
+ const dividersSet = entities.reduce((ds, e) => {
207
+ // some entities may have no data, need to filter them out
208
+ // (case with deleting a section/page that was linked to)
209
+ if (!e.hasOwnProperty('data')) return ds;
210
+ ds.add(e.start);
211
+ ds.add(e.end);
211
212
  return ds;
212
213
  }, new Set<number>([entities[0].start, entities[entities.length - 1].end]));
213
214
  const dividers = Array.from(dividersSet).sort((a, b) => a - b);
@@ -234,9 +235,10 @@ export class RichTextConverter {
234
235
  }
235
236
  const start = entities[0].start < styleGroups[0].start ? entities[0].start : styleGroups[0].start;
236
237
  const end = entities[entities.length - 1].end > styleGroups[styleGroups.length - 1].end ? entities[entities.length - 1].end : styleGroups[styleGroups.length - 1].end;
237
- const entitiesDividers = entities.reduce((ds, s) => {
238
- ds.add(s.start);
239
- ds.add(s.end);
238
+ const entitiesDividers = entities.reduce((ds, e) => {
239
+ if (!e.hasOwnProperty('data')) return ds;
240
+ ds.add(e.start);
241
+ ds.add(e.end);
240
242
  return ds;
241
243
  }, new Set<number>([start, end]));
242
244
  const entityDividers = Array.from(entitiesDividers).sort((a, b) => a - b);
@@ -249,7 +251,7 @@ export class RichTextConverter {
249
251
  stylesGroup: styleGroups.filter(s => s.start >= start && s.end <= end),
250
252
  start,
251
253
  end,
252
- ...(entity && { link: entity.data.url, target: entity.data.target })
254
+ ...(entity && { link: entity.data?.url ?? '', target: entity.data?.target ?? '_self' })
253
255
  });
254
256
  }
255
257