@tiptap/core 2.0.0-beta.159 → 2.0.0-beta.162

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.
@@ -2270,7 +2270,7 @@ function run$1(config) {
2270
2270
  editor,
2271
2271
  state,
2272
2272
  });
2273
- rule.handler({
2273
+ const handler = rule.handler({
2274
2274
  state,
2275
2275
  range,
2276
2276
  match,
@@ -2279,7 +2279,7 @@ function run$1(config) {
2279
2279
  can,
2280
2280
  });
2281
2281
  // stop if there are no changes
2282
- if (!tr.steps.length) {
2282
+ if (handler === null || !tr.steps.length) {
2283
2283
  return;
2284
2284
  }
2285
2285
  // store transform as meta data
@@ -2406,11 +2406,12 @@ const pasteRuleMatcherHandler = (text, find) => {
2406
2406
  });
2407
2407
  };
2408
2408
  function run(config) {
2409
- const { editor, state, from, to, rules, } = config;
2409
+ const { editor, state, from, to, rule, } = config;
2410
2410
  const { commands, chain, can } = new CommandManager({
2411
2411
  editor,
2412
2412
  state,
2413
2413
  });
2414
+ const handlers = [];
2414
2415
  state.doc.nodesBetween(from, to, (node, pos) => {
2415
2416
  if (!node.isTextblock || node.type.spec.code) {
2416
2417
  return;
@@ -2418,29 +2419,30 @@ function run(config) {
2418
2419
  const resolvedFrom = Math.max(from, pos);
2419
2420
  const resolvedTo = Math.min(to, pos + node.content.size);
2420
2421
  const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
2421
- rules.forEach(rule => {
2422
- const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
2423
- matches.forEach(match => {
2424
- if (match.index === undefined) {
2425
- return;
2426
- }
2427
- const start = resolvedFrom + match.index + 1;
2428
- const end = start + match[0].length;
2429
- const range = {
2430
- from: state.tr.mapping.map(start),
2431
- to: state.tr.mapping.map(end),
2432
- };
2433
- rule.handler({
2434
- state,
2435
- range,
2436
- match,
2437
- commands,
2438
- chain,
2439
- can,
2440
- });
2422
+ const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
2423
+ matches.forEach(match => {
2424
+ if (match.index === undefined) {
2425
+ return;
2426
+ }
2427
+ const start = resolvedFrom + match.index + 1;
2428
+ const end = start + match[0].length;
2429
+ const range = {
2430
+ from: state.tr.mapping.map(start),
2431
+ to: state.tr.mapping.map(end),
2432
+ };
2433
+ const handler = rule.handler({
2434
+ state,
2435
+ range,
2436
+ match,
2437
+ commands,
2438
+ chain,
2439
+ can,
2441
2440
  });
2441
+ handlers.push(handler);
2442
2442
  });
2443
2443
  });
2444
+ const success = handlers.every(handler => handler !== null);
2445
+ return success;
2444
2446
  }
2445
2447
  /**
2446
2448
  * Create an paste rules plugin. When enabled, it will cause pasted
@@ -2450,53 +2452,51 @@ function run(config) {
2450
2452
  function pasteRulesPlugin(props) {
2451
2453
  const { editor, rules } = props;
2452
2454
  let isProseMirrorHTML = false;
2453
- const plugin = new Plugin({
2454
- props: {
2455
- handlePaste: (view, event) => {
2456
- var _a;
2457
- const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2458
- isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2459
- return false;
2455
+ const plugins = rules.map(rule => {
2456
+ return new Plugin({
2457
+ props: {
2458
+ handlePaste: (view, event) => {
2459
+ var _a;
2460
+ const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2461
+ isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2462
+ return false;
2463
+ },
2460
2464
  },
2461
- },
2462
- appendTransaction: (transactions, oldState, state) => {
2463
- const transaction = transactions[0];
2464
- // stop if there is not a paste event
2465
- if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2466
- return;
2467
- }
2468
- // stop if there is no changed range
2469
- const { doc, before } = transaction;
2470
- const from = before.content.findDiffStart(doc.content);
2471
- const to = before.content.findDiffEnd(doc.content);
2472
- if (!isNumber(from) || !to || from === to.b) {
2473
- return;
2474
- }
2475
- // build a chainable state
2476
- // so we can use a single transaction for all paste rules
2477
- const tr = state.tr;
2478
- const chainableState = createChainableState({
2479
- state,
2480
- transaction: tr,
2481
- });
2482
- run({
2483
- editor,
2484
- state: chainableState,
2485
- from: Math.max(from - 1, 0),
2486
- to: to.b,
2487
- rules,
2488
- plugin,
2489
- });
2490
- // stop if there are no changes
2491
- if (!tr.steps.length) {
2492
- return;
2493
- }
2494
- return tr;
2495
- },
2496
- // @ts-ignore
2497
- isPasteRules: true,
2465
+ appendTransaction: (transactions, oldState, state) => {
2466
+ const transaction = transactions[0];
2467
+ // stop if there is not a paste event
2468
+ if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2469
+ return;
2470
+ }
2471
+ // stop if there is no changed range
2472
+ const from = oldState.doc.content.findDiffStart(state.doc.content);
2473
+ const to = oldState.doc.content.findDiffEnd(state.doc.content);
2474
+ if (!isNumber(from) || !to || from === to.b) {
2475
+ return;
2476
+ }
2477
+ // build a chainable state
2478
+ // so we can use a single transaction for all paste rules
2479
+ const tr = state.tr;
2480
+ const chainableState = createChainableState({
2481
+ state,
2482
+ transaction: tr,
2483
+ });
2484
+ const handler = run({
2485
+ editor,
2486
+ state: chainableState,
2487
+ from: Math.max(from - 1, 0),
2488
+ to: to.b,
2489
+ rule,
2490
+ });
2491
+ // stop if there are no changes
2492
+ if (!handler || !tr.steps.length) {
2493
+ return;
2494
+ }
2495
+ return tr;
2496
+ },
2497
+ });
2498
2498
  });
2499
- return plugin;
2499
+ return plugins;
2500
2500
  }
2501
2501
 
2502
2502
  /**
@@ -2970,7 +2970,7 @@ class ExtensionManager {
2970
2970
  editor,
2971
2971
  rules: inputRules,
2972
2972
  }),
2973
- pasteRulesPlugin({
2973
+ ...pasteRulesPlugin({
2974
2974
  editor,
2975
2975
  rules: pasteRules,
2976
2976
  }),
@@ -3889,7 +3889,7 @@ function markInputRule(config) {
3889
3889
  handler: ({ state, range, match }) => {
3890
3890
  const attributes = callOrReturn(config.getAttributes, undefined, match);
3891
3891
  if (attributes === false || attributes === null) {
3892
- return;
3892
+ return null;
3893
3893
  }
3894
3894
  const { tr } = state;
3895
3895
  const captureGroup = match[match.length - 1];
@@ -4019,7 +4019,7 @@ function markPasteRule(config) {
4019
4019
  handler: ({ state, range, match }) => {
4020
4020
  const attributes = callOrReturn(config.getAttributes, undefined, match);
4021
4021
  if (attributes === false || attributes === null) {
4022
- return;
4022
+ return null;
4023
4023
  }
4024
4024
  const { tr } = state;
4025
4025
  const captureGroup = match[match.length - 1];