@tiptap/core 2.0.0-beta.158 → 2.0.0-beta.161

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