@cntrl-site/sdk-nextjs 0.17.1 → 0.17.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.
- package/lib/common/useRegisterResize.js +1 -1
- package/lib/components/Item.js +4 -4
- package/lib/components/items/useStickyItemTop.js +1 -5
- package/package.json +1 -1
- package/src/common/useRegisterResize.ts +1 -1
- package/src/components/Item.tsx +4 -4
- package/src/components/items/useStickyItemTop.ts +2 -5
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -15
- package/cntrl-site-sdk-nextjs-0.17.1.tgz +0 -0
|
@@ -12,7 +12,7 @@ const useRegisterResize = (ref, onResize) => {
|
|
|
12
12
|
return;
|
|
13
13
|
const observer = new resize_observer_polyfill_1.default((entries) => {
|
|
14
14
|
const [entry] = entries;
|
|
15
|
-
onResize(entry.target.
|
|
15
|
+
onResize(entry.target.clientHeight / window.innerWidth);
|
|
16
16
|
});
|
|
17
17
|
observer.observe(ref);
|
|
18
18
|
return () => {
|
package/lib/components/Item.js
CHANGED
|
@@ -71,8 +71,6 @@ const Item = ({ item, sectionId, articleHeight }) => {
|
|
|
71
71
|
const ItemComponent = itemsMap[item.type] || noop;
|
|
72
72
|
const sectionTop = rectObserver ? rectObserver.getSectionTop(sectionId) : 0;
|
|
73
73
|
const handleItemResize = (height) => {
|
|
74
|
-
var _a, _b;
|
|
75
|
-
const itemSectionTop = (_b = (_a = itemWrapperRef.current) === null || _a === void 0 ? void 0 : _a.offsetTop) !== null && _b !== void 0 ? _b : 0;
|
|
76
74
|
if (!layout)
|
|
77
75
|
return;
|
|
78
76
|
const sticky = item.sticky[layout];
|
|
@@ -80,7 +78,7 @@ const Item = ({ item, sectionId, articleHeight }) => {
|
|
|
80
78
|
setWrapperHeight(undefined);
|
|
81
79
|
return;
|
|
82
80
|
}
|
|
83
|
-
const itemArticleOffset =
|
|
81
|
+
const itemArticleOffset = sectionTop / window.innerWidth + stickyTop;
|
|
84
82
|
const maxStickyTo = articleHeight - itemArticleOffset - height;
|
|
85
83
|
const end = sticky.to
|
|
86
84
|
? Math.min(maxStickyTo, sticky.to)
|
|
@@ -93,8 +91,10 @@ const Item = ({ item, sectionId, articleHeight }) => {
|
|
|
93
91
|
isInitialRef.current = false;
|
|
94
92
|
}, []);
|
|
95
93
|
const isRichText = isItemType(item, sdk_1.ArticleItemType.RichText);
|
|
94
|
+
if (!layout)
|
|
95
|
+
return null;
|
|
96
96
|
const styles = {
|
|
97
|
-
top: stickyTop,
|
|
97
|
+
top: `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(stickyTop, sectionHeight[layout], item.area[layout].anchorSide)}`,
|
|
98
98
|
height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
|
|
99
99
|
};
|
|
100
100
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ 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", Object.assign({ suppressHydrationWarning: true, className: `item-${item.id}`, style: isInitialRef.current ? {} : styles }, { children: (0, jsx_runtime_1.jsx)(RichTextWrapper, Object.assign({ isRichText: isRichText }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `item-${item.id}-inner`, style: {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useStickyItemTop = void 0;
|
|
4
|
-
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
4
|
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
|
-
const getAnchoredItemTop_1 = require("../../utils/getAnchoredItemTop");
|
|
7
5
|
const useLayoutContext_1 = require("../useLayoutContext");
|
|
8
6
|
function useStickyItemTop(item, sectionHeightMap, sectionId) {
|
|
9
7
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
@@ -13,8 +11,6 @@ function useStickyItemTop(item, sectionHeightMap, sectionId) {
|
|
|
13
11
|
return item.area[layoutId];
|
|
14
12
|
}, (animator, scroll, value) => animator.getPositions(value, scroll), sectionId, [layoutId]);
|
|
15
13
|
const sticky = layoutId ? item.sticky[layoutId] : undefined;
|
|
16
|
-
|
|
17
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
|
|
18
|
-
return sticky ? `${(0, getAnchoredItemTop_1.getAnchoredItemTop)(top - sticky.from, sectionHeight, anchorSide)}` : 0;
|
|
14
|
+
return sticky ? top - sticky.from : 0;
|
|
19
15
|
}
|
|
20
16
|
exports.useStickyItemTop = useStickyItemTop;
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export const useRegisterResize = (ref: HTMLElement | null, onResize?: (height: n
|
|
|
6
6
|
if (!ref || !onResize) return;
|
|
7
7
|
const observer = new ResizeObserver((entries) => {
|
|
8
8
|
const [entry] = entries;
|
|
9
|
-
onResize(entry.target.
|
|
9
|
+
onResize(entry.target.clientHeight / window.innerWidth);
|
|
10
10
|
});
|
|
11
11
|
observer.observe(ref);
|
|
12
12
|
return () => {
|
package/src/components/Item.tsx
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
ArticleItemType,
|
|
6
6
|
getLayoutStyles,
|
|
7
7
|
TArticleItem,
|
|
8
|
-
TStickyParams,
|
|
9
8
|
TArticleItemAny,
|
|
10
9
|
} from '@cntrl-site/sdk';
|
|
11
10
|
import { RectangleItem } from './items/RectangleItem';
|
|
@@ -94,14 +93,13 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
|
|
|
94
93
|
const sectionTop = rectObserver ? rectObserver.getSectionTop(sectionId) : 0;
|
|
95
94
|
|
|
96
95
|
const handleItemResize = (height: number) => {
|
|
97
|
-
const itemSectionTop = itemWrapperRef.current?.offsetTop ?? 0;
|
|
98
96
|
if (!layout) return;
|
|
99
97
|
const sticky = item.sticky[layout];
|
|
100
98
|
if (!sticky) {
|
|
101
99
|
setWrapperHeight(undefined);
|
|
102
100
|
return;
|
|
103
101
|
}
|
|
104
|
-
const itemArticleOffset =
|
|
102
|
+
const itemArticleOffset = sectionTop / window.innerWidth + stickyTop;
|
|
105
103
|
const maxStickyTo = articleHeight - itemArticleOffset - height;
|
|
106
104
|
const end = sticky.to
|
|
107
105
|
? Math.min(maxStickyTo, sticky.to)
|
|
@@ -117,8 +115,10 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
|
|
|
117
115
|
|
|
118
116
|
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
119
117
|
|
|
118
|
+
if (!layout) return null;
|
|
119
|
+
|
|
120
120
|
const styles = {
|
|
121
|
-
top: stickyTop,
|
|
121
|
+
top: `${getAnchoredItemTop(stickyTop, sectionHeight[layout], item.area[layout].anchorSide)}`,
|
|
122
122
|
height: isRichText && itemHeight ? `${itemHeight * 100}vw` : 'unset'
|
|
123
123
|
};
|
|
124
124
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TArticleItemAny } from '@cntrl-site/sdk';
|
|
2
2
|
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
|
-
import { getAnchoredItemTop } from '../../utils/getAnchoredItemTop';
|
|
4
3
|
import { useLayoutContext } from '../useLayoutContext';
|
|
5
4
|
|
|
6
5
|
export function useStickyItemTop(item: TArticleItemAny, sectionHeightMap: Record<string, string>, sectionId: string) {
|
|
@@ -16,7 +15,5 @@ export function useStickyItemTop(item: TArticleItemAny, sectionHeightMap: Record
|
|
|
16
15
|
[layoutId]
|
|
17
16
|
);
|
|
18
17
|
const sticky = layoutId ? item.sticky[layoutId] : undefined;
|
|
19
|
-
|
|
20
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
|
|
21
|
-
return sticky ? `${getAnchoredItemTop(top - sticky.from, sectionHeight, anchorSide)}` : 0
|
|
18
|
+
return sticky ? top - sticky.from : 0
|
|
22
19
|
}
|
|
@@ -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
|