@cntrl-site/sdk-nextjs 0.2.8 → 0.2.10

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.
Binary file
@@ -2,18 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Article = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const sdk_1 = require("@cntrl-site/sdk");
6
5
  const Section_1 = require("./Section");
7
6
  const Item_1 = require("./Item");
8
7
  const Article = ({ article, layouts }) => {
9
8
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "article", children: article.sections.map((section, i) => ((0, jsx_runtime_1.jsx)(Section_1.Section, { section: section, layouts: layouts, children: article.sections[i].items.map(item => ((0, jsx_runtime_1.jsx)(Item_1.Item, { layouts: layouts, item: item }, item.id))) }, section.id))) }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
10
- ${(0, sdk_1.getLayoutStyles)(layouts, [article.color], ([color]) => (`
11
- .article {
9
+ .article {
12
10
  position: relative;
13
11
  overflow: hidden;
14
- background-color: ${color ? color : 'transparent'};
15
12
  }
16
- `))}
17
13
  ` })] }));
18
14
  };
19
15
  exports.Article = Article;
@@ -0,0 +1,33 @@
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.CNTRLHead = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const html_react_parser_1 = __importDefault(require("html-react-parser"));
9
+ const head_1 = __importDefault(require("next/head"));
10
+ const sdk_1 = require("@cntrl-site/sdk");
11
+ const CNTRLHead = ({ meta, project }) => {
12
+ const googleFonts = (0, html_react_parser_1.default)(project.fonts.google);
13
+ const adobeFonts = (0, html_react_parser_1.default)(project.fonts.adobe);
14
+ const parsedFonts = {
15
+ ...(typeof googleFonts === 'object' ? googleFonts : {}),
16
+ ...(typeof adobeFonts === 'object' ? adobeFonts : {})
17
+ };
18
+ const customFonts = project.fonts.custom;
19
+ const htmlHead = (0, html_react_parser_1.default)(project.html.head);
20
+ const ffGenerator = new sdk_1.FontFaceGenerator(customFonts);
21
+ return ((0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("title", { children: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "keywords", content: meta.keywords }), (0, jsx_runtime_1.jsx)("meta", { property: "og:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", href: meta.favicon }), customFonts.length > 0 && ((0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
22
+ __html: ffGenerator.generate()
23
+ } })), Object.values(parsedFonts).map((value, i) => {
24
+ if (!value)
25
+ return undefined;
26
+ const rel = value?.rel || value.props?.rel;
27
+ const href = value?.href || value.props?.href;
28
+ if (!rel || !href)
29
+ return undefined;
30
+ return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, i));
31
+ }), htmlHead] }));
32
+ };
33
+ exports.CNTRLHead = CNTRLHead;
@@ -31,7 +31,7 @@ const Item = ({ item, layouts }) => {
31
31
  ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area]) => (`
32
32
  .item-${item.id} {
33
33
  position: absolute;
34
- top: ${area.top * 100}vw;
34
+ top: ${getItemTopStyle(area.top, area.anchorSide)};
35
35
  left: ${area.left * 100}vw;
36
36
  width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'auto'};
37
37
  height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${area.height * 100}vw` : 'auto'};
@@ -42,10 +42,23 @@ const Item = ({ item, layouts }) => {
42
42
  ` })] }));
43
43
  };
44
44
  exports.Item = Item;
45
- const parseSizing = (sizing) => {
45
+ function getItemTopStyle(top, anchorSide) {
46
+ const defaultValue = `${top * 100}vw`;
47
+ if (!anchorSide)
48
+ return defaultValue;
49
+ switch (anchorSide) {
50
+ case sdk_1.AnchorSide.Top:
51
+ return defaultValue;
52
+ case sdk_1.AnchorSide.Center:
53
+ return `calc(50% + ${top * 100}vw)`;
54
+ case sdk_1.AnchorSide.Bottom:
55
+ return `calc(100% + ${top * 100}vw)`;
56
+ }
57
+ }
58
+ function parseSizing(sizing) {
46
59
  const axisSizing = sizing.split(' ');
47
60
  return {
48
61
  y: axisSizing[0],
49
62
  x: axisSizing[1] ? axisSizing[1] : axisSizing[0]
50
63
  };
51
- };
64
+ }
@@ -6,31 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Page = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const html_react_parser_1 = __importDefault(require("html-react-parser"));
9
- const sdk_1 = require("@cntrl-site/sdk");
10
- const head_1 = __importDefault(require("next/head"));
11
9
  const Article_1 = require("./Article");
