@tiptap/core 2.5.4 → 2.5.6
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 +34 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -26
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +34 -26
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/core/src/Editor.d.ts +2 -4
- package/dist/packages/core/src/types.d.ts +6 -3
- package/package.json +3 -3
- package/src/Editor.ts +12 -5
- package/src/commands/splitBlock.ts +31 -31
- package/src/helpers/getTextContentFromNodes.ts +1 -1
- package/src/helpers/isNodeEmpty.ts +1 -1
- package/src/types.ts +157 -155
package/dist/index.js
CHANGED
|
@@ -577,7 +577,7 @@ const getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
|
577
577
|
}))
|
|
578
578
|
|| node.textContent
|
|
579
579
|
|| '%leaf%';
|
|
580
|
-
textBefore += chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
580
|
+
textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
581
581
|
});
|
|
582
582
|
return textBefore;
|
|
583
583
|
};
|
|
@@ -2814,7 +2814,7 @@ function isList(name, extensions) {
|
|
|
2814
2814
|
}
|
|
2815
2815
|
|
|
2816
2816
|
function isNodeEmpty(node) {
|
|
2817
|
-
const defaultContent = node.type.createAndFill();
|
|
2817
|
+
const defaultContent = node.type.createAndFill(node.attrs);
|
|
2818
2818
|
if (!defaultContent) {
|
|
2819
2819
|
return false;
|
|
2820
2820
|
}
|
|
@@ -3016,15 +3016,24 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
|
|
|
3016
3016
|
if (!$from.parent.isBlock) {
|
|
3017
3017
|
return false;
|
|
3018
3018
|
}
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3019
|
+
const atEnd = $to.parentOffset === $to.parent.content.size;
|
|
3020
|
+
const deflt = $from.depth === 0
|
|
3021
|
+
? undefined
|
|
3022
|
+
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
|
|
3023
|
+
let types = atEnd && deflt
|
|
3024
|
+
? [
|
|
3025
|
+
{
|
|
3026
|
+
type: deflt,
|
|
3027
|
+
attrs: newAttributes,
|
|
3028
|
+
},
|
|
3029
|
+
]
|
|
3030
|
+
: undefined;
|
|
3031
|
+
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
|
|
3032
|
+
if (!types
|
|
3033
|
+
&& !can
|
|
3034
|
+
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
|
|
3035
|
+
can = true;
|
|
3036
|
+
types = deflt
|
|
3028
3037
|
? [
|
|
3029
3038
|
{
|
|
3030
3039
|
type: deflt,
|
|
@@ -3032,21 +3041,12 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
|
|
|
3032
3041
|
},
|
|
3033
3042
|
]
|
|
3034
3043
|
: undefined;
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
&& !can
|
|
3038
|
-
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
|
|
3039
|
-
can = true;
|
|
3040
|
-
types = deflt
|
|
3041
|
-
? [
|
|
3042
|
-
{
|
|
3043
|
-
type: deflt,
|
|
3044
|
-
attrs: newAttributes,
|
|
3045
|
-
},
|
|
3046
|
-
]
|
|
3047
|
-
: undefined;
|
|
3048
|
-
}
|
|
3044
|
+
}
|
|
3045
|
+
if (dispatch) {
|
|
3049
3046
|
if (can) {
|
|
3047
|
+
if (selection instanceof TextSelection) {
|
|
3048
|
+
tr.deleteSelection();
|
|
3049
|
+
}
|
|
3050
3050
|
tr.split(tr.mapping.map($from.pos), 1, types);
|
|
3051
3051
|
if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
|
|
3052
3052
|
const first = tr.mapping.map($from.before());
|
|
@@ -3061,7 +3061,7 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor
|
|
|
3061
3061
|
}
|
|
3062
3062
|
tr.scrollIntoView();
|
|
3063
3063
|
}
|
|
3064
|
-
return
|
|
3064
|
+
return can;
|
|
3065
3065
|
};
|
|
3066
3066
|
|
|
3067
3067
|
const splitListItem = typeOrName => ({ tr, state, dispatch, editor, }) => {
|
|
@@ -4167,6 +4167,9 @@ class Editor extends EventEmitter {
|
|
|
4167
4167
|
* Creates all node views.
|
|
4168
4168
|
*/
|
|
4169
4169
|
createNodeViews() {
|
|
4170
|
+
if (this.view.isDestroyed) {
|
|
4171
|
+
return;
|
|
4172
|
+
}
|
|
4170
4173
|
this.view.setProps({
|
|
4171
4174
|
nodeViews: this.extensionManager.nodeViews,
|
|
4172
4175
|
});
|
|
@@ -4206,6 +4209,11 @@ class Editor extends EventEmitter {
|
|
|
4206
4209
|
}
|
|
4207
4210
|
const state = this.state.apply(transaction);
|
|
4208
4211
|
const selectionHasChanged = !this.state.selection.eq(state.selection);
|
|
4212
|
+
this.emit('beforeTransaction', {
|
|
4213
|
+
editor: this,
|
|
4214
|
+
transaction,
|
|
4215
|
+
nextState: state,
|
|
4216
|
+
});
|
|
4209
4217
|
this.view.updateState(state);
|
|
4210
4218
|
this.emit('transaction', {
|
|
4211
4219
|
editor: this,
|