@tiptap/core 2.5.0-beta.4 → 2.5.0-beta.5
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 +37 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -43
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +37 -43
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/insertContentAt.ts +0 -5
- package/src/commands/setContent.ts +22 -10
- package/src/commands/updateAttributes.ts +25 -40
- package/src/helpers/createNodeFromContent.ts +5 -2
package/dist/index.js
CHANGED
|
@@ -1780,6 +1780,7 @@ function createNodeFromContent(content, schema, options) {
|
|
|
1780
1780
|
if (isTextContent) {
|
|
1781
1781
|
let schemaToUse = schema;
|
|
1782
1782
|
let hasInvalidContent = false;
|
|
1783
|
+
let invalidContent = '';
|
|
1783
1784
|
// Only ever check for invalid content if we're supposed to throw an error
|
|
1784
1785
|
if (options.errorOnInvalidContent) {
|
|
1785
1786
|
schemaToUse = new Schema({
|
|
@@ -1794,9 +1795,11 @@ function createNodeFromContent(content, schema, options) {
|
|
|
1794
1795
|
parseDOM: [
|
|
1795
1796
|
{
|
|
1796
1797
|
tag: '*',
|
|
1797
|
-
getAttrs:
|
|
1798
|
+
getAttrs: e => {
|
|
1798
1799
|
// If this is ever called, we know that the content has something that we don't know how to handle in the schema
|
|
1799
1800
|
hasInvalidContent = true;
|
|
1801
|
+
// Try to stringify the element for a more helpful error message
|
|
1802
|
+
invalidContent = typeof e === 'string' ? e : e.outerHTML;
|
|
1800
1803
|
return null;
|
|
1801
1804
|
},
|
|
1802
1805
|
},
|
|
@@ -1810,7 +1813,7 @@ function createNodeFromContent(content, schema, options) {
|
|
|
1810
1813
|
? parser.parseSlice(elementFromString(content), options.parseOptions).content
|
|
1811
1814
|
: parser.parse(elementFromString(content), options.parseOptions);
|
|
1812
1815
|
if (options.errorOnInvalidContent && hasInvalidContent) {
|
|
1813
|
-
throw new Error('[tiptap error]: Invalid HTML content');
|
|
1816
|
+
throw new Error('[tiptap error]: Invalid HTML content', { cause: new Error(`Invalid element found: ${invalidContent}`) });
|
|
1814
1817
|
}
|
|
1815
1818
|
return response;
|
|
1816
1819
|
}
|
|
@@ -1863,10 +1866,6 @@ const insertContentAt = (position, value, options) => ({ tr, dispatch, editor })
|
|
|
1863
1866
|
catch (e) {
|
|
1864
1867
|
return false;
|
|
1865
1868
|
}
|
|
1866
|
-
// don’t dispatch an empty fragment because this can lead to strange errors
|
|
1867
|
-
if (content.toString() === '<>') {
|
|
1868
|
-
return true;
|
|
1869
|
-
}
|
|
1870
1869
|
let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to };
|
|
1871
1870
|
let isOnlyTextContent = true;
|
|
1872
1871
|
let isOnlyBlockContent = true;
|
|
@@ -2236,22 +2235,27 @@ function createDocument(content, schema, parseOptions = {}, options = {}) {
|
|
|
2236
2235
|
});
|
|
2237
2236
|
}
|
|
2238
2237
|
|
|
2239
|
-
const setContent = (content, emitUpdate = false, parseOptions = {}, options = {}) => ({
|
|
2240
|
-
var _a;
|
|
2238
|
+
const setContent = (content, emitUpdate = false, parseOptions = {}, options = {}) => ({ editor, tr, dispatch, commands, }) => {
|
|
2239
|
+
var _a, _b;
|
|
2241
2240
|
const { doc } = tr;
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2241
|
+
// This is to keep backward compatibility with the previous behavior
|
|
2242
|
+
// TODO remove this in the next major version
|
|
2243
|
+
if (parseOptions.preserveWhitespace !== 'full') {
|
|
2244
|
+
const document = createDocument(content, editor.schema, parseOptions, {
|
|
2245
2245
|
errorOnInvalidContent: (_a = options.errorOnInvalidContent) !== null && _a !== void 0 ? _a : editor.options.enableContentCheck,
|
|
2246
2246
|
});
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2247
|
+
if (dispatch) {
|
|
2248
|
+
tr.replaceWith(0, doc.content.size, document).setMeta('preventUpdate', !emitUpdate);
|
|
2249
|
+
}
|
|
2250
|
+
return true;
|
|
2250
2251
|
}
|
|
2251
2252
|
if (dispatch) {
|
|
2252
|
-
tr.
|
|
2253
|
+
tr.setMeta('preventUpdate', !emitUpdate);
|
|
2253
2254
|
}
|
|
2254
|
-
return
|
|
2255
|
+
return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {
|
|
2256
|
+
parseOptions,
|
|
2257
|
+
errorOnInvalidContent: (_b = options.errorOnInvalidContent) !== null && _b !== void 0 ? _b : editor.options.enableContentCheck,
|
|
2258
|
+
});
|
|
2255
2259
|
};
|
|
2256
2260
|
|
|
2257
2261
|
function getMarkAttributes(state, typeOrName) {
|
|
@@ -3355,40 +3359,30 @@ const updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch
|
|
|
3355
3359
|
markType = getMarkType(typeOrName, state.schema);
|
|
3356
3360
|
}
|
|
3357
3361
|
if (dispatch) {
|
|
3358
|
-
|
|
3359
|
-
let lastNode;
|
|
3360
|
-
let trimmedFrom;
|
|
3361
|
-
let trimmedTo;
|
|
3362
|
-
tr.selection.ranges.forEach((range) => {
|
|
3362
|
+
tr.selection.ranges.forEach(range => {
|
|
3363
3363
|
const from = range.$from.pos;
|
|
3364
3364
|
const to = range.$to.pos;
|
|
3365
3365
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
3366
3366
|
if (nodeType && nodeType === node.type) {
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3367
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
3368
|
+
...node.attrs,
|
|
3369
|
+
...attributes,
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3372
|
+
if (markType && node.marks.length) {
|
|
3373
|
+
node.marks.forEach(mark => {
|
|
3374
|
+
if (markType === mark.type) {
|
|
3375
|
+
const trimmedFrom = Math.max(pos, from);
|
|
3376
|
+
const trimmedTo = Math.min(pos + node.nodeSize, to);
|
|
3377
|
+
tr.addMark(trimmedFrom, trimmedTo, markType.create({
|
|
3378
|
+
...mark.attrs,
|
|
3379
|
+
...attributes,
|
|
3380
|
+
}));
|
|
3381
|
+
}
|
|
3382
|
+
});
|
|
3371
3383
|
}
|
|
3372
3384
|
});
|
|
3373
3385
|
});
|
|
3374
|
-
if (lastNode) {
|
|
3375
|
-
if (lastPos !== undefined) {
|
|
3376
|
-
tr.setNodeMarkup(lastPos, undefined, {
|
|
3377
|
-
...lastNode.attrs,
|
|
3378
|
-
...attributes,
|
|
3379
|
-
});
|
|
3380
|
-
}
|
|
3381
|
-
if (markType && lastNode.marks.length) {
|
|
3382
|
-
lastNode.marks.forEach((mark) => {
|
|
3383
|
-
if (markType === mark.type) {
|
|
3384
|
-
tr.addMark(trimmedFrom, trimmedTo, markType.create({
|
|
3385
|
-
...mark.attrs,
|
|
3386
|
-
...attributes,
|
|
3387
|
-
}));
|
|
3388
|
-
}
|
|
3389
|
-
});
|
|
3390
|
-
}
|
|
3391
|
-
}
|
|
3392
3386
|
}
|
|
3393
3387
|
return true;
|
|
3394
3388
|
};
|