@tiptap/core 2.1.0 → 2.1.2

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.js CHANGED
@@ -302,8 +302,8 @@ function mergeAttributes(...objects) {
302
302
  return;
303
303
  }
304
304
  if (key === 'class') {
305
- const valueClasses = value.split(' ');
306
- const existingClasses = mergedAttributes[key].split(' ');
305
+ const valueClasses = value ? value.split(' ') : [];
306
+ const existingClasses = mergedAttributes[key] ? mergedAttributes[key].split(' ') : [];
307
307
  const insertClasses = valueClasses.filter(valueClass => !existingClasses.includes(valueClass));
308
308
  mergedAttributes[key] = [...existingClasses, ...insertClasses].join(' ');
309
309
  }
@@ -3983,7 +3983,7 @@ function nodeInputRule(config) {
3983
3983
  return new InputRule({
3984
3984
  find: config.find,
3985
3985
  handler: ({ state, range, match }) => {
3986
- var _a;
3986
+ var _a, _b;
3987
3987
  const attributes = callOrReturn(config.getAttributes, undefined, match) || {};
3988
3988
  const { tr } = state;
3989
3989
  const start = config.blockReplace ? range.from - 1 : range.from;
@@ -4009,9 +4009,7 @@ function nodeInputRule(config) {
4009
4009
  tr.replaceWith(start, end, newNode);
4010
4010
  }
4011
4011
  if (config.blockReplace && config.addExtraNewline) {
4012
- const posAfter = $to.end();
4013
4012
  if ($to.nodeAfter) {
4014
- console.log($to.node().type.name);
4015
4013
  if ($to.nodeAfter.isTextblock) {
4016
4014
  tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1));
4017
4015
  }
@@ -4019,15 +4017,16 @@ function nodeInputRule(config) {
4019
4017
  tr.setSelection(NodeSelection.create(tr.doc, $to.pos));
4020
4018
  }
4021
4019
  else {
4022
- tr.setSelection(TextSelection.create(tr.doc, $to.pos));
4020
+ tr.setSelection(TextSelection.create(tr.doc, $to.pos - 1));
4023
4021
  }
4024
4022
  }
4025
4023
  else {
4026
4024
  // add node after horizontal rule if it’s the end of the document
4027
- const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();
4028
- if (node) {
4029
- tr.insert(posAfter, node);
4030
- tr.setSelection(TextSelection.create(tr.doc, posAfter + 1));
4025
+ const defaultNode = ((_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create()) || ((_b = state.doc.type.contentMatch.defaultType) === null || _b === void 0 ? void 0 : _b.create());
4026
+ if (defaultNode) {
4027
+ const newPos = start + newNode.nodeSize;
4028
+ tr.insert(newPos, defaultNode);
4029
+ tr.setSelection(TextSelection.create(tr.doc, newPos));
4031
4030
  }
4032
4031
  }
4033
4032
  tr.scrollIntoView();