@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 CHANGED
@@ -579,7 +579,7 @@ const getTextContentFromNodes = ($from, maxMatch = 500) => {
579
579
  }))
580
580
  || node.textContent
581
581
  || '%leaf%';
582
- textBefore += chunk.slice(0, Math.max(0, sliceEndPos - pos));
582
+ textBefore += node.isAtom ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
583
583
  });
584
584
  return textBefore;
585
585
  };
@@ -2816,7 +2816,7 @@ function isList(name, extensions) {
2816
2816
  }
2817
2817
 
2818
2818
  function isNodeEmpty(node) {
2819
- const defaultContent = node.type.createAndFill();
2819
+ const defaultContent = node.type.createAndFill(node.attrs);
2820
2820
  if (!defaultContent) {
2821
2821
  return false;
2822
2822
  }
@@ -3018,15 +3018,24 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state: state$1, dispatc
3018
3018
  if (!$from.parent.isBlock) {
3019
3019
  return false;
3020
3020
  }
3021
- if (dispatch) {
3022
- const atEnd = $to.parentOffset === $to.parent.content.size;
3023
- if (selection instanceof state.TextSelection) {
3024
- tr.deleteSelection();
3025
- }
3026
- const deflt = $from.depth === 0
3027
- ? undefined
3028
- : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
3029
- let types = atEnd && deflt
3021
+ const atEnd = $to.parentOffset === $to.parent.content.size;
3022
+ const deflt = $from.depth === 0
3023
+ ? undefined
3024
+ : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
3025
+ let types = atEnd && deflt
3026
+ ? [
3027
+ {
3028
+ type: deflt,
3029
+ attrs: newAttributes,
3030
+ },
3031
+ ]
3032
+ : 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
3030
3039
  ? [
3031
3040
  {
3032
3041
  type: deflt,
@@ -3034,21 +3043,12 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state: state$1, dispatc
3034
3043
  },
3035
3044
  ]
3036
3045
  : undefined;
3037
- let can = transform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
3038
- if (!types
3039
- && !can
3040
- && transform.canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)) {
3041
- can = true;
3042
- types = deflt
3043
- ? [
3044
- {
3045
- type: deflt,
3046
- attrs: newAttributes,
3047
- },
3048
- ]
3049
- : undefined;
3050
- }
3046
+ }
3047
+ if (dispatch) {
3051
3048
  if (can) {
3049
+ if (selection instanceof state.TextSelection) {
3050
+ tr.deleteSelection();
3051
+ }
3052
3052
  tr.split(tr.mapping.map($from.pos), 1, types);
3053
3053
  if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
3054
3054
  const first = tr.mapping.map($from.before());
@@ -3063,7 +3063,7 @@ const splitBlock = ({ keepMarks = true } = {}) => ({ tr, state: state$1, dispatc
3063
3063
  }
3064
3064
  tr.scrollIntoView();
3065
3065
  }
3066
- return true;
3066
+ return can;
3067
3067
  };
3068
3068
 
3069
3069
  const splitListItem = typeOrName => ({ tr, state: state$1, dispatch, editor, }) => {
@@ -4169,6 +4169,9 @@ class Editor extends EventEmitter {
4169
4169
  * Creates all node views.
4170
4170
  */
4171
4171
  createNodeViews() {
4172
+ if (this.view.isDestroyed) {
4173
+ return;
4174
+ }
4172
4175
  this.view.setProps({
4173
4176
  nodeViews: this.extensionManager.nodeViews,
4174
4177
  });
@@ -4208,6 +4211,11 @@ class Editor extends EventEmitter {
4208
4211
  }
4209
4212
  const state = this.state.apply(transaction);
4210
4213
  const selectionHasChanged = !this.state.selection.eq(state.selection);
4214
+ this.emit('beforeTransaction', {
4215
+ editor: this,
4216
+ transaction,
4217
+ nextState: state,
4218
+ });
4211
4219
  this.view.updateState(state);
4212
4220
  this.emit('transaction', {
4213
4221
  editor: this,