@tiptap/core 2.1.14 → 2.1.16
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 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +16 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/utilities/elementFromString.ts +21 -1
package/dist/index.cjs
CHANGED
|
@@ -1588,10 +1588,25 @@ const insertContent = (value, options) => ({ tr, commands }) => {
|
|
|
1588
1588
|
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
|
|
1589
1589
|
};
|
|
1590
1590
|
|
|
1591
|
+
const removeWhitespaces = (node) => {
|
|
1592
|
+
const children = node.childNodes;
|
|
1593
|
+
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
1594
|
+
const child = children[i];
|
|
1595
|
+
if (child.nodeType === 3 && child.nodeValue && !/\S/.test(child.nodeValue)) {
|
|
1596
|
+
node.removeChild(child);
|
|
1597
|
+
}
|
|
1598
|
+
else if (child.nodeType === 1) {
|
|
1599
|
+
removeWhitespaces(child);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
return node;
|
|
1603
|
+
};
|
|
1591
1604
|
function elementFromString(value) {
|
|
1592
1605
|
// add a wrapper to preserve leading and trailing whitespace
|
|
1593
1606
|
const wrappedValue = `<body>${value}</body>`;
|
|
1594
|
-
|
|
1607
|
+
const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
|
|
1608
|
+
removeWhitespaces(html);
|
|
1609
|
+
return removeWhitespaces(html);
|
|
1595
1610
|
}
|
|
1596
1611
|
|
|
1597
1612
|
function createNodeFromContent(content, schema, options) {
|