@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
package/dist/tiptap-core.esm.js
CHANGED
|
@@ -643,6 +643,9 @@ function selectionToInsertionEnd(tr, startLen, bias) {
|
|
|
643
643
|
tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
|
|
644
644
|
}
|
|
645
645
|
|
|
646
|
+
const isFragment = (nodeOrFragment) => {
|
|
647
|
+
return nodeOrFragment.toString().startsWith('<');
|
|
648
|
+
};
|
|
646
649
|
const insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) => {
|
|
647
650
|
if (dispatch) {
|
|
648
651
|
options = {
|
|
@@ -664,7 +667,10 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
664
667
|
? { from: position, to: position }
|
|
665
668
|
: position;
|
|
666
669
|
let isOnlyBlockContent = true;
|
|
667
|
-
|
|
670
|
+
const nodes = isFragment(content)
|
|
671
|
+
? content
|
|
672
|
+
: [content];
|
|
673
|
+
nodes.forEach(node => {
|
|
668
674
|
isOnlyBlockContent = isOnlyBlockContent
|
|
669
675
|
? node.isBlock
|
|
670
676
|
: false;
|
|
@@ -675,10 +681,10 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
675
681
|
// replace an empty paragraph by an inserted image
|
|
676
682
|
// instead of inserting the image below the paragraph
|
|
677
683
|
if (from === to && isOnlyBlockContent) {
|
|
678
|
-
const
|
|
679
|
-
const isEmptyTextBlock =
|
|
680
|
-
&&
|
|
681
|
-
&&
|
|
684
|
+
const { parent } = tr.doc.resolve(from);
|
|
685
|
+
const isEmptyTextBlock = parent.isTextblock
|
|
686
|
+
&& !parent.type.spec.code
|
|
687
|
+
&& !parent.childCount;
|
|
682
688
|
if (isEmptyTextBlock) {
|
|
683
689
|
from -= 1;
|
|
684
690
|
to += 1;
|
|
@@ -2666,6 +2672,18 @@ function getSchemaTypeByName(name, schema) {
|
|
|
2666
2672
|
return schema.nodes[name] || schema.marks[name] || null;
|
|
2667
2673
|
}
|
|
2668
2674
|
|
|
2675
|
+
function isExtensionRulesEnabled(extension, enabled) {
|
|
2676
|
+
if (Array.isArray(enabled)) {
|
|
2677
|
+
return enabled.some(enabledExtension => {
|
|
2678
|
+
const name = typeof enabledExtension === 'string'
|
|
2679
|
+
? enabledExtension
|
|
2680
|
+
: enabledExtension.name;
|
|
2681
|
+
return name === extension.name;
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
return enabled;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2669
2687
|
function findDuplicates(items) {
|
|
2670
2688
|
const filtered = items.filter((el, index) => items.indexOf(el) !== index);
|
|
2671
2689
|
return [...new Set(filtered)];
|
|
@@ -2820,11 +2838,11 @@ class ExtensionManager {
|
|
|
2820
2838
|
plugins.push(keyMapPlugin);
|
|
2821
2839
|
}
|
|
2822
2840
|
const addInputRules = getExtensionField(extension, 'addInputRules', context);
|
|
2823
|
-
if (editor.options.enableInputRules && addInputRules) {
|
|
2841
|
+
if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
|
|
2824
2842
|
inputRules.push(...addInputRules());
|
|
2825
2843
|
}
|
|
2826
2844
|
const addPasteRules = getExtensionField(extension, 'addPasteRules', context);
|
|
2827
|
-
if (editor.options.enablePasteRules && addPasteRules) {
|
|
2845
|
+
if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {
|
|
2828
2846
|
pasteRules.push(...addPasteRules());
|
|
2829
2847
|
}
|
|
2830
2848
|
const addProseMirrorPlugins = getExtensionField(extension, 'addProseMirrorPlugins', context);
|
|
@@ -3622,7 +3640,10 @@ class NodeView {
|
|
|
3622
3640
|
// this is because ProseMirror can’t preventDispatch on enter
|
|
3623
3641
|
// this will lead to a re-render of the node view on enter
|
|
3624
3642
|
// see: https://github.com/ueberdosis/tiptap/issues/1214
|
|
3625
|
-
if (this.dom.contains(mutation.target)
|
|
3643
|
+
if (this.dom.contains(mutation.target)
|
|
3644
|
+
&& mutation.type === 'childList'
|
|
3645
|
+
&& isiOS()
|
|
3646
|
+
&& this.editor.isFocused) {
|
|
3626
3647
|
const changedNodes = [
|
|
3627
3648
|
...Array.from(mutation.addedNodes),
|
|
3628
3649
|
...Array.from(mutation.removedNodes),
|