10
+ const Head_1 = require("./Head");
12
11
  const Page = ({ article, project, meta }) => {
13
- const googleFonts = (0, html_react_parser_1.default)(project.fonts.google);
14
- const adobeFonts = (0, html_react_parser_1.default)(project.fonts.adobe);
15
- const parsedFonts = {
16
- ...(typeof googleFonts === 'object' ? googleFonts : {}),
17
- ...(typeof adobeFonts === 'object' ? adobeFonts : {})
18
- };
19
- const customFonts = project.fonts.custom;
20
- const htmlHead = (0, html_react_parser_1.default)(project.html.head);
21
12
  const afterBodyOpen = (0, html_react_parser_1.default)(project.html.afterBodyOpen);
22
13
  const beforeBodyClose = (0, html_react_parser_1.default)(project.html.beforeBodyClose);
23
- const ffGenerator = new sdk_1.FontFaceGenerator(customFonts);
24
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(head_1.default, { children: [(0, jsx_runtime_1.jsx)("title", { children: meta.title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: meta.description }), (0, jsx_runtime_1.jsx)("meta", { name: "keywords", content: meta.keywords }), (0, jsx_runtime_1.jsx)("meta", { property: "og:image", content: meta.opengraphThumbnail }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", href: meta.favicon }), customFonts.length > 0 && ((0, jsx_runtime_1.jsx)("style", { dangerouslySetInnerHTML: {
25
- __html: ffGenerator.generate()
26
- } })), Object.values(parsedFonts).map((value, i) => {
27
- if (!value)
28
- return undefined;
29
- const rel = value?.rel || value.props?.rel;
30
- const href = value?.href || value.props?.href;
31
- if (!rel || !href)
32
- return undefined;
33
- return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: href }, i));
34
- }), htmlHead] }), afterBodyOpen, (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, layouts: project.layouts }), beforeBodyClose] }));
14
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Head_1.CNTRLHead, { project: project, meta: meta }), afterBodyOpen, (0, jsx_runtime_1.jsx)(Article_1.Article, { article: article, layouts: project.layouts }), beforeBodyClose] }));
35
15
  };
36
16
  exports.Page = Page;
@@ -21,10 +21,22 @@ const Section = ({ section, layouts, children }) => {
21
21
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: `section-${section.id}`, children: children }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
22
22
  ${(0, sdk_1.getLayoutStyles)(layouts, [section.height], ([height]) => (`
23
23
  .section-${section.id} {
24
- height: ${height * 100}vw;
24
+ height: ${getSectionHeight(height)};
25
25
  position: relative;
26
26
  }`))}
27
+ ${(0, sdk_1.getLayoutStyles)(layouts, [section.color], ([color]) => (`
28
+ .section-${section.id} {
29
+ background-color: ${color ? color : 'transparent'};
30
+ }`))}
27
31
  ${getSectionVisibilityStyles()}
28
32
  ` })] }));
29
33
  };
30
34
  exports.Section = Section;
35
+ function getSectionHeight(heightData) {
36
+ const { units, vhUnits, mode } = heightData;
37
+ if (mode === sdk_1.SectionHeightMode.ViewportHeightUnits)
38
+ return `${vhUnits}vh`;
39
+ if (mode === sdk_1.SectionHeightMode.ControlUnits)
40
+ return `${units * 100}vw`;
41
+ return '0';
42
+ }
package/lib/index.js CHANGED
@@ -14,13 +14,15 @@ 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.CustomItems = exports.CntrlProvider = exports.YoutubeEmbedItem = exports.VimeoEmbedItem = exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Page = exports.RichTextConverter = void 0;
17
+ exports.CustomItems = 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");
21
21
  Object.defineProperty(exports, "RichTextConverter", { enumerable: true, get: function () { return RichTextConverter_1.RichTextConverter; } });
22
22
  var Page_1 = require("./components/Page");
23
23
  Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return Page_1.Page; } });
24
+ var Head_1 = require("./components/Head");
25
+ Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return Head_1.CNTRLHead; } });
24
26
  var Article_1 = require("./components/Article");
25
27
  Object.defineProperty(exports, "Article", { enumerable: true, get: function () { return Article_1.Article; } });
26
28
  var Section_1 = require("./components/Section");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.js",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "homepage": "https://github.com/cntrl-site/sdk-nextjs#readme",
23
23
  "dependencies": {
24
- "@cntrl-site/sdk": "^0.2.11",
24
+ "@cntrl-site/sdk": "^0.2.13",
25
25
  "html-react-parser": "^3.0.1",
26
26
  "styled-jsx": "^5.0.2"
27
27
  },
@@ -21,13 +21,10 @@ export const Article: FC<Props> = ({ article, layouts }) => {
21
21
  ))}
22
22
  </div>
23
23
  <style jsx>{`
