@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
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComponentType,
|
|
1
|
+
import React, {
|
|
3
2
|
FC,
|
|
4
|
-
PropsWithChildren,
|
|
5
3
|
useCallback,
|
|
6
4
|
useContext,
|
|
7
5
|
useEffect,
|
|
@@ -15,39 +13,32 @@ import {
|
|
|
15
13
|
AnchorSide,
|
|
16
14
|
ArticleItemType,
|
|
17
15
|
getLayoutStyles,
|
|
18
|
-
Item as TItem,
|
|
19
16
|
ItemAny,
|
|
20
17
|
PositionType
|
|
21
18
|
} from '@cntrl-site/sdk';
|
|
22
|
-
import {
|
|
23
|
-
import { ImageItem } from './items/ImageItem';
|
|
24
|
-
import { VideoItem } from './items/VideoItem';
|
|
25
|
-
import { RichTextItem } from './items/RichTextItem';
|
|
26
|
-
import { VimeoEmbedItem } from './items/VimeoEmbed';
|
|
27
|
-
import { YoutubeEmbedItem } from './items/YoutubeEmbed';
|
|
28
|
-
import { CustomItem } from './items/CustomItem';
|
|
29
|
-
import { useCntrlContext } from '../provider/useCntrlContext';
|
|
19
|
+
import { useCntrlContext } from '../../provider/useCntrlContext';
|
|
30
20
|
import { useItemPosition } from './useItemPosition';
|
|
31
21
|
import { useItemDimensions } from './useItemDimensions';
|
|
32
22
|
import { useItemScale } from './useItemScale';
|
|
33
|
-
import { ScaleAnchorMap } from '
|
|
34
|
-
import { useSectionHeightData } from '
|
|
35
|
-
import { getItemTopStyle } from '
|
|
36
|
-
import { useStickyItemTop } from './
|
|
37
|
-
import { getAnchoredItemTop } from '
|
|
38
|
-
import { useLayoutContext } from '
|
|
39
|
-
import { ArticleRectContext } from "
|
|
40
|
-
import { useExemplary } from "
|
|
41
|
-
import { GroupItem } from './items/GroupItem';
|
|
42
|
-
import { CodeEmbedItem } from './items/CodeEmbedItem';
|
|
23
|
+
import { ScaleAnchorMap } from '../../utils/ScaleAnchorMap';
|
|
24
|
+
import { useSectionHeightData } from '../Section/useSectionHeightMap';
|
|
25
|
+
import { getItemTopStyle } from '../../utils/getItemTopStyle';
|
|
26
|
+
import { useStickyItemTop } from './useStickyItemTop';
|
|
27
|
+
import { getAnchoredItemTop } from '../../utils/getAnchoredItemTop';
|
|
28
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
29
|
+
import { ArticleRectContext } from "../../provider/ArticleRectContext";
|
|
30
|
+
import { useExemplary } from "../../common/useExemplary";
|
|
43
31
|
import { AreaAnchor } from '@cntrl-site/sdk/src/types/article/ItemArea';
|
|
44
|
-
import { KeyframesContext } from '
|
|
45
|
-
import { useItemInteractionCtrl } from '
|
|
32
|
+
import { KeyframesContext } from '../../provider/KeyframesContext';
|
|
33
|
+
import { useItemInteractionCtrl } from '../../interactions/useItemInteractionCtrl';
|
|
34
|
+
import { isItemType } from '../../utils/isItemType';
|
|
35
|
+
import { RichTextWrapper } from './RichTextWrapper';
|
|
36
|
+
import { itemsMap } from './itemsMap';
|
|
46
37
|
|
|
47
38
|
export interface ItemProps<I extends ItemAny> {
|
|
48
39
|
item: I;
|
|
49
40
|
sectionId: string;
|
|
50
|
-
articleHeight
|
|
41
|
+
articleHeight?: number;
|
|
51
42
|
onResize?: (height: number) => void;
|
|
52
43
|
interactionCtrl?: ReturnType<typeof useItemInteractionCtrl>;
|
|
53
44
|
onVisibilityChange: (isVisible: boolean) => void;
|
|
@@ -56,41 +47,16 @@ export interface ItemProps<I extends ItemAny> {
|
|
|
56
47
|
export interface ItemWrapperProps {
|
|
57
48
|
item: ItemAny;
|
|
58
49
|
sectionId: string;
|
|
59
|
-
articleHeight
|
|
50
|
+
articleHeight?: number;
|
|
60
51
|
isInGroup?: boolean;
|
|
61
52
|
isParentVisible?: boolean;
|
|
62
53
|
}
|
|
63
54
|
|
|
64
|
-
const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
|
|
65
|
-
[ArticleItemType.Rectangle]: RectangleItem,
|
|
66
|
-
[ArticleItemType.Image]: ImageItem,
|
|
67
|
-
[ArticleItemType.Video]: VideoItem,
|
|
68
|
-
[ArticleItemType.RichText]: RichTextItem,
|
|
69
|
-
[ArticleItemType.YoutubeEmbed]: YoutubeEmbedItem,
|
|
70
|
-
[ArticleItemType.VimeoEmbed]: VimeoEmbedItem,
|
|
71
|
-
[ArticleItemType.Custom]: CustomItem,
|
|
72
|
-
[ArticleItemType.Group]: GroupItem,
|
|
73
|
-
[ArticleItemType.CodeEmbed]: CodeEmbedItem
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
interface RTWrapperProps {
|
|
77
|
-
isRichText: boolean;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
55
|
const stickyFix = `
|
|
81
56
|
-webkit-transform: translate3d(0, 0, 0);
|
|
82
57
|
transform: translate3d(0, 0, 0);
|
|
83
58
|
`;
|
|
84
59
|
|
|
85
|
-
const RichTextWrapper: FC<PropsWithChildren<RTWrapperProps>> = ({ isRichText, children }) => {
|
|
86
|
-
if (!isRichText) return <>{children}</>;
|
|
87
|
-
return (
|
|
88
|
-
<div style={{ transformOrigin: 'top left', transform: 'scale(var(--layout-deviation))' }}>
|
|
89
|
-
{children}
|
|
90
|
-
</div>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
60
|
const noop = () => null;
|
|
95
61
|
|
|
96
62
|
export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isParentVisible = true, isInGroup = false }) => {
|
|
@@ -134,7 +100,7 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
134
100
|
const handleItemResize = (height: number) => {
|
|
135
101
|
if (!layout) return;
|
|
136
102
|
const sticky = item.sticky[layout];
|
|
137
|
-
if (!sticky || stickyTop === undefined) {
|
|
103
|
+
if (!sticky || stickyTop === undefined || !articleHeight) {
|
|
138
104
|
setWrapperHeight(undefined);
|
|
139
105
|
return;
|
|
140
106
|
}
|
|
@@ -160,6 +126,9 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
160
126
|
const isRichText = isItemType(item, ArticleItemType.RichText);
|
|
161
127
|
const width = (innerStateProps?.styles?.width ?? dimensions?.width) as number | undefined;
|
|
162
128
|
const height = (innerStateProps?.styles?.height ?? dimensions?.height) as number | undefined;
|
|
129
|
+
const anchorSide = layout ? item.area[layout].anchorSide : AnchorSide.Top;
|
|
130
|
+
const positionType = layout ? item.area[layout].positionType : PositionType.ScreenBased;
|
|
131
|
+
const isScreenBasedBottom = positionType === PositionType.ScreenBased && anchorSide === AnchorSide.Bottom;
|
|
163
132
|
const scale = innerStateProps?.styles?.scale ?? itemScale;
|
|
164
133
|
const hasClickTriggers = interactionCtrl?.getHasTrigger(item.id, 'click') ?? false;
|
|
165
134
|
return (
|
|
@@ -171,9 +140,9 @@ export const Item: FC<ItemWrapperProps> = ({ item, sectionId, articleHeight, isP
|
|
|
171
140
|
interactionCtrl?.handleTransitionEnd?.(e.propertyName);
|
|
172
141
|
}}
|
|
173
142
|
style={{
|
|
174
|
-
...(position ? { top: position.top } : {}),
|
|
175
|
-
...(position ? { left: position.left } : {}),
|
|
176
|
-
...(position ? { bottom: position.
|
|
143
|
+
...(position ? { top: isScreenBasedBottom ? 'unset' : getItemTopStyle(position.top, anchorSide) } : {}),
|
|
144
|
+
...(position ? { left: `${position.left * 100}vw` } : {}),
|
|
145
|
+
...(position ? { bottom: isScreenBasedBottom ? `${-position.top * 100}vw` : 'unset' } : {}),
|
|
177
146
|
...(wrapperHeight !== undefined ? { height: `${wrapperHeight * 100}vw` } : {}),
|
|
178
147
|
transition: wrapperStateProps?.transition ?? 'none'
|
|
179
148
|
}}
|
|
@@ -271,10 +240,6 @@ function parseSizing(sizing: string = 'manual'): Axis {
|
|
|
271
240
|
} as Axis;
|
|
272
241
|
}
|
|
273
242
|
|
|
274
|
-
export function isItemType<T extends ArticleItemType>(item: ItemAny, itemType: T): item is TItem<T> {
|
|
275
|
-
return item.type === itemType;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
243
|
interface Axis {
|
|
279
244
|
x: 'manual' | 'auto';
|
|
280
245
|
y: 'manual' | 'auto';
|
|
@@ -6,9 +6,9 @@ import { ItemProps } from '../Item';
|
|
|
6
6
|
import { LinkWrapper } from '../LinkWrapper';
|
|
7
7
|
import { useRectangleItem } from './useRectangleItem';
|
|
8
8
|
import { useItemAngle } from '../useItemAngle';
|
|
9
|
-
import { useCntrlContext } from '
|
|
10
|
-
import { useRegisterResize } from "
|
|
11
|
-
import { getStyleFromItemStateAndParams } from '
|
|
9
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
10
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
11
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
12
12
|
|
|
13
13
|
export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
14
14
|
const id = useId();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KeyframeType, RectangleItem } 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 defaultColor = 'rgba(0, 0, 0, 1)';
|
|
6
6
|
|
|
@@ -4,14 +4,14 @@ import { getLayoutStyles, RichTextItem as TRichTextItem } from '@cntrl-site/sdk'
|
|
|
4
4
|
import JSXStyle from 'styled-jsx/style';
|
|
5
5
|
import { ItemProps } from '../Item';
|
|
6
6
|
import { useRichTextItem } from './useRichTextItem';
|
|
7
|
-
import { useCntrlContext } from '
|
|
8
|
-
import { useRichTextItemValues } from '
|
|
9
|
-
import { useRegisterResize } from "
|
|
10
|
-
import { getFontFamilyValue } from '
|
|
11
|
-
import { useExemplary } from '
|
|
7
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
8
|
+
import { useRichTextItemValues } from '../useRichTextItemValues';
|
|
9
|
+
import { useRegisterResize } from "../../../common/useRegisterResize";
|
|
10
|
+
import { getFontFamilyValue } from '../../../utils/getFontFamilyValue';
|
|
11
|
+
import { useExemplary } from '../../../common/useExemplary';
|
|
12
12
|
import { useItemAngle } from '../useItemAngle';
|
|
13
|
-
import { getStyleFromItemStateAndParams } from '
|
|
14
|
-
import { useCurrentLayout } from '
|
|
13
|
+
import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemStateAndParams';
|
|
14
|
+
import { useCurrentLayout } from '../../../common/useCurrentLayout';
|
|
15
15
|
|
|
16
16
|
export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId, onResize, interactionCtrl, onVisibilityChange }) => {
|
|
17
17
|
const id = useId();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RichTextItem } from '@cntrl-site/sdk';
|
|
2
|
-
import { RichTextConverter } from '
|
|
3
|
-
import { useCntrlContext } from '
|
|
2
|
+
import { RichTextConverter } from '../../../utils/RichTextConverter/RichTextConverter';
|
|
3
|
+
import { useCntrlContext } from '../../../provider/useCntrlContext';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
const richTextConverter = new RichTextConverter();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { FC, PropsWithChildren } from 'react';
|
|
2
|
+
|
|
3
|
+
interface RTWrapperProps {
|
|
4
|
+
isRichText: boolean;
|
|
5
|
+
transformOrigin?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const RichTextWrapper: FC<PropsWithChildren<RTWrapperProps>> = ({ isRichText, children, transformOrigin = 'top left' }) => {
|
|
9
|
+
if (!isRichText) return <>{children}</>;
|
|
10
|
+
return (
|
|
11
|
+
<div style={{ transformOrigin, transform: 'scale(var(--layout-deviation))' }}>
|
|
12
|
+
{children}
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ArticleItemType } from '@cntrl-site/sdk';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { RectangleItem } from './RectangleItem/RectangleItem';
|
|
4
|
+
import { ImageItem } from './FileItem/ImageItem';
|
|
5
|
+
import { VideoItem } from './FileItem/VideoItem';
|
|
6
|
+
import { RichTextItem } from './RichTextItem/RichTextItem';
|
|
7
|
+
import { YoutubeEmbedItem } from './EmbedVideoItem/YoutubeEmbed';
|
|
8
|
+
import { VimeoEmbedItem } from './EmbedVideoItem/VimeoEmbed';
|
|
9
|
+
import { CustomItem } from './CustomItem/CustomItem';
|
|
10
|
+
import { GroupItem } from './GroupItem/GroupItem';
|
|
11
|
+
import { CodeEmbedItem } from './CodeEmbedItem/CodeEmbedItem';
|
|
12
|
+
import { ItemProps } from './Item';
|
|
13
|
+
import { CompoundItem } from './CompoundItem/CompoundItem';
|
|
14
|
+
|
|
15
|
+
export const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
|
|
16
|
+
[ArticleItemType.Rectangle]: RectangleItem,
|
|
17
|
+
[ArticleItemType.Image]: ImageItem,
|
|
18
|
+
[ArticleItemType.Video]: VideoItem,
|
|
19
|
+
[ArticleItemType.RichText]: RichTextItem,
|
|
20
|
+
[ArticleItemType.YoutubeEmbed]: YoutubeEmbedItem,
|
|
21
|
+
[ArticleItemType.VimeoEmbed]: VimeoEmbedItem,
|
|
22
|
+
[ArticleItemType.Custom]: CustomItem,
|
|
23
|
+
[ArticleItemType.Group]: GroupItem,
|
|
24
|
+
[ArticleItemType.Compound]: CompoundItem,
|
|
25
|
+
[ArticleItemType.CodeEmbed]: CodeEmbedItem
|
|
26
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ItemAny, KeyframeType } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '
|
|
2
|
+
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
3
|
|
|
4
4
|
export const useItemAngle = (item: ItemAny, sectionId: string) => {
|
|
5
5
|
const angle = useKeyframeValue(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ItemAny, KeyframeType } 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 useItemDimensions = (item: ItemAny, sectionId: string) => {
|
|
6
6
|
const layoutId = useLayoutContext();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnchorSide, ItemAny, KeyframeType, PositionType } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '
|
|
3
|
-
import { getItemTopStyle } from '
|
|
4
|
-
import { useLayoutContext } from '
|
|
2
|
+
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
3
|
+
import { getItemTopStyle } from '../../utils/getItemTopStyle';
|
|
4
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
5
5
|
|
|
6
6
|
export const useItemPosition = (
|
|
7
7
|
item: ItemAny,
|
|
@@ -20,18 +20,15 @@ export const useItemPosition = (
|
|
|
20
20
|
sectionId,
|
|
21
21
|
[layoutId]
|
|
22
22
|
);
|
|
23
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
|
|
24
|
-
const positionType = layoutId ? item.area[layoutId].positionType : PositionType.ScreenBased;
|
|
25
23
|
// to prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
|
|
26
|
-
const isScreenBasedBottom = positionType === PositionType.ScreenBased && anchorSide === AnchorSide.Bottom;
|
|
27
24
|
if (!position) return undefined;
|
|
28
25
|
const top = stateValues?.top ?? position.top;
|
|
29
26
|
const left = stateValues?.left ?? position.left;
|
|
30
27
|
return position ? {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
left: `${left * 100}vw`
|
|
28
|
+
top,
|
|
29
|
+
left
|
|
34
30
|
} : undefined;
|
|
31
|
+
|
|
35
32
|
};
|
|
36
33
|
|
|
37
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ItemAny, KeyframeType } 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 useItemScale = (item: ItemAny, sectionId: string) => {
|
|
6
6
|
const layoutId = useLayoutContext();
|
package/src/index.ts
CHANGED
|
@@ -5,15 +5,15 @@ export { Page } from './components/Page';
|
|
|
5
5
|
export type { PageProps } from './components/Page';
|
|
6
6
|
export { CNTRLHead as Head } from './components/Head';
|
|
7
7
|
export { Article } from './components/Article';
|
|
8
|
-
export { Section } from './components/Section';
|
|
9
|
-
export { Item } from './components/Item';
|
|
10
|
-
export { ImageItem } from './components/items/ImageItem';
|
|
11
|
-
export { RectangleItem } from './components/items/RectangleItem';
|
|
12
|
-
export { RichTextItem } from './components/items/RichTextItem';
|
|
13
|
-
export { VideoItem } from './components/items/VideoItem';
|
|
8
|
+
export { Section } from './components/Section/Section';
|
|
9
|
+
export { Item } from './components/items/Item';
|
|
10
|
+
export { ImageItem } from './components/items/FileItem/ImageItem';
|
|
11
|
+
export { RectangleItem } from './components/items/RectangleItem/RectangleItem';
|
|
12
|
+
export { RichTextItem } from './components/items/RichTextItem/RichTextItem';
|
|
13
|
+
export { VideoItem } from './components/items/FileItem/VideoItem';
|
|
14
14
|
export { LayoutStyle } from './components/LayoutStyle';
|
|
15
|
-
export { VimeoEmbedItem } from './components/items/VimeoEmbed';
|
|
16
|
-
export { YoutubeEmbedItem } from './components/items/YoutubeEmbed';
|
|
15
|
+
export { VimeoEmbedItem } from './components/items/EmbedVideoItem/VimeoEmbed';
|
|
16
|
+
export { YoutubeEmbedItem } from './components/items/EmbedVideoItem/YoutubeEmbed';
|
|
17
17
|
|
|
18
18
|
import { cntrlSdkContext as sdk } from './provider/defaultContext';
|
|
19
19
|
export { CntrlProvider } from './provider/CntrlProvider';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
InteractionTrigger,
|
|
7
7
|
ItemAny,
|
|
8
8
|
} from '@cntrl-site/sdk';
|
|
9
|
-
import { isItemType } from '../
|
|
9
|
+
import { isItemType } from '../utils/isItemType';
|
|
10
10
|
|
|
11
11
|
export class InteractionsRegistry implements InteractionsRegistryPort {
|
|
12
12
|
private ctrls: Map<ItemId, ItemInteractionCtrl> = new Map();
|
|
@@ -203,10 +203,11 @@ export class InteractionsRegistry implements InteractionsRegistryPort {
|
|
|
203
203
|
for (const item of section.items) {
|
|
204
204
|
const { items, ...itemWithoutChildren } = item;
|
|
205
205
|
itemsArr.push(itemWithoutChildren);
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
if (isItemType(item, ArticleItemType.Group) || isItemType(item, ArticleItemType.Compound)) {
|
|
207
|
+
const groupChildren = item?.items ?? [];
|
|
208
|
+
for (const child of groupChildren) {
|
|
209
|
+
itemsArr.push(child);
|
|
210
|
+
}
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
213
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
RichTextStyle,
|
|
10
10
|
RichTextEntity
|
|
11
11
|
} from '@cntrl-site/sdk';
|
|
12
|
-
import { LinkWrapper } from '../../components/LinkWrapper';
|
|
12
|
+
import { LinkWrapper } from '../../components/items/LinkWrapper';
|
|
13
13
|
import { getFontFamilyValue } from '../getFontFamilyValue';
|
|
14
14
|
|
|
15
15
|
interface StyleGroup {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AreaAnchor } from '@cntrl-site/sdk';
|
|
2
|
+
import { DimensionMode } from '@cntrl-site/sdk/src/types/article/ItemArea';
|
|
3
|
+
|
|
4
|
+
const positionMatrix: Record<AreaAnchor, [number, number]> = {
|
|
5
|
+
[AreaAnchor.TopLeft]: [0, 0],
|
|
6
|
+
[AreaAnchor.TopCenter]: [0, 0.5],
|
|
7
|
+
[AreaAnchor.TopRight]: [0, 1],
|
|
8
|
+
[AreaAnchor.MiddleLeft]: [0.5, 0],
|
|
9
|
+
[AreaAnchor.MiddleCenter]: [0.5, 0.5],
|
|
10
|
+
[AreaAnchor.MiddleRight]: [0.5, 1],
|
|
11
|
+
[AreaAnchor.BottomLeft]: [1, 0],
|
|
12
|
+
[AreaAnchor.BottomCenter]: [1, 0.5],
|
|
13
|
+
[AreaAnchor.BottomRight]: [1, 1]
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function getCompoundHeight(compoundSettings: CompoundSettings | undefined, height: number | undefined) {
|
|
17
|
+
if (!height || !compoundSettings) return;
|
|
18
|
+
if (compoundSettings.heightMode === 'relative') {
|
|
19
|
+
return `${height * 100}%`;
|
|
20
|
+
}
|
|
21
|
+
return `${height * 100}vw`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getCompoundWidth(compoundSettings: CompoundSettings | undefined, width: number | undefined, isRichText: boolean, exemplary?: number) {
|
|
25
|
+
if (!width || !compoundSettings) return;
|
|
26
|
+
if (compoundSettings.widthMode === 'relative') {
|
|
27
|
+
return `${width * 100}%`;
|
|
28
|
+
}
|
|
29
|
+
return isRichText && exemplary ? `${width * exemplary}px` : `${width * 100}vw`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getCompoundTop(compoundSettings: CompoundSettings | undefined, top: number | undefined) {
|
|
33
|
+
if (!top || !compoundSettings) return;
|
|
34
|
+
if (compoundSettings.heightMode === 'relative') {
|
|
35
|
+
return `${top * 100}%`;
|
|
36
|
+
}
|
|
37
|
+
const [ky] = positionMatrix[compoundSettings.positionAnchor];
|
|
38
|
+
return `calc(${ky * 100}% + ${top * 100}vw)`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getCompoundLeft(compoundSettings: CompoundSettings | undefined, left: number | undefined) {
|
|
42
|
+
if (!left || !compoundSettings) return;
|
|
43
|
+
if (compoundSettings.widthMode === 'relative') {
|
|
44
|
+
return `${left * 100}%`;
|
|
45
|
+
}
|
|
46
|
+
const [_, kx] = positionMatrix[compoundSettings.positionAnchor];
|
|
47
|
+
return `calc(${kx * 100}% + ${left * 100}vw)`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getCompoundTransform(compoundSettings: CompoundSettings | undefined) {
|
|
51
|
+
if (!compoundSettings) return 'unset';
|
|
52
|
+
const areaAnchor = compoundSettings.positionAnchor as AreaAnchor;
|
|
53
|
+
const [ky, kx] = positionMatrix[areaAnchor];
|
|
54
|
+
return `translate(${kx * (-100)}%, ${ky * (-100)}%)`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
type CompoundSettings = {
|
|
59
|
+
positionAnchor: AreaAnchor;
|
|
60
|
+
widthMode: DimensionMode;
|
|
61
|
+
heightMode: DimensionMode;
|
|
62
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ArticleItemType, ItemAny } from '@cntrl-site/sdk';
|
|
2
|
+
import { Item as TItem } from '@cntrl-site/sdk/src/types/article/Item';
|
|
3
|
+
|
|
4
|
+
export function isItemType<T extends ArticleItemType>(item: ItemAny, itemType: T): item is TItem<T> {
|
|
5
|
+
return item.type === itemType;
|
|
6
|
+
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import antfu from '@antfu/eslint-config';
|
|
2
|
-
|
|
3
|
-
export default antfu(
|
|
4
|
-
{
|
|
5
|
-
ignores: [],
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
rules: {
|
|
9
|
-
'import/order': 'off',
|
|
10
|
-
'style/semi': 'off',
|
|
11
|
-
'antfu/if-newline': 'off',
|
|
12
|
-
'style/comma-dangle': 'off',
|
|
13
|
-
'style/member-delimiter-style': 'off',
|
|
14
|
-
'semi': ['error', 'always'],
|
|
15
|
-
'no-alert': 'off',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
);
|
|
File without changes
|
|
File without changes
|