@20minutes/draft-convert 3.1.0 → 3.1.2
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 → dist}/blockEntities.js +4 -4
- package/{esm/blockEntities.js → dist/blockEntities.mjs} +4 -4
- package/{lib → dist}/blockInlineStyles.js +5 -5
- package/{esm/blockInlineStyles.js → dist/blockInlineStyles.mjs} +5 -5
- package/{lib → dist}/convertFromHTML.js +37 -32
- package/{esm/convertFromHTML.js → dist/convertFromHTML.mjs} +9 -4
- package/{lib → dist}/convertToHTML.js +11 -10
- package/{esm/convertToHTML.js → dist/convertToHTML.mjs} +10 -9
- package/{lib → dist}/encodeBlock.js +2 -2
- package/{esm/encodeBlock.js → dist/encodeBlock.mjs} +2 -2
- package/{lib/index.js → dist/index.cjs} +3 -3
- package/dist/index.d.ts +121 -0
- package/dist/index.mjs +4 -0
- package/{lib → dist}/util/getBlockTags.js +1 -1
- package/{esm/util/getBlockTags.js → dist/util/getBlockTags.mjs} +1 -1
- package/{lib → dist}/util/getElementHTML.js +1 -1
- package/{esm/util/getElementHTML.js → dist/util/getElementHTML.mjs} +1 -1
- package/{lib → dist}/util/getElementTagLength.js +1 -1
- package/{esm/util/getElementTagLength.js → dist/util/getElementTagLength.mjs} +1 -1
- package/{lib → dist}/util/getNestedBlockTags.js +1 -1
- package/{esm/util/getNestedBlockTags.js → dist/util/getNestedBlockTags.mjs} +1 -1
- package/package.json +17 -16
- package/esm/index.js +0 -4
- package/types/index.d.ts +0 -114
- /package/{lib → dist}/default/defaultBlockHTML.js +0 -0
- /package/{esm/default/defaultBlockHTML.js → dist/default/defaultBlockHTML.mjs} +0 -0
- /package/{lib → dist}/default/defaultInlineHTML.js +0 -0
- /package/{esm/default/defaultInlineHTML.js → dist/default/defaultInlineHTML.mjs} +0 -0
- /package/{lib → dist}/util/accumulateFunction.js +0 -0
- /package/{esm/util/accumulateFunction.js → dist/util/accumulateFunction.mjs} +0 -0
- /package/{lib → dist}/util/blockTypeObjectFunction.js +0 -0
- /package/{esm/util/blockTypeObjectFunction.js → dist/util/blockTypeObjectFunction.mjs} +0 -0
- /package/{lib → dist}/util/parseHTML.js +0 -0
- /package/{esm/util/parseHTML.js → dist/util/parseHTML.mjs} +0 -0
- /package/{lib → dist}/util/rangeSort.js +0 -0
- /package/{esm/util/rangeSort.js → dist/util/rangeSort.mjs} +0 -0
- /package/{lib → dist}/util/splitReactElement.js +0 -0
- /package/{esm/util/splitReactElement.js → dist/util/splitReactElement.mjs} +0 -0
- /package/{lib → dist}/util/styleObjectFunction.js +0 -0
- /package/{esm/util/styleObjectFunction.js → dist/util/styleObjectFunction.mjs} +0 -0
- /package/{lib → dist}/util/updateMutation.js +0 -0
- /package/{esm/util/updateMutation.js → dist/util/updateMutation.mjs} +0 -0
|
@@ -8,10 +8,10 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _updateMutation = /*#__PURE__*/ _interop_require_default(require("./util/updateMutation"));
|
|
12
|
-
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort"));
|
|
13
|
-
const _getElementHTML = /*#__PURE__*/ _interop_require_default(require("./util/getElementHTML"));
|
|
14
|
-
const _getElementTagLength = /*#__PURE__*/ _interop_require_default(require("./util/getElementTagLength"));
|
|
11
|
+
const _updateMutation = /*#__PURE__*/ _interop_require_default(require("./util/updateMutation.js"));
|
|
12
|
+
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
13
|
+
const _getElementHTML = /*#__PURE__*/ _interop_require_default(require("./util/getElementHTML.js"));
|
|
14
|
+
const _getElementTagLength = /*#__PURE__*/ _interop_require_default(require("./util/getElementTagLength.js"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
17
17
|
default: obj
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import updateMutation from './util/updateMutation';
|
|
2
|
-
import rangeSort from './util/rangeSort';
|
|
3
|
-
import getElementHTML from './util/getElementHTML';
|
|
4
|
-
import getElementTagLength from './util/getElementTagLength';
|
|
1
|
+
import updateMutation from './util/updateMutation.mjs';
|
|
2
|
+
import rangeSort from './util/rangeSort.mjs';
|
|
3
|
+
import getElementHTML from './util/getElementHTML.mjs';
|
|
4
|
+
import getElementTagLength from './util/getElementTagLength.mjs';
|
|
5
5
|
const converter = (entity = {}, originalText = '')=>originalText;
|
|
6
6
|
export default ((block, entityMap, entityConverter = converter)=>{
|
|
7
7
|
let resultText = [
|
|
@@ -9,11 +9,11 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
|
-
const _styleObjectFunction = /*#__PURE__*/ _interop_require_default(require("./util/styleObjectFunction"));
|
|
13
|
-
const _accumulateFunction = /*#__PURE__*/ _interop_require_default(require("./util/accumulateFunction"));
|
|
14
|
-
const _getElementHTML = /*#__PURE__*/ _interop_require_default(require("./util/getElementHTML"));
|
|
15
|
-
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort"));
|
|
16
|
-
const _defaultInlineHTML = /*#__PURE__*/ _interop_require_default(require("./default/defaultInlineHTML"));
|
|
12
|
+
const _styleObjectFunction = /*#__PURE__*/ _interop_require_default(require("./util/styleObjectFunction.js"));
|
|
13
|
+
const _accumulateFunction = /*#__PURE__*/ _interop_require_default(require("./util/accumulateFunction.js"));
|
|
14
|
+
const _getElementHTML = /*#__PURE__*/ _interop_require_default(require("./util/getElementHTML.js"));
|
|
15
|
+
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
16
|
+
const _defaultInlineHTML = /*#__PURE__*/ _interop_require_default(require("./default/defaultInlineHTML.js"));
|
|
17
17
|
function _interop_require_default(obj) {
|
|
18
18
|
return obj && obj.__esModule ? obj : {
|
|
19
19
|
default: obj
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
|
-
import styleObjectFunction from './util/styleObjectFunction';
|
|
3
|
-
import accumulateFunction from './util/accumulateFunction';
|
|
4
|
-
import getElementHTML from './util/getElementHTML';
|
|
5
|
-
import rangeSort from './util/rangeSort';
|
|
6
|
-
import defaultInlineHTML from './default/defaultInlineHTML';
|
|
2
|
+
import styleObjectFunction from './util/styleObjectFunction.mjs';
|
|
3
|
+
import accumulateFunction from './util/accumulateFunction.mjs';
|
|
4
|
+
import getElementHTML from './util/getElementHTML.mjs';
|
|
5
|
+
import rangeSort from './util/rangeSort.mjs';
|
|
6
|
+
import defaultInlineHTML from './default/defaultInlineHTML.mjs';
|
|
7
7
|
const subtractStyles = (original, toRemove)=>original.filter((el)=>!toRemove.some((elToRemove)=>elToRemove.style === el.style));
|
|
8
8
|
const popEndingStyles = (styleStack, endingStyles)=>endingStyles.reduceRight((stack, style)=>{
|
|
9
9
|
const styleToRemove = stack[stack.length - 1];
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* This source code is licensed under the BSD-style license found in the
|
|
9
9
|
* LICENSE file in the /src directory of this source tree. An additional grant
|
|
10
10
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
11
|
-
*/
|
|
11
|
+
*/ // immutable is CJS-only; default import maps to module.exports for Node ESM interop.
|
|
12
|
+
// eslint-disable-next-line import/default
|
|
13
|
+
"use strict";
|
|
12
14
|
Object.defineProperty(exports, "__esModule", {
|
|
13
15
|
value: true
|
|
14
16
|
});
|
|
@@ -18,15 +20,18 @@ Object.defineProperty(exports, "default", {
|
|
|
18
20
|
return _default;
|
|
19
21
|
}
|
|
20
22
|
});
|
|
21
|
-
const _immutable = require("immutable");
|
|
22
|
-
const _draftjs = require("draft-js");
|
|
23
|
-
const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML"));
|
|
24
|
-
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort"));
|
|
23
|
+
const _immutable = /*#__PURE__*/ _interop_require_default(require("immutable"));
|
|
24
|
+
const _draftjs = /*#__PURE__*/ _interop_require_default(require("draft-js"));
|
|
25
|
+
const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML.js"));
|
|
26
|
+
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
25
27
|
function _interop_require_default(obj) {
|
|
26
28
|
return obj && obj.__esModule ? obj : {
|
|
27
29
|
default: obj
|
|
28
30
|
};
|
|
29
31
|
}
|
|
32
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
33
|
+
const { List, Map, OrderedSet } = _immutable.default;
|
|
34
|
+
const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = _draftjs.default;
|
|
30
35
|
const SPACE = ' ';
|
|
31
36
|
// Arbitrary max indent
|
|
32
37
|
const MAX_DEPTH = 4;
|
|
@@ -93,18 +98,18 @@ function getWhitespaceChunk(inEntity) {
|
|
|
93
98
|
return {
|
|
94
99
|
text: SPACE,
|
|
95
100
|
inlines: [
|
|
96
|
-
|
|
101
|
+
OrderedSet()
|
|
97
102
|
],
|
|
98
103
|
entities,
|
|
99
104
|
blocks: []
|
|
100
105
|
};
|
|
101
106
|
}
|
|
102
|
-
function getSoftNewlineChunk(block, depth, flat = false, data =
|
|
107
|
+
function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
|
|
103
108
|
if (flat === true) {
|
|
104
109
|
return {
|
|
105
110
|
text: '\r',
|
|
106
111
|
inlines: [
|
|
107
|
-
|
|
112
|
+
OrderedSet()
|
|
108
113
|
],
|
|
109
114
|
entities: new Array(1),
|
|
110
115
|
blocks: [
|
|
@@ -120,17 +125,17 @@ function getSoftNewlineChunk(block, depth, flat = false, data = (0, _immutable.M
|
|
|
120
125
|
return {
|
|
121
126
|
text: '\n',
|
|
122
127
|
inlines: [
|
|
123
|
-
|
|
128
|
+
OrderedSet()
|
|
124
129
|
],
|
|
125
130
|
entities: new Array(1),
|
|
126
131
|
blocks: []
|
|
127
132
|
};
|
|
128
133
|
}
|
|
129
|
-
function getBlockDividerChunk(block, depth, data =
|
|
134
|
+
function getBlockDividerChunk(block, depth, data = Map()) {
|
|
130
135
|
return {
|
|
131
136
|
text: '\r',
|
|
132
137
|
inlines: [
|
|
133
|
-
|
|
138
|
+
OrderedSet()
|
|
134
139
|
],
|
|
135
140
|
entities: new Array(1),
|
|
136
141
|
blocks: [
|
|
@@ -198,7 +203,7 @@ function processInlineTag(tag, node, currentStyle) {
|
|
|
198
203
|
}
|
|
199
204
|
return currentStyle;
|
|
200
205
|
}
|
|
201
|
-
function baseProcessInlineTag(tag, node, inlineStyles =
|
|
206
|
+
function baseProcessInlineTag(tag, node, inlineStyles = OrderedSet()) {
|
|
202
207
|
return processInlineTag(tag, node, inlineStyles);
|
|
203
208
|
}
|
|
204
209
|
function joinChunks(A, B, flat = false) {
|
|
@@ -314,10 +319,10 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
314
319
|
blockInfo = blockInfo || {};
|
|
315
320
|
if (typeof blockInfo === 'string') {
|
|
316
321
|
blockType = blockInfo;
|
|
317
|
-
blockDataMap =
|
|
322
|
+
blockDataMap = Map();
|
|
318
323
|
} else {
|
|
319
324
|
blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
|
|
320
|
-
blockDataMap = blockInfo.data ?
|
|
325
|
+
blockDataMap = blockInfo.data ? Map(blockInfo.data) : Map();
|
|
321
326
|
}
|
|
322
327
|
if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
|
|
323
328
|
chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
|
|
@@ -361,10 +366,10 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
361
366
|
newBlockInfo = newBlockInfo || {};
|
|
362
367
|
if (typeof newBlockInfo === 'string') {
|
|
363
368
|
newBlockType = newBlockInfo;
|
|
364
|
-
newBlockData =
|
|
369
|
+
newBlockData = Map();
|
|
365
370
|
} else {
|
|
366
371
|
newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
|
|
367
|
-
newBlockData = newBlockInfo.data ?
|
|
372
|
+
newBlockData = newBlockInfo.data ? Map(newBlockInfo.data) : Map();
|
|
368
373
|
}
|
|
369
374
|
chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
|
|
370
375
|
}
|
|
@@ -375,7 +380,7 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
375
380
|
child = sibling;
|
|
376
381
|
}
|
|
377
382
|
if (newBlock) {
|
|
378
|
-
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth,
|
|
383
|
+
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Map()), options.flat);
|
|
379
384
|
}
|
|
380
385
|
return chunk;
|
|
381
386
|
}
|
|
@@ -395,7 +400,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
395
400
|
];
|
|
396
401
|
// Start with -1 block depth to offset the fact that we are passing in a fake
|
|
397
402
|
// UL block to sta rt with.
|
|
398
|
-
let chunk = genFragment(safeBody,
|
|
403
|
+
let chunk = genFragment(safeBody, OrderedSet(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options);
|
|
399
404
|
// join with previous block to prevent weirdness on paste
|
|
400
405
|
if (chunk.text.indexOf('\r') === 0) {
|
|
401
406
|
chunk = {
|
|
@@ -416,7 +421,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
416
421
|
if (chunk.blocks.length === 0) {
|
|
417
422
|
chunk.blocks.push({
|
|
418
423
|
type: 'unstyled',
|
|
419
|
-
data:
|
|
424
|
+
data: Map(),
|
|
420
425
|
depth: 0
|
|
421
426
|
});
|
|
422
427
|
}
|
|
@@ -426,7 +431,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
426
431
|
if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
|
|
427
432
|
chunk.blocks.unshift({
|
|
428
433
|
type: 'unstyled',
|
|
429
|
-
data:
|
|
434
|
+
data: Map(),
|
|
430
435
|
depth: 0
|
|
431
436
|
});
|
|
432
437
|
}
|
|
@@ -447,7 +452,7 @@ function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEn
|
|
|
447
452
|
const end = start + textBlock.length;
|
|
448
453
|
const inlines = nullthrows(chunk).inlines.slice(start, end);
|
|
449
454
|
const entities = nullthrows(chunk).entities.slice(start, end);
|
|
450
|
-
const characterList =
|
|
455
|
+
const characterList = List(inlines.map((style, entityIndex)=>{
|
|
451
456
|
const data = {
|
|
452
457
|
style,
|
|
453
458
|
entity: null
|
|
@@ -455,10 +460,10 @@ function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEn
|
|
|
455
460
|
if (entities[entityIndex]) {
|
|
456
461
|
data.entity = entities[entityIndex];
|
|
457
462
|
}
|
|
458
|
-
return
|
|
463
|
+
return CharacterMetadata.create(data);
|
|
459
464
|
}));
|
|
460
465
|
start = end + 1;
|
|
461
|
-
return new
|
|
466
|
+
return new ContentBlock({
|
|
462
467
|
key: generateKey(),
|
|
463
468
|
type: nullthrows(chunk).blocks[blockIndex].type,
|
|
464
469
|
data: nullthrows(chunk).blocks[blockIndex].data,
|
|
@@ -470,42 +475,42 @@ function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEn
|
|
|
470
475
|
}
|
|
471
476
|
const convertFromHTML = ({ htmlToStyle = defaultHTMLToStyle, htmlToEntity = defaultHTMLToEntity, textToEntity = defaultTextToEntity, htmlToBlock = defaultHTMLToBlock })=>(html, options = {
|
|
472
477
|
flat: false
|
|
473
|
-
}, DOMBuilder = _parseHTML.default, generateKey =
|
|
474
|
-
let contentState =
|
|
478
|
+
}, DOMBuilder = _parseHTML.default, generateKey = genKey)=>{
|
|
479
|
+
let contentState = ContentState.createFromText('');
|
|
475
480
|
const createEntityWithContentState = (...args)=>{
|
|
476
481
|
if (contentState.createEntity) {
|
|
477
482
|
contentState = contentState.createEntity(...args);
|
|
478
483
|
return contentState.getLastCreatedEntityKey();
|
|
479
484
|
}
|
|
480
|
-
return
|
|
485
|
+
return Entity.create(...args);
|
|
481
486
|
};
|
|
482
487
|
const getEntityWithContentState = (...args)=>{
|
|
483
488
|
if (contentState.getEntity) {
|
|
484
489
|
return contentState.getEntity(...args);
|
|
485
490
|
}
|
|
486
|
-
return
|
|
491
|
+
return Entity.get(...args);
|
|
487
492
|
};
|
|
488
493
|
const mergeEntityDataWithContentState = (...args)=>{
|
|
489
494
|
if (contentState.mergeEntityData) {
|
|
490
495
|
contentState = contentState.mergeEntityData(...args);
|
|
491
496
|
return;
|
|
492
497
|
}
|
|
493
|
-
|
|
498
|
+
Entity.mergeData(...args);
|
|
494
499
|
};
|
|
495
500
|
const replaceEntityDataWithContentState = (...args)=>{
|
|
496
501
|
if (contentState.replaceEntityData) {
|
|
497
502
|
contentState = contentState.replaceEntityData(...args);
|
|
498
503
|
return;
|
|
499
504
|
}
|
|
500
|
-
|
|
505
|
+
Entity.replaceData(...args);
|
|
501
506
|
};
|
|
502
507
|
const contentBlocks = convertFromHTMLtoContentBlocks(html, handleMiddleware(htmlToStyle, baseProcessInlineTag), handleMiddleware(htmlToEntity, defaultHTMLToEntity), handleMiddleware(textToEntity, defaultTextToEntity), handleMiddleware(htmlToBlock, baseCheckBlockType), createEntityWithContentState, getEntityWithContentState, mergeEntityDataWithContentState, replaceEntityDataWithContentState, options, DOMBuilder, generateKey);
|
|
503
|
-
const blockMap =
|
|
508
|
+
const blockMap = BlockMapBuilder.createFromArray(contentBlocks);
|
|
504
509
|
const firstBlockKey = contentBlocks[0].getKey();
|
|
505
510
|
return contentState.merge({
|
|
506
511
|
blockMap,
|
|
507
|
-
selectionBefore:
|
|
508
|
-
selectionAfter:
|
|
512
|
+
selectionBefore: SelectionState.createEmpty(firstBlockKey),
|
|
513
|
+
selectionAfter: SelectionState.createEmpty(firstBlockKey)
|
|
509
514
|
});
|
|
510
515
|
};
|
|
511
516
|
const _default = (...args)=>{
|
|
@@ -8,10 +8,15 @@
|
|
|
8
8
|
* This source code is licensed under the BSD-style license found in the
|
|
9
9
|
* LICENSE file in the /src directory of this source tree. An additional grant
|
|
10
10
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
11
|
-
*/ import
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
import
|
|
11
|
+
*/ // immutable is CJS-only; default import maps to module.exports for Node ESM interop.
|
|
12
|
+
// eslint-disable-next-line import/default
|
|
13
|
+
import Immutable from 'immutable';
|
|
14
|
+
import DraftJS from 'draft-js';
|
|
15
|
+
import getSafeBodyFromHTML from './util/parseHTML.mjs';
|
|
16
|
+
import rangeSort from './util/rangeSort.mjs';
|
|
17
|
+
// eslint-disable-next-line import/no-named-as-default-member
|
|
18
|
+
const { List, Map, OrderedSet } = Immutable;
|
|
19
|
+
const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = DraftJS;
|
|
15
20
|
const SPACE = ' ';
|
|
16
21
|
// Arbitrary max indent
|
|
17
22
|
const MAX_DEPTH = 4;
|
|
@@ -11,20 +11,21 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
13
|
const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
|
|
14
|
-
const _draftjs = require("draft-js");
|
|
15
|
-
const _encodeBlock = /*#__PURE__*/ _interop_require_default(require("./encodeBlock"));
|
|
16
|
-
const _blockEntities = /*#__PURE__*/ _interop_require_default(require("./blockEntities"));
|
|
17
|
-
const _blockInlineStyles = /*#__PURE__*/ _interop_require_default(require("./blockInlineStyles"));
|
|
18
|
-
const _accumulateFunction = /*#__PURE__*/ _interop_require_default(require("./util/accumulateFunction"));
|
|
19
|
-
const _blockTypeObjectFunction = /*#__PURE__*/ _interop_require_default(require("./util/blockTypeObjectFunction"));
|
|
20
|
-
const _getBlockTags = /*#__PURE__*/ _interop_require_default(require("./util/getBlockTags"));
|
|
21
|
-
const _getNestedBlockTags = /*#__PURE__*/ _interop_require_default(require("./util/getNestedBlockTags"));
|
|
22
|
-
const _defaultBlockHTML = /*#__PURE__*/ _interop_require_default(require("./default/defaultBlockHTML"));
|
|
14
|
+
const _draftjs = /*#__PURE__*/ _interop_require_default(require("draft-js"));
|
|
15
|
+
const _encodeBlock = /*#__PURE__*/ _interop_require_default(require("./encodeBlock.js"));
|
|
16
|
+
const _blockEntities = /*#__PURE__*/ _interop_require_default(require("./blockEntities.js"));
|
|
17
|
+
const _blockInlineStyles = /*#__PURE__*/ _interop_require_default(require("./blockInlineStyles.js"));
|
|
18
|
+
const _accumulateFunction = /*#__PURE__*/ _interop_require_default(require("./util/accumulateFunction.js"));
|
|
19
|
+
const _blockTypeObjectFunction = /*#__PURE__*/ _interop_require_default(require("./util/blockTypeObjectFunction.js"));
|
|
20
|
+
const _getBlockTags = /*#__PURE__*/ _interop_require_default(require("./util/getBlockTags.js"));
|
|
21
|
+
const _getNestedBlockTags = /*#__PURE__*/ _interop_require_default(require("./util/getNestedBlockTags.js"));
|
|
22
|
+
const _defaultBlockHTML = /*#__PURE__*/ _interop_require_default(require("./default/defaultBlockHTML.js"));
|
|
23
23
|
function _interop_require_default(obj) {
|
|
24
24
|
return obj && obj.__esModule ? obj : {
|
|
25
25
|
default: obj
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
const { convertToRaw } = _draftjs.default;
|
|
28
29
|
const defaultEntityToHTML = (entity, originalText)=>originalText;
|
|
29
30
|
const defaultValidateHTML = (html)=>true;
|
|
30
31
|
const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defaultEntityToHTML, validateHTML = defaultValidateHTML })=>(contentState)=>{
|
|
@@ -35,7 +36,7 @@ const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defa
|
|
|
35
36
|
} else {
|
|
36
37
|
getBlockHTML = (0, _accumulateFunction.default)((0, _blockTypeObjectFunction.default)(blockToHTML), (0, _blockTypeObjectFunction.default)(_defaultBlockHTML.default));
|
|
37
38
|
}
|
|
38
|
-
const rawState =
|
|
39
|
+
const rawState = convertToRaw(contentState);
|
|
39
40
|
let listStack = [];
|
|
40
41
|
let result = rawState.blocks.map((block)=>{
|
|
41
42
|
const { type, depth } = block;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import ReactDOMServer from 'react-dom/server';
|
|
4
|
-
import
|
|
5
|
-
import encodeBlock from './encodeBlock';
|
|
6
|
-
import blockEntities from './blockEntities';
|
|
7
|
-
import blockInlineStyles from './blockInlineStyles';
|
|
8
|
-
import accumulateFunction from './util/accumulateFunction';
|
|
9
|
-
import blockTypeObjectFunction from './util/blockTypeObjectFunction';
|
|
10
|
-
import getBlockTags from './util/getBlockTags';
|
|
11
|
-
import getNestedBlockTags from './util/getNestedBlockTags';
|
|
12
|
-
import defaultBlockHTML from './default/defaultBlockHTML';
|
|
4
|
+
import DraftJS from 'draft-js';
|
|
5
|
+
import encodeBlock from './encodeBlock.mjs';
|
|
6
|
+
import blockEntities from './blockEntities.mjs';
|
|
7
|
+
import blockInlineStyles from './blockInlineStyles.mjs';
|
|
8
|
+
import accumulateFunction from './util/accumulateFunction.mjs';
|
|
9
|
+
import blockTypeObjectFunction from './util/blockTypeObjectFunction.mjs';
|
|
10
|
+
import getBlockTags from './util/getBlockTags.mjs';
|
|
11
|
+
import getNestedBlockTags from './util/getNestedBlockTags.mjs';
|
|
12
|
+
import defaultBlockHTML from './default/defaultBlockHTML.mjs';
|
|
13
|
+
const { convertToRaw } = DraftJS;
|
|
13
14
|
const defaultEntityToHTML = (entity, originalText)=>originalText;
|
|
14
15
|
const defaultValidateHTML = (html)=>true;
|
|
15
16
|
const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defaultEntityToHTML, validateHTML = defaultValidateHTML })=>(contentState)=>{
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _updateMutation = /*#__PURE__*/ _interop_require_default(require("./util/updateMutation"));
|
|
12
|
-
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort"));
|
|
11
|
+
const _updateMutation = /*#__PURE__*/ _interop_require_default(require("./util/updateMutation.js"));
|
|
12
|
+
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
13
13
|
function _interop_require_default(obj) {
|
|
14
14
|
return obj && obj.__esModule ? obj : {
|
|
15
15
|
default: obj
|
|
@@ -19,9 +19,9 @@ _export(exports, {
|
|
|
19
19
|
return _parseHTML.default;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
const _convertToHTML = /*#__PURE__*/ _interop_require_default(require("./convertToHTML"));
|
|
23
|
-
const _convertFromHTML = /*#__PURE__*/ _interop_require_default(require("./convertFromHTML"));
|
|
24
|
-
const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML"));
|
|
22
|
+
const _convertToHTML = /*#__PURE__*/ _interop_require_default(require("./convertToHTML.js"));
|
|
23
|
+
const _convertFromHTML = /*#__PURE__*/ _interop_require_default(require("./convertFromHTML.js"));
|
|
24
|
+
const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML.js"));
|
|
25
25
|
function _interop_require_default(obj) {
|
|
26
26
|
return obj && obj.__esModule ? obj : {
|
|
27
27
|
default: obj
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Based on: https://github.com/HubSpot/draft-convert/issues/107#issuecomment-488581709 by <https://github.com/sbusch>
|
|
2
|
+
// Grabbed from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/draft-convert/index.d.ts
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ContentState,
|
|
6
|
+
DraftBlockType,
|
|
7
|
+
DraftEntityMutability,
|
|
8
|
+
DraftInlineStyleType,
|
|
9
|
+
Entity,
|
|
10
|
+
RawDraftContentBlock,
|
|
11
|
+
RawDraftEntity,
|
|
12
|
+
} from 'draft-js'
|
|
13
|
+
import { ReactNode } from 'react'
|
|
14
|
+
|
|
15
|
+
export type RawDraftContentBlockWithCustomType<T> = Omit<
|
|
16
|
+
RawDraftContentBlock,
|
|
17
|
+
'type'
|
|
18
|
+
> & {
|
|
19
|
+
type: T
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ExtendedHTMLElement<T> = (HTMLElement | HTMLLinkElement) & T
|
|
23
|
+
|
|
24
|
+
export type EntityKey = string
|
|
25
|
+
|
|
26
|
+
export type ContentStateConverter = (contentState: ContentState) => string
|
|
27
|
+
export type HTMLConverter = (html: string) => ContentState
|
|
28
|
+
|
|
29
|
+
export type Tag =
|
|
30
|
+
| ReactNode
|
|
31
|
+
| { start: string; end: string; empty?: string | undefined }
|
|
32
|
+
| {
|
|
33
|
+
element: ReactNode
|
|
34
|
+
empty?: ReactNode | undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IConvertToHTMLConfig<
|
|
38
|
+
S = DraftInlineStyleType,
|
|
39
|
+
B extends DraftBlockType = DraftBlockType,
|
|
40
|
+
E extends RawDraftEntity = RawDraftEntity,
|
|
41
|
+
> {
|
|
42
|
+
// Inline styles:
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
44
|
+
styleToHTML?: ((style: S) => Tag | null | undefined | void) | undefined
|
|
45
|
+
|
|
46
|
+
// Block styles:
|
|
47
|
+
blockToHTML?: ((block: RawDraftContentBlockWithCustomType<B>) => Tag | null | undefined) | undefined
|
|
48
|
+
|
|
49
|
+
// Entity styling:
|
|
50
|
+
entityToHTML?: ((entity: E, originalText: string) => Tag | null | undefined) | undefined
|
|
51
|
+
|
|
52
|
+
// HTML validation:
|
|
53
|
+
validateHTML?: ((html: string) => boolean) | undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IConvertFromHTMLConfig<
|
|
57
|
+
S extends {
|
|
58
|
+
[name: string]: unknown
|
|
59
|
+
} = DOMStringMap,
|
|
60
|
+
B extends DraftBlockType = DraftBlockType,
|
|
61
|
+
E extends RawDraftEntity = RawDraftEntity,
|
|
62
|
+
> {
|
|
63
|
+
// Inline styles:
|
|
64
|
+
htmlToStyle?:
|
|
65
|
+
| ((nodeName: string, node: ExtendedHTMLElement<S>, currentStyle: Set<string>) => Set<string>)
|
|
66
|
+
| undefined
|
|
67
|
+
|
|
68
|
+
// Block styles:
|
|
69
|
+
htmlToBlock?:
|
|
70
|
+
| ((
|
|
71
|
+
nodeName: string,
|
|
72
|
+
node: ExtendedHTMLElement<S>
|
|
73
|
+
) => B | { type: B; data: object } | false | undefined)
|
|
74
|
+
| undefined
|
|
75
|
+
|
|
76
|
+
// Html entities
|
|
77
|
+
htmlToEntity?:
|
|
78
|
+
| ((
|
|
79
|
+
nodeName: string,
|
|
80
|
+
node: ExtendedHTMLElement<S>,
|
|
81
|
+
createEntity: (type: E['type'], mutability: DraftEntityMutability, data: E['data']) => EntityKey,
|
|
82
|
+
getEntity: (key: EntityKey) => Entity,
|
|
83
|
+
mergeEntityData: (key: string, data: object) => void,
|
|
84
|
+
replaceEntityData: (key: string, data: object) => void
|
|
85
|
+
) => EntityKey | undefined)
|
|
86
|
+
| undefined
|
|
87
|
+
|
|
88
|
+
// Text entities
|
|
89
|
+
textToEntity?:
|
|
90
|
+
| ((
|
|
91
|
+
text: string,
|
|
92
|
+
createEntity: (type: E['type'], mutability: DraftEntityMutability, data: E['data']) => EntityKey,
|
|
93
|
+
getEntity: (key: EntityKey) => Entity,
|
|
94
|
+
mergeEntityData: (key: string, data: object) => void,
|
|
95
|
+
replaceEntityData: (key: string, data: object) => void
|
|
96
|
+
) => Array<{
|
|
97
|
+
entity: EntityKey
|
|
98
|
+
offset: number
|
|
99
|
+
length: number
|
|
100
|
+
result?: string | undefined
|
|
101
|
+
}>)
|
|
102
|
+
| undefined
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function convertToHTML<
|
|
106
|
+
S = DraftInlineStyleType,
|
|
107
|
+
B extends DraftBlockType = DraftBlockType,
|
|
108
|
+
E extends RawDraftEntity = RawDraftEntity,
|
|
109
|
+
>(config: IConvertToHTMLConfig<S, B, E>): ContentStateConverter
|
|
110
|
+
export function convertToHTML(contentState: ContentState): string
|
|
111
|
+
|
|
112
|
+
export function convertFromHTML<
|
|
113
|
+
S extends {
|
|
114
|
+
[name: string]: unknown
|
|
115
|
+
} = DOMStringMap,
|
|
116
|
+
B extends DraftBlockType = DraftBlockType,
|
|
117
|
+
E extends RawDraftEntity = RawDraftEntity,
|
|
118
|
+
>(config: IConvertFromHTMLConfig<S, B, E>): HTMLConverter
|
|
119
|
+
export function convertFromHTML(html: string): ContentState
|
|
120
|
+
|
|
121
|
+
export function parseHTML(html: string): HTMLBodyElement
|
package/dist/index.mjs
ADDED
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
13
|
const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
|
|
14
|
-
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
14
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement.js"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
17
17
|
default: obj
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import ReactDOMServer from 'react-dom/server';
|
|
4
|
-
import splitReactElement from './splitReactElement';
|
|
4
|
+
import splitReactElement from './splitReactElement.mjs';
|
|
5
5
|
function hasChildren(element) {
|
|
6
6
|
return /*#__PURE__*/ React.isValidElement(element) && React.Children.count(element.props.children) > 0;
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
13
|
const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
|
|
14
|
-
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
14
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement.js"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
17
17
|
default: obj
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import ReactDOMServer from 'react-dom/server';
|
|
4
|
-
import splitReactElement from './splitReactElement';
|
|
4
|
+
import splitReactElement from './splitReactElement.mjs';
|
|
5
5
|
function hasChildren(element) {
|
|
6
6
|
return /*#__PURE__*/ React.isValidElement(element) && React.Children.count(element.props.children) > 0;
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
12
|
-
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
12
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement.js"));
|
|
13
13
|
function _interop_require_default(obj) {
|
|
14
14
|
return obj && obj.__esModule ? obj : {
|
|
15
15
|
default: obj
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import splitReactElement from './splitReactElement';
|
|
2
|
+
import splitReactElement from './splitReactElement.mjs';
|
|
3
3
|
const getElementTagLength = (element, type = 'start')=>{
|
|
4
4
|
if (/*#__PURE__*/ React.isValidElement(element)) {
|
|
5
5
|
const splitElement = splitReactElement(element);
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
|
-
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
13
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement.js"));
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
16
16
|
default: obj
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import splitReactElement from './splitReactElement';
|
|
3
|
+
import splitReactElement from './splitReactElement.mjs';
|
|
4
4
|
export default function getNestedBlockTags(blockHTML, depth) {
|
|
5
5
|
invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
|
|
6
6
|
if (typeof blockHTML.nest === 'function') {
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@20minutes/draft-convert",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Extensibly serialize & deserialize Draft.js ContentState",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"repository": "20minutes/draft-convert",
|
|
16
17
|
"scripts": {
|
|
17
|
-
"build": "yarn build:cjs && yarn build:
|
|
18
|
-
"build:cjs": "swc src -d
|
|
19
|
-
"build:esm": "swc src -d
|
|
18
|
+
"build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:types",
|
|
19
|
+
"build:cjs": "swc src -d dist --config-file .swcrc.cjs --strip-leading-paths && node scripts/rename-dist-cjs-entry.js",
|
|
20
|
+
"build:esm": "swc src -d dist --config-file .swcrc.esm --strip-leading-paths --delete-dir-on-start --out-file-extension mjs && node scripts/fix-dist-esm-imports.js",
|
|
21
|
+
"build:types": "node scripts/build-dist-types.js",
|
|
20
22
|
"test": "jest",
|
|
21
23
|
"test:watch": "jest --watch",
|
|
22
|
-
"clean": "rimraf ./lib ./esm",
|
|
24
|
+
"clean": "rimraf ./dist ./lib ./esm",
|
|
23
25
|
"build-and-test": "yarn clean && yarn test",
|
|
24
26
|
"lint": "eslint src/ test/"
|
|
25
27
|
},
|
|
26
28
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"lib",
|
|
29
|
-
"esm"
|
|
29
|
+
"dist"
|
|
30
30
|
],
|
|
31
31
|
"keywords": [
|
|
32
32
|
"draft",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@20minutes/eslint-config": "^2.0.0",
|
|
53
|
-
"@swc/cli": "^0.
|
|
53
|
+
"@swc/cli": "^0.8.0",
|
|
54
54
|
"@swc/core": "^1.9.2",
|
|
55
55
|
"@swc/jest": "^0.2.36",
|
|
56
56
|
"draft-js": "^0.11.7",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"prettier": "^3.6.2",
|
|
66
66
|
"react": "^18.0.0",
|
|
67
67
|
"react-dom": "^18.0.0",
|
|
68
|
-
"rimraf": "6.1.
|
|
68
|
+
"rimraf": "6.1.3",
|
|
69
|
+
"tsx": "^4.21.0"
|
|
69
70
|
}
|
|
70
71
|
}
|
package/esm/index.js
DELETED
package/types/index.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// Based on: https://github.com/HubSpot/draft-convert/issues/107#issuecomment-488581709 by <https://github.com/sbusch>
|
|
2
|
-
// Grabbed from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/draft-convert/index.d.ts
|
|
3
|
-
|
|
4
|
-
declare module "@20minutes/draft-convert" {
|
|
5
|
-
import {
|
|
6
|
-
ContentState,
|
|
7
|
-
DraftBlockType,
|
|
8
|
-
DraftEntityMutability,
|
|
9
|
-
DraftInlineStyleType,
|
|
10
|
-
Entity,
|
|
11
|
-
RawDraftContentBlock,
|
|
12
|
-
RawDraftEntity,
|
|
13
|
-
} from "draft-js";
|
|
14
|
-
import { ReactNode } from "react";
|
|
15
|
-
|
|
16
|
-
type RawDraftContentBlockWithCustomType<T> = Omit<RawDraftContentBlock, "type"> & {
|
|
17
|
-
type: T;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type ExtendedHTMLElement<T> = (HTMLElement | HTMLLinkElement) & T;
|
|
21
|
-
|
|
22
|
-
interface IConvertToHTMLConfig<
|
|
23
|
-
S = DraftInlineStyleType,
|
|
24
|
-
B extends DraftBlockType = DraftBlockType,
|
|
25
|
-
E extends RawDraftEntity = RawDraftEntity,
|
|
26
|
-
> {
|
|
27
|
-
// Inline styles:
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
29
|
-
styleToHTML?: ((style: S) => Tag | void) | undefined;
|
|
30
|
-
|
|
31
|
-
// Block styles:
|
|
32
|
-
blockToHTML?: ((block: RawDraftContentBlockWithCustomType<B>) => Tag) | undefined;
|
|
33
|
-
|
|
34
|
-
// Entity styling:
|
|
35
|
-
entityToHTML?: ((entity: E, originalText: string) => Tag) | undefined;
|
|
36
|
-
|
|
37
|
-
// HTML validation:
|
|
38
|
-
validateHTML?: ((html: string) => boolean) | undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type EntityKey = string;
|
|
42
|
-
|
|
43
|
-
interface IConvertFromHTMLConfig<
|
|
44
|
-
S extends {
|
|
45
|
-
[name: string]: unknown;
|
|
46
|
-
} = DOMStringMap,
|
|
47
|
-
B extends DraftBlockType = DraftBlockType,
|
|
48
|
-
E extends RawDraftEntity = RawDraftEntity,
|
|
49
|
-
> {
|
|
50
|
-
// Inline styles:
|
|
51
|
-
htmlToStyle?:
|
|
52
|
-
| ((nodeName: string, node: ExtendedHTMLElement<S>, currentStyle: Set<string>) => Set<string>)
|
|
53
|
-
| undefined;
|
|
54
|
-
|
|
55
|
-
// Block styles:
|
|
56
|
-
htmlToBlock?:
|
|
57
|
-
| ((
|
|
58
|
-
nodeName: string,
|
|
59
|
-
node: ExtendedHTMLElement<S>,
|
|
60
|
-
) => B | { type: B; data: object } | false | undefined)
|
|
61
|
-
| undefined;
|
|
62
|
-
|
|
63
|
-
// Html entities
|
|
64
|
-
htmlToEntity?:
|
|
65
|
-
| ((
|
|
66
|
-
nodeName: string,
|
|
67
|
-
node: ExtendedHTMLElement<S>,
|
|
68
|
-
createEntity: (type: E["type"], mutability: DraftEntityMutability, data: E["data"]) => EntityKey,
|
|
69
|
-
getEntity: (key: EntityKey) => Entity,
|
|
70
|
-
mergeEntityData: (key: string, data: object) => void,
|
|
71
|
-
replaceEntityData: (key: string, data: object) => void,
|
|
72
|
-
) => EntityKey | undefined)
|
|
73
|
-
| undefined;
|
|
74
|
-
|
|
75
|
-
// Text entities
|
|
76
|
-
textToEntity?:
|
|
77
|
-
| ((
|
|
78
|
-
text: string,
|
|
79
|
-
createEntity: (type: E["type"], mutability: DraftEntityMutability, data: E["data"]) => EntityKey,
|
|
80
|
-
getEntity: (key: EntityKey) => Entity,
|
|
81
|
-
mergeEntityData: (key: string, data: object) => void,
|
|
82
|
-
replaceEntityData: (key: string, data: object) => void,
|
|
83
|
-
) => Array<{
|
|
84
|
-
entity: EntityKey;
|
|
85
|
-
offset: number;
|
|
86
|
-
length: number;
|
|
87
|
-
result?: string | undefined;
|
|
88
|
-
}>)
|
|
89
|
-
| undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
type ContentStateConverter = (contentState: ContentState) => string;
|
|
93
|
-
type HTMLConverter = (html: string) => ContentState;
|
|
94
|
-
|
|
95
|
-
type Tag = ReactNode | { start: string; end: string; empty?: string | undefined } | {
|
|
96
|
-
element: ReactNode;
|
|
97
|
-
empty?: ReactNode | undefined;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export function convertToHTML<
|
|
101
|
-
S = DraftInlineStyleType,
|
|
102
|
-
B extends DraftBlockType = DraftBlockType,
|
|
103
|
-
E extends RawDraftEntity = RawDraftEntity,
|
|
104
|
-
>(config: IConvertToHTMLConfig<S, B, E>): ContentStateConverter;
|
|
105
|
-
export function convertToHTML(contentState: ContentState): string;
|
|
106
|
-
export function convertFromHTML<
|
|
107
|
-
S extends {
|
|
108
|
-
[name: string]: unknown;
|
|
109
|
-
} = DOMStringMap,
|
|
110
|
-
B extends DraftBlockType = DraftBlockType,
|
|
111
|
-
E extends RawDraftEntity = RawDraftEntity,
|
|
112
|
-
>(config: IConvertFromHTMLConfig<S, B, E>): HTMLConverter;
|
|
113
|
-
export function convertFromHTML(html: string): ContentState;
|
|
114
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|