@cntrl-site/sdk-nextjs 0.11.0 → 0.12.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/inspectionProfiles/Project_Default.xml +4 -9
- package/.idea/workspace.xml +427 -0
- package/cntrl-site-sdk-nextjs-0.11.0.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.12.0.tgz +0 -0
- package/lib/common/useKeyframeValue.js +10 -10
- package/lib/components/Article.js +1 -1
- package/lib/components/Item.js +6 -15
- package/lib/components/Section.js +4 -1
- package/lib/components/items/ImageItem.js +3 -3
- package/lib/components/items/RectangleItem.js +3 -3
- package/lib/components/items/RichTextItem.js +2 -2
- package/lib/components/items/VideoItem.js +3 -3
- package/lib/components/items/VimeoEmbed.js +3 -3
- package/lib/components/items/YoutubeEmbed.js +3 -3
- package/lib/components/items/useEmbedVideoItem.js +2 -2
- package/lib/components/items/useFileItem.js +5 -5
- package/lib/components/items/useItemSticky.js +5 -5
- package/lib/components/items/useRectangleItem.js +5 -5
- package/lib/components/useItemAngle.js +2 -2
- package/lib/components/useItemDimensions.js +2 -2
- package/lib/components/useItemPosition.js +2 -2
- package/lib/components/useItemScale.js +2 -2
- package/lib/index.js +5 -4
- package/lib/provider/CntrlSdkContext.js +15 -0
- package/lib/utils/ArticleRectManager/ArticleRectObserver.js +36 -18
- package/lib/utils/ArticleRectManager/useArticleRectObserver.js +1 -1
- package/lib/utils/ArticleRectManager/useSectionRegistry.js +14 -0
- package/lib/utils/StickyManager/StickyManager.js +2 -2
- package/package.json +2 -2
- package/src/common/useKeyframeValue.ts +10 -9
- package/src/components/Article.tsx +1 -1
- package/src/components/Item.tsx +8 -17
- package/src/components/Section.tsx +5 -1
- package/src/components/items/ImageItem.tsx +3 -3
- package/src/components/items/RectangleItem.tsx +3 -3
- package/src/components/items/RichTextItem.tsx +2 -2
- package/src/components/items/VideoItem.tsx +3 -3
- package/src/components/items/VimeoEmbed.tsx +3 -3
- package/src/components/items/YoutubeEmbed.tsx +3 -3
- package/src/components/items/useEmbedVideoItem.ts +2 -1
- package/src/components/items/useFileItem.ts +7 -3
- package/src/components/items/useItemSticky.ts +5 -6
- package/src/components/items/useRectangleItem.ts +6 -2
- package/src/components/useItemAngle.ts +3 -2
- package/src/components/useItemDimensions.ts +2 -1
- package/src/components/useItemPosition.ts +2 -1
- package/src/components/useItemScale.ts +3 -2
- package/src/index.ts +4 -3
- package/src/provider/CntrlSdkContext.ts +19 -1
- package/src/utils/ArticleRectManager/ArticleRectObserver.ts +32 -15
- package/src/utils/ArticleRectManager/useArticleRectObserver.ts +1 -1
- package/src/utils/ArticleRectManager/useSectionRegistry.ts +11 -0
- package/src/utils/StickyManager/StickyManager.ts +2 -2
- package/cntrl-site-sdk-nextjs-0.10.2.tgz +0 -0
- package/lib/utils/castObject.js +0 -10
|
@@ -11,10 +11,10 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
11
11
|
const LinkWrapper_1 = require("../LinkWrapper");
|
|
12
12
|
const useFileItem_1 = require("./useFileItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
-
const VideoItem = ({ item }) => {
|
|
14
|
+
const VideoItem = ({ item, sectionId }) => {
|
|
15
15
|
const id = (0, react_1.useId)();
|
|
16
|
-
const { radius, strokeWidth, strokeColor, opacity } = (0, useFileItem_1.useFileItem)(item);
|
|
17
|
-
const angle = (0, useItemAngle_1.useItemAngle)(item);
|
|
16
|
+
const { radius, strokeWidth, strokeColor, opacity } = (0, useFileItem_1.useFileItem)(item, sectionId);
|
|
17
|
+
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
18
18
|
const borderColor = (0, react_1.useMemo)(() => sdk_1.CntrlColor.parse(strokeColor).toCss(), [strokeColor]);
|
|
19
19
|
return ((0, jsx_runtime_1.jsxs)(LinkWrapper_1.LinkWrapper, { url: item.link?.url, children: [(0, jsx_runtime_1.jsx)("div", { className: `video-wrapper-${item.id}`, style: {
|
|
20
20
|
borderRadius: `${radius * 100}vw`,
|
|
@@ -10,10 +10,10 @@ const style_1 = __importDefault(require("styled-jsx/style"));
|
|
|
10
10
|
const LinkWrapper_1 = require("../LinkWrapper");
|
|
11
11
|
const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
12
12
|
const useItemAngle_1 = require("../useItemAngle");
|
|
13
|
-
const VimeoEmbedItem = ({ item }) => {
|
|
13
|
+
const VimeoEmbedItem = ({ item, sectionId }) => {
|
|
14
14
|
const id = (0, react_1.useId)();
|
|
15
|
-
const { radius } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item);
|
|
16
|
-
const angle = (0, useItemAngle_1.useItemAngle)(item);
|
|
15
|
+
const { radius } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
16
|
+
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
17
17
|
const { autoplay, controls, loop, muted, pictureInPicture, url } = item.commonParams;
|
|
18
18
|
const getValidVimeoUrl = (url) => {
|
|
19
19
|
const validURL = new URL(url);
|
|
@@ -11,11 +11,11 @@ const LinkWrapper_1 = require("../LinkWrapper");
|
|
|
11
11
|
const getValidYoutubeUrl_1 = require("../../utils/getValidYoutubeUrl");
|
|
12
12
|
const useEmbedVideoItem_1 = require("./useEmbedVideoItem");
|
|
13
13
|
const useItemAngle_1 = require("../useItemAngle");
|
|
14
|
-
const YoutubeEmbedItem = ({ item }) => {
|
|
14
|
+
const YoutubeEmbedItem = ({ item, sectionId }) => {
|
|
15
15
|
const id = (0, react_1.useId)();
|
|
16
16
|
const { autoplay, controls, url } = item.commonParams;
|
|
17
|
-
const { radius } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item);
|
|
18
|
-
const angle = (0, useItemAngle_1.useItemAngle)(item);
|
|
17
|
+
const { radius } = (0, useEmbedVideoItem_1.useEmbedVideoItem)(item, sectionId);
|
|
18
|
+
const angle = (0, useItemAngle_1.useItemAngle)(item, sectionId);
|
|
19
19
|
const getValidYoutubeUrl = (url) => {
|
|
20
20
|
const newUrl = new URL(url);
|
|
21
21
|
const id = (0, getValidYoutubeUrl_1.getYoutubeId)(newUrl);
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useEmbedVideoItem = void 0;
|
|
4
4
|
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
5
5
|
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
6
|
-
const useEmbedVideoItem = (item) => {
|
|
6
|
+
const useEmbedVideoItem = (item, sectionId) => {
|
|
7
7
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
8
8
|
const radius = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
9
9
|
if (!layoutId)
|
|
10
10
|
return 0;
|
|
11
11
|
const layoutParams = item.layoutParams[layoutId];
|
|
12
12
|
return 'radius' in layoutParams ? layoutParams.radius : 0;
|
|
13
|
-
}, (animator, scroll, value) => animator.getRadius({ radius: value }, scroll).radius, [layoutId]);
|
|
13
|
+
}, (animator, scroll, value) => animator.getRadius({ radius: value }, scroll).radius, sectionId, [layoutId]);
|
|
14
14
|
return { radius };
|
|
15
15
|
};
|
|
16
16
|
exports.useEmbedVideoItem = useEmbedVideoItem;
|
|
@@ -4,32 +4,32 @@ exports.useFileItem = void 0;
|
|
|
4
4
|
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
5
5
|
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
6
6
|
const defaultColor = 'rgba(0, 0, 0, 1)';
|
|
7
|
-
const useFileItem = (item) => {
|
|
7
|
+
const useFileItem = (item, sectionId) => {
|
|
8
8
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
9
9
|
const radius = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
10
10
|
if (!layoutId)
|
|
11
11
|
return 0;
|
|
12
12
|
const layoutParams = item.layoutParams[layoutId];
|
|
13
13
|
return 'radius' in layoutParams ? layoutParams.radius : 0;
|
|
14
|
-
}, (animator, scroll, value) => animator.getRadius({ radius: value }, scroll).radius, [layoutId]);
|
|
14
|
+
}, (animator, scroll, value) => animator.getRadius({ radius: value }, scroll).radius, sectionId, [layoutId]);
|
|
15
15
|
const strokeWidth = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
16
16
|
if (!layoutId)
|
|
17
17
|
return 0;
|
|
18
18
|
const layoutParams = item.layoutParams[layoutId];
|
|
19
19
|
return 'strokeWidth' in layoutParams ? layoutParams.strokeWidth : 0;
|
|
20
|
-
}, (animator, scroll, value) => animator.getBorderWidth({ borderWidth: value }, scroll).borderWidth, [layoutId]);
|
|
20
|
+
}, (animator, scroll, value) => animator.getBorderWidth({ borderWidth: value }, scroll).borderWidth, sectionId, [layoutId]);
|
|
21
21
|
const opacity = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
22
22
|
if (!layoutId)
|
|
23
23
|
return 0;
|
|
24
24
|
const layoutParams = item.layoutParams[layoutId];
|
|
25
25
|
return 'opacity' in layoutParams ? layoutParams.opacity : 0;
|
|
26
|
-
}, (animator, scroll, value) => animator.getOpacity({ opacity: value }, scroll).opacity, [layoutId]);
|
|
26
|
+
}, (animator, scroll, value) => animator.getOpacity({ opacity: value }, scroll).opacity, sectionId, [layoutId]);
|
|
27
27
|
const strokeColor = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
28
28
|
if (!layoutId)
|
|
29
29
|
return defaultColor;
|
|
30
30
|
const layoutParams = item.layoutParams[layoutId];
|
|
31
31
|
return 'strokeColor' in layoutParams ? layoutParams.strokeColor : defaultColor;
|
|
32
|
-
}, (animator, scroll, value) => animator.getBorderColor({ color: value }, scroll).color);
|
|
32
|
+
}, (animator, scroll, value) => animator.getBorderColor({ color: value }, scroll).color, sectionId);
|
|
33
33
|
return { radius, strokeWidth, opacity, strokeColor };
|
|
34
34
|
};
|
|
35
35
|
exports.useFileItem = useFileItem;
|
|
@@ -6,7 +6,7 @@ const sdk_1 = require("@cntrl-site/sdk");
|
|
|
6
6
|
const StickyManager_1 = require("../../utils/StickyManager/StickyManager");
|
|
7
7
|
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
8
8
|
const ArticleRectContext_1 = require("../../provider/ArticleRectContext");
|
|
9
|
-
const useItemSticky = (top,
|
|
9
|
+
const useItemSticky = (top, item, sectionId) => {
|
|
10
10
|
const [isFixed, setIsFixed] = (0, react_1.useState)(false);
|
|
11
11
|
const [adjustedTop, setAdjustedTop] = (0, react_1.useState)(top);
|
|
12
12
|
const articleRectObserver = (0, react_1.useContext)(ArticleRectContext_1.ArticleRectContext);
|
|
@@ -15,18 +15,18 @@ const useItemSticky = (top, parentOffsetTop, item) => {
|
|
|
15
15
|
const stickyManager = (0, react_1.useMemo)(() => new StickyManager_1.StickyManager(sticky), [sticky]);
|
|
16
16
|
const handleSticky = (0, react_1.useCallback)((scroll) => {
|
|
17
17
|
setIsFixed(stickyManager.getIsSticky(scroll));
|
|
18
|
-
setAdjustedTop(stickyManager.getPosition(scroll, top
|
|
19
|
-
}, [top, stickyManager
|
|
18
|
+
setAdjustedTop(stickyManager.getPosition(scroll, top));
|
|
19
|
+
}, [top, stickyManager]);
|
|
20
20
|
(0, react_1.useEffect)(() => {
|
|
21
21
|
if (!articleRectObserver)
|
|
22
22
|
return;
|
|
23
|
-
handleSticky(articleRectObserver.
|
|
23
|
+
handleSticky(articleRectObserver.getSectionScroll(sectionId));
|
|
24
24
|
}, [handleSticky, articleRectObserver]);
|
|
25
25
|
(0, react_1.useEffect)(() => {
|
|
26
26
|
if (!articleRectObserver || !sticky)
|
|
27
27
|
return;
|
|
28
28
|
return articleRectObserver.on('scroll', () => {
|
|
29
|
-
handleSticky(articleRectObserver.
|
|
29
|
+
handleSticky(articleRectObserver.getSectionScroll(sectionId));
|
|
30
30
|
});
|
|
31
31
|
}, [handleSticky, articleRectObserver, sticky]);
|
|
32
32
|
return {
|
|
@@ -4,32 +4,32 @@ exports.useRectangleItem = void 0;
|
|
|
4
4
|
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
|
|
5
5
|
const useCurrentLayout_1 = require("../../common/useCurrentLayout");
|
|
6
6
|
const defaultColor = 'rgba(0, 0, 0, 1)';
|
|
7
|
-
const useRectangleItem = (item) => {
|
|
7
|
+
const useRectangleItem = (item, sectionId) => {
|
|
8
8
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
9
9
|
const radius = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
10
10
|
if (!layoutId)
|
|
11
11
|
return 0;
|
|
12
12
|
const layoutParams = item.layoutParams[layoutId];
|
|
13
13
|
return 'radius' in layoutParams ? layoutParams.radius : 0;
|
|
14
|
-
}, (animator, scroll, value) => animator.getRadius({ radius: value }, scroll).radius, [layoutId]);
|
|
14
|
+
}, (animator, scroll, value) => animator.getRadius({ radius: value }, scroll).radius, sectionId, [layoutId]);
|
|
15
15
|
const strokeWidth = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
16
16
|
if (!layoutId)
|
|
17
17
|
return 0;
|
|
18
18
|
const layoutParams = item.layoutParams[layoutId];
|
|
19
19
|
return 'strokeWidth' in layoutParams ? layoutParams.strokeWidth : 0;
|
|
20
|
-
}, (animator, scroll, value) => animator.getBorderWidth({ borderWidth: value }, scroll).borderWidth, [layoutId]);
|
|
20
|
+
}, (animator, scroll, value) => animator.getBorderWidth({ borderWidth: value }, scroll).borderWidth, sectionId, [layoutId]);
|
|
21
21
|
const fillColor = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
22
22
|
if (!layoutId)
|
|
23
23
|
return defaultColor;
|
|
24
24
|
const layoutParams = item.layoutParams[layoutId];
|
|
25
25
|
return 'fillColor' in layoutParams ? layoutParams.fillColor : defaultColor;
|
|
26
|
-
}, (animator, scroll, value) => animator.getColor({ color: value }, scroll).color, [layoutId]);
|
|
26
|
+
}, (animator, scroll, value) => animator.getColor({ color: value }, scroll).color, sectionId, [layoutId]);
|
|
27
27
|
const strokeColor = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => {
|
|
28
28
|
if (!layoutId)
|
|
29
29
|
return defaultColor;
|
|
30
30
|
const layoutParams = item.layoutParams[layoutId];
|
|
31
31
|
return 'strokeColor' in layoutParams ? layoutParams.strokeColor : defaultColor;
|
|
32
|
-
}, (animator, scroll, value) => animator.getBorderColor({ color: value }, scroll).color, [layoutId]);
|
|
32
|
+
}, (animator, scroll, value) => animator.getBorderColor({ color: value }, scroll).color, sectionId, [layoutId]);
|
|
33
33
|
return { fillColor, strokeWidth, radius, strokeColor };
|
|
34
34
|
};
|
|
35
35
|
exports.useRectangleItem = useRectangleItem;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useItemAngle = void 0;
|
|
4
4
|
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
5
|
-
const useItemAngle = (item) => {
|
|
6
|
-
const { angle } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => ({ angle: layoutId ? item.area[layoutId].angle : 0 }), (animator, scroll, value) => animator.getRotation(value, scroll));
|
|
5
|
+
const useItemAngle = (item, sectionId) => {
|
|
6
|
+
const { angle } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => ({ angle: layoutId ? item.area[layoutId].angle : 0 }), (animator, scroll, value) => animator.getRotation(value, scroll), sectionId);
|
|
7
7
|
return angle;
|
|
8
8
|
};
|
|
9
9
|
exports.useItemAngle = useItemAngle;
|
|
@@ -11,9 +11,9 @@ const defaultArea = {
|
|
|
11
11
|
angle: 0,
|
|
12
12
|
zIndex: 0
|
|
13
13
|
};
|
|
14
|
-
const useItemDimensions = (item) => {
|
|
14
|
+
const useItemDimensions = (item, sectionId) => {
|
|
15
15
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
16
|
-
const { width, height } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => layoutId ? item.area[layoutId] : defaultArea, (animator, scroll, value) => animator.getDimensions(value, scroll), [layoutId]);
|
|
16
|
+
const { width, height } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => layoutId ? item.area[layoutId] : defaultArea, (animator, scroll, value) => animator.getDimensions(value, scroll), sectionId, [layoutId]);
|
|
17
17
|
return { width, height };
|
|
18
18
|
};
|
|
19
19
|
exports.useItemDimensions = useItemDimensions;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useItemPosition = void 0;
|
|
4
4
|
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
5
5
|
const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
6
|
-
const useItemPosition = (item) => {
|
|
6
|
+
const useItemPosition = (item, sectionId) => {
|
|
7
7
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
8
|
-
const { top, left } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => item.area[layoutId], (animator, scroll, value) => animator.getPositions(value, scroll), [layoutId]);
|
|
8
|
+
const { top, left } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => item.area[layoutId], (animator, scroll, value) => animator.getPositions(value, scroll), sectionId, [layoutId]);
|
|
9
9
|
return { top, left };
|
|
10
10
|
};
|
|
11
11
|
exports.useItemPosition = useItemPosition;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useItemScale = void 0;
|
|
4
4
|
const useKeyframeValue_1 = require("../common/useKeyframeValue");
|
|
5
5
|
const useCurrentLayout_1 = require("../common/useCurrentLayout");
|
|
6
|
-
const useItemScale = (item) => {
|
|
6
|
+
const useItemScale = (item, sectionId) => {
|
|
7
7
|
const layout = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
8
|
-
const { scale } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => ({ scale: layoutId ? item.area[layoutId].scale : 1 }), (animator, scroll, value) => animator.getScale(value, scroll));
|
|
8
|
+
const { scale } = (0, useKeyframeValue_1.useKeyframeValue)(item, (item, layoutId) => ({ scale: layoutId ? item.area[layoutId].scale : 1 }), (animator, scroll, value) => animator.getScale(value, scroll), sectionId);
|
|
9
9
|
const scaleAnchor = item.area[layout].scaleAnchor;
|
|
10
10
|
return { scale, scaleAnchor };
|
|
11
11
|
};
|
package/lib/index.js
CHANGED
|
@@ -14,9 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useCntrlContext = exports.CntrlProvider = exports.YoutubeEmbedItem = exports.VimeoEmbedItem = exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Head = exports.Page = exports.RichTextConverter =
|
|
18
|
-
var defaultContext_1 = require("./provider/defaultContext");
|
|
19
|
-
Object.defineProperty(exports, "cntrlSdkContext", { enumerable: true, get: function () { return defaultContext_1.cntrlSdkContext; } });
|
|
17
|
+
exports.cntrlSdkContext = exports.customSections = exports.customItems = exports.useCntrlContext = exports.CntrlProvider = exports.YoutubeEmbedItem = exports.VimeoEmbedItem = exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Head = exports.Page = exports.RichTextConverter = void 0;
|
|
20
18
|
__exportStar(require("@cntrl-site/sdk"), exports);
|
|
21
19
|
var RichTextConverter_1 = require("./utils/RichTextConverter/RichTextConverter");
|
|
22
20
|
Object.defineProperty(exports, "RichTextConverter", { enumerable: true, get: function () { return RichTextConverter_1.RichTextConverter; } });
|
|
@@ -44,8 +42,11 @@ var VimeoEmbed_1 = require("./components/items/VimeoEmbed");
|
|
|
44
42
|
Object.defineProperty(exports, "VimeoEmbedItem", { enumerable: true, get: function () { return VimeoEmbed_1.VimeoEmbedItem; } });
|
|
45
43
|
var YoutubeEmbed_1 = require("./components/items/YoutubeEmbed");
|
|
46
44
|
Object.defineProperty(exports, "YoutubeEmbedItem", { enumerable: true, get: function () { return YoutubeEmbed_1.YoutubeEmbedItem; } });
|
|
47
|
-
|
|
45
|
+
const defaultContext_1 = require("./provider/defaultContext");
|
|
48
46
|
var CntrlProvider_1 = require("./provider/CntrlProvider");
|
|
49
47
|
Object.defineProperty(exports, "CntrlProvider", { enumerable: true, get: function () { return CntrlProvider_1.CntrlProvider; } });
|
|
50
48
|
var useCntrlContext_1 = require("./provider/useCntrlContext");
|
|
51
49
|
Object.defineProperty(exports, "useCntrlContext", { enumerable: true, get: function () { return useCntrlContext_1.useCntrlContext; } });
|
|
50
|
+
exports.customItems = defaultContext_1.cntrlSdkContext.customItems;
|
|
51
|
+
exports.customSections = defaultContext_1.cntrlSdkContext.customSections;
|
|
52
|
+
exports.cntrlSdkContext = defaultContext_1.cntrlSdkContext;
|
|
@@ -7,6 +7,18 @@ class CntrlSdkContext {
|
|
|
7
7
|
this.customSections = customSections;
|
|
8
8
|
this._layouts = [];
|
|
9
9
|
}
|
|
10
|
+
async resolveSectionData(sections) {
|
|
11
|
+
const resolvers = sections.map(section => {
|
|
12
|
+
const resolver = section.name ? this.customSections.getResolver(section.name) : undefined;
|
|
13
|
+
if (!resolver)
|
|
14
|
+
return;
|
|
15
|
+
return {
|
|
16
|
+
name: section.name,
|
|
17
|
+
resolver
|
|
18
|
+
};
|
|
19
|
+
}).filter(isDefined);
|
|
20
|
+
return Object.fromEntries(await Promise.all(resolvers.map(async ({ name, resolver }) => [name, await resolver()])));
|
|
21
|
+
}
|
|
10
22
|
setTypePresets(typePresets) {
|
|
11
23
|
this._typePresets = typePresets;
|
|
12
24
|
}
|
|
@@ -21,3 +33,6 @@ class CntrlSdkContext {
|
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
35
|
exports.CntrlSdkContext = CntrlSdkContext;
|
|
36
|
+
function isDefined(value) {
|
|
37
|
+
return value !== undefined;
|
|
38
|
+
}
|
|
@@ -6,35 +6,33 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
8
8
|
this.articleWidth = 0;
|
|
9
|
+
this.registry = new Map();
|
|
9
10
|
this.scrollPos = window.scrollY;
|
|
10
11
|
this.animationFrame = NaN;
|
|
12
|
+
this.parent = undefined;
|
|
13
|
+
this.sectionsScrollMap = new Map();
|
|
11
14
|
this.handleScroll = (scroll) => {
|
|
12
15
|
this.setScroll(scroll / this.articleWidth);
|
|
13
16
|
};
|
|
14
|
-
this.
|
|
15
|
-
const [entry] = entries;
|
|
16
|
-
if (!entry)
|
|
17
|
-
return;
|
|
18
|
-
const element = entry.target;
|
|
19
|
-
if (!(element instanceof HTMLElement))
|
|
20
|
-
return;
|
|
21
|
-
this.notify(element);
|
|
22
|
-
this.setScroll(window.scrollY / this.articleWidth);
|
|
23
|
-
this.emit('resize', undefined);
|
|
24
|
-
};
|
|
25
|
-
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
17
|
+
this.resizeObserver = new ResizeObserver(this.handleResize.bind(this));
|
|
26
18
|
}
|
|
27
19
|
get scroll() {
|
|
28
20
|
return this.scrollPos;
|
|
29
21
|
}
|
|
22
|
+
getSectionScroll(sectionId) {
|
|
23
|
+
const sectionTop = this.sectionsScrollMap.get(sectionId);
|
|
24
|
+
if (sectionTop === undefined)
|
|
25
|
+
return 0;
|
|
26
|
+
return -(sectionTop / this.articleWidth - this.scrollPos);
|
|
27
|
+
}
|
|
30
28
|
get width() {
|
|
31
29
|
return this.articleWidth;
|
|
32
30
|
}
|
|
33
31
|
setScroll(scroll) {
|
|
34
32
|
this.scrollPos = scroll;
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
this.
|
|
34
|
+
init(parent) {
|
|
35
|
+
this.parent = parent;
|
|
38
36
|
const onScroll = () => {
|
|
39
37
|
this.handleScroll(window.scrollY);
|
|
40
38
|
if (!isNaN(this.animationFrame))
|
|
@@ -46,7 +44,7 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
46
44
|
};
|
|
47
45
|
window.addEventListener('scroll', onScroll);
|
|
48
46
|
return () => {
|
|
49
|
-
this.
|
|
47
|
+
this.parent = undefined;
|
|
50
48
|
window.removeEventListener('scroll', onScroll);
|
|
51
49
|
if (!isNaN(this.animationFrame)) {
|
|
52
50
|
window.cancelAnimationFrame(this.animationFrame);
|
|
@@ -54,9 +52,29 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
54
52
|
}
|
|
55
53
|
};
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
55
|
+
register(el, sectionId) {
|
|
56
|
+
this.registry.set(sectionId, el);
|
|
57
|
+
this.resizeObserver.observe(el);
|
|
58
|
+
return () => {
|
|
59
|
+
this.registry.delete(sectionId);
|
|
60
|
+
this.resizeObserver.unobserve(el);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
handleResize() {
|
|
64
|
+
if (!this.parent)
|
|
65
|
+
return;
|
|
66
|
+
const parentBoundary = this.parent.getBoundingClientRect();
|
|
67
|
+
this.articleWidth = parentBoundary.width;
|
|
68
|
+
this.setScroll(window.scrollY / this.articleWidth);
|
|
69
|
+
this.emit('resize', undefined);
|
|
70
|
+
for (const sectionId of this.registry.keys()) {
|
|
71
|
+
const el = this.registry.get(sectionId);
|
|
72
|
+
if (!el)
|
|
73
|
+
continue;
|
|
74
|
+
const rect = el.getBoundingClientRect();
|
|
75
|
+
this.sectionsScrollMap.set(sectionId, rect.top - parentBoundary.top);
|
|
76
|
+
}
|
|
60
77
|
}
|
|
78
|
+
;
|
|
61
79
|
}
|
|
62
80
|
exports.ArticleRectObserver = ArticleRectObserver;
|
|
@@ -11,7 +11,7 @@ const useArticleRectObserver = (el) => {
|
|
|
11
11
|
(0, react_1.useEffect)(() => {
|
|
12
12
|
if (!el || !articleRectObserver)
|
|
13
13
|
return;
|
|
14
|
-
return articleRectObserver.
|
|
14
|
+
return articleRectObserver.init(el);
|
|
15
15
|
}, [el, articleRectObserver]);
|
|
16
16
|
return articleRectObserver;
|
|
17
17
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSectionRegistry = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ArticleRectContext_1 = require("../../provider/ArticleRectContext");
|
|
6
|
+
const useSectionRegistry = (sectionId, el) => {
|
|
7
|
+
const articleRectObserver = (0, react_1.useContext)(ArticleRectContext_1.ArticleRectContext);
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
if (!el || !articleRectObserver)
|
|
10
|
+
return;
|
|
11
|
+
return articleRectObserver.register(el, sectionId);
|
|
12
|
+
}, [el, articleRectObserver]);
|
|
13
|
+
};
|
|
14
|
+
exports.useSectionRegistry = useSectionRegistry;
|
|
@@ -10,11 +10,11 @@ class StickyManager {
|
|
|
10
10
|
return false;
|
|
11
11
|
return (this.sticky.from <= scroll) && (!this.sticky.to || this.sticky.to >= scroll);
|
|
12
12
|
}
|
|
13
|
-
getPosition(scroll, top
|
|
13
|
+
getPosition(scroll, top) {
|
|
14
14
|
if (!this.sticky)
|
|
15
15
|
return top;
|
|
16
16
|
if (this.getIsSticky(scroll)) {
|
|
17
|
-
return top - this.sticky.from
|
|
17
|
+
return top - this.sticky.from;
|
|
18
18
|
}
|
|
19
19
|
if (this.sticky.to !== undefined && this.sticky.to <= scroll) {
|
|
20
20
|
return top + this.sticky.to - this.sticky.from;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntrl-site/sdk-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "SDK for Next.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cntrl-site/sdk": "^1.1.
|
|
24
|
+
"@cntrl-site/sdk": "^1.1.1",
|
|
25
25
|
"html-react-parser": "^3.0.1",
|
|
26
26
|
"styled-jsx": "^5.0.2"
|
|
27
27
|
},
|
|
@@ -14,6 +14,7 @@ export const useKeyframeValue = <T>(
|
|
|
14
14
|
item: TArticleItemAny,
|
|
15
15
|
itemParamsGetter: ItemParamGetter<T>,
|
|
16
16
|
animatorGetter: AnimatorGetter<T>,
|
|
17
|
+
sectionId: string,
|
|
17
18
|
deps: DependencyList = emptyDeps
|
|
18
19
|
) => {
|
|
19
20
|
const animatorGetterRef = useRef(animatorGetter);
|
|
@@ -59,26 +60,26 @@ export const useKeyframeValue = <T>(
|
|
|
59
60
|
}, [paramValue]);
|
|
60
61
|
|
|
61
62
|
useEffect(() => {
|
|
62
|
-
if (!articleRectObserver) return;
|
|
63
|
-
const scroll = articleRectObserver.
|
|
63
|
+
if (!articleRectObserver || !animator) return;
|
|
64
|
+
const scroll = articleRectObserver.getSectionScroll(sectionId);
|
|
64
65
|
handleKeyframeValue(scroll);
|
|
65
|
-
}, [articleRectObserver, handleKeyframeValue])
|
|
66
|
+
}, [articleRectObserver, handleKeyframeValue, animator])
|
|
66
67
|
|
|
67
68
|
useEffect(() => {
|
|
68
|
-
if (!articleRectObserver) return;
|
|
69
|
+
if (!articleRectObserver || !animator) return;
|
|
69
70
|
return articleRectObserver.on('resize', () => {
|
|
70
|
-
const scroll = articleRectObserver.
|
|
71
|
+
const scroll = articleRectObserver.getSectionScroll(sectionId);
|
|
71
72
|
handleKeyframeValue(scroll);
|
|
72
73
|
});
|
|
73
|
-
}, [handleKeyframeValue, articleRectObserver]);
|
|
74
|
+
}, [handleKeyframeValue, articleRectObserver, animator]);
|
|
74
75
|
|
|
75
76
|
useEffect(() => {
|
|
76
|
-
if (!articleRectObserver) return;
|
|
77
|
+
if (!articleRectObserver || !animator) return;
|
|
77
78
|
return articleRectObserver.on('scroll', () => {
|
|
78
|
-
const scroll = articleRectObserver.
|
|
79
|
+
const scroll = articleRectObserver.getSectionScroll(sectionId);
|
|
79
80
|
handleKeyframeValue(scroll);
|
|
80
81
|
});
|
|
81
|
-
}, [handleKeyframeValue, articleRectObserver]);
|
|
82
|
+
}, [handleKeyframeValue, articleRectObserver, animator]);
|
|
82
83
|
return adjustedValue;
|
|
83
84
|
};
|
|
84
85
|
|
|
@@ -24,7 +24,7 @@ export const Article: FC<Props> = ({ article, sectionData }) => {
|
|
|
24
24
|
return (
|
|
25
25
|
<Section section={section} key={section.id} data={data}>
|
|
26
26
|
{article.sections[i].items.map(item => (
|
|
27
|
-
<Item item={item} key={item.id} />
|
|
27
|
+
<Item item={item} key={item.id} sectionId={section.id} />
|
|
28
28
|
))}
|
|
29
29
|
</Section>
|
|
30
30
|
);
|
package/src/components/Item.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType, FC, useEffect, useId, useRef
|
|
1
|
+
import { ComponentType, FC, useEffect, useId, useRef } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
3
|
import {
|
|
4
4
|
ArticleItemSizingType as SizingType,
|
|
@@ -18,13 +18,13 @@ import { useCntrlContext } from '../provider/useCntrlContext';
|
|
|
18
18
|
import { useItemPosition } from './useItemPosition';
|
|
19
19
|
import { useItemDimensions } from './useItemDimensions';
|
|
20
20
|
import { getItemTopStyle, useItemSticky } from './items/useItemSticky';
|
|
21
|
-
import { castObject } from '../utils/castObject';
|
|
22
21
|
import { useCurrentLayout } from '../common/useCurrentLayout';
|
|
23
22
|
import { useItemScale } from './useItemScale';
|
|
24
23
|
import { ScaleAnchorMap } from '../utils/ScaleAnchorMap';
|
|
25
24
|
|
|
26
25
|
export interface ItemProps<I extends TArticleItemAny> {
|
|
27
26
|
item: I;
|
|
27
|
+
sectionId: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
|
|
@@ -39,16 +39,14 @@ const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
|
|
|
39
39
|
|
|
40
40
|
const noop = () => null;
|
|
41
41
|
|
|
42
|
-
export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
42
|
+
export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, sectionId}) => {
|
|
43
43
|
const id = useId();
|
|
44
44
|
const { layouts } = useCntrlContext();
|
|
45
|
-
const { scale, scaleAnchor } = useItemScale(item);
|
|
46
|
-
const position = useItemPosition(item);
|
|
45
|
+
const { scale, scaleAnchor } = useItemScale(item, sectionId);
|
|
46
|
+
const position = useItemPosition(item, sectionId);
|
|
47
47
|
const layout = useCurrentLayout();
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const { top, isFixed } = useItemSticky(position.top, parentOffsetTop, item);
|
|
51
|
-
const { width, height } = useItemDimensions(item);
|
|
48
|
+
const { top, isFixed } = useItemSticky(position.top, item, sectionId);
|
|
49
|
+
const { width, height } = useItemDimensions(item, sectionId);
|
|
52
50
|
const layoutValues: Record<string, any>[] = [item.area];
|
|
53
51
|
const isInitialRef = useRef(true);
|
|
54
52
|
if (item.layoutParams) {
|
|
@@ -65,12 +63,6 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
|
65
63
|
isInitialRef.current = false;
|
|
66
64
|
}, []);
|
|
67
65
|
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (!ref) return;
|
|
70
|
-
const offsetParent = castObject(ref.offsetParent, HTMLElement);
|
|
71
|
-
setParentOffsetTop(offsetParent.offsetTop / window.innerWidth);
|
|
72
|
-
}, [ref]);
|
|
73
|
-
|
|
74
66
|
const styles = {
|
|
75
67
|
transform: `scale(${scale})`,
|
|
76
68
|
transformOrigin: ScaleAnchorMap[scaleAnchor],
|
|
@@ -84,10 +76,9 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item }) => {
|
|
|
84
76
|
<div
|
|
85
77
|
suppressHydrationWarning={true}
|
|
86
78
|
className={`item-${item.id}`}
|
|
87
|
-
ref={setRef}
|
|
88
79
|
style={isInitialRef.current ? {} : { ...styles, position: isFixed ? 'fixed': 'absolute' } }
|
|
89
80
|
>
|
|
90
|
-
<ItemComponent item={item} />
|
|
81
|
+
<ItemComponent item={item} sectionId={sectionId} />
|
|
91
82
|
<JSXStyle id={id}>{`
|
|
92
83
|
${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => {
|
|
93
84
|
const sizingAxis = parseSizing(layoutParams.sizing);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC, ReactElement, useId } from 'react';
|
|
1
|
+
import { FC, ReactElement, useId, useRef } from 'react';
|
|
2
2
|
import JSXStyle from 'styled-jsx/style';
|
|
3
3
|
import {
|
|
4
4
|
getLayoutMediaQuery,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '@cntrl-site/sdk';
|
|
10
10
|
import { useCntrlContext } from '../provider/useCntrlContext';
|
|
11
11
|
import { useSectionColor } from './useSectionColor';
|
|
12
|
+
import { useSectionRegistry } from '../utils/ArticleRectManager/useSectionRegistry';
|
|
12
13
|
|
|
13
14
|
type SectionChild = ReactElement<any, any>;
|
|
14
15
|
|
|
@@ -20,9 +21,11 @@ interface Props {
|
|
|
20
21
|
|
|
21
22
|
export const Section: FC<Props> = ({ section, data, children }) => {
|
|
22
23
|
const id = useId();
|
|
24
|
+
const sectionRef = useRef<HTMLDivElement | null>(null);
|
|
23
25
|
const { layouts, customSections } = useCntrlContext();
|
|
24
26
|
const backgroundColor = useSectionColor(section.color);
|
|
25
27
|
const SectionComponent = section.name ? customSections.getComponent(section.name) : undefined;
|
|
28
|
+
useSectionRegistry(section.id, sectionRef.current);
|
|
26
29
|
const getSectionVisibilityStyles = () => {
|
|
27
30
|
return layouts
|
|
28
31
|
.sort((a, b) => a.startsWith - b.startsWith)
|
|
@@ -48,6 +51,7 @@ export const Section: FC<Props> = ({ section, data, children }) => {
|
|
|
48
51
|
style={{
|
|
49
52
|
backgroundColor: backgroundColor
|
|
50
53
|
}}
|
|
54
|
+
ref={sectionRef}
|
|
51
55
|
>
|
|
52
56
|
{children}
|
|
53
57
|
</div>
|
|
@@ -6,10 +6,10 @@ import { LinkWrapper } from '../LinkWrapper';
|
|
|
6
6
|
import { useFileItem } from './useFileItem';
|
|
7
7
|
import { useItemAngle } from '../useItemAngle';
|
|
8
8
|
|
|
9
|
-
export const ImageItem: FC<ItemProps<TImageItem>> = ({ item }) => {
|
|
9
|
+
export const ImageItem: FC<ItemProps<TImageItem>> = ({ item, sectionId }) => {
|
|
10
10
|
const id = useId();
|
|
11
|
-
const { radius, strokeWidth, opacity, strokeColor } = useFileItem(item);
|
|
12
|
-
const angle = useItemAngle(item);
|
|
11
|
+
const { radius, strokeWidth, opacity, strokeColor } = useFileItem(item, sectionId);
|
|
12
|
+
const angle = useItemAngle(item, sectionId);
|
|
13
13
|
const borderColor = useMemo(() => CntrlColor.parse(strokeColor).toCss(), [strokeColor]);
|
|
14
14
|
return (
|
|
15
15
|
<LinkWrapper url={item.link?.url}>
|
|
@@ -6,10 +6,10 @@ import { LinkWrapper } from '../LinkWrapper';
|
|
|
6
6
|
import { useRectangleItem } from './useRectangleItem';
|
|
7
7
|
import { useItemAngle } from '../useItemAngle';
|
|
8
8
|
|
|
9
|
-
export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item }) => {
|
|
9
|
+
export const RectangleItem: FC<ItemProps<TRectangleItem>> = ({ item, sectionId }) => {
|
|
10
10
|
const id = useId();
|
|
11
|
-
const { fillColor, radius, strokeWidth, strokeColor } = useRectangleItem(item);
|
|
12
|
-
const angle = useItemAngle(item);
|
|
11
|
+
const { fillColor, radius, strokeWidth, strokeColor } = useRectangleItem(item, sectionId);
|
|
12
|
+
const angle = useItemAngle(item, sectionId);
|
|
13
13
|
const backgroundColor = useMemo(() => CntrlColor.parse(fillColor).toCss(), [fillColor]);
|
|
14
14
|
const borderColor = useMemo(() => CntrlColor.parse(strokeColor).toCss(), [strokeColor]);
|
|
15
15
|
|
|
@@ -5,9 +5,9 @@ import { ItemProps } from '../Item';
|
|
|
5
5
|
import { useRichTextItem } from './useRichTextItem';
|
|
6
6
|
import { useItemAngle } from '../useItemAngle';
|
|
7
7
|
|
|
8
|
-
export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item }) => {
|
|
8
|
+
export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item, sectionId }) => {
|
|
9
9
|
const [content, styles, preset] = useRichTextItem(item);
|
|
10
|
-
const angle = useItemAngle(item);
|
|
10
|
+
const angle = useItemAngle(item, sectionId);
|
|
11
11
|
const className = preset ? `cntrl-preset-${preset.id}` : undefined;
|
|
12
12
|
return (
|
|
13
13
|
<>
|