@tiptap/core 3.4.4 → 3.4.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.d.cts CHANGED
@@ -51,6 +51,7 @@ declare class InputRule {
51
51
  chain: () => ChainedCommands;
52
52
  can: () => CanCommands;
53
53
  }) => void | null;
54
+ undoable: boolean;
54
55
  constructor(config: {
55
56
  find: InputRuleFinder;
56
57
  handler: (props: {
@@ -61,6 +62,7 @@ declare class InputRule {
61
62
  chain: () => ChainedCommands;
62
63
  can: () => CanCommands;
63
64
  }) => void | null;
65
+ undoable?: boolean;
64
66
  });
65
67
  }
66
68
  /**
@@ -3120,6 +3122,7 @@ declare class CommandManager {
3120
3122
  declare function markInputRule(config: {
3121
3123
  find: InputRuleFinder;
3122
3124
  type: MarkType$1;
3125
+ undoable?: boolean;
3123
3126
  getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
3124
3127
  }): InputRule;
3125
3128
 
@@ -3137,6 +3140,11 @@ declare function nodeInputRule(config: {
3137
3140
  * The node type to add.
3138
3141
  */
3139
3142
  type: NodeType$1;
3143
+ /**
3144
+ * Whether the input rule should be undoable
3145
+ * when the user presses backspace.
3146
+ */
3147
+ undoable?: boolean;
3140
3148
  /**
3141
3149
  * A function that returns the attributes for the node
3142
3150
  * can also be an object of attributes
@@ -3154,6 +3162,7 @@ declare function nodeInputRule(config: {
3154
3162
  declare function textblockTypeInputRule(config: {
3155
3163
  find: InputRuleFinder;
3156
3164
  type: NodeType$1;
3165
+ undoable?: boolean;
3157
3166
  getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
3158
3167
  }): InputRule;
3159
3168
 
@@ -3165,6 +3174,7 @@ declare function textblockTypeInputRule(config: {
3165
3174
  declare function textInputRule(config: {
3166
3175
  find: InputRuleFinder;
3167
3176
  replace: string;
3177
+ undoable?: boolean;
3168
3178
  }): InputRule;
3169
3179
 
3170
3180
  /**
@@ -3188,6 +3198,7 @@ declare function wrappingInputRule(config: {
3188
3198
  keepMarks?: boolean;
3189
3199
  keepAttributes?: boolean;
3190
3200
  editor?: Editor;
3201
+ undoable?: boolean;
3191
3202
  getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
3192
3203
  joinPredicate?: (match: ExtendedRegExpMatchArray, node: Node$1) => boolean;
3193
3204
  }): InputRule;
package/dist/index.d.ts CHANGED
@@ -51,6 +51,7 @@ declare class InputRule {
51
51
  chain: () => ChainedCommands;
52
52
  can: () => CanCommands;
53
53
  }) => void | null;
54
+ undoable: boolean;
54
55
  constructor(config: {
55
56
  find: InputRuleFinder;
56
57
  handler: (props: {
@@ -61,6 +62,7 @@ declare class InputRule {
61
62
  chain: () => ChainedCommands;
62
63
  can: () => CanCommands;
63
64
  }) => void | null;
65
+ undoable?: boolean;
64
66
  });
65
67
  }
66
68
  /**
@@ -3120,6 +3122,7 @@ declare class CommandManager {
3120
3122
  declare function markInputRule(config: {
3121
3123
  find: InputRuleFinder;
3122
3124
  type: MarkType$1;
3125
+ undoable?: boolean;
3123
3126
  getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
3124
3127
  }): InputRule;
3125
3128
 
@@ -3137,6 +3140,11 @@ declare function nodeInputRule(config: {
3137
3140
  * The node type to add.
3138
3141
  */
3139
3142
  type: NodeType$1;
