@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,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BGVideoBlock = BGVideoBlock;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
|
|
18
|
+
const BackgroundContainer = _styledComponents.default.section`
|
|
19
|
+
clear: both;
|
|
20
|
+
position: relative;
|
|
21
|
+
margin: 32px calc(50% - 50vw) 0 !important;
|
|
22
|
+
width: 100vw;
|
|
23
|
+
min-height: 100vh;
|
|
24
|
+
`;
|
|
25
|
+
const BackgroundVideo = _styledComponents.default.div`
|
|
26
|
+
position: absolute;
|
|
27
|
+
z-index: 1;
|
|
28
|
+
top: 0;
|
|
29
|
+
bottom: unset;
|
|
30
|
+
left: 0;
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 100vh;
|
|
33
|
+
`;
|
|
34
|
+
const BackgroundContentRow = _styledComponents.default.div``;
|
|
35
|
+
const BackgroundContent = _styledComponents.default.div`
|
|
36
|
+
position: relative;
|
|
37
|
+
z-index: 1;
|
|
38
|
+
&.static {
|
|
39
|
+
height: 100vh;
|
|
40
|
+
${BackgroundContentRow} {
|
|
41
|
+
position: absolute;
|
|
42
|
+
bottom: 20px;
|
|
43
|
+
left: 20px;
|
|
44
|
+
right: 20px;
|
|
45
|
+
text-shadow: 0px 0px 1px #000000;
|
|
46
|
+
${({
|
|
47
|
+
theme
|
|
48
|
+
}) => theme.breakpoint.sm} {
|
|
49
|
+
bottom: 40px;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
&.parallax {
|
|
54
|
+
${BackgroundContentRow} {
|
|
55
|
+
> div {
|
|
56
|
+
background: rgba(169, 118, 118, 0.1);
|
|
57
|
+
border-radius: 8px;
|
|
58
|
+
padding: 20px;
|
|
59
|
+
${({
|
|
60
|
+
theme
|
|
61
|
+
}) => theme.breakpoint.xl} {
|
|
62
|
+
width: 480px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
> * + * {
|
|
66
|
+
margin: 27px 0 0;
|
|
67
|
+
}
|
|
68
|
+
h2 {
|
|
69
|
+
font-size: 1.44em;
|
|
70
|
+
${({
|
|
71
|
+
theme
|
|
72
|
+
}) => theme.breakpoint.md} {
|
|
73
|
+
font-size: 1.77em;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
h3 {
|
|
77
|
+
font-size: 1.33em;
|
|
78
|
+
${({
|
|
79
|
+
theme
|
|
80
|
+
}) => theme.breakpoint.md} {
|
|
81
|
+
font-size: 1.55em;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
h4 {
|
|
85
|
+
font-size: 1.11em;
|
|
86
|
+
${({
|
|
87
|
+
theme
|
|
88
|
+
}) => theme.breakpoint.md} {
|
|
89
|
+
font-size: 1.33em;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
ul {
|
|
93
|
+
list-style-type: disc;
|
|
94
|
+
list-style-position: inside;
|
|
95
|
+
}
|
|
96
|
+
ol {
|
|
97
|
+
list-style-type: decimal;
|
|
98
|
+
list-style-position: inside;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
&.left {
|
|
102
|
+
padding: 0 20px 97px;
|
|
103
|
+
${({
|
|
104
|
+
theme
|
|
105
|
+
}) => theme.breakpoint.md} {
|
|
106
|
+
padding: 0 40px 335px;
|
|
107
|
+
}
|
|
108
|
+
${({
|
|
109
|
+
theme
|
|
110
|
+
}) => theme.breakpoint.xl} {
|
|
111
|
+
padding: 0 80px 169px;
|
|
112
|
+
padding-right: calc(100% - 480px - 80px);
|
|
113
|
+
}
|
|
114
|
+
${({
|
|
115
|
+
theme
|
|
116
|
+
}) => theme.breakpoint.xxl} {
|
|
117
|
+
padding-bottom: 296px;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
&.right {
|
|
121
|
+
padding: 0 20px 97px;
|
|
122
|
+
${({
|
|
123
|
+
theme
|
|
124
|
+
}) => theme.breakpoint.md} {
|
|
125
|
+
padding: 0 40px 335px;
|
|
126
|
+
}
|
|
127
|
+
${({
|
|
128
|
+
theme
|
|
129
|
+
}) => theme.breakpoint.xl} {
|
|
130
|
+
padding: 0 80px 169px;
|
|
131
|
+
padding-left: calc(100% - 480px - 80px);
|
|
132
|
+
}
|
|
133
|
+
${({
|
|
134
|
+
theme
|
|
135
|
+
}) => theme.breakpoint.xxl} {
|
|
136
|
+
padding-bottom: 296px;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
&.bottom {
|
|
140
|
+
padding: 0 20px 20px;
|
|
141
|
+
${({
|
|
142
|
+
theme
|
|
143
|
+
}) => theme.breakpoint.md} {
|
|
144
|
+
padding: 0 40px 40px;
|
|
145
|
+
}
|
|
146
|
+
${({
|
|
147
|
+
theme
|
|
148
|
+
}) => theme.breakpoint.xl} {
|
|
149
|
+
padding: 0 calc(50% - 240px) 40px;
|
|
150
|
+
}
|
|
151
|
+
${({
|
|
152
|
+
theme
|
|
153
|
+
}) => theme.breakpoint.xxl} {
|
|
154
|
+
padding-bottom: 80px;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
`;
|
|
160
|
+
const BackgroundEmptyRow = _styledComponents.default.div`
|
|
161
|
+
height: 100vh;
|
|
162
|
+
`;
|
|
163
|
+
|
|
164
|
+
function BGVideoBlock(props) {
|
|
165
|
+
const {
|
|
166
|
+
block,
|
|
167
|
+
contentState
|
|
168
|
+
} = props;
|
|
169
|
+
const entityKey = block.getEntityAt(0);
|
|
170
|
+
const entity = contentState.getEntity(entityKey);
|
|
171
|
+
const {
|
|
172
|
+
textBlockAlign,
|
|
173
|
+
video,
|
|
174
|
+
body
|
|
175
|
+
} = entity.getData(); // 滾動視差
|
|
176
|
+
|
|
177
|
+
const isParallax = textBlockAlign !== 'fixed';
|
|
178
|
+
const [bgVideoCss, setBgVideoCss] = (0, _react.useState)({});
|
|
179
|
+
const bgRef = (0, _react.useRef)(null);
|
|
180
|
+
const videoRef = (0, _react.useRef)(null);
|
|
181
|
+
const topRef = (0, _react.useRef)(null);
|
|
182
|
+
const bottomRef = (0, _react.useRef)(null);
|
|
183
|
+
(0, _react.useEffect)(() => {
|
|
184
|
+
if (bgRef.current && topRef.current && bottomRef.current) {
|
|
185
|
+
const intersectionObserver = new IntersectionObserver(entries => {
|
|
186
|
+
entries.forEach(({
|
|
187
|
+
boundingClientRect
|
|
188
|
+
}) => {
|
|
189
|
+
if (!boundingClientRect.width || !videoRef.current || !bgRef.current) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const bounding = bgRef.current.getBoundingClientRect();
|
|
194
|
+
|
|
195
|
+
if (isParallax) {
|
|
196
|
+
if (bounding.y > 0) {
|
|
197
|
+
// before block top touch viewport top, set the video to the top of block
|
|
198
|
+
setBgVideoCss({
|
|
199
|
+
position: 'absolute',
|
|
200
|
+
top: 0,
|
|
201
|
+
bottom: 'unset'
|
|
202
|
+
});
|
|
203
|
+
videoRef.current.pause();
|
|
204
|
+
} else if (bounding.y + bounding.height >= window.innerHeight) {
|
|
205
|
+
// after block top touch viewport top, fix the video to viewport
|
|
206
|
+
setBgVideoCss({
|
|
207
|
+
position: 'fixed',
|
|
208
|
+
top: 0,
|
|
209
|
+
bottom: 'unset'
|
|
210
|
+
});
|
|
211
|
+
videoRef.current.play();
|
|
212
|
+
} else {
|
|
213
|
+
// after block bottom leave viewport bottom, set the video to the bottom of block
|
|
214
|
+
setBgVideoCss({
|
|
215
|
+
position: 'absolute',
|
|
216
|
+
top: 'unset',
|
|
217
|
+
bottom: 0
|
|
218
|
+
});
|
|
219
|
+
videoRef.current.pause();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!isParallax) {
|
|
224
|
+
if (bounding.y > window.innerHeight * 0.3 || bounding.y < -window.innerHeight * 0.3) {
|
|
225
|
+
videoRef.current.pause();
|
|
226
|
+
} else {
|
|
227
|
+
videoRef.current.play();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}, {
|
|
232
|
+
threshold: [0, 0.4, 0.7, 1.0]
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
if (!isParallax) {
|
|
236
|
+
intersectionObserver.observe(bgRef.current);
|
|
237
|
+
} else {
|
|
238
|
+
intersectionObserver.observe(topRef.current);
|
|
239
|
+
intersectionObserver.observe(bottomRef.current);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return () => {
|
|
243
|
+
intersectionObserver.disconnect();
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}, [isParallax]);
|
|
247
|
+
return /*#__PURE__*/_react.default.createElement(BackgroundContainer, {
|
|
248
|
+
ref: bgRef,
|
|
249
|
+
className: "bg"
|
|
250
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
251
|
+
ref: topRef
|
|
252
|
+
}), /*#__PURE__*/_react.default.createElement(BackgroundVideo, {
|
|
253
|
+
style: bgVideoCss
|
|
254
|
+
}, /*#__PURE__*/_react.default.createElement("video", {
|
|
255
|
+
ref: videoRef,
|
|
256
|
+
src: video === null || video === void 0 ? void 0 : video.url,
|
|
257
|
+
muted: true,
|
|
258
|
+
preload: "auto",
|
|
259
|
+
loop: true,
|
|
260
|
+
playsInline: true
|
|
261
|
+
})), /*#__PURE__*/_react.default.createElement(BackgroundContent, {
|
|
262
|
+
className: isParallax ? 'parallax' : 'static'
|
|
263
|
+
}, isParallax && /*#__PURE__*/_react.default.createElement(BackgroundEmptyRow, null), /*#__PURE__*/_react.default.createElement(BackgroundContentRow, {
|
|
264
|
+
className: textBlockAlign
|
|
265
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
266
|
+
dangerouslySetInnerHTML: {
|
|
267
|
+
__html: body
|
|
268
|
+
}
|
|
269
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
270
|
+
ref: bottomRef
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ColorBoxBlock = ColorBoxBlock;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
var _sharedStyle = require("../shared-style");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const colorBoxDefaultSpacing = 32;
|
|
17
|
+
const ColorBoxRenderWrapper = _styledComponents.default.div`
|
|
18
|
+
background-color: ${props => props.color ? props.color : ' #FFFFFF'};
|
|
19
|
+
padding: 12px 24px;
|
|
20
|
+
position: relative;
|
|
21
|
+
color: #000928;
|
|
22
|
+
${({
|
|
23
|
+
theme
|
|
24
|
+
}) => theme.margin.default};
|
|
25
|
+
|
|
26
|
+
> div > * + * {
|
|
27
|
+
margin: ${colorBoxDefaultSpacing}px 0 0;
|
|
28
|
+
min-height: 0.01px; //to make margins between paragraphs effective
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
h2 {
|
|
32
|
+
${_sharedStyle.defaultH2Style}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ul {
|
|
36
|
+
${_sharedStyle.defaultUlStyle}
|
|
37
|
+
margin-top: ${colorBoxDefaultSpacing}px;
|
|
38
|
+
|
|
39
|
+
> li {
|
|
40
|
+
${_sharedStyle.defaultUnorderedListStyle}
|
|
41
|
+
|
|
42
|
+
& + li {
|
|
43
|
+
margin: ${colorBoxDefaultSpacing / 2}px 0 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
ol {
|
|
49
|
+
${_sharedStyle.defaultOlStyle}
|
|
50
|
+
margin-top: ${colorBoxDefaultSpacing}px;
|
|
51
|
+
|
|
52
|
+
> li {
|
|
53
|
+
${_sharedStyle.defaultOrderedListStyle}
|
|
54
|
+
|
|
55
|
+
& + li {
|
|
56
|
+
margin: ${colorBoxDefaultSpacing / 2}px 0 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
a {
|
|
62
|
+
${_sharedStyle.defaultLinkStyle}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
blockquote {
|
|
66
|
+
${_sharedStyle.defaultBlockQuoteStyle}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
${({
|
|
70
|
+
theme
|
|
71
|
+
}) => theme.breakpoint.md} {
|
|
72
|
+
padding: 16px 32px;
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
function ColorBoxBlock(props) {
|
|
77
|
+
const {
|
|
78
|
+
block,
|
|
79
|
+
contentState
|
|
80
|
+
} = props;
|
|
81
|
+
const entityKey = block.getEntityAt(0);
|
|
82
|
+
const entity = contentState.getEntity(entityKey);
|
|
83
|
+
const {
|
|
84
|
+
color,
|
|
85
|
+
body
|
|
86
|
+
} = entity.getData();
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(ColorBoxRenderWrapper, {
|
|
88
|
+
color: color
|
|
89
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
90
|
+
dangerouslySetInnerHTML: {
|
|
91
|
+
__html: body
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DividerBlock = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const Divider = _styledComponents.default.hr`
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
border-width: 1px;
|
|
17
|
+
border-style: inset;
|
|
18
|
+
${({
|
|
19
|
+
theme
|
|
20
|
+
}) => theme.margin.default};
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const DividerBlock = () => {
|
|
24
|
+
return /*#__PURE__*/_react.default.createElement(Divider, null);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.DividerBlock = DividerBlock;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EmbeddedCodeBlock = exports.Caption = exports.Block = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
var _nodeHtmlParser = require("node-html-parser");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
const Block = _styledComponents.default.div`
|
|
21
|
+
position: relative;
|
|
22
|
+
white-space: normal;
|
|
23
|
+
/* styles for image link */
|
|
24
|
+
img.img-responsive {
|
|
25
|
+
margin: 0 auto;
|
|
26
|
+
max-width: 100%;
|
|
27
|
+
height: auto;
|
|
28
|
+
display: block;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
exports.Block = Block;
|
|
32
|
+
const Caption = _styledComponents.default.div`
|
|
33
|
+
line-height: 1.43;
|
|
34
|
+
letter-spacing: 0.4px;
|
|
35
|
+
${({
|
|
36
|
+
theme
|
|
37
|
+
}) => theme.fontSize.xs};
|
|
38
|
+
color: #808080;
|
|
39
|
+
padding: 15px 15px 0 15px;
|
|
40
|
+
`;
|
|
41
|
+
exports.Caption = Caption;
|
|
42
|
+
|
|
43
|
+
const EmbeddedCodeBlock = entity => {
|
|
44
|
+
const {
|
|
45
|
+
caption,
|
|
46
|
+
embeddedCode
|
|
47
|
+
} = entity.getData();
|
|
48
|
+
const embedded = (0, _react.useRef)(null); // `embeddedCode` is a string, which may includes
|
|
49
|
+
// multiple script tags and other html tags.
|
|
50
|
+
// Here we separate script tags and other html tags
|
|
51
|
+
// by using the isomorphic html parser 'node-html-parser'
|
|
52
|
+
// into scripts nodes and non-script nodes.
|
|
53
|
+
//
|
|
54
|
+
// For non-script nodes we simply put them into dangerouslySetInnerHtml.
|
|
55
|
+
//
|
|
56
|
+
// For scripts nodes we only append them on the client side. So we handle scripts
|
|
57
|
+
// nodes when useEffect is called.
|
|
58
|
+
// The reasons we don't insert script tags through dangerouslySetInnerHtml:
|
|
59
|
+
// 1. Since react use setInnerHtml to append the htmlStirng received from
|
|
60
|
+
// dangerouslySetInnerHtml, scripts won't be triggered.
|
|
61
|
+
// 2. Although the setInnerhtml way won't trigger script tags, those script tags
|
|
62
|
+
// will still show on the HTML provided from SSR. When the browser parse the
|
|
63
|
+
// html it will run those script and produce unexpected behavior.
|
|
64
|
+
|
|
65
|
+
const nodes = (0, _react.useMemo)(() => {
|
|
66
|
+
const ele = (0, _nodeHtmlParser.parse)(`<div id="draft-embed">${embeddedCode}</div>`);
|
|
67
|
+
const scripts = ele.querySelectorAll('script');
|
|
68
|
+
scripts.forEach(s => {
|
|
69
|
+
s.remove();
|
|
70
|
+
});
|
|
71
|
+
const nonScripts = ele.querySelectorAll('div#draft-embed > :not(script)');
|
|
72
|
+
const nonScriptsHtml = nonScripts.reduce((prev, next) => prev + next.toString(), '');
|
|
73
|
+
return {
|
|
74
|
+
scripts,
|
|
75
|
+
nonScripts,
|
|
76
|
+
nonScriptsHtml
|
|
77
|
+
};
|
|
78
|
+
}, [embeddedCode]);
|
|
79
|
+
const {
|
|
80
|
+
scripts,
|
|
81
|
+
nonScriptsHtml
|
|
82
|
+
} = nodes;
|
|
83
|
+
(0, _react.useEffect)(() => {
|
|
84
|
+
if (embedded.current) {
|
|
85
|
+
const node = embedded.current;
|
|
86
|
+
const fragment = document.createDocumentFragment();
|
|
87
|
+
scripts.forEach(s => {
|
|
88
|
+
const scriptEle = document.createElement('script');
|
|
89
|
+
const attrs = s.attributes;
|
|
90
|
+
|
|
91
|
+
for (const key in attrs) {
|
|
92
|
+
scriptEle.setAttribute(key, attrs[key]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
scriptEle.text = s.text || '';
|
|
96
|
+
fragment.appendChild(scriptEle);
|
|
97
|
+
});
|
|
98
|
+
node.appendChild(fragment);
|
|
99
|
+
}
|
|
100
|
+
}, [scripts]);
|
|
101
|
+
const shouldShowCaption = caption && caption !== 'reporter-scroll-video';
|
|
102
|
+
return (
|
|
103
|
+
/*#__PURE__*/
|
|
104
|
+
// only for READr
|
|
105
|
+
// if `caption === 'reporter-scroll-video'`,embeddedCode need to cover header
|
|
106
|
+
_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("input", {
|
|
107
|
+
hidden: true,
|
|
108
|
+
disabled: true
|
|
109
|
+
}), /*#__PURE__*/_react.default.createElement(Block, {
|
|
110
|
+
style: {
|
|
111
|
+
zIndex: caption === 'reporter-scroll-video' ? 999 : 'auto'
|
|
112
|
+
},
|
|
113
|
+
ref: embedded,
|
|
114
|
+
dangerouslySetInnerHTML: {
|
|
115
|
+
__html: nonScriptsHtml
|
|
116
|
+
}
|
|
117
|
+
}), shouldShowCaption ? /*#__PURE__*/_react.default.createElement(Caption, null, caption) : null)
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
exports.EmbeddedCodeBlock = EmbeddedCodeBlock;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ImageBlock = ImageBlock;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
var _reactImage = _interopRequireDefault(require("@readr-media/react-image"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// import defaultImage from '../assets/default-og-img.png'
|
|
17
|
+
const Figure = _styledComponents.default.figure`
|
|
18
|
+
width: calc(100% + 40px);
|
|
19
|
+
transform: translateX(-20px);
|
|
20
|
+
${({
|
|
21
|
+
theme
|
|
22
|
+
}) => theme.margin.default};
|
|
23
|
+
`;
|
|
24
|
+
const FigureCaption = _styledComponents.default.figcaption`
|
|
25
|
+
width: 100%;
|
|
26
|
+
${({
|
|
27
|
+
theme
|
|
28
|
+
}) => theme.fontSize.xs}
|
|
29
|
+
line-height: 20px;
|
|
30
|
+
text-align: justify;
|
|
31
|
+
color: rgba(0, 9, 40, 0.5);
|
|
32
|
+
padding: 0 20px;
|
|
33
|
+
margin: 8px 0 0;
|
|
34
|
+
|
|
35
|
+
${({
|
|
36
|
+
theme
|
|
37
|
+
}) => theme.breakpoint.xl} {
|
|
38
|
+
line-height: 24px;
|
|
39
|
+
${({
|
|
40
|
+
theme
|
|
41
|
+
}) => theme.fontSize.sm};
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
const Anchor = _styledComponents.default.a`
|
|
45
|
+
text-decoration: none;
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
function ImageBlock(entity) {
|
|
49
|
+
const {
|
|
50
|
+
desc,
|
|
51
|
+
name,
|
|
52
|
+
resized,
|
|
53
|
+
url
|
|
54
|
+
} = entity.getData();
|
|
55
|
+
|
|
56
|
+
let imgBlock = /*#__PURE__*/_react.default.createElement(Figure, null, /*#__PURE__*/_react.default.createElement(_reactImage.default, {
|
|
57
|
+
images: resized || {
|
|
58
|
+
original: url
|
|
59
|
+
},
|
|
60
|
+
defaultImage: url,
|
|
61
|
+
alt: name,
|
|
62
|
+
rwd: {
|
|
63
|
+
mobile: '100vw',
|
|
64
|
+
tablet: '608px',
|
|
65
|
+
desktop: '640px',
|
|
66
|
+
default: '100%'
|
|
67
|
+
},
|
|
68
|
+
priority: true
|
|
69
|
+
}), /*#__PURE__*/_react.default.createElement(FigureCaption, null, desc));
|
|
70
|
+
|
|
71
|
+
return imgBlock;
|
|
72
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.blockRenderers = void 0;
|
|
7
|
+
|
|
8
|
+
var _backgroundImageBlock = require("./background-image-block");
|
|
9
|
+
|
|
10
|
+
var _backgroundVideoBlock = require("./background-video-block");
|
|
11
|
+
|
|
12
|
+
var _colorBoxBlock = require("./color-box-block");
|
|
13
|
+
|
|
14
|
+
var _dividerBlock = require("./divider-block");
|
|
15
|
+
|
|
16
|
+
var _embeddedCodeBlock = require("./embedded-code-block");
|
|
17
|
+
|
|
18
|
+
var _imageBlock = require("./image-block");
|
|
19
|
+
|
|
20
|
+
var _infoBoxBlock = require("./info-box-block");
|
|
21
|
+
|
|
22
|
+
var _mediaBlock = require("./media-block");
|
|
23
|
+
|
|
24
|
+
var _relatedPostBlock = require("./related-post-block");
|
|
25
|
+
|
|
26
|
+
var _sideIndexBlock = require("./side-index-block");
|
|
27
|
+
|
|
28
|
+
var _slideshowBlock = require("./slideshow-block");
|
|
29
|
+
|
|
30
|
+
var _tableBlock = require("./table-block");
|
|
31
|
+
|
|
32
|
+
var _videoBlock = require("./video-block");
|
|
33
|
+
|
|
34
|
+
var _audioBlock = require("./audio-block");
|
|
35
|
+
|
|
36
|
+
const blockRenderers = {
|
|
37
|
+
BGImageBlock: _backgroundImageBlock.BGImageBlock,
|
|
38
|
+
BGVideoBlock: _backgroundVideoBlock.BGVideoBlock,
|
|
39
|
+
ColorBoxBlock: _colorBoxBlock.ColorBoxBlock,
|
|
40
|
+
DividerBlock: _dividerBlock.DividerBlock,
|
|
41
|
+
EmbeddedCodeBlock: _embeddedCodeBlock.EmbeddedCodeBlock,
|
|
42
|
+
ImageBlock: _imageBlock.ImageBlock,
|
|
43
|
+
InfoBoxBlock: _infoBoxBlock.InfoBoxBlock,
|
|
44
|
+
MediaBlock: _mediaBlock.MediaBlock,
|
|
45
|
+
RelatedPostBlock: _relatedPostBlock.RelatedPostBlock,
|
|
46
|
+
SideIndexBlock: _sideIndexBlock.SideIndexBlock,
|
|
47
|
+
SlideshowBlock: _slideshowBlock.SlideshowBlock,
|
|
48
|
+
SlideshowBlockV2: _slideshowBlock.SlideshowBlockV2,
|
|
49
|
+
TableBlock: _tableBlock.TableBlock,
|
|
50
|
+
VideoBlock: _videoBlock.VideoBlock,
|
|
51
|
+
AudioBlock: _audioBlock.AudioBlock
|
|
52
|
+
};
|
|
53
|
+
exports.blockRenderers = blockRenderers;
|