@cntrl-site/sdk-nextjs 1.0.20 → 1.1.1
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/jest.config.js +2 -2
- package/lib/components/Article.js +9 -8
- package/lib/components/Item.js +39 -21
- package/lib/components/items/CodeEmbedItem.js +15 -12
- package/lib/components/items/CustomItem.js +7 -9
- package/lib/components/items/GroupItem.js +15 -12
- package/lib/components/items/ImageItem.js +28 -21
- package/lib/components/items/RectangleItem.js +28 -15
- package/lib/components/items/RichTextItem.js +33 -12
- package/lib/components/items/VideoItem.js +26 -19
- package/lib/components/items/VimeoEmbed.js +22 -20
- package/lib/components/items/YoutubeEmbed.js +20 -18
- package/lib/components/useItemPosition.js +10 -5
- package/lib/interactions/CSSPropertyNameMap.js +38 -0
- package/lib/interactions/InteractionsRegistry.js +220 -0
- package/lib/interactions/ItemInteractionCtrl.js +61 -0
- package/lib/interactions/getTransition.js +21 -0
- package/lib/interactions/types.js +2 -0
- package/lib/interactions/useItemInteractionCtrl.js +17 -0
- package/lib/provider/InteractionsContext.js +23 -0
- package/lib/utils/getStyleFromItemStateAndParams.js +9 -0
- package/package.json +7 -4
- package/src/components/Article.tsx +30 -27
- package/src/components/ArticleWrapper.tsx +1 -2
- package/src/components/Item.tsx +75 -29
- package/src/components/items/CodeEmbedItem.tsx +15 -11
- package/src/components/items/CustomItem.tsx +9 -11
- package/src/components/items/GroupItem.tsx +17 -13
- package/src/components/items/ImageItem.tsx +35 -20
- package/src/components/items/RectangleItem.tsx +35 -14
- package/src/components/items/RichTextItem.tsx +41 -14
- package/src/components/items/VideoItem.tsx +34 -20
- package/src/components/items/VimeoEmbed.tsx +27 -19
- package/src/components/items/YoutubeEmbed.tsx +20 -18
- package/src/components/useItemPosition.ts +12 -5
- package/src/interactions/CSSPropertyNameMap.ts +38 -0
- package/src/interactions/InteractionsRegistry.ts +244 -0
- package/src/interactions/ItemInteractionCtrl.ts +62 -0
- package/src/interactions/getTransition.ts +27 -0
- package/src/interactions/types.ts +32 -0
- package/src/interactions/useItemInteractionCtrl.ts +18 -0
- package/src/provider/InteractionsContext.old.tsx +65 -0
- package/src/provider/InteractionsContext.test.tsx +97 -0
- package/src/provider/InteractionsContext.tsx +28 -0
- package/src/utils/getStyleFromItemStateAndParams.ts +8 -0
- package/lib/utils/HoverStyles/HoverStyles.js +0 -77
- package/src/utils/HoverStyles/HoverStyles.ts +0 -85
|
@@ -13,26 +13,41 @@ const LinkWrapper_1 = require("../LinkWrapper");
|
|
|
13
13
|
const useFileItem_1 = require("./useFileItem");
|
|
14
14
|
const useItemAngle_1 = require("../useItemAngle");
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
17
16
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
18
17
|
const useLayoutContext_1 = require("../useLayoutContext");
|
|
19
18
|
const ScrollPlaybackVideo_1 = require("../ScrollPlaybackVideo");
|
|
20
|
-
const
|
|
21
|
-
|
|
19
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
20
|
+
const VideoItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
22
22
|
const id = (0, react_1.useId)();
|
|
23
23
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
24
|
-
const { radius, strokeWidth, strokeColor, opacity, blur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
25
|
-
const
|
|
26
|
-
const borderColor = (0, react_1.useMemo)(() => strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined, [strokeColor]);
|
|
24
|
+
const { radius: itemRadius, strokeWidth: itemStrokeWidth, strokeColor: itemStrokeColor, opacity: itemOpacity, blur: itemBlur } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
27
26
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
28
27
|
const videoRef = (0, react_1.useRef)(null);
|
|
29
28
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
30
29
|
const scrollPlayback = layoutId ? item.layoutParams[layoutId].scrollPlayback : null;
|
|
31
|
-
const layoutValues = [item.area, item.layoutParams
|
|
30
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
32
31
|
const hasScrollPlayback = scrollPlayback !== null;
|
|
32
|
+
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'opacity', 'blur']);
|
|
33
|
+
const videoStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['strokeWidth', 'radius', 'strokeColor']);
|
|
34
|
+
const borderColor = (0, react_1.useMemo)(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
const strokeColor = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = videoStateParams === null || videoStateParams === void 0 ? void 0 : videoStateParams.styles) === null || _a === void 0 ? void 0 : _a.color, itemStrokeColor);
|
|
37
|
+
return strokeColor ? color_1.CntrlColor.parse(strokeColor) : undefined;
|
|
38
|
+
}, [(_a = videoStateParams === null || videoStateParams === void 0 ? void 0 : videoStateParams.styles) === null || _a === void 0 ? void 0 : _a.color, itemStrokeColor]);
|
|
39
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _b === void 0 ? void 0 : _b.angle, itemAngle);
|
|
40
|
+
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
|
|
41
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _d === void 0 ? void 0 : _d.blur, itemBlur);
|
|
42
|
+
const strokeWidth = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_e = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _e === void 0 ? void 0 : _e.strokeWidth, itemStrokeWidth);
|
|
43
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_f = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _f === void 0 ? void 0 : _f.radius, itemRadius);
|
|
33
44
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
34
|
-
const inlineStyles = Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (borderColor ? { borderColor: `${borderColor.toCss()}` } : {}));
|
|
35
|
-
|
|
45
|
+
const inlineStyles = Object.assign(Object.assign(Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), (strokeWidth !== undefined ? { borderWidth: `${strokeWidth * 100}vw` } : {})), (borderColor ? { borderColor: `${borderColor.toCss()}` } : {})), { transition: (_g = videoStateParams === null || videoStateParams === void 0 ? void 0 : videoStateParams.transition) !== null && _g !== void 0 ? _g : 'none' });
|
|
46
|
+
const isInteractive = opacity !== 0;
|
|
47
|
+
(0, react_1.useEffect)(() => {
|
|
48
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
49
|
+
}, [isInteractive, onVisibilityChange]);
|
|
50
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_h = item.link) === null || _h === void 0 ? void 0 : _h.url, target: (_j = item.link) === null || _j === void 0 ? void 0 : _j.target, children: [(0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_k = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _k !== void 0 ? _k : 'none' }), children: hasScrollPlayback ? ((0, jsx_runtime_1.jsx)(ScrollPlaybackVideo_1.ScrollPlaybackVideo, { sectionId: sectionId, src: item.commonParams.url, playbackParams: scrollPlayback, style: inlineStyles, className: `video video-playback-wrapper video-${item.id}` })) : ((0, jsx_runtime_1.jsx)("video", { poster: (_l = item.commonParams.coverUrl) !== null && _l !== void 0 ? _l : '', ref: videoRef, autoPlay: true, muted: true, loop: true, playsInline: true, className: `video video-${item.id}`, style: inlineStyles, children: (0, jsx_runtime_1.jsx)("source", { src: item.commonParams.url }) })) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
36
51
|
.video-wrapper-${item.id} {
|
|
37
52
|
position: absolute;
|
|
38
53
|
overflow: hidden;
|
|
@@ -53,31 +68,23 @@ const VideoItem = ({ item, sectionId, onResize }) => {
|
|
|
53
68
|
pointer-events: auto;
|
|
54
69
|
}
|
|
55
70
|
.video-${item.id} {
|
|
56
|
-
border-color: ${
|
|
71
|
+
border-color: ${itemStrokeColor};
|
|
57
72
|
}
|
|
58
73
|
.video-playback-wrapper {
|
|
59
74
|
display: flex;
|
|
60
75
|
justify-content: center;
|
|
61
76
|
}
|
|
62
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
77
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
63
78
|
return (`
|
|
64
79
|
.video-wrapper-${item.id} {
|
|
65
80
|
opacity: ${layoutParams.opacity};
|
|
66
81
|
transform: rotate(${area.angle}deg);
|
|
67
82
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
68
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'opacity', 'blur'], hoverParams)};
|
|
69
|
-
}
|
|
70
|
-
.video-wrapper-${item.id}:hover {
|
|
71
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'opacity', 'blur'], hoverParams)};
|
|
72
83
|
}
|
|
73
84
|
.video-${item.id} {
|
|
74
85
|
border-color: ${color_1.CntrlColor.parse(layoutParams.strokeColor).fmt('rgba')};
|
|
75
86
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
76
87
|
border-width: ${layoutParams.strokeWidth * 100}vw;
|
|
77
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['strokeWidth', 'radius', 'strokeColor'], hoverParams)};
|
|
78
|
-
}
|
|
79
|
-
.video-wrapper-${item.id}:hover .video {
|
|
80
|
-
${(0, HoverStyles_1.getHoverStyles)(['strokeWidth', 'radius', 'strokeColor'], hoverParams)};
|
|
81
88
|
}
|
|
82
89
|
`);
|
|
83
90
|
})}
|
|
@@ -13,21 +13,27 @@ const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
14
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
16
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
17
16
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
18
|
-
const
|
|
19
|
-
|
|
17
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
18
|
+
const VimeoEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
20
20
|
const id = (0, react_1.useId)();
|
|
21
21
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
22
|
-
const { radius, blur, opacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
22
|
+
const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
23
23
|
const [iframeRef, setIframeRef] = (0, react_1.useState)(null);
|
|
24
24
|
const vimeoPlayer = (0, react_1.useMemo)(() => iframeRef ? new player_1.default(iframeRef) : undefined, [iframeRef]);
|
|
25
|
-
const
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
26
26
|
const { play, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
27
27
|
const [ref, setRef] = (0, react_1.useState)(null);
|
|
28
28
|
const [imgRef, setImgRef] = (0, react_1.useState)(null);
|
|
29
29
|
const [isCoverVisible, setIsCoverVisible] = (0, react_1.useState)(false);
|
|
30
|
-
const layoutValues = [item.area, item.layoutParams
|
|
30
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
31
|
+
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'opacity']);
|
|
32
|
+
const frameStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['radius']);
|
|
33
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
|
|
34
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _b === void 0 ? void 0 : _b.blur, itemBlur);
|
|
35
|
+
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
|
|
36
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.styles) === null || _d === void 0 ? void 0 : _d.radius, itemRadius);
|
|
31
37
|
(0, useRegisterResize_1.useRegisterResize)(ref, onResize);
|
|
32
38
|
const getValidVimeoUrl = (url) => {
|
|
33
39
|
const validURL = new URL(url);
|
|
@@ -61,7 +67,11 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
61
67
|
vimeoPlayer.play();
|
|
62
68
|
setIsCoverVisible(false);
|
|
63
69
|
};
|
|
64
|
-
|
|
70
|
+
const isInteractive = opacity !== 0;
|
|
71
|
+
(0, react_1.useEffect)(() => {
|
|
72
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
73
|
+
}, [isInteractive, onVisibilityChange]);
|
|
74
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_e = item.link) === null || _e === void 0 ? void 0 : _e.url, target: (_f = item.link) === null || _f === void 0 ? void 0 : _f.target, children: [(0, jsx_runtime_1.jsxs)("div", { className: `embed-video-wrapper-${item.id}`, ref: setRef, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_g = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _g !== void 0 ? _g : 'none' }), onMouseEnter: () => {
|
|
65
75
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
66
76
|
return;
|
|
67
77
|
vimeoPlayer.play();
|
|
@@ -69,7 +79,7 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
69
79
|
if (!vimeoPlayer || play !== 'on-hover')
|
|
70
80
|
return;
|
|
71
81
|
vimeoPlayer.pause();
|
|
72
|
-
}, children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (
|
|
82
|
+
}, children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (_h = item.commonParams.coverUrl) !== null && _h !== void 0 ? _h : '', style: {
|
|
73
83
|
display: isCoverVisible ? 'block' : 'none',
|
|
74
84
|
cursor: 'pointer',
|
|
75
85
|
position: 'absolute',
|
|
@@ -78,36 +88,28 @@ const VimeoEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
78
88
|
width: '100%',
|
|
79
89
|
top: '0',
|
|
80
90
|
left: '0'
|
|
81
|
-
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className:
|
|
91
|
+
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("iframe", { ref: setIframeRef, className: `embed-video`, src: validUrl || '', allow: "autoplay; fullscreen; picture-in-picture;", allowFullScreen: true, style: Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), { transition: (_j = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.transition) !== null && _j !== void 0 ? _j : 'none' }) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
82
92
|
.embed-video-wrapper-${item.id} {
|
|
83
93
|
position: absolute;
|
|
84
94
|
width: 100%;
|
|
85
95
|
height: 100%;
|
|
86
96
|
}
|
|
87
|
-
.
|
|
97
|
+
.embed-video {
|
|
88
98
|
width: 100%;
|
|
89
99
|
height: 100%;
|
|
90
100
|
z-index: 1;
|
|
91
101
|
border: none;
|
|
92
102
|
overflow: hidden;
|
|
93
103
|
}
|
|
94
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
104
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
95
105
|
return (`
|
|
96
106
|
.embed-video-wrapper-${item.id} {
|
|
97
107
|
opacity: ${layoutParams.opacity};
|
|
98
108
|
transform: rotate(${area.angle}deg);
|
|
99
109
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
100
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'opacity'], hoverParams)};
|
|
101
|
-
}
|
|
102
|
-
.embed-video-wrapper-${item.id}:hover {
|
|
103
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'opacity'], hoverParams)}
|
|
104
110
|
}
|
|
105
|
-
.embed-video-wrapper-${item.id} .
|
|
111
|
+
.embed-video-wrapper-${item.id} .embed-video {
|
|
106
112
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
107
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['radius'], hoverParams)};
|
|
108
|
-
}
|
|
109
|
-
.embed-video-wrapper-${item.id}:hover .embedVideo {
|
|
110
|
-
${(0, HoverStyles_1.getHoverStyles)(['radius'], hoverParams)};
|
|
111
113
|
}
|
|
112
114
|
`);
|
|
113
115
|
})}
|
|
@@ -12,23 +12,33 @@ const getValidYoutubeUrl_1 = require("../../utils/getValidYoutubeUrl");
|
|
|
12
12
|
const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
14
|
const sdk_1 = require("@cntrl-site/sdk");
|
|
15
|
-
const HoverStyles_1 = require("../../utils/HoverStyles/HoverStyles");
|
|
16
15
|
const useCntrlContext_1 = require("../../provider/useCntrlContext");
|
|
17
16
|
const useYouTubeIframeApi_1 = require("../../utils/Youtube/useYouTubeIframeApi");
|
|
18
17
|
const useRegisterResize_1 = require("../../common/useRegisterResize");
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
const getStyleFromItemStateAndParams_1 = require("../../utils/getStyleFromItemStateAndParams");
|
|
19
|
+
const YoutubeEmbedItem = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
21
|
const id = (0, react_1.useId)();
|
|
22
22
|
const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
|
|
23
23
|
const { play, controls, url } = item.commonParams;
|
|
24
|
-
const { radius, blur, opacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
25
|
-
const
|
|
24
|
+
const { radius: itemRadius, blur: itemBlur, opacity: itemOpacity } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
25
|
+
const itemAngle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
26
26
|
const YT = (0, useYouTubeIframeApi_1.useYouTubeIframeApi)();
|
|
27
27
|
const [div, setDiv] = (0, react_1.useState)(null);
|
|
28
28
|
const [player, setPlayer] = (0, react_1.useState)(undefined);
|
|
29
29
|
const [isCoverVisible, setIsCoverVisible] = (0, react_1.useState)(false);
|
|
30
30
|
const [imgRef, setImgRef] = (0, react_1.useState)(null);
|
|
31
|
-
const layoutValues = [item.area, item.layoutParams
|
|
31
|
+
const layoutValues = [item.area, item.layoutParams];
|
|
32
|
+
const wrapperStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['angle', 'blur', 'opacity']);
|
|
33
|
+
const frameStateParams = interactionCtrl === null || interactionCtrl === void 0 ? void 0 : interactionCtrl.getState(['radius']);
|
|
34
|
+
const angle = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_a = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _a === void 0 ? void 0 : _a.angle, itemAngle);
|
|
35
|
+
const blur = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_b = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _b === void 0 ? void 0 : _b.blur, itemBlur);
|
|
36
|
+
const opacity = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_c = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.styles) === null || _c === void 0 ? void 0 : _c.opacity, itemOpacity);
|
|
37
|
+
const radius = (0, getStyleFromItemStateAndParams_1.getStyleFromItemStateAndParams)((_d = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.styles) === null || _d === void 0 ? void 0 : _d.radius, itemRadius);
|
|
38
|
+
const isInteractive = opacity !== 0;
|
|
39
|
+
(0, react_1.useEffect)(() => {
|
|
40
|
+
onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(isInteractive);
|
|
41
|
+
}, [isInteractive, onVisibilityChange]);
|
|
32
42
|
(0, useRegisterResize_1.useRegisterResize)(div, onResize);
|
|
33
43
|
(0, react_1.useEffect)(() => {
|
|
34
44
|
const newUrl = new URL(url);
|
|
@@ -80,7 +90,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
80
90
|
setIsCoverVisible(true);
|
|
81
91
|
}
|
|
82
92
|
}, []);
|
|
83
|
-
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (
|
|
93
|
+
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: (_e = item.link) === null || _e === void 0 ? void 0 : _e.url, target: (_f = item.link) === null || _f === void 0 ? void 0 : _f.target, children: [(0, jsx_runtime_1.jsxs)("div", { className: `embed-youtube-video-wrapper-${item.id}`, onMouseEnter: () => {
|
|
84
94
|
if (!player || play !== 'on-hover')
|
|
85
95
|
return;
|
|
86
96
|
player.playVideo();
|
|
@@ -88,7 +98,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
88
98
|
if (!player || play !== 'on-hover')
|
|
89
99
|
return;
|
|
90
100
|
player.pauseVideo();
|
|
91
|
-
}, style: Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (
|
|
101
|
+
}, style: Object.assign(Object.assign(Object.assign(Object.assign({}, (opacity !== undefined ? { opacity } : {})), (angle !== undefined ? { transform: `rotate(${angle}deg)` } : {})), (blur !== undefined ? { filter: `blur(${blur * 100}vw)` } : {})), { transition: (_g = wrapperStateParams === null || wrapperStateParams === void 0 ? void 0 : wrapperStateParams.transition) !== null && _g !== void 0 ? _g : 'none' }), children: [item.commonParams.coverUrl && ((0, jsx_runtime_1.jsx)("img", { ref: setImgRef, onClick: () => onCoverClick(), src: (_h = item.commonParams.coverUrl) !== null && _h !== void 0 ? _h : '', style: {
|
|
92
102
|
display: isCoverVisible ? 'block' : 'none',
|
|
93
103
|
cursor: 'pointer',
|
|
94
104
|
position: 'absolute',
|
|
@@ -98,7 +108,7 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
98
108
|
top: '0',
|
|
99
109
|
left: '0',
|
|
100
110
|
zIndex: 1
|
|
101
|
-
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, ref: setDiv, style: Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
111
|
+
}, alt: "Cover img" })), (0, jsx_runtime_1.jsx)("div", { className: `embed-${item.id}`, ref: setDiv, style: Object.assign(Object.assign({}, (radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {})), { transition: (_j = frameStateParams === null || frameStateParams === void 0 ? void 0 : frameStateParams.transition) !== null && _j !== void 0 ? _j : 'none' }) })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
|
|
102
112
|
.embed-youtube-video-wrapper-${item.id},
|
|
103
113
|
.embed-${item.id} {
|
|
104
114
|
position: absolute;
|
|
@@ -114,23 +124,15 @@ const YoutubeEmbedItem = ({ item, sectionId, onResize }) => {
|
|
|
114
124
|
z-index: 1;
|
|
115
125
|
border: none;
|
|
116
126
|
}
|
|
117
|
-
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams
|
|
127
|
+
${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => {
|
|
118
128
|
return (`
|
|
119
129
|
.embed-youtube-video-wrapper-${item.id} {
|
|
120
130
|
opacity: ${layoutParams.opacity};
|
|
121
131
|
transform: rotate(${area.angle}deg);
|
|
122
132
|
filter: ${layoutParams.blur !== 0 ? `blur(${layoutParams.blur * 100}vw)` : 'unset'};
|
|
123
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['angle', 'blur', 'opacity'], hoverParams)};
|
|
124
133
|
}
|
|
125
134
|
.embed-youtube-video-wrapper-${item.id} .embed-${item.id} {
|
|
126
135
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
127
|
-
transition: ${(0, HoverStyles_1.getTransitions)(['radius'], hoverParams)};
|
|
128
|
-
}
|
|
129
|
-
.embed-youtube-video-wrapper-${item.id}:hover {
|
|
130
|
-
${(0, HoverStyles_1.getHoverStyles)(['angle', 'blur', 'opacity'], hoverParams)};
|
|
131
|
-
}
|
|
132
|
-
.embed-youtube-video-wrapper-${item.id}:hover .embed-${item.id} {
|
|
133
|
-
${(0, HoverStyles_1.getHoverStyles)(['radius'], hoverParams)};
|
|
134
136
|
}
|
|
135
137
|
`);
|
|
136
138
|
})}
|
|
@@ -5,7 +5,8 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
5
5
|
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
6
6
|
const getItemTopStyle_1 = require("../utils/getItemTopStyle");
|
|
7
7
|
const useLayoutContext_1 = require("./useLayoutContext");
|
|
8
|
-
const useItemPosition = (item, sectionId) => {
|
|
8
|
+
const useItemPosition = (item, sectionId, stateValues) => {
|
|
9
|
+
var _a, _b;
|
|
9
10
|
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
10
11
|
const position = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Position, (item, layoutId) => {
|
|
11
12
|
if (!layoutId)
|
|
@@ -14,12 +15,16 @@ const useItemPosition = (item, sectionId) => {
|
|
|
14
15
|
}, (animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined, sectionId, [layoutId]);
|
|
15
16
|
const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
|
|
16
17
|
const positionType = layoutId ? item.area[layoutId].positionType : sdk_1.PositionType.ScreenBased;
|
|
17
|
-
//
|
|
18
|
+
// to prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
|
|
18
19
|
const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
|
|
20
|
+
if (!position)
|
|
21
|
+
return undefined;
|
|
22
|
+
const top = (_a = stateValues === null || stateValues === void 0 ? void 0 : stateValues.top) !== null && _a !== void 0 ? _a : position.top;
|
|
23
|
+
const left = (_b = stateValues === null || stateValues === void 0 ? void 0 : stateValues.left) !== null && _b !== void 0 ? _b : position.left;
|
|
19
24
|
return position ? {
|
|
20
|
-
bottom: isScreenBasedBottom ? `${-
|
|
21
|
-
top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(
|
|
22
|
-
left: `${
|
|
25
|
+
bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset',
|
|
26
|
+
top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide),
|
|
27
|
+
left: `${left * 100}vw`
|
|
23
28
|
} : undefined;
|
|
24
29
|
};
|
|
25
30
|
exports.useItemPosition = useItemPosition;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStyleKeysFromCSSProperty = exports.CSSPropertyNameMap = void 0;
|
|
4
|
+
exports.CSSPropertyNameMap = {
|
|
5
|
+
'width': 'width',
|
|
6
|
+
'height': 'height',
|
|
7
|
+
'top': 'top',
|
|
8
|
+
'left': 'left',
|
|
9
|
+
'scale': 'transform',
|
|
10
|
+
'angle': 'transform',
|
|
11
|
+
'opacity': 'opacity',
|
|
12
|
+
'radius': 'border-radius',
|
|
13
|
+
'strokeWidth': 'border-width',
|
|
14
|
+
'strokeColor': 'border-color',
|
|
15
|
+
'fillColor': 'background-color',
|
|
16
|
+
'blur': 'filter',
|
|
17
|
+
'backdropBlur': 'backdrop-filter',
|
|
18
|
+
'letterSpacing': 'letter-spacing',
|
|
19
|
+
'wordSpacing': 'word-spacing',
|
|
20
|
+
'color': 'color'
|
|
21
|
+
};
|
|
22
|
+
const PropertyNameCSSMap = {
|
|
23
|
+
'transform': ['angle', 'scale'],
|
|
24
|
+
'border-radius': ['radius'],
|
|
25
|
+
'border-width': ['strokeWidth'],
|
|
26
|
+
'border-color': ['strokeColor'],
|
|
27
|
+
'background-color': ['fillColor'],
|
|
28
|
+
'filter': ['blur'],
|
|
29
|
+
'backdrop-filter': ['backdrop-blur'],
|
|
30
|
+
'letter-spacing': ['letterSpacing'],
|
|
31
|
+
'word-spacing': ['wordSpacing'],
|
|
32
|
+
};
|
|
33
|
+
function getStyleKeysFromCSSProperty(cssProp) {
|
|
34
|
+
var _a;
|
|
35
|
+
const key = (_a = PropertyNameCSSMap[cssProp]) !== null && _a !== void 0 ? _a : [cssProp];
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
exports.getStyleKeysFromCSSProperty = getStyleKeysFromCSSProperty;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.InteractionsRegistry = void 0;
|
|
15
|
+
const sdk_1 = require("@cntrl-site/sdk");
|
|
16
|
+
const Item_1 = require("../components/Item");
|
|
17
|
+
class InteractionsRegistry {
|
|
18
|
+
constructor(article, layoutId) {
|
|
19
|
+
this.layoutId = layoutId;
|
|
20
|
+
this.ctrls = new Map();
|
|
21
|
+
const { interactions } = article;
|
|
22
|
+
this.items = this.unpackItems(article);
|
|
23
|
+
const activeStatesIds = interactions.reduce((map, inter) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const activeStateId = (_a = inter.states.find((state) => state.id !== inter.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
26
|
+
map.push(activeStateId);
|
|
27
|
+
return map;
|
|
28
|
+
}, []);
|
|
29
|
+
const interactionStateMap = interactions.reduce((map, { id, startStateId }) => {
|
|
30
|
+
map[id] = startStateId;
|
|
31
|
+
return map;
|
|
32
|
+
}, {});
|
|
33
|
+
this.activeStateIdInteractionIdMap = interactions.reduce((map, interaction) => {
|
|
34
|
+
const activeState = interaction.states.find((state) => state.id !== interaction.startStateId);
|
|
35
|
+
if (activeState) {
|
|
36
|
+
map[activeState.id] = interaction.id;
|
|
37
|
+
}
|
|
38
|
+
return map;
|
|
39
|
+
}, {});
|
|
40
|
+
const itemStages = this.getDefaultItemStages();
|
|
41
|
+
const stateItemsIdsMap = activeStatesIds.reduce((map, stateId) => {
|
|
42
|
+
map[stateId] = this.items
|
|
43
|
+
.filter((item) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const layoutStates = (_a = item.state[layoutId]) !== null && _a !== void 0 ? _a : {};
|
|
46
|
+
const state = (_b = layoutStates === null || layoutStates === void 0 ? void 0 : layoutStates[stateId]) !== null && _b !== void 0 ? _b : {};
|
|
47
|
+
const hasKeys = Object.keys(state).length !== 0;
|
|
48
|
+
return hasKeys;
|
|
49
|
+
})
|
|
50
|
+
.map((item) => item.id);
|
|
51
|
+
return map;
|
|
52
|
+
}, {});
|
|
53
|
+
this.interactions = interactions;
|
|
54
|
+
this.itemsStages = itemStages;
|
|
55
|
+
this.stateItemsIdsMap = stateItemsIdsMap;
|
|
56
|
+
this.interactionStateMap = interactionStateMap;
|
|
57
|
+
}
|
|
58
|
+
register(itemId, ctrl) {
|
|
59
|
+
this.ctrls.set(itemId, ctrl);
|
|
60
|
+
}
|
|
61
|
+
getStatePropsForItem(itemId) {
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
63
|
+
const { items, layoutId } = this;
|
|
64
|
+
const item = items.find((item) => item.id === itemId);
|
|
65
|
+
const itemStages = this.itemsStages.filter((stage) => stage.itemId === itemId);
|
|
66
|
+
itemStages.sort((a, b) => a.updated - b.updated);
|
|
67
|
+
const itemStyles = {};
|
|
68
|
+
for (const stage of itemStages) {
|
|
69
|
+
if (stage.type === 'active') {
|
|
70
|
+
if (stage.isStartState)
|
|
71
|
+
continue;
|
|
72
|
+
const params = (_b = (_a = item.state[layoutId]) === null || _a === void 0 ? void 0 : _a[stage.stateId]) !== null && _b !== void 0 ? _b : {};
|
|
73
|
+
for (const [key, stateDetails] of Object.entries(params)) {
|
|
74
|
+
itemStyles[key] = {
|
|
75
|
+
value: stateDetails.value
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (stage.type === 'transitioning') {
|
|
80
|
+
const activeStateId = stage.direction === 'in' ? stage.to : stage.from;
|
|
81
|
+
const params = (_d = (_c = item.state[layoutId]) === null || _c === void 0 ? void 0 : _c[activeStateId]) !== null && _d !== void 0 ? _d : {};
|
|
82
|
+
for (const [key, stateDetails] of Object.entries(params)) {
|
|
83
|
+
itemStyles[key] = {
|
|
84
|
+
value: stage.direction === 'in' ? stateDetails.value : (_e = itemStyles[key]) === null || _e === void 0 ? void 0 : _e.value,
|
|
85
|
+
transition: {
|
|
86
|
+
timing: stateDetails[stage.direction].timing,
|
|
87
|
+
duration: stateDetails[stage.direction].duration,
|
|
88
|
+
delay: stateDetails[stage.direction].delay
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return itemStyles;
|
|
95
|
+
}
|
|
96
|
+
notifyTrigger(itemId, triggerType) {
|
|
97
|
+
var _a;
|
|
98
|
+
const timestamp = Date.now();
|
|
99
|
+
for (const interaction of this.interactions) {
|
|
100
|
+
const currentStateId = this.getCurrentStateByInteractionId(interaction.id);
|
|
101
|
+
const matchingTrigger = interaction.triggers.find((trigger) => trigger.itemId === itemId
|
|
102
|
+
&& trigger.from === currentStateId
|
|
103
|
+
&& trigger.type === triggerType);
|
|
104
|
+
if (!matchingTrigger)
|
|
105
|
+
continue;
|
|
106
|
+
const activeStateId = this.getActiveInteractionState(interaction.id);
|
|
107
|
+
const isNewStateActive = matchingTrigger.to === activeStateId;
|
|
108
|
+
this.setCurrentStateForInteraction(interaction.id, matchingTrigger.to);
|
|
109
|
+
const transitioningItems = (_a = this.stateItemsIdsMap[activeStateId]) !== null && _a !== void 0 ? _a : [];
|
|
110
|
+
this.itemsStages = this.itemsStages.map((stage) => {
|
|
111
|
+
if (stage.interactionId !== interaction.id)
|
|
112
|
+
return stage;
|
|
113
|
+
return {
|
|
114
|
+
itemId: stage.itemId,
|
|
115
|
+
interactionId: stage.interactionId,
|
|
116
|
+
type: 'transitioning',
|
|
117
|
+
from: stage.type === 'transitioning' ? stage.to : stage.stateId,
|
|
118
|
+
to: matchingTrigger.to,
|
|
119
|
+
direction: isNewStateActive ? 'in' : 'out',
|
|
120
|
+
updated: timestamp
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
this.notifyItemCtrlsChange(transitioningItems);
|
|
124
|
+
this.notifyTransitionStartForItems(transitioningItems, activeStateId);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
notifyTransitionStartForItems(itemsIds, activeStateId) {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
for (const itemId of itemsIds) {
|
|
130
|
+
const ctrl = this.ctrls.get(itemId);
|
|
131
|
+
const item = this.items.find((item) => item.id === itemId);
|
|
132
|
+
const keys = Object.keys((_b = (_a = item.state[this.layoutId]) === null || _a === void 0 ? void 0 : _a[activeStateId]) !== null && _b !== void 0 ? _b : {});
|
|
133
|
+
(_c = ctrl === null || ctrl === void 0 ? void 0 : ctrl.handleTransitionStart) === null || _c === void 0 ? void 0 : _c.call(ctrl, keys);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
notifyTransitionEnd(itemId) {
|
|
137
|
+
var _a;
|
|
138
|
+
const timestamp = Date.now();
|
|
139
|
+
this.itemsStages = this.itemsStages.map((stage) => {
|
|
140
|
+
if (stage.itemId !== itemId || stage.type !== 'transitioning')
|
|
141
|
+
return stage;
|
|
142
|
+
return {
|
|
143
|
+
itemId: itemId,
|
|
144
|
+
interactionId: stage.interactionId,
|
|
145
|
+
type: 'active',
|
|
146
|
+
stateId: stage.to,
|
|
147
|
+
isStartState: stage.direction === 'out',
|
|
148
|
+
updated: timestamp
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
152
|
+
}
|
|
153
|
+
getCurrentStateByInteractionId(id) {
|
|
154
|
+
let state;
|
|
155
|
+
for (const interactionId of Object.keys(this.interactionStateMap)) {
|
|
156
|
+
if (id !== interactionId)
|
|
157
|
+
continue;
|
|
158
|
+
state = this.interactionStateMap[interactionId];
|
|
159
|
+
}
|
|
160
|
+
if (!state)
|
|
161
|
+
throw new Error(`Failed to find current state for interaction w/ id="${id}"`);
|
|
162
|
+
return state;
|
|
163
|
+
}
|
|
164
|
+
setCurrentStateForInteraction(interactionId, stateId) {
|
|
165
|
+
this.interactionStateMap = Object.assign(Object.assign({}, this.interactionStateMap), { [interactionId]: stateId });
|
|
166
|
+
}
|
|
167
|
+
getActiveInteractionState(interactionId) {
|
|
168
|
+
var _a;
|
|
169
|
+
const { interactions } = this;
|
|
170
|
+
const interaction = interactions.find((interaction) => interaction.id === interactionId);
|
|
171
|
+
return (_a = interaction.states.find(state => state.id !== interaction.startStateId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
172
|
+
}
|
|
173
|
+
notifyItemCtrlsChange(itemsIds) {
|
|
174
|
+
var _a;
|
|
175
|
+
for (const itemId of itemsIds) {
|
|
176
|
+
(_a = this.ctrls.get(itemId)) === null || _a === void 0 ? void 0 : _a.receiveChange();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
unpackItems(article) {
|
|
180
|
+
var _a;
|
|
181
|
+
const itemsArr = [];
|
|
182
|
+
for (const section of article.sections) {
|
|
183
|
+
for (const item of section.items) {
|
|
184
|
+
const { items } = item, itemWithoutChildren = __rest(item, ["items"]);
|
|
185
|
+
itemsArr.push(itemWithoutChildren);
|
|
186
|
+
if (!(0, Item_1.isItemType)(item, sdk_1.ArticleItemType.Group))
|
|
187
|
+
continue;
|
|
188
|
+
const groupChildren = (_a = item === null || item === void 0 ? void 0 : item.items) !== null && _a !== void 0 ? _a : [];
|
|
189
|
+
for (const child of groupChildren) {
|
|
190
|
+
itemsArr.push(child);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return itemsArr;
|
|
195
|
+
}
|
|
196
|
+
getDefaultItemStages() {
|
|
197
|
+
const timestamp = Date.now();
|
|
198
|
+
const { items, layoutId } = this;
|
|
199
|
+
const stages = [];
|
|
200
|
+
for (const item of items) {
|
|
201
|
+
const itemStatesMap = item.state[layoutId];
|
|
202
|
+
if (!itemStatesMap)
|
|
203
|
+
continue;
|
|
204
|
+
for (const stateId of Object.keys(itemStatesMap)) {
|
|
205
|
+
const interactionId = this.activeStateIdInteractionIdMap[stateId];
|
|
206
|
+
if (!interactionId)
|
|
207
|
+
continue;
|
|
208
|
+
stages.push({
|
|
209
|
+
itemId: item.id,
|
|
210
|
+
interactionId,
|
|
211
|
+
type: 'active',
|
|
212
|
+
isStartState: true,
|
|
213
|
+
updated: timestamp
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return stages;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.InteractionsRegistry = InteractionsRegistry;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ItemInteractionController = void 0;
|
|
4
|
+
const getTransition_1 = require("./getTransition");
|
|
5
|
+
const CSSPropertyNameMap_1 = require("./CSSPropertyNameMap");
|
|
6
|
+
class ItemInteractionController {
|
|
7
|
+
constructor(itemId, registry, onChange) {
|
|
8
|
+
this.itemId = itemId;
|
|
9
|
+
this.registry = registry;
|
|
10
|
+
this.onChange = onChange;
|
|
11
|
+
this.transitionsInProgress = new Set();
|
|
12
|
+
this.handleTransitionStart = (types) => {
|
|
13
|
+
this.transitionsInProgress.clear();
|
|
14
|
+
for (const type of types) {
|
|
15
|
+
this.transitionsInProgress.add(type);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
this.handleTransitionEnd = (cssPropKey) => {
|
|
19
|
+
if (cssPropKey.startsWith('border-') && cssPropKey.endsWith('-radius')) {
|
|
20
|
+
cssPropKey = 'border-radius';
|
|
21
|
+
}
|
|
22
|
+
if (cssPropKey.startsWith('border-') && cssPropKey.endsWith('-width')) {
|
|
23
|
+
cssPropKey = 'border-width';
|
|
24
|
+
}
|
|
25
|
+
const styleKeys = (0, CSSPropertyNameMap_1.getStyleKeysFromCSSProperty)(cssPropKey);
|
|
26
|
+
for (const key of styleKeys) {
|
|
27
|
+
const found = this.transitionsInProgress.has(key);
|
|
28
|
+
if (!found)
|
|
29
|
+
continue;
|
|
30
|
+
this.transitionsInProgress.delete(key);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (this.transitionsInProgress.size !== 0)
|
|
34
|
+
return;
|
|
35
|
+
this.registry.notifyTransitionEnd(this.itemId);
|
|
36
|
+
};
|
|
37
|
+
this.registry.register(itemId, this);
|
|
38
|
+
}
|
|
39
|
+
getState(keys) {
|
|
40
|
+
const stateProps = this.registry.getStatePropsForItem(this.itemId);
|
|
41
|
+
const styles = keys.reduce((map, styleKey) => {
|
|
42
|
+
const prop = stateProps[styleKey];
|
|
43
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.value) === undefined)
|
|
44
|
+
return map;
|
|
45
|
+
map[styleKey] = prop.value;
|
|
46
|
+
return map;
|
|
47
|
+
}, {});
|
|
48
|
+
const transition = (0, getTransition_1.getTransition)(stateProps, keys);
|
|
49
|
+
return {
|
|
50
|
+
styles,
|
|
51
|
+
transition
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
sendTrigger(type) {
|
|
55
|
+
this.registry.notifyTrigger(this.itemId, type);
|
|
56
|
+
}
|
|
57
|
+
receiveChange() {
|
|
58
|
+
this.onChange();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ItemInteractionController = ItemInteractionController;
|