@cntrl-site/sdk-nextjs 0.0.5 → 0.0.8

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.
@@ -8,7 +8,7 @@ const Article = ({ article, layouts }) => {
8
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: `
9
9
  .article {
10
10
  position: relative;
11
- overflow-x: hidden;
11
+ overflow: hidden;
12
12
  }
13
13
  ` })] }));
14
14
  };
@@ -0,0 +1,19 @@
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.LayoutStyle = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const core_1 = require("@cntrl-site/core");
9
+ // @ts-ignore
10
+ const style_1 = __importDefault(require("styled-jsx/style"));
11
+ const LayoutStyle = ({ id, layouts, layoutId, children }) => {
12
+ const layout = layouts.find(l => l.id === layoutId);
13
+ return ((0, jsx_runtime_1.jsx)(style_1.default, { id: id, children: `
14
+ ${(0, core_1.getLayoutMediaQuery)(layoutId, layouts)} {
15
+ ${children?.(layout)}
16
+ }
17
+ ` }));
18
+ };
19
+ exports.LayoutStyle = LayoutStyle;
package/lib/index.js CHANGED
@@ -1,6 +1,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Page = exports.RichTextConverter = void 0;
17
+ exports.LayoutStyle = exports.VideoItem = exports.RichTextItem = exports.RectangleItem = exports.ImageItem = exports.Item = exports.Section = exports.Article = exports.Page = exports.RichTextConverter = void 0;
18
+ __exportStar(require("@cntrl-site/core"), exports);
19
+ __exportStar(require("@cntrl-site/sdk"), exports);
4
20
  var RichTextConverter_1 = require("./utils/RichTextConverter");
5
21
  Object.defineProperty(exports, "RichTextConverter", { enumerable: true, get: function () { return RichTextConverter_1.RichTextConverter; } });
6
22
  var Page_1 = require("./components/Page");
@@ -19,3 +35,5 @@ var RichTextItem_1 = require("./components/items/RichTextItem");
19
35
  Object.defineProperty(exports, "RichTextItem", { enumerable: true, get: function () { return RichTextItem_1.RichTextItem; } });
20
36
  var VideoItem_1 = require("./components/items/VideoItem");
21
37
  Object.defineProperty(exports, "VideoItem", { enumerable: true, get: function () { return VideoItem_1.VideoItem; } });
38
+ var LayoutStyle_1 = require("./components/LayoutStyle");
39
+ Object.defineProperty(exports, "LayoutStyle", { enumerable: true, get: function () { return LayoutStyle_1.LayoutStyle; } });
@@ -10,7 +10,8 @@ exports.FontStyles = {
10
10
  };
