@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.cjs CHANGED
@@ -579,7 +579,7 @@ const getTextContentFromNodes = ($from, maxMatch = 500) => {
579
579
  }))
580
580
  || node.textContent
581
581
  || '%leaf%';
582
- textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
582
+ textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
583
583
  });
584
584
  return textBefore;
585
585
  };
@@ -966,7 +966,7 @@ function pasteRulesPlugin(props) {
966
966
 
967
967
  function findDuplicates(items) {
968
968
  const filtered = items.filter((el, index) => items.indexOf(el) !== index);
969
- return [...new Set(filtered)];
969
+ return Array.from(new Set(filtered));
970
970
  }
971
971
 
972
972
  class ExtensionManager {
@@ -2636,7 +2636,7 @@ function getMarksBetween(from, to, doc) {
2636
2636
  .resolve(from)
2637
2637
  .marks()
2638
2638
  .forEach(mark => {
2639
- const $pos = doc.resolve(from - 1);
2639
+ const $pos = doc.resolve(from);
2640
2640
  const range = getMarkRange($pos, mark.type);
2641
2641
  if (!range) {
2642
2642
  return;
@@ -2829,31 +2829,40 @@ function isList(name, extensions) {
2829
2829
  }
2830
2830
 
2831
2831
  /**
2832
- * Returns true if the given node is empty.
2833
- * When `checkChildren` is true (default), it will also check if all children are empty.
2832
+ * Returns true if the given prosemirror node is empty.
2834
2833
  */
2835
- function isNodeEmpty(node, { checkChildren } = { checkChildren: true }) {
2834
+ function isNodeEmpty(node, { checkChildren = true, ignoreWhitespace = false, } = {}) {
2835
+ var _a;
2836
+ if (ignoreWhitespace) {
2837
+ if (node.type.name === 'hardBreak') {
2838
+ // Hard breaks are considered empty
2839
+ return true;
2840
+ }
2841
+ if (node.isText) {
2842
+ return /^\s*$/m.test((_a = node.text) !== null && _a !== void 0 ? _a : '');
2843
+ }
2844
+ }
2836
2845
  if (node.isText) {
2837
2846
  return !node.text;
2838
2847
  }
2848
+ if (node.isAtom || node.isLeaf) {
2849
+ return false;
2850
+ }
2839
2851
  if (node.content.childCount === 0) {
2840
2852
  return true;
2841
2853
  }
2842
- if (node.isLeaf) {
2843
- return false;
2844
- }
2845
2854
  if (checkChildren) {
2846
- let hasSameContent = true;
2855
+ let isContentEmpty = true;
2847
2856
  node.content.forEach(childNode => {
2848
- if (hasSameContent === false) {
2857
+ if (isContentEmpty === false) {
2849
2858
  // Exit early for perf
2850
2859
  return;
2851
2860
  }
2852
- if (!isNodeEmpty(childNode)) {
2853
- hasSameContent = false;
2861
+ if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
2862
+ isContentEmpty = false;
2854
2863
  }
2855
2864
  });
2856
- return hasSameContent;
2865
+ return isContentEmpty;
2857
2866
  }
2858
2867
  return false;
2859
2868
  }