@tiptap/core 2.5.8 → 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
@@ -962,7 +962,7 @@
962
962
 
963
963
  function findDuplicates(items) {
964
964
  const filtered = items.filter((el, index) => items.indexOf(el) !== index);
965
- return [...new Set(filtered)];
965
+ return Array.from(new Set(filtered));
966
966
  }
967
967
 
968
968
  class ExtensionManager {
@@ -2632,7 +2632,7 @@
2632
2632
  .resolve(from)
2633
2633
  .marks()
2634
2634
  .forEach(mark => {
2635
- const $pos = doc.resolve(from - 1);
2635
+ const $pos = doc.resolve(from);
2636
2636
  const range = getMarkRange($pos, mark.type);
2637
2637
  if (!range) {
2638
2638
  return;
@@ -2825,31 +2825,40 @@
2825
2825
  }
2826
2826
 
2827
2827
  /**
2828
- * Returns true if the given node is empty.
2829
- * When `checkChildren` is true (default), it will also check if all children are empty.
2828
+ * Returns true if the given prosemirror node is empty.
2830
2829
  */
2831
- function isNodeEmpty(node, { checkChildren } = { checkChildren: true }) {
2830
+ function isNodeEmpty(node, { checkChildren = true, ignoreWhitespace = false, } = {}) {
2831
+ var _a;
2832
+ if (ignoreWhitespace) {
2833
+ if (node.type.name === 'hardBreak') {
2834
+ // Hard breaks are considered empty
2835
+ return true;
2836
+ }
2837
+ if (node.isText) {
2838
+ return /^\s*$/m.test((_a = node.text) !== null && _a !== void 0 ? _a : '');
2839
+ }
2840
+ }
2832
2841
  if (node.isText) {
2833
2842
  return !node.text;
2834
2843
  }
2844
+ if (node.isAtom || node.isLeaf) {
2845
+ return false;
2846
+ }
2835
2847
  if (node.content.childCount === 0) {
2836
2848
  return true;
2837
2849
  }
2838
- if (node.isLeaf) {
2839
- return false;
2840
- }
2841
2850
  if (checkChildren) {
2842
- let hasSameContent = true;
2851
+ let isContentEmpty = true;
2843
2852
  node.content.forEach(childNode => {
2844
- if (hasSameContent === false) {
2853
+ if (isContentEmpty === false) {
2845
2854
  // Exit early for perf
2846
2855
  return;
2847
2856
  }
2848
- if (!isNodeEmpty(childNode)) {
2849
- hasSameContent = false;
2857
+ if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
2858
+ isContentEmpty = false;
2850
2859
  }
2851
2860
  });
2852
- return hasSameContent;
2861
+ return isContentEmpty;
2853
2862
  }
2854
2863
  return false;
2855
2864
  }
@@ -3097,7 +3106,7 @@
3097
3106
  return can;
3098
3107
  };
3099
3108
 
3100
- const splitListItem = typeOrName => ({ tr, state: state$1, dispatch, editor, }) => {
3109
+ const splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state: state$1, dispatch, editor, }) => {
3101
3110
  var _a;
3102
3111
  const type = getNodeType(typeOrName, state$1.schema);
3103
3112
  const { $from, $to } = state$1.selection;
@@ -3133,7 +3142,10 @@
3133
3142
  // eslint-disable-next-line
3134
3143
  const depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3;
3135
3144
  // Add a second list item with an empty default start node
3136
- 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
+ };
3137
3149
  const nextType = ((_a = type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.createAndFill(newNextTypeAttributes)) || undefined;
3138
3150
  wrap = wrap.append(model.Fragment.from(type.createAndFill(null, nextType) || undefined));
3139
3151
  const start = $from.before($from.depth - (depthBefore - 1));
@@ -3155,8 +3167,14 @@
3155
3167
  return true;
3156
3168
  }
3157
3169
  const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
3158
- const newTypeAttributes = getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs);
3159
- 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
+ };
3160
3178
  tr.delete($from.pos, $to.pos);
3161
3179
  const types = nextType
3162
3180
  ? [
@@ -3958,6 +3976,10 @@ img.ProseMirror-separator {
3958
3976
  constructor(options = {}) {
3959
3977
  super();
3960
3978
  this.isFocused = false;
3979
+ /**
3980
+ * The editor is considered initialized after the `create` event has been emitted.
3981
+ */
3982
+ this.isInitialized = false;
3961
3983
  this.extensionStorage = {};
3962
3984
  this.options = {
3963
3985
  element: document.createElement('div'),
@@ -4008,6 +4030,7 @@ img.ProseMirror-separator {
4008
4030
  }
4009
4031
  this.commands.focus(this.options.autofocus);
4010
4032
  this.emit('create', { editor: this });
4033
+ this.isInitialized = true;
4011
4034
  }, 0);
4012
4035
  }
4013
4036
  /**
@@ -4975,14 +4998,16 @@ img.ProseMirror-separator {
4975
4998
  find: config.find,
4976
4999
  handler({ match, chain, range, pasteEvent, }) {
4977
5000
  const attributes = callOrReturn(config.getAttributes, undefined, match, pasteEvent);
5001
+ const content = callOrReturn(config.getContent, undefined, attributes);
4978
5002
  if (attributes === false || attributes === null) {
4979
5003
  return null;
4980
5004
  }
5005
+ const node = { type: config.type.name, attrs: attributes };
5006
+ if (content) {
5007
+ node.content = content;
5008
+ }
4981
5009
  if (match.input) {
4982
- chain().deleteRange(range).insertContentAt(range.from, {
4983
- type: config.type.name,
4984
- attrs: attributes,
4985
- });
5010
+ chain().deleteRange(range).insertContentAt(range.from, node);
4986
5011
  }
4987
5012
  },
4988
5013
  });