@20minutes/draft-convert 3.0.3 → 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.
- package/README.md +2 -3
- package/esm/blockEntities.js +58 -61
- package/esm/blockInlineStyles.js +64 -87
- package/esm/convertFromHTML.js +442 -478
- package/esm/convertToHTML.js +71 -93
- package/esm/default/defaultBlockHTML.js +33 -30
- package/esm/default/defaultInlineHTML.js +16 -16
- package/esm/encodeBlock.js +36 -40
- package/esm/index.js +1 -1
- package/esm/util/accumulateFunction.js +7 -9
- package/esm/util/blockTypeObjectFunction.js +7 -9
- package/esm/util/getBlockTags.js +19 -19
- package/esm/util/getElementHTML.js +24 -28
- package/esm/util/getElementTagLength.js +14 -16
- package/esm/util/getNestedBlockTags.js +20 -25
- package/esm/util/parseHTML.js +15 -15
- package/esm/util/rangeSort.js +6 -6
- package/esm/util/splitReactElement.js +27 -13
- package/esm/util/styleObjectFunction.js +6 -8
- package/esm/util/updateMutation.js +57 -47
- package/lib/blockEntities.js +74 -69
- package/lib/blockInlineStyles.js +81 -96
- package/lib/convertFromHTML.js +459 -487
- package/lib/convertToHTML.js +93 -107
- package/lib/default/defaultBlockHTML.js +47 -35
- package/lib/default/defaultInlineHTML.js +29 -21
- package/lib/encodeBlock.js +50 -46
- package/lib/index.js +25 -23
- package/lib/util/accumulateFunction.js +13 -11
- package/lib/util/blockTypeObjectFunction.js +13 -11
- package/lib/util/getBlockTags.js +35 -27
- package/lib/util/getElementHTML.js +40 -36
- package/lib/util/getElementTagLength.js +28 -22
- package/lib/util/getNestedBlockTags.js +35 -32
- package/lib/util/parseHTML.js +22 -18
- package/lib/util/rangeSort.js +13 -9
- package/lib/util/splitReactElement.js +42 -19
- package/lib/util/styleObjectFunction.js +12 -10
- package/lib/util/updateMutation.js +64 -51
- package/package.json +24 -28
- package/dist/draft-convert.js +0 -440
- package/dist/draft-convert.min.js +0 -1
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
|
|
3
|
+
value: true
|
|
6
4
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getElementHTML;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
|
+
const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
|
|
14
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
13
20
|
function hasChildren(element) {
|
|
14
|
-
|
|
21
|
+
return /*#__PURE__*/ _react.default.isValidElement(element) && _react.default.Children.count(element.props.children) > 0;
|
|
15
22
|
}
|
|
16
|
-
function getElementHTML(element) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return element;
|
|
20
|
-
}
|
|
21
|
-
if (typeof element === 'string') {
|
|
22
|
-
return element;
|
|
23
|
-
}
|
|
24
|
-
if (/*#__PURE__*/_react["default"].isValidElement(element)) {
|
|
25
|
-
if (hasChildren(element)) {
|
|
26
|
-
return _server["default"].renderToStaticMarkup(element);
|
|
23
|
+
function getElementHTML(element, text = null) {
|
|
24
|
+
if (element === undefined || element === null) {
|
|
25
|
+
return element;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var start = tags.start,
|
|
31
|
-
end = tags.end;
|
|
32
|
-
return start + text + end;
|
|
27
|
+
if (typeof element === 'string') {
|
|
28
|
+
return element;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
if (/*#__PURE__*/ _react.default.isValidElement(element)) {
|
|
31
|
+
if (hasChildren(element)) {
|
|
32
|
+
return _server.default.renderToStaticMarkup(element);
|
|
33
|
+
}
|
|
34
|
+
const tags = (0, _splitReactElement.default)(element);
|
|
35
|
+
if (text !== null && typeof tags === 'object') {
|
|
36
|
+
const { start, end } = tags;
|
|
37
|
+
return start + text + end;
|
|
38
|
+
}
|
|
39
|
+
return tags;
|
|
40
|
+
}
|
|
41
|
+
(0, _invariant.default)(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');
|
|
42
|
+
if (text !== null) {
|
|
43
|
+
const { start, end } = element;
|
|
44
|
+
return start + text + end;
|
|
45
|
+
}
|
|
46
|
+
return element;
|
|
47
|
+
}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
|
|
3
|
+
value: true
|
|
6
4
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _getElementTagLength = function getElementTagLength(element) {
|
|
12
|
-
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'start';
|
|
13
|
-
if (/*#__PURE__*/_react["default"].isValidElement(element)) {
|
|
14
|
-
var splitElement = (0, _splitReactElement["default"])(element);
|
|
15
|
-
if (typeof splitElement === 'string') {
|
|
16
|
-
return 0;
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
17
9
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
});
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
12
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const getElementTagLength = (element, type = 'start')=>{
|
|
19
|
+
if (/*#__PURE__*/ _react.default.isValidElement(element)) {
|
|
20
|
+
const splitElement = (0, _splitReactElement.default)(element);
|
|
21
|
+
if (typeof splitElement === 'string') {
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
const { length } = splitElement[type];
|
|
25
|
+
const child = _react.default.Children.toArray(element.props.children)[0];
|
|
26
|
+
return length + (child && /*#__PURE__*/ _react.default.isValidElement(child) ? getElementTagLength(child, type) : 0);
|
|
27
|
+
}
|
|
28
|
+
if (typeof element === 'object') {
|
|
29
|
+
return element[type] ? element[type].length : 0;
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
26
32
|
};
|
|
27
|
-
|
|
33
|
+
const _default = getElementTagLength;
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
|
|
3
|
+
value: true
|
|
6
4
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getNestedBlockTags;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
|
+
const _splitReactElement = /*#__PURE__*/ _interop_require_default(require("./splitReactElement"));
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
14
19
|
function getNestedBlockTags(blockHTML, depth) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return blockHTML;
|
|
36
|
-
}
|
|
20
|
+
(0, _invariant.default)(blockHTML !== null && blockHTML !== undefined, 'Expected block HTML value to be non-null');
|
|
21
|
+
if (typeof blockHTML.nest === 'function') {
|
|
22
|
+
const { start, end } = (0, _splitReactElement.default)(blockHTML.nest(depth));
|
|
23
|
+
return {
|
|
24
|
+
...blockHTML,
|
|
25
|
+
nestStart: start,
|
|
26
|
+
nestEnd: end
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (/*#__PURE__*/ _react.default.isValidElement(blockHTML.nest)) {
|
|
30
|
+
const { start, end } = (0, _splitReactElement.default)(blockHTML.nest);
|
|
31
|
+
return {
|
|
32
|
+
...blockHTML,
|
|
33
|
+
nestStart: start,
|
|
34
|
+
nestEnd: end
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
(0, _invariant.default)(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');
|
|
38
|
+
return blockHTML;
|
|
39
|
+
}
|
package/lib/util/parseHTML.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parseHTML;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const fallback = (html)=>{
|
|
12
|
+
const doc = document.implementation.createHTMLDocument('');
|
|
13
|
+
doc.documentElement.innerHTML = html;
|
|
14
|
+
return doc;
|
|
11
15
|
};
|
|
12
16
|
function parseHTML(html) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
let doc;
|
|
18
|
+
if (typeof DOMParser !== 'undefined') {
|
|
19
|
+
const parser = new DOMParser();
|
|
20
|
+
doc = parser.parseFromString(html, 'text/html');
|
|
21
|
+
if (doc === null || doc.body === null) {
|
|
22
|
+
doc = fallback(html);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
doc = fallback(html);
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return doc.body;
|
|
24
|
-
}
|
|
27
|
+
return doc.body;
|
|
28
|
+
}
|
package/lib/util/rangeSort.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _default = (r1, r2)=>{
|
|
12
|
+
if (r1.offset === r2.offset) {
|
|
13
|
+
return r2.length - r1.length;
|
|
14
|
+
}
|
|
15
|
+
return r1.offset - r2.offset;
|
|
16
|
+
};
|
|
@@ -1,24 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
|
|
3
|
+
value: true
|
|
6
4
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return splitReactElement;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _invariant = /*#__PURE__*/ _interop_require_default(require("invariant"));
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
13
|
+
const _server = /*#__PURE__*/ _interop_require_default(require("react-dom/server"));
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
11
19
|
// see http://w3c.github.io/html/syntax.html#writing-html-documents-elements
|
|
12
|
-
|
|
20
|
+
const VOID_TAGS = [
|
|
21
|
+
'area',
|
|
22
|
+
'base',
|
|
23
|
+
'br',
|
|
24
|
+
'col',
|
|
25
|
+
'embed',
|
|
26
|
+
'hr',
|
|
27
|
+
'img',
|
|
28
|
+
'input',
|
|
29
|
+
'link',
|
|
30
|
+
'meta',
|
|
31
|
+
'param',
|
|
32
|
+
'source',
|
|
33
|
+
'track',
|
|
34
|
+
'wbr'
|
|
35
|
+
];
|
|
13
36
|
function splitReactElement(element) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
37
|
+
if (VOID_TAGS.indexOf(element.type) !== -1) {
|
|
38
|
+
return _server.default.renderToStaticMarkup(element);
|
|
39
|
+
}
|
|
40
|
+
const tags = _server.default.renderToStaticMarkup(/*#__PURE__*/ _react.default.cloneElement(element, {}, '\r')).split('\r');
|
|
41
|
+
(0, _invariant.default)(tags.length > 1, `convertToHTML: Element of type ${element.type} must render children`);
|
|
42
|
+
(0, _invariant.default)(tags.length < 3, `convertToHTML: Element of type ${element.type} cannot use carriage return character`);
|
|
43
|
+
return {
|
|
44
|
+
start: tags[0],
|
|
45
|
+
end: tags[1]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return object(style);
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
});
|
|
11
|
+
const _default = (object)=>(style)=>{
|
|
12
|
+
if (typeof object === 'function') {
|
|
13
|
+
return object(style);
|
|
14
|
+
}
|
|
15
|
+
return object[style];
|
|
16
|
+
};
|
|
@@ -1,55 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return updateMutation;
|
|
9
|
+
}
|
|
6
10
|
});
|
|
7
|
-
exports["default"] = updateMutation;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
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; }
|
|
10
|
-
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) { (0, _defineProperty2["default"])(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; }
|
|
11
11
|
function updateMutation(mutation, originalOffset, originalLength, newLength, prefixLength, suffixLength) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
12
|
+
// three cases we can reasonably adjust - disjoint mutations that
|
|
13
|
+
// happen later on where the offset will need to be changed,
|
|
14
|
+
// mutations that completely contain the new one where we can adjust
|
|
15
|
+
// the length, and mutations that occur partially within the new one.
|
|
16
|
+
const lengthDiff = newLength - originalLength;
|
|
17
|
+
const mutationAfterChange = originalOffset + originalLength <= mutation.offset;
|
|
18
|
+
if (mutationAfterChange) {
|
|
19
|
+
return {
|
|
20
|
+
...mutation,
|
|
21
|
+
offset: mutation.offset + lengthDiff
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const mutationContainsChange = originalOffset >= mutation.offset && originalOffset + originalLength <= mutation.offset + mutation.length;
|
|
25
|
+
if (mutationContainsChange) {
|
|
26
|
+
return {
|
|
27
|
+
...mutation,
|
|
28
|
+
length: mutation.length + lengthDiff
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const mutationWithinPrefixChange = mutation.offset >= originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && prefixLength > 0;
|
|
32
|
+
if (mutationWithinPrefixChange) {
|
|
33
|
+
return {
|
|
34
|
+
...mutation,
|
|
35
|
+
offset: mutation.offset + prefixLength
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const mutationContainsPrefix = mutation.offset < originalOffset && mutation.offset + mutation.length <= originalOffset + originalLength && mutation.offset + mutation.length > originalOffset && prefixLength > 0;
|
|
39
|
+
if (mutationContainsPrefix) {
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
...mutation,
|
|
43
|
+
length: originalOffset - mutation.offset
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
...mutation,
|
|
47
|
+
offset: originalOffset + prefixLength,
|
|
48
|
+
length: mutation.offset - originalOffset + mutation.length
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
const mutationContainsSuffix = mutation.offset >= originalOffset && mutation.offset + mutation.length > originalOffset + originalLength && originalOffset + originalLength > mutation.offset && suffixLength > 0;
|
|
53
|
+
if (mutationContainsSuffix) {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
...mutation,
|
|
57
|
+
offset: mutation.offset + prefixLength,
|
|
58
|
+
length: originalOffset + originalLength - mutation.offset
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
...mutation,
|
|
62
|
+
offset: originalOffset + originalLength + prefixLength + suffixLength,
|
|
63
|
+
length: mutation.offset + mutation.length - (originalOffset + originalLength)
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
return mutation;
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@20minutes/draft-convert",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Extensibly serialize & deserialize Draft.js ContentState",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"module": "esm/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"require": "./lib/index.js",
|
|
12
|
+
"import": "./esm/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"repository": "20minutes/draft-convert",
|
|
9
16
|
"scripts": {
|
|
10
|
-
"build": "yarn build:cjs && yarn build:esm
|
|
11
|
-
"build:cjs": "
|
|
12
|
-
"build:esm": "
|
|
13
|
-
"build:umd": "wp",
|
|
17
|
+
"build": "yarn build:cjs && yarn build:esm",
|
|
18
|
+
"build:cjs": "swc src -d lib --config-file .swcrc.cjs --strip-leading-paths --delete-dir-on-start",
|
|
19
|
+
"build:esm": "swc src -d esm --config-file .swcrc.esm --strip-leading-paths --delete-dir-on-start",
|
|
14
20
|
"test": "jest",
|
|
15
21
|
"test:watch": "jest --watch",
|
|
16
|
-
"clean": "rimraf ./
|
|
17
|
-
"build-and-test": "yarn clean && yarn
|
|
22
|
+
"clean": "rimraf ./lib ./esm",
|
|
23
|
+
"build-and-test": "yarn clean && yarn test",
|
|
18
24
|
"lint": "eslint src/ test/"
|
|
19
25
|
},
|
|
20
26
|
"files": [
|
|
21
27
|
"types",
|
|
22
|
-
"dist",
|
|
23
28
|
"lib",
|
|
24
29
|
"esm"
|
|
25
30
|
],
|
|
@@ -31,44 +36,35 @@
|
|
|
31
36
|
],
|
|
32
37
|
"author": "bbriggs@hubspot.com",
|
|
33
38
|
"license": "Apache-2.0",
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22"
|
|
41
|
+
},
|
|
34
42
|
"peerDependencies": {
|
|
35
43
|
"draft-js": ">=0.7.0",
|
|
36
44
|
"react": "^15.0.2 || ^16.0.0-rc || ^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
37
45
|
"react-dom": "^15.0.2 || ^16.0.0-rc || ^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
38
46
|
},
|
|
39
47
|
"dependencies": {
|
|
40
|
-
"
|
|
41
|
-
"immutable": "~3.7.4",
|
|
48
|
+
"immutable": "~5.1.4",
|
|
42
49
|
"invariant": "^2.2.1"
|
|
43
50
|
},
|
|
44
51
|
"devDependencies": {
|
|
45
|
-
"@20minutes/eslint-config": "^
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@babel/plugin-transform-runtime": "^7.28.5",
|
|
50
|
-
"@babel/preset-env": "^7.28.5",
|
|
51
|
-
"@babel/preset-react": "^7.28.5",
|
|
52
|
-
"babel-eslint": "^10.0.2",
|
|
53
|
-
"babel-jest": "^30.2.0",
|
|
54
|
-
"babel-loader": "^10.0.0",
|
|
55
|
-
"cross-env": "^10.1.0",
|
|
52
|
+
"@20minutes/eslint-config": "^2.0.0",
|
|
53
|
+
"@swc/cli": "^0.7.10",
|
|
54
|
+
"@swc/core": "^1.9.2",
|
|
55
|
+
"@swc/jest": "^0.2.36",
|
|
56
56
|
"draft-js": "^0.11.7",
|
|
57
|
-
"eslint": "^
|
|
58
|
-
"eslint-config-airbnb": "^19.0.4",
|
|
57
|
+
"eslint": "^9.0.0",
|
|
59
58
|
"eslint-config-prettier": "^10.1.8",
|
|
60
|
-
"eslint-plugin-babel": "^5.3.1",
|
|
61
59
|
"eslint-plugin-import": "^2.32.0",
|
|
62
|
-
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
63
60
|
"eslint-plugin-prettier": "^5.5.4",
|
|
64
61
|
"eslint-plugin-react": "7.37.5",
|
|
62
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
65
63
|
"jest": "^30.2.0",
|
|
66
64
|
"jest-environment-jsdom": "^30.2.0",
|
|
67
65
|
"prettier": "^3.6.2",
|
|
68
66
|
"react": "^18.0.0",
|
|
69
67
|
"react-dom": "^18.0.0",
|
|
70
|
-
"rimraf": "6.1.2"
|
|
71
|
-
"webpack": "^5.103.0",
|
|
72
|
-
"webpack-nano": "^1.1.1"
|
|
68
|
+
"rimraf": "6.1.2"
|
|
73
69
|
}
|
|
74
70
|
}
|