@mirrormedia/lilith-draft-editor 1.0.0-beta
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/draft-js/block-renderer/background-image-block.tsx +113 -0
- package/lib/draft-js/block-renderer/background-video-block.tsx +120 -0
- package/lib/draft-js/block-renderer/color-box-block.tsx +85 -0
- package/lib/draft-js/block-renderer/divider-block.tsx +12 -0
- package/lib/draft-js/block-renderer/embedded-code-block.tsx +65 -0
- package/lib/draft-js/block-renderer/image-block.tsx +41 -0
- package/lib/draft-js/block-renderer/info-box-block.tsx +85 -0
- package/lib/draft-js/block-renderer/media-block.tsx +36 -0
- package/lib/draft-js/block-renderer/related-post-block.tsx +47 -0
- package/lib/draft-js/block-renderer/side-index-block.tsx +113 -0
- package/lib/draft-js/block-renderer/slideshow-block.tsx +62 -0
- package/lib/draft-js/block-renderer/table-block.tsx +488 -0
- package/lib/draft-js/buttons/annotation.tsx +113 -0
- package/lib/draft-js/buttons/background-color.tsx +125 -0
- package/lib/draft-js/buttons/background-image.tsx +276 -0
- package/lib/draft-js/buttons/background-video.tsx +275 -0
- package/lib/draft-js/buttons/color-box.tsx +207 -0
- package/lib/draft-js/buttons/divider.tsx +56 -0
- package/lib/draft-js/buttons/embedded-code.tsx +126 -0
- package/lib/draft-js/buttons/enlarge.tsx +11 -0
- package/lib/draft-js/buttons/font-color.tsx +113 -0
- package/lib/draft-js/buttons/image.tsx +71 -0
- package/lib/draft-js/buttons/info-box.tsx +170 -0
- package/lib/draft-js/buttons/link.tsx +103 -0
- package/lib/draft-js/buttons/media.tsx +120 -0
- package/lib/draft-js/buttons/related-post.tsx +81 -0
- package/lib/draft-js/buttons/selector/align-selector.tsx +65 -0
- package/lib/draft-js/buttons/selector/image-selector.tsx +485 -0
- package/lib/draft-js/buttons/selector/pagination.tsx +83 -0
- package/lib/draft-js/buttons/selector/post-selector.tsx +367 -0
- package/lib/draft-js/buttons/selector/search-box.tsx +39 -0
- package/lib/draft-js/buttons/selector/video-selector.tsx +312 -0
- package/lib/draft-js/buttons/side-index.tsx +257 -0
- package/lib/draft-js/buttons/slideshow.tsx +81 -0
- package/lib/draft-js/buttons/table.tsx +63 -0
- package/lib/draft-js/buttons/text-align.tsx +88 -0
- package/lib/draft-js/editor/basic-editor.tsx +384 -0
- package/lib/draft-js/editor/block-redender-fn.tsx +77 -0
- package/lib/draft-js/editor/draft-converter/api-data-instance.js +58 -0
- package/lib/draft-js/editor/draft-converter/atomic-block-processor.js +233 -0
- package/lib/draft-js/editor/draft-converter/entities.js +76 -0
- package/lib/draft-js/editor/draft-converter/index.js +201 -0
- package/lib/draft-js/editor/draft-converter/inline-styles-processor.js +238 -0
- package/lib/draft-js/editor/entity-decorator.tsx +7 -0
- package/lib/draft-js/editor/modifier.tsx +71 -0
- package/lib/draft-js/entity-decorator/annotation-decorator.tsx +81 -0
- package/lib/draft-js/entity-decorator/link-decorator.tsx +27 -0
- package/lib/index.js +31 -0
- package/lib/website/mirrormedia/custom/block-renderer/background-image-block.tsx +128 -0
- package/lib/website/mirrormedia/custom/block-renderer/background-video-block.tsx +135 -0
- package/lib/website/mirrormedia/custom/block-renderer/color-box-block.tsx +98 -0
- package/lib/website/mirrormedia/custom/block-renderer/divider-block.tsx +12 -0
- package/lib/website/mirrormedia/custom/block-renderer/embedded-code-block.tsx +65 -0
- package/lib/website/mirrormedia/custom/block-renderer/image-block.tsx +41 -0
- package/lib/website/mirrormedia/custom/block-renderer/info-box-block.tsx +98 -0
- package/lib/website/mirrormedia/custom/block-renderer/media-block.tsx +36 -0
- package/lib/website/mirrormedia/custom/block-renderer/related-post-block.tsx +47 -0
- package/lib/website/mirrormedia/custom/block-renderer/side-index-block.tsx +125 -0
- package/lib/website/mirrormedia/custom/block-renderer/slideshow-block.tsx +62 -0
- package/lib/website/mirrormedia/custom/block-renderer/table-block.tsx +537 -0
- package/lib/website/mirrormedia/custom/entity-decorator/annotation-decorator.tsx +81 -0
- package/lib/website/mirrormedia/custom/entity-decorator/link-decorator.tsx +27 -0
- package/lib/website/mirrormedia/custom/selector/align-selector.tsx +65 -0
- package/lib/website/mirrormedia/custom/selector/image-selector.tsx +485 -0
- package/lib/website/mirrormedia/custom/selector/pagination.tsx +83 -0
- package/lib/website/mirrormedia/custom/selector/post-selector.tsx +367 -0
- package/lib/website/mirrormedia/custom/selector/search-box.tsx +39 -0
- package/lib/website/mirrormedia/custom/selector/video-selector.tsx +310 -0
- package/lib/website/mirrormedia/draft-editor/block-redender-fn.tsx +77 -0
- package/lib/website/mirrormedia/draft-editor/entity-decorator.tsx +7 -0
- package/lib/website/mirrormedia/draft-editor/index.tsx +909 -0
- package/lib/website/mirrormedia/draft-renderer/block-redender-fn.tsx +77 -0
- package/lib/website/mirrormedia/draft-renderer/entity-decorator.tsx +7 -0
- package/lib/website/mirrormedia/draft-renderer/index-deprecated.tsx +43 -0
- package/lib/website/mirrormedia/draft-renderer/index.tsx +150 -0
- package/lib/website/mirrormedia/index.js +19 -0
- package/lib/website/readr/custom/block-renderer/background-image-block.tsx +128 -0
- package/lib/website/readr/custom/block-renderer/background-video-block.tsx +135 -0
- package/lib/website/readr/custom/block-renderer/color-box-block.tsx +98 -0
- package/lib/website/readr/custom/block-renderer/divider-block.tsx +12 -0
- package/lib/website/readr/custom/block-renderer/embedded-code-block.tsx +65 -0
- package/lib/website/readr/custom/block-renderer/image-block.tsx +41 -0
- package/lib/website/readr/custom/block-renderer/info-box-block.tsx +98 -0
- package/lib/website/readr/custom/block-renderer/media-block.tsx +36 -0
- package/lib/website/readr/custom/block-renderer/related-post-block.tsx +47 -0
- package/lib/website/readr/custom/block-renderer/side-index-block.tsx +125 -0
- package/lib/website/readr/custom/block-renderer/slideshow-block.tsx +62 -0
- package/lib/website/readr/custom/block-renderer/table-block.tsx +537 -0
- package/lib/website/readr/custom/entity-decorator/annotation-decorator.tsx +81 -0
- package/lib/website/readr/custom/entity-decorator/link-decorator.tsx +27 -0
- package/lib/website/readr/custom/selector/align-selector.tsx +65 -0
- package/lib/website/readr/custom/selector/image-selector.tsx +485 -0
- package/lib/website/readr/custom/selector/pagination.tsx +83 -0
- package/lib/website/readr/custom/selector/post-selector.tsx +367 -0
- package/lib/website/readr/custom/selector/search-box.tsx +39 -0
- package/lib/website/readr/custom/selector/video-selector.tsx +310 -0
- package/lib/website/readr/draft-editor/block-redender-fn.tsx +77 -0
- package/lib/website/readr/draft-editor/entity-decorator.tsx +7 -0
- package/lib/website/readr/draft-editor/index.tsx +909 -0
- package/lib/website/readr/draft-renderer/block-redender-fn.tsx +77 -0
- package/lib/website/readr/draft-renderer/entity-decorator.tsx +7 -0
- package/lib/website/readr/draft-renderer/index-deprecated.tsx +43 -0
- package/lib/website/readr/draft-renderer/index.tsx +150 -0
- package/lib/website/readr/index.js +19 -0
- package/package.json +39 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
|
|
10
|
+
var _apiDataInstance = _interopRequireDefault(require("./api-data-instance"));
|
|
11
|
+
|
|
12
|
+
var _entities = _interopRequireDefault(require("./entities"));
|
|
13
|
+
|
|
14
|
+
var _server = _interopRequireDefault(require("react-dom/server"));
|
|
15
|
+
|
|
16
|
+
var _draftJs = require("draft-js");
|
|
17
|
+
|
|
18
|
+
var _draftConvert = require("draft-convert");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
23
|
+
// import sizeOf from 'image-size';
|
|
24
|
+
// eslint-disable-line
|
|
25
|
+
// import htmlparser2 from 'htmlparser2'
|
|
26
|
+
// eslint-disable-next-line no-undef
|
|
27
|
+
const htmlparser2 = require('htmlparser2');
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {Object} DraftEditor.TableEntity.TableStyles
|
|
30
|
+
* @property {Record<string, string>[]} rows
|
|
31
|
+
* @property {Record<string, string>[]} columns
|
|
32
|
+
* @property {Record<string, string>[][]} cells
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {RawDraftContentState[][]} DraftEditor.TableEntity.TableData
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const processor = {
|
|
41
|
+
convertBlock(entityMap, block) {
|
|
42
|
+
let alignment = 'center';
|
|
43
|
+
let content;
|
|
44
|
+
let entityRange = block.entityRanges[0];
|
|
45
|
+
let styles = {}; // current block's entity data
|
|
46
|
+
// ex:
|
|
47
|
+
// entity.type = IMAGE, entity.data={id,name,url...}
|
|
48
|
+
|
|
49
|
+
const entity = entityMap[entityRange.key];
|
|
50
|
+
|
|
51
|
+
let type = _lodash.default.get(entity, 'type', ''); // backward compatible. Old entity type might be lower case
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
switch (type && type.toUpperCase()) {
|
|
55
|
+
case _entities.default.INFOBOX.type:
|
|
56
|
+
{
|
|
57
|
+
var _entity$data, _entity$data2;
|
|
58
|
+
|
|
59
|
+
// About INFOBOX atomic block entity data structure,
|
|
60
|
+
// see `../views/editor/info-box.tsx` for more information.
|
|
61
|
+
content = [{
|
|
62
|
+
title: entity === null || entity === void 0 ? void 0 : (_entity$data = entity.data) === null || _entity$data === void 0 ? void 0 : _entity$data.title,
|
|
63
|
+
body: entity === null || entity === void 0 ? void 0 : (_entity$data2 = entity.data) === null || _entity$data2 === void 0 ? void 0 : _entity$data2.body
|
|
64
|
+
}];
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
case _entities.default.COLORBOX.type:
|
|
69
|
+
{
|
|
70
|
+
var _entity$data3, _entity$data4;
|
|
71
|
+
|
|
72
|
+
content = [{
|
|
73
|
+
color: entity === null || entity === void 0 ? void 0 : (_entity$data3 = entity.data) === null || _entity$data3 === void 0 ? void 0 : _entity$data3.color,
|
|
74
|
+
body: entity === null || entity === void 0 ? void 0 : (_entity$data4 = entity.data) === null || _entity$data4 === void 0 ? void 0 : _entity$data4.body
|
|
75
|
+
}];
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
case _entities.default.TABLE.type:
|
|
80
|
+
{
|
|
81
|
+
var _content, _content2;
|
|
82
|
+
|
|
83
|
+
// About TABLE atomic block entity data structure,
|
|
84
|
+
// see `../views/editor/table.tsx` for more information.
|
|
85
|
+
content = entity === null || entity === void 0 ? void 0 : entity.data;
|
|
86
|
+
/** @type DraftEditor.TableEntity.TableStyles */
|
|
87
|
+
|
|
88
|
+
const tableStyles = (_content = content) === null || _content === void 0 ? void 0 : _content.tableStyles;
|
|
89
|
+
/** @type DraftEditor.TableEntity.TableData */
|
|
90
|
+
|
|
91
|
+
const tableData = (_content2 = content) === null || _content2 === void 0 ? void 0 : _content2.tableData;
|
|
92
|
+
const rowsJsx = tableData === null || tableData === void 0 ? void 0 : tableData.map((row, rIndex) => {
|
|
93
|
+
var _tableStyles$rows;
|
|
94
|
+
|
|
95
|
+
const colsJsx = row === null || row === void 0 ? void 0 : row.map((col, cIndex) => {
|
|
96
|
+
var _tableStyles$columns, _tableStyles$cells, _tableStyles$cells$rI;
|
|
97
|
+
|
|
98
|
+
const colStyle = tableStyles === null || tableStyles === void 0 ? void 0 : (_tableStyles$columns = tableStyles.columns) === null || _tableStyles$columns === void 0 ? void 0 : _tableStyles$columns[cIndex];
|
|
99
|
+
const cellStyle = tableStyles === null || tableStyles === void 0 ? void 0 : (_tableStyles$cells = tableStyles.cells) === null || _tableStyles$cells === void 0 ? void 0 : (_tableStyles$cells$rI = _tableStyles$cells[rIndex]) === null || _tableStyles$cells$rI === void 0 ? void 0 : _tableStyles$cells$rI[cIndex];
|
|
100
|
+
return /*#__PURE__*/React.createElement("td", {
|
|
101
|
+
key: `col_${cIndex}`,
|
|
102
|
+
style: Object.assign({}, colStyle, cellStyle),
|
|
103
|
+
dangerouslySetInnerHTML: {
|
|
104
|
+
__html: (0, _draftConvert.convertToHTML)((0, _draftJs.convertFromRaw)(col))
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
109
|
+
key: `row_${rIndex}`,
|
|
110
|
+
style: tableStyles === null || tableStyles === void 0 ? void 0 : (_tableStyles$rows = tableStyles.rows) === null || _tableStyles$rows === void 0 ? void 0 : _tableStyles$rows[rIndex]
|
|
111
|
+
}, colsJsx);
|
|
112
|
+
}); // Use `React.renderToStsaticMarkup` to generate plain HTML string
|
|
113
|
+
|
|
114
|
+
const html = _server.default.renderToStaticMarkup( /*#__PURE__*/React.createElement("table", null, /*#__PURE__*/React.createElement("tbody", null, rowsJsx)));
|
|
115
|
+
|
|
116
|
+
content = [{
|
|
117
|
+
html
|
|
118
|
+
}];
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
case _entities.default.DIVIDER.type:
|
|
123
|
+
content = ['<hr>'];
|
|
124
|
+
break;
|
|
125
|
+
|
|
126
|
+
case _entities.default.BLOCKQUOTE.type:
|
|
127
|
+
// this is different from default blockquote of draftjs
|
|
128
|
+
// so we name our specific blockquote as 'quoteby'
|
|
129
|
+
type = 'quoteby';
|
|
130
|
+
alignment = entity.data && entity.data.alignment || alignment;
|
|
131
|
+
content = _lodash.default.get(entity, 'data');
|
|
132
|
+
content = Array.isArray(content) ? content : [content];
|
|
133
|
+
break;
|
|
134
|
+
|
|
135
|
+
case _entities.default.AUDIO.type:
|
|
136
|
+
case _entities.default.IMAGE.type:
|
|
137
|
+
case _entities.default.IMAGEDIFF.type:
|
|
138
|
+
case _entities.default.SLIDESHOW.type:
|
|
139
|
+
case _entities.default['SLIDESHOW-V2'].type:
|
|
140
|
+
case _entities.default.VIDEO.type:
|
|
141
|
+
case _entities.default.YOUTUBE.type:
|
|
142
|
+
case _entities.default.BACKGROUNDIMAGE.type:
|
|
143
|
+
case _entities.default.BACKGROUNDVIDEO.type:
|
|
144
|
+
case _entities.default.RELATEDPOST.type:
|
|
145
|
+
case _entities.default.SIDEINDEX.type:
|
|
146
|
+
alignment = entity.data && entity.data.alignment || alignment;
|
|
147
|
+
content = _lodash.default.get(entity, 'data');
|
|
148
|
+
content = Array.isArray(content) ? content : [content];
|
|
149
|
+
break;
|
|
150
|
+
|
|
151
|
+
case _entities.default.IMAGELINK.type:
|
|
152
|
+
{
|
|
153
|
+
// use Embedded component to dangerouslySetInnerHTML
|
|
154
|
+
type = _entities.default.EMBEDDEDCODE.type;
|
|
155
|
+
alignment = entity.data && entity.data.alignment || alignment;
|
|
156
|
+
|
|
157
|
+
let description = _lodash.default.get(entity, ['data', 'description'], '');
|
|
158
|
+
|
|
159
|
+
let url = _lodash.default.get(entity, ['data', 'url'], '');
|
|
160
|
+
|
|
161
|
+
content = [{
|
|
162
|
+
caption: description,
|
|
163
|
+
embeddedCodeWithoutScript: `<img alt="${description}" src="${url}" class="img-responsive"/>`,
|
|
164
|
+
url: url
|
|
165
|
+
}];
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
case _entities.default.EMBEDDEDCODE.type:
|
|
170
|
+
{
|
|
171
|
+
alignment = entity.data && entity.data.alignment || alignment;
|
|
172
|
+
|
|
173
|
+
let caption = _lodash.default.get(entity, ['data', 'caption'], '');
|
|
174
|
+
|
|
175
|
+
let embeddedCode = _lodash.default.get(entity, ['data', 'embeddedCode'], '');
|
|
176
|
+
|
|
177
|
+
let script = {};
|
|
178
|
+
let scripts = [];
|
|
179
|
+
let scriptTagStart = false;
|
|
180
|
+
let height;
|
|
181
|
+
let width;
|
|
182
|
+
let parser = new htmlparser2.Parser({
|
|
183
|
+
onopentag: (name, attribs) => {
|
|
184
|
+
if (name === 'script') {
|
|
185
|
+
scriptTagStart = true;
|
|
186
|
+
script.attribs = attribs;
|
|
187
|
+
} else if (name === 'iframe') {
|
|
188
|
+
height = _lodash.default.get(attribs, 'height', 0);
|
|
189
|
+
width = _lodash.default.get(attribs, 'width', 0);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
ontext: text => {
|
|
193
|
+
if (scriptTagStart) {
|
|
194
|
+
script.text = text;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
onclosetag: tagname => {
|
|
198
|
+
if (tagname === 'script' && scriptTagStart) {
|
|
199
|
+
scriptTagStart = false;
|
|
200
|
+
scripts.push(script);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
parser.write(embeddedCode);
|
|
205
|
+
parser.end();
|
|
206
|
+
content = [{
|
|
207
|
+
caption,
|
|
208
|
+
embeddedCode,
|
|
209
|
+
embeddedCodeWithoutScript: embeddedCode.replace(/<script(.+?)\/script>/g, ''),
|
|
210
|
+
height,
|
|
211
|
+
scripts,
|
|
212
|
+
width
|
|
213
|
+
}];
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
default:
|
|
218
|
+
return;
|
|
219
|
+
} // block type of api data should be lower case
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
return new _apiDataInstance.default({
|
|
223
|
+
id: block.key,
|
|
224
|
+
alignment,
|
|
225
|
+
type: type && type.toLowerCase(),
|
|
226
|
+
content,
|
|
227
|
+
styles
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
};
|
|
232
|
+
var _default = processor;
|
|
233
|
+
exports.default = _default;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
// 'use strict';
|
|
8
|
+
const ENTITY = {
|
|
9
|
+
DIVIDER: {
|
|
10
|
+
type: 'DIVIDER'
|
|
11
|
+
},
|
|
12
|
+
ANNOTATION: {
|
|
13
|
+
type: 'ANNOTATION'
|
|
14
|
+
},
|
|
15
|
+
BLOCKQUOTE: {
|
|
16
|
+
type: 'BLOCKQUOTE'
|
|
17
|
+
},
|
|
18
|
+
LINK: {
|
|
19
|
+
type: 'LINK'
|
|
20
|
+
},
|
|
21
|
+
INFOBOX: {
|
|
22
|
+
type: 'INFOBOX'
|
|
23
|
+
},
|
|
24
|
+
COLORBOX: {
|
|
25
|
+
type: 'COLORBOX'
|
|
26
|
+
},
|
|
27
|
+
EMBEDDEDCODE: {
|
|
28
|
+
type: 'EMBEDDEDCODE'
|
|
29
|
+
},
|
|
30
|
+
AUDIO: {
|
|
31
|
+
type: 'AUDIO'
|
|
32
|
+
},
|
|
33
|
+
VIDEO: {
|
|
34
|
+
type: 'VIDEO'
|
|
35
|
+
},
|
|
36
|
+
IMAGE: {
|
|
37
|
+
type: 'IMAGE'
|
|
38
|
+
},
|
|
39
|
+
STOREDIMAGE: {
|
|
40
|
+
type: 'STOREDIMAGE'
|
|
41
|
+
},
|
|
42
|
+
IMAGEDIFF: {
|
|
43
|
+
type: 'IMAGEDIFF'
|
|
44
|
+
},
|
|
45
|
+
IMAGELINK: {
|
|
46
|
+
type: 'IMAGELINK'
|
|
47
|
+
},
|
|
48
|
+
SLIDESHOW: {
|
|
49
|
+
type: 'SLIDESHOW',
|
|
50
|
+
slideshowSelectionLimit: 30
|
|
51
|
+
},
|
|
52
|
+
['SLIDESHOW-V2']: {
|
|
53
|
+
type: 'SLIDESHOW-V2',
|
|
54
|
+
slideshowSelectionLimit: 30
|
|
55
|
+
},
|
|
56
|
+
YOUTUBE: {
|
|
57
|
+
type: 'YOUTUBE'
|
|
58
|
+
},
|
|
59
|
+
TABLE: {
|
|
60
|
+
type: 'TABLE'
|
|
61
|
+
},
|
|
62
|
+
BACKGROUNDIMAGE: {
|
|
63
|
+
type: 'BACKGROUNDIMAGE'
|
|
64
|
+
},
|
|
65
|
+
BACKGROUNDVIDEO: {
|
|
66
|
+
type: 'BACKGROUNDVIDEO'
|
|
67
|
+
},
|
|
68
|
+
RELATEDPOST: {
|
|
69
|
+
type: 'RELATEDPOST'
|
|
70
|
+
},
|
|
71
|
+
SIDEINDEX: {
|
|
72
|
+
type: 'SIDEINDEX'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var _default = ENTITY;
|
|
76
|
+
exports.default = _default;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _immutable = require("immutable");
|
|
9
|
+
|
|
10
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
+
|
|
12
|
+
var InlineStylesProcessor = _interopRequireWildcard(require("./inline-styles-processor"));
|
|
13
|
+
|
|
14
|
+
var _apiDataInstance = _interopRequireDefault(require("./api-data-instance"));
|
|
15
|
+
|
|
16
|
+
var _atomicBlockProcessor = _interopRequireDefault(require("./atomic-block-processor"));
|
|
17
|
+
|
|
18
|
+
var _entities = _interopRequireDefault(require("./entities"));
|
|
19
|
+
|
|
20
|
+
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
|
+
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
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
+
|
|
26
|
+
// Modified from https://github.com/dburrows/draft-js-basic-html-editor/blob/master/src/utils/draftRawToHtml.js
|
|
27
|
+
// 'use strict';
|
|
28
|
+
let defaultBlockTagMap = {
|
|
29
|
+
atomic: `<div>%content%</div>`,
|
|
30
|
+
blockquote: `<blockquote>%content%</blockquote>`,
|
|
31
|
+
'code-block': `<code>%content%</code>`,
|
|
32
|
+
default: `<p>%content%</p>`,
|
|
33
|
+
'header-two': `<h2>%content%</h2>`,
|
|
34
|
+
'header-three': `<h3>%content%</h3>`,
|
|
35
|
+
'header-four': `<h4>%content%</h4>`,
|
|
36
|
+
'ordered-list-item': `<li>%content%</li>`,
|
|
37
|
+
paragraph: `<p>%content%</p>`,
|
|
38
|
+
'unordered-list-item': `<li>%content%</li>`,
|
|
39
|
+
unstyled: `<p>%content%</p>`
|
|
40
|
+
};
|
|
41
|
+
let inlineTagMap = {
|
|
42
|
+
BOLD: ['<strong>', '</strong>'],
|
|
43
|
+
CODE: ['<code>', '</code>'],
|
|
44
|
+
default: ['<span>', '</span>'],
|
|
45
|
+
ITALIC: ['<em>', '</em>'],
|
|
46
|
+
UNDERLINE: ['<u>', '</u>']
|
|
47
|
+
};
|
|
48
|
+
let defaultEntityTagMap = {
|
|
49
|
+
[_entities.default.DIVIDER.type]: ['<hr>', ''],
|
|
50
|
+
[_entities.default.ANNOTATION.type]: ['<abbr title="<%= data.body %>"><%= data.text %>', '</abbr>'],
|
|
51
|
+
[_entities.default.AUDIO.type]: ['<div class="audio-container center"><div class="audio-title"><%= data.name %></div><!-- <div class="audio-desc"><%= data.description %></div> --><audio src="<%= data.url %>" />', '</div>'],
|
|
52
|
+
[_entities.default.BLOCKQUOTE.type]: ['<blockquote class="center"><div><%= data.quote %></div><div><%= data.quotedBy %></div>', '<blockquote>'],
|
|
53
|
+
[_entities.default.EMBEDDEDCODE.type]: ['<div class="embedded <%= data.alignment %>" title="<%= data.caption %>"><%= data.code%>', '</div>'],
|
|
54
|
+
[_entities.default.INFOBOX.type]: ['<div class="info-box-container center"><div class="info-box-title"><%= data.title %></div><div class="info-box-body"><%= data.body %></div>', '</div>'],
|
|
55
|
+
[_entities.default.STOREDIMAGE.type]: ['<img alt="<%= data.name %>" src="<%= data.url %>" srcset="<%= data.urlMobileSized %> 800w, <%= data.urlTabletSized %> 1280w, <%= data.urlDesktopSized %> 2400w" class="center">', '</img>'],
|
|
56
|
+
[_entities.default.IMAGE.type]: ['<img alt="<%=data.name%>" src="<%=data.url%>" srcset="<%= data.mobile.url %> 800w, <%= data.tablet.url %> 1280w, <%= data.desktop.url %> 2400w" class="center">', '</img>'],
|
|
57
|
+
|
|
58
|
+
/*[ENTITY.IMAGEDIFF.type]: ['<!-- imageDiff component start --> <ol class="image-diff-container"> <% _.forEach(data, function(image, index) { if (index > 1) { return; } %><li class="image-diff-item"><img src="<%- image.url %>" /></li><% }); %>', '</ol><!-- imageDiff component end-->'],
|
|
59
|
+
[ENTITY.IMAGELINK.type]: ['<img alt="<%= data.description %>" src="<%= data.url %>" class="<%= data.alignment %>">', '</img>'],*/
|
|
60
|
+
[_entities.default.LINK.type]: ['<a target="_blank" href="<%= data.url %>">', '</a>'],
|
|
61
|
+
[_entities.default.SLIDESHOW.type]: ['<!-- slideshow component start --> <ol class="slideshow-container"> <% _.forEach(data, function(image) { %><li class="slideshow-slide"><img alt="<%- image.name %>" src="<%- image.url %>" srcset="<%= image.mobile.url %> 800w, <%= image.tablet.url %> 1280w, <%= image.desktop.url %> 2400w" /></li><% }); %>', '</ol><!-- slideshow component end -->'],
|
|
62
|
+
[_entities.default.VIDEO.type]: ['<div controls class="video-container <%= data.alignment %>"><div class="video-name"><%= data.title %></div><div class="video-desc"><%= data.description %></div><video src="<%= data.url %>" />', '</div>'],
|
|
63
|
+
[_entities.default.YOUTUBE.type]: ['<iframe width="560" alt="<%= data.description %>" height="315" src="https://www.youtube.com/embed/<%= data.id %>" frameborder="0" allowfullscreen>', '</iframe>']
|
|
64
|
+
};
|
|
65
|
+
let nestedTagMap = {
|
|
66
|
+
'ordered-list-item': ['<ol>', '</ol>'],
|
|
67
|
+
'unordered-list-item': ['<ul>', '</ul>']
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function _convertInlineStyle(block, entityMap, blockTagMap, entityTagMap) {
|
|
71
|
+
return blockTagMap[block.type] ? blockTagMap[block.type].replace('%content%', InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block)) : blockTagMap.default.replace('%content%', InlineStylesProcessor.convertToHtml(inlineTagMap, block));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _convertBlocksToHtml(blocks, entityMap, blockTagMap, entityTagMap) {
|
|
75
|
+
let html = '';
|
|
76
|
+
let nestLevel = []; // store the list type of the previous item: null/ol/ul
|
|
77
|
+
|
|
78
|
+
blocks.forEach(block => {
|
|
79
|
+
// create tag for <ol> or <ul>: deal with ordered/unordered list item
|
|
80
|
+
// if the block is a list-item && the previous block is not a list-item
|
|
81
|
+
if (nestedTagMap[block.type] && nestLevel[0] !== block.type) {
|
|
82
|
+
html += nestedTagMap[block.type][0]; // start with <ol> or <ul>
|
|
83
|
+
|
|
84
|
+
nestLevel.unshift(block.type);
|
|
85
|
+
} // end tag with </ol> or </ul>: deal with ordered/unordered list item
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if (nestLevel.length > 0 && nestLevel[0] !== block.type) {
|
|
89
|
+
html += nestedTagMap[nestLevel.shift()][1]; // close with </ol> or </ul>
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
html += _convertInlineStyle(block, entityMap, blockTagMap, entityTagMap);
|
|
93
|
+
}); // end tag with </ol> or </ul>: or if it is the last block
|
|
94
|
+
|
|
95
|
+
if (blocks.length > 0 && nestedTagMap[blocks[blocks.length - 1].type]) {
|
|
96
|
+
html += nestedTagMap[nestLevel.shift()][1]; // close with </ol> or </ul>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return html;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
103
|
+
let apiDataArr = (0, _immutable.List)();
|
|
104
|
+
let content = [];
|
|
105
|
+
let nestLevel = [];
|
|
106
|
+
blocks.forEach(block => {
|
|
107
|
+
// block is not a list-item
|
|
108
|
+
if (!nestedTagMap[block.type]) {
|
|
109
|
+
// if previous block is a list-item
|
|
110
|
+
if (content.length > 0 && nestLevel.length > 0) {
|
|
111
|
+
apiDataArr = apiDataArr.push(new _apiDataInstance.default({
|
|
112
|
+
type: nestLevel[0],
|
|
113
|
+
content: [content]
|
|
114
|
+
}));
|
|
115
|
+
content = [];
|
|
116
|
+
nestLevel.shift();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (block.type.startsWith('atomic') || block.type.startsWith('media')) {
|
|
120
|
+
try {
|
|
121
|
+
apiDataArr = apiDataArr.push(_atomicBlockProcessor.default.convertBlock(entityMap, block));
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.error(e);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
var _block$data;
|
|
127
|
+
|
|
128
|
+
let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block);
|
|
129
|
+
const type = block.type;
|
|
130
|
+
const textAlign = (_block$data = block.data) === null || _block$data === void 0 ? void 0 : _block$data.textAlign;
|
|
131
|
+
apiDataArr = apiDataArr.push(new _apiDataInstance.default({
|
|
132
|
+
id: block.key,
|
|
133
|
+
type,
|
|
134
|
+
content: [converted],
|
|
135
|
+
textAlign
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block); // previous block is not an item-list block
|
|
140
|
+
|
|
141
|
+
if (nestLevel.length === 0) {
|
|
142
|
+
nestLevel.unshift(block.type);
|
|
143
|
+
content.push(converted);
|
|
144
|
+
} else if (nestLevel[0] === block.type) {
|
|
145
|
+
// previous block is a item-list and current block is the same item-list
|
|
146
|
+
content.push(converted);
|
|
147
|
+
} else if (nestLevel[0] !== block.type) {
|
|
148
|
+
// previous block is a different item-list.
|
|
149
|
+
apiDataArr = apiDataArr.push(new _apiDataInstance.default({
|
|
150
|
+
id: block.key,
|
|
151
|
+
type: nestLevel[0],
|
|
152
|
+
content: [content]
|
|
153
|
+
}));
|
|
154
|
+
content = [converted];
|
|
155
|
+
nestLevel[0] = block.type;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}); // last block is a item-list
|
|
159
|
+
|
|
160
|
+
if (blocks.length > 0 && nestLevel.length > 0) {
|
|
161
|
+
let block = blocks[blocks.length - 1];
|
|
162
|
+
apiDataArr = apiDataArr.push(new _apiDataInstance.default({
|
|
163
|
+
id: block.key,
|
|
164
|
+
type: block.type,
|
|
165
|
+
content: content
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return apiDataArr;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function convertRawToHtml(raw, blockTagMap, entityTagMap) {
|
|
173
|
+
blockTagMap = _lodash.default.merge({}, defaultBlockTagMap, blockTagMap);
|
|
174
|
+
entityTagMap = entityTagMap || defaultEntityTagMap;
|
|
175
|
+
let html = '';
|
|
176
|
+
raw = raw || {};
|
|
177
|
+
const blocks = Array.isArray(raw.blocks) ? raw.blocks : [];
|
|
178
|
+
const entityMap = typeof raw.entityMap === 'object' ? raw.entityMap : {};
|
|
179
|
+
html = _convertBlocksToHtml(blocks, entityMap, blockTagMap, entityTagMap);
|
|
180
|
+
return html;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function convertRawToApiData(raw) {
|
|
184
|
+
let apiData;
|
|
185
|
+
raw = raw || {};
|
|
186
|
+
const blocks = Array.isArray(raw.blocks) ? raw.blocks : [];
|
|
187
|
+
const entityMap = typeof raw.entityMap === 'object' ? raw.entityMap : {};
|
|
188
|
+
|
|
189
|
+
let entityTagMap = _lodash.default.merge({}, defaultEntityTagMap, {
|
|
190
|
+
[_entities.default.ANNOTATION.type]: [`<span data-entity-type="annotation" data-annotation-body="<%= data.bodyEscapedHTML %>">`, '</span>']
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
apiData = convertBlocksToApiData(blocks, entityMap, entityTagMap);
|
|
194
|
+
return apiData;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
var _default = {
|
|
198
|
+
convertToHtml: convertRawToHtml,
|
|
199
|
+
convertToApiData: convertRawToApiData
|
|
200
|
+
};
|
|
201
|
+
exports.default = _default;
|