24
- ${getLayoutStyles(layouts, [article.color], ([color]) => (`
25
- .article {
24
+ .article {
26
25
  position: relative;
27
26
  overflow: hidden;
28
- background-color: ${color ? color : 'transparent'};
29
27
  }
30
- `))}
31
28
  `}</style>
32
29
  </>
33
30
  );
@@ -0,0 +1,48 @@
1
+ import React, { FC } from 'react';
2
+ import HTMLReactParser, { domToReact } from 'html-react-parser';
3
+ import Head from 'next/head';
4
+ import { FontFaceGenerator, TMeta, TProject } from '@cntrl-site/sdk';
5
+
6
+ interface Props {
7
+ project: TProject;
8
+ meta: TMeta;
9
+ }
10
+
11
+ export const CNTRLHead: FC<Props> = ({ meta, project }) => {
12
+ const googleFonts: ReturnType<typeof domToReact> = HTMLReactParser(project.fonts.google);
13
+ const adobeFonts: ReturnType<typeof domToReact> = HTMLReactParser(project.fonts.adobe);
14
+ const parsedFonts = {
15
+ ...(typeof googleFonts === 'object' ? googleFonts : {}),
16
+ ...(typeof adobeFonts === 'object' ? adobeFonts : {})
17
+ };
18
+ const customFonts = project.fonts.custom;
19
+ const htmlHead = HTMLReactParser(project.html.head);
20
+ const ffGenerator = new FontFaceGenerator(customFonts);
21
+ return (
22
+ <Head>
23
+ <title>{meta.title}</title>
24
+ <meta name="description" content={meta.description} />
25
+ <meta name="keywords" content={meta.keywords} />
26
+ <meta property="og:image" content={meta.opengraphThumbnail} />
27
+ <link rel="icon" href={meta.favicon} />
28
+ {customFonts.length > 0 && (
29
+ <style
30
+ dangerouslySetInnerHTML={{
31
+ __html: ffGenerator.generate()
32
+ }}
33
+ />
34
+ )}
35
+ {Object.values(parsedFonts as ReturnType<typeof domToReact>).map((value, i) => {
36
+ if (!value) return undefined;
37
+ const rel = value?.rel || value.props?.rel;
38
+ const href = value?.href || value.props?.href;
39
+ if (!rel || !href) return undefined;
40
+ return (
41
+ <link key={i} rel={rel} href={href} />
42
+ );
43
+ })}
44
+ {htmlHead}
45
+
46
+ </Head>
47
+ );
48
+ };
@@ -4,7 +4,8 @@ import {
4
4
  ArticleItemType,
5
5
  ArticleItemSizingType as SizingType,
6
6
  TArticleItemAny,
7
- TLayout
7
+ TLayout,
8
+ AnchorSide
8
9
  } from '@cntrl-site/sdk';
9
10
  import { RectangleItem } from './items/RectangleItem';
10
11
  import { ImageItem } from './items/ImageItem';
@@ -47,7 +48,7 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, layouts }) => {
47
48
  ${getLayoutStyles(layouts, layoutValues, ([area]) => (`
48
49
  .item-${item.id} {
49
50
  position: absolute;
50
- top: ${area.top * 100}vw;
51
+ top: ${getItemTopStyle(area.top, area.anchorSide)};
51
52
  left: ${area.left * 100}vw;
52
53
  width: ${sizingAxis.x === SizingType.Manual ? `${area.width * 100}vw` : 'auto'};
53
54
  height: ${sizingAxis.y === SizingType.Manual ? `${area.height * 100}vw` : 'auto'};
@@ -60,13 +61,26 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, layouts }) => {
60
61
  );
61
62
  };
62
63
 
63
- const parseSizing = (sizing: string): Axis => {
64
+ function getItemTopStyle(top: number, anchorSide: AnchorSide) {
65
+ const defaultValue = `${top * 100}vw`;
66
+ if (!anchorSide) return defaultValue;
67
+ switch (anchorSide) {
68
+ case AnchorSide.Top:
69
+ return defaultValue;
70
+ case AnchorSide.Center:
71
+ return `calc(50% + ${top * 100}vw)`;
72
+ case AnchorSide.Bottom:
73
+ return `calc(100% + ${top * 100}vw)`;
74
+ }
75
+ }
76
+
77
+ function parseSizing(sizing: string): Axis {
64
78
  const axisSizing = sizing.split(' ');
65
79
  return {
66
80
  y: axisSizing[0],
67
81
  x: axisSizing[1] ? axisSizing[1] : axisSizing[0]
68
82
  } as Axis;
69
- };
83
+ }
70
84
 
