@20minutes/draft-convert 3.0.2 → 3.1.0

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 +58 -61
  3. package/esm/blockInlineStyles.js +64 -87
  4. package/esm/convertFromHTML.js +442 -478
  5. package/esm/convertToHTML.js +71 -93
  6. package/esm/default/defaultBlockHTML.js +33 -30
  7. package/esm/default/defaultInlineHTML.js +16 -16
  8. package/esm/encodeBlock.js +36 -40
  9. package/esm/index.js +1 -1
  10. package/esm/util/accumulateFunction.js +7 -9
  11. package/esm/util/blockTypeObjectFunction.js +7 -9
  12. package/esm/util/getBlockTags.js +19 -19
  13. package/esm/util/getElementHTML.js +24 -28
  14. package/esm/util/getElementTagLength.js +14 -16
  15. package/esm/util/getNestedBlockTags.js +20 -25
  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 +459 -487
  24. package/lib/convertToHTML.js +93 -107
  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 +31 -35
  41. package/dist/draft-convert.js +0 -440
  42. package/dist/draft-convert.min.js +0 -1
@@ -10,98 +10,76 @@ import blockTypeObjectFunction from './util/blockTypeObjectFunction';
10
10
  import getBlockTags from './util/getBlockTags';
11
11
  import getNestedBlockTags from './util/getNestedBlockTags';
12
12
  import defaultBlockHTML from './default/defaultBlockHTML';
