@cntrl-site/sdk-nextjs 1.9.136-alpha.0 → 1.9.136

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.
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -14,8 +14,7 @@ const ArticleWrapper_1 = require("./ArticleWrapper");
14
14
  const InteractionsContext_1 = require("../provider/InteractionsContext");
15
15
  const WebGLContextManagerContext_1 = require("../provider/WebGLContextManagerContext");
16
16
  const effects_1 = require("@cntrl-site/effects");
17
- const Navigation_1 = require("./Navigation/Navigation");
18
- const Article = ({ article, sectionData, navigation, pages = [] }) => {
17
+ const Article = ({ article, sectionData }) => {
19
18
  const articleRef = (0, react_1.useRef)(null);
20
19
  const articleRectObserver = (0, useArticleRectObserver_1.useArticleRectObserver)(articleRef.current);
21
20
  const id = (0, react_1.useId)();
@@ -29,10 +28,10 @@ const Article = ({ article, sectionData, navigation, pages = [] }) => {
29
28
  }, [articleRectObserver]);
30
29
  const webglContextManager = (0, react_1.useMemo)(() => new effects_1.WebGLContextManager(), []);
31
30
  const sectionsLength = article.sections.length;
32
- return ((0, jsx_runtime_1.jsx)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: (0, jsx_runtime_1.jsxs)(InteractionsContext_1.InteractionsProvider, { article: article, children: [(0, jsx_runtime_1.jsxs)(ArticleWrapper_1.ArticleWrapper, { children: [navigation && ((0, jsx_runtime_1.jsx)(Navigation_1.Navigation, { navigation: navigation, pages: pages, hidden: article.navigationHidden })), (0, jsx_runtime_1.jsxs)("div", { className: "article", ref: articleRef, children: [(0, jsx_runtime_1.jsx)(WebGLContextManagerContext_1.WebglContextManagerContext.Provider, { value: webglContextManager, children: article.sections.map((section, i) => {
33
- const data = section.name ? sectionData[section.name] : {};
34
- return ((0, jsx_runtime_1.jsx)(Section_1.Section, { articleHeight: articleHeight, section: section, data: data, zIndex: sectionsLength - i }, section.id));
35
- }) }), (0, jsx_runtime_1.jsx)("div", { id: "component-portal" }), (0, jsx_runtime_1.jsx)("div", { id: "grid-component-lightbox-portal" })] })] }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
31
+ return ((0, jsx_runtime_1.jsx)(ArticleRectContext_1.ArticleRectContext.Provider, { value: articleRectObserver, children: (0, jsx_runtime_1.jsxs)(InteractionsContext_1.InteractionsProvider, { article: article, children: [(0, jsx_runtime_1.jsx)(ArticleWrapper_1.ArticleWrapper, { children: (0, jsx_runtime_1.jsxs)("div", { className: "article", ref: articleRef, children: [(0, jsx_runtime_1.jsx)(WebGLContextManagerContext_1.WebglContextManagerContext.Provider, { value: webglContextManager, children: article.sections.map((section, i) => {
32
+ const data = section.name ? sectionData[section.name] : {};
33
+ return ((0, jsx_runtime_1.jsx)(Section_1.Section, { articleHeight: articleHeight, section: section, data: data, zIndex: sectionsLength - i }, section.id));
34
+ }) }), (0, jsx_runtime_1.jsx)("div", { id: "component-portal" }), (0, jsx_runtime_1.jsx)("div", { id: "grid-component-lightbox-portal" })] }) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
36
35
  .article {
37
36
  position: relative;
38
37
  overflow: clip;
@@ -6,10 +6,7 @@ const useCurrentLayout_1 = require("../common/useCurrentLayout");
6
6
  const LayoutContext_1 = require("../provider/LayoutContext");
7
7
  const ArticleWrapper = ({ children }) => {
8
8
  const { layoutId, layoutDeviation } = (0, useCurrentLayout_1.useCurrentLayout)();
9
- const layoutDeviationStyle = {
10
- '--layout-deviation': layoutDeviation,
11
- position: 'relative'
12
- };
9
+ const layoutDeviationStyle = { '--layout-deviation': layoutDeviation };
13
10
  return ((0, jsx_runtime_1.jsx)(LayoutContext_1.LayoutContext.Provider, { value: layoutId, children: (0, jsx_runtime_1.jsx)("div", { className: "article-wrapper", style: Object.assign({}, layoutDeviationStyle), children: children }) }));
14
11
  };
15
12
  exports.ArticleWrapper = ArticleWrapper;
@@ -13,13 +13,13 @@ const Head_1 = require("./Head");
13
13
  const Keyframes_1 = require("../provider/Keyframes");
14
14
  const ItemGeometryContext_1 = require("../ItemGeometry/ItemGeometryContext");
15
15
  const ItemGeometryService_1 = require("../ItemGeometry/ItemGeometryService");
16
- const Page = ({ article, project, meta, keyframes, navigation, sectionData, siteUrl, fontsVault }) => {
16
+ const Page = ({ article, project, meta, keyframes, sectionData, siteUrl, fontsVault }) => {
17
17
  var _a;
18
18
  const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
19
19
  const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
20
20
  const keyframesRepo = (0, react_1.useMemo)(() => new Keyframes_1.Keyframes(keyframes), [keyframes]);
21
21
  const itemGeometryService = (0, react_1.useMemo)(() => new ItemGeometryService_1.ItemGeometryService(), []);
22
22
  const currentSlug = (_a = project.pages.find(p => p.articleId === article.id)) === null || _a === void 0 ? void 0 : _a.slug;
23
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta, slug: currentSlug, siteUrl: siteUrl, fontsVault: fontsVault }), afterBodyOpen, (0, jsx_runtime_1.jsx)(ItemGeometryContext_1.ItemGeometryContext.Provider, { value: itemGeometryService, children: (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, { value: keyframesRepo, children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData, navigation: navigation, pages: project.pages }) }) }), beforeBodyClose] }));
23
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta, slug: currentSlug, siteUrl: siteUrl, fontsVault: fontsVault }), afterBodyOpen, (0, jsx_runtime_1.jsx)(ItemGeometryContext_1.ItemGeometryContext.Provider, { value: itemGeometryService, children: (0, jsx_runtime_1.jsx)(KeyframesContext_1.KeyframesContext.Provider, { value: keyframesRepo, children: (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, sectionData: sectionData }) }) }), beforeBodyClose] }));
24
24
  };
25
25
  exports.Page = Page;
@@ -11,7 +11,6 @@ const react_1 = require("react");
11
11
  const useCntrlContext_1 = require("../../../provider/useCntrlContext");
12
12
  const useLayoutContext_1 = require("../../useLayoutContext");
13
13
  const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
14
- const mergeComponentSettings_1 = require("../../../utils/mergeComponentSettings");
15
14
  const StructuredComponent = ({ block }) => {
16
15
  var _a, _b;
17
16
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
@@ -26,7 +25,7 @@ const StructuredComponent = ({ block }) => {
26
25
  const Element = component ? component.element : undefined;
27
26
  const layoutParameters = effectiveLayout ? (_b = block.layoutParams[effectiveLayout]) === null || _b === void 0 ? void 0 : _b.parameters : undefined;
28
27
  const commonParameters = block.commonParams.parameters;
29
- const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: (0, mergeComponentSettings_1.mergeComponentSettings)(layoutParameters.settings, commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
28
+ const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: Object.assign(Object.assign({}, layoutParameters.settings), commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
30
29
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${block.id}`, ref: setRef,
31
30
  // preventing layout shift while supporting SSG for proper SEO
32
31
  style: { opacity: layout == null ? 0 : undefined }, children: parameters && Element && ((0, jsx_runtime_1.jsx)(Element, Object.assign({ metadata: {
@@ -16,7 +16,6 @@ const getStyleFromItemStateAndParams_1 = require("../../../utils/getStyleFromIte
16
16
  const useLayoutContext_1 = require("../../useLayoutContext");
17
17
  const useItemGeometry_1 = require("../../../ItemGeometry/useItemGeometry");
18
18
  const LinkWrapper_1 = require("../LinkWrapper");
19
- const mergeComponentSettings_1 = require("../../../utils/mergeComponentSettings");
20
19
  const ComponentItem = ({ item, sectionId, onResize, interactionCtrl }) => {
21
20
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
22
21
  const sdk = (0, useCntrlContext_1.useCntrlContext)();
@@ -38,7 +37,7 @@ const ComponentItem = ({ item, sectionId, onResize, interactionCtrl }) => {
38
37
  const Element = component ? component.element : undefined;
39
38
  const layoutParameters = effectiveLayout ? (_e = item.layoutParams[effectiveLayout]) === null || _e === void 0 ? void 0 : _e.parameters : undefined;
40
39
  const commonParameters = item.commonParams.parameters;
41
- const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: (0, mergeComponentSettings_1.mergeComponentSettings)(layoutParameters.settings, commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
40
+ const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: Object.assign(Object.assign({}, layoutParameters.settings), commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
42
41
  const hasLink = Boolean((_f = item.link) === null || _f === void 0 ? void 0 : _f.url);
43
42
  return ((0, jsx_runtime_1.jsx)(LinkWrapper_1.LinkWrapper, { url: (_g = item.link) === null || _g === void 0 ? void 0 : _g.url, target: (_h = item.link) === null || _h === void 0 ? void 0 : _h.target,
44
43
  // Let the component define its own hit area (e.g. rounded button),
package/lib/index.js CHANGED
@@ -14,7 +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.cntrlSdkContext = exports.customSections = exports.customItems = exports.resolveCustomComponents = exports.evaluateComponentBundle = exports.useCntrlContext = exports.CntrlProvider = exports.YoutubeEmbedItem = exports.VimeoEmbedItem = exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Navigation = exports.Article = exports.Head = exports.Page = exports.RichTextConverter = void 0;
17
+ exports.cntrlSdkContext = exports.customSections = exports.customItems = exports.resolveCustomComponents = exports.evaluateComponentBundle = 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;
18
18
  const defaultContext_1 = require("./provider/defaultContext");
19
19
  __exportStar(require("@cntrl-site/sdk"), exports);
20
20
  var RichTextConverter_1 = require("./utils/RichTextConverter/RichTextConverter");
@@ -25,8 +25,6 @@ var Head_1 = require("./components/Head");
25
25
  Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return Head_1.CNTRLHead; } });
26
26
  var Article_1 = require("./components/Article");
27
27
  Object.defineProperty(exports, "Article", { enumerable: true, get: function () { return Article_1.Article; } });
28
- var Navigation_1 = require("./components/Navigation/Navigation");
29
- Object.defineProperty(exports, "Navigation", { enumerable: true, get: function () { return Navigation_1.Navigation; } });
30
28
  var Section_1 = require("./components/Section/Section");
31
29
  Object.defineProperty(exports, "Section", { enumerable: true, get: function () { return Section_1.Section; } });
32
30
  var Item_1 = require("./components/items/Item");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "1.9.136-alpha.0",
3
+ "version": "1.9.136",
4
4
  "description": "SDK for Next.js",
5
5
  "author": "arsen@momdesign.nyc",
6
6
  "license": "MIT",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@antfu/eslint-config": "^3.8.0",
33
33
  "@cntrl-site/color": "^1.0.0",
34
- "@cntrl-site/components": "^1.0.79-alpha.5",
34
+ "@cntrl-site/components": "^1.0.81",
35
35
  "@cntrl-site/effects": "^1.4.2",
36
- "@cntrl-site/sdk": "^1.28.9-alpha.2",
36
+ "@cntrl-site/sdk": "^1.28.7",
37
37
  "@types/vimeo__player": "^2.18.0",
38
38
  "@vimeo/player": "^2.25.0",
39
39
  "html-react-parser": "^3.0.1",
@@ -1,23 +1,22 @@
1
1
  import { FC, useEffect, useId, useMemo, useRef, useState } from 'react';
2
2
  import JSXStyle from 'styled-jsx/style';
3
- import { Article as TArticle, ProjectNavigation } from '@cntrl-site/sdk';
3
+ import { Article as TArticle } from '@cntrl-site/sdk';
4
4
  import { Section } from './Section/Section';
5
+ import { Item } from './items/Item';
5
6
  import { useArticleRectObserver } from '../utils/ArticleRectManager/useArticleRectObserver';
6
7
  import { ArticleRectContext } from '../provider/ArticleRectContext';
7
8
  import { ArticleWrapper } from './ArticleWrapper';
8
9
  import { InteractionsProvider } from '../provider/InteractionsContext';
9
10
  import { WebglContextManagerContext } from '../provider/WebGLContextManagerContext';
10
11
  import { WebGLContextManager } from '@cntrl-site/effects';
11
- import { Navigation } from './Navigation/Navigation';
12
+ import { StructuredContent } from './StructuredContent/StructuredContent';
12
13
 
13
14
  interface Props {
14
15
  article: TArticle;
15
16
  sectionData: Record<SectionName, any>;
16
- navigation?: ProjectNavigation | null;
17
- pages?: Array<{ id: string; slug: string }>;
18
17
  }
19
18
 
20
- export const Article: FC<Props> = ({ article, sectionData, navigation, pages = [] }) => {
19
+ export const Article: FC<Props> = ({ article, sectionData }) => {
21
20
  const articleRef = useRef<HTMLDivElement | null>(null);
22
21
  const articleRectObserver = useArticleRectObserver(articleRef.current);
23
22
  const id = useId();
@@ -37,13 +36,6 @@ export const Article: FC<Props> = ({ article, sectionData, navigation, pages = [
37
36
  <ArticleRectContext.Provider value={articleRectObserver}>
38
37
  <InteractionsProvider article={article}>
39
38
  <ArticleWrapper>
40
- {navigation && (
41
- <Navigation
42
- navigation={navigation}
43
- pages={pages}
44
- hidden={article.navigationHidden}
45
- />
46
- )}
47
39
  <div className="article" ref={articleRef}>
48
40
  <WebglContextManagerContext.Provider value={webglContextManager}>
49
41
  {article.sections.map((section, i) => {
@@ -4,10 +4,7 @@ import { LayoutContext } from '../provider/LayoutContext';
4
4
 
5
5
  export const ArticleWrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
6
6
  const { layoutId, layoutDeviation } = useCurrentLayout();
7
- const layoutDeviationStyle = {
8
- '--layout-deviation': layoutDeviation,
9
- position: 'relative'
10
- } as CSSProperties;
7
+ const layoutDeviationStyle = { '--layout-deviation': layoutDeviation } as CSSProperties;
11
8
 
12
9
  return (
13
10
  <LayoutContext.Provider value={layoutId}>
@@ -1,6 +1,6 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import HTMLReactParser from 'html-react-parser';
3
- import { Article as TArticle, Project, Meta, KeyframeAny, FontVault, ProjectNavigation } from '@cntrl-site/sdk';
3
+ import { Article as TArticle, Project, Meta, KeyframeAny, FontVault } from '@cntrl-site/sdk';
4
4
  import { Article } from './Article';
5
5
  import { KeyframesContext } from '../provider/KeyframesContext';
6
6
  import { CNTRLHead } from './Head';
@@ -19,14 +19,13 @@ export interface PageProps {
19
19
  meta: Meta;
20
20
  fontsVault: FontVault[];
21
21
  keyframes: KeyframeAny[];
22
- navigation?: ProjectNavigation | null;
23
22
  sectionData: Record<SectionName, any>;
24
23
  publicApiBase?: string;
25
24
  customComponentBundles?: CustomComponentBundlesData;
26
25
  siteUrl?: string;
27
26
  }
28
27
 
29
- export const Page: FC<PageProps> = ({ article, project, meta, keyframes, navigation, sectionData, siteUrl, fontsVault }) => {
28
+ export const Page: FC<PageProps> = ({ article, project, meta, keyframes, sectionData, siteUrl, fontsVault }) => {
30
29
  const afterBodyOpen = HTMLReactParser(project.html.afterBodyOpen);
31
30
  const beforeBodyClose = HTMLReactParser(project.html.beforeBodyClose);
32
31
  const keyframesRepo = useMemo(() => new Keyframes(keyframes), [keyframes]);
@@ -38,7 +37,7 @@ export const Page: FC<PageProps> = ({ article, project, meta, keyframes, navigat
38
37
  {afterBodyOpen}
39
38
  <ItemGeometryContext.Provider value={itemGeometryService}>
40
39
  <KeyframesContext.Provider value={keyframesRepo}>
41
- <Article article={article} sectionData={sectionData} navigation={navigation} pages={project.pages} />
40
+ <Article article={article} sectionData={sectionData} />
42
41
  </KeyframesContext.Provider>
43
42
  </ItemGeometryContext.Provider>
44
43
  {beforeBodyClose}
@@ -4,7 +4,6 @@ import { FC, useState } from 'react';
4
4
  import { useCntrlContext } from '../../../provider/useCntrlContext';
5
5
  import { useLayoutContext } from '../../useLayoutContext';
6
6
  import { useItemGeometry } from '../../../ItemGeometry/useItemGeometry';
7
- import { mergeComponentSettings } from '../../../utils/mergeComponentSettings';
8
7
 
9
8
  interface Props {
10
9
  block: StructuredBlock<StructuredBlockType.Component>;
@@ -25,7 +24,7 @@ export const StructuredComponent: FC<Props> = ({ block }) => {
25
24
  const commonParameters = block.commonParams.parameters;
26
25
  const parameters = layoutParameters ? {
27
26
  ...layoutParameters,
28
- settings: mergeComponentSettings(layoutParameters.settings, commonParameters?.settings)
27
+ settings: { ...layoutParameters.settings, ...commonParameters?.settings }
29
28
  } : undefined;
30
29
 
31
30
  return (
@@ -10,7 +10,6 @@ import { getStyleFromItemStateAndParams } from '../../../utils/getStyleFromItemS
10
10
  import { useLayoutContext } from '../../useLayoutContext';
11
11
  import { useItemGeometry } from '../../../ItemGeometry/useItemGeometry';
12
12
  import { LinkWrapper } from '../LinkWrapper';
13
- import { mergeComponentSettings } from '../../../utils/mergeComponentSettings';
14
13
 
15
14
  export const ComponentItem: FC<ItemProps<TComponentItem>> = ({ item, sectionId, onResize, interactionCtrl }) => {
16
15
  const sdk = useCntrlContext();
@@ -34,7 +33,7 @@ export const ComponentItem: FC<ItemProps<TComponentItem>> = ({ item, sectionId,
34
33
  const commonParameters = item.commonParams.parameters;
35
34
  const parameters = layoutParameters ? {
36
35
  ...layoutParameters,
37
- settings: mergeComponentSettings(layoutParameters.settings, commonParameters?.settings)
36
+ settings: { ...layoutParameters.settings, ...commonParameters?.settings }
38
37
  } : undefined;
39
38
 
40
39
  const hasLink = Boolean(item.link?.url);
package/src/index.ts CHANGED
@@ -6,7 +6,6 @@ export { Page } from './components/Page';
6
6
  export type { PageProps, CustomComponentBundlesData } from './components/Page';
7
7
  export { CNTRLHead as Head } from './components/Head';
8
8
  export { Article } from './components/Article';
9
- export { Navigation } from './components/Navigation/Navigation';
10
9
  export { Section } from './components/Section/Section';
11
10
  export { Item } from './components/items/Item';
12
11
  export { ImageItem } from './components/items/FileItem/ImageItem';
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Navigation = void 0;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const react_1 = require("react");
9
- const style_1 = __importDefault(require("styled-jsx/style"));
10
- const sdk_1 = require("@cntrl-site/sdk");
11
- const useCntrlContext_1 = require("../../provider/useCntrlContext");
12
- const useLayoutContext_1 = require("../useLayoutContext");
13
- const NavigationComponent_1 = require("./NavigationComponent");
14
- const useNavigationSwitch_1 = require("./useNavigationSwitch");
15
- const DEFAULT_POSITION = 'default';
16
- const Navigation = ({ navigation, pages, hidden }) => {
17
- var _a, _b, _c, _d;
18
- const { layouts } = (0, useCntrlContext_1.useCntrlContext)();
19
- const layout = (0, useLayoutContext_1.useLayoutContext)();
20
- const [wrapperRef, setWrapperRef] = (0, react_1.useState)(null);
21
- const reactId = (0, react_1.useId)();
22
- const id = `${reactId}-navigation-${navigation.id}`;
23
- const position = (_c = (layout && ((_b = (_a = navigation.settings) === null || _a === void 0 ? void 0 : _a[layout]) === null || _b === void 0 ? void 0 : _b.position))) !== null && _c !== void 0 ? _c : DEFAULT_POSITION;
24
- const isSwitch = position === 'switch';
25
- const isSwitchOnScroll = (0, useNavigationSwitch_1.useNavigationSwitch)(isSwitch, wrapperRef);
26
- const layoutValues = [(_d = navigation.settings) !== null && _d !== void 0 ? _d : {}, hidden !== null && hidden !== void 0 ? hidden : {}];
27
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { id: navigation.component.id, ref: setWrapperRef, className: `navigation-${navigation.id}${isSwitch && isSwitchOnScroll ? ` navigation-${navigation.id}-switch-inactive` : ''}`, children: (0, jsx_runtime_1.jsx)(NavigationComponent_1.NavigationComponent, { component: navigation.component, pages: pages, currentState: isSwitch ? 'default' : undefined }) }), isSwitch && ((0, jsx_runtime_1.jsx)("div", { "aria-hidden": !isSwitchOnScroll, className: `navigation-switch-clone-${navigation.id}${isSwitchOnScroll ? ` navigation-switch-clone-${navigation.id}-visible` : ''}`, children: (0, jsx_runtime_1.jsx)(NavigationComponent_1.NavigationComponent, { component: navigation.component, pages: pages, currentState: "compact", isSwitchClone: true }) })), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
28
- .navigation-${navigation.id} {
29
- position: absolute;
30
- top: 0;
31
- left: 0;
32
- width: 100%;
33
- z-index: 10000;
34
- }
35
- .navigation-${navigation.id}-switch-inactive {
36
- visibility: hidden;
37
- pointer-events: none;
38
- }
39
- .navigation-switch-clone-${navigation.id} {
40
- position: fixed;
41
- top: var(--cntrl-article-top, 0px);
42
- left: var(--cntrl-article-left, 0px);
43
- width: var(--cntrl-article-width, 100%);
44
- z-index: 10001;
45
- pointer-events: none;
46
- visibility: hidden;
47
- transition: visibility 0s linear 320ms;
48
- --cntrl-nav-slide: -100%;
49
- }
50
- .navigation-switch-clone-${navigation.id}-visible {
51
- pointer-events: auto;
52
- visibility: visible;
53
- transition: visibility 0s;
54
- --cntrl-nav-slide: 0%;
55
- }
56
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([settings, isHidden]) => {
57
- var _a;
58
- const layoutPosition = (_a = settings === null || settings === void 0 ? void 0 : settings.position) !== null && _a !== void 0 ? _a : DEFAULT_POSITION;
59
- const isSticky = layoutPosition === 'stickyTop' || layoutPosition === 'switch';
60
- return (`
61
- .navigation-${navigation.id} {
62
- position: ${layoutPosition === 'stickyTop' ? 'fixed' : 'absolute'};
63
- top: ${isSticky ? 'var(--cntrl-article-top, 0px)' : '0'};
64
- left: ${isSticky ? 'var(--cntrl-article-left, 0px)' : '0'};
65
- width: ${isSticky ? 'var(--cntrl-article-width, 100%)' : '100%'};
66
- display: ${isHidden ? 'none' : 'block'};
67
- }
68
- .navigation-switch-clone-${navigation.id} {
69
- display: ${isHidden || layoutPosition !== 'switch' ? 'none' : 'block'};
70
- }
71
- `);
72
- })}
73
- ` })] }));
74
- };
75
- exports.Navigation = Navigation;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NavigationComponent = void 0;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const style_1 = __importDefault(require("styled-jsx/style"));
9
- const sdk_1 = require("@cntrl-site/sdk");
10
- const react_1 = require("react");
11
- const useCntrlContext_1 = require("../../provider/useCntrlContext");
12
- const useLayoutContext_1 = require("../useLayoutContext");
13
- const mergeComponentSettings_1 = require("../../utils/mergeComponentSettings");
14
- const NavigationComponent = ({ component: block, pages, currentState, isSwitchClone }) => {
15
- var _a, _b;
16
- const sdk = (0, useCntrlContext_1.useCntrlContext)();
17
- const { layouts } = sdk;
18
- const layout = (0, useLayoutContext_1.useLayoutContext)();
19
- const fallbackLayout = (_a = layouts[0]) === null || _a === void 0 ? void 0 : _a.id;
20
- const effectiveLayout = layout !== null && layout !== void 0 ? layout : fallbackLayout;
21
- const layoutValues = [block.layoutParams];
22
- const component = sdk.getComponent(block.commonParams.componentId);
23
- const Element = component ? component.element : undefined;
24
- const layoutParameters = effectiveLayout ? (_b = block.layoutParams[effectiveLayout]) === null || _b === void 0 ? void 0 : _b.parameters : undefined;
25
- const commonParameters = block.commonParams.parameters;
26
- const parameters = layoutParameters ? Object.assign(Object.assign({}, layoutParameters), { settings: (0, mergeComponentSettings_1.mergeComponentSettings)(layoutParameters.settings, commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.settings) }) : undefined;
27
- const reactId = (0, react_1.useId)();
28
- const id = `${reactId}-custom-component-${block.id}`;
29
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `custom-component-${block.id}`, style: { opacity: layout == null ? 0 : undefined }, children: parameters && Element && ((0, jsx_runtime_1.jsx)(Element, Object.assign({ metadata: {
30
- itemId: block.id,
31
- submitUrl: sdk.getSubmitUrl(commonParameters === null || commonParameters === void 0 ? void 0 : commonParameters.pluginConfigId)
32
- }, portalId: "component-portal", content: block.commonParams.content }, parameters, { layoutId: effectiveLayout, pages: pages, currentState: currentState, isSwitchClone: isSwitchClone }))) }), (0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
33
- .custom-component-${block.id} {
34
- width: 100%;
35
- height: 100%;
36
- pointer-events: auto;
37
- }
38
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([layoutParams]) => {
39
- return (`
40
- .custom-component-${block.id} {
41
- opacity: ${layoutParams.opacity};
42
- ${layoutParams.blur !== 0 ? `filter: blur(${layoutParams.blur}vw);` : ''}
43
- ${layoutParams.blur !== 0 ? 'will-change: transform;' : ''}
44
- }
45
- `);
46
- })}` })] }));
47
- };
48
- exports.NavigationComponent = NavigationComponent;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useNavigationSwitch = void 0;
4
- const react_1 = require("react");
5
- const COMPACT_SWITCH_SCROLL_OFFSET_PX = 20;
6
- function getArticleTop(element) {
7
- const raw = getComputedStyle(element).getPropertyValue('--cntrl-article-top');
8
- const parsed = parseFloat(raw);
9
- return Number.isFinite(parsed) ? parsed : 0;
10
- }
11
- function useNavigationSwitch(isEnabled, element) {
12
- const [isPinned, setIsPinned] = (0, react_1.useState)(false);
13
- (0, react_1.useEffect)(() => {
14
- if (!isEnabled || !element) {
15
- setIsPinned(false);
16
- return;
17
- }
18
- const sync = () => {
19
- const next = element.getBoundingClientRect().bottom
20
- <= getArticleTop(element) - COMPACT_SWITCH_SCROLL_OFFSET_PX + 0.5;
21
- setIsPinned(prev => (prev === next ? prev : next));
22
- };
23
- const observer = new ResizeObserver(sync);
24
- observer.observe(element);
25
- sync();
26
- window.addEventListener('scroll', sync, { passive: true });
27
- return () => {
28
- observer.disconnect();
29
- window.removeEventListener('scroll', sync);
30
- };
31
- }, [isEnabled, element]);
32
- return isPinned;
33
- }
34
- exports.useNavigationSwitch = useNavigationSwitch;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeComponentSettings = void 0;
4
- function mergeComponentSettings(layoutSettings, commonSettings) {
5
- return Object.assign(Object.assign({}, (layoutSettings !== null && layoutSettings !== void 0 ? layoutSettings : {})), (commonSettings !== null && commonSettings !== void 0 ? commonSettings : {}));
6
- }
7
- exports.mergeComponentSettings = mergeComponentSettings;
@@ -1,107 +0,0 @@
1
- import { FC, useId, useState } from 'react';
2
- import JSXStyle from 'styled-jsx/style';
3
- import {
4
- getLayoutStyles,
5
- Project,
6
- ProjectNavigation,
7
- ProjectNavigationPosition
8
- } from '@cntrl-site/sdk';
9
- import { useCntrlContext } from '../../provider/useCntrlContext';
10
- import { useLayoutContext } from '../useLayoutContext';
11
- import { NavigationComponent } from './NavigationComponent';
12
- import { useNavigationSwitch } from './useNavigationSwitch';
13
-
14
- interface Props {
15
- navigation: ProjectNavigation;
16
- pages: Array<{ id: string; slug: string }>;
17
- hidden?: Record<string, boolean>;
18
- }
19
-
20
- const DEFAULT_POSITION: ProjectNavigationPosition = 'default';
21
-
22
- export const Navigation: FC<Props> = ({ navigation, pages, hidden }) => {
23
- const { layouts } = useCntrlContext();
24
- const layout = useLayoutContext();
25
- const [wrapperRef, setWrapperRef] = useState<HTMLDivElement | null>(null);
26
- const reactId = useId();
27
- const id = `${reactId}-navigation-${navigation.id}`;
28
- const position = (layout && navigation.settings?.[layout]?.position) ?? DEFAULT_POSITION;
29
- const isSwitch = position === 'switch';
30
- const isSwitchOnScroll = useNavigationSwitch(isSwitch, wrapperRef);
31
- const layoutValues: Record<string, any>[] = [navigation.settings ?? {}, hidden ?? {}];
32
-
33
- return (
34
- <>
35
- <div
36
- id={navigation.component.id}
37
- ref={setWrapperRef}
38
- className={`navigation-${navigation.id}${isSwitch && isSwitchOnScroll ? ` navigation-${navigation.id}-switch-inactive` : ''}`}
39
- >
40
- <NavigationComponent
41
- component={navigation.component}
42
- pages={pages}
43
- currentState={isSwitch ? 'default' : undefined}
44
- />
45
- </div>
46
- {isSwitch && (
47
- <div
48
- aria-hidden={!isSwitchOnScroll}
49
- className={`navigation-switch-clone-${navigation.id}${isSwitchOnScroll ? ` navigation-switch-clone-${navigation.id}-visible` : ''}`}
50
- >
51
- <NavigationComponent
52
- component={navigation.component}
53
- pages={pages}
54
- currentState="compact"
55
- isSwitchClone
56
- />
57
- </div>
58
- )}
59
- <JSXStyle id={id}>{`
60
- .navigation-${navigation.id} {
61
- position: absolute;
62
- top: 0;
63
- left: 0;
64
- width: 100%;
65
- z-index: 10000;
66
- }
67
- .navigation-${navigation.id}-switch-inactive {
68
- visibility: hidden;
69
- pointer-events: none;
70
- }
71
- .navigation-switch-clone-${navigation.id} {
72
- position: fixed;
73
- top: var(--cntrl-article-top, 0px);
74
- left: var(--cntrl-article-left, 0px);
75
- width: var(--cntrl-article-width, 100%);
76
- z-index: 10001;
77
- pointer-events: none;
78
- visibility: hidden;
79
- transition: visibility 0s linear 320ms;
80
- --cntrl-nav-slide: -100%;
81
- }
82
- .navigation-switch-clone-${navigation.id}-visible {
83
- pointer-events: auto;
84
- visibility: visible;
85
- transition: visibility 0s;
86
- --cntrl-nav-slide: 0%;
87
- }
88
- ${getLayoutStyles(layouts, layoutValues, ([settings, isHidden]) => {
89
- const layoutPosition = settings?.position ?? DEFAULT_POSITION;
90
- const isSticky = layoutPosition === 'stickyTop' || layoutPosition === 'switch';
91
- return (`
92
- .navigation-${navigation.id} {
93
- position: ${layoutPosition === 'stickyTop' ? 'fixed' : 'absolute'};
94
- top: ${isSticky ? 'var(--cntrl-article-top, 0px)' : '0'};
95
- left: ${isSticky ? 'var(--cntrl-article-left, 0px)' : '0'};
96
- width: ${isSticky ? 'var(--cntrl-article-width, 100%)' : '100%'};
97
- display: ${isHidden ? 'none' : 'block'};
98
- }
99
- .navigation-switch-clone-${navigation.id} {
100
- display: ${isHidden || layoutPosition !== 'switch' ? 'none' : 'block'};
101
- }
102
- `);
103
- })}
104
- `}</JSXStyle>
105
- </>
106
- );
107
- };
@@ -1,78 +0,0 @@
1
- import JSXStyle from 'styled-jsx/style';
2
- import { NavigationComponent as TNavigationComponent, getLayoutStyles, Project } from '@cntrl-site/sdk';
3
- import { FC, useId } from 'react';
4
- import { useCntrlContext } from '../../provider/useCntrlContext';
5
- import { useLayoutContext } from '../useLayoutContext';
6
- import { mergeComponentSettings } from '../../utils/mergeComponentSettings';
7
-
8
- interface Props {
9
- component: TNavigationComponent;
10
- pages: Array<{ id: string; slug: string }>;
11
- currentState?: string;
12
- isSwitchClone?: boolean;
13
- }
14
-
15
- export const NavigationComponent: FC<Props> = ({
16
- component: block,
17
- pages,
18
- currentState,
19
- isSwitchClone
20
- }) => {
21
- const sdk = useCntrlContext();
22
- const { layouts } = sdk;
23
- const layout = useLayoutContext();
24
- const fallbackLayout = layouts[0]?.id;
25
- const effectiveLayout = layout ?? fallbackLayout;
26
- const layoutValues: Record<string, any>[] = [block.layoutParams];
27
- const component = sdk.getComponent(block.commonParams.componentId);
28
- const Element = component ? component.element : undefined;
29
- const layoutParameters = effectiveLayout ? block.layoutParams[effectiveLayout]?.parameters : undefined;
30
- const commonParameters = block.commonParams.parameters;
31
- const parameters = layoutParameters ? {
32
- ...layoutParameters,
33
- settings: mergeComponentSettings(layoutParameters.settings, commonParameters?.settings)
34
- } : undefined;
35
- const reactId = useId();
36
- const id = `${reactId}-custom-component-${block.id}`;
37
-
38
- return (
39
- <>
40
- <div
41
- className={`custom-component-${block.id}`}
42
- style={{ opacity: layout == null ? 0 : undefined }}
43
- >
44
- {parameters && Element && (
45
- <Element
46
- metadata={{
47
- itemId: block.id,
48
- submitUrl: sdk.getSubmitUrl(commonParameters?.pluginConfigId)
49
- }}
50
- portalId="component-portal"
51
- content={block.commonParams.content}
52
- {...parameters}
53
- layoutId={effectiveLayout}
54
- pages={pages}
55
- currentState={currentState}
56
- isSwitchClone={isSwitchClone}
57
- />
58
- )}
59
- </div>
60
- <JSXStyle id={id}>{`
61
- .custom-component-${block.id} {
62
- width: 100%;
63
- height: 100%;
64
- pointer-events: auto;
65
- }
66
- ${getLayoutStyles(layouts, layoutValues, ([layoutParams]) => {
67
- return (`
68
- .custom-component-${block.id} {
69
- opacity: ${layoutParams.opacity};
70
- ${layoutParams.blur !== 0 ? `filter: blur(${layoutParams.blur}vw);` : ''}
71
- ${layoutParams.blur !== 0 ? 'will-change: transform;' : ''}
72
- }
73
- `);
74
- })}`}
75
- </JSXStyle>
76
- </>
77
- );
78
- };
@@ -1,38 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- const COMPACT_SWITCH_SCROLL_OFFSET_PX = 20;
4
-
5
- function getArticleTop(element: HTMLElement): number {
6
- const raw = getComputedStyle(element).getPropertyValue('--cntrl-article-top');
7
- const parsed = parseFloat(raw);
8
- return Number.isFinite(parsed) ? parsed : 0;
9
- }
10
-
11
- export function useNavigationSwitch(isEnabled: boolean, element: HTMLElement | null): boolean {
12
- const [isPinned, setIsPinned] = useState(false);
13
-
14
- useEffect(() => {
15
- if (!isEnabled || !element) {
16
- setIsPinned(false);
17
- return;
18
- }
19
-
20
- const sync = () => {
21
- const next = element.getBoundingClientRect().bottom
22
- <= getArticleTop(element) - COMPACT_SWITCH_SCROLL_OFFSET_PX + 0.5;
23
- setIsPinned(prev => (prev === next ? prev : next));
24
- };
25
-
26
- const observer = new ResizeObserver(sync);
27
- observer.observe(element);
28
- sync();
29
- window.addEventListener('scroll', sync, { passive: true });
30
-
31
- return () => {
32
- observer.disconnect();
33
- window.removeEventListener('scroll', sync);
34
- };
35
- }, [isEnabled, element]);
36
-
37
- return isPinned;
38
- }
@@ -1,9 +0,0 @@
1
- export function mergeComponentSettings<T extends Record<string, any>>(
2
- layoutSettings?: T,
3
- commonSettings?: T,
4
- ): T {
5
- return {
6
- ...(layoutSettings ?? {} as T),
7
- ...(commonSettings ?? {} as T)
8
- };
9
- }