@tiptap/core 2.1.15 → 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 -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/createNodeFromContent.ts +0 -1
- 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) {
|
|
@@ -1613,7 +1628,6 @@ function createNodeFromContent(content, schema, options) {
|
|
|
1613
1628
|
}
|
|
1614
1629
|
}
|
|
1615
1630
|
if (typeof content === 'string') {
|
|
1616
|
-
content = content.split('\n').map(part => part.trim()).join(''); // we need to remove new lines since the parser will add breaks
|
|
1617
1631
|
const parser = model.DOMParser.fromSchema(schema);
|
|
1618
1632
|
return options.slice
|
|
1619
1633
|
? parser.parseSlice(elementFromString(content), options.parseOptions).content
|