13
- var defaultEntityToHTML = function defaultEntityToHTML(entity, originalText) {
14
- return originalText;
15
- };
16
- var defaultValidateHTML = function defaultValidateHTML(html) {
17
- return true;
18
- };
19
- var convertToHTML = function convertToHTML(_ref) {
20
- var _ref$styleToHTML = _ref.styleToHTML,
21
- styleToHTML = _ref$styleToHTML === void 0 ? {} : _ref$styleToHTML,
22
- _ref$blockToHTML = _ref.blockToHTML,
23
- blockToHTML = _ref$blockToHTML === void 0 ? {} : _ref$blockToHTML,
24
- _ref$entityToHTML = _ref.entityToHTML,
25
- entityToHTML = _ref$entityToHTML === void 0 ? defaultEntityToHTML : _ref$entityToHTML,
26
- _ref$validateHTML = _ref.validateHTML,
27
- validateHTML = _ref$validateHTML === void 0 ? defaultValidateHTML : _ref$validateHTML;
28
- return function (contentState) {
29
- invariant(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
30
- var getBlockHTML;
31
- if (blockToHTML.__isMiddleware === true) {
32
- getBlockHTML = blockToHTML(blockTypeObjectFunction(defaultBlockHTML));
33
- } else {
34
- getBlockHTML = accumulateFunction(blockTypeObjectFunction(blockToHTML), blockTypeObjectFunction(defaultBlockHTML));
35
- }
36
- var rawState = convertToRaw(contentState);
37
- var listStack = [];
38
- var result = rawState.blocks.map(function (block) {
39
- var type = block.type,
40
- depth = block.depth;
41
- var closeNestTags = '';
42
- var openNestTags = '';
43
- var blockHTMLResult = getBlockHTML(block);
44
- if (!blockHTMLResult) {
45
- throw new Error("convertToHTML: missing HTML definition for block with type ".concat(block.type));
46
- }
47
- if (!blockHTMLResult.nest) {
48
- // this block can't be nested, so reset all nesting if necessary
49
- closeNestTags = listStack.reduceRight(function (string, nestedBlock) {
50
- return string + getNestedBlockTags(getBlockHTML(nestedBlock), depth).nestEnd;
51
- }, '');
52
- listStack = [];
53
- } else {
54
- while (depth + 1 !== listStack.length || type !== listStack[depth].type) {
55
- if (depth + 1 === listStack.length) {
56
- // depth is right but doesn't match type
57
- var blockToClose = listStack[depth];
58
- closeNestTags += getNestedBlockTags(getBlockHTML(blockToClose), depth).nestEnd;
59
- openNestTags += getNestedBlockTags(getBlockHTML(block), depth).nestStart;
60
- listStack[depth] = block;
61
- } else if (depth + 1 < listStack.length) {
62
- var _blockToClose = listStack[listStack.length - 1];
63
- closeNestTags += getNestedBlockTags(getBlockHTML(_blockToClose), depth).nestEnd;
64
- listStack = listStack.slice(0, -1);
65
- } else {
66
- openNestTags += getNestedBlockTags(getBlockHTML(block), depth).nestStart;
67
- listStack.push(block);
68
- }
69
- }
70
- }
71
- var innerHTML = blockInlineStyles(blockEntities(encodeBlock(block), rawState.entityMap, entityToHTML), styleToHTML);
72
- var blockHTML = getBlockTags(getBlockHTML(block));
73
- var html;
74
- if (typeof blockHTML === 'string') {
75
- html = blockHTML;
76
- } else {
77
- html = blockHTML.start + innerHTML + blockHTML.end;
78
- }
79
- if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
80
- if (/*#__PURE__*/React.isValidElement(blockHTML.empty)) {
81
- html = ReactDOMServer.renderToStaticMarkup(blockHTML.empty);
13
+ const defaultEntityToHTML = (entity, originalText)=>originalText;
14
+ const defaultValidateHTML = (html)=>true;
15
+ const convertToHTML = ({ styleToHTML = {}, blockToHTML = {}, entityToHTML = defaultEntityToHTML, validateHTML = defaultValidateHTML })=>(contentState)=>{
16
+ invariant(contentState !== null && contentState !== undefined, 'Expected contentState to be non-null');
17
+ let getBlockHTML;
18
+ if (blockToHTML.__isMiddleware === true) {
19
+ getBlockHTML = blockToHTML(blockTypeObjectFunction(defaultBlockHTML));
82
20
  } else {
83
- html = blockHTML.empty;
21
+ getBlockHTML = accumulateFunction(blockTypeObjectFunction(blockToHTML), blockTypeObjectFunction(defaultBlockHTML));
84
22
  }
85
- }
86
- var finalHtml = closeNestTags + openNestTags + html;
87
- if (!validateHTML(finalHtml)) {
88
- return '';
89
- }
90
- return finalHtml;
91
- }).join('');
92
- result = listStack.reduce(function (res, nestBlock) {
93
- return res + getNestedBlockTags(getBlockHTML(nestBlock), nestBlock.depth).nestEnd;
94
- }, result);
95
- return result;
96
- };
97
- };
98
- export default (function () {
99
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
100
- args[_key] = arguments[_key];
101
- }
102
- if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
103
- // skip higher-order function and use defaults
104
- return convertToHTML({}).apply(void 0, args);
105
- }
106
- return convertToHTML.apply(void 0, args);
107
- });
23
+ const rawState = convertToRaw(contentState);
24
+ let listStack = [];
25
+ let result = rawState.blocks.map((block)=>{
26
+ const { type, depth } = block;
27
+ let closeNestTags = '';
28
+ let openNestTags = '';
29
+ const blockHTMLResult = getBlockHTML(block);
30
+ if (!blockHTMLResult) {
31
+ throw new Error(`convertToHTML: missing HTML definition for block with type ${block.type}`);
32
+ }
33
+ if (!blockHTMLResult.nest) {
34
+ // this block can't be nested, so reset all nesting if necessary
35
+ closeNestTags = listStack.reduceRight((string, nestedBlock)=>string + getNestedBlockTags(getBlockHTML(nestedBlock), depth).nestEnd, '');
36
+ listStack = [];
37
+ } else {
38
+ while(depth + 1 !== listStack.length || type !== listStack[depth].type){
39
+ if (depth + 1 === listStack.length) {
40
+ // depth is right but doesn't match type
41
+ const blockToClose = listStack[depth];
42
+ closeNestTags += getNestedBlockTags(getBlockHTML(blockToClose), depth).nestEnd;
43
+ openNestTags += getNestedBlockTags(getBlockHTML(block), depth).nestStart;
44
+ listStack[depth] = block;
45
+ } else if (depth + 1 < listStack.length) {
46
+ const blockToClose = listStack[listStack.length - 1];
47
+ closeNestTags += getNestedBlockTags(getBlockHTML(blockToClose), depth).nestEnd;
48
+ listStack = listStack.slice(0, -1);
49
+ } else {
50
+ openNestTags += getNestedBlockTags(getBlockHTML(block), depth).nestStart;
51
+ listStack.push(block);
52
+ }
53
+ }
54
+ }
55
+ const innerHTML = blockInlineStyles(blockEntities(encodeBlock(block), rawState.entityMap, entityToHTML), styleToHTML);
56
+ const blockHTML = getBlockTags(getBlockHTML(block));
57
+ let html;
58
+ if (typeof blockHTML === 'string') {
59
+ html = blockHTML;
60
+ } else {
61
+ html = blockHTML.start + innerHTML + blockHTML.end;
62
+ }
63
+ if (innerHTML.length === 0 && Object.prototype.hasOwnProperty.call(blockHTML, 'empty')) {
64
+ if (/*#__PURE__*/ React.isValidElement(blockHTML.empty)) {
65
+ html = ReactDOMServer.renderToStaticMarkup(blockHTML.empty);
66
+ } else {
67
+ html = blockHTML.empty;
68
+ }
69
+ }
70
+ const finalHtml = closeNestTags + openNestTags + html;
71
+ if (!validateHTML(finalHtml)) {
72
+ return '';
73
+ }
74
+ return finalHtml;
75
+ }).join('');
76
+ result = listStack.reduce((res, nestBlock)=>res + getNestedBlockTags(getBlockHTML(nestBlock), nestBlock.depth).nestEnd, result);
77
+ return result;
78
+ };
79
+ export default ((...args)=>{
80
+ if (args.length === 1 && Object.prototype.hasOwnProperty.call(args[0], '_map') && args[0].getBlockMap != null) {
81
+ // skip higher-order function and use defaults
82
+ return convertToHTML({})(...args);
83
+ }
84
+ return convertToHTML(...args);
85
+ });
@@ -1,33 +1,36 @@
1
1
  import React from 'react';
