@cntrl-site/sdk-nextjs 0.6.0 → 0.7.0

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,15 @@
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>
Binary file
Binary file
@@ -5,20 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RichTextItem = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- const react_1 = require("react");
9
8
  //@ts-ignore
10
9
  const style_1 = __importDefault(require("styled-jsx/style"));
11
10
  const RichTextConverter_1 = require("../../utils/RichTextConverter/RichTextConverter");
12
- const useCntrlContext_1 = require("../../provider/useCntrlContext");
11
+ const useRichTextItem_1 = require("./useRichTextItem");
13
12
  const richTextConv = new RichTextConverter_1.RichTextConverter();
14
13
  const RichTextItem = ({ item }) => {
15
- const { layouts, typePresets } = (0, useCntrlContext_1.useCntrlContext)();
16
- const preset = item.commonParams.preset
17
- ? typePresets?.presets.find(p => p.id === item.commonParams.preset)
18
- : null;
19
- const [content, styles] = richTextConv.toHtml(item, layouts, !!preset);
20
- return (0, react_1.createElement)(preset?.tag ?? 'div', {
21
- className: preset ? `cntrl-preset-${preset.id}` : undefined
22
- }, ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [content, (0, jsx_runtime_1.jsx)(style_1.default, { id: item.id, children: styles })] })));
14
+ const [content, styles, preset] = (0, useRichTextItem_1.useRichTextItem)(item);
15
+ const className = preset ? `cntrl-preset-${preset.id}` : undefined;
16
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: className, children: content }), (0, jsx_runtime_1.jsx)(style_1.default, { id: item.id, children: styles })] }));
23
17
  };
24
18
  exports.RichTextItem = RichTextItem;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRichTextItem = void 0;
4
+ const useCurrentLayout_1 = require("../../common/useCurrentLayout");
5
+ const RichTextConverter_1 = require("../../utils/RichTextConverter/RichTextConverter");
6
+ const useCntrlContext_1 = require("../../provider/useCntrlContext");
7
+ const richTextConv = new RichTextConverter_1.RichTextConverter();
8
+ const useRichTextItem = (item) => {
9
+ const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
10
+ const { layouts, typePresets } = (0, useCntrlContext_1.useCntrlContext)();
11
+ const presetId = item.layoutParams[layoutId].preset;
12
+ const preset = presetId
13
+ ? typePresets?.presets.find(p => p.id === presetId) ?? null
14
+ : null;
15
+ const [content, styles] = richTextConv.toHtml(item, layouts, !!preset);
16
+ return [content, styles, preset];
17
+ };
18
+ exports.useRichTextItem = useRichTextItem;
@@ -6,14 +6,14 @@ const binSearchInsertAt_1 = require("../binSearchInsertAt");
6
6
  const compare = (lhs, rhs) => lhs.position - rhs.position;
7
7
  const insertBin = (0, binSearchInsertAt_1.createInsert)(binSearchInsertAt_1.binSearchInsertAt, compare);
