@cntrl-site/sdk-nextjs 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
+ </state>
5
+ </component>
@@ -2,14 +2,18 @@
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");
5
6
  const Section_1 = require("./Section");
6
7
  const Item_1 = require("./Item");
7
8
  const Article = ({ article, layouts }) => {
8
9
  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]) => (`
9
11
  .article {
10
12
  position: relative;
11
13
  overflow: hidden;
14
+ background-color: ${color ? color : 'transparent'};
12
15
  }
16
+ `))}
13
17
  ` })] }));
14
18
  };
15
19
  exports.Article = Article;
@@ -7,11 +7,13 @@ const RectangleItem_1 = require("./items/RectangleItem");
7
7
  const ImageItem_1 = require("./items/ImageItem");
8
8
  const VideoItem_1 = require("./items/VideoItem");
9
9
  const RichTextItem_1 = require("./items/RichTextItem");
10
+ const VimeoEmbed_1 = require("./items/VimeoEmbed");
10
11
  const itemsMap = {
11
12
  [sdk_1.ArticleItemType.Rectangle]: RectangleItem_1.RectangleItem,
12
13
  [sdk_1.ArticleItemType.Image]: ImageItem_1.ImageItem,
13
14
  [sdk_1.ArticleItemType.Video]: VideoItem_1.VideoItem,
14
- [sdk_1.ArticleItemType.RichText]: RichTextItem_1.RichTextItem
15
+ [sdk_1.ArticleItemType.RichText]: RichTextItem_1.RichTextItem,
16
+ [sdk_1.ArticleItemType.VimeoEmbed]: VimeoEmbed_1.VimeoEmbed
15
17
  };
16
18
  const noop = () => null;
17
19
  const Item = ({ item, layouts }) => {
@@ -22,12 +24,12 @@ const Item = ({ item, layouts }) => {
22
24
  const sizingAxis = parseSizing(item.commonParams.sizing);
23
25
  const ItemComponent = itemsMap[item.type] || noop;
24
26
  return ((0, jsx_runtime_1.jsxs)("div", { className: `item-${item.id}`, children: [(0, jsx_runtime_1.jsx)(ItemComponent, { item: item, layouts: layouts }), (0, jsx_runtime_1.jsx)("style", { jsx: true, children: `
25
- ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area, layoutParams]) => (`
27
+ ${(0, sdk_1.getLayoutStyles)(layouts, layoutValues, ([area]) => (`
26
28
  .item-${item.id} {
27
29
  position: absolute;
28
30
  top: ${area.top * 100}vw;
29
- left: ${layoutParams?.fullwidth ? 0 : area.left * 100}vw;
30
- width: ${layoutParams?.fullwidth ? '100vw' : sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'auto'};
31
+ left: ${area.left * 100}vw;
32
+ width: ${sizingAxis.x === sdk_1.ArticleItemSizingType.Manual ? `${area.width * 100}vw` : 'auto'};
31
33
  height: ${sizingAxis.y === sdk_1.ArticleItemSizingType.Manual ? `${area.height * 100}vw` : 'auto'};
32
34
  z-index: ${area.zIndex};
33
35
  transform: rotate(${area.angle}deg);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VimeoEmbed = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const VimeoEmbed = () => (
6
+ // TODO
7
+ (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}));
8
+ exports.VimeoEmbed = VimeoEmbed;
@@ -19,7 +19,7 @@ class RichTextConverter {
19
19
  return rec;
20
20
  }, {});
21
21
  let currentLineHeight = layouts.reduce((rec, layout) => {
22
- const styles = (0, sdk_1.getClosestLayoutValue)(richText.layoutParams, layouts, layout.id)?.styles;
22
+ const styles = richText.layoutParams[layout.id].styles;
23
23
  rec[layout.id] = styles?.find(s => s.style === 'LINEHEIGHT')?.value ?? '0';
24
24
  return rec;
25
25
  }, {});
@@ -39,7 +39,7 @@ class RichTextConverter {
39
39
  continue;
40
40
  }
