@20minutes/draft-convert 3.0.3 → 3.1.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/README.md +2 -3
- package/esm/blockEntities.js +62 -65
- package/esm/blockInlineStyles.js +69 -92
- package/esm/convertFromHTML.js +447 -481
- package/esm/convertToHTML.js +81 -102
- package/esm/default/defaultBlockHTML.js +33 -30
- package/esm/default/defaultInlineHTML.js +16 -16
- package/esm/encodeBlock.js +38 -42
- package/esm/index.js +4 -4
- package/esm/util/accumulateFunction.js +7 -9
- package/esm/util/blockTypeObjectFunction.js +7 -9
- package/esm/util/getBlockTags.js +20 -20
- package/esm/util/getElementHTML.js +25 -29
- package/esm/util/getElementTagLength.js +15 -17
- package/esm/util/getNestedBlockTags.js +21 -26
- package/esm/util/parseHTML.js +15 -15
- package/esm/util/rangeSort.js +6 -6
- package/esm/util/splitReactElement.js +27 -13
- package/esm/util/styleObjectFunction.js +6 -8
- package/esm/util/updateMutation.js +57 -47
- package/lib/blockEntities.js +74 -69
- package/lib/blockInlineStyles.js +81 -96
- package/lib/convertFromHTML.js +502 -487
- package/lib/convertToHTML.js +134 -106
- package/lib/default/defaultBlockHTML.js +47 -35
- package/lib/default/defaultInlineHTML.js +29 -21
- package/lib/encodeBlock.js +50 -46
- package/lib/index.js +25 -23
- package/lib/util/accumulateFunction.js +13 -11
- package/lib/util/blockTypeObjectFunction.js +13 -11
- package/lib/util/getBlockTags.js +35 -27
- package/lib/util/getElementHTML.js +40 -36
- package/lib/util/getElementTagLength.js +28 -22
- package/lib/util/getNestedBlockTags.js +35 -32
- package/lib/util/parseHTML.js +22 -18
- package/lib/util/rangeSort.js +13 -9
- package/lib/util/splitReactElement.js +42 -19
- package/lib/util/styleObjectFunction.js +12 -10
- package/lib/util/updateMutation.js +64 -51
- package/package.json +25 -28
- package/dist/draft-convert.js +0 -440
- package/dist/draft-convert.min.js +0 -1
package/lib/convertFromHTML.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = void 0;
|
|
8
|
-
var _immutable = require("immutable");
|
|
9
|
-
var _draftJs = require("draft-js");
|
|
10
|
-
var _parseHTML = _interopRequireDefault(require("./util/parseHTML"));
|
|
11
|
-
var _rangeSort = _interopRequireDefault(require("./util/rangeSort"));
|
|
12
1
|
/**
|
|
13
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
14
3
|
* All rights reserved.
|
|
@@ -19,526 +8,552 @@ var _rangeSort = _interopRequireDefault(require("./util/rangeSort"));
|
|
|
19
8
|
* This source code is licensed under the BSD-style license found in the
|
|
20
9
|
* LICENSE file in the /src directory of this source tree. An additional grant
|
|
21
10
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
*/ "use strict";
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "default", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return _default;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const _immutable = /*#__PURE__*/ _interop_require_wildcard(require("immutable"));
|
|
22
|
+
const _draftjs = /*#__PURE__*/ _interop_require_wildcard(require("draft-js"));
|
|
23
|
+
const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML.js"));
|
|
24
|
+
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
25
|
+
function _interop_require_default(obj) {
|
|
26
|
+
return obj && obj.__esModule ? obj : {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
31
|
+
if (typeof WeakMap !== "function") return null;
|
|
32
|
+
var cacheBabelInterop = new WeakMap();
|
|
33
|
+
var cacheNodeInterop = new WeakMap();
|
|
34
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
35
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
36
|
+
})(nodeInterop);
|
|
37
|
+
}
|
|
38
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
39
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
43
|
+
return {
|
|
44
|
+
default: obj
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
48
|
+
if (cache && cache.has(obj)) {
|
|
49
|
+
return cache.get(obj);
|
|
50
|
+
}
|
|
51
|
+
var newObj = {
|
|
52
|
+
__proto__: null
|
|
53
|
+
};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
const { List, Map, OrderedSet } = _immutable;
|
|
72
|
+
const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = _draftjs;
|
|
73
|
+
const SPACE = ' ';
|
|
26
74
|
// Arbitrary max indent
|
|
27
|
-
|
|
28
|
-
|
|
75
|
+
const MAX_DEPTH = 4;
|
|
29
76
|
// used for replacing characters in HTML
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
77
|
+
const REGEX_CR = /\r/g;
|
|
78
|
+
const REGEX_LF = /\n/g;
|
|
79
|
+
const REGEX_NBSP = / /g;
|
|
80
|
+
const REGEX_BLOCK_DELIMITER = /\r/g;
|
|
35
81
|
// Block tag flow is different because LIs do not have
|
|
36
82
|
// a deterministic style ;_;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
83
|
+
const blockTags = [
|
|
84
|
+
'p',
|
|
85
|
+
'h1',
|
|
86
|
+
'h2',
|
|
87
|
+
'h3',
|
|
88
|
+
'h4',
|
|
89
|
+
'h5',
|
|
90
|
+
'h6',
|
|
91
|
+
'li',
|
|
92
|
+
'blockquote',
|
|
93
|
+
'pre'
|
|
94
|
+
];
|
|
95
|
+
const inlineTags = {
|
|
96
|
+
b: 'BOLD',
|
|
97
|
+
code: 'CODE',
|
|
98
|
+
del: 'STRIKETHROUGH',
|
|
99
|
+
em: 'ITALIC',
|
|
100
|
+
i: 'ITALIC',
|
|
101
|
+
s: 'STRIKETHROUGH',
|
|
102
|
+
strike: 'STRIKETHROUGH',
|
|
103
|
+
strong: 'BOLD',
|
|
104
|
+
u: 'UNDERLINE'
|
|
48
105
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
var defaultHTMLToBlock = function defaultHTMLToBlock(nodeName, node, lastList) {
|
|
56
|
-
return undefined;
|
|
57
|
-
};
|
|
58
|
-
var defaultHTMLToStyle = function defaultHTMLToStyle(nodeName, node, currentStyle) {
|
|
59
|
-
return currentStyle;
|
|
60
|
-
};
|
|
61
|
-
var defaultHTMLToEntity = function defaultHTMLToEntity(nodeName, node) {
|
|
62
|
-
return undefined;
|
|
63
|
-
};
|
|
64
|
-
var defaultTextToEntity = function defaultTextToEntity(text) {
|
|
65
|
-
return [];
|
|
66
|
-
};
|
|
67
|
-
var nullthrows = function nullthrows(x) {
|
|
68
|
-
if (x != null) {
|
|
69
|
-
return x;
|
|
70
|
-
}
|
|
71
|
-
throw new Error('Got unexpected null or undefined');
|
|
106
|
+
const handleMiddleware = (maybeMiddleware, base)=>{
|
|
107
|
+
if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
|
|
108
|
+
return maybeMiddleware(base);
|
|
109
|
+
}
|
|
110
|
+
return maybeMiddleware;
|
|
72
111
|
};
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
const defaultHTMLToBlock = (nodeName, node, lastList)=>undefined;
|
|
113
|
+
const defaultHTMLToStyle = (nodeName, node, currentStyle)=>currentStyle;
|
|
114
|
+
const defaultHTMLToEntity = (nodeName, node)=>undefined;
|
|
115
|
+
const defaultTextToEntity = (text)=>[];
|
|
116
|
+
const nullthrows = (x)=>{
|
|
117
|
+
if (x != null) {
|
|
118
|
+
return x;
|
|
119
|
+
}
|
|
120
|
+
throw new Error('Got unexpected null or undefined');
|
|
75
121
|
};
|
|
122
|
+
const sanitizeDraftText = (input)=>input.replace(REGEX_BLOCK_DELIMITER, '');
|
|
76
123
|
function getEmptyChunk() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
124
|
+
return {
|
|
125
|
+
text: '',
|
|
126
|
+
inlines: [],
|
|
127
|
+
entities: [],
|
|
128
|
+
blocks: []
|
|
129
|
+
};
|
|
83
130
|
}
|
|
84
131
|
function getWhitespaceChunk(inEntity) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
132
|
+
const entities = new Array(1);
|
|
133
|
+
if (inEntity) {
|
|
134
|
+
entities[0] = inEntity;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
text: SPACE,
|
|
138
|
+
inlines: [
|
|
139
|
+
OrderedSet()
|
|
140
|
+
],
|
|
141
|
+
entities,
|
|
142
|
+
blocks: []
|
|
143
|
+
};
|
|
95
144
|
}
|
|
96
|
-
function getSoftNewlineChunk(block, depth) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
145
|
+
function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
|
|
146
|
+
if (flat === true) {
|
|
147
|
+
return {
|
|
148
|
+
text: '\r',
|
|
149
|
+
inlines: [
|
|
150
|
+
OrderedSet()
|
|
151
|
+
],
|
|
152
|
+
entities: new Array(1),
|
|
153
|
+
blocks: [
|
|
154
|
+
{
|
|
155
|
+
type: block,
|
|
156
|
+
data,
|
|
157
|
+
depth: Math.max(0, Math.min(MAX_DEPTH, depth))
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
isNewline: true
|
|
161
|
+
};
|
|
162
|
+
}
|
|
100
163
|
return {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
depth: Math.max(0, Math.min(MAX_DEPTH, depth))
|
|
108
|
-
}],
|
|
109
|
-
isNewline: true
|
|
164
|
+
text: '\n',
|
|
165
|
+
inlines: [
|
|
166
|
+
OrderedSet()
|
|
167
|
+
],
|
|
168
|
+
entities: new Array(1),
|
|
169
|
+
blocks: []
|
|
110
170
|
};
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
text: '\n',
|
|
114
|
-
inlines: [(0, _immutable.OrderedSet)()],
|
|
115
|
-
entities: new Array(1),
|
|
116
|
-
blocks: []
|
|
117
|
-
};
|
|
118
171
|
}
|
|
119
|
-
function getBlockDividerChunk(block, depth) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
172
|
+
function getBlockDividerChunk(block, depth, data = Map()) {
|
|
173
|
+
return {
|
|
174
|
+
text: '\r',
|
|
175
|
+
inlines: [
|
|
176
|
+
OrderedSet()
|
|
177
|
+
],
|
|
178
|
+
entities: new Array(1),
|
|
179
|
+
blocks: [
|
|
180
|
+
{
|
|
181
|
+
type: block,
|
|
182
|
+
data,
|
|
183
|
+
depth: Math.max(0, Math.min(MAX_DEPTH, depth))
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
};
|
|
131
187
|
}
|
|
132
188
|
function getBlockTypeForTag(tag, lastList) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
189
|
+
switch(tag){
|
|
190
|
+
case 'h1':
|
|
191
|
+
return 'header-one';
|
|
192
|
+
case 'h2':
|
|
193
|
+
return 'header-two';
|
|
194
|
+
case 'h3':
|
|
195
|
+
return 'header-three';
|
|
196
|
+
case 'h4':
|
|
197
|
+
return 'header-four';
|
|
198
|
+
case 'h5':
|
|
199
|
+
return 'header-five';
|
|
200
|
+
case 'h6':
|
|
201
|
+
return 'header-six';
|
|
202
|
+
case 'li':
|
|
203
|
+
if (lastList === 'ol') {
|
|
204
|
+
return 'ordered-list-item';
|
|
205
|
+
}
|
|
206
|
+
return 'unordered-list-item';
|
|
207
|
+
case 'blockquote':
|
|
208
|
+
return 'blockquote';
|
|
209
|
+
case 'pre':
|
|
210
|
+
return 'code-block';
|
|
211
|
+
case 'div':
|
|
212
|
+
case 'p':
|
|
213
|
+
return 'unstyled';
|
|
214
|
+
default:
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
161
217
|
}
|
|
162
218
|
function baseCheckBlockType(nodeName, node, lastList) {
|
|
163
|
-
|
|
219
|
+
return getBlockTypeForTag(nodeName, lastList);
|
|
164
220
|
}
|
|
165
221
|
function processInlineTag(tag, node, currentStyle) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
222
|
+
const styleToCheck = inlineTags[tag];
|
|
223
|
+
if (styleToCheck) {
|
|
224
|
+
currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
|
|
225
|
+
} else if (node instanceof HTMLElement) {
|
|
226
|
+
const htmlElement = node;
|
|
227
|
+
currentStyle = currentStyle.withMutations((style)=>{
|
|
228
|
+
if (htmlElement.style.fontWeight === 'bold') {
|
|
229
|
+
style.add('BOLD');
|
|
230
|
+
}
|
|
231
|
+
if (htmlElement.style.fontStyle === 'italic') {
|
|
232
|
+
style.add('ITALIC');
|
|
233
|
+
}
|
|
234
|
+
if (htmlElement.style.textDecoration === 'underline') {
|
|
235
|
+
style.add('UNDERLINE');
|
|
236
|
+
}
|
|
237
|
+
if (htmlElement.style.textDecoration === 'line-through') {
|
|
238
|
+
style.add('STRIKETHROUGH');
|
|
239
|
+
}
|
|
240
|
+
}).toOrderedSet();
|
|
241
|
+
}
|
|
242
|
+
return currentStyle;
|
|
187
243
|
}
|
|
188
|
-
function baseProcessInlineTag(tag, node) {
|
|
189
|
-
|
|
190
|
-
return processInlineTag(tag, node, inlineStyles);
|
|
244
|
+
function baseProcessInlineTag(tag, node, inlineStyles = OrderedSet()) {
|
|
245
|
+
return processInlineTag(tag, node, inlineStyles);
|
|
191
246
|
}
|
|
192
|
-
function joinChunks(A, B) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Kill whitespace after blocks if flat mode is on
|
|
210
|
-
if (A.text.slice(-1) === '\r' && flat === true) {
|
|
211
|
-
if (B.text === SPACE || B.text === '\n') {
|
|
212
|
-
return A;
|
|
247
|
+
function joinChunks(A, B, flat = false) {
|
|
248
|
+
// Sometimes two blocks will touch in the DOM and we need to strip the
|
|
249
|
+
// extra delimiter to preserve niceness.
|
|
250
|
+
const firstInB = B.text.slice(0, 1);
|
|
251
|
+
const lastInA = A.text.slice(-1);
|
|
252
|
+
const adjacentDividers = lastInA === '\r' && firstInB === '\r';
|
|
253
|
+
const isJoiningBlocks = A.text !== '\r' && B.text !== '\r' // when joining two full blocks like this we want to pop one divider
|
|
254
|
+
;
|
|
255
|
+
const addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline // when joining a newline to an empty block we want to remove the newline
|
|
256
|
+
;
|
|
257
|
+
if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
|
|
258
|
+
A.text = A.text.slice(0, -1);
|
|
259
|
+
A.inlines.pop();
|
|
260
|
+
A.entities.pop();
|
|
261
|
+
A.blocks.pop();
|
|
213
262
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
263
|
+
// Kill whitespace after blocks if flat mode is on
|
|
264
|
+
if (A.text.slice(-1) === '\r' && flat === true) {
|
|
265
|
+
if (B.text === SPACE || B.text === '\n') {
|
|
266
|
+
return A;
|
|
267
|
+
}
|
|
268
|
+
if (firstInB === SPACE || firstInB === '\n') {
|
|
269
|
+
B.text = B.text.slice(1);
|
|
270
|
+
B.inlines.shift();
|
|
271
|
+
B.entities.shift();
|
|
272
|
+
}
|
|
218
273
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
};
|
|
274
|
+
const isNewline = A.text.length === 0 && B.isNewline;
|
|
275
|
+
return {
|
|
276
|
+
text: A.text + B.text,
|
|
277
|
+
inlines: A.inlines.concat(B.inlines),
|
|
278
|
+
entities: A.entities.concat(B.entities),
|
|
279
|
+
blocks: A.blocks.concat(B.blocks),
|
|
280
|
+
isNewline
|
|
281
|
+
};
|
|
228
282
|
}
|
|
229
|
-
|
|
230
283
|
/*
|
|
231
284
|
* Check to see if we have anything like <p> <blockquote> <h1>... to create
|
|
232
285
|
* block tags from. If we do, we can use those and ignore <div> tags. If we
|
|
233
286
|
* don't, we can treat <div> tags as meaningful (unstyled) blocks.
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
return blockTags.some(function (tag) {
|
|
237
|
-
return html.indexOf("<".concat(tag)) !== -1;
|
|
238
|
-
});
|
|
287
|
+
*/ function containsSemanticBlockMarkup(html) {
|
|
288
|
+
return blockTags.some((tag)=>html.indexOf(`<${tag}`) !== -1);
|
|
239
289
|
}
|
|
240
290
|
function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, inEntity) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
291
|
+
let nodeName = node.nodeName.toLowerCase();
|
|
292
|
+
let newBlock = false;
|
|
293
|
+
let nextBlockType = 'unstyled';
|
|
294
|
+
// Base Case
|
|
295
|
+
if (nodeName === '#text') {
|
|
296
|
+
let text = node.textContent;
|
|
297
|
+
if (text.trim() === '' && inBlock === null) {
|
|
298
|
+
return getEmptyChunk();
|
|
299
|
+
}
|
|
300
|
+
if (text.trim() === '' && inBlock !== 'code-block') {
|
|
301
|
+
return getWhitespaceChunk(inEntity);
|
|
302
|
+
}
|
|
303
|
+
if (inBlock !== 'code-block') {
|
|
304
|
+
// Can't use empty string because MSWord
|
|
305
|
+
text = text.replace(REGEX_LF, SPACE);
|
|
306
|
+
}
|
|
307
|
+
const entities = Array(text.length).fill(inEntity);
|
|
308
|
+
let offsetChange = 0;
|
|
309
|
+
const textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort.default);
|
|
310
|
+
textEntities.forEach(({ entity, offset, length, result })=>{
|
|
311
|
+
const adjustedOffset = offset + offsetChange;
|
|
312
|
+
if (result === null || result === undefined) {
|
|
313
|
+
result = text.substr(adjustedOffset, length);
|
|
314
|
+
}
|
|
315
|
+
const textArray = text.split('');
|
|
316
|
+
textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
|
|
317
|
+
text = textArray.join('');
|
|
318
|
+
entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
|
|
319
|
+
offsetChange += result.length - length;
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
text,
|
|
323
|
+
inlines: Array(text.length).fill(inlineStyle),
|
|
324
|
+
entities,
|
|
325
|
+
blocks: []
|
|
326
|
+
};
|
|
250
327
|
}
|
|
251
|
-
|
|
252
|
-
|
|
328
|
+
// BR tags
|
|
329
|
+
if (nodeName === 'br') {
|
|
330
|
+
const blockType = inBlock;
|
|
331
|
+
if (blockType === null) {
|
|
332
|
+
// BR tag is at top level, treat it as an unstyled block
|
|
333
|
+
return getSoftNewlineChunk('unstyled', depth, true);
|
|
334
|
+
}
|
|
335
|
+
return getSoftNewlineChunk(blockType || 'unstyled', depth, options.flat);
|
|
253
336
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
337
|
+
let chunk = getEmptyChunk();
|
|
338
|
+
let newChunk = null;
|
|
339
|
+
// Inline tags
|
|
340
|
+
inlineStyle = processInlineTag(nodeName, node, inlineStyle);
|
|
341
|
+
inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle);
|
|
342
|
+
// Handle lists
|
|
343
|
+
if (nodeName === 'ul' || nodeName === 'ol') {
|
|
344
|
+
if (lastList) {
|
|
345
|
+
depth += 1;
|
|
346
|
+
}
|
|
347
|
+
lastList = nodeName;
|
|
348
|
+
inBlock = null;
|
|
257
349
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
350
|
+
// Block Tags
|
|
351
|
+
let blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
|
|
352
|
+
let blockType;
|
|
353
|
+
let blockDataMap;
|
|
354
|
+
if (blockInfo === false) {
|
|
355
|
+
return getEmptyChunk();
|
|
356
|
+
}
|
|
357
|
+
blockInfo = blockInfo || {};
|
|
358
|
+
if (typeof blockInfo === 'string') {
|
|
359
|
+
blockType = blockInfo;
|
|
360
|
+
blockDataMap = Map();
|
|
361
|
+
} else {
|
|
362
|
+
blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
|
|
363
|
+
blockDataMap = blockInfo.data ? Map(blockInfo.data) : Map();
|
|
364
|
+
}
|
|
365
|
+
if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
|
|
366
|
+
chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
|
|
367
|
+
inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
|
|
368
|
+
newBlock = true;
|
|
369
|
+
} else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
|
|
370
|
+
const listItemBlockType = getBlockTypeForTag(nodeName, lastList);
|
|
371
|
+
chunk = getBlockDividerChunk(listItemBlockType, depth);
|
|
372
|
+
inBlock = listItemBlockType;
|
|
373
|
+
newBlock = true;
|
|
374
|
+
nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
|
|
375
|
+
} else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
|
|
376
|
+
inBlock = blockType;
|
|
377
|
+
newBlock = true;
|
|
378
|
+
chunk = getSoftNewlineChunk(blockType, depth, true, blockDataMap);
|
|
379
|
+
}
|
|
380
|
+
// Recurse through children
|
|
381
|
+
let child = node.firstChild;
|
|
382
|
+
// hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
|
|
383
|
+
// src="..." /></figure>). since metadata must be stored on an entity text
|
|
384
|
+
// must exist for the entity to apply to. the way chunks are joined strips
|
|
385
|
+
// whitespace at the end so it cannot be a space character.
|
|
386
|
+
if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
|
|
387
|
+
child = document.createTextNode('a');
|
|
290
388
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
var chunk = getEmptyChunk();
|
|
294
|
-
var newChunk = null;
|
|
295
|
-
|
|
296
|
-
// Inline tags
|
|
297
|
-
inlineStyle = processInlineTag(nodeName, node, inlineStyle);
|
|
298
|
-
inlineStyle = processCustomInlineStyles(nodeName, node, inlineStyle);
|
|
299
|
-
|
|
300
|
-
// Handle lists
|
|
301
|
-
if (nodeName === 'ul' || nodeName === 'ol') {
|
|
302
|
-
if (lastList) {
|
|
303
|
-
depth += 1;
|
|
389
|
+
if (child != null) {
|
|
390
|
+
nodeName = child.nodeName.toLowerCase();
|
|
304
391
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
newBlock = true;
|
|
328
|
-
} else if (lastList && (inBlock === 'ordered-list-item' || inBlock === 'unordered-list-item') && nodeName === 'li') {
|
|
329
|
-
var listItemBlockType = getBlockTypeForTag(nodeName, lastList);
|
|
330
|
-
chunk = getBlockDividerChunk(listItemBlockType, depth);
|
|
331
|
-
inBlock = listItemBlockType;
|
|
332
|
-
newBlock = true;
|
|
333
|
-
nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
|
|
334
|
-
} else if (inBlock && inBlock !== 'atomic' && blockType === 'atomic') {
|
|
335
|
-
inBlock = blockType;
|
|
336
|
-
newBlock = true;
|
|
337
|
-
chunk = getSoftNewlineChunk(blockType, depth, true,
|
|
338
|
-
// atomic blocks within non-atomic blocks must always be split out
|
|
339
|
-
blockDataMap);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Recurse through children
|
|
343
|
-
var child = node.firstChild;
|
|
344
|
-
|
|
345
|
-
// hack to allow conversion of atomic blocks from HTML (e.g. <figure><img
|
|
346
|
-
// src="..." /></figure>). since metadata must be stored on an entity text
|
|
347
|
-
// must exist for the entity to apply to. the way chunks are joined strips
|
|
348
|
-
// whitespace at the end so it cannot be a space character.
|
|
349
|
-
|
|
350
|
-
if (child == null && inEntity && (blockType === 'atomic' || inBlock === 'atomic')) {
|
|
351
|
-
child = document.createTextNode('a');
|
|
352
|
-
}
|
|
353
|
-
if (child != null) {
|
|
354
|
-
nodeName = child.nodeName.toLowerCase();
|
|
355
|
-
}
|
|
356
|
-
var entityId = null;
|
|
357
|
-
while (child) {
|
|
358
|
-
entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
|
|
359
|
-
newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
|
|
360
|
-
chunk = joinChunks(chunk, newChunk, options.flat);
|
|
361
|
-
var sibling = child.nextSibling;
|
|
362
|
-
|
|
363
|
-
// Put in a newline to break up blocks inside blocks
|
|
364
|
-
if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
|
|
365
|
-
var newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
|
|
366
|
-
var newBlockType = void 0;
|
|
367
|
-
var newBlockData = void 0;
|
|
368
|
-
if (newBlockInfo !== false) {
|
|
369
|
-
newBlockInfo = newBlockInfo || {};
|
|
370
|
-
if (typeof newBlockInfo === 'string') {
|
|
371
|
-
newBlockType = newBlockInfo;
|
|
372
|
-
newBlockData = (0, _immutable.Map)();
|
|
373
|
-
} else {
|
|
374
|
-
newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
|
|
375
|
-
newBlockData = newBlockInfo.data ? (0, _immutable.Map)(newBlockInfo.data) : (0, _immutable.Map)();
|
|
392
|
+
let entityId = null;
|
|
393
|
+
while(child){
|
|
394
|
+
entityId = checkEntityNode(nodeName, child, createEntity, getEntity, mergeEntityData, replaceEntityData);
|
|
395
|
+
newChunk = genFragment(child, inlineStyle, lastList, inBlock, fragmentBlockTags, depth, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, entityId || inEntity);
|
|
396
|
+
chunk = joinChunks(chunk, newChunk, options.flat);
|
|
397
|
+
const sibling = child.nextSibling;
|
|
398
|
+
// Put in a newline to break up blocks inside blocks
|
|
399
|
+
if (sibling && fragmentBlockTags.indexOf(nodeName) >= 0 && inBlock) {
|
|
400
|
+
let newBlockInfo = checkBlockType(nodeName, child, lastList, inBlock);
|
|
401
|
+
let newBlockType;
|
|
402
|
+
let newBlockData;
|
|
403
|
+
if (newBlockInfo !== false) {
|
|
404
|
+
newBlockInfo = newBlockInfo || {};
|
|
405
|
+
if (typeof newBlockInfo === 'string') {
|
|
406
|
+
newBlockType = newBlockInfo;
|
|
407
|
+
newBlockData = Map();
|
|
408
|
+
} else {
|
|
409
|
+
newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
|
|
410
|
+
newBlockData = newBlockInfo.data ? Map(newBlockInfo.data) : Map();
|
|
411
|
+
}
|
|
412
|
+
chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
|
|
413
|
+
}
|
|
376
414
|
}
|
|
377
|
-
|
|
378
|
-
|
|
415
|
+
if (sibling) {
|
|
416
|
+
nodeName = sibling.nodeName.toLowerCase();
|
|
417
|
+
}
|
|
418
|
+
child = sibling;
|
|
379
419
|
}
|
|
380
|
-
if (
|
|
381
|
-
|
|
420
|
+
if (newBlock) {
|
|
421
|
+
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Map()), options.flat);
|
|
382
422
|
}
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
if (newBlock) {
|
|
386
|
-
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, (0, _immutable.Map)()), options.flat);
|
|
387
|
-
}
|
|
388
|
-
return chunk;
|
|
423
|
+
return chunk;
|
|
389
424
|
}
|
|
390
425
|
function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
chunk
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
return chunk;
|
|
426
|
+
html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
|
|
427
|
+
const safeBody = DOMBuilder(html);
|
|
428
|
+
if (!safeBody) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
// Sometimes we aren't dealing with content that contains nice semantic
|
|
432
|
+
// tags. In this case, use divs to separate everything out into paragraphs
|
|
433
|
+
// and hope for the best.
|
|
434
|
+
const workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat([
|
|
435
|
+
'div'
|
|
436
|
+
]) : [
|
|
437
|
+
'div'
|
|
438
|
+
];
|
|
439
|
+
// Start with -1 block depth to offset the fact that we are passing in a fake
|
|
440
|
+
// UL block to sta rt with.
|
|
441
|
+
let chunk = genFragment(safeBody, OrderedSet(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options);
|
|
442
|
+
// join with previous block to prevent weirdness on paste
|
|
443
|
+
if (chunk.text.indexOf('\r') === 0) {
|
|
444
|
+
chunk = {
|
|
445
|
+
text: chunk.text.slice(1),
|
|
446
|
+
inlines: chunk.inlines.slice(1),
|
|
447
|
+
entities: chunk.entities.slice(1),
|
|
448
|
+
blocks: chunk.blocks
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
// Kill block delimiter at the end
|
|
452
|
+
if (chunk.text.slice(-1) === '\r') {
|
|
453
|
+
chunk.text = chunk.text.slice(0, -1);
|
|
454
|
+
chunk.inlines = chunk.inlines.slice(0, -1);
|
|
455
|
+
chunk.entities = chunk.entities.slice(0, -1);
|
|
456
|
+
chunk.blocks.pop();
|
|
457
|
+
}
|
|
458
|
+
// If we saw no block tags, put an unstyled one in
|
|
459
|
+
if (chunk.blocks.length === 0) {
|
|
460
|
+
chunk.blocks.push({
|
|
461
|
+
type: 'unstyled',
|
|
462
|
+
data: Map(),
|
|
463
|
+
depth: 0
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
// Sometimes we start with text that isn't in a block, which is then
|
|
467
|
+
// followed by blocks. Need to fix up the blocks to add in
|
|
468
|
+
// an unstyled block for this content
|
|
469
|
+
if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
|
|
470
|
+
chunk.blocks.unshift({
|
|
471
|
+
type: 'unstyled',
|
|
472
|
+
data: Map(),
|
|
473
|
+
depth: 0
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
return chunk;
|
|
444
477
|
}
|
|
445
478
|
function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
+
// Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
|
|
480
|
+
// arbitrary code in whatever environment you're running this in. For an
|
|
481
|
+
// example of how we try to do this in-browser, see getSafeBodyFromHTML.
|
|
482
|
+
const chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey);
|
|
483
|
+
if (chunk == null) {
|
|
484
|
+
return [];
|
|
485
|
+
}
|
|
486
|
+
let start = 0;
|
|
487
|
+
return chunk.text.split('\r').map((textBlock, blockIndex)=>{
|
|
488
|
+
// Make absolutely certain that our text is acceptable.
|
|
489
|
+
textBlock = sanitizeDraftText(textBlock);
|
|
490
|
+
const end = start + textBlock.length;
|
|
491
|
+
const inlines = nullthrows(chunk).inlines.slice(start, end);
|
|
492
|
+
const entities = nullthrows(chunk).entities.slice(start, end);
|
|
493
|
+
const characterList = List(inlines.map((style, entityIndex)=>{
|
|
494
|
+
const data = {
|
|
495
|
+
style,
|
|
496
|
+
entity: null
|
|
497
|
+
};
|
|
498
|
+
if (entities[entityIndex]) {
|
|
499
|
+
data.entity = entities[entityIndex];
|
|
500
|
+
}
|
|
501
|
+
return CharacterMetadata.create(data);
|
|
502
|
+
}));
|
|
503
|
+
start = end + 1;
|
|
504
|
+
return new ContentBlock({
|
|
505
|
+
key: generateKey(),
|
|
506
|
+
type: nullthrows(chunk).blocks[blockIndex].type,
|
|
507
|
+
data: nullthrows(chunk).blocks[blockIndex].data,
|
|
508
|
+
depth: nullthrows(chunk).blocks[blockIndex].depth,
|
|
509
|
+
text: textBlock,
|
|
510
|
+
characterList
|
|
511
|
+
});
|
|
479
512
|
});
|
|
480
|
-
});
|
|
481
513
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
514
|
+
const convertFromHTML = ({ htmlToStyle = defaultHTMLToStyle, htmlToEntity = defaultHTMLToEntity, textToEntity = defaultTextToEntity, htmlToBlock = defaultHTMLToBlock })=>(html, options = {
|
|
515
|
+
flat: false
|
|
516
|
+
}, DOMBuilder = _parseHTML.default, generateKey = genKey)=>{
|
|
517
|
+
let contentState = ContentState.createFromText('');
|
|
518
|
+
const createEntityWithContentState = (...args)=>{
|
|
519
|
+
if (contentState.createEntity) {
|
|
520
|
+
contentState = contentState.createEntity(...args);
|
|
521
|
+
return contentState.getLastCreatedEntityKey();
|
|
522
|
+
}
|
|
523
|
+
return Entity.create(...args);
|
|
524
|
+
};
|
|
525
|
+
const getEntityWithContentState = (...args)=>{
|
|
526
|
+
if (contentState.getEntity) {
|
|
527
|
+
return contentState.getEntity(...args);
|
|
528
|
+
}
|
|
529
|
+
return Entity.get(...args);
|
|
530
|
+
};
|
|
531
|
+
const mergeEntityDataWithContentState = (...args)=>{
|
|
532
|
+
if (contentState.mergeEntityData) {
|
|
533
|
+
contentState = contentState.mergeEntityData(...args);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
Entity.mergeData(...args);
|
|
537
|
+
};
|
|
538
|
+
const replaceEntityDataWithContentState = (...args)=>{
|
|
539
|
+
if (contentState.replaceEntityData) {
|
|
540
|
+
contentState = contentState.replaceEntityData(...args);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
Entity.replaceData(...args);
|
|
544
|
+
};
|
|
545
|
+
const contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
|
|
546
|
+
const blockMap = BlockMapBuilder.createFromArray(contentBlocks);
|
|
547
|
+
const firstBlockKey = contentBlocks[0].getKey();
|
|
548
|
+
return contentState.merge({
|
|
549
|
+
blockMap,
|
|
550
|
+
selectionBefore: SelectionState.createEmpty(firstBlockKey),
|
|
551
|
+
selectionAfter: SelectionState.createEmpty(firstBlockKey)
|
|
552
|
+
});
|
|
512
553
|
};
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
_draftJs.Entity.mergeData.apply(_draftJs.Entity, arguments);
|
|
520
|
-
};
|
|
521
|
-
var replaceEntityDataWithContentState = function replaceEntityDataWithContentState() {
|
|
522
|
-
if (contentState.replaceEntityData) {
|
|
523
|
-
var _contentState4;
|
|
524
|
-
contentState = (_contentState4 = contentState).replaceEntityData.apply(_contentState4, arguments);
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
_draftJs.Entity.replaceData.apply(_draftJs.Entity, arguments);
|
|
528
|
-
};
|
|
529
|
-
var contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
|
|
530
|
-
var blockMap = _draftJs.BlockMapBuilder.createFromArray(contentBlocks);
|
|
531
|
-
var firstBlockKey = contentBlocks[0].getKey();
|
|
532
|
-
return contentState.merge({
|
|
533
|
-
blockMap: blockMap,
|
|
534
|
-
selectionBefore: _draftJs.SelectionState.createEmpty(firstBlockKey),
|
|
535
|
-
selectionAfter: _draftJs.SelectionState.createEmpty(firstBlockKey)
|
|
536
|
-
});
|
|
537
|
-
};
|
|
554
|
+
const _default = (...args)=>{
|
|
555
|
+
if (args.length >= 1 && typeof args[0] === 'string') {
|
|
556
|
+
return convertFromHTML({})(...args);
|
|
557
|
+
}
|
|
558
|
+
return convertFromHTML(...args);
|
|
538
559
|
};
|
|
539
|
-
var _default = exports["default"] = function _default() {
|
|
540
|
-
if (arguments.length >= 1 && typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') {
|
|
541
|
-
return convertFromHTML({}).apply(void 0, arguments);
|
|
542
|
-
}
|
|
543
|
-
return convertFromHTML.apply(void 0, arguments);
|
|
544
|
-
};
|