8
8
  class Animator {
9
+ static pushKeyframeToMap(keyframe, map) {
10
+ insertBin(map[keyframe.type], keyframe);
11
+ }
9
12
  constructor(keyframes) {
10
13
  this.keyframes = keyframes;
11
14
  this.keyframesMap = createKeyframesMap();
12
15
  this.fillKeyframesMap();
13
16
  }
14
- static pushKeyframeToMap(keyframe, map) {
15
- insertBin(map[keyframe.type], keyframe);
16
- }
17
17
  getDimensions(values, pos) {
18
18
  const keyframes = this.keyframesMap[sdk_1.KeyframeType.Dimensions];
19
19
  if (!keyframes || !keyframes.length)
@@ -15,11 +15,11 @@ function generateTypePresetStyles(preset, layouts) {
15
15
  ${sorted.map(l => (`
16
16
  ${(0, sdk_1.getLayoutMediaQuery)(l.id, sorted)} {
17
17
  .cntrl-preset-${p.id} {
18
- font-size: ${p.layoutParams[l.id].fontSize * 100}vw;
19
- line-height: ${p.layoutParams[l.id].lineHeight * 100}vw;
20
- letter-spacing: ${p.layoutParams[l.id].letterSpacing * 100}vw;
21
- word-spacing: ${p.layoutParams[l.id].wordSpacing * 100}vw;
22
- color: ${sdk_1.CntrlColor.parse(p.layoutParams[l.id].color).toCss()};
18
+ font-size: ${p.fontSize / l.exemplary * 100}vw;
19
+ line-height: ${p.lineHeight / l.exemplary * 100}vw;
20
+ letter-spacing: ${p.letterSpacing / l.exemplary * 100}vw;
21
+ word-spacing: ${p.wordSpacing / l.exemplary * 100}vw;
22
+ color: ${sdk_1.CntrlColor.parse(p.color).toCss()};
23
23
  }
24
24
  }`)).join('\n')}`)).join('\n')}`);
25
25
  return stylesStr.replace(reEmptyLines, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/sdk-nextjs",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
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.4.4",
24
+ "@cntrl-site/sdk": "^0.6.2",
25
25
  "html-react-parser": "^3.0.1",
26
26
  "styled-jsx": "^5.0.2"
27
27
  },
@@ -40,7 +40,7 @@
40
40
  "@types/react": "^18.0.15",
41
41
  "jest": "^29.3.1",
42
42
  "ts-jest": "^29.0.3",
43
- "typescript": "^4.7.4"
43
+ "typescript": "^4.9.5"
44
44
  },
45
45
  "directories": {
46
46
  "lib": "lib"
@@ -1,4 +1,4 @@
1
- import { FC, useEffect, useMemo, useState } from 'react';
1
+ import { FC, useMemo } from 'react';
2
2
  import { TRectangleItem, CntrlColor } from '@cntrl-site/sdk';
3
3
  import { ItemProps } from '../Item';
4
4
  import { LinkWrapper } from '../LinkWrapper';
@@ -5,27 +5,19 @@ import JSXStyle from 'styled-jsx/style';
5
5
  import { ItemProps } from '../Item';
6
6
  import { RichTextConverter } from '../../utils/RichTextConverter/RichTextConverter';
7
7
  import { useCntrlContext } from '../../provider/useCntrlContext';
8
+ import { useRichTextItem } from './useRichTextItem';
8
9
 
9
10
  const richTextConv = new RichTextConverter();
10
11
 
11
12
  export const RichTextItem: FC<ItemProps<TRichTextItem>> = ({ item }) => {
12
- const { layouts, typePresets } = useCntrlContext();
13
- const preset = item.commonParams.preset
14
- ? typePresets?.presets.find(p => p.id === item.commonParams.preset)
15
- : null;
16
- const [content, styles] = richTextConv.toHtml(item, layouts, !!preset);
17
- return createElement(
18
- preset?.tag ?? 'div',
19
- {
20
- className: preset ? `cntrl-preset-${preset.id}` : undefined
21
- },
22
- (
23
- <>
24
- {content}
25
- <JSXStyle id={item.id}>
26
- {styles}
27
- </JSXStyle>
28
- </>
29
- )
13
+ const [content, styles, preset] = useRichTextItem(item);
14
+ const className = preset ? `cntrl-preset-${preset.id}` : undefined;
15
+ return (
16
+ <>
17
+ <div className={className}>{content}</div>
18
+ <JSXStyle id={item.id}>
19
+ {styles}
20
+ </JSXStyle>
21
+ </>
30
22
  );
31
23
  };
@@ -0,0 +1,18 @@
1
+ import { TRichTextItem, TTypePresetEntry } from '@cntrl-site/sdk';
2
+ import { useCurrentLayout } from '../../common/useCurrentLayout';
3
+ import { RichTextConverter } from '../../utils/RichTextConverter/RichTextConverter';
4
+ import { useCntrlContext } from '../../provider/useCntrlContext';
5
+ import { ReactNode } from 'react';
6
+
7
+ const richTextConv = new RichTextConverter();
8
+
9
+ export const useRichTextItem = (item: TRichTextItem): [ReactNode[], string, TTypePresetEntry | null] => {
10
+ const layoutId = useCurrentLayout();
11
+ const { layouts, typePresets } = useCntrlContext();
12
+ const presetId = item.layoutParams[layoutId].preset;
13
+ const preset = presetId
14
+ ? typePresets?.presets.find(p => p.id === presetId) ?? null
15
+ : null;
16
+ const [content, styles] = richTextConv.toHtml(item, layouts, !!preset);
17
+ return [content, styles, preset];
18
+ };
@@ -1,28 +1,4 @@
1
- import { AllowedTags, TTypePresets } from '@cntrl-site/sdk';
2
-
3
- const layoutParams = {
4
- 'desktop': {
5
- fontSize: 0.011111,
6
- lineHeight: 0.013888,
7
- wordSpacing: 0.0006944,
8
- letterSpacing: 0.0006944,
9
- color: 'rgba(0, 0, 0, 1)'
10
- },
11
- 'tablet': {
12
- fontSize: 0.02604,
13
- lineHeight: 0.03125,
14
- wordSpacing: 0,
15
- letterSpacing: 0,
16
- color: 'rgba(0, 0, 0, 1)'
17
- },
18
- 'mobile': {
19
- fontSize: 0.053333,
20
- lineHeight: 0.064,
21
- wordSpacing: 0.008,
22
- letterSpacing: 0.008,
23
- color: 'rgba(0, 0, 0, 1)'
24
- }
25
- };
1
+ import { TTypePresets, TypePresetStatus } from '@cntrl-site/sdk';
26
2
 
27
3
  export const presetMock: TTypePresets = {
28
4
  id: 'presetId',
@@ -33,17 +9,25 @@ export const presetMock: TTypePresets = {
33
9
  fontWeight: '400',
34
10
  fontStyle: '',
35
11
  name: 'Heading',
36
- tag: AllowedTags.h1,
37
- layoutParams
12
+ fontSize: 24,
13
+ lineHeight: 36,
14
+ wordSpacing: 1,
15
+ letterSpacing: 1,
16
+ color: 'rgba(0, 0, 0, 1)',
17
+ status: TypePresetStatus.Active
38
18
  },
39
19
  {
40
20
  id: 'heading02',
41
21
  fontFamily: 'Aeonik',
42
22
  fontWeight: '400',
43
23
  fontStyle: 'italic',
44
- name: 'Heading',
45
- tag: AllowedTags.h1,
46
- layoutParams
24
+ name: 'Heading 2',
25
+ fontSize: 24,
26
+ lineHeight: 36,
27
+ wordSpacing: 1,
28
+ letterSpacing: 1,
29
+ color: 'rgba(0, 0, 0, 1)',
30
+ status: TypePresetStatus.Active
47
31
  }
48
32
  ]
49
33
  };
@@ -8,28 +8,28 @@ describe('generateTypePresetStyles', () => {
8
8
  const expectedMedia = (id: string) =>
9
9
  `@media (min-width: 0px) and (max-width: 767px) {
10
10
  .cntrl-preset-${id} {
11
- font-size: 5.3332999999999995vw;
12
- line-height: 6.4vw;
13
- letter-spacing: 0.8vw;
14
- word-spacing: 0.8vw;
11
+ font-size: 6.4vw;
12
+ line-height: 9.6vw;
13
+ letter-spacing: 0.26666666666666666vw;
14
+ word-spacing: 0.26666666666666666vw;
15
15
  color: rgba(0, 0, 0, 1);
16
16
  }
17
17
  }
18
18
  @media (min-width: 768px) and (max-width: 1023px) {
19
19
  .cntrl-preset-${id} {
20
- font-size: 2.604vw;
21
- line-height: 3.125vw;
22
- letter-spacing: 0vw;
23
- word-spacing: 0vw;
20
+ font-size: 3.125vw;
21
+ line-height: 4.6875vw;
22
+ letter-spacing: 0.13020833333333331vw;
23
+ word-spacing: 0.13020833333333331vw;
24
24
  color: rgba(0, 0, 0, 1);
25
25
  }
26
26
  }
27
27
  @media (min-width: 1024px) {
28
28
  .cntrl-preset-${id} {
29
- font-size: 1.1111vw;
30
- line-height: 1.3888vw;
31
- letter-spacing: 0.06944vw;
32
- word-spacing: 0.06944vw;
29
+ font-size: 1.6666666666666667vw;
30
+ line-height: 2.5vw;
31
+ letter-spacing: 0.06944444444444445vw;
32
+ word-spacing: 0.06944444444444445vw;
33
33
  color: rgba(0, 0, 0, 1);
34
34
  }
35
35
  }`;
@@ -14,11 +14,11 @@ export function generateTypePresetStyles(preset: TTypePresets, layouts: TLayout[
14
14
  ${sorted.map(l => (`
15
15
  ${getLayoutMediaQuery(l.id, sorted)} {
16
16
  .cntrl-preset-${p.id} {
17
- font-size: ${p.layoutParams[l.id].fontSize * 100}vw;
18
- line-height: ${p.layoutParams[l.id].lineHeight * 100}vw;
19
- letter-spacing: ${p.layoutParams[l.id].letterSpacing * 100}vw;
20
- word-spacing: ${p.layoutParams[l.id].wordSpacing * 100}vw;
21
- color: ${CntrlColor.parse(p.layoutParams[l.id].color).toCss()};
17
+ font-size: ${p.fontSize / l.exemplary * 100}vw;
18
+ line-height: ${p.lineHeight / l.exemplary * 100}vw;
19
+ letter-spacing: ${p.letterSpacing / l.exemplary * 100}vw;
20
+ word-spacing: ${p.wordSpacing / l.exemplary * 100}vw;
21
+ color: ${CntrlColor.parse(p.color).toCss()};
22
22
  }
23
23
  }`)).join('\n')}`)).join('\n')}`);
24
24
  return stylesStr.replace(reEmptyLines, '');