@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 CHANGED
@@ -1587,10 +1587,24 @@ const insertContent = (value, options) => ({ tr, commands }) => {
1587
1587
  return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options);
1588
1588
  };
1589
1589
 
1590
+ const removeWhitespaces = (node) => {
1591
+ const children = node.childNodes;
1592
+ for (let i = children.length - 1; i >= 0; i -= 1) {
1593
+ const child = children[i];
1594
+ if (child.nodeType === 3 && child.nodeValue && /^(\n\s\s|\n)$/.test(child.nodeValue)) {
1595
+ node.removeChild(child);
1596
+ }
1597
+ else if (child.nodeType === 1) {
1598
+ removeWhitespaces(child);
1599
+ }
1600
+ }
1601
+ return node;
1602
+ };
1590
1603
  function elementFromString(value) {
1591
1604
  // add a wrapper to preserve leading and trailing whitespace
1592
1605
  const wrappedValue = `<body>${value}</body>`;
1593
- return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
1606
+ const html = new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
1607
+ return removeWhitespaces(html);
1594
1608
  }
1595
1609
 
1596
1610
  function createNodeFromContent(content, schema, options) {
@@ -2318,7 +2332,7 @@ function getMarksBetween(from, to, doc) {
2318
2332
  }
2319
2333
  else {
2320
2334
  doc.nodesBetween(from, to, (node, pos) => {
2321
- if (!node || node.nodeSize === undefined) {
2335
+ if (!node || (node === null || node === void 0 ? void 0 : node.nodeSize) === undefined) {
2322
2336
  return;
2323
2337
  }
2324
2338
  marks.push(...node.marks.map(mark => ({