2
-
3
2
  // based on Draft.js' custom list depth styling
4
- var ORDERED_LIST_TYPES = ['1', 'a', 'i'];
3
+ const ORDERED_LIST_TYPES = [
4
+ '1',
5
+ 'a',
6
+ 'i'
7
+ ];
5
8
  export default {
6
- unstyled: /*#__PURE__*/React.createElement("p", null),
7
- paragraph: /*#__PURE__*/React.createElement("p", null),
8
- 'header-one': /*#__PURE__*/React.createElement("h1", null),
9
- 'header-two': /*#__PURE__*/React.createElement("h2", null),
10
- 'header-two-unordered': /*#__PURE__*/React.createElement("h2", null),
11
- 'header-two-ordered': /*#__PURE__*/React.createElement("h2", null),
12
- 'header-three': /*#__PURE__*/React.createElement("h3", null),
13
- 'header-four': /*#__PURE__*/React.createElement("h4", null),
14
- 'header-five': /*#__PURE__*/React.createElement("h5", null),
15
- 'header-six': /*#__PURE__*/React.createElement("h6", null),
16
- 'code-block': /*#__PURE__*/React.createElement("pre", null),
17
- blockquote: /*#__PURE__*/React.createElement("blockquote", null),
18
- 'unordered-list-item': {
19
- element: /*#__PURE__*/React.createElement("li", null),
20
- nest: /*#__PURE__*/React.createElement("ul", null)
21
- },
22
- 'ordered-list-item': {
23
- element: /*#__PURE__*/React.createElement("li", null),
24
- nest: function nest(depth) {
25
- var type = ORDERED_LIST_TYPES[depth % 3];
26
- return /*#__PURE__*/React.createElement("ol", {
27
- type: type
28
- });
29
- }
30
- },
31
- media: /*#__PURE__*/React.createElement("figure", null),
32
- atomic: /*#__PURE__*/React.createElement("figure", null)
33
- };
9
+ unstyled: /*#__PURE__*/ React.createElement("p", null),
10
+ paragraph: /*#__PURE__*/ React.createElement("p", null),
11
+ 'header-one': /*#__PURE__*/ React.createElement("h1", null),
12
+ 'header-two': /*#__PURE__*/ React.createElement("h2", null),
13
+ 'header-two-unordered': /*#__PURE__*/ React.createElement("h2", null),
14
+ 'header-two-ordered': /*#__PURE__*/ React.createElement("h2", null),
15
+ 'header-three': /*#__PURE__*/ React.createElement("h3", null),
16
+ 'header-four': /*#__PURE__*/ React.createElement("h4", null),
17
+ 'header-five': /*#__PURE__*/ React.createElement("h5", null),
18
+ 'header-six': /*#__PURE__*/ React.createElement("h6", null),
19
+ 'code-block': /*#__PURE__*/ React.createElement("pre", null),
20
+ blockquote: /*#__PURE__*/ React.createElement("blockquote", null),
21
+ 'unordered-list-item': {
22
+ element: /*#__PURE__*/ React.createElement("li", null),
23
+ nest: /*#__PURE__*/ React.createElement("ul", null)
24
+ },
25
+ 'ordered-list-item': {
26
+ element: /*#__PURE__*/ React.createElement("li", null),
27
+ nest: (depth)=>{
28
+ const type = ORDERED_LIST_TYPES[depth % 3];
29
+ return /*#__PURE__*/ React.createElement("ol", {
30
+ type: type
31
+ });
32
+ }
33
+ },
34
+ media: /*#__PURE__*/ React.createElement("figure", null),
35
+ atomic: /*#__PURE__*/ React.createElement("figure", null)
36
+ };
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
2
  export default function defaultInlineHTML(style) {
3
- switch (style) {
4
- case 'BOLD':
5
- return /*#__PURE__*/React.createElement("strong", null);
6
- case 'ITALIC':
7
- return /*#__PURE__*/React.createElement("em", null);
8
- case 'UNDERLINE':
9
- return /*#__PURE__*/React.createElement("u", null);
10
- case 'CODE':
11
- return /*#__PURE__*/React.createElement("code", null);
12
- default:
13
- return {
14
- start: '',
15
- end: ''
16
- };
17
- }
18
- }
3
+ switch(style){
4
+ case 'BOLD':
5
+ return /*#__PURE__*/ React.createElement("strong", null);
6
+ case 'ITALIC':
7
+ return /*#__PURE__*/ React.createElement("em", null);
8
+ case 'UNDERLINE':
9
+ return /*#__PURE__*/ React.createElement("u", null);
10
+ case 'CODE':
11
+ return /*#__PURE__*/ React.createElement("code", null);
12
+ default:
13
+ return {
14
+ start: '',
15
+ end: ''
16
+ };
17
+ }
18
+ }
@@ -1,44 +1,40 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
1
  import updateMutation from './util/updateMutation';
