@tiptap/core 2.2.0-rc.8 → 2.2.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/dist/index.cjs +16 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +16 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/helpers/getMarksBetween.ts +1 -1
- package/src/utilities/elementFromString.ts +19 -1
package/dist/index.js
CHANGED
|
@@ -1583,10 +1583,24 @@ const insertContent = (value, options) => ({ tr, commands }) => {
|
|
|
1583
1583
|
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
|
|
1584
1584
|
};
|
|
1585
1585
|
|
|
1586
|
+
const removeWhitespaces = (node) => {
|
|
1587
|
+
const children = node.childNodes;
|
|
1588
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
1589
|
+
const child = children[i];
|
|
1590
|
+
if (child.nodeType === 3 && child.nodeValue && /^(\n\s\s|\n)$/.test(child.nodeValue)) {
|
|
1591
|
+
node.removeChild(child);
|
|
1592
|
+
}
|
|
1593
|
+
else if (child.nodeType === 1) {
|
|
1594
|
+
removeWhitespaces(child);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
return node;
|
|
1598
|
+
};
|
|
1586
1599
|
function elementFromString(value) {
|
|
1587
1600
|
// add a wrapper to preserve leading and trailing whitespace
|
|
1588
1601
|
const wrappedValue = `<body>${value}</body>`;
|
|
1589
|
-
|
|
1602
|
+
const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
|
|
1603
|
+
return removeWhitespaces(html);
|
|
1590
1604
|
}
|
|
1591
1605
|
|
|
1592
1606
|
function createNodeFromContent(content, schema, options) {
|
|
@@ -2314,7 +2328,7 @@ function getMarksBetween(from, to, doc) {
|
|
|
2314
2328
|
}
|
|
2315
2329
|
else {
|
|
2316
2330
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
2317
|
-
if (!node || node.nodeSize === undefined) {
|
|
2331
|
+
if (!node || (node === null || node === void 0 ? void 0 : node.nodeSize) === undefined) {
|
|
2318
2332
|
return;
|
|
2319
2333
|
}
|
|
2320
2334
|
marks.push(...node.marks.map(mark => ({
|