41
41
  const newStylesGroup = layouts.map(({ id: layoutId }) => {
42
- const params = (0, sdk_1.getClosestLayoutValue)(richText.layoutParams, layouts, layoutId);
42
+ const params = richText.layoutParams[layoutId];
43
43
  const styles = params.styles
44
44
  .filter(s => s.start >= block.start && s.end <= block.end)
45
45
  .map(s => ({ ...s, start: s.start - block.start, end: s.end - block.start }));
@@ -53,7 +53,7 @@ class RichTextConverter {
53
53
  const blockClass = `rt_${richText.id}-b${blockIndex}_${layouts.map(l => group.some(g => g.layout === l.id) ? '1' : '0').join('')}`;
54
54
  const kids = [];
55
55
  layouts.forEach(l => {
56
- const ta = (0, sdk_1.getClosestLayoutValue)(richText.layoutParams, layouts, l.id).textAlign;
56
+ const ta = richText.layoutParams[l.id].textAlign;
57
57
  const whiteSpace = ta === sdk_1.TextAlign.Justify || ta === sdk_1.TextAlign.Right ? 'normal' : 'pre-wrap';
58
58
  styleRules[l.id].push(`
59
59
  .${blockClass} {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
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.6",
24
+ "@cntrl-site/sdk": "^0.2.8",
25
25
  "html-react-parser": "^3.0.1",
26
26
  "styled-jsx": "^5.0.2"
27
27
  },
@@ -33,6 +33,7 @@
33
33
  "devDependencies": {
34
34
  "@tsconfig/node16": "^1.0.3",
35
35
  "@tsconfig/recommended": "^1.0.1",
36
+ "@types/node": "^18.11.7",
36
37
  "@types/react": "^18.0.15",
37
38
  "typescript": "^4.7.4"
38
39
  },
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { TArticle, TLayout } from '@cntrl-site/sdk';
2
+ import { TArticle, TLayout, getLayoutStyles } from '@cntrl-site/sdk';
3
3
  import { Section } from './Section';
4
4
  import { Item } from './Item';
5
5
 
@@ -21,10 +21,13 @@ export const Article: FC<Props> = ({ article, layouts }) => {
21
21
  ))}
22
22
  </div>
23
23
  <style jsx>{`
24
+ ${getLayoutStyles(layouts, [article.color], ([color]) => (`
24
25
  .article {
25
26
  position: relative;
26
27
  overflow: hidden;
28
+ background-color: ${color ? color : 'transparent'};
27
29
  }
30
+ `))}
28
31
  `}</style>
29
32
  </>
30
33
  );
@@ -10,6 +10,7 @@ import { RectangleItem } from './items/RectangleItem';
10
10
  import { ImageItem } from './items/ImageItem';
11
11
  import { VideoItem } from './items/VideoItem';
12
12
  import { RichTextItem } from './items/RichTextItem';
13
+ import { VimeoEmbed } from './items/VimeoEmbed';
13
14
 
14
15
  export interface ItemProps<I extends TArticleItemAny> {
15
16
  layouts: TLayout[];
@@ -20,7 +21,8 @@ const itemsMap: Record<ArticleItemType, ComponentType<ItemProps<any>>> = {
20
21
  [ArticleItemType.Rectangle]: RectangleItem,
21
22
  [ArticleItemType.Image]: ImageItem,
22
23
  [ArticleItemType.Video]: VideoItem,
23
- [ArticleItemType.RichText]: RichTextItem
24
+ [ArticleItemType.RichText]: RichTextItem,
25
+ [ArticleItemType.VimeoEmbed]: VimeoEmbed
24
26
  };
25
27
 
26
28
  const noop = () => null;
@@ -38,12 +40,12 @@ export const Item: FC<ItemProps<TArticleItemAny>> = ({ item, layouts }) => {
38
40
  <div className={`item-${item.id}`}>
39
41
  <ItemComponent item={item} layouts={layouts} />
40
42
  <style jsx>{`
41
- ${getLayoutStyles(layouts, layoutValues, ([area, layoutParams]) => (`
43
+ ${getLayoutStyles(layouts, layoutValues, ([area]) => (`
42
44
  .item-${item.id} {
43
45
  position: absolute;
44
46
  top: ${area.top * 100}vw;
45
- left: ${layoutParams?.fullwidth ? 0 : area.left * 100}vw;
46
- width: ${layoutParams?.fullwidth ? '100vw' : sizingAxis.x === SizingType.Manual ? `${area.width * 100}vw` : 'auto'};
47
+ left: ${area.left * 100}vw;
48
+ width: ${sizingAxis.x === SizingType.Manual ? `${area.width * 100}vw` : 'auto'};
47
49
  height: ${sizingAxis.y === SizingType.Manual ? `${area.height * 100}vw` : 'auto'};
48
50
  z-index: ${area.zIndex};
49
51
  transform: rotate(${area.angle}deg);
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ import { ItemProps } from '../Item';
3
+ import { VimeoEmbedItem } from '@cntrl-site/core/src/article/ArticleItems';
4
+
5
+ export const VimeoEmbed:FC<ItemProps<VimeoEmbedItem>> = () => (
6
+ // TODO
7
+ <>
8
+ </>
9
+ )
@@ -1,6 +1,5 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
2
  import {
3
- getClosestLayoutValue,
4
3
  getLayoutMediaQuery,
5
4
  RichText,
6
5
  TextAlign,
@@ -48,7 +47,7 @@ export class RichTextConverter {
48
47
  return rec;
49
48
  }, {});
50
49
  let currentLineHeight = layouts.reduce<Record<string, string>>((rec, layout) => {
51
- const styles = getClosestLayoutValue(richText.layoutParams, layouts, layout.id)?.styles;
50
+ const styles = richText.layoutParams[layout.id].styles;
52
51
  rec[layout.id] = styles?.find(s => s.style === 'LINEHEIGHT')?.value ?? '0';
53
52
  return rec;
54
53
  }, {});
@@ -69,7 +68,7 @@ export class RichTextConverter {
69
68
  continue;
70
69
  }
71
70
  const newStylesGroup = layouts.map(({ id: layoutId }) => {
72
- const params = getClosestLayoutValue(richText.layoutParams, layouts, layoutId);
71
+ const params = richText.layoutParams[layoutId];
73
72
  const styles = params.styles!
74
73
  .filter(s => s.start >= block.start && s.end <= block.end)
75
74
  .map(s => ({ ...s, start: s.start - block.start, end: s.end - block.start }));
@@ -83,7 +82,7 @@ export class RichTextConverter {
83
82
  const blockClass = `rt_${richText.id}-b${blockIndex}_${layouts.map(l => group.some(g => g.layout === l.id) ? '1' : '0').join('')}`;
84
83
  const kids: ReactNode[] = [];
85
84
  layouts.forEach(l => {
86
- const ta = getClosestLayoutValue(richText.layoutParams, layouts, l.id).textAlign;
85
+ const ta = richText.layoutParams[l.id].textAlign;
87
86
  const whiteSpace = ta === TextAlign.Justify || ta === TextAlign.Right ? 'normal' : 'pre-wrap';
88
87
  styleRules[l.id].push(`
89
88
  .${blockClass} {
Binary file