@cntrl-site/sdk-nextjs 1.1.5 → 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/.idea/modules.xml +8 -0
- package/.idea/sdk-nextjs.iml +12 -0
- package/.idea/vcs.xml +6 -0
- 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} +10 -13
- 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 -6
- 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 +18 -19
- 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} +19 -28
- 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 +6 -5
- package/src/utils/RichTextConverter/RichTextConverter.tsx +1 -1
- package/src/utils/getCompoundBondaryStyles.ts +62 -0
- package/src/utils/isItemType.ts +6 -0
- package/eslint.config.mjs +0 -18
- /package/lib/components/{LinkWrapper.js → items/LinkWrapper.js} +0 -0
- /package/src/components/{LinkWrapper.tsx → items/LinkWrapper.tsx} +0 -0
|
@@ -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 }) => {
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { FC } from 'react';
|
|
3
|
-
import type { ItemProps } from '../Item';
|
|
4
|
-
import { getLayoutStyles } from '@cntrl-site/sdk';
|
|
1
|
+
import { FC, useEffect, useId, useMemo, useState } from 'react';
|
|
5
2
|
import Player from '@vimeo/player';
|
|
6
|
-
import { useEffect, useId, useMemo, useState } from 'react';
|
|
7
3
|
import JSXStyle from 'styled-jsx/style';
|
|
8
|
-
import {
|
|
9
|
-
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
10
|
-
import { getStyleFromItemStateAndParams } from '../../utils/getStyleFromItemStateAndParams';
|
|
4
|
+
import { ItemProps } from '../Item';
|
|
11
5
|
import { LinkWrapper } from '../LinkWrapper';
|
|
12
|
-
import { useItemAngle } from '../useItemAngle';
|
|
13
6
|
import { useEmbedVideoItem } from './useEmbedVideoItem';
|
|
7
|
+
import { useItemAngle } from '../useItemAngle';
|
|
8
|
+
import { getLayoutStyles, VimeoEmbedItem as TVimeoEmbedItem } from '@cntrl-site/sdk';
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
11
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
14
12
|
|
|
15
13
|
export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
16
14
|
const id = useId();
|
|
@@ -39,7 +37,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
39
37
|
const validURL = new URL(url);
|
|
40
38
|
validURL.searchParams.append('controls', String(controls));
|
|
41
39
|
validURL.searchParams.append('autoplay', String(play === 'auto'));
|
|
42
|
-
validURL.searchParams.append('muted', String(muted));
|
|
40
|
+
validURL.searchParams.append('muted', String(play !== 'on-click' ? true : muted));
|
|
43
41
|
validURL.searchParams.append('loop', String(loop));
|
|
44
42
|
validURL.searchParams.append('pip', String(pictureInPicture));
|
|
45
43
|
validURL.searchParams.append('title', '0');
|
|
@@ -48,12 +46,12 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
48
46
|
validURL.searchParams.append('autopause', 'false');
|
|
49
47
|
|
|
50
48
|
return validURL.href;
|
|
51
|
-
}
|
|
49
|
+
}
|
|
52
50
|
const validUrl = getValidVimeoUrl(url);
|
|
53
51
|
|
|
54
52
|
useEffect(() => {
|
|
55
53
|
if (!vimeoPlayer || !imgRef) return;
|
|
56
|
-
if (play === 'on-click') {
|
|
54
|
+
if (play === 'on-click' && !controls) {
|
|
57
55
|
setIsCoverVisible(true);
|
|
58
56
|
}
|
|
59
57
|
vimeoPlayer.on('pause', (e) => {
|
|
@@ -61,9 +59,6 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
61
59
|
setIsCoverVisible(true);
|
|
62
60
|
}
|
|
63
61
|
});
|
|
64
|
-
vimeoPlayer.on('ended', () => {
|
|
65
|
-
setIsCoverVisible(true);
|
|
66
|
-
});
|
|
67
62
|
}, [vimeoPlayer, imgRef]);
|
|
68
63
|
|
|
69
64
|
const handleClick = async () => {
|
|
@@ -72,8 +67,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
72
67
|
if (isPaused) {
|
|
73
68
|
vimeoPlayer.play();
|
|
74
69
|
setIsCoverVisible(false);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
70
|
+
} else {
|
|
77
71
|
vimeoPlayer.pause();
|
|
78
72
|
}
|
|
79
73
|
};
|
|
@@ -83,7 +77,6 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
83
77
|
vimeoPlayer!.play();
|
|
84
78
|
setIsCoverVisible(false);
|
|
85
79
|
};
|
|
86
|
-
|
|
87
80
|
const isInteractive = opacity !== 0;
|
|
88
81
|
useEffect(() => {
|
|
89
82
|
onVisibilityChange?.(isInteractive);
|
|
@@ -104,7 +97,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
104
97
|
if (!vimeoPlayer || play !== 'on-hover') return;
|
|
105
98
|
vimeoPlayer.play();
|
|
106
99
|
}}
|
|
107
|
-
onMouseLeave={() =>
|
|
100
|
+
onMouseLeave={() =>{
|
|
108
101
|
if (!vimeoPlayer || play !== 'on-hover') return;
|
|
109
102
|
vimeoPlayer.pause();
|
|
110
103
|
}}
|
|
@@ -128,7 +121,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
128
121
|
/>
|
|
129
122
|
)}
|
|
130
123
|
{/* ↓ This is necessary to track clicks on an iframe. */}
|
|
131
|
-
{(!item.commonParams.controls &&
|
|
124
|
+
{(!item.commonParams.controls && play === 'on-click') && (
|
|
132
125
|
<div
|
|
133
126
|
onClick={handleClick}
|
|
134
127
|
style={{
|
|
@@ -142,18 +135,17 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
142
135
|
)}
|
|
143
136
|
<iframe
|
|
144
137
|
ref={setIframeRef}
|
|
145
|
-
className=
|
|
138
|
+
className={`embed-video`}
|
|
146
139
|
src={validUrl || ''}
|
|
147
140
|
allow="autoplay; fullscreen; picture-in-picture;"
|
|
148
141
|
allowFullScreen
|
|
149
142
|
style={{
|
|
150
|
-
...(radius !== undefined
|
|
143
|
+
...(radius !== undefined ? { borderRadius: `${radius * 100}vw` } : {}),
|
|
151
144
|
transition: frameStateParams?.transition ?? 'none'
|
|
152
145
|
}}
|
|
153
146
|
/>
|
|
154
147
|
</div>
|
|
155
|
-
<JSXStyle id={id}>
|
|
156
|
-
{`
|
|
148
|
+
<JSXStyle id={id}>{`
|
|
157
149
|
.embed-video-wrapper-${item.id} {
|
|
158
150
|
position: absolute;
|
|
159
151
|
width: 100%;
|
|
@@ -167,7 +159,7 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
167
159
|
overflow: hidden;
|
|
168
160
|
}
|
|
169
161
|
${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
170
|
-
|
|
162
|
+
return (`
|
|
171
163
|
.embed-video-wrapper-${item.id} {
|
|
172
164
|
opacity: ${layoutParams.opacity};
|
|
173
165
|
transform: rotate(${area.angle}deg);
|
|
@@ -177,9 +169,8 @@ export const VimeoEmbedItem: FC<ItemProps<TVimeoEmbedItem>> = ({ item, sectionId
|
|
|
177
169
|
border-radius: ${layoutParams.radius * 100}vw;
|
|
178
170
|
}
|
|
179
171
|
`);
|
|
180
|
-
|
|
181
|
-
`}
|
|
182
|
-
</JSXStyle>
|
|
172
|
+
})}
|
|
173
|
+
`}</JSXStyle>
|
|
183
174
|
</LinkWrapper>
|
|
184
175
|
);
|
|
185
176
|
};
|
|
@@ -2,15 +2,15 @@ import { FC, useEffect, useId, useState } from 'react';
|
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
3
|
import { ItemProps } from '../Item';
|
|
4
4
|
import { LinkWrapper } from '../LinkWrapper';
|
|
5
|
-
import { getYoutubeId } from '
|
|
5
|
+
import { getYoutubeId } from '../../../utils/getValidYoutubeUrl';
|
|
6
6
|
import { useEmbedVideoItem } from './useEmbedVideoItem';
|
|
7
7
|
import { useItemAngle } from '../useItemAngle';
|
|
8
8
|
import { getLayoutStyles, YoutubeEmbedItem as TYoutubeEmbedItem } from '@cntrl-site/sdk';
|
|
9
|
-
import { useCntrlContext } from '
|
|
10
|
-
import { useYouTubeIframeApi } from '
|
|
11
|
-
import { YTPlayer } from '
|
|
12
|
-
import { useRegisterResize } from "
|
|
13
|
-
import { getStyleFromItemStateAndParams } from '
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useYouTubeIframeApi } from '../../../utils/Youtube/useYouTubeIframeApi';
|
|
11
|
+
import { YTPlayer } from '../../../utils/Youtube/YoutubeIframeApi';
|
|
12
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
13
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
14
14
|
|
|
15
15
|
export const YoutubeEmbedItem: FC<ItemProps<TYoutubeEmbedItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
16
16
|
const id = useId();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KeyframeType, VimeoEmbedItem, YoutubeEmbedItem } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '
|
|
3
|
-
import { useLayoutContext } from '
|
|
2
|
+
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
3
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
export const useEmbedVideoItem = (item: VimeoEmbedItem | YoutubeEmbedItem, sectionId: string) => {
|
|
6
6
|
const layoutId = useLayoutContext();
|
|
@@ -6,12 +6,12 @@ import { ItemProps } from '../Item';
|
|
|
6
6
|
import { LinkWrapper } from '../LinkWrapper';
|
|
7
7
|
import { useFileItem } from './useFileItem';
|
|
8
8
|
import { useItemAngle } from '../useItemAngle';
|
|
9
|
-
import { useCntrlContext } from '
|
|
10
|
-
import { useRegisterResize } from "
|
|
11
|
-
import { useImageFx } from '
|
|
12
|
-
import { useElementRect } from '
|
|
13
|
-
import { useLayoutContext } from '
|
|
14
|
-
import { getStyleFromItemStateAndParams } from '
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
11
|
+
import { useImageFx } from '../../../utils/effects/useImageFx';
|
|
12
|
+
import { useElementRect } from '../../../utils/useElementRect';
|
|
13
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
14
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
15
15
|
|
|
16
16
|
const baseVariables = `precision mediump float;
|
|
17
17
|
uniform sampler2D u_image;
|
|
@@ -6,11 +6,11 @@ import { ItemProps } from '../Item';
|
|
|
6
6
|
import { LinkWrapper } from '../LinkWrapper';
|
|
7
7
|
import { useFileItem } from './useFileItem';
|
|
8
8
|
import { useItemAngle } from '../useItemAngle';
|
|
9
|
-
import { useCntrlContext } from '
|
|
10
|
-
import { useRegisterResize } from "
|
|
11
|
-
import { useLayoutContext } from '
|
|
12
|
-
import { ScrollPlaybackVideo } from '
|
|
13
|
-
import { getStyleFromItemStateAndParams } from '
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
11
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
12
|
+
import { ScrollPlaybackVideo } from '../../ScrollPlaybackVideo';
|
|
13
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
14
14
|
|
|
15
15
|
export const VideoItem: FC<ItemProps<TVideoItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
16
16
|
const id = useId();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ImageItem, KeyframeType, VideoItem } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '
|
|
3
|
-
import { useLayoutContext } from '
|
|
2
|
+
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
3
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_COLOR = 'rgba(0, 0, 0, 1)';
|
|
6
6
|
export const useFileItem = (item: ImageItem | VideoItem, sectionId: string) => {
|
|
@@ -3,13 +3,13 @@ import { Item, ItemProps } from '../Item';
|
|
|
3
3
|
import JSXStyle from 'styled-jsx/style';
|
|
4
4
|
import { getLayoutStyles, GroupItem as TGroupItem } from '@cntrl-site/sdk';
|
|
5
5
|
import { LinkWrapper } from '../LinkWrapper';
|
|
6
|
-
import { useRegisterResize } from '
|
|
7
|
-
import { useCntrlContext } from '
|
|
6
|
+
import { useRegisterResize } from '../../../common/useRegisterResize';
|
|
7
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
8
8
|
import { useItemAngle } from '../useItemAngle';
|
|
9
9
|
import { useGroupItem } from './useGroupItem';
|
|
10
|
-
import { getStyleFromItemStateAndParams } from '
|
|
10
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
11
11
|
|
|
12
|
-
export const GroupItem: FC<ItemProps<TGroupItem>> = ({ item, sectionId, onResize,
|
|
12
|
+
export const GroupItem: FC<ItemProps<TGroupItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
13
13
|
const id = useId();
|
|
14
14
|
const { items } = item;
|
|
15
15
|
const itemAngle = useItemAngle(item, sectionId);
|
|
@@ -42,7 +42,6 @@ export const GroupItem: FC<ItemProps<TGroupItem>> = ({ item, sectionId, onResize
|
|
|
42
42
|
item={item}
|
|
43
43
|
key={item.id}
|
|
44
44
|
sectionId={sectionId}
|
|
45
|
-
articleHeight={articleHeight}
|
|
46
45
|
isParentVisible={isInteractive}
|
|
47
46
|
isInGroup
|
|
48
47
|
/>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useKeyframeValue } from '
|
|
1
|
+
import { useKeyframeValue } from '../../../common/useKeyframeValue';
|
|
2
2
|
import { GroupItem, KeyframeType } from '@cntrl-site/sdk';
|
|
3
|
-
import { useLayoutContext } from '
|
|
3
|
+
import { useLayoutContext } from '../../useLayoutContext';
|
|
4
4
|
|
|
5
5
|
export function useGroupItem(item: GroupItem, sectionId: string) {
|
|
6
6
|
const layoutId = useLayoutContext();
|