@mirrormedia/lilith-draft-editor 1.1.0-alpha.1 → 1.1.0-alpha.3
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/buttons/annotation.js +0 -22
- package/lib/draft-js/buttons/audio.js +52 -0
- package/lib/draft-js/buttons/background-color.js +0 -26
- package/lib/draft-js/buttons/background-image.js +13 -32
- package/lib/draft-js/buttons/background-video.js +13 -32
- package/lib/draft-js/buttons/color-box.js +5 -21
- package/lib/draft-js/buttons/divider.js +3 -12
- package/lib/draft-js/buttons/embedded-code.js +5 -16
- package/lib/draft-js/buttons/enlarge.js +0 -3
- package/lib/draft-js/buttons/font-color.js +0 -26
- package/lib/draft-js/buttons/image.js +5 -16
- package/lib/draft-js/buttons/info-box.js +5 -21
- package/lib/draft-js/buttons/link.js +0 -19
- package/lib/draft-js/buttons/media.js +3 -16
- package/lib/draft-js/buttons/related-post.js +3 -14
- package/lib/draft-js/buttons/selector/align-selector.js +2 -11
- package/lib/draft-js/buttons/selector/audio-selector.js +252 -0
- package/lib/draft-js/buttons/selector/image-selector.js +6 -50
- package/lib/draft-js/buttons/selector/pagination.js +2 -6
- package/lib/draft-js/buttons/selector/post-selector.js +6 -39
- package/lib/draft-js/buttons/selector/search-box.js +0 -9
- package/lib/draft-js/buttons/selector/video-selector.js +4 -33
- package/lib/draft-js/buttons/side-index.js +15 -31
- package/lib/draft-js/buttons/slideshow.js +7 -16
- package/lib/draft-js/buttons/table.js +5 -11
- package/lib/draft-js/buttons/text-align.js +0 -14
- package/lib/draft-js/buttons/video.js +52 -0
- package/lib/draft-js/const.js +0 -2
- package/lib/draft-js/draft-converter/api-data-instance.js +0 -14
- package/lib/draft-js/draft-converter/atomic-block-processor.js +12 -41
- package/lib/draft-js/draft-converter/entities.js +1 -0
- package/lib/draft-js/draft-converter/index.js +10 -29
- package/lib/draft-js/draft-converter/inline-styles-processor.js +22 -55
- package/lib/draft-js/modifier.js +5 -13
- package/lib/index.js +0 -4
- package/lib/website/mirrormedia/block-renderer/background-image-block.js +2 -14
- package/lib/website/mirrormedia/block-renderer/background-video-block.js +2 -14
- package/lib/website/mirrormedia/block-renderer/color-box-block.js +2 -14
- package/lib/website/mirrormedia/block-renderer/embedded-code-block.js +3 -12
- package/lib/website/mirrormedia/block-renderer/info-box-block.js +2 -14
- package/lib/website/mirrormedia/block-renderer/side-index-block.js +2 -13
- package/lib/website/mirrormedia/block-renderer/slideshow-block.js +4 -11
- package/lib/website/mirrormedia/block-renderer/table-block.js +28 -62
- package/lib/website/mirrormedia/block-renderer-fn.js +11 -29
- package/lib/website/mirrormedia/draft-editor.js +31 -105
- package/lib/website/mirrormedia/entity-decorator.js +0 -4
- package/lib/website/mirrormedia/index.js +0 -3
- package/lib/website/mirrormedia/selector/align-selector.js +2 -11
- package/lib/website/mirrormedia/selector/audio-selector.js +252 -0
- package/lib/website/mirrormedia/selector/image-selector.js +10 -50
- package/lib/website/mirrormedia/selector/pagination.js +2 -6
- package/lib/website/mirrormedia/selector/post-selector.js +6 -39
- package/lib/website/mirrormedia/selector/search-box.js +0 -9
- package/lib/website/mirrormedia/selector/video-selector.js +8 -33
- package/lib/website/readr/block-renderer/background-image-block.js +2 -14
- package/lib/website/readr/block-renderer/background-video-block.js +2 -14
- package/lib/website/readr/block-renderer/color-box-block.js +2 -14
- package/lib/website/readr/block-renderer/info-box-block.js +2 -14
- package/lib/website/readr/block-renderer/side-index-block.js +2 -13
- package/lib/website/readr/block-renderer/table-block.js +28 -62
- package/lib/website/readr/block-renderer-fn.js +11 -27
- package/lib/website/readr/draft-editor.js +31 -105
- package/lib/website/readr/entity-decorator.js +0 -4
- package/lib/website/readr/index.js +0 -3
- package/lib/website/readr/selector/align-selector.js +2 -11
- package/lib/website/readr/selector/audio-selector.js +252 -0
- package/lib/website/readr/selector/image-selector.js +10 -50
- package/lib/website/readr/selector/pagination.js +2 -6
- package/lib/website/readr/selector/post-selector.js +6 -39
- package/lib/website/readr/selector/search-box.js +0 -9
- package/lib/website/readr/selector/video-selector.js +8 -33
- package/package.json +2 -2
|
@@ -6,45 +6,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.AlignCenterButton = AlignCenterButton;
|
|
7
7
|
exports.AlignLeftButton = AlignLeftButton;
|
|
8
8
|
exports.getSelectionBlockData = void 0;
|
|
9
|
-
|
|
10
9
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
10
|
var _draftJs = require("draft-js");
|
|
13
|
-
|
|
14
11
|
var _modifier = require("../modifier");
|
|
15
|
-
|
|
16
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
13
|
const toggleSelectionTextAlign = (editorState, textAlign) => {
|
|
19
14
|
return setSelectionBlockData(editorState, {
|
|
20
15
|
textAlign: getSelectionBlockData(editorState, 'textAlign') !== textAlign ? textAlign : undefined
|
|
21
16
|
});
|
|
22
17
|
};
|
|
23
|
-
|
|
24
18
|
const setSelectionBlockData = (editorState, blockData) => {
|
|
25
19
|
return _modifier.Modifier.setBlockData(editorState.getCurrentContent(), editorState.getSelection(), blockData);
|
|
26
20
|
};
|
|
27
|
-
|
|
28
21
|
const getSelectionBlockData = (editorState, name) => {
|
|
29
22
|
const block = editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
|
|
30
23
|
const blockData = block.getData();
|
|
31
24
|
return blockData.get(name);
|
|
32
25
|
};
|
|
33
|
-
|
|
34
26
|
exports.getSelectionBlockData = getSelectionBlockData;
|
|
35
|
-
|
|
36
27
|
function AlignCenterButton(props) {
|
|
37
28
|
const {
|
|
38
29
|
isActive,
|
|
39
30
|
editorState,
|
|
40
31
|
onChange
|
|
41
32
|
} = props;
|
|
42
|
-
|
|
43
33
|
const toggleTextAlign = () => {
|
|
44
34
|
const newContentState = toggleSelectionTextAlign(editorState, 'center');
|
|
45
35
|
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-block-style'));
|
|
46
36
|
};
|
|
47
|
-
|
|
48
37
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
49
38
|
className: props.className,
|
|
50
39
|
onMouseDown: toggleTextAlign
|
|
@@ -59,19 +48,16 @@ function AlignCenterButton(props) {
|
|
|
59
48
|
fill: isActive ? '#ED8B00' : '#6b7280'
|
|
60
49
|
}))));
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
function AlignLeftButton(props) {
|
|
64
52
|
const {
|
|
65
53
|
isActive,
|
|
66
54
|
editorState,
|
|
67
55
|
onChange
|
|
68
56
|
} = props;
|
|
69
|
-
|
|
70
57
|
const toggleTextAlign = () => {
|
|
71
58
|
const newContentState = toggleSelectionTextAlign(editorState, 'left');
|
|
72
59
|
onChange(_draftJs.EditorState.push(editorState, newContentState, 'change-block-style'));
|
|
73
60
|
};
|
|
74
|
-
|
|
75
61
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
76
62
|
className: props.className,
|
|
77
63
|
onMouseDown: toggleTextAlign
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VideoButton = VideoButton;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
var _videoSelector = require("./selector/video-selector");
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
function VideoButton(props) {
|
|
13
|
+
const {
|
|
14
|
+
editorState,
|
|
15
|
+
onChange,
|
|
16
|
+
className,
|
|
17
|
+
VideoSelector = _videoSelector.VideoSelector
|
|
18
|
+
} = props;
|
|
19
|
+
const [toShowVideoSelector, setToShowVideoSelector] = (0, _react.useState)(false);
|
|
20
|
+
const promptForVideoSelector = () => {
|
|
21
|
+
setToShowVideoSelector(true);
|
|
22
|
+
};
|
|
23
|
+
const onVideoSelectorChange = selectedVideosWithMeta => {
|
|
24
|
+
var _selectedVideosWithMe;
|
|
25
|
+
const video = selectedVideosWithMeta === null || selectedVideosWithMeta === void 0 ? void 0 : (_selectedVideosWithMe = selectedVideosWithMeta[0]) === null || _selectedVideosWithMe === void 0 ? void 0 : _selectedVideosWithMe.video;
|
|
26
|
+
if (!video) {
|
|
27
|
+
setToShowVideoSelector(false);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const contentState = editorState.getCurrentContent();
|
|
31
|
+
const contentStateWithEntity = contentState.createEntity('VIDEO', 'IMMUTABLE', {
|
|
32
|
+
video
|
|
33
|
+
});
|
|
34
|
+
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
35
|
+
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
36
|
+
currentContent: contentStateWithEntity
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// The third parameter here is a space string, not an empty string
|
|
40
|
+
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
41
|
+
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
42
|
+
setToShowVideoSelector(false);
|
|
43
|
+
};
|
|
44
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowVideoSelector && /*#__PURE__*/_react.default.createElement(VideoSelector, {
|
|
45
|
+
onChange: onVideoSelectorChange
|
|
46
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
47
|
+
className: className,
|
|
48
|
+
onClick: promptForVideoSelector
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
50
|
+
className: "fa fa-video-camera"
|
|
51
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, " Video")));
|
|
52
|
+
}
|
package/lib/draft-js/const.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _const = require("@mirrormedia/lilith-draft-renderer/lib/draft-js/const");
|
|
8
|
-
|
|
9
7
|
Object.keys(_const).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _const[key]) return;
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _immutable = require("immutable");
|
|
9
|
-
|
|
10
8
|
var _shortid = _interopRequireDefault(require("shortid"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const ApiDataInstanceRecord = (0, _immutable.Record)({
|
|
15
11
|
id: _shortid.default.generate(),
|
|
16
12
|
type: 'paragraph',
|
|
@@ -19,40 +15,30 @@ const ApiDataInstanceRecord = (0, _immutable.Record)({
|
|
|
19
15
|
styles: {},
|
|
20
16
|
textAlign: undefined
|
|
21
17
|
});
|
|
22
|
-
|
|
23
18
|
class ApiDataInstance extends ApiDataInstanceRecord {
|
|
24
19
|
constructor(props) {
|
|
25
20
|
let id = props && props.id || _shortid.default.generate();
|
|
26
|
-
|
|
27
21
|
props.id = id;
|
|
28
22
|
super(props);
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
getId() {
|
|
32
25
|
return this.get('id');
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
getType() {
|
|
36
28
|
return this.get('type');
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
getAlignment() {
|
|
40
31
|
return this.get('alignment');
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
getContent() {
|
|
44
34
|
return this.get('content');
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
getStyles() {
|
|
48
37
|
return this.get('styles');
|
|
49
38
|
}
|
|
50
|
-
|
|
51
39
|
getTextAlign() {
|
|
52
40
|
return this.get('textAlign');
|
|
53
41
|
}
|
|
54
|
-
|
|
55
42
|
}
|
|
56
|
-
|
|
57
43
|
var _default = ApiDataInstance;
|
|
58
44
|
exports.default = _default;
|
|
@@ -4,27 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
-
|
|
10
8
|
var _apiDataInstance = _interopRequireDefault(require("./api-data-instance"));
|
|
11
|
-
|
|
12
9
|
var _entities = _interopRequireDefault(require("./entities"));
|
|
13
|
-
|
|
14
10
|
var _server = _interopRequireDefault(require("react-dom/server"));
|
|
15
|
-
|
|
16
11
|
var _draftJs = require("draft-js");
|
|
17
|
-
|
|
18
12
|
var _draftConvert = require("draft-convert");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
15
|
+
|
|
23
16
|
// import sizeOf from 'image-size';
|
|
17
|
+
|
|
24
18
|
// eslint-disable-line
|
|
19
|
+
|
|
25
20
|
// import htmlparser2 from 'htmlparser2'
|
|
26
21
|
// eslint-disable-next-line no-undef
|
|
27
22
|
const htmlparser2 = require('htmlparser2');
|
|
23
|
+
|
|
28
24
|
/**
|
|
29
25
|
* @typedef {Object} DraftEditor.TableEntity.TableStyles
|
|
30
26
|
* @property {Record<string, string>[]} rows
|
|
@@ -36,26 +32,23 @@ const htmlparser2 = require('htmlparser2');
|
|
|
36
32
|
* @typedef {RawDraftContentState[][]} DraftEditor.TableEntity.TableData
|
|
37
33
|
*/
|
|
38
34
|
|
|
39
|
-
|
|
40
35
|
const processor = {
|
|
41
36
|
convertBlock(entityMap, block) {
|
|
42
37
|
let alignment = 'center';
|
|
43
38
|
let content;
|
|
44
39
|
let entityRange = block.entityRanges[0];
|
|
45
|
-
let styles = {};
|
|
40
|
+
let styles = {};
|
|
41
|
+
// current block's entity data
|
|
46
42
|
// ex:
|
|
47
43
|
// entity.type = IMAGE, entity.data={id,name,url...}
|
|
48
|
-
|
|
49
44
|
const entity = entityMap[entityRange.key];
|
|
45
|
+
let type = _lodash.default.get(entity, 'type', '');
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
// backward compatible. Old entity type might be lower case
|
|
54
48
|
switch (type && type.toUpperCase()) {
|
|
55
49
|
case _entities.default.INFOBOX.type:
|
|
56
50
|
{
|
|
57
51
|
var _entity$data, _entity$data2;
|
|
58
|
-
|
|
59
52
|
// About INFOBOX atomic block entity data structure,
|
|
60
53
|
// see `../views/editor/info-box.tsx` for more information.
|
|
61
54
|
content = [{
|
|
@@ -64,37 +57,29 @@ const processor = {
|
|
|
64
57
|
}];
|
|
65
58
|
break;
|
|
66
59
|
}
|
|
67
|
-
|
|
68
60
|
case _entities.default.COLORBOX.type:
|
|
69
61
|
{
|
|
70
62
|
var _entity$data3, _entity$data4;
|
|
71
|
-
|
|
72
63
|
content = [{
|
|
73
64
|
color: entity === null || entity === void 0 ? void 0 : (_entity$data3 = entity.data) === null || _entity$data3 === void 0 ? void 0 : _entity$data3.color,
|
|
74
65
|
body: entity === null || entity === void 0 ? void 0 : (_entity$data4 = entity.data) === null || _entity$data4 === void 0 ? void 0 : _entity$data4.body
|
|
75
66
|
}];
|
|
76
67
|
break;
|
|
77
68
|
}
|
|
78
|
-
|
|
79
69
|
case _entities.default.TABLE.type:
|
|
80
70
|
{
|
|
81
71
|
var _content, _content2;
|
|
82
|
-
|
|
83
72
|
// About TABLE atomic block entity data structure,
|
|
84
73
|
// see `../views/editor/table.tsx` for more information.
|
|
85
74
|
content = entity === null || entity === void 0 ? void 0 : entity.data;
|
|
86
75
|
/** @type DraftEditor.TableEntity.TableStyles */
|
|
87
|
-
|
|
88
76
|
const tableStyles = (_content = content) === null || _content === void 0 ? void 0 : _content.tableStyles;
|
|
89
77
|
/** @type DraftEditor.TableEntity.TableData */
|
|
90
|
-
|
|
91
78
|
const tableData = (_content2 = content) === null || _content2 === void 0 ? void 0 : _content2.tableData;
|
|
92
79
|
const rowsJsx = tableData === null || tableData === void 0 ? void 0 : tableData.map((row, rIndex) => {
|
|
93
80
|
var _tableStyles$rows;
|
|
94
|
-
|
|
95
81
|
const colsJsx = row === null || row === void 0 ? void 0 : row.map((col, cIndex) => {
|
|
96
82
|
var _tableStyles$columns, _tableStyles$cells, _tableStyles$cells$rI;
|
|
97
|
-
|
|
98
83
|
const colStyle = tableStyles === null || tableStyles === void 0 ? void 0 : (_tableStyles$columns = tableStyles.columns) === null || _tableStyles$columns === void 0 ? void 0 : _tableStyles$columns[cIndex];
|
|
99
84
|
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
85
|
return /*#__PURE__*/React.createElement("td", {
|
|
@@ -109,20 +94,17 @@ const processor = {
|
|
|
109
94
|
key: `row_${rIndex}`,
|
|
110
95
|
style: tableStyles === null || tableStyles === void 0 ? void 0 : (_tableStyles$rows = tableStyles.rows) === null || _tableStyles$rows === void 0 ? void 0 : _tableStyles$rows[rIndex]
|
|
111
96
|
}, colsJsx);
|
|
112
|
-
});
|
|
113
|
-
|
|
97
|
+
});
|
|
98
|
+
// Use `React.renderToStsaticMarkup` to generate plain HTML string
|
|
114
99
|
const html = _server.default.renderToStaticMarkup( /*#__PURE__*/React.createElement("table", null, /*#__PURE__*/React.createElement("tbody", null, rowsJsx)));
|
|
115
|
-
|
|
116
100
|
content = [{
|
|
117
101
|
html
|
|
118
102
|
}];
|
|
119
103
|
break;
|
|
120
104
|
}
|
|
121
|
-
|
|
122
105
|
case _entities.default.DIVIDER.type:
|
|
123
106
|
content = ['<hr>'];
|
|
124
107
|
break;
|
|
125
|
-
|
|
126
108
|
case _entities.default.BLOCKQUOTE.type:
|
|
127
109
|
// this is different from default blockquote of draftjs
|
|
128
110
|
// so we name our specific blockquote as 'quoteby'
|
|
@@ -131,7 +113,6 @@ const processor = {
|
|
|
131
113
|
content = _lodash.default.get(entity, 'data');
|
|
132
114
|
content = Array.isArray(content) ? content : [content];
|
|
133
115
|
break;
|
|
134
|
-
|
|
135
116
|
case _entities.default.AUDIO.type:
|
|
136
117
|
case _entities.default.IMAGE.type:
|
|
137
118
|
case _entities.default.IMAGEDIFF.type:
|
|
@@ -147,17 +128,13 @@ const processor = {
|
|
|
147
128
|
content = _lodash.default.get(entity, 'data');
|
|
148
129
|
content = Array.isArray(content) ? content : [content];
|
|
149
130
|
break;
|
|
150
|
-
|
|
151
131
|
case _entities.default.IMAGELINK.type:
|
|
152
132
|
{
|
|
153
133
|
// use Embedded component to dangerouslySetInnerHTML
|
|
154
134
|
type = _entities.default.EMBEDDEDCODE.type;
|
|
155
135
|
alignment = entity.data && entity.data.alignment || alignment;
|
|
156
|
-
|
|
157
136
|
let description = _lodash.default.get(entity, ['data', 'description'], '');
|
|
158
|
-
|
|
159
137
|
let url = _lodash.default.get(entity, ['data', 'url'], '');
|
|
160
|
-
|
|
161
138
|
content = [{
|
|
162
139
|
caption: description,
|
|
163
140
|
embeddedCodeWithoutScript: `<img alt="${description}" src="${url}" class="img-responsive"/>`,
|
|
@@ -165,15 +142,11 @@ const processor = {
|
|
|
165
142
|
}];
|
|
166
143
|
break;
|
|
167
144
|
}
|
|
168
|
-
|
|
169
145
|
case _entities.default.EMBEDDEDCODE.type:
|
|
170
146
|
{
|
|
171
147
|
alignment = entity.data && entity.data.alignment || alignment;
|
|
172
|
-
|
|
173
148
|
let caption = _lodash.default.get(entity, ['data', 'caption'], '');
|
|
174
|
-
|
|
175
149
|
let embeddedCode = _lodash.default.get(entity, ['data', 'embeddedCode'], '');
|
|
176
|
-
|
|
177
150
|
let script = {};
|
|
178
151
|
let scripts = [];
|
|
179
152
|
let scriptTagStart = false;
|
|
@@ -213,12 +186,11 @@ const processor = {
|
|
|
213
186
|
}];
|
|
214
187
|
break;
|
|
215
188
|
}
|
|
216
|
-
|
|
217
189
|
default:
|
|
218
190
|
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
191
|
+
}
|
|
221
192
|
|
|
193
|
+
// block type of api data should be lower case
|
|
222
194
|
return new _apiDataInstance.default({
|
|
223
195
|
id: block.key,
|
|
224
196
|
alignment,
|
|
@@ -227,7 +199,6 @@ const processor = {
|
|
|
227
199
|
styles
|
|
228
200
|
});
|
|
229
201
|
}
|
|
230
|
-
|
|
231
202
|
};
|
|
232
203
|
var _default = processor;
|
|
233
204
|
exports.default = _default;
|
|
@@ -4,27 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _immutable = require("immutable");
|
|
9
|
-
|
|
10
8
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
-
|
|
12
9
|
var InlineStylesProcessor = _interopRequireWildcard(require("./inline-styles-processor"));
|
|
13
|
-
|
|
14
10
|
var _apiDataInstance = _interopRequireDefault(require("./api-data-instance"));
|
|
15
|
-
|
|
16
11
|
var _atomicBlockProcessor = _interopRequireDefault(require("./atomic-block-processor"));
|
|
17
|
-
|
|
18
12
|
var _entities = _interopRequireDefault(require("./entities"));
|
|
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
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
16
|
// Modified from https://github.com/dburrows/draft-js-basic-html-editor/blob/master/src/utils/draftRawToHtml.js
|
|
17
|
+
|
|
27
18
|
// 'use strict';
|
|
19
|
+
|
|
28
20
|
let defaultBlockTagMap = {
|
|
29
21
|
atomic: `<div>%content%</div>`,
|
|
30
22
|
blockquote: `<blockquote>%content%</blockquote>`,
|
|
@@ -54,7 +46,6 @@ let defaultEntityTagMap = {
|
|
|
54
46
|
[_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
47
|
[_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
48
|
[_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
49
|
/*[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
50
|
[ENTITY.IMAGELINK.type]: ['<img alt="<%= data.description %>" src="<%= data.url %>" class="<%= data.alignment %>">', '</img>'],*/
|
|
60
51
|
[_entities.default.LINK.type]: ['<a target="_blank" href="<%= data.url %>">', '</a>'],
|
|
@@ -66,39 +57,35 @@ let nestedTagMap = {
|
|
|
66
57
|
'ordered-list-item': ['<ol>', '</ol>'],
|
|
67
58
|
'unordered-list-item': ['<ul>', '</ul>']
|
|
68
59
|
};
|
|
69
|
-
|
|
70
60
|
function _convertInlineStyle(block, entityMap, blockTagMap, entityTagMap) {
|
|
71
61
|
return blockTagMap[block.type] ? blockTagMap[block.type].replace('%content%', InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block)) : blockTagMap.default.replace('%content%', InlineStylesProcessor.convertToHtml(inlineTagMap, block));
|
|
72
62
|
}
|
|
73
|
-
|
|
74
63
|
function _convertBlocksToHtml(blocks, entityMap, blockTagMap, entityTagMap) {
|
|
75
64
|
let html = '';
|
|
76
65
|
let nestLevel = []; // store the list type of the previous item: null/ol/ul
|
|
77
|
-
|
|
78
66
|
blocks.forEach(block => {
|
|
79
67
|
// create tag for <ol> or <ul>: deal with ordered/unordered list item
|
|
80
68
|
// if the block is a list-item && the previous block is not a list-item
|
|
81
69
|
if (nestedTagMap[block.type] && nestLevel[0] !== block.type) {
|
|
82
70
|
html += nestedTagMap[block.type][0]; // start with <ol> or <ul>
|
|
83
|
-
|
|
84
71
|
nestLevel.unshift(block.type);
|
|
85
|
-
}
|
|
86
|
-
|
|
72
|
+
}
|
|
87
73
|
|
|
74
|
+
// end tag with </ol> or </ul>: deal with ordered/unordered list item
|
|
88
75
|
if (nestLevel.length > 0 && nestLevel[0] !== block.type) {
|
|
89
76
|
html += nestedTagMap[nestLevel.shift()][1]; // close with </ol> or </ul>
|
|
90
77
|
}
|
|
91
78
|
|
|
92
79
|
html += _convertInlineStyle(block, entityMap, blockTagMap, entityTagMap);
|
|
93
|
-
});
|
|
80
|
+
});
|
|
94
81
|
|
|
82
|
+
// end tag with </ol> or </ul>: or if it is the last block
|
|
95
83
|
if (blocks.length > 0 && nestedTagMap[blocks[blocks.length - 1].type]) {
|
|
96
84
|
html += nestedTagMap[nestLevel.shift()][1]; // close with </ol> or </ul>
|
|
97
85
|
}
|
|
98
86
|
|
|
99
87
|
return html;
|
|
100
88
|
}
|
|
101
|
-
|
|
102
89
|
function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
103
90
|
let apiDataArr = (0, _immutable.List)();
|
|
104
91
|
let content = [];
|
|
@@ -115,7 +102,6 @@ function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
|
115
102
|
content = [];
|
|
116
103
|
nestLevel.shift();
|
|
117
104
|
}
|
|
118
|
-
|
|
119
105
|
if (block.type.startsWith('atomic') || block.type.startsWith('media')) {
|
|
120
106
|
try {
|
|
121
107
|
apiDataArr = apiDataArr.push(_atomicBlockProcessor.default.convertBlock(entityMap, block));
|
|
@@ -124,7 +110,6 @@ function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
|
124
110
|
}
|
|
125
111
|
} else {
|
|
126
112
|
var _block$data;
|
|
127
|
-
|
|
128
113
|
let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block);
|
|
129
114
|
const type = block.type;
|
|
130
115
|
const textAlign = (_block$data = block.data) === null || _block$data === void 0 ? void 0 : _block$data.textAlign;
|
|
@@ -136,8 +121,9 @@ function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
|
136
121
|
}));
|
|
137
122
|
}
|
|
138
123
|
} else {
|
|
139
|
-
let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block);
|
|
124
|
+
let converted = InlineStylesProcessor.convertToHtml(inlineTagMap, entityTagMap, entityMap, block);
|
|
140
125
|
|
|
126
|
+
// previous block is not an item-list block
|
|
141
127
|
if (nestLevel.length === 0) {
|
|
142
128
|
nestLevel.unshift(block.type);
|
|
143
129
|
content.push(converted);
|
|
@@ -155,8 +141,9 @@ function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
|
155
141
|
nestLevel[0] = block.type;
|
|
156
142
|
}
|
|
157
143
|
}
|
|
158
|
-
});
|
|
144
|
+
});
|
|
159
145
|
|
|
146
|
+
// last block is a item-list
|
|
160
147
|
if (blocks.length > 0 && nestLevel.length > 0) {
|
|
161
148
|
let block = blocks[blocks.length - 1];
|
|
162
149
|
apiDataArr = apiDataArr.push(new _apiDataInstance.default({
|
|
@@ -165,10 +152,8 @@ function convertBlocksToApiData(blocks, entityMap, entityTagMap) {
|
|
|
165
152
|
content: content
|
|
166
153
|
}));
|
|
167
154
|
}
|
|
168
|
-
|
|
169
155
|
return apiDataArr;
|
|
170
156
|
}
|
|
171
|
-
|
|
172
157
|
function convertRawToHtml(raw, blockTagMap, entityTagMap) {
|
|
173
158
|
blockTagMap = _lodash.default.merge({}, defaultBlockTagMap, blockTagMap);
|
|
174
159
|
entityTagMap = entityTagMap || defaultEntityTagMap;
|
|
@@ -179,21 +164,17 @@ function convertRawToHtml(raw, blockTagMap, entityTagMap) {
|
|
|
179
164
|
html = _convertBlocksToHtml(blocks, entityMap, blockTagMap, entityTagMap);
|
|
180
165
|
return html;
|
|
181
166
|
}
|
|
182
|
-
|
|
183
167
|
function convertRawToApiData(raw) {
|
|
184
168
|
let apiData;
|
|
185
169
|
raw = raw || {};
|
|
186
170
|
const blocks = Array.isArray(raw.blocks) ? raw.blocks : [];
|
|
187
171
|
const entityMap = typeof raw.entityMap === 'object' ? raw.entityMap : {};
|
|
188
|
-
|
|
189
172
|
let entityTagMap = _lodash.default.merge({}, defaultEntityTagMap, {
|
|
190
173
|
[_entities.default.ANNOTATION.type]: [`<span data-entity-type="annotation" data-annotation-body="<%= data.bodyEscapedHTML %>">`, '</span>']
|
|
191
174
|
});
|
|
192
|
-
|
|
193
175
|
apiData = convertBlocksToApiData(blocks, entityMap, entityTagMap);
|
|
194
176
|
return apiData;
|
|
195
177
|
}
|
|
196
|
-
|
|
197
178
|
var _default = {
|
|
198
179
|
convertToHtml: convertRawToHtml,
|
|
199
180
|
convertToApiData: convertRawToApiData
|