11
11
  class RichTextConverter {
12
12
  toHtml(richText, layouts) {
13
- const { text, blocks = [] } = richText.commonParams;
13
+ const { text: rawText, blocks = [] } = richText.commonParams;
14
+ const text = Array.from(rawText); // because of emoji
14
15
  const root = [];
15
16
  const styleRules = layouts.reduce((rec, layout) => {
16
17
  rec[layout.id] = [];
@@ -65,18 +66,18 @@ class RichTextConverter {
65
66
  for (const entity of entitiesGroups) {
66
67
  const entityKids = [];
67
68
  if (offset < entity.start) {
68
- kids.push(content.slice(offset, entity.start));
69
+ kids.push(content.slice(offset, entity.start).join(''));
69
70
  offset = entity.start;
70
71
  }
71
72
  for (const style of entity.stylesGroup) {
72
73
  if (offset < style.start) {
73
- entityKids.push(content.slice(offset, style.start));
74
+ entityKids.push(content.slice(offset, style.start).join(''));
74
75
  }
75
- entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}`, children: content.slice(style.start, style.end) }, style.start));
76
+ entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}`, children: content.slice(style.start, style.end).join('') }, style.start));
76
77
  offset = style.end;
77
78
  }
78
79
  if (offset < entity.end) {
79
- entityKids.push(content.slice(offset, entity.end));
80
+ entityKids.push(content.slice(offset, entity.end).join(''));
80
81
  offset = entity.end;
81
82
  }
82
83
  if (entity.link) {
@@ -86,7 +87,7 @@ class RichTextConverter {
86
87
  kids.push(...entityKids);
87
88
  }
88
89
  if (offset < content.length) {
89
- kids.push(content.slice(offset));
90
+ kids.push(content.slice(offset).join(''));
90
91
  }
91
92
  for (const item of group) {
92
93
  const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "description": "SDK for Next.js",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/index.js",
@@ -23,7 +23,7 @@ export const Article: FC<Props> = ({ article, layouts }) => {
23
23
  <style jsx>{`
24
24
  .article {
25
25
  position: relative;
26
- overflow-x: hidden;
26
+ overflow: hidden;
27
27
  }
28
28
  `}</style>
29
29
  </>
@@ -0,0 +1,22 @@
1
+ import React, { FC } from 'react';
2
+ import { getLayoutMediaQuery, TLayout } from '@cntrl-site/core';
3
+ // @ts-ignore
4
+ import JSXStyle from 'styled-jsx/style';
5
+
6
+ export interface LayoutStyleProps {
7
+ id: string;
8
+ layouts: TLayout[];
9
+ layoutId: string;
10
+ children?: (layout: TLayout) => string;
11
+ }
12
+
13
+ export const LayoutStyle: FC<LayoutStyleProps> = ({ id, layouts, layoutId, children }) => {
14
+ const layout = layouts.find(l => l.id === layoutId)!;
15
+ return (
16
+ <JSXStyle id={id}>{`
17
+ ${getLayoutMediaQuery(layoutId, layouts)} {
18
+ ${children?.(layout)}
19
+ }
20
+ `}</JSXStyle>
21
+ );
22
+ };
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
- export { RichTextConverter } from './utils/RichTextConverter';
1
+ export * from '@cntrl-site/core';
2
+ export * from '@cntrl-site/sdk';
2
3
 
4
+ export { RichTextConverter } from './utils/RichTextConverter';
3
5
  export { Page } from './components/Page';
4
6
  export { Article } from './components/Article';
5
7
  export { Section } from './components/Section';
@@ -8,3 +10,4 @@ export { ImageItem } from './components/items/ImageItem';
8
10
  export { RectangleItem } from './components/items/RectangleItem';
9
11
  export { RichTextItem } from './components/items/RichTextItem';
10
12
  export { VideoItem } from './components/items/VideoItem';
13
+ export { LayoutStyle } from './components/LayoutStyle';
@@ -38,7 +38,8 @@ export class RichTextConverter {
38
38
  richText: TRichTextItem,
39
39
  layouts: TLayout[]
40
40
  ): [ReactNode[], string] {
41
- const { text, blocks = [] } = richText.commonParams;
41
+ const { text: rawText, blocks = [] } = richText.commonParams;
42
+ const text = Array.from(rawText); // because of emoji
42
43
  const root: ReactElement[] = [];
43
44
  const styleRules = layouts.reduce<Record<string, string[]>>((rec, layout) => {
44
45
  rec[layout.id] = [];
@@ -94,18 +95,18 @@ export class RichTextConverter {
94
95
  for (const entity of entitiesGroups) {
95
96
  const entityKids: ReactNode[] = [];
96
97
  if (offset < entity.start) {
97
- kids.push(content.slice(offset, entity.start));
98
+ kids.push(content.slice(offset, entity.start).join(''));
98
99
  offset = entity.start;
99
100
  }
100
101
  for (const style of entity.stylesGroup) {
101
102
  if (offset < style.start) {
102
- entityKids.push(content.slice(offset, style.start));
103
+ entityKids.push(content.slice(offset, style.start).join(''));
103
104
  }
104
- entityKids.push(<span key={style.start} className={`s-${style.start}-${style.end}`}>{content.slice(style.start, style.end)}</span>);
105
+ entityKids.push(<span key={style.start} className={`s-${style.start}-${style.end}`}>{content.slice(style.start, style.end).join('')}</span>);
105
106
  offset = style.end;
106
107
  }
107
108
  if (offset < entity.end) {
108
- entityKids.push(content.slice(offset, entity.end));
109
+ entityKids.push(content.slice(offset, entity.end).join(''));
109
110
  offset = entity.end;
110
111
  }
111
112
  if (entity.link) {
@@ -115,7 +116,7 @@ export class RichTextConverter {
115
116
  kids.push(...entityKids);
116
117
  }
117
118
  if (offset < content.length) {
118
- kids.push(content.slice(offset));
119
+ kids.push(content.slice(offset).join(''));
119
120
  }
120
121
  for (const item of group) {
121
122
  const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];