@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.
@@ -18,7 +18,7 @@ export declare class InputRule {
18
18
  commands: SingleCommands;
19
19
  chain: () => ChainedCommands;
20
20
  can: () => CanCommands;
21
- }) => void;
21
+ }) => void | null;
22
22
  constructor(config: {
23
23
  find: InputRuleFinder;
24
24
  handler: (props: {
@@ -28,7 +28,7 @@ export declare class InputRule {
28
28
  commands: SingleCommands;
29
29
  chain: () => ChainedCommands;
30
30
  can: () => CanCommands;
31
- }) => void;
31
+ }) => void | null;
32
32
  });
33
33
  }
34
34
  /**
@@ -309,6 +309,15 @@ declare module '@tiptap/core' {
309
309
  storage: Storage;
310
310
  parent: ParentConfig<NodeConfig<Options, Storage>>['code'];
311
311
  }) => NodeSpec['code']);
312
+ /**
313
+ * Whitespace
314
+ */
315
+ whitespace?: NodeSpec['whitespace'] | ((this: {
316
+ name: string;
317
+ options: Options;
318
+ storage: Storage;
319
+ parent: ParentConfig<NodeConfig<Options, Storage>>['whitespace'];
320
+ }) => NodeSpec['whitespace']);
312
321
  /**
313
322
  * Defining
314
323
  */
@@ -18,7 +18,7 @@ export declare class PasteRule {
18
18
  commands: SingleCommands;
19
19
  chain: () => ChainedCommands;
20
20
  can: () => CanCommands;
21
- }) => void;
21
+ }) => void | null;
22
22
  constructor(config: {
23
23
  find: PasteRuleFinder;
24
24
  handler: (props: {
@@ -28,7 +28,7 @@ export declare class PasteRule {
28
28
  commands: SingleCommands;
29
29
  chain: () => ChainedCommands;
30
30
  can: () => CanCommands;
31
- }) => void;
31
+ }) => void | null;
32
32
  });
33
33
  }
