@cntrl-site/sdk-nextjs 0.21.5 → 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.
Binary file
@@ -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,
@@ -35,7 +36,8 @@ const itemsMap = {
35
36
  [sdk_1.ArticleItemType.RichText]: RichTextItem_1.RichTextItem,
36
37
  [sdk_1.ArticleItemType.YoutubeEmbed]: YoutubeEmbed_1.YoutubeEmbedItem,
37
38
  [sdk_1.ArticleItemType.VimeoEmbed]: VimeoEmbed_1.VimeoEmbedItem,
38
- [sdk_1.ArticleItemType.Custom]: CustomItem_1.CustomItem
39
+ [sdk_1.ArticleItemType.Custom]: CustomItem_1.CustomItem,
40
+ [sdk_1.ArticleItemType.Group]: GroupItem_1.GroupItem
39
41
  };
40
42
  const RichTextWrapper = ({ isRichText, children }) => {
41
43
  if (!isRichText)
@@ -106,7 +108,7 @@ const Item = ({ item, sectionId, articleHeight }) => {
106
108
  height: `${sizingAxis.y === 'manual' ? `${height * 100}vw` : 'unset'}`,
107
109
  transform: `scale(${scale})`,
108
110
  transformOrigin: ScaleAnchorMap_1.ScaleAnchorMap[scaleAnchor]
109
- } }, { 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: `
110
112
  ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, hidden, hoverParams, sticky, sectionHeight, layoutParams]) => {
111
113
  const sizingAxis = parseSizing(layoutParams.sizing);
112
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.21.5",
3
+ "version": "0.22.0",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.ts",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@cntrl-site/color": "^1.0.0",
25
25
  "@cntrl-site/effects": "^1.0.5-1",
26
- "@cntrl-site/sdk": "^1.4.2",
26
+ "@cntrl-site/sdk": "^1.5.5",
27
27
  "@types/vimeo__player": "^2.18.0",
28
28
  "@vimeo/player": "^2.20.1",
29
29
  "html-react-parser": "^3.0.1",
@@ -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> {
@@ -45,7 +47,8 @@ const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
45
47
  [ArticleItemType.RichText]: RichTextItem,
46
48
  [ArticleItemType.YoutubeEmbed]: YoutubeEmbedItem,
47
49
  [ArticleItemType.VimeoEmbed]: VimeoEmbedItem,
48
- [ArticleItemType.Custom]: CustomItem
50
+ [ArticleItemType.Custom]: CustomItem,
51
+ [ArticleItemType.Group]: GroupItem
49
52
  };
50
53
 
51
54
  interface RTWrapperProps {
@@ -146,7 +149,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight }) =
146
149
  transformOrigin: ScaleAnchorMap[scaleAnchor]
147
150
  }}
148
151
  >
149
- <ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} />
152
+ <ItemComponent item={item} sectionId={sectionId} onResize={handleItemResize} articleHeight={articleHeight} />
150
153
  </div>
151
154
  </RichTextWrapper>
152
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,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
@@ -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>