@tiptap/core 3.2.2 → 3.3.1

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
@@ -2035,12 +2035,17 @@ function run2(config) {
2035
2035
  });
2036
2036
  const handlers = [];
2037
2037
  state.doc.nodesBetween(from, to, (node, pos) => {
2038
- if (!node.isTextblock || node.type.spec.code) {
2038
+ var _a, _b, _c, _d, _e;
2039
+ if (((_b = (_a = node.type) == null ? void 0 : _a.spec) == null ? void 0 : _b.code) || !(node.isText || node.isTextblock || node.isInline)) {
2039
2040
  return;
2040
2041
  }
2042
+ const contentSize = (_e = (_d = (_c = node.content) == null ? void 0 : _c.size) != null ? _d : node.nodeSize) != null ? _e : 0;
2041
2043
  const resolvedFrom = Math.max(from, pos);
2042
- const resolvedTo = Math.min(to, pos + node.content.size);
2043
- const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, void 0, "\uFFFC");
2044
+ const resolvedTo = Math.min(to, pos + contentSize);
2045
+ if (resolvedFrom >= resolvedTo) {
2046
+ return;
2047
+ }
2048
+ const textToMatch = node.isText ? node.text || "" : node.textBetween(resolvedFrom - pos, resolvedTo - pos, void 0, "\uFFFC");
2044
2049
  const matches = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent);
2045
2050
  matches.forEach((match) => {
2046
2051
  if (match.index === void 0) {
@@ -2257,8 +2262,6 @@ var ExtensionManager = class {
2257
2262
  get plugins() {
2258
2263
  const { editor } = this;
2259
2264
  const extensions = sortExtensions([...this.extensions].reverse());
2260
- const inputRules = [];
2261
- const pasteRules = [];
2262
2265
  const allPlugins = extensions.map((extension) => {
2263
2266
  const context = {
2264
2267
  name: extension.name,
@@ -2289,11 +2292,23 @@ var ExtensionManager = class {
2289
2292
  plugins.push(keyMapPlugin);
2290
2293
  const addInputRules = getExtensionField(extension, "addInputRules", context);
2291
2294
  if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
2292
- inputRules.push(...addInputRules());
2295
+ const rules = addInputRules();
2296
+ if (rules && rules.length) {
2297
+ const inputResult = inputRulesPlugin({
2298
+ editor,
2299
+ rules
2300
+ });
2301
+ const inputPlugins = Array.isArray(inputResult) ? inputResult : [inputResult];
2302
+ plugins.push(...inputPlugins);
2303
+ }
2293
2304
  }
2294
2305
  const addPasteRules = getExtensionField(extension, "addPasteRules", context);
2295
2306
  if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {
2296
- pasteRules.push(...addPasteRules());
2307
+ const rules = addPasteRules();
2308
+ if (rules && rules.length) {
2309
+ const pasteRules = pasteRulesPlugin({ editor, rules });
2310
+ plugins.push(...pasteRules);
2311
+ }
2297
2312
  }
2298
2313
  const addProseMirrorPlugins = getExtensionField(
2299
2314
  extension,
@@ -2306,17 +2321,7 @@ var ExtensionManager = class {
2306
2321
  }
2307
2322
  return plugins;
2308
2323
  }).flat();
2309
- return [
2310
- inputRulesPlugin({
2311
- editor,
2312
- rules: inputRules
2313
- }),
2314
- ...pasteRulesPlugin({
2315
- editor,
2316
- rules: pasteRules
2317
- }),
2318
- ...allPlugins
2319
- ];
2324
+ return allPlugins;
2320
2325
  }
2321
2326
  /**
2322
2327
  * Get all attributes from the extensions.