3143
+ /**
3144
+ * Whether the input rule should be undoable
3145
+ * when the user presses backspace.
3146
+ */
3147
+ undoable?: boolean;
3140
3148
  /**
3141
3149
  * A function that returns the attributes for the node
3142
3150
  * can also be an object of attributes
@@ -3154,6 +3162,7 @@ declare function nodeInputRule(config: {
3154
3162
  declare function textblockTypeInputRule(config: {
3155
3163
  find: InputRuleFinder;
3156
3164
  type: NodeType$1;
3165
+ undoable?: boolean;
3157
3166
  getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
3158
3167
  }): InputRule;
3159
3168
 
@@ -3165,6 +3174,7 @@ declare function textblockTypeInputRule(config: {
3165
3174
  declare function textInputRule(config: {
3166
3175
  find: InputRuleFinder;
3167
3176
  replace: string;
3177
+ undoable?: boolean;
3168
3178
  }): InputRule;
3169
3179
 
3170
3180
  /**
@@ -3188,6 +3198,7 @@ declare function wrappingInputRule(config: {
3188
3198
  keepMarks?: boolean;
3189
3199
  keepAttributes?: boolean;
3190
3200
  editor?: Editor;
3201
+ undoable?: boolean;
3191
3202
  getAttributes?: Record<string, any> | ((match: ExtendedRegExpMatchArray) => Record<string, any>) | false | null;
3192
3203
  joinPredicate?: (match: ExtendedRegExpMatchArray, node: Node$1) => boolean;
3193
3204
  }): InputRule;
package/dist/index.js CHANGED
@@ -1568,8 +1568,10 @@ import { Fragment as Fragment2 } from "@tiptap/pm/model";
1568
1568
  import { Plugin } from "@tiptap/pm/state";
1569
1569
  var InputRule = class {
1570
1570
  constructor(config) {
1571
+ var _a;
1571
1572
  this.find = config.find;
1572
1573
  this.handler = config.handler;
1574
+ this.undoable = (_a = config.undoable) != null ? _a : true;
1573
1575
  }
1574
1576
  };
1575
1577
  var inputRuleMatcherHandler = (text, find) => {
@@ -1641,12 +1643,14 @@ function run(config) {
1641
1643
  if (handler === null || !tr.steps.length) {
1642
1644
  return;
1643
1645
  }
1644
- tr.setMeta(plugin, {
1645
- transform: tr,
1646
- from,
1647
- to,
1648
- text
1649
- });
1646
+ if (rule.undoable) {
1647
+ tr.setMeta(plugin, {
1648
+ transform: tr,
1649
+ from,
1650
+ to,
1651
+ text
1652
+ });
1653
+ }
1650
1654
  view.dispatch(tr);
1651
1655
  matched = true;
1652
1656
  });
@@ -2141,7 +2145,7 @@ var ExtensionManager = class {
2141
2145
  get plugins() {
2142
2146
  const { editor } = this;
2143
2147
  const extensions = sortExtensions([...this.extensions].reverse());
2144
- const allPlugins = extensions.map((extension) => {
2148
+ const allPlugins = extensions.flatMap((extension) => {
2145
2149
  const context = {
2146
2150
  name: extension.name,
2147
2151
  options: extension.options,
@@ -2199,7 +2203,7 @@ var ExtensionManager = class {
2199
2203
  plugins.push(...proseMirrorPlugins);
2200
2204
  }
2201
2205
  return plugins;
2202
- }).flat();
2206
+ });
2203
2207
  return allPlugins;
2204
2208
  }
2205
2209
  /**
@@ -4370,6 +4374,9 @@ var Editor = class extends EventEmitter {
4370
4374
  }
4371
4375
  this.createView(el);
4372
4376
  this.emit("mount", { editor: this });
4377
+ if (this.css && !document.head.contains(this.css)) {
4378
+ document.head.appendChild(this.css);
4379
+ }
4373
4380
  window.setTimeout(() => {
4374
4381
  if (this.isDestroyed) {
4375
4382
  return;
@@ -4859,7 +4866,8 @@ function markInputRule(config) {
4859
4866
  tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
4860
4867
  tr.removeStoredMark(config.type);
4861
4868
  }
4862
- }
4869
+ },
4870
+ undoable: config.undoable
4863
4871
  });
4864
4872
  }
4865
4873
 
@@ -4889,7 +4897,8 @@ function nodeInputRule(config) {
4889
4897
  tr.insert(insertionStart, config.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end));
4890
4898
  }
4891
4899
  tr.scrollIntoView();
4892
- }
4900
+ },
4901
+ undoable: config.undoable
4893
4902
  });
4894
4903
  }
4895
4904
 
@@ -4904,7 +4913,8 @@ function textblockTypeInputRule(config) {
4904
4913
  return null;
4905
4914
  }
4906
4915
  state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes);
4907
- }
4916
+ },
4917
+ undoable: config.undoable
4908
4918
  });
4909
4919
  }
4910
4920
 
@@ -4927,7 +4937,8 @@ function textInputRule(config) {
4927
4937
  }
4928
4938
  }
4929
4939
  state.tr.insertText(insert, start, end);
4930
- }
4940
+ },
4941
+ undoable: config.undoable
4931
4942
  });
4932
4943
  }
4933
4944
 
@@ -4963,7 +4974,8 @@ function wrappingInputRule(config) {
4963
4974
  if (before && before.type === config.type && canJoin2(tr.doc, range.from - 1) && (!config.joinPredicate || config.joinPredicate(match, before))) {
4964
4975
  tr.join(range.from - 1);
4965
4976
  }
4966
- }
4977
+ },
4978
+ undoable: config.undoable
4967
4979
  });
4968
4980
  }
4969
4981