@cntrl-site/sdk-nextjs 0.8.2 → 0.8.4
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/cntrl-site-sdk-nextjs-0.7.1.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.8.4.tgz +0 -0
- package/lib/common/useKeyframeValue.js +21 -11
- package/lib/components/items/useItemSticky.js +4 -2
- package/lib/utils/ArticleRectManager/ArticleRectObserver.js +1 -0
- package/lib/utils/RichTextConverter/RichTextConverter.js +3 -2
- package/package.json +1 -1
- package/src/common/useKeyframeValue.ts +21 -11
- package/src/components/items/useItemSticky.ts +3 -2
- package/src/utils/ArticleRectManager/ArticleRectObserver.ts +1 -0
- package/src/utils/RichTextConverter/RichTextConverter.tsx +5 -3
- package/.idea/inspectionProfiles/Project_Default.xml +0 -15
- package/cntrl-site-sdk-nextjs-0.7.2.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.8.0.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.8.1.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.8.2.tgz +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -19,7 +19,7 @@ const useKeyframeValue = (item, itemParamsGetter, animatorGetter, deps = emptyDe
|
|
|
19
19
|
const articleRectObserver = (0, react_1.useContext)(ArticleRectContext_1.ArticleRectContext);
|
|
20
20
|
const layoutId = (0, useCurrentLayout_1.useCurrentLayout)();
|
|
21
21
|
const keyframesRepo = (0, react_1.useContext)(KeyframesContext_1.KeyframesContext);
|
|
22
|
-
const keyframes = keyframesRepo.getItemKeyframes(item.id);
|
|
22
|
+
const keyframes = (0, react_1.useMemo)(() => keyframesRepo.getItemKeyframes(item.id), [item.id, keyframesRepo]);
|
|
23
23
|
const paramValue = (0, react_1.useMemo)(() => {
|
|
24
24
|
return itemParamsGetterRef.current(item, layoutId);
|
|
25
25
|
}, [item, layoutId, ...deps]);
|
|
@@ -38,29 +38,39 @@ const useKeyframeValue = (item, itemParamsGetter, animatorGetter, deps = emptyDe
|
|
|
38
38
|
}));
|
|
39
39
|
return new Animator_1.Animator(animationData);
|
|
40
40
|
}, [keyframes, layoutId]);
|
|
41
|
+
const handleKeyframeValue = (0, react_1.useCallback)((scroll) => {
|
|
42
|
+
if (!animator)
|
|
43
|
+
return;
|
|
44
|
+
const newValue = animatorGetterRef.current(animator, scroll, paramValue);
|
|
45
|
+
if (!(0, lodash_isequal_1.default)(newValue, adjustedValueRef.current)) {
|
|
46
|
+
setAdjustedValue(newValue);
|
|
47
|
+
}
|
|
48
|
+
}, [animator, paramValue]);
|
|
41
49
|
(0, react_1.useEffect)(() => {
|
|
42
50
|
setAdjustedValue(paramValue);
|
|
43
51
|
}, [paramValue]);
|
|
44
52
|
(0, react_1.useEffect)(() => {
|
|
45
|
-
if (!
|
|
53
|
+
if (!articleRectObserver)
|
|
54
|
+
return;
|
|
55
|
+
const scroll = articleRectObserver.scroll;
|
|
56
|
+
handleKeyframeValue(scroll);
|
|
57
|
+
}, [articleRectObserver, handleKeyframeValue]);
|
|
58
|
+
(0, react_1.useEffect)(() => {
|
|
59
|
+
if (!articleRectObserver)
|
|
46
60
|
return;
|
|
47
61
|
return articleRectObserver.on('resize', () => {
|
|
48
62
|
const scroll = articleRectObserver.scroll;
|
|
49
|
-
|
|
50
|
-
setAdjustedValue(newValue);
|
|
63
|
+
handleKeyframeValue(scroll);
|
|
51
64
|
});
|
|
52
|
-
}, [
|
|
65
|
+
}, [handleKeyframeValue, articleRectObserver]);
|
|
53
66
|
(0, react_1.useEffect)(() => {
|
|
54
|
-
if (!
|
|
67
|
+
if (!articleRectObserver)
|
|
55
68
|
return;
|
|
56
69
|
return articleRectObserver.on('scroll', () => {
|
|
57
70
|
const scroll = articleRectObserver.scroll;
|
|
58
|
-
|
|
59
|
-
if (!(0, lodash_isequal_1.default)(newValue, adjustedValueRef.current)) {
|
|
60
|
-
setAdjustedValue(newValue);
|
|
61
|
-
}
|
|
71
|
+
handleKeyframeValue(scroll);
|
|
62
72
|
});
|
|
63
|
-
}, [
|
|
73
|
+
}, [handleKeyframeValue, articleRectObserver]);
|
|
64
74
|
return adjustedValue;
|
|
65
75
|
};
|
|
66
76
|
exports.useKeyframeValue = useKeyframeValue;
|
|
@@ -18,8 +18,10 @@ const useItemSticky = (top, parentOffsetTop, item) => {
|
|
|
18
18
|
setAdjustedTop(stickyManager.getPosition(scroll, top, parentOffsetTop));
|
|
19
19
|
}, [top, stickyManager, parentOffsetTop]);
|
|
20
20
|
(0, react_1.useEffect)(() => {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (!articleRectObserver)
|
|
22
|
+
return;
|
|
23
|
+
handleSticky(articleRectObserver.scroll);
|
|
24
|
+
}, [handleSticky, articleRectObserver]);
|
|
23
25
|
(0, react_1.useEffect)(() => {
|
|
24
26
|
if (!articleRectObserver || !sticky)
|
|
25
27
|
return;
|
|
@@ -19,6 +19,7 @@ class ArticleRectObserver extends EventEmitter_1.EventEmitter {
|
|
|
19
19
|
if (!(element instanceof HTMLElement))
|
|
20
20
|
return;
|
|
21
21
|
this.notify(element);
|
|
22
|
+
this.setScroll(window.scrollY / this.articleWidth);
|
|
22
23
|
this.emit('resize', undefined);
|
|
23
24
|
};
|
|
24
25
|
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
@@ -54,13 +54,14 @@ class RichTextConverter {
|
|
|
54
54
|
const kids = [];
|
|
55
55
|
layouts.forEach(l => {
|
|
56
56
|
const ta = richText.layoutParams[l.id].textAlign;
|
|
57
|
+
const whiteSpace = ta === sdk_1.TextAlign.Right ? 'normal' : 'pre-wrap';
|
|
57
58
|
styleRules[l.id].push(`
|
|
58
59
|
.${blockClass} {
|
|
59
60
|
display: ${group.some(g => g.layout === l.id) ? 'block' : 'none'};
|
|
60
61
|
text-align: ${ta};
|
|
61
|
-
white-space:
|
|
62
|
+
white-space: ${whiteSpace};
|
|
62
63
|
overflow-wrap: break-word;
|
|
63
|
-
${!hasPreset
|
|
64
|
+
${!hasPreset ? 'line-height: 0;' : ''}
|
|
64
65
|
}
|
|
65
66
|
`);
|
|
66
67
|
});
|
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@ export const useKeyframeValue = <T>(
|
|
|
25
25
|
const articleRectObserver = useContext(ArticleRectContext);
|
|
26
26
|
const layoutId = useCurrentLayout();
|
|
27
27
|
const keyframesRepo = useContext(KeyframesContext);
|
|
28
|
-
const keyframes = keyframesRepo.getItemKeyframes(item.id);
|
|
28
|
+
const keyframes = useMemo(() => keyframesRepo.getItemKeyframes(item.id), [item.id, keyframesRepo]);
|
|
29
29
|
const paramValue = useMemo<T>(() => {
|
|
30
30
|
return itemParamsGetterRef.current(item, layoutId);
|
|
31
31
|
}, [item, layoutId, ...deps]);
|
|
@@ -46,29 +46,39 @@ export const useKeyframeValue = <T>(
|
|
|
46
46
|
return new Animator(animationData);
|
|
47
47
|
}, [keyframes, layoutId]);
|
|
48
48
|
|
|
49
|
+
const handleKeyframeValue = useCallback((scroll: number) => {
|
|
50
|
+
if (!animator) return;
|
|
51
|
+
const newValue = animatorGetterRef.current(animator, scroll, paramValue);
|
|
52
|
+
if (!isEqual(newValue, adjustedValueRef.current)) {
|
|
53
|
+
setAdjustedValue(newValue);
|
|
54
|
+
}
|
|
55
|
+
}, [animator, paramValue]);
|
|
56
|
+
|
|
49
57
|
useEffect(() => {
|
|
50
58
|
setAdjustedValue(paramValue);
|
|
51
59
|
}, [paramValue]);
|
|
52
60
|
|
|
53
61
|
useEffect(() => {
|
|
54
|
-
if (!
|
|
62
|
+
if (!articleRectObserver) return;
|
|
63
|
+
const scroll = articleRectObserver.scroll;
|
|
64
|
+
handleKeyframeValue(scroll);
|
|
65
|
+
}, [articleRectObserver, handleKeyframeValue])
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!articleRectObserver) return;
|
|
55
69
|
return articleRectObserver.on('resize', () => {
|
|
56
70
|
const scroll = articleRectObserver.scroll;
|
|
57
|
-
|
|
58
|
-
setAdjustedValue(newValue);
|
|
71
|
+
handleKeyframeValue(scroll);
|
|
59
72
|
});
|
|
60
|
-
}, [
|
|
73
|
+
}, [handleKeyframeValue, articleRectObserver]);
|
|
61
74
|
|
|
62
75
|
useEffect(() => {
|
|
63
|
-
if (!
|
|
76
|
+
if (!articleRectObserver) return;
|
|
64
77
|
return articleRectObserver.on('scroll', () => {
|
|
65
78
|
const scroll = articleRectObserver.scroll;
|
|
66
|
-
|
|
67
|
-
if (!isEqual(newValue, adjustedValueRef.current)) {
|
|
68
|
-
setAdjustedValue(newValue);
|
|
69
|
-
}
|
|
79
|
+
handleKeyframeValue(scroll);
|
|
70
80
|
});
|
|
71
|
-
}, [
|
|
81
|
+
}, [handleKeyframeValue, articleRectObserver]);
|
|
72
82
|
return adjustedValue;
|
|
73
83
|
};
|
|
74
84
|
|
|
@@ -22,8 +22,9 @@ export const useItemSticky = (top: number, parentOffsetTop: number, item: TArtic
|
|
|
22
22
|
}, [top, stickyManager, parentOffsetTop]);
|
|
23
23
|
|
|
24
24
|
useEffect(() => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (!articleRectObserver) return;
|
|
26
|
+
handleSticky(articleRectObserver.scroll);
|
|
27
|
+
}, [handleSticky, articleRectObserver]);
|
|
27
28
|
|
|
28
29
|
useEffect(() => {
|
|
29
30
|
if (!articleRectObserver || !sticky) return;
|
|
@@ -59,6 +59,7 @@ export class ArticleRectObserver extends EventEmitter<EventMap> {
|
|
|
59
59
|
const element = entry.target;
|
|
60
60
|
if (!(element instanceof HTMLElement)) return;
|
|
61
61
|
this.notify(element);
|
|
62
|
+
this.setScroll(window.scrollY / this.articleWidth);
|
|
62
63
|
this.emit('resize', undefined);
|
|
63
64
|
};
|
|
64
65
|
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
TextTransform,
|
|
7
7
|
TLayout,
|
|
8
8
|
TRichTextItem,
|
|
9
|
-
VerticalAlign
|
|
9
|
+
VerticalAlign,
|
|
10
|
+
TextAlign
|
|
10
11
|
} from '@cntrl-site/sdk';
|
|
11
12
|
import { LinkWrapper } from '../../components/LinkWrapper';
|
|
12
13
|
|
|
@@ -84,13 +85,14 @@ export class RichTextConverter {
|
|
|
84
85
|
const kids: ReactNode[] = [];
|
|
85
86
|
layouts.forEach(l => {
|
|
86
87
|
const ta = richText.layoutParams[l.id].textAlign;
|
|
88
|
+
const whiteSpace = ta === TextAlign.Right ? 'normal' : 'pre-wrap';
|
|
87
89
|
styleRules[l.id].push(`
|
|
88
90
|
.${blockClass} {
|
|
89
91
|
display: ${group.some(g => g.layout === l.id) ? 'block' : 'none'};
|
|
90
92
|
text-align: ${ta};
|
|
91
|
-
white-space:
|
|
93
|
+
white-space: ${whiteSpace};
|
|
92
94
|
overflow-wrap: break-word;
|
|
93
|
-
${!hasPreset
|
|
95
|
+
${!hasPreset ? 'line-height: 0;' : ''}
|
|
94
96
|
}
|
|
95
97
|
`);
|
|
96
98
|
});
|
|
@@ -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>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|