@cntrl-site/sdk-nextjs 0.27.1 → 0.28.0

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.
@@ -0,0 +1,15 @@
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>
@@ -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
  }
@@ -17,6 +17,7 @@ const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
17
17
  const useRegisterResize_1 = require("../../common/useRegisterResize");
18
18
  const useImageFx_1 = require("../../utils/effects/useImageFx");
19
19
  const useElementRect_1 = require("../../utils/useElementRect");
20
+ const useLayoutContext_1 = require("../useLayoutContext");
20
21
  const baseVariables = `precision mediump float;
21
22
  uniform sampler2D u_image;
22
23
  uniform sampler2D u_pattern;
@@ -26,9 +27,10 @@ uniform float u_time;
26
27
  uniform vec2 u_cursor;
27
28
  varying vec2 v_texCoord;`;
28
29
  const ImageItem = ({ item, sectionId, onResize }) => {
29
- var _a, _b, _c, _d, _e;
30
+ var _a, _b, _c, _d, _e, _f;
30
31
  const id = (0, react_1.useId)();
31
32
  const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
33
+ const layoutId = (0, useLayoutContext_1.useLayoutContext)();
32
34
  const { radius, strokeWidth, opacity, strokeColor, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
33
35
  const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
34
36
  const borderColor = (0, react_1.useMemo)(() => color_1.CntrlColor.parse(strokeColor), [strokeColor]);
@@ -44,21 +46,25 @@ const ImageItem = ({ item, sectionId, onResize }) => {
44
46
  return acc;
45
47
  }, {});
46
48
  const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
49
+ const area = layoutId ? item.area[layoutId] : null;
50
+ const exemplary = (_b = layouts === null || layouts === void 0 ? void 0 : layouts.find(l => l.id === layoutId)) === null || _b === void 0 ? void 0 : _b.exemplary;
51
+ const width = area && exemplary ? area.width * exemplary : 0;
52
+ const height = area && exemplary ? area.height * exemplary : 0;
47
53
  (0, useImageFx_1.useImageFx)(fxCanvas.current, hasGLEffect !== null && hasGLEffect !== void 0 ? hasGLEffect : false, {
48
54
  imageUrl: url,
49
55
  fragmentShader: fullShaderCode,
50
56
  cursor: item.commonParams.FXCursor,
51
57
  controls: controlValues
52
- });
58
+ }, width, height);
53
59
  const rect = (0, useElementRect_1.useElementRect)(ref);
54
- const rectWidth = Math.floor((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0);
55
- const rectHeight = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0);
60
+ const rectWidth = Math.floor((_c = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _c !== void 0 ? _c : 0);
61
+ const rectHeight = Math.floor((_d = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _d !== void 0 ? _d : 0);
56
62
  const inlineStyles = {
57
63
  borderRadius: `${radius * 100}vw`,
58
64
  borderWidth: `${strokeWidth * 100}vw`,
59
65
  borderColor: `${borderColor.toCss()}`
60
66
  };
61
- return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_d = item.link) === null || _d === void 0 ? void 0 : _d.url, target: (_e = item.link) === null || _e === void 0 ? void 0 : _e.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setRef, style: {
67
+ return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_e = item.link) === null || _e === void 0 ? void 0 : _e.url, target: (_f = item.link) === null || _f === void 0 ? void 0 : _f.target, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `image-wrapper-${item.id}`, ref: setRef, style: {
62
68
  opacity: `${opacity}`,
63
69
  transform: `rotate(${angle}deg)`,
64
70
  filter: `blur(${blur * 100}vw)`
@@ -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
  }
@@ -6,14 +6,14 @@ const effects_1 = require("@cntrl-site/effects");
6
6
  const rangeMap_1 = require("../rangeMap");
7
7
  const PATTERN_URL = 'https://cdn.cntrl.site/client-app-files/texture2.png';
8
8
  const PATTERN_2_URL = 'https://cdn.cntrl.site/client-app-files/bayer16.png';
9
- function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, controls }) {
9
+ function useImageFx(canvas, enabled, { imageUrl, fragmentShader, cursor, controls }, width, height) {
10
10
  const mousePos = (0, react_1.useRef)([0.0, 0.0]);
11
11
  const imageFx = (0, react_1.useMemo)(() => {
12
12
  if (!imageUrl || !cursor)
13
13
  return undefined;
14
14
  const { type, x, y } = cursor;
15
- return new effects_1.ImageEffect(imageUrl, PATTERN_URL, PATTERN_2_URL, fragmentShader, Object.assign({ time: 0, cursor: type === 'mouse' ? mousePos.current : [x, y] }, controls));
16
- }, [imageUrl, fragmentShader]);
15
+ return new effects_1.ImageEffect(imageUrl, PATTERN_URL, PATTERN_2_URL, fragmentShader, Object.assign({ time: 0, cursor: type === 'mouse' ? mousePos.current : [x, y] }, controls), width, height);
16
+ }, [imageUrl, fragmentShader, width, height]);
17
17
  (0, react_1.useEffect)(() => {
18
18
  if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx)
19
19
  return;
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.28.0",
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.2.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
  }