71
85
  interface Axis {
72
86
  x: SizingType;
@@ -1,8 +1,8 @@
1
1
  import React, { FC } from 'react';
2
- import HTMLReactParser, { domToReact } from 'html-react-parser';
3
- import { TArticle, TProject, TMeta, FontFaceGenerator } from '@cntrl-site/sdk';
4
- import Head from 'next/head';
2
+ import HTMLReactParser from 'html-react-parser';
3
+ import { TArticle, TProject, TMeta } from '@cntrl-site/sdk';
5
4
  import { Article } from './Article';
5
+ import { CNTRLHead } from './Head';
6
6
 
7
7
  interface Props {
8
8
  article: TArticle;
@@ -11,44 +11,11 @@ interface Props {
11
11
  }
12
12
 
13
13
  export const Page: FC<Props> = ({ article, project, meta }) => {
14
- const googleFonts: ReturnType<typeof domToReact> = HTMLReactParser(project.fonts.google);
15
- const adobeFonts: ReturnType<typeof domToReact> = HTMLReactParser(project.fonts.adobe);
16
- const parsedFonts = {
17
- ...(typeof googleFonts === 'object' ? googleFonts : {}),
18
- ...(typeof adobeFonts === 'object' ? adobeFonts : {})
19
- };
20
- const customFonts = project.fonts.custom;
21
- const htmlHead = HTMLReactParser(project.html.head);
22
14
  const afterBodyOpen = HTMLReactParser(project.html.afterBodyOpen);
23
15
  const beforeBodyClose = HTMLReactParser(project.html.beforeBodyClose);
24
- const ffGenerator = new FontFaceGenerator(customFonts);
25
16
  return (
26
17
  <>
27
- <Head>
28
- <title>{meta.title}</title>
29
- <meta name="description" content={meta.description} />
30
- <meta name="keywords" content={meta.keywords} />
31
- <meta property="og:image" content={meta.opengraphThumbnail} />
32
- <link rel="icon" href={meta.favicon} />
33
- {customFonts.length > 0 && (
34
- <style
35
- dangerouslySetInnerHTML={{
36
- __html: ffGenerator.generate()
37
- }}
38
- />
39
- )}
40
- {Object.values(parsedFonts as ReturnType<typeof domToReact>).map((value, i) => {
41
- if (!value) return undefined;
42
- const rel = value?.rel || value.props?.rel;
43
- const href = value?.href || value.props?.href;
44
- if (!rel || !href) return undefined;
45
- return (
46
- <link key={i} rel={rel} href={href} />
47
- );
48
- })}
49
- {htmlHead}
50
-
51
- </Head>
18
+ <CNTRLHead project={project} meta={meta} />
52
19
  {afterBodyOpen}
53
20
  <Article article={article} layouts={project.layouts} />
54
21
  {beforeBodyClose}
@@ -1,5 +1,5 @@
1
1
  import { FC, ReactElement } from 'react';
2
- import { getLayoutMediaQuery, getLayoutStyles, TArticleSection, TLayout } from '@cntrl-site/sdk';
2
+ import { getLayoutMediaQuery, getLayoutStyles, TArticleSection, TLayout, TSectionHeight, SectionHeightMode } from '@cntrl-site/sdk';
3
3
 
4
4
  type SectionChild = ReactElement<any, any>;
5
5
 
@@ -34,13 +34,27 @@ export const Section: FC<Props> = ({ section, layouts, children }) => {
34
34
  ${
35
35
  getLayoutStyles(layouts, [section.height], ([height]) => (`
36
36
  .section-${section.id} {
37
- height: ${height * 100}vw;
37
+ height: ${getSectionHeight(height)};
38
38
  position: relative;
39
39
  }`
40
40
  ))
41
41
  }
42
+ ${
43
+ getLayoutStyles(layouts, [section.color], ([color]) => (`
44
+ .section-${section.id} {
45
+ background-color: ${color ? color : 'transparent'};
46
+ }`
47
+ ))
48
+ }
42
49
  ${getSectionVisibilityStyles()}
43
50
  `}</style>
44
51
  </>
45
52
  );
46
53
  };
54
+
55
+ function getSectionHeight(heightData: TSectionHeight): string {
56
+ const { units, vhUnits, mode } = heightData;
57
+ if (mode === SectionHeightMode.ViewportHeightUnits) return `${vhUnits}vh`;
58
+ if (mode === SectionHeightMode.ControlUnits) return `${units * 100}vw`;
59
+ return '0';
60
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from '@cntrl-site/sdk';
4
4
 
5
5
  export { RichTextConverter } from './utils/RichTextConverter';
6
6
  export { Page } from './components/Page';
7
+ export { CNTRLHead as Head } from './components/Head';
7
8
  export { Article } from './components/Article';
8
9
  export { Section } from './components/Section';
9
10
  export { Item } from './components/Item';
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>