@cntrl-site/sdk-nextjs 0.7.3 → 0.8.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.
|
Binary file
|
package/lib/components/Item.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Item = void 0;
|
|
3
|
+
exports.isItemType = exports.Item = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
@@ -17,6 +17,7 @@ const useItemPosition_1 = require("./useItemPosition");
|
|
|
17
17
|
const useItemDimensions_1 = require("./useItemDimensions");
|
|
18
18
|
const useItemSticky_1 = require("./items/useItemSticky");
|
|
19
19
|
const castObject_1 = require("../utils/castObject");
|
|
20
|
+
const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
20
21
|
const itemsMap = {
|
|
21
22
|
[sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
|
|
22
23
|
[sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
|
|
@@ -31,6 +32,7 @@ const Item = ({ item }) => {
|
|
|
31
32
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
32
33
|
const angle = (0, useItemAngle_1.useItemAngle)(item);
|
|
33
34
|
const position = (0, useItemPosition_1.useItemPosition)(item);
|
|
35
|
+
const layout = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
34
36
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
35
37
|
const [parentOffsetTop, setParentOffsetTop] = (0, react_1.useState)(0);
|
|
36
38
|
const { top, isFixed } = (0, useItemSticky_1.useItemSticky)(position.top, parentOffsetTop, item);
|
|
@@ -40,7 +42,10 @@ const Item = ({ item }) => {
|
|
|
40
42
|
if (item.layoutParams) {
|
|
41
43
|
layoutValues.push(item.layoutParams);
|
|
42
44
|
}
|
|
43
|
-
const
|
|
45
|
+
const sizing = isItemType(item, sdk_1.ArticleItemType.RichText)
|
|
46
|
+
? item.layoutParams[layout].sizing
|
|
47
|
+
: undefined;
|
|
48
|
+
const sizingAxis = parseSizing(sizing);
|
|
44
49
|
const ItemComponent = itemsMap[item.type] || noop;
|
|
45
50
|
(0, react_1.useEffect)(() => {
|
|
46
51
|
isInitialRef.current = false;
|
|
@@ -59,7 +64,9 @@ const Item = ({ item }) => {
|
|
|
59
64
|
top
|
|
60
65
|
};
|
|
61
66
|
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
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area]) =>
|
|
67
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
68
|
+
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
69
|
+
return (`
|
|
63
70
|
.item-${item.id} {
|
|
64
71
|
position: absolute;
|
|
65
72
|
z-index: ${area.zIndex};
|
|
@@ -70,14 +77,19 @@ const Item = ({ item }) => {
|
|
|
70
77
|
z-index: ${area.zIndex};
|
|
71
78
|
transform: rotate(${area.angle}deg);
|
|
72
79
|
}
|
|
73
|
-
|
|
80
|
+
`);
|
|
81
|
+
})}
|
|
74
82
|
` })] }));
|
|
75
83
|
};
|
|
76
84
|
exports.Item = Item;
|
|
77
|
-
function parseSizing(sizing) {
|
|
85
|
+
function parseSizing(sizing = 'manual') {
|
|
78
86
|
const axisSizing = sizing.split(' ');
|
|
79
87
|
return {
|
|
80
88
|
y: axisSizing[0],
|
|
81
89
|
x: axisSizing[1] ? axisSizing[1] : axisSizing[0]
|
|
82
90
|
};
|
|
83
91
|
}
|
|
92
|
+
function isItemType(item, itemType) {
|
|
93
|
+
return item.type === itemType;
|
|
94
|
+
}
|
|
95
|
+
exports.isItemType = isItemType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cntrl-site/sdk": "^0.
|
|
24
|
+
"@cntrl-site/sdk": "^0.7.0",
|
|
25
25
|
"html-react-parser": "^3.0.1",
|
|
26
26
|
"styled-jsx": "^5.0.2"
|
|
27
27
|
},
|
|
@@ -8,7 +8,7 @@ interface LayoutData {
|
|
|
8
8
|
end: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const useCurrentLayout = () => {
|
|
11
|
+
export const useCurrentLayout = (): string => {
|
|
12
12
|
const { layouts } = useCntrlContext();
|
|
13
13
|
const articleRectObserver = useContext(ArticleRectContext);
|
|
14
14
|
const layoutRanges = useMemo(() => {
|
package/src/components/Item.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ComponentType, FC, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
getLayoutStyles,
|
|
4
|
-
ArticleItemType,
|
|
5
3
|
ArticleItemSizingType as SizingType,
|
|
4
|
+
ArticleItemType,
|
|
5
|
+
getLayoutStyles,
|
|
6
|
+
TArticleItem,
|
|
6
7
|
TArticleItemAny
|
|
7
8
|
} from '@cntrl-site/sdk';
|
|
8
9
|
import { RectangleItem } from './items/RectangleItem';
|
|
@@ -18,6 +19,7 @@ import { useItemPosition } from './useItemPosition';
|
|
|
18
19
|
import { useItemDimensions } from './useItemDimensions';
|
|
19
20
|
import { getItemTopStyle, useItemSticky } from './items/useItemSticky';
|
|
20
21
|
import { castObject } from '../utils/castObject';
|
|
22
|
+
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
21
23
|
|
|
22
24
|
export interface ItemProps<I extends TArticleItemAny> {
|
|
23
25
|
item: I;
|
|
@@ -39,6 +41,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
|
39
41
|
const { layouts } = useCntrlContext();
|
|
40
42
|
const angle = useItemAngle(item);
|
|
41
43
|
const position = useItemPosition(item);
|
|
44
|
+
const layout = useCurrentLayout();
|
|
42
45
|
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
43
46
|
const [parentOffsetTop, setParentOffsetTop] = useState(0);
|
|
44
47
|
const { top, isFixed } = useItemSticky(position.top, parentOffsetTop, item);
|
|
@@ -49,7 +52,10 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
|
49
52
|
layoutValues.push(item.layoutParams);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
const
|
|
55
|
+
const sizing = isItemType(item, ArticleItemType.RichText)
|
|
56
|
+
? item.layoutParams[layout].sizing
|
|
57
|
+
: undefined;
|
|
58
|
+
const sizingAxis = parseSizing(sizing);
|
|
53
59
|
const ItemComponent = itemsMap[item.type] || noop;
|
|
54
60
|
|
|
55
61
|
useEffect(() => {
|
|
@@ -79,7 +85,9 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
|
79
85
|
>
|
|
80
86
|
<ItemComponent item={item} />
|
|
81
87
|
<style jsx>{`
|
|
82
|
-
${getLayoutStyles(layouts, layoutValues, ([area]) =>
|
|
88
|
+
${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
89
|
+
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
90
|
+
return (`
|
|
83
91
|
.item-${item.id} {
|
|
84
92
|
position: absolute;
|
|
85
93
|
z-index: ${area.zIndex};
|
|
@@ -90,13 +98,14 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
|
90
98
|
z-index: ${area.zIndex};
|
|
91
99
|
transform: rotate(${area.angle}deg);
|
|
92
100
|
}
|
|
93
|
-
|
|
101
|
+
`);
|
|
102
|
+
})}
|
|
94
103
|
`}</style>
|
|
95
104
|
</div>
|
|
96
105
|
);
|
|
97
106
|
};
|
|
98
107
|
|
|
99
|
-
function parseSizing(sizing: string): Axis {
|
|
108
|
+
function parseSizing(sizing: string = 'manual'): Axis {
|
|
100
109
|
const axisSizing = sizing.split(' ');
|
|
101
110
|
return {
|
|
102
111
|
y: axisSizing[0],
|
|
@@ -108,3 +117,7 @@ interface Axis {
|
|
|
108
117
|
x: SizingType;
|
|
109
118
|
y: SizingType;
|
|
110
119
|
}
|
|
120
|
+
|
|
121
|
+
export function isItemType<T extends ArticleItemType>(item: TArticleItemAny, itemType: T): item is TArticleItem<T> {
|
|
122
|
+
return item.type === itemType;
|
|
123
|
+
}
|