@kids-reporter/draft-renderer 0.3.0 → 0.4.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/lib/block-render-map.js +65 -28
- package/lib/block-renderer-fn.js +2 -13
- package/lib/block-renderers/blockquote.js +3 -14
- package/lib/block-renderers/embedded-code-block.js +3 -14
- package/lib/block-renderers/image-block.js +33 -13
- package/lib/block-renderers/index.js +0 -6
- package/lib/block-renderers/info-box-block.js +95 -42
- package/lib/block-renderers/multimedia.js +7 -10
- package/lib/block-renderers/slideshow-block.js +31 -58
- package/lib/draft-renderer.js +5 -24
- package/lib/entity-decorators/annotation-decorator.js +3 -16
- package/lib/entity-decorators/index.js +3 -7
- package/lib/entity-decorators/link-decorator.js +0 -7
- package/lib/index.js +3 -9
- package/package.json +1 -1
package/lib/block-render-map.js
CHANGED
|
@@ -3,18 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.blockRenderMapForAnnotation = exports.blockRenderMap = void 0;
|
|
7
|
-
|
|
6
|
+
exports.blockRenderMapForInfoBoxWithHeaderBorder = exports.blockRenderMapForInfoBox = exports.blockRenderMapForAnnotation = exports.blockRenderMap = void 0;
|
|
8
7
|
var _immutable = _interopRequireDefault(require("immutable"));
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
-
|
|
9
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
14
10
|
var _draftJs = require("draft-js");
|
|
15
|
-
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
16
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
14
|
const ParagraphBlock = _styledComponents.default.div`
|
|
19
15
|
width: 100%;
|
|
20
16
|
max-width: 700px;
|
|
@@ -25,7 +21,6 @@ const ParagraphBlock = _styledComponents.default.div`
|
|
|
25
21
|
letter-spacing: 0.9px;
|
|
26
22
|
line-height: 2;
|
|
27
23
|
`;
|
|
28
|
-
|
|
29
24
|
function Paragraph({
|
|
30
25
|
className,
|
|
31
26
|
children
|
|
@@ -34,7 +29,6 @@ function Paragraph({
|
|
|
34
29
|
className: className
|
|
35
30
|
}, children);
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
const HeadingBlock = _styledComponents.default.div`
|
|
39
33
|
font-weight: 700;
|
|
40
34
|
line-height: 1.5;
|
|
@@ -45,23 +39,27 @@ const HeadingBlock = _styledComponents.default.div`
|
|
|
45
39
|
|
|
46
40
|
h2,
|
|
47
41
|
h3,
|
|
48
|
-
h4
|
|
42
|
+
h4,
|
|
43
|
+
h5 {
|
|
49
44
|
margin: 0;
|
|
50
45
|
}
|
|
51
46
|
|
|
52
47
|
h2 {
|
|
53
|
-
font-size:
|
|
48
|
+
font-size: 35px;
|
|
54
49
|
}
|
|
55
50
|
|
|
56
51
|
h3 {
|
|
57
|
-
font-size:
|
|
52
|
+
font-size: 30px;
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
h4 {
|
|
61
|
-
font-size:
|
|
56
|
+
font-size: 25px;
|
|
62
57
|
}
|
|
63
|
-
`;
|
|
64
58
|
|
|
59
|
+
h5 {
|
|
60
|
+
font-size: 20px;
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
65
63
|
function Heading({
|
|
66
64
|
className,
|
|
67
65
|
children
|
|
@@ -70,7 +68,6 @@ function Heading({
|
|
|
70
68
|
className: className
|
|
71
69
|
}, children);
|
|
72
70
|
}
|
|
73
|
-
|
|
74
71
|
const ListBlock = _styledComponents.default.ol`
|
|
75
72
|
width: 100%;
|
|
76
73
|
max-width: 700px;
|
|
@@ -84,7 +81,6 @@ const ListBlock = _styledComponents.default.ol`
|
|
|
84
81
|
margin-bottom: 6px;
|
|
85
82
|
}
|
|
86
83
|
`;
|
|
87
|
-
|
|
88
84
|
function OrderdedList({
|
|
89
85
|
children,
|
|
90
86
|
className
|
|
@@ -93,7 +89,6 @@ function OrderdedList({
|
|
|
93
89
|
className: className
|
|
94
90
|
}, children);
|
|
95
91
|
}
|
|
96
|
-
|
|
97
92
|
function UnorderdedList({
|
|
98
93
|
children,
|
|
99
94
|
className
|
|
@@ -103,7 +98,6 @@ function UnorderdedList({
|
|
|
103
98
|
className: className
|
|
104
99
|
}, children);
|
|
105
100
|
}
|
|
106
|
-
|
|
107
101
|
const _blockRenderMap = _immutable.default.Map({
|
|
108
102
|
atomic: {
|
|
109
103
|
element: 'div'
|
|
@@ -120,6 +114,10 @@ const _blockRenderMap = _immutable.default.Map({
|
|
|
120
114
|
element: 'h4',
|
|
121
115
|
wrapper: /*#__PURE__*/_react.default.createElement(Heading, null)
|
|
122
116
|
},
|
|
117
|
+
'header-five': {
|
|
118
|
+
element: 'h5',
|
|
119
|
+
wrapper: /*#__PURE__*/_react.default.createElement(Heading, null)
|
|
120
|
+
},
|
|
123
121
|
'ordered-list-item': {
|
|
124
122
|
element: 'li',
|
|
125
123
|
wrapper: /*#__PURE__*/_react.default.createElement(OrderdedList, null)
|
|
@@ -133,14 +131,10 @@ const _blockRenderMap = _immutable.default.Map({
|
|
|
133
131
|
wrapper: /*#__PURE__*/_react.default.createElement(Paragraph, null)
|
|
134
132
|
}
|
|
135
133
|
});
|
|
136
|
-
|
|
137
134
|
const blockRenderMap = _draftJs.DefaultDraftBlockRenderMap.merge(_blockRenderMap);
|
|
138
|
-
|
|
139
135
|
exports.blockRenderMap = blockRenderMap;
|
|
140
136
|
const HeadingForAnnotation = (0, _styledComponents.default)(Heading)`
|
|
141
|
-
|
|
142
|
-
font-size: 20px;
|
|
143
|
-
}
|
|
137
|
+
margin: 0 auto 27px auto;
|
|
144
138
|
`;
|
|
145
139
|
const OrderdedListForAnnotation = (0, _styledComponents.default)(OrderdedList)`
|
|
146
140
|
li {
|
|
@@ -156,14 +150,17 @@ const ParagraphForAnnotation = (0, _styledComponents.default)(Paragraph)`
|
|
|
156
150
|
/* overwrite css */
|
|
157
151
|
font-size: 16px;
|
|
158
152
|
font-weight: 400;
|
|
159
|
-
margin-bottom:
|
|
153
|
+
margin-bottom: 20px;
|
|
160
154
|
`;
|
|
161
|
-
|
|
162
155
|
const _blockRenderMapForAnnotation = _immutable.default.Map({
|
|
163
156
|
'header-four': {
|
|
164
157
|
element: 'h4',
|
|
165
158
|
wrapper: /*#__PURE__*/_react.default.createElement(HeadingForAnnotation, null)
|
|
166
159
|
},
|
|
160
|
+
'header-five': {
|
|
161
|
+
element: 'h5',
|
|
162
|
+
wrapper: /*#__PURE__*/_react.default.createElement(HeadingForAnnotation, null)
|
|
163
|
+
},
|
|
167
164
|
'ordered-list-item': {
|
|
168
165
|
element: 'li',
|
|
169
166
|
wrapper: /*#__PURE__*/_react.default.createElement(OrderdedListForAnnotation, null)
|
|
@@ -177,7 +174,47 @@ const _blockRenderMapForAnnotation = _immutable.default.Map({
|
|
|
177
174
|
wrapper: /*#__PURE__*/_react.default.createElement(ParagraphForAnnotation, null)
|
|
178
175
|
}
|
|
179
176
|
});
|
|
180
|
-
|
|
181
177
|
const blockRenderMapForAnnotation = _draftJs.DefaultDraftBlockRenderMap.merge(_blockRenderMapForAnnotation);
|
|
178
|
+
exports.blockRenderMapForAnnotation = blockRenderMapForAnnotation;
|
|
179
|
+
const HeadingForInfoBox = (0, _styledComponents.default)(Heading)`
|
|
180
|
+
margin-top: 30px;
|
|
181
|
+
margin-bottom: 30px;
|
|
182
|
+
`;
|
|
183
|
+
const blockRenderMapForInfoBox = blockRenderMapForAnnotation.merge(_immutable.default.Map({
|
|
184
|
+
'header-four': {
|
|
185
|
+
element: 'h4',
|
|
186
|
+
wrapper: /*#__PURE__*/_react.default.createElement(HeadingForInfoBox, null)
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
exports.blockRenderMapForInfoBox = blockRenderMapForInfoBox;
|
|
190
|
+
const dividerStyles = (0, _styledComponents.css)`
|
|
191
|
+
content: '';
|
|
192
|
+
width: 100%;
|
|
193
|
+
height: 12px;
|
|
194
|
+
display: block;
|
|
195
|
+
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/box2_768.png);
|
|
196
|
+
background-size: contain;
|
|
197
|
+
background-repeat: no-repeat;
|
|
198
|
+
background-position: center;
|
|
199
|
+
`;
|
|
200
|
+
const HeadingForInfoBoxWithHeaderBorder = (0, _styledComponents.default)(HeadingForInfoBox)`
|
|
201
|
+
h4 {
|
|
202
|
+
margin-top: 33px;
|
|
203
|
+
margin-bottom: 33px;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
&::before {
|
|
207
|
+
${dividerStyles}
|
|
208
|
+
}
|
|
182
209
|
|
|
183
|
-
|
|
210
|
+
&::after {
|
|
211
|
+
${dividerStyles}
|
|
212
|
+
}
|
|
213
|
+
`;
|
|
214
|
+
const blockRenderMapForInfoBoxWithHeaderBorder = blockRenderMapForInfoBox.merge(_immutable.default.Map({
|
|
215
|
+
'header-four': {
|
|
216
|
+
element: 'h4',
|
|
217
|
+
wrapper: /*#__PURE__*/_react.default.createElement(HeadingForInfoBoxWithHeaderBorder, null)
|
|
218
|
+
}
|
|
219
|
+
}));
|
|
220
|
+
exports.blockRenderMapForInfoBoxWithHeaderBorder = blockRenderMapForInfoBoxWithHeaderBorder;
|
package/lib/block-renderer-fn.js
CHANGED
|
@@ -4,22 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.atomicBlockRenderer = atomicBlockRenderer;
|
|
7
|
-
|
|
8
7
|
var _blockRenderers = require("./block-renderers");
|
|
9
|
-
|
|
10
8
|
const {
|
|
11
9
|
BlockquoteInArticleBody,
|
|
12
10
|
EmbeddedCodeInArticleBody,
|
|
13
11
|
ImageInArticleBody,
|
|
14
|
-
|
|
12
|
+
InfoBoxInArticleBody,
|
|
15
13
|
SlideshowInArticleBody
|
|
16
14
|
} = _blockRenderers.blockRenderers;
|
|
17
|
-
|
|
18
15
|
const AtomicBlock = props => {
|
|
19
16
|
const entity = props.contentState.getEntity(props.block.getEntityAt(0));
|
|
20
17
|
const entityType = entity.getType();
|
|
21
18
|
const entityData = entity.getData();
|
|
22
|
-
|
|
23
19
|
switch (entityType) {
|
|
24
20
|
case 'BLOCKQUOTE':
|
|
25
21
|
{
|
|
@@ -27,39 +23,33 @@ const AtomicBlock = props => {
|
|
|
27
23
|
data: entityData
|
|
28
24
|
});
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
case 'IMAGE':
|
|
32
27
|
{
|
|
33
28
|
return ImageInArticleBody({
|
|
34
29
|
data: entityData
|
|
35
30
|
});
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
case 'SLIDESHOW':
|
|
39
33
|
{
|
|
40
34
|
return SlideshowInArticleBody({
|
|
41
35
|
data: entityData
|
|
42
36
|
});
|
|
43
37
|
}
|
|
44
|
-
|
|
45
38
|
case 'EMBEDDEDCODE':
|
|
46
39
|
{
|
|
47
40
|
return EmbeddedCodeInArticleBody({
|
|
48
41
|
data: entityData
|
|
49
42
|
});
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
case 'INFOBOX':
|
|
53
45
|
{
|
|
54
|
-
return
|
|
46
|
+
return InfoBoxInArticleBody({
|
|
55
47
|
data: entityData
|
|
56
48
|
});
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
return null;
|
|
61
52
|
};
|
|
62
|
-
|
|
63
53
|
function atomicBlockRenderer(block) {
|
|
64
54
|
if (block.getType() === 'atomic') {
|
|
65
55
|
return {
|
|
@@ -67,6 +57,5 @@ function atomicBlockRenderer(block) {
|
|
|
67
57
|
editable: false
|
|
68
58
|
};
|
|
69
59
|
}
|
|
70
|
-
|
|
71
60
|
return null;
|
|
72
61
|
}
|
|
@@ -6,25 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.BlockquoteInArticleBody = BlockquoteInArticleBody;
|
|
7
7
|
exports.BorderLeftBlockquote = BorderLeftBlockquote;
|
|
8
8
|
exports.QuoteLeftBlockquote = QuoteLeftBlockquote;
|
|
9
|
-
|
|
10
9
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
-
|
|
14
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
12
|
const BorderLeftContainer = _styledComponents.default.blockquote`
|
|
17
13
|
margin: 0;
|
|
18
14
|
padding-left: 30px;
|
|
19
15
|
border-left: 4px solid #27b5f7;
|
|
20
16
|
`;
|
|
21
|
-
|
|
22
17
|
function BorderLeftBlockquote({
|
|
23
18
|
text
|
|
24
19
|
}) {
|
|
25
20
|
return /*#__PURE__*/_react.default.createElement(BorderLeftContainer, null, /*#__PURE__*/_react.default.createElement(QuoteText, null, text));
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
const QuoteLeftContainer = _styledComponents.default.blockquote`
|
|
29
23
|
margin: 0;
|
|
30
24
|
padding: 40px;
|
|
@@ -48,7 +42,6 @@ const SvgBlock = _styledComponents.default.div`
|
|
|
48
42
|
width: 36px;
|
|
49
43
|
}
|
|
50
44
|
`;
|
|
51
|
-
|
|
52
45
|
function QuoteSvg() {
|
|
53
46
|
return /*#__PURE__*/_react.default.createElement(SvgBlock, null, /*#__PURE__*/_react.default.createElement("svg", {
|
|
54
47
|
fill: "#27B5F7",
|
|
@@ -59,24 +52,20 @@ function QuoteSvg() {
|
|
|
59
52
|
d: "M9.4 14.6c-2.4 2.9-3.6 5.9-3.6 8.9 0 1.3.2 2.4.5 3.3 1.8-1.4 3.8-2.1 6-2.1 2.9 0 5.3.9 7.3 2.7 2 1.8 3 4.2 3 7.3 0 1.9-.5 3.6-1.4 5.1-.9 1.5-2.2 2.7-3.8 3.6s-3.3 1.3-5.1 1.3c-4.1 0-7.3-1.6-9.5-4.9C.9 36.9 0 33.5 0 29.4c0-5.2 1.4-9.9 4.1-14 2.8-4.1 6.9-7.5 12.5-10l1.5 2.8c-3.3 1.3-6.2 3.5-8.7 6.4zm27.5 0c-2.4 2.9-3.6 5.9-3.6 8.9 0 1.3.2 2.4.5 3.3 1.8-1.4 3.8-2.1 6-2.1 2.9 0 5.4.9 7.4 2.7 2 1.8 3 4.2 3 7.3 0 2.8-1 5.2-3 7.1-2 1.9-4.4 2.9-7.3 2.9-4.1 0-7.3-1.6-9.5-4.9-1.8-2.7-2.8-6.2-2.8-10.3 0-5.2 1.4-9.9 4.1-14 2.8-4.1 6.9-7.5 12.5-10l1.5 2.8c-3.5 1.2-6.4 3.4-8.8 6.3z"
|
|
60
53
|
})));
|
|
61
54
|
}
|
|
62
|
-
|
|
63
55
|
function QuoteLeftBlockquote({
|
|
64
56
|
text
|
|
65
57
|
}) {
|
|
66
58
|
return /*#__PURE__*/_react.default.createElement(QuoteLeftContainer, null, /*#__PURE__*/_react.default.createElement(QuoteSvg, null), /*#__PURE__*/_react.default.createElement(QuoteText, null, text));
|
|
67
59
|
}
|
|
68
|
-
|
|
69
60
|
const ArticleBodyContainer = _styledComponents.default.div`
|
|
70
61
|
max-width: 700px;
|
|
71
62
|
margin: 0 auto 27px auto;
|
|
72
63
|
`;
|
|
73
|
-
var BlockquoteType
|
|
74
|
-
|
|
75
|
-
(function (BlockquoteType) {
|
|
64
|
+
var BlockquoteType = /*#__PURE__*/function (BlockquoteType) {
|
|
76
65
|
BlockquoteType["borderLeft"] = "border_left";
|
|
77
66
|
BlockquoteType["quoteLeft"] = "quote_left";
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
return BlockquoteType;
|
|
68
|
+
}(BlockquoteType || {});
|
|
80
69
|
function BlockquoteInArticleBody({
|
|
81
70
|
className = '',
|
|
82
71
|
data = {
|
|
@@ -5,19 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.EmbeddedCodeBlock = exports.Caption = exports.Block = void 0;
|
|
7
7
|
exports.EmbeddedCodeInArticleBody = EmbeddedCodeInArticleBody;
|
|
8
|
-
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
|
|
11
9
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
12
|
-
|
|
13
10
|
var _nodeHtmlParser = require("node-html-parser");
|
|
14
|
-
|
|
15
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
12
|
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); }
|
|
18
|
-
|
|
19
13
|
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; }
|
|
20
|
-
|
|
21
14
|
const Block = _styledComponents.default.div`
|
|
22
15
|
position: relative;
|
|
23
16
|
white-space: normal;
|
|
@@ -40,7 +33,6 @@ const Caption = _styledComponents.default.div`
|
|
|
40
33
|
padding: 15px 15px 0 15px;
|
|
41
34
|
`;
|
|
42
35
|
exports.Caption = Caption;
|
|
43
|
-
|
|
44
36
|
const EmbeddedCodeBlock = ({
|
|
45
37
|
className,
|
|
46
38
|
data
|
|
@@ -49,7 +41,9 @@ const EmbeddedCodeBlock = ({
|
|
|
49
41
|
caption,
|
|
50
42
|
embeddedCode
|
|
51
43
|
} = data;
|
|
52
|
-
const embedded = (0, _react.useRef)(null);
|
|
44
|
+
const embedded = (0, _react.useRef)(null);
|
|
45
|
+
|
|
46
|
+
// `embeddedCode` is a string, which may includes
|
|
53
47
|
// multiple script tags and other html tags.
|
|
54
48
|
// Here we separate script tags and other html tags
|
|
55
49
|
// by using the isomorphic html parser 'node-html-parser'
|
|
@@ -65,7 +59,6 @@ const EmbeddedCodeBlock = ({
|
|
|
65
59
|
// 2. Although the setInnerhtml way won't trigger script tags, those script tags
|
|
66
60
|
// will still show on the HTML provided from SSR. When the browser parse the
|
|
67
61
|
// html it will run those script and produce unexpected behavior.
|
|
68
|
-
|
|
69
62
|
const nodes = (0, _react.useMemo)(() => {
|
|
70
63
|
const ele = (0, _nodeHtmlParser.parse)(`<div id="draft-embed">${embeddedCode}</div>`);
|
|
71
64
|
const scripts = ele.querySelectorAll('script');
|
|
@@ -91,11 +84,9 @@ const EmbeddedCodeBlock = ({
|
|
|
91
84
|
scripts.forEach(s => {
|
|
92
85
|
const scriptEle = document.createElement('script');
|
|
93
86
|
const attrs = s.attributes;
|
|
94
|
-
|
|
95
87
|
for (const key in attrs) {
|
|
96
88
|
scriptEle.setAttribute(key, attrs[key]);
|
|
97
89
|
}
|
|
98
|
-
|
|
99
90
|
scriptEle.text = s.text || '';
|
|
100
91
|
fragment.appendChild(scriptEle);
|
|
101
92
|
});
|
|
@@ -114,13 +105,11 @@ const EmbeddedCodeBlock = ({
|
|
|
114
105
|
}
|
|
115
106
|
}), caption && /*#__PURE__*/_react.default.createElement(Caption, null, caption));
|
|
116
107
|
};
|
|
117
|
-
|
|
118
108
|
exports.EmbeddedCodeBlock = EmbeddedCodeBlock;
|
|
119
109
|
const ArticleBodyContainer = _styledComponents.default.div`
|
|
120
110
|
max-width: 700px;
|
|
121
111
|
margin: 0 auto 27px auto;
|
|
122
112
|
`;
|
|
123
|
-
|
|
124
113
|
function EmbeddedCodeInArticleBody({
|
|
125
114
|
className = '',
|
|
126
115
|
data
|
|
@@ -5,15 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ImageBlock = ImageBlock;
|
|
7
7
|
exports.ImageInArticleBody = ImageInArticleBody;
|
|
8
|
-
|
|
8
|
+
exports.ImageInInfoBox = ImageInInfoBox;
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
12
|
-
|
|
13
11
|
var _index = require("../theme/index");
|
|
14
|
-
|
|
15
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
13
|
const Figure = _styledComponents.default.figure`
|
|
18
14
|
width: 100%;
|
|
19
15
|
`;
|
|
@@ -31,7 +27,6 @@ const FigureCaption = _styledComponents.default.figcaption`
|
|
|
31
27
|
const Img = _styledComponents.default.img`
|
|
32
28
|
width: 100%;
|
|
33
29
|
`;
|
|
34
|
-
|
|
35
30
|
function ImageBlock({
|
|
36
31
|
className = '',
|
|
37
32
|
data
|
|
@@ -42,15 +37,12 @@ function ImageBlock({
|
|
|
42
37
|
resized
|
|
43
38
|
} = data || {};
|
|
44
39
|
const imgSrcSetArr = [];
|
|
45
|
-
|
|
46
40
|
if (resized !== null && resized !== void 0 && resized.medium) {
|
|
47
41
|
imgSrcSetArr.push(`${resized.medium} 500w`);
|
|
48
42
|
}
|
|
49
|
-
|
|
50
43
|
if (resized !== null && resized !== void 0 && resized.large) {
|
|
51
44
|
imgSrcSetArr.push(`${resized.large} 1000w`);
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
const imgBlock = /*#__PURE__*/_react.default.createElement(Figure, {
|
|
55
47
|
className: className
|
|
56
48
|
}, /*#__PURE__*/_react.default.createElement(Img, {
|
|
@@ -59,10 +51,8 @@ function ImageBlock({
|
|
|
59
51
|
srcSet: imgSrcSetArr.join(','),
|
|
60
52
|
sizes: "(min-width: 1200px) 1000px, 100vw"
|
|
61
53
|
}), /*#__PURE__*/_react.default.createElement(FigureCaption, null, desc));
|
|
62
|
-
|
|
63
54
|
return imgBlock;
|
|
64
55
|
}
|
|
65
|
-
|
|
66
56
|
const ArticleBodyContainer = _styledComponents.default.div`
|
|
67
57
|
/* reset browser default styles */
|
|
68
58
|
figure {
|
|
@@ -90,7 +80,6 @@ const ArticleBodyContainer = _styledComponents.default.div`
|
|
|
90
80
|
margin: 5px 0px 5px 27px;
|
|
91
81
|
}
|
|
92
82
|
`;
|
|
93
|
-
|
|
94
83
|
case 'left':
|
|
95
84
|
return `
|
|
96
85
|
${_index.theme.breakpoint.xl} {
|
|
@@ -102,7 +91,6 @@ const ArticleBodyContainer = _styledComponents.default.div`
|
|
|
102
91
|
}
|
|
103
92
|
}}
|
|
104
93
|
`;
|
|
105
|
-
|
|
106
94
|
function ImageInArticleBody({
|
|
107
95
|
className = '',
|
|
108
96
|
data
|
|
@@ -113,4 +101,36 @@ function ImageInArticleBody({
|
|
|
113
101
|
}, /*#__PURE__*/_react.default.createElement(ImageBlock, {
|
|
114
102
|
data: data
|
|
115
103
|
}));
|
|
104
|
+
}
|
|
105
|
+
const InfoBoxContainer = _styledComponents.default.div`
|
|
106
|
+
/* reset browser default styles */
|
|
107
|
+
figure {
|
|
108
|
+
margin: 0;
|
|
109
|
+
}
|
|
110
|
+
margin-bottom: 30px;
|
|
111
|
+
width: fit-content;
|
|
112
|
+
|
|
113
|
+
${props => {
|
|
114
|
+
switch (props.$alignment) {
|
|
115
|
+
case 'center':
|
|
116
|
+
{
|
|
117
|
+
return `margin-left: auto; margin-right: auto;`;
|
|
118
|
+
}
|
|
119
|
+
case 'right':
|
|
120
|
+
{
|
|
121
|
+
return `margin-left: auto`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}}
|
|
125
|
+
`;
|
|
126
|
+
function ImageInInfoBox({
|
|
127
|
+
className = '',
|
|
128
|
+
data
|
|
129
|
+
}) {
|
|
130
|
+
return /*#__PURE__*/_react.default.createElement(InfoBoxContainer, {
|
|
131
|
+
$alignment: data.alignment,
|
|
132
|
+
className: className
|
|
133
|
+
}, /*#__PURE__*/_react.default.createElement(ImageBlock, {
|
|
134
|
+
data: data
|
|
135
|
+
}));
|
|
116
136
|
}
|
|
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.blockRenderers = void 0;
|
|
7
|
-
|
|
8
7
|
var _blockquote = require("./blockquote");
|
|
9
|
-
|
|
10
8
|
var _embeddedCodeBlock = require("./embedded-code-block");
|
|
11
|
-
|
|
12
9
|
var _imageBlock = require("./image-block");
|
|
13
|
-
|
|
14
10
|
var _infoBoxBlock = require("./info-box-block");
|
|
15
|
-
|
|
16
11
|
var _slideshowBlock = require("./slideshow-block");
|
|
17
|
-
|
|
18
12
|
const blockRenderers = {
|
|
19
13
|
BlockquoteInArticleBody: _blockquote.BlockquoteInArticleBody,
|
|
20
14
|
EmbeddedCodeBlock: _embeddedCodeBlock.EmbeddedCodeBlock,
|
|
@@ -4,33 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.InfoBoxInArticleBody = InfoBoxInArticleBody;
|
|
7
|
-
|
|
8
7
|
var _draftJs = require("draft-js");
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
-
|
|
10
|
+
var _blockRenderMap = require("../block-render-map");
|
|
11
|
+
var _imageBlock = require("../block-renderers/image-block");
|
|
14
12
|
var _index = require("../entity-decorators/index");
|
|
15
|
-
|
|
16
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
var InfoBoxType;
|
|
19
|
-
|
|
20
|
-
(function (InfoBoxType) {
|
|
14
|
+
var InfoBoxType = /*#__PURE__*/function (InfoBoxType) {
|
|
21
15
|
InfoBoxType["newsChargeStation"] = "news-charge-station";
|
|
22
|
-
InfoBoxType["headerBorder"] = "
|
|
23
|
-
InfoBoxType["boxBorder"] = "
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var InfoBoxLabel;
|
|
27
|
-
|
|
28
|
-
(function (InfoBoxLabel) {
|
|
29
|
-
InfoBoxLabel["newsChargeStation"] = "\u65B0\u805E\u5145\u96FB\u5668";
|
|
30
|
-
InfoBoxLabel["headerBorder"] = "\u7121\u908A\u6846\u677F";
|
|
31
|
-
InfoBoxLabel["boxBorder"] = "\u6709\u908A\u6846\u677F";
|
|
32
|
-
})(InfoBoxLabel || (InfoBoxLabel = {}));
|
|
33
|
-
|
|
16
|
+
InfoBoxType["headerBorder"] = "header-border";
|
|
17
|
+
InfoBoxType["boxBorder"] = "box-border";
|
|
18
|
+
return InfoBoxType;
|
|
19
|
+
}(InfoBoxType || {});
|
|
34
20
|
const NewsChargeStationContainer = _styledComponents.default.div`
|
|
35
21
|
padding: 40px;
|
|
36
22
|
background-color: #fffcf4;
|
|
@@ -41,33 +27,71 @@ const NewsChargeStationContainer = _styledComponents.default.div`
|
|
|
41
27
|
content: '';
|
|
42
28
|
width: 300px;
|
|
43
29
|
height: 80px;
|
|
30
|
+
/* TODO: change image url */
|
|
44
31
|
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/newsChargeStation.svg);
|
|
45
32
|
position: absolute;
|
|
46
33
|
top: -40px;
|
|
47
34
|
left: 50%;
|
|
48
35
|
transform: translateX(-50%);
|
|
49
|
-
}
|
|
36
|
+
}
|
|
50
37
|
`;
|
|
51
|
-
|
|
52
38
|
function NewsChargeStation({
|
|
53
39
|
children
|
|
54
40
|
}) {
|
|
55
41
|
return /*#__PURE__*/_react.default.createElement(NewsChargeStationContainer, null, children);
|
|
56
42
|
}
|
|
43
|
+
const HeaderBorderContainer = _styledComponents.default.div`
|
|
44
|
+
padding: 40px;
|
|
45
|
+
background-color: #d2f5ff;
|
|
46
|
+
position: relative;
|
|
47
|
+
border-radius: 30px;
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
&::before {
|
|
50
|
+
content: '';
|
|
51
|
+
width: 120px;
|
|
52
|
+
height: 120px;
|
|
53
|
+
/* TODO: change image url */
|
|
54
|
+
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/box2_yellow.png);
|
|
55
|
+
background-size: contain;
|
|
56
|
+
position: absolute;
|
|
57
|
+
bottom: 10px;
|
|
58
|
+
right: 10px;
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
function HeaderBorder({
|
|
62
|
+
children
|
|
63
|
+
}) {
|
|
64
|
+
return /*#__PURE__*/_react.default.createElement(HeaderBorderContainer, null, children);
|
|
60
65
|
}
|
|
66
|
+
const BoxBorderContainer = _styledComponents.default.div`
|
|
67
|
+
padding: 40px;
|
|
68
|
+
background-color: #ebebeb;
|
|
69
|
+
position: relative;
|
|
70
|
+
border-radius: 30px;
|
|
71
|
+
border: 3px solid #232323;
|
|
72
|
+
overflow: hidden;
|
|
61
73
|
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
&::before {
|
|
75
|
+
content: '';
|
|
76
|
+
width: 100px;
|
|
77
|
+
height: 100px;
|
|
78
|
+
/* TODO: change image url */
|
|
79
|
+
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/box2_blue-b.png);
|
|
80
|
+
background-size: contain;
|
|
81
|
+
position: absolute;
|
|
82
|
+
bottom: 0;
|
|
83
|
+
right: 0;
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
function BoxBorder({
|
|
87
|
+
children
|
|
88
|
+
}) {
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement(BoxBorderContainer, null, children);
|
|
64
90
|
}
|
|
65
|
-
|
|
66
91
|
const ArticleBodyContainer = _styledComponents.default.div`
|
|
67
92
|
max-width: 700px;
|
|
68
|
-
|
|
93
|
+
margin: 60px auto;
|
|
69
94
|
`;
|
|
70
|
-
|
|
71
95
|
function InfoBoxInArticleBody({
|
|
72
96
|
className,
|
|
73
97
|
data
|
|
@@ -77,24 +101,21 @@ function InfoBoxInArticleBody({
|
|
|
77
101
|
rawContentState
|
|
78
102
|
} = data;
|
|
79
103
|
const contentState = (0, _draftJs.convertFromRaw)(rawContentState);
|
|
80
|
-
|
|
81
|
-
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorators);
|
|
82
|
-
|
|
104
|
+
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorator);
|
|
83
105
|
let Component;
|
|
84
|
-
|
|
106
|
+
let blockRenderMap = _blockRenderMap.blockRenderMapForInfoBox;
|
|
85
107
|
switch (type) {
|
|
86
|
-
case InfoBoxType.
|
|
108
|
+
case InfoBoxType.headerBorder:
|
|
87
109
|
{
|
|
88
|
-
Component =
|
|
110
|
+
Component = HeaderBorder;
|
|
111
|
+
blockRenderMap = _blockRenderMap.blockRenderMapForInfoBoxWithHeaderBorder;
|
|
89
112
|
break;
|
|
90
113
|
}
|
|
91
|
-
|
|
92
|
-
case InfoBoxType.headerBorder:
|
|
114
|
+
case InfoBoxType.boxBorder:
|
|
93
115
|
{
|
|
94
|
-
Component =
|
|
116
|
+
Component = BoxBorder;
|
|
95
117
|
break;
|
|
96
118
|
}
|
|
97
|
-
|
|
98
119
|
case InfoBoxType.newsChargeStation:
|
|
99
120
|
default:
|
|
100
121
|
{
|
|
@@ -102,6 +123,38 @@ function InfoBoxInArticleBody({
|
|
|
102
123
|
break;
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
|
-
|
|
106
|
-
|
|
126
|
+
return /*#__PURE__*/_react.default.createElement(ArticleBodyContainer, {
|
|
127
|
+
className: className
|
|
128
|
+
}, /*#__PURE__*/_react.default.createElement(Component, null, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
129
|
+
blockRenderMap: blockRenderMap,
|
|
130
|
+
blockRendererFn: blockRendererFn,
|
|
131
|
+
editorState: editorState,
|
|
132
|
+
readOnly: true
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
134
|
+
,
|
|
135
|
+
onChange: () => {}
|
|
136
|
+
})));
|
|
137
|
+
}
|
|
138
|
+
function AtomicBlock(props) {
|
|
139
|
+
const entity = props.contentState.getEntity(props.block.getEntityAt(0));
|
|
140
|
+
const entityType = entity.getType();
|
|
141
|
+
const entityData = entity.getData();
|
|
142
|
+
switch (entityType) {
|
|
143
|
+
case 'IMAGE':
|
|
144
|
+
{
|
|
145
|
+
return (0, _imageBlock.ImageInInfoBox)({
|
|
146
|
+
data: entityData
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
function blockRendererFn(block) {
|
|
153
|
+
if (block.getType() === 'atomic') {
|
|
154
|
+
return {
|
|
155
|
+
component: AtomicBlock,
|
|
156
|
+
editable: false
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
107
160
|
}
|
|
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
|
|
9
|
-
|
|
10
8
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
// @ts-ignore @twreporter/core does not provide ts header file
|
|
11
|
+
|
|
15
12
|
const mockup = {
|
|
16
13
|
mobile: {
|
|
17
14
|
figure: {
|
|
@@ -19,47 +16,47 @@ const mockup = {
|
|
|
19
16
|
},
|
|
20
17
|
caption: {
|
|
21
18
|
width: 250 // px
|
|
22
|
-
|
|
23
19
|
}
|
|
24
20
|
},
|
|
21
|
+
|
|
25
22
|
tablet: {
|
|
26
23
|
figure: {
|
|
27
24
|
width: '100%'
|
|
28
25
|
},
|
|
29
26
|
caption: {
|
|
30
27
|
width: 512 // px
|
|
31
|
-
|
|
32
28
|
}
|
|
33
29
|
},
|
|
30
|
+
|
|
34
31
|
desktop: {
|
|
35
32
|
figure: {
|
|
36
33
|
width: {
|
|
37
34
|
normal: 100,
|
|
38
35
|
// %
|
|
39
36
|
small: 403 // px
|
|
40
|
-
|
|
41
37
|
}
|
|
42
38
|
},
|
|
39
|
+
|
|
43
40
|
caption: {
|
|
44
41
|
width: 180 // px
|
|
45
|
-
|
|
46
42
|
}
|
|
47
43
|
},
|
|
44
|
+
|
|
48
45
|
hd: {
|
|
49
46
|
figure: {
|
|
50
47
|
width: {
|
|
51
48
|
normal: 100,
|
|
52
49
|
// %
|
|
53
50
|
small: 532 // px
|
|
54
|
-
|
|
55
51
|
}
|
|
56
52
|
},
|
|
53
|
+
|
|
57
54
|
caption: {
|
|
58
55
|
width: 265 // px
|
|
59
|
-
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
58
|
};
|
|
59
|
+
|
|
63
60
|
const Caption = _styledComponents.default.figcaption`
|
|
64
61
|
color: #494949;
|
|
65
62
|
&::after {
|
|
@@ -5,96 +5,90 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.SlideshowBlock = SlideshowBlock;
|
|
7
7
|
exports.SlideshowInArticleBody = SlideshowInArticleBody;
|
|
8
|
-
|
|
9
8
|
var _multimedia = _interopRequireDefault(require("./multimedia"));
|
|
10
|
-
|
|
11
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
|
|
13
10
|
var _mediaQuery = _interopRequireDefault(require("@twreporter/core/lib/utils/media-query"));
|
|
14
|
-
|
|
15
11
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
16
|
-
|
|
17
12
|
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); }
|
|
18
|
-
|
|
19
13
|
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; }
|
|
20
|
-
|
|
21
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
15
|
// @ts-ignore pkg does not contain ts header file
|
|
16
|
+
|
|
24
17
|
const mockup = {
|
|
25
18
|
mobile: {
|
|
26
19
|
container: {
|
|
27
20
|
width: 375 // px
|
|
28
|
-
|
|
29
21
|
},
|
|
22
|
+
|
|
30
23
|
slide: {
|
|
31
24
|
width: 339,
|
|
32
25
|
// px
|
|
33
26
|
height: 189,
|
|
34
27
|
// px
|
|
35
28
|
paddingRight: 2 // px
|
|
36
|
-
|
|
37
29
|
},
|
|
30
|
+
|
|
38
31
|
offset: {
|
|
39
32
|
left: 18 // px
|
|
40
|
-
|
|
41
33
|
}
|
|
42
34
|
},
|
|
35
|
+
|
|
43
36
|
tablet: {
|
|
44
37
|
container: {
|
|
45
38
|
width: 768 // px
|
|
46
|
-
|
|
47
39
|
},
|
|
40
|
+
|
|
48
41
|
slide: {
|
|
49
42
|
width: 687,
|
|
50
43
|
// px
|
|
51
44
|
height: 387,
|
|
52
45
|
// px
|
|
53
46
|
paddingRight: 4 // px
|
|
54
|
-
|
|
55
47
|
},
|
|
48
|
+
|
|
56
49
|
offset: {
|
|
57
50
|
left: 41 // px
|
|
58
|
-
|
|
59
51
|
}
|
|
60
52
|
},
|
|
53
|
+
|
|
61
54
|
desktop: {
|
|
62
55
|
container: {
|
|
63
56
|
width: 752 // px
|
|
64
|
-
|
|
65
57
|
},
|
|
58
|
+
|
|
66
59
|
slide: {
|
|
67
60
|
width: 688,
|
|
68
61
|
// px
|
|
69
62
|
height: 387,
|
|
70
63
|
// px
|
|
71
64
|
paddingRight: 4 // px
|
|
72
|
-
|
|
73
65
|
},
|
|
66
|
+
|
|
74
67
|
offset: {
|
|
75
68
|
left: 32 // px
|
|
76
|
-
|
|
77
69
|
}
|
|
78
70
|
},
|
|
71
|
+
|
|
79
72
|
hd: {
|
|
80
73
|
container: {
|
|
81
74
|
width: 1034 // px
|
|
82
|
-
|
|
83
75
|
},
|
|
76
|
+
|
|
84
77
|
slide: {
|
|
85
78
|
width: 944,
|
|
86
79
|
// px
|
|
87
80
|
height: 531,
|
|
88
81
|
// px
|
|
89
82
|
paddingRight: 4 // px
|
|
90
|
-
|
|
91
83
|
},
|
|
84
|
+
|
|
92
85
|
offset: {
|
|
93
86
|
left: 45 // px
|
|
94
|
-
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
|
-
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Assuming there are three images [ A, B, C ] for slideshow.
|
|
98
92
|
// If image B is rendered in the center,
|
|
99
93
|
// users can see part of image A(left side) and image C(right side) with masks.
|
|
100
94
|
// When users click right button to see image C, which means, C is in the center,
|
|
@@ -105,11 +99,12 @@ const mockup = {
|
|
|
105
99
|
//
|
|
106
100
|
// `slidesOffset` indicates how many slides rendered before/after image B, which is, 2 (A and C).
|
|
107
101
|
//
|
|
102
|
+
const slidesOffset = 2;
|
|
108
103
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const duration = 300; // current index to indicate which image should be rendered in the center
|
|
104
|
+
// duration of transition of transform(translateX(?px))
|
|
105
|
+
const duration = 300;
|
|
112
106
|
|
|
107
|
+
// current index to indicate which image should be rendered in the center
|
|
113
108
|
const defaultCurIndex = 0;
|
|
114
109
|
const SlidesSection = _styledComponents.default.div`
|
|
115
110
|
flex-shrink: 0;
|
|
@@ -420,48 +415,45 @@ const SlideshowFlexBox = _styledComponents.default.div`
|
|
|
420
415
|
width: ${mockup.hd.container.width}px;
|
|
421
416
|
`}
|
|
422
417
|
`;
|
|
423
|
-
|
|
424
418
|
function getTranslateX(deviceMockup, unit) {
|
|
425
|
-
const slideWidth = getSlideWidth(deviceMockup);
|
|
419
|
+
const slideWidth = getSlideWidth(deviceMockup);
|
|
426
420
|
|
|
427
|
-
|
|
421
|
+
// total slides width including padding
|
|
422
|
+
let translateX = unit * slideWidth;
|
|
428
423
|
|
|
424
|
+
// add left mask width and padding
|
|
429
425
|
translateX = translateX + deviceMockup.offset.left;
|
|
430
426
|
return translateX; // px
|
|
431
427
|
}
|
|
428
|
+
|
|
432
429
|
/**
|
|
433
430
|
* @param {DeviceMockup} deviceMockup
|
|
434
431
|
* @return {number}
|
|
435
432
|
*/
|
|
436
|
-
|
|
437
|
-
|
|
438
433
|
function getContainerWidth(deviceMockup) {
|
|
439
434
|
return deviceMockup.container.width;
|
|
440
435
|
}
|
|
436
|
+
|
|
441
437
|
/**
|
|
442
438
|
* @param {DeviceMockup} deviceMockup
|
|
443
439
|
* @return {number}
|
|
444
440
|
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
441
|
function getSlideWidth(deviceMockup) {
|
|
448
442
|
return deviceMockup.slide.width + deviceMockup.slide.paddingRight;
|
|
449
443
|
}
|
|
444
|
+
|
|
450
445
|
/**
|
|
451
446
|
* @param {DeviceMockup} deviceMockup
|
|
452
447
|
* @return {number}
|
|
453
448
|
*/
|
|
454
|
-
|
|
455
|
-
|
|
456
449
|
function getLeftMaskWidth(deviceMockup) {
|
|
457
450
|
return deviceMockup.offset.left - deviceMockup.slide.paddingRight; // px
|
|
458
451
|
}
|
|
452
|
+
|
|
459
453
|
/**
|
|
460
454
|
* @param {DeviceMockup} deviceMockup
|
|
461
455
|
* @return {number}
|
|
462
456
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
457
|
function getRightMaskWidth(deviceMockup) {
|
|
466
458
|
return deviceMockup.container.width - deviceMockup.offset.left - getSlideWidth(deviceMockup); // px
|
|
467
459
|
}
|
|
@@ -471,21 +463,19 @@ function SlideshowBlock({
|
|
|
471
463
|
data
|
|
472
464
|
}) {
|
|
473
465
|
var _images$curSlideIndex;
|
|
466
|
+
const defaultTranslateXUnit = -slidesOffset;
|
|
474
467
|
|
|
475
|
-
|
|
468
|
+
// value of curSlideIndex would be in [ 0 ~ props.data.content.length ] range,
|
|
476
469
|
// it indicates which image should be placed in the center
|
|
477
|
-
|
|
478
470
|
const [curSlideIndex, setCurSlideIndex] = (0, _react.useState)(defaultCurIndex);
|
|
479
471
|
const [slideTo, setSlideTo] = (0, _react.useState)(''); // '', 'previous' or 'next'. '' means no sliding.
|
|
480
|
-
|
|
481
472
|
const [translateXUnit, setTranslateXUnit] = (0, _react.useState)(defaultTranslateXUnit);
|
|
482
473
|
const images = ((data === null || data === void 0 ? void 0 : data.images) || []).filter(img => {
|
|
483
474
|
var _img$imageFile;
|
|
484
|
-
|
|
485
|
-
return img === null || img === void 0 ? void 0 : (_img$imageFile = img.imageFile) === null || _img$imageFile === void 0 ? void 0 : _img$imageFile.url;
|
|
475
|
+
return img === null || img === void 0 || (_img$imageFile = img.imageFile) === null || _img$imageFile === void 0 ? void 0 : _img$imageFile.url;
|
|
486
476
|
});
|
|
487
477
|
const total = images === null || images === void 0 ? void 0 : images.length;
|
|
488
|
-
const desc = images === null || images === void 0
|
|
478
|
+
const desc = images === null || images === void 0 || (_images$curSlideIndex = images[curSlideIndex]) === null || _images$curSlideIndex === void 0 ? void 0 : _images$curSlideIndex.desc;
|
|
489
479
|
const appendedClassName = className + ' avoid-break';
|
|
490
480
|
const slides = (0, _react.useMemo)(() => {
|
|
491
481
|
// add last `slidesOffset` elements into top of images array.
|
|
@@ -497,24 +487,19 @@ function SlideshowBlock({
|
|
|
497
487
|
const _images = [...images.slice(-slidesOffset), ...images, ...images.slice(defaultCurIndex, slidesOffset)];
|
|
498
488
|
return _images === null || _images === void 0 ? void 0 : _images.map((img, index) => {
|
|
499
489
|
var _img$resized, _img$resized2, _img$resized3, _img$resized4;
|
|
500
|
-
|
|
501
490
|
const width = img.imageFile.width ?? 0;
|
|
502
491
|
const height = img.imageFile.height ?? 0;
|
|
503
492
|
const imgSrc = ((_img$resized = img.resized) === null || _img$resized === void 0 ? void 0 : _img$resized.medium) ?? img.imageFile.url;
|
|
504
493
|
const imgSrcSetArr = [];
|
|
505
|
-
|
|
506
494
|
if ((_img$resized2 = img.resized) !== null && _img$resized2 !== void 0 && _img$resized2.small) {
|
|
507
495
|
imgSrcSetArr.push(`${img.resized.medium} 600w`);
|
|
508
496
|
}
|
|
509
|
-
|
|
510
497
|
if ((_img$resized3 = img.resized) !== null && _img$resized3 !== void 0 && _img$resized3.medium) {
|
|
511
498
|
imgSrcSetArr.push(`${img.resized.medium} 1200w`);
|
|
512
499
|
}
|
|
513
|
-
|
|
514
500
|
if ((_img$resized4 = img.resized) !== null && _img$resized4 !== void 0 && _img$resized4.large) {
|
|
515
501
|
imgSrcSetArr.push(`${img.resized.large} 2000w`);
|
|
516
502
|
}
|
|
517
|
-
|
|
518
503
|
const objectFit = width > height ? 'cover' : 'contain';
|
|
519
504
|
return (
|
|
520
505
|
/*#__PURE__*/
|
|
@@ -534,38 +519,30 @@ function SlideshowBlock({
|
|
|
534
519
|
);
|
|
535
520
|
});
|
|
536
521
|
}, [images]);
|
|
537
|
-
|
|
538
522
|
const slideToPrev = () => {
|
|
539
523
|
setSlideTo('previous');
|
|
540
524
|
setTranslateXUnit(translateXUnit + 1);
|
|
541
525
|
};
|
|
542
|
-
|
|
543
526
|
const slideToNext = () => {
|
|
544
527
|
setSlideTo('next');
|
|
545
528
|
setTranslateXUnit(translateXUnit - 1);
|
|
546
529
|
};
|
|
547
|
-
|
|
548
530
|
(0, _react.useEffect)(() => {
|
|
549
531
|
if (slideTo === '') {
|
|
550
532
|
return;
|
|
551
533
|
}
|
|
552
|
-
|
|
553
534
|
let _curSlideIndex;
|
|
554
|
-
|
|
555
535
|
if (slideTo === 'previous') {
|
|
556
536
|
_curSlideIndex = curSlideIndex - 1;
|
|
557
|
-
|
|
558
537
|
if (_curSlideIndex < defaultCurIndex) {
|
|
559
538
|
_curSlideIndex = total + _curSlideIndex;
|
|
560
539
|
}
|
|
561
540
|
} else if (slideTo === 'next') {
|
|
562
541
|
_curSlideIndex = curSlideIndex + 1;
|
|
563
|
-
|
|
564
542
|
if (_curSlideIndex >= total) {
|
|
565
543
|
_curSlideIndex = _curSlideIndex % total;
|
|
566
544
|
}
|
|
567
545
|
}
|
|
568
|
-
|
|
569
546
|
setTimeout(() => {
|
|
570
547
|
setSlideTo('');
|
|
571
548
|
setCurSlideIndex(_curSlideIndex);
|
|
@@ -585,7 +562,6 @@ function SlideshowBlock({
|
|
|
585
562
|
onClick: isSliding ? undefined : slideToNext
|
|
586
563
|
}, /*#__PURE__*/_react.default.createElement(NextArrowSvg, null))), /*#__PURE__*/_react.default.createElement(ImageNumberCircle, null, /*#__PURE__*/_react.default.createElement(ImageNumber, null, curSlideIndex + 1), /*#__PURE__*/_react.default.createElement(ImageTotal, null, total)), desc ? /*#__PURE__*/_react.default.createElement(Desc, null, desc) : /*#__PURE__*/_react.default.createElement(EmptyDesc, null));
|
|
587
564
|
}
|
|
588
|
-
|
|
589
565
|
function NextArrowSvg() {
|
|
590
566
|
return /*#__PURE__*/_react.default.createElement("svg", {
|
|
591
567
|
viewBox: "0 0 31 17",
|
|
@@ -598,7 +574,6 @@ function NextArrowSvg() {
|
|
|
598
574
|
fillRule: "nonzero"
|
|
599
575
|
}));
|
|
600
576
|
}
|
|
601
|
-
|
|
602
577
|
function PreArrowSvg() {
|
|
603
578
|
return /*#__PURE__*/_react.default.createElement("svg", {
|
|
604
579
|
viewBox: "0 0 31 17",
|
|
@@ -610,12 +585,10 @@ function PreArrowSvg() {
|
|
|
610
585
|
fill: "gray"
|
|
611
586
|
}));
|
|
612
587
|
}
|
|
613
|
-
|
|
614
588
|
const ArticleBodyContainer = _styledComponents.default.div`
|
|
615
589
|
width: fit-content;
|
|
616
590
|
margin: 0 auto 27px auto;
|
|
617
591
|
`;
|
|
618
|
-
|
|
619
592
|
function SlideshowInArticleBody({
|
|
620
593
|
className = '',
|
|
621
594
|
data
|
package/lib/draft-renderer.js
CHANGED
|
@@ -4,46 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.DraftRenderer = DraftRenderer;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _draftJs = require("draft-js");
|
|
11
|
-
|
|
12
9
|
var _blockRendererFn = require("./block-renderer-fn");
|
|
13
|
-
|
|
14
10
|
var _blockRenderMap = require("./block-render-map");
|
|
15
|
-
|
|
16
11
|
var _index = require("./entity-decorators/index");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
const customStyleMap = {
|
|
21
|
-
CODE: {
|
|
22
|
-
backgroundColor: 'rgba(0, 0, 0, 0.05)',
|
|
23
|
-
fontFamily: '"Inconsolata", "Menlo", "Consolas", monospace',
|
|
24
|
-
fontSize: 16,
|
|
25
|
-
padding: 2
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
13
|
const blockRendererFn = block => {
|
|
30
14
|
const atomicBlockObj = (0, _blockRendererFn.atomicBlockRenderer)(block);
|
|
31
15
|
return atomicBlockObj;
|
|
32
16
|
};
|
|
33
|
-
|
|
34
17
|
function DraftRenderer({
|
|
35
|
-
|
|
18
|
+
rawContentState
|
|
36
19
|
}) {
|
|
37
|
-
const contentState = (0, _draftJs.convertFromRaw)(
|
|
38
|
-
|
|
39
|
-
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorators);
|
|
40
|
-
|
|
20
|
+
const contentState = (0, _draftJs.convertFromRaw)(rawContentState);
|
|
21
|
+
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorator);
|
|
41
22
|
return /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
42
23
|
editorState: editorState,
|
|
43
|
-
customStyleMap: customStyleMap,
|
|
44
24
|
blockRenderMap: _blockRenderMap.blockRenderMap,
|
|
45
25
|
blockRendererFn: blockRendererFn,
|
|
46
|
-
readOnly: true
|
|
26
|
+
readOnly: true
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
47
28
|
,
|
|
48
29
|
onChange: () => {}
|
|
49
30
|
});
|
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.annotationDecorator = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
8
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
-
|
|
12
9
|
var _draftJs = require("draft-js");
|
|
13
|
-
|
|
14
10
|
var _blockRenderMap = require("../block-render-map");
|
|
15
|
-
|
|
16
11
|
var _index = require("../entity-decorators/index");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
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); }
|
|
21
|
-
|
|
22
14
|
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; }
|
|
23
|
-
|
|
24
15
|
const AnnotationWrapper = _styledComponents.default.span`
|
|
25
16
|
display: inline-block;
|
|
26
17
|
cursor: pointer;
|
|
@@ -70,7 +61,6 @@ const ArrowIcon = _styledComponents.default.span`
|
|
|
70
61
|
transition: transform 200ms ease 0s;
|
|
71
62
|
}
|
|
72
63
|
`;
|
|
73
|
-
|
|
74
64
|
function AnnotationBlock(props) {
|
|
75
65
|
const {
|
|
76
66
|
children: annotated
|
|
@@ -80,9 +70,7 @@ function AnnotationBlock(props) {
|
|
|
80
70
|
rawContentState
|
|
81
71
|
} = props.contentState.getEntity(props.entityKey).getData();
|
|
82
72
|
const contentState = (0, _draftJs.convertFromRaw)(rawContentState);
|
|
83
|
-
|
|
84
|
-
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorators);
|
|
85
|
-
|
|
73
|
+
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorator);
|
|
86
74
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(AnnotationWrapper, {
|
|
87
75
|
onClick: e => {
|
|
88
76
|
e.preventDefault();
|
|
@@ -93,19 +81,18 @@ function AnnotationBlock(props) {
|
|
|
93
81
|
})), showContent ? /*#__PURE__*/_react.default.createElement(AnnotationBody, null, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
94
82
|
editorState: editorState,
|
|
95
83
|
blockRenderMap: _blockRenderMap.blockRenderMapForAnnotation,
|
|
96
|
-
readOnly: true
|
|
84
|
+
readOnly: true
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
97
86
|
,
|
|
98
87
|
onChange: () => {}
|
|
99
88
|
})) : null);
|
|
100
89
|
}
|
|
101
|
-
|
|
102
90
|
function findAnnotationEntities(contentBlock, callback, contentState) {
|
|
103
91
|
contentBlock.findEntityRanges(character => {
|
|
104
92
|
const entityKey = character.getEntity();
|
|
105
93
|
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'ANNOTATION';
|
|
106
94
|
}, callback);
|
|
107
95
|
}
|
|
108
|
-
|
|
109
96
|
const annotationDecorator = {
|
|
110
97
|
strategy: findAnnotationEntities,
|
|
111
98
|
component: AnnotationBlock
|
|
@@ -9,19 +9,15 @@ Object.defineProperty(exports, "annotationDecorator", {
|
|
|
9
9
|
return _annotationDecorator.annotationDecorator;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
exports.
|
|
12
|
+
exports.decorator = void 0;
|
|
13
13
|
Object.defineProperty(exports, "linkDecorator", {
|
|
14
14
|
enumerable: true,
|
|
15
15
|
get: function () {
|
|
16
16
|
return _linkDecorator.linkDecorator;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
|
|
20
19
|
var _draftJs = require("draft-js");
|
|
21
|
-
|
|
22
20
|
var _annotationDecorator = require("./annotation-decorator");
|
|
23
|
-
|
|
24
21
|
var _linkDecorator = require("./link-decorator");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
exports.decorators = decorators;
|
|
22
|
+
const decorator = new _draftJs.CompositeDecorator([_annotationDecorator.annotationDecorator, _linkDecorator.linkDecorator]);
|
|
23
|
+
exports.decorator = decorator;
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.linkDecorator = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
8
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const LinkWrapper = _styledComponents.default.a`
|
|
15
11
|
text-decoration: underline;
|
|
16
12
|
color: #27b5f7;
|
|
@@ -20,20 +16,17 @@ const LinkWrapper = _styledComponents.default.a`
|
|
|
20
16
|
color: #232323;
|
|
21
17
|
}
|
|
22
18
|
`;
|
|
23
|
-
|
|
24
19
|
function findLinkEntities(contentBlock, callback, contentState) {
|
|
25
20
|
contentBlock.findEntityRanges(character => {
|
|
26
21
|
const entityKey = character.getEntity();
|
|
27
22
|
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK';
|
|
28
23
|
}, callback);
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
const linkDecorator = {
|
|
32
26
|
strategy: findLinkEntities,
|
|
33
27
|
component: Link
|
|
34
28
|
};
|
|
35
29
|
exports.linkDecorator = linkDecorator;
|
|
36
|
-
|
|
37
30
|
function Link(props) {
|
|
38
31
|
const {
|
|
39
32
|
url
|
package/lib/index.js
CHANGED
|
@@ -27,29 +27,23 @@ Object.defineProperty(exports, "blockRenderers", {
|
|
|
27
27
|
return _blockRenderers.blockRenderers;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "decorator", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function () {
|
|
33
|
-
return _index.
|
|
33
|
+
return _index.decorator;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
exports.default = void 0;
|
|
37
|
-
|
|
38
37
|
var _draftRenderer = require("./draft-renderer");
|
|
39
|
-
|
|
40
38
|
var _blockRendererFn = require("./block-renderer-fn");
|
|
41
|
-
|
|
42
39
|
var _blockRenderMap = require("./block-render-map");
|
|
43
|
-
|
|
44
40
|
var _blockRenderers = require("./block-renderers");
|
|
45
|
-
|
|
46
41
|
var _index = require("./entity-decorators/index");
|
|
47
|
-
|
|
48
42
|
var _default = {
|
|
49
43
|
DraftRenderer: _draftRenderer.DraftRenderer,
|
|
50
44
|
atomicBlockRenderer: _blockRendererFn.atomicBlockRenderer,
|
|
51
45
|
blockRenderMap: _blockRenderMap.blockRenderMap,
|
|
52
46
|
blockRenderers: _blockRenderers.blockRenderers,
|
|
53
|
-
|
|
47
|
+
decorator: _index.decorator
|
|
54
48
|
};
|
|
55
49
|
exports.default = _default;
|