@tiptap/core 2.5.7 → 2.5.9

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.umd.js CHANGED
@@ -575,7 +575,7 @@
575
575
  }))
576
576
  || node.textContent
577
577
  || '%leaf%';
578
- textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
578
+ textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
579
579
  });
580
580
  return textBefore;
581
581
  };
@@ -962,7 +962,7 @@
962
962
 
963
963
  function findDuplicates(items) {
964
964
  const filtered = items.filter((el, index) => items.indexOf(el) !== index);
965
- return [...new Set(filtered)];
965
+ return Array.from(new Set(filtered));
966
966
  }
967
967
 
968
968
  class ExtensionManager {
@@ -2632,7 +2632,7 @@
2632
2632
  .resolve(from)
2633
2633
  .marks()
2634
2634
  .forEach(mark => {
2635
- const $pos = doc.resolve(from - 1);
2635
+ const $pos = doc.resolve(from);
2636
2636
  const range = getMarkRange($pos, mark.type);
2637
2637
  if (!range) {
2638
2638
  return;
@@ -2825,31 +2825,40 @@
2825
2825
  }
2826
2826
 
2827
2827
  /**
2828
- * Returns true if the given node is empty.
2829
- * When `checkChildren` is true (default), it will also check if all children are empty.
2828
+ * Returns true if the given prosemirror node is empty.
2830
2829
  */
2831
- function isNodeEmpty(node, { checkChildren } = { checkChildren: true }) {
2830
+ function isNodeEmpty(node, { checkChildren = true, ignoreWhitespace = false, } = {}) {
2831
+ var _a;
2832
+ if (ignoreWhitespace) {
2833
+ if (node.type.name === 'hardBreak') {
2834
+ // Hard breaks are considered empty
2835
+ return true;
2836
+ }
2837
+ if (node.isText) {
2838
+ return /^\s*$/m.test((_a = node.text) !== null && _a !== void 0 ? _a : '');
2839
+ }
2840
+ }
2832
2841
  if (node.isText) {
2833
2842
  return !node.text;
2834
2843
  }
2844
+ if (node.isAtom || node.isLeaf) {
2845
+ return false;
2846
+ }
2835
2847
  if (node.content.childCount === 0) {
2836
2848
  return true;
2837
2849
  }
2838
- if (node.isLeaf) {
2839
- return false;
2840
- }
2841
2850
  if (checkChildren) {
2842
- let hasSameContent = true;
2851
+ let isContentEmpty = true;
2843
2852
  node.content.forEach(childNode => {
2844
- if (hasSameContent === false) {
2853
+ if (isContentEmpty === false) {
2845
2854
  // Exit early for perf
2846
2855
  return;
2847
2856
  }
2848
- if (!isNodeEmpty(childNode)) {
2849
- hasSameContent = false;
2857
+ if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
2858
+ isContentEmpty = false;
2850
2859
  }
2851
2860
  });
2852
- return hasSameContent;
2861
+ return isContentEmpty;
2853
2862
  }
2854
2863
  return false;
2855
2864
  }