@cntrl-site/sdk-nextjs 0.2.9 → 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;
@@ -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
+ }
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.2.9",
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
  );
@@ -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,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
+ }
@@ -1,15 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
5
- <option name="myValues">
6
- <value>
7
- <list size="1">
8
- <item index="0" class="java.lang.String" itemvalue="jsx" />
9
- </list>
10
- </value>
11
- </option>
12
- <option name="myCustomValuesEnabled" value="true" />
13
- </inspection_tool>
14
- </profile>
15
- </component>