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