@cntrl-site/sdk-nextjs 0.6.0 → 0.7.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.
- package/.idea/inspectionProfiles/Project_Default.xml +15 -0
- package/cntrl-site-sdk-nextjs-0.4.3.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.7.0.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.7.1.tgz +0 -0
- package/lib/common/useCurrentLayout.js +5 -0
- package/lib/components/items/RichTextItem.js +4 -10
- package/lib/components/items/useItemSticky.js +7 -1
- package/lib/components/items/useRichTextItem.js +18 -0
- package/lib/utils/Animator/Animator.js +3 -3
- package/lib/utils/generateTypePresetStyles/generateTypePresetStyles.js +5 -5
- package/package.json +3 -3
- package/src/common/useCurrentLayout.ts +6 -0
- package/src/components/items/RectangleItem.tsx +1 -1
- package/src/components/items/RichTextItem.tsx +10 -18
- package/src/components/items/useItemSticky.ts +9 -1
- package/src/components/items/useRichTextItem.ts +18 -0
- package/src/utils/generateTypePresetStyles/__mock__/presetMock.ts +14 -30
- package/src/utils/generateTypePresetStyles/generateTypePresetStyles.test.ts +12 -12
- package/src/utils/generateTypePresetStyles/generateTypePresetStyles.ts +5 -5
|
@@ -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
|
|
Binary file
|
|
@@ -25,6 +25,11 @@ const useCurrentLayout = () => {
|
|
|
25
25
|
return layoutRanges.find(l => articleWidth >= l.start && articleWidth < l.end).layoutId;
|
|
26
26
|
}, [layoutRanges]);
|
|
27
27
|
const [layoutId, setLayoutId] = (0, react_1.useState)(getCurrentLayout(0));
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
if (typeof window !== 'undefined') {
|
|
30
|
+
getCurrentLayout(window.innerWidth);
|
|
31
|
+
}
|
|
32
|
+
}, []);
|
|
28
33
|
(0, react_1.useEffect)(() => {
|
|
29
34
|
if (!articleRectObserver)
|
|
30
35
|
return;
|
|
@@ -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
|
|
11
|
+
const useRichTextItem_1 = require("./useRichTextItem");
|
|
13
12
|
const richTextConv = new RichTextConverter_1.RichTextConverter();
|
|
14
13
|
const RichTextItem = ({ item }) => {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
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;
|
|
@@ -12,11 +12,17 @@ const useItemSticky = (top, parentOffsetTop, item) => {
|
|
|
12
12
|
const articleRectObserver = (0, react_1.useContext)(ArticleRectContext_1.ArticleRectContext);
|
|
13
13
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
14
14
|
const sticky = (0, react_1.useMemo)(() => item.layoutParams[layoutId].sticky, [layoutId]);
|
|
15
|
-
const stickyManager = (0, react_1.useMemo)(() => new StickyManager_1.StickyManager(sticky), []);
|
|
15
|
+
const stickyManager = (0, react_1.useMemo)(() => new StickyManager_1.StickyManager(sticky), [sticky]);
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
setAdjustedTop(top);
|
|
18
|
+
}, [layoutId, top]);
|
|
16
19
|
const handleSticky = (0, react_1.useCallback)((scroll) => {
|
|
17
20
|
setIsFixed(stickyManager.getIsSticky(scroll));
|
|
18
21
|
setAdjustedTop(stickyManager.getPosition(scroll, top, parentOffsetTop));
|
|
19
22
|
}, [top, stickyManager, parentOffsetTop]);
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
setAdjustedTop(top);
|
|
25
|
+
}, [top]);
|
|
20
26
|
(0, react_1.useEffect)(() => {
|
|
21
27
|
if (!articleRectObserver || !sticky)
|
|
22
28
|
return;
|
|
@@ -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.
|
|
19
|
-
line-height: ${p.
|
|
20
|
-
letter-spacing: ${p.
|
|
21
|
-
word-spacing: ${p.
|
|
22
|
-
color: ${sdk_1.CntrlColor.parse(p.
|
|
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.
|
|
3
|
+
"version": "0.7.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.
|
|
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.
|
|
43
|
+
"typescript": "^4.9.5"
|
|
44
44
|
},
|
|
45
45
|
"directories": {
|
|
46
46
|
"lib": "lib"
|
|
@@ -30,6 +30,12 @@ export const useCurrentLayout = () => {
|
|
|
30
30
|
}, [layoutRanges]);
|
|
31
31
|
const [layoutId, setLayoutId] = useState<string>(getCurrentLayout(0));
|
|
32
32
|
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (typeof window !== 'undefined') {
|
|
35
|
+
getCurrentLayout(window.innerWidth);
|
|
36
|
+
}
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
33
39
|
useEffect(() => {
|
|
34
40
|
if (!articleRectObserver) return;
|
|
35
41
|
return articleRectObserver.on('resize', () => {
|
|
@@ -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
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
};
|
|
@@ -10,7 +10,11 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
|
|
|
10
10
|
const articleRectObserver = useContext(ArticleRectContext);
|
|
11
11
|
const layoutId = useCurrentLayout();
|
|
12
12
|
const sticky = useMemo(() => item.layoutParams[layoutId].sticky, [layoutId]);
|
|
13
|
-
const stickyManager = useMemo(() => new StickyManager(sticky), []);
|
|
13
|
+
const stickyManager = useMemo(() => new StickyManager(sticky), [sticky]);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
setAdjustedTop(top);
|
|
17
|
+
}, [layoutId, top]);
|
|
14
18
|
|
|
15
19
|
const handleSticky = useCallback((scroll: number) => {
|
|
16
20
|
setIsFixed(stickyManager.getIsSticky(scroll));
|
|
@@ -21,6 +25,10 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
|
|
|
21
25
|
));
|
|
22
26
|
}, [top, stickyManager, parentOffsetTop]);
|
|
23
27
|
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setAdjustedTop(top);
|
|
30
|
+
}, [top]);
|
|
31
|
+
|
|
24
32
|
useEffect(() => {
|
|
25
33
|
if (!articleRectObserver || !sticky) return;
|
|
26
34
|
return articleRectObserver.on('scroll', () => {
|
|
@@ -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 {
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
46
|
-
|
|
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:
|
|
12
|
-
line-height:
|
|
13
|
-
letter-spacing: 0.
|
|
14
|
-
word-spacing: 0.
|
|
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:
|
|
21
|
-
line-height:
|
|
22
|
-
letter-spacing:
|
|
23
|
-
word-spacing:
|
|
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.
|
|
30
|
-
line-height:
|
|
31
|
-
letter-spacing: 0.
|
|
32
|
-
word-spacing: 0.
|
|
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.
|
|
18
|
-
line-height: ${p.
|
|
19
|
-
letter-spacing: ${p.
|
|
20
|
-
word-spacing: ${p.
|
|
21
|
-
color: ${CntrlColor.parse(p.
|
|
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, '');
|