@cntrl-site/sdk-nextjs 1.1.5 → 1.2.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/.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.0.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 +95 -0
- package/lib/components/items/CompoundItem/CompoundItem.js +52 -0
- package/lib/components/items/CompoundItem/useCompoundItem.js +17 -0
- package/lib/components/items/{CustomItem.js → CustomItem/CustomItem.js} +2 -2
- package/lib/components/items/{VimeoEmbed.js → EmbedVideoItem/VimeoEmbed.js} +4 -4
- package/lib/components/items/{YoutubeEmbed.js → EmbedVideoItem/YoutubeEmbed.js} +5 -5
- package/lib/components/items/{useEmbedVideoItem.js → EmbedVideoItem/useEmbedVideoItem.js} +2 -2
- package/lib/components/items/{ImageItem.js → FileItem/ImageItem.js} +6 -6
- package/lib/components/items/{VideoItem.js → FileItem/VideoItem.js} +5 -5
- package/lib/components/items/{useFileItem.js → FileItem/useFileItem.js} +2 -2
- package/lib/components/items/{GroupItem.js → GroupItem/GroupItem.js} +5 -5
- package/lib/components/items/{useGroupItem.js → GroupItem/useGroupItem.js} +2 -2
- package/lib/components/{Item.js → items/Item.js} +39 -85
- 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/items/useItemArea.js +22 -0
- package/lib/components/items/useItemPointerEvents.js +14 -0
- package/lib/components/{useItemScale.js → items/useItemScale.js} +2 -2
- package/lib/components/items/useItemTriggers.js +17 -0
- package/lib/components/items/useSizing.js +23 -0
- 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 +2 -2
- 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 +130 -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} +5 -5
- package/src/components/items/{YoutubeEmbed.tsx → EmbedVideoItem/YoutubeEmbed.tsx} +6 -6
- package/src/components/items/{useEmbedVideoItem.ts → EmbedVideoItem/useEmbedVideoItem.ts} +2 -2
- package/src/components/items/{ImageItem.tsx → FileItem/ImageItem.tsx} +6 -6
- package/src/components/items/{VideoItem.tsx → FileItem/VideoItem.tsx} +5 -5
- package/src/components/items/{useFileItem.ts → FileItem/useFileItem.ts} +2 -2
- package/src/components/items/{GroupItem.tsx → GroupItem/GroupItem.tsx} +4 -5
- package/src/components/items/{useGroupItem.ts → GroupItem/useGroupItem.ts} +2 -2
- package/src/components/{Item.tsx → items/Item.tsx} +36 -105
- 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/items/useItemArea.ts +35 -0
- package/src/components/items/useItemPointerEvents.ts +10 -0
- package/src/components/{useItemScale.ts → items/useItemScale.ts} +2 -2
- package/src/components/items/useItemTriggers.ts +15 -0
- package/src/components/items/useSizing.ts +25 -0
- 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/lib/components/useItemDimensions.js +0 -12
- package/lib/components/useItemPosition.js +0 -30
- package/src/components/useItemDimensions.ts +0 -16
- package/src/components/useItemPosition.ts +0 -37
- /package/lib/components/{LinkWrapper.js → items/LinkWrapper.js} +0 -0
- /package/src/components/{LinkWrapper.tsx → items/LinkWrapper.tsx} +0 -0
|
@@ -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(
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ItemAny, KeyframeType } from '@cntrl-site/sdk';
|
|
2
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
3
|
+
import { useKeyframeValue } from '../../common/useKeyframeValue';
|
|
4
|
+
|
|
5
|
+
export function useItemArea(
|
|
6
|
+
item: ItemAny,
|
|
7
|
+
sectionId: string,
|
|
8
|
+
stateValues: { top?: number; left?: number; width?: number; height?: number }
|
|
9
|
+
) {
|
|
10
|
+
const layoutId = useLayoutContext();
|
|
11
|
+
const position = useKeyframeValue<{ top: number; left: number } | undefined>(
|
|
12
|
+
item,
|
|
13
|
+
KeyframeType.Position,
|
|
14
|
+
(item, layoutId) => {
|
|
15
|
+
if (!layoutId) return;
|
|
16
|
+
return item.area[layoutId]
|
|
17
|
+
},
|
|
18
|
+
(animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined,
|
|
19
|
+
sectionId,
|
|
20
|
+
[layoutId]
|
|
21
|
+
);
|
|
22
|
+
const dimensions = useKeyframeValue<{ width: number; height: number } | undefined>(
|
|
23
|
+
item,
|
|
24
|
+
KeyframeType.Dimensions,
|
|
25
|
+
(item, layoutId) => layoutId ? item.area[layoutId] : undefined,
|
|
26
|
+
(animator, scroll, value) => value ? animator.getDimensions(value, scroll) : undefined,
|
|
27
|
+
sectionId,
|
|
28
|
+
[layoutId]
|
|
29
|
+
);
|
|
30
|
+
const width = (stateValues.width ?? dimensions?.width) as number | undefined;
|
|
31
|
+
const height = (stateValues.height ?? dimensions?.height) as number | undefined;
|
|
32
|
+
const top = (stateValues.top ?? position?.top) as number | undefined;
|
|
33
|
+
const left = (stateValues.left ?? position?.left) as number | undefined;
|
|
34
|
+
return { width, height, top, left };
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useItemPointerEvents(isParentVisible: boolean) {
|
|
4
|
+
const [allowPointerEvents, setAllowPointerEvents] = useState<boolean>(isParentVisible);
|
|
5
|
+
const handleVisibilityChange = useCallback((isVisible: boolean) => {
|
|
6
|
+
if (!isParentVisible) return;
|
|
7
|
+
setAllowPointerEvents(isVisible);
|
|
8
|
+
}, [isParentVisible]);
|
|
9
|
+
return { allowPointerEvents, handleVisibilityChange };
|
|
10
|
+
}
|
|
@@ -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();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ItemInteractionCtrl } from '../../interactions/types';
|
|
2
|
+
|
|
3
|
+
export function useItemTriggers(interactionCtrl: ItemInteractionCtrl | undefined) {
|
|
4
|
+
return {
|
|
5
|
+
onClick: () => {
|
|
6
|
+
interactionCtrl?.sendTrigger('click');
|
|
7
|
+
},
|
|
8
|
+
onMouseEnter: () => {
|
|
9
|
+
interactionCtrl?.sendTrigger('hover-in');
|
|
10
|
+
},
|
|
11
|
+
onMouseLeave: () => {
|
|
12
|
+
interactionCtrl?.sendTrigger('hover-out');
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isItemType } from '../../utils/isItemType';
|
|
2
|
+
import { ArticleItemType, ItemAny } from '@cntrl-site/sdk';
|
|
3
|
+
import { useLayoutContext } from '../useLayoutContext';
|
|
4
|
+
|
|
5
|
+
export function useSizing(item: ItemAny) {
|
|
6
|
+
const layout = useLayoutContext();
|
|
7
|
+
const sizing = layout && isItemType(item, ArticleItemType.RichText)
|
|
8
|
+
? item.layoutParams[layout].sizing
|
|
9
|
+
: undefined;
|
|
10
|
+
const sizingAxis = parseSizing(sizing);
|
|
11
|
+
return sizingAxis;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseSizing(sizing: string = 'manual'): Axis {
|
|
15
|
+
const axisSizing = sizing.split(' ');
|
|
16
|
+
return {
|
|
17
|
+
y: axisSizing[0],
|
|
18
|
+
x: axisSizing[1] ? axisSizing[1] : axisSizing[0]
|
|
19
|
+
} as Axis;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface Axis {
|
|
23
|
+
x: 'manual' | 'auto';
|
|
24
|
+
y: 'manual' | 'auto';
|
|
25
|
+
}
|
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
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useItemDimensions = void 0;
|
|
4
|
-
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
6
|
-
const useLayoutContext_1 = require("./useLayoutContext");
|
|
7
|
-
const useItemDimensions = (item, sectionId) => {
|
|
8
|
-
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
9
|
-
const dimensions = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Dimensions, (item, layoutId) => layoutId ? item.area[layoutId] : undefined, (animator, scroll, value) => value ? animator.getDimensions(value, scroll) : undefined, sectionId, [layoutId]);
|
|
10
|
-
return dimensions;
|
|
11
|
-
};
|
|
12
|
-
exports.useItemDimensions = useItemDimensions;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useItemPosition = void 0;
|
|
4
|
-
const sdk_1 = require("@cntrl-site/sdk");
|
|
5
|
-
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
6
|
-
const getItemTopStyle_1 = require("../utils/getItemTopStyle");
|
|
7
|
-
const useLayoutContext_1 = require("./useLayoutContext");
|
|
8
|
-
const useItemPosition = (item, sectionId, stateValues) => {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
const layoutId = (0, useLayoutContext_1.useLayoutContext)();
|
|
11
|
-
const position = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Position, (item, layoutId) => {
|
|
12
|
-
if (!layoutId)
|
|
13
|
-
return;
|
|
14
|
-
return item.area[layoutId];
|
|
15
|
-
}, (animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined, sectionId, [layoutId]);
|
|
16
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : sdk_1.AnchorSide.Top;
|
|
17
|
-
const positionType = layoutId ? item.area[layoutId].positionType : sdk_1.PositionType.ScreenBased;
|
|
18
|
-
// to prevent fixed item (with anchor point bottom) to jump when scroll in safari on mobile
|
|
19
|
-
const isScreenBasedBottom = positionType === sdk_1.PositionType.ScreenBased && anchorSide === sdk_1.AnchorSide.Bottom;
|
|
20
|
-
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;
|
|
24
|
-
return position ? {
|
|
25
|
-
bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset',
|
|
26
|
-
top: isScreenBasedBottom ? 'unset' : (0, getItemTopStyle_1.getItemTopStyle)(top, anchorSide),
|
|
27
|
-
left: `${left * 100}vw`
|
|
28
|
-
} : undefined;
|
|
29
|
-
};
|
|
30
|
-
exports.useItemPosition = useItemPosition;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ItemAny, KeyframeType } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
|
-
import { useLayoutContext } from './useLayoutContext';
|
|
4
|
-
|
|
5
|
-
export const useItemDimensions = (item: ItemAny, sectionId: string) => {
|
|
6
|
-
const layoutId = useLayoutContext();
|
|
7
|
-
const dimensions = useKeyframeValue<{ width: number; height: number } | undefined>(
|
|
8
|
-
item,
|
|
9
|
-
KeyframeType.Dimensions,
|
|
10
|
-
(item, layoutId) => layoutId ? item.area[layoutId] : undefined,
|
|
11
|
-
(animator, scroll, value) => value ? animator.getDimensions(value, scroll) : undefined,
|
|
12
|
-
sectionId,
|
|
13
|
-
[layoutId]
|
|
14
|
-
);
|
|
15
|
-
return dimensions;
|
|
16
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { AnchorSide, ItemAny, KeyframeType, PositionType } from '@cntrl-site/sdk';
|
|
2
|
-
import { useKeyframeValue } from '../common/useKeyframeValue';
|
|
3
|
-
import { getItemTopStyle } from '../utils/getItemTopStyle';
|
|
4
|
-
import { useLayoutContext } from './useLayoutContext';
|
|
5
|
-
|
|
6
|
-
export const useItemPosition = (
|
|
7
|
-
item: ItemAny,
|
|
8
|
-
sectionId: string,
|
|
9
|
-
stateValues: { top?: number; left?: number; }
|
|
10
|
-
) => {
|
|
11
|
-
const layoutId = useLayoutContext();
|
|
12
|
-
const position = useKeyframeValue<{ top: number; left: number } | undefined>(
|
|
13
|
-
item,
|
|
14
|
-
KeyframeType.Position,
|
|
15
|
-
(item, layoutId) => {
|
|
16
|
-
if (!layoutId) return;
|
|
17
|
-
return item.area[layoutId]
|
|
18
|
-
},
|
|
19
|
-
(animator, scroll, value) => value ? animator.getPositions(value, scroll) : undefined,
|
|
20
|
-
sectionId,
|
|
21
|
-
[layoutId]
|
|
22
|
-
);
|
|
23
|
-
const anchorSide = layoutId ? item.area[layoutId].anchorSide : AnchorSide.Top;
|
|
24
|
-
const positionType = layoutId ? item.area[layoutId].positionType : PositionType.ScreenBased;
|
|
25
|
-
// 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
|
-
if (!position) return undefined;
|
|
28
|
-
const top = stateValues?.top ?? position.top;
|
|
29
|
-
const left = stateValues?.left ?? position.left;
|
|
30
|
-
return position ? {
|
|
31
|
-
bottom: isScreenBasedBottom ? `${-top * 100}vw` : 'unset',
|
|
32
|
-
top: isScreenBasedBottom ? 'unset' : getItemTopStyle(top, anchorSide),
|
|
33
|
-
left: `${left * 100}vw`
|
|
34
|
-
} : undefined;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
|
|
File without changes
|
|
File without changes
|