@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.
Files changed (42) hide show
  1. package/README.md +2 -3
  2. package/esm/blockEntities.js +62 -65
  3. package/esm/blockInlineStyles.js +69 -92
  4. package/esm/convertFromHTML.js +447 -481
  5. package/esm/convertToHTML.js +81 -102
  6. package/esm/default/defaultBlockHTML.js +33 -30
  7. package/esm/default/defaultInlineHTML.js +16 -16
  8. package/esm/encodeBlock.js +38 -42
  9. package/esm/index.js +4 -4
  10. package/esm/util/accumulateFunction.js +7 -9
  11. package/esm/util/blockTypeObjectFunction.js +7 -9
  12. package/esm/util/getBlockTags.js +20 -20
  13. package/esm/util/getElementHTML.js +25 -29
  14. package/esm/util/getElementTagLength.js +15 -17
  15. package/esm/util/getNestedBlockTags.js +21 -26
  16. package/esm/util/parseHTML.js +15 -15
  17. package/esm/util/rangeSort.js +6 -6
  18. package/esm/util/splitReactElement.js +27 -13
  19. package/esm/util/styleObjectFunction.js +6 -8
  20. package/esm/util/updateMutation.js +57 -47
  21. package/lib/blockEntities.js +74 -69
  22. package/lib/blockInlineStyles.js +81 -96
  23. package/lib/convertFromHTML.js +502 -487
  24. package/lib/convertToHTML.js +134 -106
  25. package/lib/default/defaultBlockHTML.js +47 -35
  26. package/lib/default/defaultInlineHTML.js +29 -21
  27. package/lib/encodeBlock.js +50 -46
  28. package/lib/index.js +25 -23
  29. package/lib/util/accumulateFunction.js +13 -11
  30. package/lib/util/blockTypeObjectFunction.js +13 -11
  31. package/lib/util/getBlockTags.js +35 -27
  32. package/lib/util/getElementHTML.js +40 -36
  33. package/lib/util/getElementTagLength.js +28 -22
  34. package/lib/util/getNestedBlockTags.js +35 -32
  35. package/lib/util/parseHTML.js +22 -18
  36. package/lib/util/rangeSort.js +13 -9
  37. package/lib/util/splitReactElement.js +42 -19
  38. package/lib/util/styleObjectFunction.js +12 -10
  39. package/lib/util/updateMutation.js +64 -51
  40. package/package.json +25 -28
  41. package/dist/draft-convert.js +0 -440
  42. package/dist/draft-convert.min.js +0 -1
@@ -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
- var SPACE = ' ';
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
- var MAX_DEPTH = 4;
28
-
75
+ const MAX_DEPTH = 4;
29
76
  // used for replacing characters in HTML
