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

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
  */
@@ -0,0 +1,2 @@
1
+ import { AnyExtension, EnableRules } from '../types';
2
+ export default function isExtensionRulesEnabled(extension: AnyExtension, enabled: EnableRules): boolean;
@@ -47,6 +47,7 @@ export interface EditorEvents {
47
47
  };
48
48
  destroy: void;
49
49
  }
50
+ export declare type EnableRules = (AnyExtension | string)[] | boolean;
50
51
  export interface EditorOptions {
51
52
  element: Element;
52
53
  content: Content;
@@ -56,8 +57,8 @@ export interface EditorOptions {
56
57
  editable: boolean;
57
58
  editorProps: EditorProps;
58
59
  parseOptions: ParseOptions;
59
- enableInputRules: boolean;
60
- enablePasteRules: boolean;
60
+ enableInputRules: EnableRules;
61
+ enablePasteRules: EnableRules;
61
62
  enableCoreExtensions: boolean;
62
63
  onBeforeCreate: (props: EditorEvents['beforeCreate']) => void;
63
64
  onCreate: (props: EditorEvents['create']) => void;
@@ -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;
@@ -2670,6 +2676,18 @@ function getSchemaTypeByName(name, schema) {
2670
2676
  return schema.nodes[name] || schema.marks[name] || null;
2671
2677
  }
2672
2678
 
2679
+ function isExtensionRulesEnabled(extension, enabled) {
2680
+ if (Array.isArray(enabled)) {
2681
+ return enabled.some(enabledExtension => {
2682
+ const name = typeof enabledExtension === 'string'
2683
+ ? enabledExtension
2684
+ : enabledExtension.name;
2685
+ return name === extension.name;
2686
+ });
2687
+ }
2688
+ return enabled;
2689
+ }
2690
+
2673
2691
  function findDuplicates(items) {
2674
2692
  const filtered = items.filter((el, index) => items.indexOf(el) !== index);
2675
2693
  return [...new Set(filtered)];
@@ -2824,11 +2842,11 @@ class ExtensionManager {
2824
2842
  plugins.push(keyMapPlugin);
2825
2843
  }
2826
2844
  const addInputRules = getExtensionField(extension, 'addInputRules', context);
2827
- if (editor.options.enableInputRules && addInputRules) {
2845
+ if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
2828
2846
  inputRules.push(...addInputRules());
2829
2847
  }
2830
2848
  const addPasteRules = getExtensionField(extension, 'addPasteRules', context);
2831
- if (editor.options.enablePasteRules && addPasteRules) {
2849
+ if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {
2832
2850
  pasteRules.push(...addPasteRules());
2833
2851
  }
2834
2852
  const addProseMirrorPlugins = getExtensionField(extension, 'addProseMirrorPlugins', context);
@@ -3626,7 +3644,10 @@ class NodeView {
3626
3644
  // this is because ProseMirror can’t preventDispatch on enter
3627
3645
  // this will lead to a re-render of the node view on enter
3628
3646
  // see: https://github.com/ueberdosis/tiptap/issues/1214
3629
- if (this.dom.contains(mutation.target) && mutation.type === 'childList' && isiOS()) {
3647
+ if (this.dom.contains(mutation.target)
3648
+ && mutation.type === 'childList'
3649
+ && isiOS()
3650
+ && this.editor.isFocused) {
3630
3651
  const changedNodes = [
3631
3652
  ...Array.from(mutation.addedNodes),
3632
3653
  ...Array.from(mutation.removedNodes),