@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.umd.js CHANGED
@@ -575,7 +575,7 @@
575
575
  }))
576
576
  || node.textContent
577
577
  || '%leaf%';
578
- textBefore += chunk.slice(0, Math.max(0, sliceEndPos - pos));
578
+ textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
579
579
  });
580
580
  return textBefore;
581
581
  };
@@ -2812,7 +2812,7 @@
2812
2812
  }
2813
2813
 
2814
2814
  function isNodeEmpty(node) {
2815
- const defaultContent = node.type.createAndFill();
2815
+ const defaultContent = node.type.createAndFill(node.attrs);
2816
2816
  if (!defaultContent) {
2817
2817
  return false;
2818
2818
  }
@@ -3014,15 +3014,24 @@
3014
3014
  if (!$from.parent.isBlock) {
3015
3015
  return false;
3016
3016
  }
3017
- if (dispatch) {
3018
- const atEnd = $to.parentOffset === $to.parent.content.size;
3019
- if (selection instanceof state.TextSelection) {
3020
- tr.deleteSelection();
3021
- }
3022
- const deflt = $from.depth === 0
3023
- ? undefined
3024
- : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
3025
- let types = atEnd && deflt
3017
+ const atEnd = $to.parentOffset === $to.parent.content.size;
3018
+ const deflt = $from.depth === 0
3019
+ ? undefined
3020
+ : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
3021
+ let types = atEnd && deflt
3022
+ ? [
3023
+ {
3024
+ type: deflt,
3025
+ attrs: newAttributes,
3026
+ },
3027
+ ]
3028
+ : undefined;
3029
+ let can = transform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
3030
+ if (!types
3031
+ && !can
3032
+ && transform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
3033
+ can = true;
3034
+ types = deflt
3026
3035
  ? [
3027
3036
  {
3028
3037
  type: deflt,
@@ -3030,21 +3039,12 @@
3030
3039
  },
3031
3040
  ]
3032
3041
  : undefined;
3033
- let can = transform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
3034
- if (!types
3035
- && !can
3036
- && transform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
3037
- can = true;
3038
- types = deflt
3039
- ? [
3040
- {
3041
- type: deflt,
3042
- attrs: newAttributes,
3043
- },
3044
- ]
3045
- : undefined;
3046
- }
3042
+ }
3043
+ if (dispatch) {
3047
3044
  if (can) {
3045
+ if (selection instanceof state.TextSelection) {
3046
+ tr.deleteSelection();
3047
+ }
3048
3048
  tr.split(tr.mapping.map($from.pos), 1, types);
3049
3049
  if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
3050
3050
  const first = tr.mapping.map($from.before());
@@ -3059,7 +3059,7 @@
3059
3059
  }
3060
3060
  tr.scrollIntoView();
3061
3061
  }
3062
- return true;
3062
+ return can;
3063
3063
  };
3064
3064
 
3065
3065
  const splitListItem = typeOrName => ({ tr, state: state$1, dispatch, editor, }) => {
@@ -4165,6 +4165,9 @@ img.ProseMirror-separator {
4165
4165
  * Creates all node views.
4166
4166
  */
4167
4167
  createNodeViews() {
4168
+ if (this.view.isDestroyed) {
4169
+ return;
4170
+ }
4168
4171
  this.view.setProps({
4169
4172
  nodeViews: this.extensionManager.nodeViews,
4170
4173
  });
@@ -4204,6 +4207,11 @@ img.ProseMirror-separator {
4204
4207
  }
4205
4208
  const state = this.state.apply(transaction);
4206
4209
  const selectionHasChanged = !this.state.selection.eq(state.selection);
4210
+ this.emit('beforeTransaction', {
4211
+ editor: this,
4212
+ transaction,
4213
+ nextState: state,
4214
+ });
4207
4215
  this.view.updateState(state);
4208
4216
  this.emit('transaction', {
4209
4217
  editor: this,