@cntrl-site/sdk-nextjs 1.1.5-alpha.2 → 1.2.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-1.2.3.tgz +0 -0
- package/lib/components/Article.js +2 -2
- package/lib/components/{Section.js → Section/Section.js} +2 -2
- package/lib/components/{useSectionHeightMap.js → Section/useSectionHeightMap.js} +1 -1
- package/lib/components/items/{CodeEmbedItem.js → CodeEmbedItem/CodeEmbedItem.js} +2 -2
- package/lib/components/items/{useCodeEmbedItem.js → CodeEmbedItem/useCodeEmbedItem.js} +2 -2
- package/lib/components/items/CompoundItem/CompoundChild.js +115 -0
- package/lib/components/items/CompoundItem/CompoundItem.js +52 -0
- package/lib/components/items/CompoundItem/useCompoundItem.js +17 -0
- package/lib/components/items/{CustomItem.js → CustomItem/CustomItem.js} +2 -2
- package/lib/components/items/{VimeoEmbed.js → EmbedVideoItem/VimeoEmbed.js} +4 -4
- package/lib/components/items/{YoutubeEmbed.js → EmbedVideoItem/YoutubeEmbed.js} +5 -5
- package/lib/components/items/{useEmbedVideoItem.js → EmbedVideoItem/useEmbedVideoItem.js} +2 -2
- package/lib/components/items/{ImageItem.js → FileItem/ImageItem.js} +6 -6
- package/lib/components/items/{VideoItem.js → FileItem/VideoItem.js} +5 -5
- package/lib/components/items/{useFileItem.js → FileItem/useFileItem.js} +2 -2
- package/lib/components/items/{GroupItem.js → GroupItem/GroupItem.js} +5 -5
- package/lib/components/items/{useGroupItem.js → GroupItem/useGroupItem.js} +2 -2
- package/lib/components/{Item.js → items/Item.js} +24 -47
- package/lib/components/items/{RectangleItem.js → RectangleItem/RectangleItem.js} +3 -3
- package/lib/components/items/{useRectangleItem.js → RectangleItem/useRectangleItem.js} +2 -2
- package/lib/components/items/{RichTextItem.js → RichTextItem/RichTextItem.js} +7 -7
- package/lib/components/items/{useRichTextItem.js → RichTextItem/useRichTextItem.js} +2 -2
- package/lib/components/items/RichTextWrapper.js +10 -0
- package/lib/components/items/itemsMap.js +26 -0
- package/lib/components/{useItemAngle.js → items/useItemAngle.js} +1 -1
- package/lib/components/{useItemDimensions.js → items/useItemDimensions.js} +2 -2
- package/lib/components/{useItemPosition.js → items/useItemPosition.js} +4 -9
- package/lib/components/{useItemScale.js → items/useItemScale.js} +2 -2
- package/lib/index.js +8 -8
- package/lib/interactions/InteractionsRegistry.js +6 -14
- package/lib/utils/RichTextConverter/RichTextConverter.js +1 -1
- package/lib/utils/getCompoundBondaryStyles.js +61 -0
- package/lib/utils/isItemType.js +7 -0
- package/package.json +2 -4
- package/src/components/Article.tsx +2 -2
- package/src/components/{Section.tsx → Section/Section.tsx} +2 -2
- package/src/components/{useSectionColor.ts → Section/useSectionColor.ts} +1 -1
- package/src/components/{useSectionHeightMap.ts → Section/useSectionHeightMap.ts} +1 -1
- package/src/components/items/{CodeEmbedItem.tsx → CodeEmbedItem/CodeEmbedItem.tsx} +2 -2
- package/src/components/items/{useCodeEmbedItem.ts → CodeEmbedItem/useCodeEmbedItem.ts} +2 -2
- package/src/components/items/CompoundItem/CompoundChild.tsx +160 -0
- package/src/components/items/CompoundItem/CompoundItem.tsx +70 -0
- package/src/components/items/CompoundItem/useCompoundItem.ts +21 -0
- package/src/components/items/{CustomItem.tsx → CustomItem/CustomItem.tsx} +2 -2
- package/src/components/items/{VimeoEmbed.tsx → EmbedVideoItem/VimeoEmbed.tsx} +4 -5
- package/src/components/items/{YoutubeEmbed.tsx → EmbedVideoItem/YoutubeEmbed.tsx} +6 -6
- package/src/components/items/{useEmbedVideoItem.ts → EmbedVideoItem/useEmbedVideoItem.ts} +2 -2
- package/src/components/items/{ImageItem.tsx → FileItem/ImageItem.tsx} +6 -6
- package/src/components/items/{VideoItem.tsx → FileItem/VideoItem.tsx} +5 -5
- package/src/components/items/{useFileItem.ts → FileItem/useFileItem.ts} +2 -2
- package/src/components/items/{GroupItem.tsx → GroupItem/GroupItem.tsx} +4 -5
- package/src/components/items/{useGroupItem.ts → GroupItem/useGroupItem.ts} +2 -2
- package/src/components/{Item.tsx → items/Item.tsx} +24 -59
- package/src/components/items/{RectangleItem.tsx → RectangleItem/RectangleItem.tsx} +3 -3
- package/src/components/items/{useRectangleItem.ts → RectangleItem/useRectangleItem.ts} +2 -2
- package/src/components/items/{RichTextItem.tsx → RichTextItem/RichTextItem.tsx} +7 -7
- package/src/components/items/{useRichTextItem.ts → RichTextItem/useRichTextItem.ts} +2 -2
- package/src/components/items/RichTextWrapper.tsx +15 -0
- package/src/components/items/itemsMap.ts +26 -0
- package/src/components/{useItemAngle.ts → items/useItemAngle.ts} +1 -1
- package/src/components/{useItemDimensions.ts → items/useItemDimensions.ts} +2 -2
- package/src/components/{useItemPosition.ts → items/useItemPosition.ts} +6 -9
- package/src/components/{useItemScale.ts → items/useItemScale.ts} +2 -2
- package/src/index.ts +8 -8
- package/src/interactions/InteractionsRegistry.ts +7 -14
- package/src/utils/RichTextConverter/RichTextConverter.tsx +1 -1
- package/src/utils/getCompoundBondaryStyles.ts +62 -0
- package/src/utils/isItemType.ts +6 -0
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -15
- package/lib/interactions/AudioPlayer.js +0 -16
- package/src/interactions/AudioPlayer.ts +0 -16
- /package/lib/components/{LinkWrapper.js → items/LinkWrapper.js} +0 -0
- /package/src/components/{LinkWrapper.tsx → items/LinkWrapper.tsx} +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RichTextWrapper = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const RichTextWrapper = ({ isRichText, children, transformOrigin = 'top left' }) => {
|
|
6
|
+
if (!isRichText)
|
|
7
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { transformOrigin, transform: 'scale(var(--layout-deviation))' }, children: children }));
|
|
9
|
+
};
|
|
10
|
+
exports.RichTextWrapper = RichTextWrapper;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.itemsMap = void 0;
|
|
4
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
+
const RectangleItem_1 = require("./RectangleItem/RectangleItem");
|
|
6
|
+
const ImageItem_1 = require("./FileItem/ImageItem");
|
|
7
|
+
const VideoItem_1 = require("./FileItem/VideoItem");
|
|
8
|
+
const RichTextItem_1 = require("./RichTextItem/RichTextItem");
|
|
9
|
+
const YoutubeEmbed_1 = require("./EmbedVideoItem/YoutubeEmbed");
|
|
10
|
+
const VimeoEmbed_1 = require("./EmbedVideoItem/VimeoEmbed");
|
|
11
|
+
const CustomItem_1 = require("./CustomItem/CustomItem");
|
|
12
|
+
const GroupItem_1 = require("./GroupItem/GroupItem");
|
|
13
|
+
const CodeEmbedItem_1 = require("./CodeEmbedItem/CodeEmbedItem");
|
|
14
|
+
const CompoundItem_1 = require("./CompoundItem/CompoundItem");
|
|
15
|
+
exports.itemsMap = {
|
|
16
|
+
[sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
|
|
17
|
+
[sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
|
|
18
|
+
[sdk_1.ArticleItemType.Video]: VideoItem_1.VideoItem,
|
|
19
|
+
[sdk_1.ArticleItemType.RichText]: RichTextItem_1.RichTextItem,
|
|
20
|
+
[sdk_1.ArticleItemType.YoutubeEmbed]: YoutubeEmbed_1.YoutubeEmbedItem,
|
|
21
|
+
[sdk_1.ArticleItemType.VimeoEmbed]: VimeoEmbed_1.VimeoEmbedItem,
|
|
22
|
+
[sdk_1.ArticleItemType.Custom]: CustomItem_1.CustomItem,
|
|
23
|
+
[sdk_1.ArticleItemType.Group]: GroupItem_1.GroupItem,
|
|
24
|
+
[sdk_1.ArticleItemType.Compound]: CompoundItem_1.CompoundItem,
|
|
25
|
+
[sdk_1.ArticleItemType.CodeEmbed]: CodeEmbedItem_1.CodeEmbedItem
|
|
26
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useItemAngle = void 0;
|
|
4
4
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const useKeyframeValue_1 = require("
|
|
5
|
+
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
6
|
const useItemAngle = (item, sectionId) => {
|
|
7
7
|
const angle = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Rotation, (item, layoutId) => layoutId ? item.area[layoutId].angle : undefined, (animator, scroll, value) => value !== undefined ? animator.getRotation({ angle: value }, scroll).angle : undefined, sectionId);
|
|
8
8
|
return angle;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useItemDimensions = void 0;
|
|
4
4
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const useKeyframeValue_1 = require("
|
|
6
|
-
const useLayoutContext_1 = require("
|
|
5
|
+
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
|
+
const useLayoutContext_1 = require("../useLayoutContext");
|
|
7
7
|
const useItemDimensions = (item, sectionId) => {
|
|
8
8
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
9
9
|
const dimensions = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Dimensions, (item, layoutId) => layoutId ? item.area[layoutId] : undefined, (animator, scroll, value) => value ? animator.getDimensions(value, scroll) : undefined, sectionId, [layoutId]);
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useItemPosition = void 0;
|
|
4
4
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const useKeyframeValue_1 = require("
|
|
6
|
-
const
|
|
7
|
-
const useLayoutContext_1 = require("./useLayoutContext");
|
|
5
|
+
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
|
+
const useLayoutContext_1 = require("../useLayoutContext");
|
|
8
7
|
const useItemPosition = (item, sectionId, stateValues) => {
|
|
9
8
|
var _a, _b;
|
|
10
9
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
@@ -13,18 +12,14 @@ const useItemPosition = (item, sectionId, stateValues) => {
|
|
|
13
12
|
return;
|
|
14
13
|
return item.area[layoutId];
|
|
15
14
|
}, (animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined, sectionId, [layoutId]);
|
|
16
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
|
|
17
|
-
const positionType = layoutId ? item.area[layoutId].positionType : sdk_1.PositionType.ScreenBased;
|
|
18
15
|
// to prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
|
|
19
|
-
const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
|
|
20
16
|
if (!position)
|
|
21
17
|
return undefined;
|
|
22
18
|
const top = (_a = stateValues === null || stateValues === void 0 ? void 0 : stateValues.top) !== null && _a !== void 0 ? _a : position.top;
|
|
23
19
|
const left = (_b = stateValues === null || stateValues === void 0 ? void 0 : stateValues.left) !== null && _b !== void 0 ? _b : position.left;
|
|
24
20
|
return position ? {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
left: `${left * 100}vw`
|
|
21
|
+
top,
|
|
22
|
+
left
|
|
28
23
|
} : undefined;
|
|
29
24
|
};
|
|
30
25
|
exports.useItemPosition = useItemPosition;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useItemScale = void 0;
|
|
4
4
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const useKeyframeValue_1 = require("
|
|
6
|
-
const useLayoutContext_1 = require("
|
|
5
|
+
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
|
+
const useLayoutContext_1 = require("../useLayoutContext");
|
|
7
7
|
const useItemScale = (item, sectionId) => {
|
|
8
8
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
9
9
|
const scale = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Scale, (item, layoutId) => (layoutId ? item.area[layoutId].scale : undefined), (animator, scroll, value) => value !== undefined ? animator.getScale({ scale: value }, scroll).scale : undefined, sectionId, [layoutId]);
|
package/lib/index.js
CHANGED
|
@@ -24,23 +24,23 @@ var Head_1 = require("./components/Head");
|
|
|
24
24
|
Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return Head_1.CNTRLHead; } });
|
|
25
25
|
var Article_1 = require("./components/Article");
|
|
26
26
|
Object.defineProperty(exports, "Article", { enumerable: true, get: function () { return Article_1.Article; } });
|
|
27
|
-
var Section_1 = require("./components/Section");
|
|
27
|
+
var Section_1 = require("./components/Section/Section");
|
|
28
28
|
Object.defineProperty(exports, "Section", { enumerable: true, get: function () { return Section_1.Section; } });
|
|
29
|
-
var Item_1 = require("./components/Item");
|
|
29
|
+
var Item_1 = require("./components/items/Item");
|
|
30
30
|
Object.defineProperty(exports, "Item", { enumerable: true, get: function () { return Item_1.Item; } });
|
|
31
|
-
var ImageItem_1 = require("./components/items/ImageItem");
|
|
31
|
+
var ImageItem_1 = require("./components/items/FileItem/ImageItem");
|
|
32
32
|
Object.defineProperty(exports, "ImageItem", { enumerable: true, get: function () { return ImageItem_1.ImageItem; } });
|
|
33
|
-
var RectangleItem_1 = require("./components/items/RectangleItem");
|
|
33
|
+
var RectangleItem_1 = require("./components/items/RectangleItem/RectangleItem");
|
|
34
34
|
Object.defineProperty(exports, "RectangleItem", { enumerable: true, get: function () { return RectangleItem_1.RectangleItem; } });
|
|
35
|
-
var RichTextItem_1 = require("./components/items/RichTextItem");
|
|
35
|
+
var RichTextItem_1 = require("./components/items/RichTextItem/RichTextItem");
|
|
36
36
|
Object.defineProperty(exports, "RichTextItem", { enumerable: true, get: function () { return RichTextItem_1.RichTextItem; } });
|
|
37
|
-
var VideoItem_1 = require("./components/items/VideoItem");
|
|
37
|
+
var VideoItem_1 = require("./components/items/FileItem/VideoItem");
|
|
38
38
|
Object.defineProperty(exports, "VideoItem", { enumerable: true, get: function () { return VideoItem_1.VideoItem; } });
|
|
39
39
|
var LayoutStyle_1 = require("./components/LayoutStyle");
|
|
40
40
|
Object.defineProperty(exports, "LayoutStyle", { enumerable: true, get: function () { return LayoutStyle_1.LayoutStyle; } });
|
|
41
|
-
var VimeoEmbed_1 = require("./components/items/VimeoEmbed");
|
|
41
|
+
var VimeoEmbed_1 = require("./components/items/EmbedVideoItem/VimeoEmbed");
|
|
42
42
|
Object.defineProperty(exports, "VimeoEmbedItem", { enumerable: true, get: function () { return VimeoEmbed_1.VimeoEmbedItem; } });
|
|
43
|
-
var YoutubeEmbed_1 = require("./components/items/YoutubeEmbed");
|
|
43
|
+
var YoutubeEmbed_1 = require("./components/items/EmbedVideoItem/YoutubeEmbed");
|
|
44
44
|
Object.defineProperty(exports, "YoutubeEmbedItem", { enumerable: true, get: function () { return YoutubeEmbed_1.YoutubeEmbedItem; } });
|
|
45
45
|
const defaultContext_1 = require("./provider/defaultContext");
|
|
46
46
|
var CntrlProvider_1 = require("./provider/CntrlProvider");
|
|
@@ -13,13 +13,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.InteractionsRegistry = void 0;
|
|
15
15
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
16
|
-
const
|
|
17
|
-
const AudioPlayer_1 = require("./AudioPlayer");
|
|
16
|
+
const isItemType_1 = require("../utils/isItemType");
|
|
18
17
|
class InteractionsRegistry {
|
|
19
18
|
constructor(article, layoutId) {
|
|
20
19
|
this.layoutId = layoutId;
|
|
21
20
|
this.ctrls = new Map();
|
|
22
|
-
this.audioPlayer = new AudioPlayer_1.AudioPlayer();
|
|
23
21
|
const { interactions } = article;
|
|
24
22
|
this.items = this.unpackItems(article);
|
|
25
23
|
const activeStatesIds = interactions.reduce((map, inter) => {
|
|
@@ -141,9 +139,6 @@ class InteractionsRegistry {
|
|
|
141
139
|
for (const trigger of interaction.triggers) {
|
|
142
140
|
itemsToNotify.add(trigger.itemId);
|
|
143
141
|
}
|
|
144
|
-
if (triggerType === 'click') {
|
|
145
|
-
this.playClickSound();
|
|
146
|
-
}
|
|
147
142
|
this.notifyItemCtrlsChange(Array.from(itemsToNotify));
|
|
148
143
|
this.notifyTransitionStartForItems(transitioningItems, activeStateId);
|
|
149
144
|
}
|
|
@@ -207,11 +202,11 @@ class InteractionsRegistry {
|
|
|
207
202
|
for (const item of section.items) {
|
|
208
203
|
const { items } = item, itemWithoutChildren = __rest(item, ["items"]);
|
|
209
204
|
itemsArr.push(itemWithoutChildren);
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
205
|
+
if ((0, isItemType_1.isItemType)(item, sdk_1.ArticleItemType.Group) || (0, isItemType_1.isItemType)(item, sdk_1.ArticleItemType.Compound)) {
|
|
206
|
+
const groupChildren = (_a = item === null || item === void 0 ? void 0 : item.items) !== null && _a !== void 0 ? _a : [];
|
|
207
|
+
for (const child of groupChildren) {
|
|
208
|
+
itemsArr.push(child);
|
|
209
|
+
}
|
|
215
210
|
}
|
|
216
211
|
}
|
|
217
212
|
}
|
|
@@ -240,8 +235,5 @@ class InteractionsRegistry {
|
|
|
240
235
|
}
|
|
241
236
|
return stages;
|
|
242
237
|
}
|
|
243
|
-
playClickSound() {
|
|
244
|
-
this.audioPlayer.play();
|
|
245
|
-
}
|
|
246
238
|
}
|
|
247
239
|
exports.InteractionsRegistry = InteractionsRegistry;
|
|
@@ -4,7 +4,7 @@ exports.RichTextConverter = exports.FontStyles = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const color_1 = require("@cntrl-site/color");
|
|
6
6
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
7
|
-
const LinkWrapper_1 = require("../../components/LinkWrapper");
|
|
7
|
+
const LinkWrapper_1 = require("../../components/items/LinkWrapper");
|
|
8
8
|
const getFontFamilyValue_1 = require("../getFontFamilyValue");
|
|
9
9
|
exports.FontStyles = {
|
|
10
10
|
'normal': {},
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCompoundTransform = exports.getCompoundLeft = exports.getCompoundTop = exports.getCompoundWidth = exports.getCompoundHeight = void 0;
|
|
4
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
+
const positionMatrix = {
|
|
6
|
+
[sdk_1.AreaAnchor.TopLeft]: [0, 0],
|
|
7
|
+
[sdk_1.AreaAnchor.TopCenter]: [0, 0.5],
|
|
8
|
+
[sdk_1.AreaAnchor.TopRight]: [0, 1],
|
|
9
|
+
[sdk_1.AreaAnchor.MiddleLeft]: [0.5, 0],
|
|
10
|
+
[sdk_1.AreaAnchor.MiddleCenter]: [0.5, 0.5],
|
|
11
|
+
[sdk_1.AreaAnchor.MiddleRight]: [0.5, 1],
|
|
12
|
+
[sdk_1.AreaAnchor.BottomLeft]: [1, 0],
|
|
13
|
+
[sdk_1.AreaAnchor.BottomCenter]: [1, 0.5],
|
|
14
|
+
[sdk_1.AreaAnchor.BottomRight]: [1, 1]
|
|
15
|
+
};
|
|
16
|
+
function getCompoundHeight(compoundSettings, height) {
|
|
17
|
+
if (!height || !compoundSettings)
|
|
18
|
+
return;
|
|
19
|
+
if (compoundSettings.heightMode === 'relative') {
|
|
20
|
+
return `${height * 100}%`;
|
|
21
|
+
}
|
|
22
|
+
return `${height * 100}vw`;
|
|
23
|
+
}
|
|
24
|
+
exports.getCompoundHeight = getCompoundHeight;
|
|
25
|
+
function getCompoundWidth(compoundSettings, width, isRichText, exemplary) {
|
|
26
|
+
if (!width || !compoundSettings)
|
|
27
|
+
return;
|
|
28
|
+
if (compoundSettings.widthMode === 'relative') {
|
|
29
|
+
return `${width * 100}%`;
|
|
30
|
+
}
|
|
31
|
+
return isRichText && exemplary ? `${width * exemplary}px` : `${width * 100}vw`;
|
|
32
|
+
}
|
|
33
|
+
exports.getCompoundWidth = getCompoundWidth;
|
|
34
|
+
function getCompoundTop(compoundSettings, top) {
|
|
35
|
+
if (!top || !compoundSettings)
|
|
36
|
+
return;
|
|
37
|
+
if (compoundSettings.heightMode === 'relative') {
|
|
38
|
+
return `${top * 100}%`;
|
|
39
|
+
}
|
|
40
|
+
const [ky] = positionMatrix[compoundSettings.positionAnchor];
|
|
41
|
+
return `calc(${ky * 100}% + ${top * 100}vw)`;
|
|
42
|
+
}
|
|
43
|
+
exports.getCompoundTop = getCompoundTop;
|
|
44
|
+
function getCompoundLeft(compoundSettings, left) {
|
|
45
|
+
if (!left || !compoundSettings)
|
|
46
|
+
return;
|
|
47
|
+
if (compoundSettings.widthMode === 'relative') {
|
|
48
|
+
return `${left * 100}%`;
|
|
49
|
+
}
|
|
50
|
+
const [_, kx] = positionMatrix[compoundSettings.positionAnchor];
|
|
51
|
+
return `calc(${kx * 100}% + ${left * 100}vw)`;
|
|
52
|
+
}
|
|
53
|
+
exports.getCompoundLeft = getCompoundLeft;
|
|
54
|
+
function getCompoundTransform(compoundSettings) {
|
|
55
|
+
if (!compoundSettings)
|
|
56
|
+
return 'unset';
|
|
57
|
+
const areaAnchor = compoundSettings.positionAnchor;
|
|
58
|
+
const [ky, kx] = positionMatrix[areaAnchor];
|
|
59
|
+
return `translate(${kx * (-100)}%, ${ky * (-100)}%)`;
|
|
60
|
+
}
|
|
61
|
+
exports.getCompoundTransform = getCompoundTransform;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -23,11 +23,9 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cntrl-site/color": "^1.0.0",
|
|
25
25
|
"@cntrl-site/effects": "^1.2.0",
|
|
26
|
-
"@cntrl-site/sdk": "^1.
|
|
27
|
-
"@types/howler": "^2.2.12",
|
|
26
|
+
"@cntrl-site/sdk": "^1.14.0",
|
|
28
27
|
"@types/vimeo__player": "^2.18.0",
|
|
29
28
|
"@vimeo/player": "^2.20.1",
|
|
30
|
-
"howler": "^2.2.4",
|
|
31
29
|
"html-react-parser": "^3.0.1",
|
|
32
30
|
"resize-observer-polyfill": "^1.5.1",
|
|
33
31
|
"styled-jsx": "^5.0.2"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FC, useEffect, useId, useRef, useState } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
3
|
import { Article as TArticle } from '@cntrl-site/sdk';
|
|
4
|
-
import { Section } from './Section';
|
|
5
|
-
import { Item } from './Item';
|
|
4
|
+
import { Section } from './Section/Section';
|
|
5
|
+
import { Item } from './items/Item';
|
|
6
6
|
import { useArticleRectObserver } from '../utils/ArticleRectManager/useArticleRectObserver';
|
|
7
7
|
import { ArticleRectContext } from '../provider/ArticleRectContext';
|
|
8
8
|
import { ArticleWrapper } from './ArticleWrapper';
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
SectionHeight,
|
|
8
8
|
SectionHeightMode
|
|
9
9
|
} from '@cntrl-site/sdk';
|
|
10
|
-
import { useCntrlContext } from '
|
|
11
|
-
import { useSectionRegistry } from '
|
|
10
|
+
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
11
|
+
import { useSectionRegistry } from '../../utils/ArticleRectManager/useSectionRegistry';
|
|
12
12
|
import { CntrlColor } from '@cntrl-site/color';
|
|
13
13
|
|
|
14
14
|
type SectionChild = ReactElement<any, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { CntrlColor } from '@cntrl-site/color';
|
|
3
|
-
import { useLayoutContext } from '
|
|
3
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
type LayoutIdentifier = string;
|
|
6
6
|
const DEFAULT_COLOR = 'rgba(0, 0, 0, 0)';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getLayoutStyles, CodeEmbedItem as TCodeEmbedItem, AreaAnchor } from '@cntrl-site/sdk';
|
|
2
2
|
import { FC, useEffect, useId, useState } from 'react';
|
|
3
|
-
import { useCntrlContext } from '
|
|
3
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
4
4
|
import { ItemProps } from '../Item';
|
|
5
5
|
import JSXStyle from 'styled-jsx/style';
|
|
6
|
-
import { useRegisterResize } from "
|
|
6
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
7
7
|
import { useItemAngle } from '../useItemAngle';
|
|
8
8
|
import { LinkWrapper } from '../LinkWrapper';
|
|
9
9
|
import { useCodeEmbedItem } from './useCodeEmbedItem';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CodeEmbedItem, AreaAnchor, KeyframeType } from '@cntrl-site/sdk';
|
|
2
|
-
import { useLayoutContext } from '
|
|
3
|
-
import { useKeyframeValue } from '
|
|
2
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
3
|
+
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
4
4
|
|
|
5
5
|
export const useCodeEmbedItem = (item: CodeEmbedItem, sectionId: string) => {
|
|
6
6
|
const layoutId = useLayoutContext();
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
FC,
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useRef,
|
|
7
|
+
useState
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
11
|
+
import { useExemplary } from '../../../common/useExemplary';
|
|
12
|
+
import { useItemScale } from '../useItemScale';
|
|
13
|
+
import { useItemInteractionCtrl } from '../../../interactions/useItemInteractionCtrl';
|
|
14
|
+
import { useItemPosition } from '../useItemPosition';
|
|
15
|
+
import { useItemDimensions } from '../useItemDimensions';
|
|
16
|
+
import { ArticleItemType, getLayoutStyles, ItemAny, AreaAnchor } from '@cntrl-site/sdk';
|
|
17
|
+
import JSXStyle from 'styled-jsx/style';
|
|
18
|
+
import { ScaleAnchorMap } from '../../../utils/ScaleAnchorMap';
|
|
19
|
+
import { isItemType } from '../../../utils/isItemType';
|
|
20
|
+
import { RichTextWrapper } from '../RichTextWrapper';
|
|
21
|
+
import { itemsMap } from '../itemsMap';
|
|
22
|
+
import {
|
|
23
|
+
getCompoundHeight,
|
|
24
|
+
getCompoundLeft,
|
|
25
|
+
getCompoundTop, getCompoundTransform,
|
|
26
|
+
getCompoundWidth
|
|
27
|
+
} from '../../../utils/getCompoundBondaryStyles';
|
|
28
|
+
|
|
29
|
+
interface ChildItemProps {
|
|
30
|
+
item: ItemAny;
|
|
31
|
+
sectionId: string;
|
|
32
|
+
isParentVisible?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const noop = () => null;
|
|
36
|
+
|
|
37
|
+
export const CompoundChild: FC<ChildItemProps> = ({ item, sectionId, isParentVisible = true }) => {
|
|
38
|
+
const id = useId();
|
|
39
|
+
const { layouts } = useCntrlContext();
|
|
40
|
+
const layout = useLayoutContext();
|
|
41
|
+
const exemplary = useExemplary();
|
|
42
|
+
const [allowPointerEvents, setAllowPointerEvents] = useState<boolean>(isParentVisible);
|
|
43
|
+
const itemScale = useItemScale(item, sectionId);
|
|
44
|
+
const interactionCtrl = useItemInteractionCtrl(item.id);
|
|
45
|
+
const wrapperStateProps = interactionCtrl?.getState(['top', 'left']);
|
|
46
|
+
const innerStateProps = interactionCtrl?.getState(['width', 'height', 'scale']);
|
|
47
|
+
const position = useItemPosition(item, sectionId, {
|
|
48
|
+
top: wrapperStateProps?.styles?.top as number,
|
|
49
|
+
left: wrapperStateProps?.styles?.left as number,
|
|
50
|
+
});
|
|
51
|
+
const compoundSettings = layout && item.compoundSettings ? item.compoundSettings[layout] : undefined;
|
|
52
|
+
const dimensions = useItemDimensions(item, sectionId);
|
|
53
|
+
const isInitialRef = useRef(true);
|
|
54
|
+
const sizing = layout && isItemType(item, ArticleItemType.RichText)
|
|
55
|
+
? item.layoutParams[layout].sizing
|
|
56
|
+
: undefined;
|
|
57
|
+
const sizingAxis = parseSizing(sizing);
|
|
58
|
+
const ItemComponent = itemsMap[item.type] || noop;
|
|
59
|
+
const handleVisibilityChange = useCallback((isVisible: boolean) => {
|
|
60
|
+
if (!isParentVisible) return;
|
|
61
|
+
setAllowPointerEvents(isVisible);
|
|
62
|
+
}, [isParentVisible]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
isInitialRef.current = false;
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
const transformOrigin = compoundSettings ? ScaleAnchorMap[compoundSettings.positionAnchor] : 'top left';
|
|
69
|
+
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
70
|
+
const width = (innerStateProps?.styles?.width ?? dimensions?.width) as number | undefined;
|
|
71
|
+
const height = (innerStateProps?.styles?.height ?? dimensions?.height) as number | undefined;
|
|
72
|
+
const scale = innerStateProps?.styles?.scale ?? itemScale;
|
|
73
|
+
const hasClickTriggers = interactionCtrl?.getHasTrigger(item.id, 'click') ?? false;
|
|
74
|
+
if (!item.compoundSettings) return null;
|
|
75
|
+
const layoutValues: Record<string, any>[] = [item.area, item.hidden, item.compoundSettings];
|
|
76
|
+
if (item.layoutParams) {
|
|
77
|
+
layoutValues.push(item.layoutParams);
|
|
78
|
+
}
|
|
79
|
+
return (
|
|
80
|
+
<div
|
|
81
|
+
className={`item-${item.id}`}
|
|
82
|
+
onTransitionEnd={(e) => {
|
|
83
|
+
e.stopPropagation();
|
|
84
|
+
interactionCtrl?.handleTransitionEnd?.(e.propertyName);
|
|
85
|
+
}}
|
|
86
|
+
style={{
|
|
87
|
+
...(position && compoundSettings ? { top: getCompoundTop(compoundSettings, position.top) } : {}),
|
|
88
|
+
...(position && compoundSettings ? { left: getCompoundLeft(compoundSettings, position.left) } : {}),
|
|
89
|
+
...(width && compoundSettings
|
|
90
|
+
? { width: `${sizingAxis.x === 'manual'
|
|
91
|
+
? getCompoundWidth(compoundSettings, width, isRichText, exemplary)
|
|
92
|
+
: 'max-content'}` }
|
|
93
|
+
: {}),
|
|
94
|
+
...(height && compoundSettings
|
|
95
|
+
? { height: `${sizingAxis.y === 'manual'
|
|
96
|
+
? getCompoundHeight(compoundSettings, height)
|
|
97
|
+
: 'unset'}` }
|
|
98
|
+
: {}),
|
|
99
|
+
...(scale && compoundSettings ? { transform: `scale(${scale}) ${getCompoundTransform(compoundSettings)}` } : {}),
|
|
100
|
+
transition: innerStateProps?.transition ?? 'none',
|
|
101
|
+
cursor: hasClickTriggers ? 'pointer' : 'unset',
|
|
102
|
+
pointerEvents: allowPointerEvents ? 'auto' : 'none'
|
|
103
|
+
}}
|
|
104
|
+
onClick={() => {
|
|
105
|
+
interactionCtrl?.sendTrigger('click');
|
|
106
|
+
}}
|
|
107
|
+
onMouseEnter={() => {
|
|
108
|
+
interactionCtrl?.sendTrigger('hover-in');
|
|
109
|
+
}}
|
|
110
|
+
onMouseLeave={() => {
|
|
111
|
+
interactionCtrl?.sendTrigger('hover-out');
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
<RichTextWrapper isRichText={isRichText} transformOrigin={transformOrigin}>
|
|
115
|
+
<ItemComponent
|
|
116
|
+
item={item}
|
|
117
|
+
sectionId={sectionId}
|
|
118
|
+
interactionCtrl={interactionCtrl}
|
|
119
|
+
onVisibilityChange={handleVisibilityChange}
|
|
120
|
+
/>
|
|
121
|
+
</RichTextWrapper>
|
|
122
|
+
<JSXStyle id={id}>{`
|
|
123
|
+
${getLayoutStyles(layouts, layoutValues, ([area, hidden, compoundSettings, layoutParams]) => {
|
|
124
|
+
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
125
|
+
const scaleAnchor = area.scaleAnchor as AreaAnchor;
|
|
126
|
+
return (`
|
|
127
|
+
.item-${item.id} {
|
|
128
|
+
position: absolute;
|
|
129
|
+
top: ${getCompoundTop(compoundSettings, area.top)};
|
|
130
|
+
left: ${getCompoundLeft(compoundSettings, area.left)};
|
|
131
|
+
transition: opacity 0.2s linear 0.1s;
|
|
132
|
+
display: ${hidden ? 'none' : 'block'};
|
|
133
|
+
width: ${sizingAxis.x === 'manual'
|
|
134
|
+
? `${getCompoundWidth(compoundSettings, area.width, isRichText)}`
|
|
135
|
+
: 'max-content'};
|
|
136
|
+
height: ${sizingAxis.y === 'manual' ? `${getCompoundHeight(compoundSettings, area.height)}` : 'unset'};
|
|
137
|
+
transform-origin: ${ScaleAnchorMap[scaleAnchor]};
|
|
138
|
+
transform: scale(${area.scale}) ${getCompoundTransform(compoundSettings)};
|
|
139
|
+
z-index: ${area.zIndex};
|
|
140
|
+
}
|
|
141
|
+
`);
|
|
142
|
+
})}
|
|
143
|
+
`}</JSXStyle>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
function parseSizing(sizing: string = 'manual'): Axis {
|
|
150
|
+
const axisSizing = sizing.split(' ');
|
|
151
|
+
return {
|
|
152
|
+
y: axisSizing[0],
|
|
153
|
+
x: axisSizing[1] ? axisSizing[1] : axisSizing[0]
|
|
154
|
+
} as Axis;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface Axis {
|
|
158
|
+
x: 'manual' | 'auto';
|
|
159
|
+
y: 'manual' | 'auto';
|
|
160
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { FC, useEffect, useId, useState } from 'react';
|
|
2
|
+
import { useItemAngle } from '../useItemAngle';
|
|
3
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
4
|
+
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
5
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
6
|
+
import { LinkWrapper } from '../LinkWrapper';
|
|
7
|
+
import { ItemProps } from '../Item';
|
|
8
|
+
import JSXStyle from 'styled-jsx/style';
|
|
9
|
+
import { getLayoutStyles } from '@cntrl-site/sdk';
|
|
10
|
+
import { CompoundItem as TCompoundItem } from '@cntrl-site/sdk';
|
|
11
|
+
import { CompoundChild } from './CompoundChild';
|
|
12
|
+
import { useCompoundItem } from './useCompoundItem';
|
|
13
|
+
|
|
14
|
+
export const CompoundItem: FC<ItemProps<TCompoundItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
15
|
+
const id = useId();
|
|
16
|
+
const { items } = item;
|
|
17
|
+
const itemAngle = useItemAngle(item, sectionId);
|
|
18
|
+
const { layouts } = useCntrlContext();
|
|
19
|
+
const { opacity: itemOpacity } = useCompoundItem(item, sectionId);
|
|
20
|
+
const layoutValues: Record<string, any>[] = [item.area, item.layoutParams];
|
|
21
|
+
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
22
|
+
useRegisterResize(ref, onResize);
|
|
23
|
+
const stateParams = interactionCtrl?.getState(['opacity', 'angle']);
|
|
24
|
+
const angle = getStyleFromItemStateAndParams(stateParams?.styles?.angle, itemAngle);
|
|
25
|
+
const opacity = getStyleFromItemStateAndParams(stateParams?.styles?.opacity, itemOpacity);
|
|
26
|
+
const isInteractive = opacity !== 0 && opacity !== undefined;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
onVisibilityChange?.(isInteractive);
|
|
29
|
+
}, [isInteractive, onVisibilityChange]);
|
|
30
|
+
return (
|
|
31
|
+
<LinkWrapper url={item.link?.url} target={item.link?.target}>
|
|
32
|
+
<>
|
|
33
|
+
<div
|
|
34
|
+
className={`compound-${item.id}`}
|
|
35
|
+
ref={setRef}
|
|
36
|
+
style={{
|
|
37
|
+
...(opacity !== undefined ? { opacity } : {}),
|
|
38
|
+
...(angle !== undefined ? { transform: `rotate(${angle}deg)` } : {}),
|
|
39
|
+
transition: stateParams?.transition ?? 'none'
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
{items && items.map(item => (
|
|
43
|
+
<CompoundChild
|
|
44
|
+
item={item}
|
|
45
|
+
key={item.id}
|
|
46
|
+
sectionId={sectionId}
|
|
47
|
+
isParentVisible={isInteractive}
|
|
48
|
+
/>
|
|
49
|
+
))}
|
|
50
|
+
</div>
|
|
51
|
+
<JSXStyle id={id}>{`
|
|
52
|
+
.compound-${item.id} {
|
|
53
|
+
position: absolute;
|
|
54
|
+
width: 100%;
|
|
55
|
+
height: 100%;
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
}
|
|
58
|
+
${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
59
|
+
return (`
|
|
60
|
+
.compound-${item.id} {
|
|
61
|
+
opacity: ${layoutParams.opacity};
|
|
62
|
+
transform: rotate(${area.angle}deg);
|
|
63
|
+
}
|
|
64
|
+
`);
|
|
65
|
+
})}
|
|
66
|
+
`}</JSXStyle>
|
|
67
|
+
</>
|
|
68
|
+
</LinkWrapper>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CompoundItem, KeyframeType } from '@cntrl-site/sdk';
|
|
2
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
3
|
+
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
4
|
+
|
|
5
|
+
export function useCompoundItem(item: CompoundItem, sectionId: string) {
|
|
6
|
+
const layoutId = useLayoutContext();
|
|
7
|
+
const opacity = useKeyframeValue(
|
|
8
|
+
item,
|
|
9
|
+
KeyframeType.Opacity,
|
|
10
|
+
(item, layoutId) => {
|
|
11
|
+
if (!layoutId) return;
|
|
12
|
+
const layoutParams = item.layoutParams[layoutId];
|
|
13
|
+
return 'opacity' in layoutParams ? layoutParams.opacity : 1;
|
|
14
|
+
},
|
|
15
|
+
(animator, scroll, value) => value !== undefined ? animator.getOpacity({ opacity: value }, scroll).opacity : undefined,
|
|
16
|
+
sectionId,
|
|
17
|
+
[layoutId]
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return { opacity };
|
|
21
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getLayoutStyles, CustomItem as TCustomItem } from '@cntrl-site/sdk';
|
|
2
2
|
import { FC, useState } from 'react';
|
|
3
|
-
import { useCntrlContext } from '
|
|
3
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
4
4
|
import { ItemProps } from '../Item';
|
|
5
5
|
import JSXStyle from 'styled-jsx/style';
|
|
6
|
-
import { useRegisterResize } from '
|
|
6
|
+
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
7
7
|
import { useItemAngle } from '../useItemAngle';
|
|
8
8
|
|
|
9
9
|
export const CustomItem: FC<ItemProps<TCustomItem>> = ({ item, onResize, sectionId, interactionCtrl }) => {
|