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