@tiptap/core 2.0.0-beta.132 → 2.0.0-beta.136

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.
@@ -664,13 +664,34 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
664
664
  if (content.toString() === '<>') {
665
665
  return true;
666
666
  }
667
- const { from, to } = typeof position === 'number'
667
+ let { from, to } = typeof position === 'number'
668
668
  ? { from: position, to: position }
669
669
  : position;
670
+ let isOnlyBlockContent = true;
671
+ content.forEach(node => {
672
+ isOnlyBlockContent = isOnlyBlockContent
673
+ ? node.isBlock
674
+ : false;
675
+ });
676
+ // check if we can replace the wrapping node by
677
+ // the newly inserted content
678
+ // example:
679
+ // replace an empty paragraph by an inserted image
680
+ // instead of inserting the image below the paragraph
681
+ if (from === to && isOnlyBlockContent) {
682
+ const $from = tr.doc.resolve(from);
683
+ const isEmptyTextBlock = $from.parent.isTextblock
684
+ && !$from.parent.type.spec.code
685
+ && !$from.parent.textContent;
686
+ if (isEmptyTextBlock) {
687
+ from -= 1;
688
+ to += 1;
689
+ }
690
+ }
670
691
  tr.replaceWith(from, to, content);
671
692
  // set cursor at end of inserted content
672
693
  if (options.updateSelection) {
673
- selectionToInsertionEnd(tr, tr.steps.length - 1, 1);
694
+ selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
674
695
  }
675
696
  }
676
697
  return true;
@@ -2489,7 +2510,7 @@ function fromString(value) {
2489
2510
  if (typeof value !== 'string') {
2490
2511
  return value;
2491
2512
  }
2492
- if (value.match(/^\d*(\.\d+)?$/)) {
2513
+ if (value.match(/^[+-]?(?:\d*\.)?\d+$/)) {
2493
2514
  return Number(value);
2494
2515
  }
2495
2516
  if (value === 'true') {