@cntrl-site/sdk-nextjs 0.21.7 → 0.22.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.
- package/cntrl-site-sdk-nextjs-0.21.7.tgz +0 -0
- package/lib/components/Item.js +3 -2
- package/lib/components/items/GroupItem.js +49 -0
- package/lib/components/items/useGroupItem.js +16 -0
- package/package.json +1 -1
- package/src/components/Item.tsx +4 -2
- package/src/components/items/GroupItem.tsx +62 -0
- package/src/components/items/useGroupItem.ts +20 -0
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -15
|
Binary file
|
package/lib/components/Item.js
CHANGED
|
@@ -28,6 +28,7 @@ const getAnchoredItemTop_1 = require("../utils/getAnchoredItemTop");
|
|
|
28
28
|
const useLayoutContext_1 = require("./useLayoutContext");
|
|
29
29
|
const ArticleRectContext_1 = require("../provider/ArticleRectContext");
|
|
30
30
|
const useExemplary_1 = require("../common/useExemplary");
|
|
31
|
+
const GroupItem_1 = require("./items/GroupItem");
|
|
31
32
|
const itemsMap = {
|
|
32
33
|
[sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
|
|
33
34
|
[sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
|
|
@@ -36,7 +37,7 @@ const itemsMap = {
|
|
|
36
37
|
[sdk_1.ArticleItemType.YoutubeEmbed]: YoutubeEmbed_1.YoutubeEmbedItem,
|
|
37
38
|
[sdk_1.ArticleItemType.VimeoEmbed]: VimeoEmbed_1.VimeoEmbedItem,
|
|
38
39
|
[sdk_1.ArticleItemType.Custom]: CustomItem_1.CustomItem,
|
|
39
|
-
[sdk_1.ArticleItemType.Group]:
|
|
40
|
+
[sdk_1.ArticleItemType.Group]: GroupItem_1.GroupItem
|
|
40
41
|
};
|
|
41
42
|
const RichTextWrapper = ({ isRichText, children }) => {
|
|
42
43
|
if (!isRichText)
|
|
@@ -107,7 +108,7 @@ const Item = ({ item, sectionId, articleHeight }) => {
|
|
|
107
108
|
height: `${sizingAxis.y === 'manual' ? `${height * 100}vw` : 'unset'}`,
|
|
108
109
|
transform: `scale(${scale})`,
|
|
109
110
|
transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]
|
|
110
|
-
} }, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize }) })) })) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
111
|
+
} }, { children: (0, jsx_runtime_1.jsx)(ItemComponent, { item: item, sectionId: sectionId, onResize: handleItemResize, articleHeight: articleHeight }) })) })) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
111
112
|
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
|
|
112
113
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
113
114
|
return (`
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GroupItem = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const Item_1 = require("../Item");
|
|
10
|
+
const style_1 = __importDefault(require("styled-jsx/style"));
|
|
11
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
12
|
+
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
13
|
+
const LinkWrapper_1 = require("../LinkWrapper");
|
|
14
|
+
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
15
|
+
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
|
+
const useItemAngle_1 = require("../useItemAngle");
|
|
17
|
+
const useGroupItem_1 = require("./useGroupItem");
|
|
18
|
+
const GroupItem = ({ item, sectionId, onResize, articleHeight }) => {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const id = (0, react_1.useId)();
|
|
21
|
+
const { items } = item;
|
|
22
|
+
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
23
|
+
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
24
|
+
const { opacity } = (0, useGroupItem_1.useGroupItem)(item, sectionId);
|
|
25
|
+
const [ref, setRef] = (0, react_1.useState)(null);
|
|
26
|
+
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, Object.assign({ url: (_a = item.link) === null || _a === void 0 ? void 0 : _a.url, target: (_b = item.link) === null || _b === void 0 ? void 0 : _b.target }, { children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: `group-${item.id}`, ref: setRef, style: {
|
|
28
|
+
opacity,
|
|
29
|
+
transform: `rotate(${angle}deg)`,
|
|
30
|
+
} }, { children: items && items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { item: item, sectionId: sectionId, articleHeight: articleHeight }, item.id))) })), (0, jsx_runtime_1.jsx)(style_1.default, Object.assign({ id: id }, { children: `
|
|
31
|
+
.group-${item.id} {
|
|
32
|
+
position: absolute;
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
}
|
|
37
|
+
${(0, sdk_1.getLayoutStyles)(layouts, [item.state.hover], ([hoverParams]) => {
|
|
38
|
+
return (`
|
|
39
|
+
.group-${item.id} {
|
|
40
|
+
transition: ${(0, HoverStyles_1.getTransitions)(['opacity'], hoverParams)};
|
|
41
|
+
}
|
|
42
|
+
.group-${item.id}:hover {
|
|
43
|
+
${(0, HoverStyles_1.getHoverStyles)(['opacity'], hoverParams)}
|
|
44
|
+
}
|
|
45
|
+
`);
|
|
46
|
+
})}
|
|
47
|
+
` }))] }) })));
|
|
48
|
+
};
|
|
49
|
+
exports.GroupItem = GroupItem;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useGroupItem = void 0;
|
|
4
|
+
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
5
|
+
const useLayoutContext_1 = require("../useLayoutContext");
|
|
6
|
+
function useGroupItem(item, sectionId) {
|
|
7
|
+
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
8
|
+
const opacity = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
9
|
+
if (!layoutId)
|
|
10
|
+
return 0;
|
|
11
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
12
|
+
return 'opacity' in layoutParams ? layoutParams.opacity : 0;
|
|
13
|
+
}, (animator, scroll, value) => animator.getOpacity({ opacity: value }, scroll).opacity, sectionId, [layoutId]);
|
|
14
|
+
return { opacity };
|
|
15
|
+
}
|
|
16
|
+
exports.useGroupItem = useGroupItem;
|
package/package.json
CHANGED
package/src/components/Item.tsx
CHANGED
|
@@ -27,11 +27,13 @@ import { getAnchoredItemTop } from '../utils/getAnchoredItemTop';
|
|
|
27
27
|
import { useLayoutContext } from './useLayoutContext';
|
|
28
28
|
import { ArticleRectContext } from "../provider/ArticleRectContext";
|
|
29
29
|
import { useExemplary } from "../common/useExemplary";
|
|
30
|
+
import { GroupItem } from './items/GroupItem';
|
|
30
31
|
|
|
31
32
|
export interface ItemProps<I extends ItemAny> {
|
|
32
33
|
item: I;
|
|
33
34
|
sectionId: string;
|
|
34
35
|
onResize?: (height: number) => void;
|
|
36
|
+
articleHeight: number;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export interface ItemWrapperProps extends ItemProps<ItemAny> {
|
|
@@ -46,7 +48,7 @@ const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
|
|
|
46
48
|
[ArticleItemType.YoutubeEmbed]: YoutubeEmbedItem,
|
|
47
49
|
[ArticleItemType.VimeoEmbed]: VimeoEmbedItem,
|
|
48
50
|
[ArticleItemType.Custom]: CustomItem,
|
|
49
|
-
[ArticleItemType.Group]:
|
|
51
|
+
[ArticleItemType.Group]: GroupItem
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
interface RTWrapperProps {
|
|
@@ -147,7 +149,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
|
|
|
147
149
|
transformOrigin: ScaleAnchorMap[scaleAnchor]
|
|
148
150
|
}}
|
|
149
151
|
>
|
|
150
|
-
<ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} />
|
|
152
|
+
<ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} articleHeight={articleHeight} />
|
|
151
153
|
</div>
|
|
152
154
|
</RichTextWrapper>
|
|
153
155
|
</div>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { FC, useId, useState } from 'react';
|
|
2
|
+
import { Item, ItemProps } from '../Item';
|
|
3
|
+
import JSXStyle from 'styled-jsx/style';
|
|
4
|
+
import { ArticleItemType, getLayoutStyles, GroupItem as TGroupItem } from '@cntrl-site/sdk';
|
|
5
|
+
import { getHoverStyles, getTransitions } from '../../utils/HoverStyles/HoverStyles';
|
|
6
|
+
import { LinkWrapper } from '../LinkWrapper';
|
|
7
|
+
import { useRegisterResize } from '../../common/useRegisterResize';
|
|
8
|
+
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
9
|
+
import { useItemAngle } from '../useItemAngle';
|
|
10
|
+
import { useGroupItem } from './useGroupItem';
|
|
11
|
+
|
|
12
|
+
export const GroupItem: FC<ItemProps<TGroupItem>> = ({ item, sectionId, onResize, articleHeight }) => {
|
|
13
|
+
const id = useId();
|
|
14
|
+
const { items } = item;
|
|
15
|
+
const angle = useItemAngle(item, sectionId);
|
|
16
|
+
const { layouts } = useCntrlContext();
|
|
17
|
+
const { opacity } = useGroupItem(item, sectionId);
|
|
18
|
+
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
19
|
+
useRegisterResize(ref, onResize);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<LinkWrapper url={item.link?.url} target={item.link?.target}>
|
|
23
|
+
<>
|
|
24
|
+
<div
|
|
25
|
+
className={`group-${item.id}`}
|
|
26
|
+
ref={setRef}
|
|
27
|
+
style={{
|
|
28
|
+
opacity,
|
|
29
|
+
transform: `rotate(${angle}deg)`,
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
{items && items.map(item => (
|
|
33
|
+
<Item
|
|
34
|
+
item={item}
|
|
35
|
+
key={item.id}
|
|
36
|
+
sectionId={sectionId}
|
|
37
|
+
articleHeight={articleHeight}
|
|
38
|
+
/>
|
|
39
|
+
))}
|
|
40
|
+
</div>
|
|
41
|
+
<JSXStyle id={id}>{`
|
|
42
|
+
.group-${item.id} {
|
|
43
|
+
position: absolute;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: 100%;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
}
|
|
48
|
+
${getLayoutStyles(layouts, [item.state.hover], ([hoverParams]) => {
|
|
49
|
+
return (`
|
|
50
|
+
.group-${item.id} {
|
|
51
|
+
transition: ${getTransitions<ArticleItemType.Group>(['opacity'], hoverParams)};
|
|
52
|
+
}
|
|
53
|
+
.group-${item.id}:hover {
|
|
54
|
+
${getHoverStyles<ArticleItemType.Group>(['opacity'], hoverParams)}
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
|
+
})}
|
|
58
|
+
`}</JSXStyle>
|
|
59
|
+
</>
|
|
60
|
+
</LinkWrapper>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
2
|
+
import { GroupItem } from '@cntrl-site/sdk';
|
|
3
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
4
|
+
|
|
5
|
+
export function useGroupItem(item: GroupItem, sectionId: string) {
|
|
6
|
+
const layoutId = useLayoutContext();
|
|
7
|
+
const opacity = useKeyframeValue(
|
|
8
|
+
item,
|
|
9
|
+
(item, layoutId) => {
|
|
10
|
+
if (!layoutId) return 0;
|
|
11
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
12
|
+
return 'opacity' in layoutParams ? layoutParams.opacity : 0;
|
|
13
|
+
},
|
|
14
|
+
(animator, scroll, value) => animator.getOpacity({ opacity: value }, scroll).opacity,
|
|
15
|
+
sectionId,
|
|
16
|
+
[layoutId]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return { opacity };
|
|
20
|
+
}
|
|
@@ -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>
|