34
34
  /**
@@ -39,4 +39,4 @@ export declare class PasteRule {
39
39
  export declare function pasteRulesPlugin(props: {
40
40
  editor: Editor;
41
41
  rules: PasteRule[];
42
- }): Plugin;
42
+ }): Plugin[];
@@ -2252,7 +2252,7 @@ function run$1(config) {
2252
2252
  }
2253
2253
  let matched = false;
2254
2254
  const maxMatch = 500;
2255
- const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - maxMatch), $from.parentOffset, undefined, '\ufffc') + text;
2255
+ const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - maxMatch), $from.parentOffset, undefined, ' ') + text;
2256
2256
  rules.forEach(rule => {
2257
2257
  if (matched) {
2258
2258
  return;
@@ -2274,7 +2274,7 @@ function run$1(config) {
2274
2274
  editor,
2275
2275
  state,
2276
2276
  });
2277
- rule.handler({
2277
+ const handler = rule.handler({
2278
2278
  state,
2279
2279
  range,
2280
2280
  match,
@@ -2283,7 +2283,7 @@ function run$1(config) {
2283
2283
  can,
2284
2284
  });
2285
2285
  // stop if there are no changes
2286
- if (!tr.steps.length) {
2286
+ if (handler === null || !tr.steps.length) {
2287
2287
  return;
2288
2288
  }
2289
2289
  // store transform as meta data
@@ -2410,11 +2410,12 @@ const pasteRuleMatcherHandler = (text, find) => {
2410
2410
  });
2411
2411
  };
2412
2412
  function run(config) {
2413
- const { editor, state, from, to, rules, } = config;
2413
+ const { editor, state, from, to, rule, } = config;
2414
2414
  const { commands, chain, can } = new CommandManager({
2415
2415
  editor,
2416
2416
  state,
2417
2417
  });
2418
+ const handlers = [];
2418
2419
  state.doc.nodesBetween(from, to, (node, pos) => {
2419
2420
  if (!node.isTextblock || node.type.spec.code) {
2420
2421
  return;
@@ -2422,29 +2423,30 @@ function run(config) {
2422
2423
  const resolvedFrom = Math.max(from, pos);
2423
2424
  const resolvedTo = Math.min(to, pos + node.content.size);
2424
2425
  const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
2425
- rules.forEach(rule => {
2426
- const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
2427
- matches.forEach(match => {
2428
- if (match.index === undefined) {
2429
- return;
2430
- }
2431
- const start = resolvedFrom + match.index + 1;
2432
- const end = start + match[0].length;
2433
- const range = {
2434
- from: state.tr.mapping.map(start),
2435
- to: state.tr.mapping.map(end),
2436
- };
2437
- rule.handler({
2438
- state,
2439
- range,
2440
- match,
2441
- commands,
2442
- chain,
2443
- can,
2444
- });
2426
+ const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
2427
+ matches.forEach(match => {
2428
+ if (match.index === undefined) {
2429
+ return;
2430
+ }
2431
+ const start = resolvedFrom + match.index + 1;
2432
+ const end = start + match[0].length;
2433
+ const range = {
2434
+ from: state.tr.mapping.map(start),
2435
+ to: state.tr.mapping.map(end),
2436
+ };
2437
+ const handler = rule.handler({
2438
+ state,
2439
+ range,
2440
+ match,
2441
+ commands,
2442
+ chain,
2443
+ can,
2445
2444
  });
2445
+ handlers.push(handler);
2446
2446
  });
2447
2447
  });
2448
+ const success = handlers.every(handler => handler !== null);
2449
+ return success;
2448
2450
  }
2449
2451
  /**
2450
2452
  * Create an paste rules plugin. When enabled, it will cause pasted
@@ -2454,53 +2456,51 @@ function run(config) {
2454
2456
  function pasteRulesPlugin(props) {
2455
2457
  const { editor, rules } = props;
2456
2458
  let isProseMirrorHTML = false;
2457
- const plugin = new prosemirrorState.Plugin({
2458
- props: {
2459
- handlePaste: (view, event) => {
2460
- var _a;
2461
- const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2462
- isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2463
- return false;
2459
+ const plugins = rules.map(rule => {
2460
+ return new prosemirrorState.Plugin({
2461
+ props: {
2462
+ handlePaste: (view, event) => {
2463
+ var _a;
2464
+ const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
2465
+ isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
2466
+ return false;
2467
+ },
2464
2468
  },
2465
- },
2466
- appendTransaction: (transactions, oldState, state) => {
2467
- const transaction = transactions[0];
2468
- // stop if there is not a paste event
2469
- if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2470
- return;
2471
- }
2472
- // stop if there is no changed range
2473
- const { doc, before } = transaction;
2474
- const from = before.content.findDiffStart(doc.content);
2475
- const to = before.content.findDiffEnd(doc.content);
2476
- if (!isNumber(from) || !to || from === to.b) {
2477
- return;
2478
- }
2479
- // build a chainable state
2480
- // so we can use a single transaction for all paste rules
2481
- const tr = state.tr;
2482
- const chainableState = createChainableState({
2483
- state,
2484
- transaction: tr,
2485
- });
2486
- run({
2487
- editor,
2488
- state: chainableState,
2489
- from: Math.max(from - 1, 0),
2490
- to: to.b,
2491
- rules,
2492
- plugin,
2493
- });
2494
- // stop if there are no changes
2495
- if (!tr.steps.length) {
2496
- return;
2497
- }
2498
- return tr;
2499
- },
2500
- // @ts-ignore
2501
- isPasteRules: true,
2469
+ appendTransaction: (transactions, oldState, state) => {
2470
+ const transaction = transactions[0];
2471
+ // stop if there is not a paste event
2472
+ if (!transaction.getMeta('paste') || isProseMirrorHTML) {
2473
+ return;
2474
+ }
2475
+ // stop if there is no changed range
2476
+ const from = oldState.doc.content.findDiffStart(state.doc.content);
2477
+ const to = oldState.doc.content.findDiffEnd(state.doc.content);
2478
+ if (!isNumber(from) || !to || from === to.b) {
2479
+ return;
2480
+ }
2481
+ // build a chainable state
2482
+ // so we can use a single transaction for all paste rules
2483
+ const tr = state.tr;
2484
+ const chainableState = createChainableState({
2485
+ state,
2486
+ transaction: tr,
2487
+ });
2488
+ const handler = run({
2489
+ editor,
2490
+ state: chainableState,
2491
+ from: Math.max(from - 1, 0),
2492
+ to: to.b,
2493
+ rule,
2494
+ });
2495
+ // stop if there are no changes
2496
+ if (!handler || !tr.steps.length) {
2497
+ return;
2498
+ }
2499
+ return tr;
2500
+ },
2501
+ });
2502
2502
  });
2503
- return plugin;
2503
+ return plugins;
2504
2504
  }
2505
2505
 
2506
2506
  /**
@@ -2974,7 +2974,7 @@ class ExtensionManager {
2974
2974
  editor,
2975
2975
  rules: inputRules,
2976
2976
  }),
2977
- pasteRulesPlugin({
2977
+ ...pasteRulesPlugin({
2978
2978
  editor,
2979
2979
  rules: pasteRules,
2980
2980
  }),
@@ -3893,7 +3893,7 @@ function markInputRule(config) {
3893
3893
  handler: ({ state, range, match }) => {
3894
3894
  const attributes = callOrReturn(config.getAttributes, undefined, match);
3895
3895
  if (attributes === false || attributes === null) {
3896
- return;
3896
+ return null;
3897
3897
  }
3898
3898
  const { tr } = state;
3899
3899
  const captureGroup = match[match.length - 1];
@@ -4023,7 +4023,7 @@ function markPasteRule(config) {
4023
4023
  handler: ({ state, range, match }) => {
4024
4024
  const attributes = callOrReturn(config.getAttributes, undefined, match);
4025
4025
  if (attributes === false || attributes === null) {
4026
- return;
4026
+ return null;
4027
4027
  }
4028
4028
  const { tr } = state;
4029
4029
  const captureGroup = match[match.length - 1];