@kids-reporter/draft-renderer 0.1.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.
- package/README.md +86 -0
- package/lib/assets/annotation-arrow.png +0 -0
- package/lib/assets/audio-pause.png +0 -0
- package/lib/assets/audio-play.png +0 -0
- package/lib/assets/citation-download.png +0 -0
- package/lib/assets/default-og-img.png +0 -0
- package/lib/assets/slideshow-arrow-down-dark.png +0 -0
- package/lib/assets/slideshow-arrow-down.png +0 -0
- package/lib/assets/slideshow-arrow-up.png +0 -0
- package/lib/assets/slideshow-close-cross.png +0 -0
- package/lib/block-renderer-fn.js +123 -0
- package/lib/block-renderers/audio-block.js +162 -0
- package/lib/block-renderers/background-image-block.js +257 -0
- package/lib/block-renderers/background-video-block.js +272 -0
- package/lib/block-renderers/color-box-block.js +94 -0
- package/lib/block-renderers/divider-block.js +27 -0
- package/lib/block-renderers/embedded-code-block.js +121 -0
- package/lib/block-renderers/image-block.js +72 -0
- package/lib/block-renderers/index.js +53 -0
- package/lib/block-renderers/info-box-block.js +124 -0
- package/lib/block-renderers/media-block.js +65 -0
- package/lib/block-renderers/related-post-block.js +73 -0
- package/lib/block-renderers/side-index-block.js +49 -0
- package/lib/block-renderers/slideshow-block.js +253 -0
- package/lib/block-renderers/table-block.js +455 -0
- package/lib/block-renderers/video-block.js +37 -0
- package/lib/components/slideshow-lightbox.js +134 -0
- package/lib/components/slideshow-sidebar.js +148 -0
- package/lib/const.js +10 -0
- package/lib/draft-renderer.js +234 -0
- package/lib/entity-decorator.js +18 -0
- package/lib/entity-decorators/annotation-decorator.js +155 -0
- package/lib/entity-decorators/index.js +16 -0
- package/lib/entity-decorators/link-decorator.js +48 -0
- package/lib/index.js +30 -0
- package/lib/public/07d1287fd390346af0c15b930148a5e4.png +0 -0
- package/lib/public/5b3cb1a908786c8750f1041860699cc1.png +0 -0
- package/lib/public/679d63b1846e81ada28c2f76edbd2931.png +0 -0
- package/lib/public/722f90c535fa64c27555ec6ee5f22393.png +0 -0
- package/lib/public/903cf84ef5c5ad76634c30bdc0ff8c49.png +0 -0
- package/lib/public/dc249b3412c5af890a004508287a3c3d.png +0 -0
- package/lib/public/dd45f0788d9c70cabe72430bf08e7413.png +0 -0
- package/lib/public/f96d4b486ba2061c460962ae694f4670.png +0 -0
- package/lib/shared-style/content-type.js +163 -0
- package/lib/shared-style/index.js +108 -0
- package/lib/theme/index.js +39 -0
- package/lib/types/index.js +32 -0
- package/lib/utils/common.js +44 -0
- package/lib/utils/post.js +147 -0
- package/package.json +44 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SummaryStyle = exports.NormalStyle = exports.CitationStyle = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = require("styled-components");
|
|
9
|
+
|
|
10
|
+
var _index = require("./index");
|
|
11
|
+
|
|
12
|
+
const SummaryStyle = (0, _styledComponents.css)`
|
|
13
|
+
${({
|
|
14
|
+
theme
|
|
15
|
+
}) => theme.fontSize.sm};
|
|
16
|
+
line-height: 1.6;
|
|
17
|
+
|
|
18
|
+
*:not(:first-child) {
|
|
19
|
+
.public-DraftStyleDefault-block {
|
|
20
|
+
margin-top: 12px;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.public-DraftStyleDefault-ul,
|
|
25
|
+
.public-DraftStyleDefault-ol {
|
|
26
|
+
margin-top: 12px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.public-DraftStyleDefault-unorderedListItem,
|
|
30
|
+
.public-DraftStyleDefault-orderedListItem {
|
|
31
|
+
.public-DraftStyleDefault-block {
|
|
32
|
+
margin-top: 4px;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.public-DraftStyleDefault-blockquote {
|
|
37
|
+
${_index.defaultBlockQuoteStyle};
|
|
38
|
+
|
|
39
|
+
& + blockquote {
|
|
40
|
+
${_index.blockQuoteSpacingBetweenContent};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
exports.SummaryStyle = SummaryStyle;
|
|
45
|
+
const NormalStyle = (0, _styledComponents.css)`
|
|
46
|
+
${({
|
|
47
|
+
theme
|
|
48
|
+
}) => theme.fontSize.md};
|
|
49
|
+
line-height: 2;
|
|
50
|
+
|
|
51
|
+
*:not(:first-child) {
|
|
52
|
+
${_index.defaultSpacingBetweenContent}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.public-DraftStyleDefault-unorderedListItem,
|
|
56
|
+
.public-DraftStyleDefault-orderedListItem {
|
|
57
|
+
${_index.noSpacingBetweenContent};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.public-DraftStyleDefault-ul,
|
|
61
|
+
.public-DraftStyleDefault-ol {
|
|
62
|
+
margin-top: 32px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.public-DraftStyleDefault-blockquote {
|
|
66
|
+
${_index.defaultBlockQuoteStyle};
|
|
67
|
+
|
|
68
|
+
& + blockquote {
|
|
69
|
+
${_index.blockQuoteSpacingBetweenContent};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
exports.NormalStyle = NormalStyle;
|
|
74
|
+
const CitationStyle = (0, _styledComponents.css)`
|
|
75
|
+
${({
|
|
76
|
+
theme
|
|
77
|
+
}) => theme.fontSize.sm};
|
|
78
|
+
line-height: 1.6;
|
|
79
|
+
|
|
80
|
+
*:not(:first-child) {
|
|
81
|
+
.public-DraftStyleDefault-block {
|
|
82
|
+
margin-top: 12px;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.public-DraftStyleDefault-unorderedListItem,
|
|
87
|
+
.public-DraftStyleDefault-orderedListItem {
|
|
88
|
+
.public-DraftStyleDefault-block {
|
|
89
|
+
margin-top: 4px;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.public-DraftStyleDefault-ul,
|
|
94
|
+
.public-DraftStyleDefault-ol {
|
|
95
|
+
margin-top: 12px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//檔案下載
|
|
99
|
+
.public-DraftStyleDefault-ul:has(a) {
|
|
100
|
+
padding: 0;
|
|
101
|
+
|
|
102
|
+
.public-DraftStyleDefault-unorderedListItem {
|
|
103
|
+
list-style-type: none;
|
|
104
|
+
padding: 8px 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
a {
|
|
108
|
+
width: 100%;
|
|
109
|
+
border: none;
|
|
110
|
+
font-weight: 700;
|
|
111
|
+
font-size: 16px;
|
|
112
|
+
line-height: 1.5;
|
|
113
|
+
color: #04295e;
|
|
114
|
+
display: inline-block;
|
|
115
|
+
position: relative;
|
|
116
|
+
padding-right: 60px;
|
|
117
|
+
|
|
118
|
+
&:hover {
|
|
119
|
+
color: rgba(0, 9, 40, 0.87);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
&::after {
|
|
123
|
+
content: '';
|
|
124
|
+
background-image: url('../assets/citation-download.png');
|
|
125
|
+
background-repeat: no-repeat;
|
|
126
|
+
background-position: center center;
|
|
127
|
+
background-size: contain;
|
|
128
|
+
position: absolute;
|
|
129
|
+
right: 0;
|
|
130
|
+
top: 50%;
|
|
131
|
+
width: 24px;
|
|
132
|
+
height: 24px;
|
|
133
|
+
transform: translate(0%, -12px);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.public-DraftStyleDefault-blockquote {
|
|
139
|
+
width: 100%;
|
|
140
|
+
color: rgba(0, 9, 40, 0.5);
|
|
141
|
+
${({
|
|
142
|
+
theme
|
|
143
|
+
}) => theme.fontSize.sm};
|
|
144
|
+
line-height: 1.6;
|
|
145
|
+
padding: 0;
|
|
146
|
+
|
|
147
|
+
& + blockquote {
|
|
148
|
+
${_index.blockQuoteSpacingBetweenContent};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
& + ul {
|
|
152
|
+
border-top: 1px solid rgba(0, 9, 40, 0.1);
|
|
153
|
+
padding-top: 4px;
|
|
154
|
+
|
|
155
|
+
${({
|
|
156
|
+
theme
|
|
157
|
+
}) => theme.breakpoint.md} {
|
|
158
|
+
margin-top: 16px;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
163
|
+
exports.CitationStyle = CitationStyle;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.textAroundPictureStyle = exports.noSpacingBetweenContent = exports.narrowSpacingBetweenContent = exports.defaultUnorderedListStyle = exports.defaultUlStyle = exports.defaultSpacingBetweenContent = exports.defaultOrderedListStyle = exports.defaultOlStyle = exports.defaultLinkStyle = exports.defaultH2Style = exports.defaultBlockQuoteStyle = exports.blockQuoteSpacingBetweenContent = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = require("styled-components");
|
|
9
|
+
|
|
10
|
+
const blockQuoteSpacingBetweenContent = (0, _styledComponents.css)`
|
|
11
|
+
.public-DraftStyleDefault-block {
|
|
12
|
+
margin-top: 8px;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
exports.blockQuoteSpacingBetweenContent = blockQuoteSpacingBetweenContent;
|
|
16
|
+
const textAroundPictureStyle = (0, _styledComponents.css)`
|
|
17
|
+
max-width: 33.3%;
|
|
18
|
+
> figure {
|
|
19
|
+
margin-bottom: 0;
|
|
20
|
+
width: 150%;
|
|
21
|
+
transform: unset;
|
|
22
|
+
}
|
|
23
|
+
figcaption {
|
|
24
|
+
padding: 0;
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
exports.textAroundPictureStyle = textAroundPictureStyle;
|
|
28
|
+
const defaultH2Style = (0, _styledComponents.css)`
|
|
29
|
+
${({
|
|
30
|
+
theme
|
|
31
|
+
}) => theme.fontSize.lg};
|
|
32
|
+
font-weight: 700;
|
|
33
|
+
line-height: 1.5;
|
|
34
|
+
letter-spacing: 0.032em;
|
|
35
|
+
color: #000928;
|
|
36
|
+
|
|
37
|
+
${({
|
|
38
|
+
theme
|
|
39
|
+
}) => theme.breakpoint.md} {
|
|
40
|
+
${({
|
|
41
|
+
theme
|
|
42
|
+
}) => theme.fontSize.xl};
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
exports.defaultH2Style = defaultH2Style;
|
|
46
|
+
const defaultUlStyle = (0, _styledComponents.css)`
|
|
47
|
+
list-style-type: disc;
|
|
48
|
+
padding-left: 1.2rem;
|
|
49
|
+
`;
|
|
50
|
+
exports.defaultUlStyle = defaultUlStyle;
|
|
51
|
+
const defaultUnorderedListStyle = (0, _styledComponents.css)`
|
|
52
|
+
letter-spacing: 0.01em;
|
|
53
|
+
text-align: justify;
|
|
54
|
+
color: rgba(0, 9, 40, 0.87);
|
|
55
|
+
`;
|
|
56
|
+
exports.defaultUnorderedListStyle = defaultUnorderedListStyle;
|
|
57
|
+
const defaultOlStyle = (0, _styledComponents.css)`
|
|
58
|
+
list-style-type: decimal;
|
|
59
|
+
padding-left: 1.2rem;
|
|
60
|
+
`;
|
|
61
|
+
exports.defaultOlStyle = defaultOlStyle;
|
|
62
|
+
const defaultOrderedListStyle = (0, _styledComponents.css)`
|
|
63
|
+
letter-spacing: 0.01em;
|
|
64
|
+
text-align: justify;
|
|
65
|
+
color: rgba(0, 9, 40, 0.87);
|
|
66
|
+
`;
|
|
67
|
+
exports.defaultOrderedListStyle = defaultOrderedListStyle;
|
|
68
|
+
const defaultLinkStyle = (0, _styledComponents.css)`
|
|
69
|
+
display: inline;
|
|
70
|
+
border-bottom: 2px solid #ebf02c;
|
|
71
|
+
letter-spacing: 0.01em;
|
|
72
|
+
text-align: justify;
|
|
73
|
+
color: rgba(0, 9, 40, 0.87);
|
|
74
|
+
padding-bottom: 2px;
|
|
75
|
+
|
|
76
|
+
&:hover {
|
|
77
|
+
border-bottom: 2px solid #04295e;
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
exports.defaultLinkStyle = defaultLinkStyle;
|
|
81
|
+
const defaultBlockQuoteStyle = (0, _styledComponents.css)`
|
|
82
|
+
${({
|
|
83
|
+
theme
|
|
84
|
+
}) => theme.fontSize.sm};
|
|
85
|
+
line-height: 1.6;
|
|
86
|
+
color: rgba(0, 9, 40, 0.66);
|
|
87
|
+
opacity: 0.87;
|
|
88
|
+
padding: 0 20px;
|
|
89
|
+
`;
|
|
90
|
+
exports.defaultBlockQuoteStyle = defaultBlockQuoteStyle;
|
|
91
|
+
const defaultSpacingBetweenContent = (0, _styledComponents.css)`
|
|
92
|
+
.public-DraftStyleDefault-block {
|
|
93
|
+
margin-top: 32px;
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
exports.defaultSpacingBetweenContent = defaultSpacingBetweenContent;
|
|
97
|
+
const narrowSpacingBetweenContent = (0, _styledComponents.css)`
|
|
98
|
+
.public-DraftStyleDefault-block {
|
|
99
|
+
margin-top: 16px;
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
exports.narrowSpacingBetweenContent = narrowSpacingBetweenContent;
|
|
103
|
+
const noSpacingBetweenContent = (0, _styledComponents.css)`
|
|
104
|
+
.public-DraftStyleDefault-block {
|
|
105
|
+
margin-top: unset;
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
exports.noSpacingBetweenContent = noSpacingBetweenContent;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.theme = exports.mediaSize = exports.default = void 0;
|
|
7
|
+
const mediaSize = {
|
|
8
|
+
xs: 0,
|
|
9
|
+
sm: 576,
|
|
10
|
+
md: 768,
|
|
11
|
+
lg: 960,
|
|
12
|
+
xl: 1200,
|
|
13
|
+
xxl: 1400
|
|
14
|
+
};
|
|
15
|
+
exports.mediaSize = mediaSize;
|
|
16
|
+
const theme = {
|
|
17
|
+
breakpoint: {
|
|
18
|
+
xs: `@media (min-width: ${mediaSize.xs}px)`,
|
|
19
|
+
sm: `@media (min-width: ${mediaSize.sm}px)`,
|
|
20
|
+
md: `@media (min-width: ${mediaSize.md}px)`,
|
|
21
|
+
lg: `@media (min-width: ${mediaSize.lg}px)`,
|
|
22
|
+
xl: `@media (min-width: ${mediaSize.xl}px)`,
|
|
23
|
+
xxl: `@media (min-width: ${mediaSize.xxl}px)`
|
|
24
|
+
},
|
|
25
|
+
fontSize: {
|
|
26
|
+
xs: 'font-size: 14px;',
|
|
27
|
+
sm: 'font-size: 16px;',
|
|
28
|
+
md: 'font-size: 18px;',
|
|
29
|
+
lg: 'font-size: 24px;',
|
|
30
|
+
xl: 'font-size: 28px;'
|
|
31
|
+
},
|
|
32
|
+
margin: {
|
|
33
|
+
default: 'margin: 32px auto;',
|
|
34
|
+
narrow: 'margin: 16px auto;'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.theme = theme;
|
|
38
|
+
var _default = theme;
|
|
39
|
+
exports.default = _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ValidPostContentType = void 0;
|
|
7
|
+
var ValidPostStyle;
|
|
8
|
+
|
|
9
|
+
(function (ValidPostStyle) {
|
|
10
|
+
ValidPostStyle["NEWS"] = "news";
|
|
11
|
+
ValidPostStyle["FRAME"] = "frame";
|
|
12
|
+
ValidPostStyle["BLANK"] = "blank";
|
|
13
|
+
ValidPostStyle["REPORT"] = "report";
|
|
14
|
+
ValidPostStyle["PROJECT3"] = "project3";
|
|
15
|
+
ValidPostStyle["EMBEDDED"] = "embedded";
|
|
16
|
+
ValidPostStyle["REVIEW"] = "review";
|
|
17
|
+
ValidPostStyle["MEMO"] = "memo";
|
|
18
|
+
ValidPostStyle["DUMMY"] = "dummy";
|
|
19
|
+
ValidPostStyle["CARD"] = "card";
|
|
20
|
+
ValidPostStyle["QA"] = "qa";
|
|
21
|
+
ValidPostStyle["SCROLLABLE_VIDEO"] = "scrollablevideo";
|
|
22
|
+
})(ValidPostStyle || (ValidPostStyle = {}));
|
|
23
|
+
|
|
24
|
+
let ValidPostContentType;
|
|
25
|
+
exports.ValidPostContentType = ValidPostContentType;
|
|
26
|
+
|
|
27
|
+
(function (ValidPostContentType) {
|
|
28
|
+
ValidPostContentType["SUMMARY"] = "summary";
|
|
29
|
+
ValidPostContentType["NORMAL"] = "normal";
|
|
30
|
+
ValidPostContentType["ACTIONLIST"] = "actionlist";
|
|
31
|
+
ValidPostContentType["CITATION"] = "citation";
|
|
32
|
+
})(ValidPostContentType || (exports.ValidPostContentType = ValidPostContentType = {}));
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeEmptyContentBlock = exports.hasContentInRawContentBlock = void 0;
|
|
7
|
+
|
|
8
|
+
const hasContentInRawContentBlock = rawContentBlock => {
|
|
9
|
+
if (!rawContentBlock || !rawContentBlock.blocks || !rawContentBlock.blocks.length) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const hasAtomicBlock = Boolean(rawContentBlock.blocks.some(block => block.type === 'atomic'));
|
|
14
|
+
|
|
15
|
+
if (hasAtomicBlock) {
|
|
16
|
+
return hasAtomicBlock;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const defaultBlockHasContent = Boolean(rawContentBlock.blocks.filter(block => block.type !== 'atomic').some(block => block.text.trim()));
|
|
20
|
+
return defaultBlockHasContent;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.hasContentInRawContentBlock = hasContentInRawContentBlock;
|
|
24
|
+
|
|
25
|
+
const removeEmptyContentBlock = rawContentBlock => {
|
|
26
|
+
const hasContent = hasContentInRawContentBlock(rawContentBlock);
|
|
27
|
+
|
|
28
|
+
if (!hasContent) {
|
|
29
|
+
throw new Error('There is no content in rawContentBlock, please check again.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const blocksWithHideEmptyBlock = rawContentBlock === null || rawContentBlock === void 0 ? void 0 : rawContentBlock.blocks.map(block => {
|
|
33
|
+
if (block.type === 'atomic' || block.text) {
|
|
34
|
+
return block;
|
|
35
|
+
} else {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}).filter(block => block);
|
|
39
|
+
return { ...rawContentBlock,
|
|
40
|
+
blocks: blocksWithHideEmptyBlock
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.removeEmptyContentBlock = removeEmptyContentBlock;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.insertRecommendInContentBlock = exports.getSideIndexEntityData = exports.getFirstBlockEntityType = void 0;
|
|
7
|
+
|
|
8
|
+
var _common = require("./common");
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line prettier/prettier
|
|
11
|
+
const insertRecommendInContentBlock = (rawContentBlock, insertRecommend) => {
|
|
12
|
+
const relatedPostsEntityMaps = insertRecommend === null || insertRecommend === void 0 ? void 0 : insertRecommend.map(post => ({
|
|
13
|
+
data: {
|
|
14
|
+
posts: [{
|
|
15
|
+
heroImage: (post === null || post === void 0 ? void 0 : post.heroImage) || {},
|
|
16
|
+
id: (post === null || post === void 0 ? void 0 : post.id) || '',
|
|
17
|
+
name: (post === null || post === void 0 ? void 0 : post.title) || '',
|
|
18
|
+
ogImage: (post === null || post === void 0 ? void 0 : post.ogImage) || null,
|
|
19
|
+
slug: (post === null || post === void 0 ? void 0 : post.slug) || '',
|
|
20
|
+
subtitle: null
|
|
21
|
+
}]
|
|
22
|
+
},
|
|
23
|
+
type: 'RELATEDPOST',
|
|
24
|
+
mutability: 'IMMUTABLE'
|
|
25
|
+
}));
|
|
26
|
+
const insertRelatedEntities = relatedPostsEntityMaps.reduce((accumulator, current) => {
|
|
27
|
+
var _current$data;
|
|
28
|
+
|
|
29
|
+
// +1000 to increase diversity to avoid `key` duplication
|
|
30
|
+
const entityKey = Number(current === null || current === void 0 ? void 0 : (_current$data = current.data) === null || _current$data === void 0 ? void 0 : _current$data.posts[0].id) + 1000;
|
|
31
|
+
return { ...accumulator,
|
|
32
|
+
[entityKey]: current
|
|
33
|
+
};
|
|
34
|
+
}, {});
|
|
35
|
+
const entityMapWithInsertRecommend = { ...rawContentBlock.entityMap,
|
|
36
|
+
...insertRelatedEntities
|
|
37
|
+
};
|
|
38
|
+
const relatedPostsBlocks = insertRecommend.map((post, index) => {
|
|
39
|
+
// +1000 to increase diversity to avoid `key` duplication
|
|
40
|
+
const entityKey = Number(post.id) + 1000;
|
|
41
|
+
return {
|
|
42
|
+
key: `insertRecommend-${index}`,
|
|
43
|
+
data: {},
|
|
44
|
+
text: ' ',
|
|
45
|
+
//notice: if text: '' will show error
|
|
46
|
+
type: 'atomic',
|
|
47
|
+
depth: 0,
|
|
48
|
+
entityRanges: [{
|
|
49
|
+
key: entityKey,
|
|
50
|
+
length: 1,
|
|
51
|
+
offset: 0
|
|
52
|
+
}],
|
|
53
|
+
inlineStyleRanges: []
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
function insertRecommendBlocks(data) {
|
|
58
|
+
let i = 0;
|
|
59
|
+
let count = 0; // B: insert recommends based on related-posts amount
|
|
60
|
+
|
|
61
|
+
const paragraphs = data === null || data === void 0 ? void 0 : data.filter(item => (item === null || item === void 0 ? void 0 : item.type) === 'unstyled' && (item === null || item === void 0 ? void 0 : item.text.length));
|
|
62
|
+
let divideAmount;
|
|
63
|
+
|
|
64
|
+
if (relatedPostsBlocks.length) {
|
|
65
|
+
divideAmount = Math.round((paragraphs === null || paragraphs === void 0 ? void 0 : paragraphs.length) / (relatedPostsBlocks.length + 1)) || (paragraphs !== null && paragraphs !== void 0 && paragraphs.length ? 1 : 0);
|
|
66
|
+
} else {
|
|
67
|
+
divideAmount = 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (data !== null && data !== void 0 && data.length) {
|
|
71
|
+
while (i < data.length && divideAmount) {
|
|
72
|
+
var _data$i, _data$i2;
|
|
73
|
+
|
|
74
|
+
if (((_data$i = data[i]) === null || _data$i === void 0 ? void 0 : _data$i.type) === 'unstyled' && (_data$i2 = data[i]) !== null && _data$i2 !== void 0 && _data$i2.text.length) {
|
|
75
|
+
count++;
|
|
76
|
+
const item = relatedPostsBlocks[count / divideAmount - 1];
|
|
77
|
+
|
|
78
|
+
if (count % divideAmount === 0 && item) {
|
|
79
|
+
data.splice(i + 1, 0, item);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
i++;
|
|
84
|
+
}
|
|
85
|
+
} // A: insert recommends each 5 paragraphs (same as READr 2.0)
|
|
86
|
+
// if (data?.length) {
|
|
87
|
+
// while (i < data.length) {
|
|
88
|
+
// if (data[i]?.type === 'unstyled' && data[i]?.text.length) {
|
|
89
|
+
// count++
|
|
90
|
+
// const item = relatedPostsBlocks[count / 5 - 1]
|
|
91
|
+
// if (count % 5 === 0 && item) {
|
|
92
|
+
// data.splice(i + 1, 0, item)
|
|
93
|
+
// }
|
|
94
|
+
// }
|
|
95
|
+
// i++
|
|
96
|
+
// }
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const contentWithoutEmptyBlock = (0, _common.removeEmptyContentBlock)(rawContentBlock);
|
|
104
|
+
const contentWithInsertRecommend = {
|
|
105
|
+
blocks: insertRecommendBlocks(contentWithoutEmptyBlock === null || contentWithoutEmptyBlock === void 0 ? void 0 : contentWithoutEmptyBlock.blocks),
|
|
106
|
+
entityMap: entityMapWithInsertRecommend
|
|
107
|
+
};
|
|
108
|
+
return contentWithInsertRecommend;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports.insertRecommendInContentBlock = insertRecommendInContentBlock;
|
|
112
|
+
|
|
113
|
+
const getFirstBlockEntityType = rawContentBlock => {
|
|
114
|
+
const contentBlocks = (0, _common.removeEmptyContentBlock)(rawContentBlock);
|
|
115
|
+
|
|
116
|
+
if (contentBlocks) {
|
|
117
|
+
var _contentBlocks$entity;
|
|
118
|
+
|
|
119
|
+
return contentBlocks === null || contentBlocks === void 0 ? void 0 : (_contentBlocks$entity = contentBlocks.entityMap[0]) === null || _contentBlocks$entity === void 0 ? void 0 : _contentBlocks$entity.type;
|
|
120
|
+
} else {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
exports.getFirstBlockEntityType = getFirstBlockEntityType;
|
|
126
|
+
|
|
127
|
+
const getSideIndexEntityData = rawContentBlock => {
|
|
128
|
+
const contentBlocks = (0, _common.removeEmptyContentBlock)(rawContentBlock);
|
|
129
|
+
|
|
130
|
+
if (contentBlocks !== null && contentBlocks !== void 0 && contentBlocks.entityMap) {
|
|
131
|
+
return Object.values(contentBlocks.entityMap).filter(entity => entity.type === 'SIDEINDEX').map(entity => {
|
|
132
|
+
const content = entity.data ?? {};
|
|
133
|
+
const sideIndexTitle = content.sideIndexText || content.h2Text || '';
|
|
134
|
+
const key = sideIndexTitle.replace(/\s+/g, '');
|
|
135
|
+
return {
|
|
136
|
+
title: sideIndexTitle,
|
|
137
|
+
id: `header-${key}`,
|
|
138
|
+
href: (content === null || content === void 0 ? void 0 : content.sideIndexUrl) || null,
|
|
139
|
+
isActive: false
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
exports.getSideIndexEntityData = getSideIndexEntityData;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kids-reporter/draft-renderer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"dev": "make dev",
|
|
9
|
+
"build": "make build",
|
|
10
|
+
"clean": "make clean",
|
|
11
|
+
"build-lib": "make build-lib"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/@kids-reporter/cms.git",
|
|
16
|
+
"directory": "packages/draft-renderer"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react",
|
|
20
|
+
"kids-reporter",
|
|
21
|
+
"draft.js"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@readr-media/react-image": "1.6.0",
|
|
26
|
+
"body-scroll-lock": "3.1.5",
|
|
27
|
+
"draft-js": "^0.11.7",
|
|
28
|
+
"node-html-parser": "^6.1.5"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "18.2.0",
|
|
32
|
+
"react-dom": "18.2.0",
|
|
33
|
+
"styled-components": "5.3.5"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"lib"
|
|
37
|
+
],
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/draft-js": "^0.11.10",
|
|
40
|
+
"@types/styled-components": "^5.1.26",
|
|
41
|
+
"babel-plugin-file-loader": "^2.0.0",
|
|
42
|
+
"babel-plugin-inline-react-svg": "^2.0.1"
|
|
43
|
+
}
|
|
44
|
+
}
|