30
- var REGEX_CR = /\r/g;
31
- var REGEX_LF = /\n/g;
32
- var REGEX_NBSP = / /g;
33
- var REGEX_BLOCK_DELIMITER = /\r/g;
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
- var blockTags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'blockquote', 'pre'];
38
- var inlineTags = {
39
- b: 'BOLD',
40
- code: 'CODE',
41
- del: 'STRIKETHROUGH',
42
- em: 'ITALIC',
43
- i: 'ITALIC',
44
- s: 'STRIKETHROUGH',
45
- strike: 'STRIKETHROUGH',
46
- strong: 'BOLD',
47
- u: 'UNDERLINE'
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
- var handleMiddleware = function handleMiddleware(maybeMiddleware, base) {
50
- if (maybeMiddleware && maybeMiddleware.__isMiddleware === true) {
51
- return maybeMiddleware(base);
52
- }
53
- return maybeMiddleware;
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
- var sanitizeDraftText = function sanitizeDraftText(input) {
74
- return input.replace(REGEX_BLOCK_DELIMITER, '');
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
- return {
78
- text: '',
79
- inlines: [],
80
- entities: [],
81
- blocks: []
82
- };
124
+ return {
125
+ text: '',
126
+ inlines: [],
127
+ entities: [],
128
+ blocks: []
129
+ };
83
130
  }
84
131
  function getWhitespaceChunk(inEntity) {
85
- var entities = new Array(1);
86
- if (inEntity) {
87
- entities[0] = inEntity;
88
- }
89
- return {
90
- text: SPACE,
91
- inlines: [(0, _immutable.OrderedSet)()],
92
- entities: entities,
93
- blocks: []
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
- var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
98
- var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (0, _immutable.Map)();
99
- if (flat === true) {
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
- text: '\r',
102
- inlines: [(0, _immutable.OrderedSet)()],
103
- entities: new Array(1),
104
- blocks: [{
105
- type: block,
106
- data: data,
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
- var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, _immutable.Map)();
121
- return {
122
- text: '\r',
123
- inlines: [(0, _immutable.OrderedSet)()],
124
- entities: new Array(1),
125
- blocks: [{
126
- type: block,
127
- data: data,
128
- depth: Math.max(0, Math.min(MAX_DEPTH, depth))
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
- switch (tag) {
134
- case 'h1':
135
- return 'header-one';
136
- case 'h2':
137
- return 'header-two';
138
- case 'h3':
139
- return 'header-three';
140
- case 'h4':
141
- return 'header-four';
142
- case 'h5':
143
- return 'header-five';
144
- case 'h6':
145
- return 'header-six';
146
- case 'li':
147
- if (lastList === 'ol') {
148
- return 'ordered-list-item';
149
- }
150
- return 'unordered-list-item';
151
- case 'blockquote':
152
- return 'blockquote';
153
- case 'pre':
154
- return 'code-block';
155
- case 'div':
156
- case 'p':
157
- return 'unstyled';
158
- default:
159
- return null;
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
- return getBlockTypeForTag(nodeName, lastList);
219
+ return getBlockTypeForTag(nodeName, lastList);
164
220
  }
165
221
  function processInlineTag(tag, node, currentStyle) {
166
- var styleToCheck = inlineTags[tag];
167
- if (styleToCheck) {
168
- currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
169
- } else if (node instanceof HTMLElement) {
170
- var htmlElement = node;
171
- currentStyle = currentStyle.withMutations(function (style) {
172
- if (htmlElement.style.fontWeight === 'bold') {
173
- style.add('BOLD');
174
- }
175
- if (htmlElement.style.fontStyle === 'italic') {
176
- style.add('ITALIC');
177
- }
178
- if (htmlElement.style.textDecoration === 'underline') {
179
- style.add('UNDERLINE');
180
- }
181
- if (htmlElement.style.textDecoration === 'line-through') {
182
- style.add('STRIKETHROUGH');
183
- }
184
- }).toOrderedSet();
185
- }
186
- return currentStyle;
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
- var inlineStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, _immutable.OrderedSet)();
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
- var flat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
194
- // Sometimes two blocks will touch in the DOM and we need to strip the
195
- // extra delimiter to preserve niceness.
196
- var firstInB = B.text.slice(0, 1);
197
- var lastInA = A.text.slice(-1);
198
- var adjacentDividers = lastInA === '\r' && firstInB === '\r';
199
- var isJoiningBlocks = A.text !== '\r' && B.text !== '\r'; // when joining two full blocks like this we want to pop one divider
200
- var addingNewlineToEmptyBlock = A.text === '\r' && !A.isNewline && B.isNewline; // when joining a newline to an empty block we want to remove the newline
201
-
202
- if (adjacentDividers && (isJoiningBlocks || addingNewlineToEmptyBlock)) {
203
- A.text = A.text.slice(0, -1);
204
- A.inlines.pop();
205
- A.entities.pop();
206
- A.blocks.pop();
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
- if (firstInB === SPACE || firstInB === '\n') {
215
- B.text = B.text.slice(1);
216
- B.inlines.shift();
217
- B.entities.shift();
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
- var isNewline = A.text.length === 0 && B.isNewline;
221
- return {
222
- text: A.text + B.text,
223
- inlines: A.inlines.concat(B.inlines),
224
- entities: A.entities.concat(B.entities),
225
- blocks: A.blocks.concat(B.blocks),
226
- isNewline: isNewline
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
- function containsSemanticBlockMarkup(html) {
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
- var nodeName = node.nodeName.toLowerCase();
242
- var newBlock = false;
243
- var nextBlockType = 'unstyled';
244
-
245
- // Base Case
246
- if (nodeName === '#text') {
247
- var text = node.textContent;
248
- if (text.trim() === '' && inBlock === null) {
249
- return getEmptyChunk();
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
- if (text.trim() === '' && inBlock !== 'code-block') {
252
- return getWhitespaceChunk(inEntity);
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
- if (inBlock !== 'code-block') {
255
- // Can't use empty string because MSWord
256
- text = text.replace(REGEX_LF, SPACE);
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
- var entities = Array(text.length).fill(inEntity);
259
- var offsetChange = 0;
260
- var textEntities = checkEntityText(text, createEntity, getEntity, mergeEntityData, replaceEntityData).sort(_rangeSort["default"]);
261
- textEntities.forEach(function (_ref) {
262
- var entity = _ref.entity,
263
- offset = _ref.offset,
264
- length = _ref.length,
265
- result = _ref.result;
266
- var adjustedOffset = offset + offsetChange;
267
- if (result === null || result === undefined) {
268
- result = text.substr(adjustedOffset, length);
269
- }
270
- var textArray = text.split('');
271
- textArray.splice.bind(textArray, adjustedOffset, length).apply(textArray, result.split(''));
272
- text = textArray.join('');
273
- entities.splice.bind(entities, adjustedOffset, length).apply(entities, Array(result.length).fill(entity));
274
- offsetChange += result.length - length;
275
- });
276
- return {
277
- text: text,
278
- inlines: Array(text.length).fill(inlineStyle),
279
- entities: entities,
280
- blocks: []
281
- };
282
- }
283
-
284
- // BR tags
285
- if (nodeName === 'br') {
286
- var _blockType = inBlock;
287
- if (_blockType === null) {
288
- // BR tag is at top level, treat it as an unstyled block
289
- return getSoftNewlineChunk('unstyled', depth, true);
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
- return getSoftNewlineChunk(_blockType || 'unstyled', depth, options.flat);
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
- lastList = nodeName;
306
- inBlock = null;
307
- }
308
-
309
- // Block Tags
310
- var blockInfo = checkBlockType(nodeName, node, lastList, inBlock);
311
- var blockType;
312
- var blockDataMap;
313
- if (blockInfo === false) {
314
- return getEmptyChunk();
315
- }
316
- blockInfo = blockInfo || {};
317
- if (typeof blockInfo === 'string') {
318
- blockType = blockInfo;
319
- blockDataMap = (0, _immutable.Map)();
320
- } else {
321
- blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
322
- blockDataMap = blockInfo.data ? (0, _immutable.Map)(blockInfo.data) : (0, _immutable.Map)();
323
- }
324
- if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
325
- chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
326
- inBlock = blockType || getBlockTypeForTag(nodeName, lastList);
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
- chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
378
- }
415
+ if (sibling) {
416
+ nodeName = sibling.nodeName.toLowerCase();
417
+ }
418
+ child = sibling;
379
419
  }
380
- if (sibling) {
381
- nodeName = sibling.nodeName.toLowerCase();
420
+ if (newBlock) {
421
+ chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Map()), options.flat);
382
422
  }
383
- child = sibling;
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
- html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE);
392
- var safeBody = DOMBuilder(html);
393
- if (!safeBody) {
394
- return null;
395
- }
396
-
397
- // Sometimes we aren't dealing with content that contains nice semantic
398
- // tags. In this case, use divs to separate everything out into paragraphs
399
- // and hope for the best.
400
- var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags.concat(['div']) : ['div'];
401
-
402
- // Start with -1 block depth to offset the fact that we are passing in a fake
403
- // UL block to sta rt with.
404
- var chunk = genFragment(safeBody, (0, _immutable.OrderedSet)(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options);
405
-
406
- // join with previous block to prevent weirdness on paste
407
- if (chunk.text.indexOf('\r') === 0) {
408
- chunk = {
409
- text: chunk.text.slice(1),
410
- inlines: chunk.inlines.slice(1),
411
- entities: chunk.entities.slice(1),
412
- blocks: chunk.blocks
413
- };
414
- }
415
-
416
- // Kill block delimiter at the end
417
- if (chunk.text.slice(-1) === '\r') {
418
- chunk.text = chunk.text.slice(0, -1);
419
- chunk.inlines = chunk.inlines.slice(0, -1);
420
- chunk.entities = chunk.entities.slice(0, -1);
421
- chunk.blocks.pop();
422
- }
423
-
424
- // If we saw no block tags, put an unstyled one in
425
- if (chunk.blocks.length === 0) {
426
- chunk.blocks.push({
427
- type: 'unstyled',
428
- data: (0, _immutable.Map)(),
429
- depth: 0
430
- });
431
- }
432
-
433
- // Sometimes we start with text that isn't in a block, which is then
434
- // followed by blocks. Need to fix up the blocks to add in
435
- // an unstyled block for this content
436
- if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
437
- chunk.blocks.unshift({
438
- type: 'unstyled',
439
- data: (0, _immutable.Map)(),
440
- depth: 0
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
- // Be ABSOLUTELY SURE that the dom builder you pass hare won't execute
447
- // arbitrary code in whatever environment you're running this in. For an
448
- // example of how we try to do this in-browser, see getSafeBodyFromHTML.
449
-
450
- var chunk = getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options, DOMBuilder, generateKey);
451
- if (chunk == null) {
452
- return [];
453
- }
454
- var start = 0;
455
- return chunk.text.split('\r').map(function (textBlock, blockIndex) {
456
- // Make absolutely certain that our text is acceptable.
457
- textBlock = sanitizeDraftText(textBlock);
458
- var end = start + textBlock.length;
459
- var inlines = nullthrows(chunk).inlines.slice(start, end);
460
- var entities = nullthrows(chunk).entities.slice(start, end);
461
- var characterList = (0, _immutable.List)(inlines.map(function (style, entityIndex) {
462
- var data = {
463
- style: style,
464
- entity: null
465
- };
466
- if (entities[entityIndex]) {
467
- data.entity = entities[entityIndex];
468
- }
469
- return _draftJs.CharacterMetadata.create(data);
470
- }));
471
- start = end + 1;
472
- return new _draftJs.ContentBlock({
473
- key: generateKey(),
474
- type: nullthrows(chunk).blocks[blockIndex].type,
475
- data: nullthrows(chunk).blocks[blockIndex].data,
476
- depth: nullthrows(chunk).blocks[blockIndex].depth,
477
- text: textBlock,
478
- characterList: characterList
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
- var convertFromHTML = function convertFromHTML(_ref2) {
483
- var _ref2$htmlToStyle = _ref2.htmlToStyle,
484
- htmlToStyle = _ref2$htmlToStyle === void 0 ? defaultHTMLToStyle : _ref2$htmlToStyle,
485
- _ref2$htmlToEntity = _ref2.htmlToEntity,
486
- htmlToEntity = _ref2$htmlToEntity === void 0 ? defaultHTMLToEntity : _ref2$htmlToEntity,
487
- _ref2$textToEntity = _ref2.textToEntity,
488
- textToEntity = _ref2$textToEntity === void 0 ? defaultTextToEntity : _ref2$textToEntity,
489
- _ref2$htmlToBlock = _ref2.htmlToBlock,
490
- htmlToBlock = _ref2$htmlToBlock === void 0 ? defaultHTMLToBlock : _ref2$htmlToBlock;
491
- return function (html) {
492
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
493
- flat: false
494
- };
495
- var DOMBuilder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _parseHTML["default"];
496
- var generateKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _draftJs.genKey;
497
- var contentState = _draftJs.ContentState.createFromText('');
498
- var createEntityWithContentState = function createEntityWithContentState() {
499
- if (contentState.createEntity) {
500
- var _contentState;
501
- contentState = (_contentState = contentState).createEntity.apply(_contentState, arguments);
502
- return contentState.getLastCreatedEntityKey();
503
- }
504
- return _draftJs.Entity.create.apply(_draftJs.Entity, arguments);
505
- };
506
- var getEntityWithContentState = function getEntityWithContentState() {
507
- if (contentState.getEntity) {
508
- var _contentState2;
509
- return (_contentState2 = contentState).getEntity.apply(_contentState2, arguments);
510
- }
511
- return _draftJs.Entity.get.apply(_draftJs.Entity, arguments);
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
- var mergeEntityDataWithContentState = function mergeEntityDataWithContentState() {
514
- if (contentState.mergeEntityData) {
515
- var _contentState3;
516
- contentState = (_contentState3 = contentState).mergeEntityData.apply(_contentState3, arguments);
517
- return;
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
- };