@tiptap/core 2.5.6 → 2.5.8
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/index.cjs +53 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -17
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +53 -17
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +7 -1
- package/package.json +3 -3
- package/src/Editor.ts +2 -0
- package/src/commands/insertContentAt.ts +7 -0
- package/src/helpers/createNodeFromContent.ts +21 -13
- package/src/helpers/getTextContentFromNodes.ts +1 -1
- package/src/helpers/isNodeEmpty.ts +34 -4
package/dist/index.umd.js
CHANGED
|
@@ -575,7 +575,7 @@
|
|
|
575
575
|
}))
|
|
576
576
|
|| node.textContent
|
|
577
577
|
|| '%leaf%';
|
|
578
|
-
textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
578
|
+
textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
579
579
|
});
|
|
580
580
|
return textBefore;
|
|
581
581
|
};
|
|
@@ -1775,12 +1775,12 @@
|
|
|
1775
1775
|
}
|
|
1776
1776
|
}
|
|
1777
1777
|
if (isTextContent) {
|
|
1778
|
-
|
|
1779
|
-
let hasInvalidContent = false;
|
|
1780
|
-
let invalidContent = '';
|
|
1781
|
-
// Only ever check for invalid content if we're supposed to throw an error
|
|
1778
|
+
// Check for invalid content
|
|
1782
1779
|
if (options.errorOnInvalidContent) {
|
|
1783
|
-
|
|
1780
|
+
let hasInvalidContent = false;
|
|
1781
|
+
let invalidContent = '';
|
|
1782
|
+
// A copy of the current schema with a catch-all node at the end
|
|
1783
|
+
const contentCheckSchema = new model.Schema({
|
|
1784
1784
|
topNode: schema.spec.topNode,
|
|
1785
1785
|
marks: schema.spec.marks,
|
|
1786
1786
|
// Prosemirror's schemas are executed such that: the last to execute, matches last
|
|
@@ -1804,15 +1804,21 @@
|
|
|
1804
1804
|
},
|
|
1805
1805
|
}),
|
|
1806
1806
|
});
|
|
1807
|
+
if (options.slice) {
|
|
1808
|
+
model.DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions);
|
|
1809
|
+
}
|
|
1810
|
+
else {
|
|
1811
|
+
model.DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions);
|
|
1812
|
+
}
|
|
1813
|
+
if (options.errorOnInvalidContent && hasInvalidContent) {
|
|
1814
|
+
throw new Error('[tiptap error]: Invalid HTML content', { cause: new Error(`Invalid element found: ${invalidContent}`) });
|
|
1815
|
+
}
|
|
1807
1816
|
}
|
|
1808
|
-
const parser = model.DOMParser.fromSchema(
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
: parser.parse(elementFromString(content), options.parseOptions);
|
|
1812
|
-
if (options.errorOnInvalidContent && hasInvalidContent) {
|
|
1813
|
-
throw new Error('[tiptap error]: Invalid HTML content', { cause: new Error(`Invalid element found: ${invalidContent}`) });
|
|
1817
|
+
const parser = model.DOMParser.fromSchema(schema);
|
|
1818
|
+
if (options.slice) {
|
|
1819
|
+
return parser.parseSlice(elementFromString(content), options.parseOptions).content;
|
|
1814
1820
|
}
|
|
1815
|
-
return
|
|
1821
|
+
return parser.parse(elementFromString(content), options.parseOptions);
|
|
1816
1822
|
}
|
|
1817
1823
|
return createNodeFromContent('', schema, options);
|
|
1818
1824
|
}
|
|
@@ -1861,6 +1867,13 @@
|
|
|
1861
1867
|
});
|
|
1862
1868
|
}
|
|
1863
1869
|
catch (e) {
|
|
1870
|
+
editor.emit('contentError', {
|
|
1871
|
+
editor,
|
|
1872
|
+
error: e,
|
|
1873
|
+
disableCollaboration: () => {
|
|
1874
|
+
console.error('[tiptap error]: Unable to disable collaboration at this point in time');
|
|
1875
|
+
},
|
|
1876
|
+
});
|
|
1864
1877
|
return false;
|
|
1865
1878
|
}
|
|
1866
1879
|
let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to };
|
|
@@ -2811,12 +2824,34 @@
|
|
|
2811
2824
|
return group.split(' ').includes('list');
|
|
2812
2825
|
}
|
|
2813
2826
|
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2827
|
+
/**
|
|
2828
|
+
* Returns true if the given node is empty.
|
|
2829
|
+
* When `checkChildren` is true (default), it will also check if all children are empty.
|
|
2830
|
+
*/
|
|
2831
|
+
function isNodeEmpty(node, { checkChildren } = { checkChildren: true }) {
|
|
2832
|
+
if (node.isText) {
|
|
2833
|
+
return !node.text;
|
|
2834
|
+
}
|
|
2835
|
+
if (node.content.childCount === 0) {
|
|
2836
|
+
return true;
|
|
2837
|
+
}
|
|
2838
|
+
if (node.isLeaf) {
|
|
2817
2839
|
return false;
|
|
2818
2840
|
}
|
|
2819
|
-
|
|
2841
|
+
if (checkChildren) {
|
|
2842
|
+
let hasSameContent = true;
|
|
2843
|
+
node.content.forEach(childNode => {
|
|
2844
|
+
if (hasSameContent === false) {
|
|
2845
|
+
// Exit early for perf
|
|
2846
|
+
return;
|
|
2847
|
+
}
|
|
2848
|
+
if (!isNodeEmpty(childNode)) {
|
|
2849
|
+
hasSameContent = false;
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
return hasSameContent;
|
|
2853
|
+
}
|
|
2854
|
+
return false;
|
|
2820
2855
|
}
|
|
2821
2856
|
|
|
2822
2857
|
function isNodeSelection(value) {
|
|
@@ -4158,6 +4193,7 @@ img.ProseMirror-separator {
|
|
|
4158
4193
|
this.prependClass();
|
|
4159
4194
|
// Let’s store the editor instance in the DOM element.
|
|
4160
4195
|
// So we’ll have access to it for tests.
|
|
4196
|
+
// @ts-ignore
|
|
4161
4197
|
const dom = this.view.dom;
|
|
4162
4198
|
dom.editor = this;
|
|
4163
4199
|
}
|