@@ -11,6 +11,7 @@ import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverSty
11
11
  import { useRegisterResize } from "../../common/useRegisterResize";
12
12
  import { useImageFx } from '../../utils/effects/useImageFx';
13
13
  import { useElementRect } from '../../utils/useElementRect';
14
+ import { useLayoutContext } from '../useLayoutContext';
14
15
 
15
16
  const baseVariables = `precision mediump float;
16
17
  uniform sampler2D u_image;
@@ -24,6 +25,7 @@ varying vec2 v_texCoord;`;
24
25
  export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize }) => {
25
26
  const id = useId();
26
27
  const { layouts } = useCntrlContext();
28
+ const layoutId = useLayoutContext();
27
29
  const { radius, strokeWidth, opacity, strokeColor, blur } = useFileItem(item, sectionId);
28
30
  const angle = useItemAngle(item, sectionId);
29
31
  const borderColor = useMemo(() => CntrlColor.parse(strokeColor), [strokeColor]);
@@ -39,12 +41,22 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
39
41
  return acc;
40
42
  }, {});
41
43
  const fullShaderCode = `${baseVariables}\n${controlsVariables}\n${fragmentShader}`;
42
- useImageFx(fxCanvas.current, hasGLEffect ?? false, {
43
- imageUrl: url,
44
- fragmentShader: fullShaderCode,
45
- cursor: item.commonParams.FXCursor,
46
- controls: controlValues
47
- });
44
+ const area = layoutId ? item.area[layoutId] : null;
45
+ const exemplary = layouts?.find(l => l.id === layoutId)?.exemplary;
46
+ const width = area && exemplary ? area.width * exemplary : 0;
47
+ const height = area && exemplary ? area.height * exemplary : 0;
48
+ useImageFx(
49
+ fxCanvas.current,
50
+ hasGLEffect ?? false,
51
+ {
52
+ imageUrl: url,
53
+ fragmentShader: fullShaderCode,
54
+ cursor: item.commonParams.FXCursor,
55
+ controls: controlValues
56
+ },
57
+ width,
58
+ height
59
+ );
48
60
  const rect = useElementRect(ref);
49
61
  const rectWidth = Math.floor(rect?.width ?? 0);
50
62
  const rectHeight = Math.floor(rect?.height ?? 0);
@@ -81,7 +93,6 @@ export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId, onResize
81
93
  src={item.commonParams.url}
82
94
  />
83
95
  )}
84
-
85
96
  </div>
86
97
  <JSXStyle id={id}>{`
87
98
  @supports not (color: oklch(42% 0.3 90 / 1)) {
@@ -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
 
@@ -27,7 +27,9 @@ export function useImageFx(
27
27
  fragmentShader,
28
28
  cursor,
29
29
  controls
30
- }: FxParams
30
+ }: FxParams,
31
+ width: number,
32
+ height: number
31
33
  ): void {
32
34
  const mousePos = useRef<[number, number]>([0.0, 0.0]);
33
35
  const imageFx = useMemo<ImageEffect | undefined>(() => {
@@ -42,8 +44,11 @@ export function useImageFx(
42
44
  time: 0,
43
45
  cursor: type === 'mouse' ? mousePos.current : [x, y],
44
46
  ...controls
45
- });
46
- }, [imageUrl, fragmentShader]);
47
+ },
48
+ width,
49
+ height
50
+ );
51
+ }, [imageUrl, fragmentShader, width, height]);
47
52
 
48
53
  useEffect(() => {
49
54
  if (!cursor || cursor.type !== 'mouse' || !canvas || !imageFx) return;