6
2
  import rangeSort from './util/rangeSort';
7
- var ENTITY_MAP = {
8
- '&': '&amp;',
9
- '<': '&lt;',
10
- '>': '&gt;',
11
- '"': '&quot;',
12
- "'": '&#x27;',
13
- '`': '&#x60;',
14
- '\n': '<br/>'
3
+ const ENTITY_MAP = {
4
+ '&': '&amp;',
5
+ '<': '&lt;',
6
+ '>': '&gt;',
7
+ '"': '&quot;',
8
+ "'": '&#x27;',
9
+ '`': '&#x60;',
10
+ '\n': '<br/>'
15
11
  };
16
- export default (function (block) {
17
- var blockText = _toConsumableArray(block.text);
18
- var entities = block.entityRanges.sort(rangeSort);
19
- var styles = block.inlineStyleRanges.sort(rangeSort);
20
- var resultText = '';
21
- var _loop = function _loop() {
22
- var _char = blockText[index];
23
- if (ENTITY_MAP[_char] !== undefined) {
24
- var encoded = ENTITY_MAP[_char];
25
- var resultIndex = _toConsumableArray(resultText).length;
26
- resultText += encoded;
27
- var updateForChar = function updateForChar(mutation) {
28
- return updateMutation(mutation, resultIndex, _char.length, encoded.length, 0, 0);
29
- };
30
- entities = entities.map(updateForChar);
31
- styles = styles.map(updateForChar);
32
- } else {
33
- resultText += _char;
12
+ export default ((block)=>{
13
+ const blockText = [
14
+ ...block.text
15
+ ];
16
+ let entities = block.entityRanges.sort(rangeSort);
17
+ let styles = block.inlineStyleRanges.sort(rangeSort);
18
+ let resultText = '';
19
+ for(let index = 0; index < blockText.length; index += 1){
20
+ const char = blockText[index];
21
+ if (ENTITY_MAP[char] !== undefined) {
22
+ const encoded = ENTITY_MAP[char];
23
+ const resultIndex = [
24
+ ...resultText
25
+ ].length;
26
+ resultText += encoded;
27
+ const updateForChar = (mutation)=>updateMutation(mutation, resultIndex, char.length, encoded.length, 0, 0);
28
+ entities = entities.map(updateForChar);
29
+ styles = styles.map(updateForChar);
30
+ } else {
31
+ resultText += char;
32
+ }
34
33
  }
35
- };
36
- for (var index = 0; index < blockText.length; index += 1) {
37
- _loop();
38
- }
39
- return _objectSpread(_objectSpread({}, block), {}, {
40
- text: resultText,
41
- inlineStyleRanges: styles,
42
- entityRanges: entities
43
- });
44
- });
34
+ return {
35
+ ...block,
36
+ text: resultText,
37
+ inlineStyleRanges: styles,
38
+ entityRanges: entities
39
+ };
40
+ });
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import convertToHTML from './convertToHTML';
2
2
  import convertFromHTML from './convertFromHTML';
3
3
  import parseHTML from './util/parseHTML';
4
- export { convertToHTML, convertFromHTML, parseHTML };
4
+ export { convertToHTML, convertFromHTML, parseHTML };
@@ -1,9 +1,7 @@
1
- export default (function (newFn, rest) {
2
- return function () {
3
- var newResult = newFn.apply(void 0, arguments);
4
- if (newResult !== undefined && newResult !== null) {
5
- return newResult;
6
- }
7
- return rest.apply(void 0, arguments);
8
- };
9
- });
1
+ export default ((newFn, rest)=>(...args)=>{
2
+ const newResult = newFn(...args);
3
+ if (newResult !== undefined && newResult !== null) {
4
+ return newResult;
5
+ }
6
+ return rest(...args);
7
+ });
@@ -1,9 +1,7 @@
1
- export default (function (typeObject) {
2
- return function (block) {
3
- if (typeof typeObject === 'function') {
4
- // handle case where typeObject is already a function
5
- return typeObject(block);
6
- }
7
- return typeObject[block.type];
8
- };
9
- });
1
+ export default ((typeObject)=>(block)=>{
2
+ if (typeof typeObject === 'function') {
3
+ // handle case where typeObject is already a function
4
+ return typeObject(block);
5
+ }
6
+ return typeObject[block.type];
7
+ });
@@ -1,27 +1,27 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
1
  import invariant from 'invariant';
5
2
  import React from 'react';
6
3
  import ReactDOMServer from 'react-dom/server';
7
4
  import splitReactElement from './splitReactElement';
8
5
  function hasChildren(element) {
9
- return /*#__PURE__*/React.isValidElement(element) && React.Children.count(element.props.children) > 0;
6
+ return /*#__PURE__*/ React.isValidElement(element) && React.Children.count(element.props.children) > 0;
10
7
  }
11
8
  export default function getBlockTags(blockHTML) {
12
- invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
13
- if (typeof blockHTML === 'string') {
14
- return blockHTML;
15
- }
16
- if (/*#__PURE__*/React.isValidElement(blockHTML)) {
17
- if (hasChildren(blockHTML)) {
18
- return ReactDOMServer.renderToStaticMarkup(blockHTML);
9
+ invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
10
+ if (typeof blockHTML === 'string') {
11
+ return blockHTML;
12
+ }
13
+ if (/*#__PURE__*/ React.isValidElement(blockHTML)) {
14
+ if (hasChildren(blockHTML)) {
15
+ return ReactDOMServer.renderToStaticMarkup(blockHTML);
16
+ }
17
+ return splitReactElement(blockHTML);
18
+ }
19
+ if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && /*#__PURE__*/ React.isValidElement(blockHTML.element)) {
20
+ return {
21
+ ...blockHTML,
22
+ ...splitReactElement(blockHTML.element)
23
+ };
19
24
  }
20
- return splitReactElement(blockHTML);
21
- }
22
- if (Object.prototype.hasOwnProperty.call(blockHTML, 'element') && /*#__PURE__*/React.isValidElement(blockHTML.element)) {
23
- return _objectSpread(_objectSpread({}, blockHTML), splitReactElement(blockHTML.element));
24
- }
25
- invariant(Object.prototype.hasOwnProperty.call(blockHTML, 'start') && Object.prototype.hasOwnProperty.call(blockHTML, 'end'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
26
- return blockHTML;
27
- }
25
+ invariant(Object.prototype.hasOwnProperty.call(blockHTML, 'start') && Object.prototype.hasOwnProperty.call(blockHTML, 'end'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
26
+ return blockHTML;
27
+ }
@@ -1,36 +1,32 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
1
  import invariant from 'invariant';
3
2
  import React from 'react';
4
3
  import ReactDOMServer from 'react-dom/server';
5
4
  import splitReactElement from './splitReactElement';
6
5
  function hasChildren(element) {
7
- return /*#__PURE__*/React.isValidElement(element) && React.Children.count(element.props.children) > 0;
6
+ return /*#__PURE__*/ React.isValidElement(element) && React.Children.count(element.props.children) > 0;
8
7
  }
9
- export default function getElementHTML(element) {
10
- var text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
11
- if (element === undefined || element === null) {
12
- return element;
13
- }
14
- if (typeof element === 'string') {
15
- return element;
16
- }
17
- if (/*#__PURE__*/React.isValidElement(element)) {
18
- if (hasChildren(element)) {
19
- return ReactDOMServer.renderToStaticMarkup(element);
8
+ export default function getElementHTML(element, text = null) {
9
+ if (element === undefined || element === null) {
10
+ return element;
11
+ }
12
+ if (typeof element === 'string') {
13
+ return element;
20
14
  }
21
- var tags = splitReactElement(element);
22
- if (text !== null && _typeof(tags) === 'object') {
23
- var start = tags.start,
24
- end = tags.end;
25
- return start + text + end;
15
+ if (/*#__PURE__*/ React.isValidElement(element)) {
16
+ if (hasChildren(element)) {
17
+ return ReactDOMServer.renderToStaticMarkup(element);
18
+ }
19
+ const tags = splitReactElement(element);
20
+ if (text !== null && typeof tags === 'object') {
21
+ const { start, end } = tags;
22
+ return start + text + end;
23
+ }
24
+ return tags;
26
25
  }
27
- return tags;
28
- }
29
- invariant(Object.prototype.hasOwnProperty.call(element, 'start') && Object.prototype.hasOwnProperty.call(element, 'end'), 'convertToHTML: received conversion data without either an HTML string, ReactElement or an object with start/end tags');
30
- if (text !== null) {
31
- var _start = element.start,
32
- _end = element.end;
33
- return _start + text + _end;
34
- }
35
- return element;
36
- }
26
+ invariant(Object.prototype.hasOwnProperty.call(element, 'start') && Object.prototype.hasOwnProperty.call(element, 'end'), 'convertToHTML: received conversion data without either an HTML string, ReactElement or an object with start/end tags');
27
+ if (text !== null) {
28
+ const { start, end } = element;
29
+ return start + text + end;
30
+ }
31
+ return element;
32
+ }
@@ -1,20 +1,18 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
1
  import React from 'react';
3
2
  import splitReactElement from './splitReactElement';
4
- var _getElementTagLength = function getElementTagLength(element) {
5
- var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
6
- if (/*#__PURE__*/React.isValidElement(element)) {
7
- var splitElement = splitReactElement(element);
8
- if (typeof splitElement === 'string') {
9
- return 0;
3
+ const getElementTagLength = (element, type = 'start')=>{
4
+ if (/*#__PURE__*/ React.isValidElement(element)) {
5
+ const splitElement = splitReactElement(element);
6
+ if (typeof splitElement === 'string') {
7
+ return 0;
8
+ }
9
+ const { length } = splitElement[type];
10
+ const child = React.Children.toArray(element.props.children)[0];
11
+ return length + (child && /*#__PURE__*/ React.isValidElement(child) ? getElementTagLength(child, type) : 0);
10
12
  }
11
- var length = splitElement[type].length;
12
- var child = React.Children.toArray(element.props.children)[0];
13
- return length + (child && /*#__PURE__*/React.isValidElement(child) ? _getElementTagLength(child, type) : 0);
14
- }
15
- if (_typeof(element) === 'object') {
16
- return element[type] ? element[type].length : 0;
17
- }
18
- return 0;
13
+ if (typeof element === 'object') {
14
+ return element[type] ? element[type].length : 0;
15
+ }
16
+ return 0;
19
17
  };
20
- export default _getElementTagLength;
18
+ export default getElementTagLength;
@@ -1,29 +1,24 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
1
  import invariant from 'invariant';
5
2
  import React from 'react';
6
3
  import splitReactElement from './splitReactElement';
7
4
  export default function getNestedBlockTags(blockHTML, depth) {
8
- invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
9
- if (typeof blockHTML.nest === 'function') {
10
- var _splitReactElement = splitReactElement(blockHTML.nest(depth)),
11
- start = _splitReactElement.start,
12
- end = _splitReactElement.end;
13
- return _objectSpread(_objectSpread({}, blockHTML), {}, {
14
- nestStart: start,
15
- nestEnd: end
16
- });
17
- }
18
- if (/*#__PURE__*/React.isValidElement(blockHTML.nest)) {
19
- var _splitReactElement2 = splitReactElement(blockHTML.nest),
20
- _start = _splitReactElement2.start,
21
- _end = _splitReactElement2.end;
22
- return _objectSpread(_objectSpread({}, blockHTML), {}, {
23
- nestStart: _start,
24
- nestEnd: _end
25
- });
26
- }
27
- invariant(Object.prototype.hasOwnProperty.call(blockHTML, 'nestStart') && Object.prototype.hasOwnProperty.call(blockHTML, 'nestEnd'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
28
- return blockHTML;
29
- }
5
+ invariant(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
6
+ if (typeof blockHTML.nest === 'function') {
7
+ const { start, end } = splitReactElement(blockHTML.nest(depth));
8
+ return {
9
+ ...blockHTML,
10
+ nestStart: start,
11
+ nestEnd: end
12
+ };
13
+ }
14
+ if (/*#__PURE__*/ React.isValidElement(blockHTML.nest)) {
15
+ const { start, end } = splitReactElement(blockHTML.nest);
16
+ return {
17
+ ...blockHTML,
18
+ nestStart: start,
19
+ nestEnd: end
20
+ };
21
+ }
22
+ invariant(Object.prototype.hasOwnProperty.call(blockHTML, 'nestStart') && Object.prototype.hasOwnProperty.call(blockHTML, 'nestEnd'), 'convertToHTML: received block information without either a ReactElement or an object with start/end tags');
23
+ return blockHTML;
24
+ }
@@ -1,18 +1,18 @@
1
- var fallback = function fallback(html) {
2
- var doc = document.implementation.createHTMLDocument('');
3
- doc.documentElement.innerHTML = html;
4
- return doc;
1
+ const fallback = (html)=>{
2
+ const doc = document.implementation.createHTMLDocument('');
3
+ doc.documentElement.innerHTML = html;
4
+ return doc;
5
5
  };
6
6
  export default function parseHTML(html) {
7
- var doc;
8
- if (typeof DOMParser !== 'undefined') {
9
- var parser = new DOMParser();
10
- doc = parser.parseFromString(html, 'text/html');
11
- if (doc === null || doc.body === null) {
12
- doc = fallback(html);
7
+ let doc;
8
+ if (typeof DOMParser !== 'undefined') {
9
+ const parser = new DOMParser();
10
+ doc = parser.parseFromString(html, 'text/html');
11
+ if (doc === null || doc.body === null) {
12
+ doc = fallback(html);
13
+ }
14
+ } else {
15
+ doc = fallback(html);
13
16
  }
14
- } else {
15
- doc = fallback(html);
16
- }
17
- return doc.body;
18
- }
17
+ return doc.body;
18
+ }