@tiptap/core 2.5.9 → 2.6.0

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
@@ -3106,7 +3106,7 @@
3106
3106
  return can;
3107
3107
  };
3108
3108
 
3109
- const splitListItem = typeOrName => ({ tr, state: state$1, dispatch, editor, }) => {
3109
+ const splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state: state$1, dispatch, editor, }) => {
3110
3110
  var _a;
3111
3111
  const type = getNodeType(typeOrName, state$1.schema);
3112
3112
  const { $from, $to } = state$1.selection;
@@ -3142,7 +3142,10 @@
3142
3142
  // eslint-disable-next-line
3143
3143
  const depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3;
3144
3144
  // Add a second list item with an empty default start node
3145
- const newNextTypeAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs);
3145
+ const newNextTypeAttributes = {
3146
+ ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
3147
+ ...overrideAttrs,
3148
+ };
3146
3149
  const nextType = ((_a = type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.createAndFill(newNextTypeAttributes)) || undefined;
3147
3150
  wrap = wrap.append(model.Fragment.from(type.createAndFill(null, nextType) || undefined));
3148
3151
  const start = $from.before($from.depth - (depthBefore - 1));
@@ -3164,8 +3167,14 @@
3164
3167
  return true;
3165
3168
  }
3166
3169
  const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
3167
- const newTypeAttributes = getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs);
3168
- const newNextTypeAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs);
3170
+ const newTypeAttributes = {
3171
+ ...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),
3172
+ ...overrideAttrs,
3173
+ };
3174
+ const newNextTypeAttributes = {
3175
+ ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
3176
+ ...overrideAttrs,
3177
+ };
3169
3178
  tr.delete($from.pos, $to.pos);
3170
3179
  const types = nextType
3171
3180
  ? [
@@ -3967,6 +3976,10 @@ img.ProseMirror-separator {
3967
3976
  constructor(options = {}) {
3968
3977
  super();
3969
3978
  this.isFocused = false;
3979
+ /**
3980
+ * The editor is considered initialized after the `create` event has been emitted.
3981
+ */
3982
+ this.isInitialized = false;
3970
3983
  this.extensionStorage = {};
3971
3984
  this.options = {
3972
3985
  element: document.createElement('div'),
@@ -4017,6 +4030,7 @@ img.ProseMirror-separator {
4017
4030
  }
4018
4031
  this.commands.focus(this.options.autofocus);
4019
4032
  this.emit('create', { editor: this });
4033
+ this.isInitialized = true;
4020
4034
  }, 0);
4021
4035
  }
4022
4036
  /**
@@ -4984,14 +4998,16 @@ img.ProseMirror-separator {
4984
4998
  find: config.find,
4985
4999
  handler({ match, chain, range, pasteEvent, }) {
4986
5000
  const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent);
5001
+ const content = callOrReturn(config.getContent, undefined, attributes);
4987
5002
  if (attributes === false || attributes === null) {
4988
5003
  return null;
4989
5004
  }
5005
+ const node = { type: config.type.name, attrs: attributes };
5006
+ if (content) {
5007
+ node.content = content;
5008
+ }
4990
5009
  if (match.input) {
4991
- chain().deleteRange(range).insertContentAt(range.from, {
4992
- type: config.type.name,
4993
- attrs: attributes,
4994
- });
5010
+ chain().deleteRange(range).insertContentAt(range.from, node);
4995
5011
  }
4996
5012
  },
4997
5013
  });