@20minutes/draft-convert 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{lib → dist}/blockEntities.js +6 -6
- package/{esm/blockEntities.js → dist/blockEntities.mjs} +8 -8
- package/{lib → dist}/blockInlineStyles.js +6 -6
- package/{esm/blockInlineStyles.js → dist/blockInlineStyles.mjs} +6 -6
- package/{lib → dist}/convertFromHTML.js +24 -66
- package/{esm/convertFromHTML.js → dist/convertFromHTML.mjs} +25 -26
- package/{lib → dist}/convertToHTML.js +10 -51
- package/{esm/convertToHTML.js → dist/convertToHTML.mjs} +14 -14
- package/{esm/encodeBlock.js → dist/encodeBlock.mjs} +2 -2
- package/dist/index.d.ts +127 -0
- package/dist/index.mjs +4 -0
- package/{lib → dist}/util/getBlockTags.js +4 -4
- package/{esm/util/getBlockTags.js → dist/util/getBlockTags.mjs} +4 -4
- package/{lib → dist}/util/getElementHTML.js +2 -2
- package/{esm/util/getElementHTML.js → dist/util/getElementHTML.mjs} +3 -3
- package/{esm/util/getElementTagLength.js → dist/util/getElementTagLength.mjs} +1 -1
- package/{lib → dist}/util/getNestedBlockTags.js +3 -3
- package/{esm/util/getNestedBlockTags.js → dist/util/getNestedBlockTags.mjs} +3 -3
- package/{lib → dist}/util/splitReactElement.js +3 -3
- package/{esm/util/splitReactElement.js → dist/util/splitReactElement.mjs} +1 -1
- package/package.json +21 -25
- 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}/encodeBlock.js +1 -1
- package/{lib/index.js → dist/index.cjs} +1 -1
- /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/getElementTagLength.js +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/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,16 +8,16 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _updateMutation = /*#__PURE__*/ _interop_require_default(require("./util/updateMutation.js"));
|
|
12
|
-
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
13
11
|
const _getElementHTML = /*#__PURE__*/ _interop_require_default(require("./util/getElementHTML.js"));
|
|
14
12
|
const _getElementTagLength = /*#__PURE__*/ _interop_require_default(require("./util/getElementTagLength.js"));
|
|
13
|
+
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
14
|
+
const _updateMutation = /*#__PURE__*/ _interop_require_default(require("./util/updateMutation.js"));
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
17
17
|
default: obj
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
const converter = (
|
|
20
|
+
const converter = (_entity = {}, originalText = '')=>originalText;
|
|
21
21
|
const _default = (block, entityMap, entityConverter = converter)=>{
|
|
22
22
|
let resultText = [
|
|
23
23
|
...block.text
|
|
@@ -26,7 +26,7 @@ const _default = (block, entityMap, entityConverter = converter)=>{
|
|
|
26
26
|
if (entityConverter.__isMiddleware) {
|
|
27
27
|
getEntityHTML = entityConverter(converter);
|
|
28
28
|
}
|
|
29
|
-
if (Object.
|
|
29
|
+
if (Object.hasOwn(block, 'entityRanges') && block.entityRanges.length > 0) {
|
|
30
30
|
let entities = block.entityRanges.sort(_rangeSort.default);
|
|
31
31
|
let styles = block.inlineStyleRanges;
|
|
32
32
|
for(let index = 0; index < entities.length; index += 1){
|
|
@@ -36,7 +36,7 @@ const _default = (block, entityMap, entityConverter = converter)=>{
|
|
|
36
36
|
const entityHTML = getEntityHTML(entity, originalText);
|
|
37
37
|
const elementHTML = (0, _getElementHTML.default)(entityHTML, originalText);
|
|
38
38
|
let converted;
|
|
39
|
-
if (
|
|
39
|
+
if (elementHTML || elementHTML === '') {
|
|
40
40
|
converted = [
|
|
41
41
|
...elementHTML
|
|
42
42
|
];
|
|
@@ -46,7 +46,7 @@ const _default = (block, entityMap, entityConverter = converter)=>{
|
|
|
46
46
|
const prefixLength = (0, _getElementTagLength.default)(entityHTML, 'start');
|
|
47
47
|
const suffixLength = (0, _getElementTagLength.default)(entityHTML, 'end');
|
|
48
48
|
const updateLaterMutation = (mutation, mutationIndex)=>{
|
|
49
|
-
if (mutationIndex > index || Object.
|
|
49
|
+
if (mutationIndex > index || Object.hasOwn(mutation, 'style')) {
|
|
50
50
|
return (0, _updateMutation.default)(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
|
|
51
51
|
}
|
|
52
52
|
return mutation;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const converter = (
|
|
1
|
+
import getElementHTML from './util/getElementHTML.mjs';
|
|
2
|
+
import getElementTagLength from './util/getElementTagLength.mjs';
|
|
3
|
+
import rangeSort from './util/rangeSort.mjs';
|
|
4
|
+
import updateMutation from './util/updateMutation.mjs';
|
|
5
|
+
const converter = (_entity = {}, originalText = '')=>originalText;
|
|
6
6
|
export default ((block, entityMap, entityConverter = converter)=>{
|
|
7
7
|
let resultText = [
|
|
8
8
|
...block.text
|
|
@@ -11,7 +11,7 @@ export default ((block, entityMap, entityConverter = converter)=>{
|
|
|
11
11
|
if (entityConverter.__isMiddleware) {
|
|
12
12
|
getEntityHTML = entityConverter(converter);
|
|
13
13
|
}
|
|
14
|
-
if (Object.
|
|
14
|
+
if (Object.hasOwn(block, 'entityRanges') && block.entityRanges.length > 0) {
|
|
15
15
|
let entities = block.entityRanges.sort(rangeSort);
|
|
16
16
|
let styles = block.inlineStyleRanges;
|
|
17
17
|
for(let index = 0; index < entities.length; index += 1){
|
|
@@ -21,7 +21,7 @@ export default ((block, entityMap, entityConverter = converter)=>{
|
|
|
21
21
|
const entityHTML = getEntityHTML(entity, originalText);
|
|
22
22
|
const elementHTML = getElementHTML(entityHTML, originalText);
|
|
23
23
|
let converted;
|
|
24
|
-
if (
|
|
24
|
+
if (elementHTML || elementHTML === '') {
|
|
25
25
|
converted = [
|
|
26
26
|
...elementHTML
|
|
27
27
|
];
|
|
@@ -31,7 +31,7 @@ export default ((block, entityMap, entityConverter = converter)=>{
|
|
|
31
31
|
const prefixLength = getElementTagLength(entityHTML, 'start');
|
|
32
32
|
const suffixLength = getElementTagLength(entityHTML, 'end');
|
|
33
33
|
const updateLaterMutation = (mutation, mutationIndex)=>{
|
|
34
|
-
if (mutationIndex > index || Object.
|
|
34
|
+
if (mutationIndex > index || Object.hasOwn(mutation, 'style')) {
|
|
35
35
|
return updateMutation(mutation, entityRange.offset, entityRange.length, converted.length, prefixLength, suffixLength);
|
|
36
36
|
}
|
|
37
37
|
return mutation;
|
|
@@ -8,12 +8,12 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const _tinyinvariant = /*#__PURE__*/ _interop_require_default(require("tiny-invariant"));
|
|
12
|
+
const _defaultInlineHTML = /*#__PURE__*/ _interop_require_default(require("./default/defaultInlineHTML.js"));
|
|
13
13
|
const _accumulateFunction = /*#__PURE__*/ _interop_require_default(require("./util/accumulateFunction.js"));
|
|
14
14
|
const _getElementHTML = /*#__PURE__*/ _interop_require_default(require("./util/getElementHTML.js"));
|
|
15
15
|
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
16
|
-
const
|
|
16
|
+
const _styleObjectFunction = /*#__PURE__*/ _interop_require_default(require("./util/styleObjectFunction.js"));
|
|
17
17
|
function _interop_require_default(obj) {
|
|
18
18
|
return obj && obj.__esModule ? obj : {
|
|
19
19
|
default: obj
|
|
@@ -22,7 +22,7 @@ function _interop_require_default(obj) {
|
|
|
22
22
|
const subtractStyles = (original, toRemove)=>original.filter((el)=>!toRemove.some((elToRemove)=>elToRemove.style === el.style));
|
|
23
23
|
const popEndingStyles = (styleStack, endingStyles)=>endingStyles.reduceRight((stack, style)=>{
|
|
24
24
|
const styleToRemove = stack[stack.length - 1];
|
|
25
|
-
(0,
|
|
25
|
+
(0, _tinyinvariant.default)(styleToRemove.style === style.style, `Style ${styleToRemove.style} to be removed doesn't match expected ${style.style}`);
|
|
26
26
|
return stack.slice(0, -1);
|
|
27
27
|
}, styleStack);
|
|
28
28
|
const characterStyles = (offset, ranges)=>ranges.filter((range)=>offset >= range.offset && offset < range.offset + range.length);
|
|
@@ -54,7 +54,7 @@ const prependEndMarkup = (inlineHTML, string, styleRange)=>(0, _getElementHTML.d
|
|
|
54
54
|
const defaultCustomInlineHTML = (next)=>(style)=>next(style);
|
|
55
55
|
defaultCustomInlineHTML.__isMiddleware = true;
|
|
56
56
|
const _default = (rawBlock, customInlineHTML = defaultCustomInlineHTML)=>{
|
|
57
|
-
(0,
|
|
57
|
+
(0, _tinyinvariant.default)(rawBlock !== null && rawBlock !== undefined, 'Expected raw block to be non-null');
|
|
58
58
|
let inlineHTML;
|
|
59
59
|
if (customInlineHTML.__isMiddleware === true) {
|
|
60
60
|
inlineHTML = customInlineHTML(_defaultInlineHTML.default);
|
|
@@ -83,7 +83,7 @@ const _default = (rawBlock, customInlineHTML = defaultCustomInlineHTML)=>{
|
|
|
83
83
|
result += endingStyleTags + openingStyleTags + originalTextArray[i];
|
|
84
84
|
styleStack = popEndingStyles(styleStack, resetStyles.concat(endingStyles));
|
|
85
85
|
styleStack = styleStack.concat(openingStyles);
|
|
86
|
-
(0,
|
|
86
|
+
(0, _tinyinvariant.default)(styleStack.length === styles.length, `Character ${i}: ${styleStack.length - styles.length} styles left on stack that should no longer be there`);
|
|
87
87
|
}
|
|
88
88
|
result = styleStack.reduceRight((res, openStyle)=>res + (0, _getElementHTML.default)(inlineHTML(openStyle.style)).end, result);
|
|
89
89
|
return result;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import invariant from 'invariant';
|
|
2
|
-
import
|
|
3
|
-
import accumulateFunction from './util/accumulateFunction.
|
|
4
|
-
import getElementHTML from './util/getElementHTML.
|
|
5
|
-
import rangeSort from './util/rangeSort.
|
|
6
|
-
import
|
|
1
|
+
import invariant from 'tiny-invariant';
|
|
2
|
+
import defaultInlineHTML from './default/defaultInlineHTML.mjs';
|
|
3
|
+
import accumulateFunction from './util/accumulateFunction.mjs';
|
|
4
|
+
import getElementHTML from './util/getElementHTML.mjs';
|
|
5
|
+
import rangeSort from './util/rangeSort.mjs';
|
|
6
|
+
import styleObjectFunction from './util/styleObjectFunction.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];
|
|
@@ -18,8 +18,8 @@ Object.defineProperty(exports, "default", {
|
|
|
18
18
|
return _default;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
-
const
|
|
22
|
-
const
|
|
21
|
+
const _draftjs = /*#__PURE__*/ _interop_require_default(require("draft-js"));
|
|
22
|
+
const _immutable = /*#__PURE__*/ _interop_require_default(require("immutable"));
|
|
23
23
|
const _parseHTML = /*#__PURE__*/ _interop_require_default(require("./util/parseHTML.js"));
|
|
24
24
|
const _rangeSort = /*#__PURE__*/ _interop_require_default(require("./util/rangeSort.js"));
|
|
25
25
|
function _interop_require_default(obj) {
|
|
@@ -27,49 +27,7 @@ function _interop_require_default(obj) {
|
|
|
27
27
|
default: obj
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
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;
|
|
30
|
+
const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = _draftjs.default;
|
|
73
31
|
const SPACE = ' ';
|
|
74
32
|
// Arbitrary max indent
|
|
75
33
|
const MAX_DEPTH = 4;
|
|
@@ -109,10 +67,10 @@ const handleMiddleware = (maybeMiddleware, base)=>{
|
|
|
109
67
|
}
|
|
110
68
|
return maybeMiddleware;
|
|
111
69
|
};
|
|
112
|
-
const defaultHTMLToBlock = (
|
|
113
|
-
const defaultHTMLToStyle = (
|
|
114
|
-
const defaultHTMLToEntity = (
|
|
115
|
-
const defaultTextToEntity = (
|
|
70
|
+
const defaultHTMLToBlock = (_nodeName, _node, _lastList)=>undefined;
|
|
71
|
+
const defaultHTMLToStyle = (_nodeName, _node, currentStyle)=>currentStyle;
|
|
72
|
+
const defaultHTMLToEntity = (_nodeName, _node)=>undefined;
|
|
73
|
+
const defaultTextToEntity = (_text)=>[];
|
|
116
74
|
const nullthrows = (x)=>{
|
|
117
75
|
if (x != null) {
|
|
118
76
|
return x;
|
|
@@ -136,18 +94,18 @@ function getWhitespaceChunk(inEntity) {
|
|
|
136
94
|
return {
|
|
137
95
|
text: SPACE,
|
|
138
96
|
inlines: [
|
|
139
|
-
OrderedSet()
|
|
97
|
+
_immutable.default.OrderedSet()
|
|
140
98
|
],
|
|
141
99
|
entities,
|
|
142
100
|
blocks: []
|
|
143
101
|
};
|
|
144
102
|
}
|
|
145
|
-
function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
|
|
103
|
+
function getSoftNewlineChunk(block, depth, flat = false, data = _immutable.default.Map()) {
|
|
146
104
|
if (flat === true) {
|
|
147
105
|
return {
|
|
148
106
|
text: '\r',
|
|
149
107
|
inlines: [
|
|
150
|
-
OrderedSet()
|
|
108
|
+
_immutable.default.OrderedSet()
|
|
151
109
|
],
|
|
152
110
|
entities: new Array(1),
|
|
153
111
|
blocks: [
|
|
@@ -163,17 +121,17 @@ function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
|
|
|
163
121
|
return {
|
|
164
122
|
text: '\n',
|
|
165
123
|
inlines: [
|
|
166
|
-
OrderedSet()
|
|
124
|
+
_immutable.default.OrderedSet()
|
|
167
125
|
],
|
|
168
126
|
entities: new Array(1),
|
|
169
127
|
blocks: []
|
|
170
128
|
};
|
|
171
129
|
}
|
|
172
|
-
function getBlockDividerChunk(block, depth, data = Map()) {
|
|
130
|
+
function getBlockDividerChunk(block, depth, data = _immutable.default.Map()) {
|
|
173
131
|
return {
|
|
174
132
|
text: '\r',
|
|
175
133
|
inlines: [
|
|
176
|
-
OrderedSet()
|
|
134
|
+
_immutable.default.OrderedSet()
|
|
177
135
|
],
|
|
178
136
|
entities: new Array(1),
|
|
179
137
|
blocks: [
|
|
@@ -215,7 +173,7 @@ function getBlockTypeForTag(tag, lastList) {
|
|
|
215
173
|
return null;
|
|
216
174
|
}
|
|
217
175
|
}
|
|
218
|
-
function baseCheckBlockType(nodeName,
|
|
176
|
+
function baseCheckBlockType(nodeName, _node, lastList) {
|
|
219
177
|
return getBlockTypeForTag(nodeName, lastList);
|
|
220
178
|
}
|
|
221
179
|
function processInlineTag(tag, node, currentStyle) {
|
|
@@ -241,7 +199,7 @@ function processInlineTag(tag, node, currentStyle) {
|
|
|
241
199
|
}
|
|
242
200
|
return currentStyle;
|
|
243
201
|
}
|
|
244
|
-
function baseProcessInlineTag(tag, node, inlineStyles = OrderedSet()) {
|
|
202
|
+
function baseProcessInlineTag(tag, node, inlineStyles = _immutable.default.OrderedSet()) {
|
|
245
203
|
return processInlineTag(tag, node, inlineStyles);
|
|
246
204
|
}
|
|
247
205
|
function joinChunks(A, B, flat = false) {
|
|
@@ -357,10 +315,10 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
357
315
|
blockInfo = blockInfo || {};
|
|
358
316
|
if (typeof blockInfo === 'string') {
|
|
359
317
|
blockType = blockInfo;
|
|
360
|
-
blockDataMap = Map();
|
|
318
|
+
blockDataMap = _immutable.default.Map();
|
|
361
319
|
} else {
|
|
362
320
|
blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
|
|
363
|
-
blockDataMap = blockInfo.data ? Map(blockInfo.data) : Map();
|
|
321
|
+
blockDataMap = blockInfo.data ? _immutable.default.Map(blockInfo.data) : _immutable.default.Map();
|
|
364
322
|
}
|
|
365
323
|
if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
|
|
366
324
|
chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
|
|
@@ -404,10 +362,10 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
404
362
|
newBlockInfo = newBlockInfo || {};
|
|
405
363
|
if (typeof newBlockInfo === 'string') {
|
|
406
364
|
newBlockType = newBlockInfo;
|
|
407
|
-
newBlockData = Map();
|
|
365
|
+
newBlockData = _immutable.default.Map();
|
|
408
366
|
} else {
|
|
409
367
|
newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
|
|
410
|
-
newBlockData = newBlockInfo.data ? Map(newBlockInfo.data) : Map();
|
|
368
|
+
newBlockData = newBlockInfo.data ? _immutable.default.Map(newBlockInfo.data) : _immutable.default.Map();
|
|
411
369
|
}
|
|
412
370
|
chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
|
|
413
371
|
}
|
|
@@ -418,7 +376,7 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
418
376
|
child = sibling;
|
|
419
377
|
}
|
|
420
378
|
if (newBlock) {
|
|
421
|
-
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Map()), options.flat);
|
|
379
|
+
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, _immutable.default.Map()), options.flat);
|
|
422
380
|
}
|
|
423
381
|
return chunk;
|
|
424
382
|
}
|
|
@@ -438,7 +396,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
438
396
|
];
|
|
439
397
|
// Start with -1 block depth to offset the fact that we are passing in a fake
|
|
440
398
|
// 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);
|
|
399
|
+
let chunk = genFragment(safeBody, _immutable.default.OrderedSet(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options);
|
|
442
400
|
// join with previous block to prevent weirdness on paste
|
|
443
401
|
if (chunk.text.indexOf('\r') === 0) {
|
|
444
402
|
chunk = {
|
|
@@ -459,7 +417,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
459
417
|
if (chunk.blocks.length === 0) {
|
|
460
418
|
chunk.blocks.push({
|
|
461
419
|
type: 'unstyled',
|
|
462
|
-
data: Map(),
|
|
420
|
+
data: _immutable.default.Map(),
|
|
463
421
|
depth: 0
|
|
464
422
|
});
|
|
465
423
|
}
|
|
@@ -469,7 +427,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
469
427
|
if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
|
|
470
428
|
chunk.blocks.unshift({
|
|
471
429
|
type: 'unstyled',
|
|
472
|
-
data: Map(),
|
|
430
|
+
data: _immutable.default.Map(),
|
|
473
431
|
depth: 0
|
|
474
432
|
});
|
|
475
433
|
}
|
|
@@ -490,7 +448,7 @@ function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEn
|
|
|
490
448
|
const end = start + textBlock.length;
|
|
491
449
|
const inlines = nullthrows(chunk).inlines.slice(start, end);
|
|
492
450
|
const entities = nullthrows(chunk).entities.slice(start, end);
|
|
493
|
-
const characterList = List(inlines.map((style, entityIndex)=>{
|
|
451
|
+
const characterList = _immutable.default.List(inlines.map((style, entityIndex)=>{
|
|
494
452
|
const data = {
|
|
495
453
|
style,
|
|
496
454
|
entity: null
|
|
@@ -8,11 +8,10 @@
|
|
|
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
|
-
import
|
|
13
|
-
import getSafeBodyFromHTML from './util/parseHTML.
|
|
14
|
-
import rangeSort from './util/rangeSort.
|
|
15
|
-
const { List, Map, OrderedSet } = Immutable;
|
|
11
|
+
*/ import DraftJS from 'draft-js';
|
|
12
|
+
import Immutable from 'immutable';
|
|
13
|
+
import getSafeBodyFromHTML from './util/parseHTML.mjs';
|
|
14
|
+
import rangeSort from './util/rangeSort.mjs';
|
|
16
15
|
const { BlockMapBuilder, CharacterMetadata, ContentBlock, ContentState, Entity, SelectionState, genKey } = DraftJS;
|
|
17
16
|
const SPACE = ' ';
|
|
18
17
|
// Arbitrary max indent
|
|
@@ -53,10 +52,10 @@ const handleMiddleware = (maybeMiddleware, base)=>{
|
|
|
53
52
|
}
|
|
54
53
|
return maybeMiddleware;
|
|
55
54
|
};
|
|
56
|
-
const defaultHTMLToBlock = (
|
|
57
|
-
const defaultHTMLToStyle = (
|
|
58
|
-
const defaultHTMLToEntity = (
|
|
59
|
-
const defaultTextToEntity = (
|
|
55
|
+
const defaultHTMLToBlock = (_nodeName, _node, _lastList)=>undefined;
|
|
56
|
+
const defaultHTMLToStyle = (_nodeName, _node, currentStyle)=>currentStyle;
|
|
57
|
+
const defaultHTMLToEntity = (_nodeName, _node)=>undefined;
|
|
58
|
+
const defaultTextToEntity = (_text)=>[];
|
|
60
59
|
const nullthrows = (x)=>{
|
|
61
60
|
if (x != null) {
|
|
62
61
|
return x;
|
|
@@ -80,18 +79,18 @@ function getWhitespaceChunk(inEntity) {
|
|
|
80
79
|
return {
|
|
81
80
|
text: SPACE,
|
|
82
81
|
inlines: [
|
|
83
|
-
OrderedSet()
|
|
82
|
+
Immutable.OrderedSet()
|
|
84
83
|
],
|
|
85
84
|
entities,
|
|
86
85
|
blocks: []
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
|
|
88
|
+
function getSoftNewlineChunk(block, depth, flat = false, data = Immutable.Map()) {
|
|
90
89
|
if (flat === true) {
|
|
91
90
|
return {
|
|
92
91
|
text: '\r',
|
|
93
92
|
inlines: [
|
|
94
|
-
OrderedSet()
|
|
93
|
+
Immutable.OrderedSet()
|
|
95
94
|
],
|
|
96
95
|
entities: new Array(1),
|
|
97
96
|
blocks: [
|
|
@@ -107,17 +106,17 @@ function getSoftNewlineChunk(block, depth, flat = false, data = Map()) {
|
|
|
107
106
|
return {
|
|
108
107
|
text: '\n',
|
|
109
108
|
inlines: [
|
|
110
|
-
OrderedSet()
|
|
109
|
+
Immutable.OrderedSet()
|
|
111
110
|
],
|
|
112
111
|
entities: new Array(1),
|
|
113
112
|
blocks: []
|
|
114
113
|
};
|
|
115
114
|
}
|
|
116
|
-
function getBlockDividerChunk(block, depth, data = Map()) {
|
|
115
|
+
function getBlockDividerChunk(block, depth, data = Immutable.Map()) {
|
|
117
116
|
return {
|
|
118
117
|
text: '\r',
|
|
119
118
|
inlines: [
|
|
120
|
-
OrderedSet()
|
|
119
|
+
Immutable.OrderedSet()
|
|
121
120
|
],
|
|
122
121
|
entities: new Array(1),
|
|
123
122
|
blocks: [
|
|
@@ -159,7 +158,7 @@ function getBlockTypeForTag(tag, lastList) {
|
|
|
159
158
|
return null;
|
|
160
159
|
}
|
|
161
160
|
}
|
|
162
|
-
function baseCheckBlockType(nodeName,
|
|
161
|
+
function baseCheckBlockType(nodeName, _node, lastList) {
|
|
163
162
|
return getBlockTypeForTag(nodeName, lastList);
|
|
164
163
|
}
|
|
165
164
|
function processInlineTag(tag, node, currentStyle) {
|
|
@@ -185,7 +184,7 @@ function processInlineTag(tag, node, currentStyle) {
|
|
|
185
184
|
}
|
|
186
185
|
return currentStyle;
|
|
187
186
|
}
|
|
188
|
-
function baseProcessInlineTag(tag, node, inlineStyles = OrderedSet()) {
|
|
187
|
+
function baseProcessInlineTag(tag, node, inlineStyles = Immutable.OrderedSet()) {
|
|
189
188
|
return processInlineTag(tag, node, inlineStyles);
|
|
190
189
|
}
|
|
191
190
|
function joinChunks(A, B, flat = false) {
|
|
@@ -301,10 +300,10 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
301
300
|
blockInfo = blockInfo || {};
|
|
302
301
|
if (typeof blockInfo === 'string') {
|
|
303
302
|
blockType = blockInfo;
|
|
304
|
-
blockDataMap = Map();
|
|
303
|
+
blockDataMap = Immutable.Map();
|
|
305
304
|
} else {
|
|
306
305
|
blockType = typeof blockInfo === 'string' ? blockInfo : blockInfo.type;
|
|
307
|
-
blockDataMap = blockInfo.data ? Map(blockInfo.data) : Map();
|
|
306
|
+
blockDataMap = blockInfo.data ? Immutable.Map(blockInfo.data) : Immutable.Map();
|
|
308
307
|
}
|
|
309
308
|
if (!inBlock && (fragmentBlockTags.indexOf(nodeName) !== -1 || blockType)) {
|
|
310
309
|
chunk = getBlockDividerChunk(blockType || getBlockTypeForTag(nodeName, lastList), depth, blockDataMap);
|
|
@@ -348,10 +347,10 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
348
347
|
newBlockInfo = newBlockInfo || {};
|
|
349
348
|
if (typeof newBlockInfo === 'string') {
|
|
350
349
|
newBlockType = newBlockInfo;
|
|
351
|
-
newBlockData = Map();
|
|
350
|
+
newBlockData = Immutable.Map();
|
|
352
351
|
} else {
|
|
353
352
|
newBlockType = newBlockInfo.type || getBlockTypeForTag(nodeName, lastList);
|
|
354
|
-
newBlockData = newBlockInfo.data ? Map(newBlockInfo.data) : Map();
|
|
353
|
+
newBlockData = newBlockInfo.data ? Immutable.Map(newBlockInfo.data) : Immutable.Map();
|
|
355
354
|
}
|
|
356
355
|
chunk = joinChunks(chunk, getSoftNewlineChunk(newBlockType, depth, options.flat, newBlockData), options.flat);
|
|
357
356
|
}
|
|
@@ -362,7 +361,7 @@ function genFragment(node, inlineStyle, lastList, inBlock, fragmentBlockTags, de
|
|
|
362
361
|
child = sibling;
|
|
363
362
|
}
|
|
364
363
|
if (newBlock) {
|
|
365
|
-
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Map()), options.flat);
|
|
364
|
+
chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, Immutable.Map()), options.flat);
|
|
366
365
|
}
|
|
367
366
|
return chunk;
|
|
368
367
|
}
|
|
@@ -382,7 +381,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
382
381
|
];
|
|
383
382
|
// Start with -1 block depth to offset the fact that we are passing in a fake
|
|
384
383
|
// UL block to sta rt with.
|
|
385
|
-
let chunk = genFragment(safeBody, OrderedSet(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options);
|
|
384
|
+
let chunk = genFragment(safeBody, Immutable.OrderedSet(), 'ul', null, workingBlocks, -1, processCustomInlineStyles, checkEntityNode, checkEntityText, checkBlockType, createEntity, getEntity, mergeEntityData, replaceEntityData, options);
|
|
386
385
|
// join with previous block to prevent weirdness on paste
|
|
387
386
|
if (chunk.text.indexOf('\r') === 0) {
|
|
388
387
|
chunk = {
|
|
@@ -403,7 +402,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
403
402
|
if (chunk.blocks.length === 0) {
|
|
404
403
|
chunk.blocks.push({
|
|
405
404
|
type: 'unstyled',
|
|
406
|
-
data: Map(),
|
|
405
|
+
data: Immutable.Map(),
|
|
407
406
|
depth: 0
|
|
408
407
|
});
|
|
409
408
|
}
|
|
@@ -413,7 +412,7 @@ function getChunkForHTML(html, processCustomInlineStyles, checkEntityNode, check
|
|
|
413
412
|
if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
|
|
414
413
|
chunk.blocks.unshift({
|
|
415
414
|
type: 'unstyled',
|
|
416
|
-
data: Map(),
|
|
415
|
+
data: Immutable.Map(),
|
|
417
416
|
depth: 0
|
|
418
417
|
});
|
|
419
418
|
}
|
|
@@ -434,7 +433,7 @@ function convertFromHTMLtoContentBlocks(html, processCustomInlineStyles, checkEn
|
|
|
434
433
|
const end = start + textBlock.length;
|
|
435
434
|
const inlines = nullthrows(chunk).inlines.slice(start, end);
|
|
436
435
|
const entities = nullthrows(chunk).entities.slice(start, end);
|
|
437
|
-
const characterList = List(inlines.map((style, entityIndex)=>{
|
|
436
|
+
const characterList = Immutable.List(inlines.map((style, entityIndex)=>{
|
|
438
437
|
const data = {
|
|
439
438
|
style,
|
|
440
439
|
entity: null
|
|
@@ -8,69 +8,28 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return _default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const _draftjs = /*#__PURE__*/ _interop_require_default(require("draft-js"));
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
13
|
const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
|
|
14
|
-
const
|
|
15
|
-
const _encodeBlock = /*#__PURE__*/ _interop_require_default(require("./encodeBlock.js"));
|
|
14
|
+
const _tinyinvariant = /*#__PURE__*/ _interop_require_default(require("tiny-invariant"));
|
|
16
15
|
const _blockEntities = /*#__PURE__*/ _interop_require_default(require("./blockEntities.js"));
|
|
17
16
|
const _blockInlineStyles = /*#__PURE__*/ _interop_require_default(require("./blockInlineStyles.js"));
|
|
17
|
+
const _defaultBlockHTML = /*#__PURE__*/ _interop_require_default(require("./default/defaultBlockHTML.js"));
|
|
18
|
+
const _encodeBlock = /*#__PURE__*/ _interop_require_default(require("./encodeBlock.js"));
|
|
18
19
|
const _accumulateFunction = /*#__PURE__*/ _interop_require_default(require("./util/accumulateFunction.js"));
|
|
19
20
|
const _blockTypeObjectFunction = /*#__PURE__*/ _interop_require_default(require("./util/blockTypeObjectFunction.js"));
|
|
20
21
|
const _getBlockTags = /*#__PURE__*/ _interop_require_default(require("./util/getBlockTags.js"));
|
|
21
22
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var cacheNodeInterop = new WeakMap();
|
|
32
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
33
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
34
|
-
})(nodeInterop);
|
|
35
|
-
}
|
|
36
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
37
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
38
|
-
return obj;
|
|
39
|
-
}
|
|
40
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
41
|
-
return {
|
|
42
|
-
default: obj
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
46
|
-
if (cache && cache.has(obj)) {
|
|
47
|
-
return cache.get(obj);
|
|
48
|
-
}
|
|
49
|
-
var newObj = {
|
|
50
|
-
__proto__: null
|
|
51
|
-
};
|
|
52
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
53
|
-
for(var key in obj){
|
|
54
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
55
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
56
|
-
if (desc && (desc.get || desc.set)) {
|
|
57
|
-
Object.defineProperty(newObj, key, desc);
|
|
58
|
-
} else {
|
|
59
|
-
newObj[key] = obj[key];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
newObj.default = obj;
|
|
64
|
-
if (cache) {
|
|
65
|
-
cache.set(obj, newObj);
|
|
66
|
-
}
|
|
67
|
-
return newObj;
|
|
68
|
-
}
|
|
69
|
-
const { convertToRaw } = _draftjs;
|
|
70
|
-
const defaultEntityToHTML = (entity, originalText)=>originalText;
|
|
71
|
-
const defaultValidateHTML = (html)=>true;
|
|
28
|
+
const { convertToRaw } = _draftjs.default;
|
|
29
|
+
const defaultEntityToHTML = (_entity, originalText)=>originalText;
|
|
30
|
+
const defaultValidateHTML = (_html)=>true;
|
|
72
31
|
const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defaultEntityToHTML, validateHTML = defaultValidateHTML })=>(contentState)=>{
|
|
73
|
-
(0,
|
|
32
|
+
(0, _tinyinvariant.default)(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
|
|
74
33
|
let getBlockHTML;
|
|
75
34
|
if (blockToHTML.__isMiddleware === true) {
|
|
76
35
|
getBlockHTML = blockToHTML((0, _blockTypeObjectFunction.default)(_defaultBlockHTML.default));
|
|
@@ -117,7 +76,7 @@ const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defa
|
|
|
117
76
|
} else {
|
|
118
77
|
html = blockHTML.start + innerHTML + blockHTML.end;
|
|
119
78
|
}
|
|
120
|
-
if (innerHTML.length === 0 && Object.
|
|
79
|
+
if (innerHTML.length === 0 && Object.hasOwn(blockHTML, 'empty')) {
|
|
121
80
|
if (/*#__PURE__*/ _react.default.isValidElement(blockHTML.empty)) {
|
|
122
81
|
html = _server.default.renderToStaticMarkup(blockHTML.empty);
|
|
123
82
|
} else {
|
|
@@ -134,7 +93,7 @@ const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defa
|
|
|
134
93
|
return result;
|
|
135
94
|
};
|
|
136
95
|
const _default = (...args)=>{
|
|
137
|
-
if (args.length === 1 && Object.
|
|
96
|
+
if (args.length === 1 && Object.hasOwn(args[0], '_map') && args[0].getBlockMap != null) {
|
|
138
97
|
// skip higher-order function and use defaults
|
|
139
98
|
return convertToHTML({})(...args);
|
|
140
99
|
}
|