@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.
- package/dist/packages/core/src/Editor.d.ts +2 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
- package/dist/packages/core/src/types.d.ts +3 -2
- package/dist/tiptap-core.cjs.js +29 -8
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +29 -8
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +29 -8
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/Editor.ts +2 -1
- package/src/ExtensionManager.ts +3 -2
- package/src/NodeView.ts +6 -1
- package/src/commands/insertContentAt.ts +13 -6
- package/src/helpers/isExtensionRulesEnabled.ts +15 -0
- package/src/types.ts +4 -2
|
@@ -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():
|
|
117
|
+
getJSON(): JSONContent;
|
|
118
118
|
/**
|
|
119
119
|
* Get the document as HTML.
|
|
120
120
|
*/
|
|
@@ -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:
|
|
60
|
-
enablePasteRules:
|
|
60
|
+
enableInputRules: EnableRules;
|
|
61
|
+
enablePasteRules: EnableRules;
|
|
61
62
|
enableCoreExtensions: boolean;
|
|
62
63
|
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void;
|
|
63
64
|
onCreate: (props: EditorEvents['create']) => void;
|
package/dist/tiptap-core.cjs.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
683
|
-
const isEmptyTextBlock =
|
|
684
|
-
&&
|
|
685
|
-
&&
|
|
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)
|
|
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),
|