@tiptap/core 2.0.0-beta.137 → 2.0.0-beta.138

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.
@@ -3,7 +3,7 @@ import { EditorView } from 'prosemirror-view';
3
3
  import { Schema, MarkType, NodeType } from 'prosemirror-model';
4
4
  import ExtensionManager from './ExtensionManager';
5
5
  import EventEmitter from './EventEmitter';
6
- import { EditorOptions, CanCommands, ChainedCommands, SingleCommands, TextSerializer, EditorEvents } from './types';
6
+ import { EditorOptions, CanCommands, ChainedCommands, JSONContent, SingleCommands, TextSerializer, EditorEvents } from './types';
7
7
  import * as extensions from './extensions';
8
8
  export { extensions };
9
9
  export interface HTMLElement {
@@ -114,7 +114,7 @@ export declare class Editor extends EventEmitter<EditorEvents> {
114
114
  /**
115
115
  * Get the document as JSON.
116
116
  */
117
- getJSON(): Record<string, any>;
117
+ getJSON(): JSONContent;
118
118
  /**
119
119
  * Get the document as HTML.
120
120
  */
@@ -647,6 +647,9 @@ function selectionToInsertionEnd(tr, startLen, bias) {
647
647
  tr.setSelection(prosemirrorState.Selection.near(tr.doc.resolve(end), bias));
648
648
  }
649
649
 
650
+ const isFragment = (nodeOrFragment) => {
651
+ return nodeOrFragment.toString().startsWith('<');
652
+ };
650
653
  const insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) => {
651
654
  if (dispatch) {
652
655
  options = {
@@ -668,7 +671,10 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
668
671
  ? { from: position, to: position }
669
672
  : position;
670
673
  let isOnlyBlockContent = true;
671
- content.forEach(node => {
674
+ const nodes = isFragment(content)
675
+ ? content
676
+ : [content];
677
+ nodes.forEach(node => {
672
678
  isOnlyBlockContent = isOnlyBlockContent
673
679
  ? node.isBlock
674
680
  : false;
@@ -679,10 +685,10 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
679
685
  // replace an empty paragraph by an inserted image
680
686
  // instead of inserting the image below the paragraph
681
687
  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;
688
+ const { parent } = tr.doc.resolve(from);
689
+ const isEmptyTextBlock = parent.isTextblock
690
+ && !parent.type.spec.code
691
+ && !parent.childCount;
686
692
  if (isEmptyTextBlock) {
687
693
  from -= 1;
688
694
  to += 1;