@kids-reporter/draft-renderer 0.3.0 → 0.4.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/lib/block-render-map.js +54 -10
- package/lib/block-renderer-fn.js +2 -2
- package/lib/block-renderers/image-block.js +36 -0
- package/lib/block-renderers/info-box-block.js +102 -22
- package/lib/draft-renderer.js +3 -3
- package/lib/entity-decorators/annotation-decorator.js +1 -1
- package/lib/entity-decorators/index.js +3 -3
- package/lib/index.js +3 -3
- package/package.json +1 -1
package/lib/block-render-map.js
CHANGED
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.blockRenderMapForAnnotation = exports.blockRenderMap = void 0;
|
|
6
|
+
exports.blockRenderMapForInfoBoxWithHeaderBorder = exports.blockRenderMapForInfoBox = exports.blockRenderMapForAnnotation = exports.blockRenderMap = void 0;
|
|
7
7
|
|
|
8
8
|
var _immutable = _interopRequireDefault(require("immutable"));
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
-
var _styledComponents =
|
|
12
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
13
13
|
|
|
14
14
|
var _draftJs = require("draft-js");
|
|
15
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
|
+
|
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
21
|
|
|
18
22
|
const ParagraphBlock = _styledComponents.default.div`
|
|
@@ -50,15 +54,15 @@ const HeadingBlock = _styledComponents.default.div`
|
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
h2 {
|
|
53
|
-
font-size:
|
|
57
|
+
font-size: 35px;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
h3 {
|
|
57
|
-
font-size:
|
|
61
|
+
font-size: 30px;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
h4 {
|
|
61
|
-
font-size:
|
|
65
|
+
font-size: 25px;
|
|
62
66
|
}
|
|
63
67
|
`;
|
|
64
68
|
|
|
@@ -138,9 +142,7 @@ const blockRenderMap = _draftJs.DefaultDraftBlockRenderMap.merge(_blockRenderMap
|
|
|
138
142
|
|
|
139
143
|
exports.blockRenderMap = blockRenderMap;
|
|
140
144
|
const HeadingForAnnotation = (0, _styledComponents.default)(Heading)`
|
|
141
|
-
|
|
142
|
-
font-size: 20px;
|
|
143
|
-
}
|
|
145
|
+
margin: 0 auto 27px auto;
|
|
144
146
|
`;
|
|
145
147
|
const OrderdedListForAnnotation = (0, _styledComponents.default)(OrderdedList)`
|
|
146
148
|
li {
|
|
@@ -156,7 +158,7 @@ const ParagraphForAnnotation = (0, _styledComponents.default)(Paragraph)`
|
|
|
156
158
|
/* overwrite css */
|
|
157
159
|
font-size: 16px;
|
|
158
160
|
font-weight: 400;
|
|
159
|
-
margin-bottom:
|
|
161
|
+
margin-bottom: 20px;
|
|
160
162
|
`;
|
|
161
163
|
|
|
162
164
|
const _blockRenderMapForAnnotation = _immutable.default.Map({
|
|
@@ -180,4 +182,46 @@ const _blockRenderMapForAnnotation = _immutable.default.Map({
|
|
|
180
182
|
|
|
181
183
|
const blockRenderMapForAnnotation = _draftJs.DefaultDraftBlockRenderMap.merge(_blockRenderMapForAnnotation);
|
|
182
184
|
|
|
183
|
-
exports.blockRenderMapForAnnotation = blockRenderMapForAnnotation;
|
|
185
|
+
exports.blockRenderMapForAnnotation = blockRenderMapForAnnotation;
|
|
186
|
+
const HeadingForInfoBox = (0, _styledComponents.default)(Heading)`
|
|
187
|
+
margin-top: 30px;
|
|
188
|
+
margin-bottom: 30px;
|
|
189
|
+
`;
|
|
190
|
+
const blockRenderMapForInfoBox = blockRenderMapForAnnotation.merge(_immutable.default.Map({
|
|
191
|
+
'header-four': {
|
|
192
|
+
element: 'h4',
|
|
193
|
+
wrapper: /*#__PURE__*/_react.default.createElement(HeadingForInfoBox, null)
|
|
194
|
+
}
|
|
195
|
+
}));
|
|
196
|
+
exports.blockRenderMapForInfoBox = blockRenderMapForInfoBox;
|
|
197
|
+
const dividerStyles = (0, _styledComponents.css)`
|
|
198
|
+
content: '';
|
|
199
|
+
width: 100%;
|
|
200
|
+
height: 12px;
|
|
201
|
+
display: block;
|
|
202
|
+
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/box2_768.png);
|
|
203
|
+
background-size: contain;
|
|
204
|
+
background-repeat: no-repeat;
|
|
205
|
+
background-position: center;
|
|
206
|
+
`;
|
|
207
|
+
const HeadingForInfoBoxWithHeaderBorder = (0, _styledComponents.default)(HeadingForInfoBox)`
|
|
208
|
+
h4 {
|
|
209
|
+
margin-top: 33px;
|
|
210
|
+
margin-bottom: 33px;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
&::before {
|
|
214
|
+
${dividerStyles}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&::after {
|
|
218
|
+
${dividerStyles}
|
|
219
|
+
}
|
|
220
|
+
`;
|
|
221
|
+
const blockRenderMapForInfoBoxWithHeaderBorder = blockRenderMapForInfoBox.merge(_immutable.default.Map({
|
|
222
|
+
'header-four': {
|
|
223
|
+
element: 'h4',
|
|
224
|
+
wrapper: /*#__PURE__*/_react.default.createElement(HeadingForInfoBoxWithHeaderBorder, null)
|
|
225
|
+
}
|
|
226
|
+
}));
|
|
227
|
+
exports.blockRenderMapForInfoBoxWithHeaderBorder = blockRenderMapForInfoBoxWithHeaderBorder;
|
package/lib/block-renderer-fn.js
CHANGED
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
BlockquoteInArticleBody,
|
|
12
12
|
EmbeddedCodeInArticleBody,
|
|
13
13
|
ImageInArticleBody,
|
|
14
|
-
|
|
14
|
+
InfoBoxInArticleBody,
|
|
15
15
|
SlideshowInArticleBody
|
|
16
16
|
} = _blockRenderers.blockRenderers;
|
|
17
17
|
|
|
@@ -51,7 +51,7 @@ const AtomicBlock = props => {
|
|
|
51
51
|
|
|
52
52
|
case 'INFOBOX':
|
|
53
53
|
{
|
|
54
|
-
return
|
|
54
|
+
return InfoBoxInArticleBody({
|
|
55
55
|
data: entityData
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ImageBlock = ImageBlock;
|
|
7
7
|
exports.ImageInArticleBody = ImageInArticleBody;
|
|
8
|
+
exports.ImageInInfoBox = ImageInInfoBox;
|
|
8
9
|
|
|
9
10
|
var _react = _interopRequireDefault(require("react"));
|
|
10
11
|
|
|
@@ -113,4 +114,39 @@ function ImageInArticleBody({
|
|
|
113
114
|
}, /*#__PURE__*/_react.default.createElement(ImageBlock, {
|
|
114
115
|
data: data
|
|
115
116
|
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const InfoBoxContainer = _styledComponents.default.div`
|
|
120
|
+
/* reset browser default styles */
|
|
121
|
+
figure {
|
|
122
|
+
margin: 0;
|
|
123
|
+
}
|
|
124
|
+
margin-bottom: 30px;
|
|
125
|
+
width: fit-content;
|
|
126
|
+
|
|
127
|
+
${props => {
|
|
128
|
+
switch (props.$alignment) {
|
|
129
|
+
case 'center':
|
|
130
|
+
{
|
|
131
|
+
return `margin-left: auto; margin-right: auto;`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
case 'right':
|
|
135
|
+
{
|
|
136
|
+
return `margin-left: auto`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}}
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
function ImageInInfoBox({
|
|
143
|
+
className = '',
|
|
144
|
+
data
|
|
145
|
+
}) {
|
|
146
|
+
return /*#__PURE__*/_react.default.createElement(InfoBoxContainer, {
|
|
147
|
+
$alignment: data.alignment,
|
|
148
|
+
className: className
|
|
149
|
+
}, /*#__PURE__*/_react.default.createElement(ImageBlock, {
|
|
150
|
+
data: data
|
|
151
|
+
}));
|
|
116
152
|
}
|
|
@@ -11,6 +11,10 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
11
11
|
|
|
12
12
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
13
|
|
|
14
|
+
var _blockRenderMap = require("../block-render-map");
|
|
15
|
+
|
|
16
|
+
var _imageBlock = require("../block-renderers/image-block");
|
|
17
|
+
|
|
14
18
|
var _index = require("../entity-decorators/index");
|
|
15
19
|
|
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -19,18 +23,10 @@ var InfoBoxType;
|
|
|
19
23
|
|
|
20
24
|
(function (InfoBoxType) {
|
|
21
25
|
InfoBoxType["newsChargeStation"] = "news-charge-station";
|
|
22
|
-
InfoBoxType["headerBorder"] = "
|
|
23
|
-
InfoBoxType["boxBorder"] = "
|
|
26
|
+
InfoBoxType["headerBorder"] = "header-border";
|
|
27
|
+
InfoBoxType["boxBorder"] = "box-border";
|
|
24
28
|
})(InfoBoxType || (InfoBoxType = {}));
|
|
25
29
|
|
|
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
|
-
|
|
34
30
|
const NewsChargeStationContainer = _styledComponents.default.div`
|
|
35
31
|
padding: 40px;
|
|
36
32
|
background-color: #fffcf4;
|
|
@@ -41,12 +37,13 @@ const NewsChargeStationContainer = _styledComponents.default.div`
|
|
|
41
37
|
content: '';
|
|
42
38
|
width: 300px;
|
|
43
39
|
height: 80px;
|
|
40
|
+
/* TODO: change image url */
|
|
44
41
|
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/newsChargeStation.svg);
|
|
45
42
|
position: absolute;
|
|
46
43
|
top: -40px;
|
|
47
44
|
left: 50%;
|
|
48
45
|
transform: translateX(-50%);
|
|
49
|
-
}
|
|
46
|
+
}
|
|
50
47
|
`;
|
|
51
48
|
|
|
52
49
|
function NewsChargeStation({
|
|
@@ -55,17 +52,61 @@ function NewsChargeStation({
|
|
|
55
52
|
return /*#__PURE__*/_react.default.createElement(NewsChargeStationContainer, null, children);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const HeaderBorderContainer = _styledComponents.default.div`
|
|
56
|
+
padding: 40px;
|
|
57
|
+
background-color: #d2f5ff;
|
|
58
|
+
position: relative;
|
|
59
|
+
border-radius: 30px;
|
|
60
|
+
|
|
61
|
+
&::before {
|
|
62
|
+
content: '';
|
|
63
|
+
width: 120px;
|
|
64
|
+
height: 120px;
|
|
65
|
+
/* TODO: change image url */
|
|
66
|
+
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/box2_yellow.png);
|
|
67
|
+
background-size: contain;
|
|
68
|
+
position: absolute;
|
|
69
|
+
bottom: 10px;
|
|
70
|
+
right: 10px;
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
function HeaderBorder({
|
|
75
|
+
children
|
|
76
|
+
}) {
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement(HeaderBorderContainer, null, children);
|
|
60
78
|
}
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
const BoxBorderContainer = _styledComponents.default.div`
|
|
81
|
+
padding: 40px;
|
|
82
|
+
background-color: #ebebeb;
|
|
83
|
+
position: relative;
|
|
84
|
+
border-radius: 30px;
|
|
85
|
+
border: 3px solid #232323;
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
|
|
88
|
+
&::before {
|
|
89
|
+
content: '';
|
|
90
|
+
width: 100px;
|
|
91
|
+
height: 100px;
|
|
92
|
+
/* TODO: change image url */
|
|
93
|
+
background-image: url(https://kids.twreporter.org/wp-content/themes/blocksy-child/assets/js/components/rpjr-box/box2_blue-b.png);
|
|
94
|
+
background-size: contain;
|
|
95
|
+
position: absolute;
|
|
96
|
+
bottom: 0;
|
|
97
|
+
right: 0;
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
function BoxBorder({
|
|
102
|
+
children
|
|
103
|
+
}) {
|
|
104
|
+
return /*#__PURE__*/_react.default.createElement(BoxBorderContainer, null, children);
|
|
64
105
|
}
|
|
65
106
|
|
|
66
107
|
const ArticleBodyContainer = _styledComponents.default.div`
|
|
67
108
|
max-width: 700px;
|
|
68
|
-
|
|
109
|
+
margin: 60px auto;
|
|
69
110
|
`;
|
|
70
111
|
|
|
71
112
|
function InfoBoxInArticleBody({
|
|
@@ -78,20 +119,22 @@ function InfoBoxInArticleBody({
|
|
|
78
119
|
} = data;
|
|
79
120
|
const contentState = (0, _draftJs.convertFromRaw)(rawContentState);
|
|
80
121
|
|
|
81
|
-
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.
|
|
122
|
+
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorator);
|
|
82
123
|
|
|
83
124
|
let Component;
|
|
125
|
+
let blockRenderMap = _blockRenderMap.blockRenderMapForInfoBox;
|
|
84
126
|
|
|
85
127
|
switch (type) {
|
|
86
|
-
case InfoBoxType.
|
|
128
|
+
case InfoBoxType.headerBorder:
|
|
87
129
|
{
|
|
88
|
-
Component =
|
|
130
|
+
Component = HeaderBorder;
|
|
131
|
+
blockRenderMap = _blockRenderMap.blockRenderMapForInfoBoxWithHeaderBorder;
|
|
89
132
|
break;
|
|
90
133
|
}
|
|
91
134
|
|
|
92
|
-
case InfoBoxType.
|
|
135
|
+
case InfoBoxType.boxBorder:
|
|
93
136
|
{
|
|
94
|
-
Component =
|
|
137
|
+
Component = BoxBorder;
|
|
95
138
|
break;
|
|
96
139
|
}
|
|
97
140
|
|
|
@@ -103,5 +146,42 @@ function InfoBoxInArticleBody({
|
|
|
103
146
|
}
|
|
104
147
|
}
|
|
105
148
|
|
|
106
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
149
|
+
return /*#__PURE__*/_react.default.createElement(ArticleBodyContainer, {
|
|
150
|
+
className: className
|
|
151
|
+
}, /*#__PURE__*/_react.default.createElement(Component, null, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
152
|
+
blockRenderMap: blockRenderMap,
|
|
153
|
+
blockRendererFn: blockRendererFn,
|
|
154
|
+
editorState: editorState,
|
|
155
|
+
readOnly: true // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
156
|
+
,
|
|
157
|
+
onChange: () => {}
|
|
158
|
+
})));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function AtomicBlock(props) {
|
|
162
|
+
const entity = props.contentState.getEntity(props.block.getEntityAt(0));
|
|
163
|
+
const entityType = entity.getType();
|
|
164
|
+
const entityData = entity.getData();
|
|
165
|
+
|
|
166
|
+
switch (entityType) {
|
|
167
|
+
case 'IMAGE':
|
|
168
|
+
{
|
|
169
|
+
return (0, _imageBlock.ImageInInfoBox)({
|
|
170
|
+
data: entityData
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function blockRendererFn(block) {
|
|
179
|
+
if (block.getType() === 'atomic') {
|
|
180
|
+
return {
|
|
181
|
+
component: AtomicBlock,
|
|
182
|
+
editable: false
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return null;
|
|
107
187
|
}
|
package/lib/draft-renderer.js
CHANGED
|
@@ -32,11 +32,11 @@ const blockRendererFn = block => {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
function DraftRenderer({
|
|
35
|
-
|
|
35
|
+
rawContentState
|
|
36
36
|
}) {
|
|
37
|
-
const contentState = (0, _draftJs.convertFromRaw)(
|
|
37
|
+
const contentState = (0, _draftJs.convertFromRaw)(rawContentState);
|
|
38
38
|
|
|
39
|
-
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.
|
|
39
|
+
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorator);
|
|
40
40
|
|
|
41
41
|
return /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
42
42
|
editorState: editorState,
|
|
@@ -81,7 +81,7 @@ function AnnotationBlock(props) {
|
|
|
81
81
|
} = props.contentState.getEntity(props.entityKey).getData();
|
|
82
82
|
const contentState = (0, _draftJs.convertFromRaw)(rawContentState);
|
|
83
83
|
|
|
84
|
-
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.
|
|
84
|
+
const editorState = _draftJs.EditorState.createWithContent(contentState, _index.decorator);
|
|
85
85
|
|
|
86
86
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(AnnotationWrapper, {
|
|
87
87
|
onClick: e => {
|
|
@@ -9,7 +9,7 @@ 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 () {
|
|
@@ -23,5 +23,5 @@ var _annotationDecorator = require("./annotation-decorator");
|
|
|
23
23
|
|
|
24
24
|
var _linkDecorator = require("./link-decorator");
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
exports.
|
|
26
|
+
const decorator = new _draftJs.CompositeDecorator([_annotationDecorator.annotationDecorator, _linkDecorator.linkDecorator]);
|
|
27
|
+
exports.decorator = decorator;
|
package/lib/index.js
CHANGED
|
@@ -27,10 +27,10 @@ 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;
|
|
@@ -50,6 +50,6 @@ var _default = {
|
|
|
50
50
|
atomicBlockRenderer: _blockRendererFn.atomicBlockRenderer,
|
|
51
51
|
blockRenderMap: _blockRenderMap.blockRenderMap,
|
|
52
52
|
blockRenderers: _blockRenderers.blockRenderers,
|
|
53
|
-
|
|
53
|
+
decorator: _index.decorator
|
|
54
54
|
};
|
|
55
55
|
exports.default = _default;
|