UNPKG

2.93 kBTypeScriptView Raw
1import type { Handler, ProsemirrorPlugin } from '@remirror/core-types';
2import type { ShouldSkipFunction } from '@remirror/core-utils';
3import { InputRule } from '@remirror/pm/inputrules';
4import { PlainExtension } from '../extension';
5export interface InputRulesOptions {
6 /**
7 * Handlers which can be registered to check whether an input rule should be
8 * active at this time.
9 *
10 * The handlers are given a parameter with the current `state`, the `fullMatch`
11 * and the `captureGroup` and can determine whether the input rule should
12 * still be run.
13 *
14 * Return `true` to prevent any active input rules from being triggered.
15 */
16 shouldSkipInputRule?: Handler<ShouldSkipFunction>;
17}
18/**
19 * This extension allows others extension to add the `createInputRules` method
20 * for automatically transforming text when a certain regex pattern is typed.
21 *
22 * @remarks
23 *
24 * This is an example of adding custom functionality to an extension via the
25 * `ExtensionParameterMethods`.
26 *
27 * @category Builtin Extension
28 */
29export declare class InputRulesExtension extends PlainExtension<InputRulesOptions> {
30 get name(): "inputRules";
31 /**
32 * Add the extension store method for rebuilding all input rules.
33 */
34 onCreate(): void;
35 /**
36 * Add the `inputRules` plugin to the editor.
37 */
38 createExternalPlugins(): ProsemirrorPlugin[];
39 private generateInputRulesPlugin;
40 /**
41 * The method for rebuilding all the input rules.
42 *
43 * 1. Rebuild inputRules.
44 * 2. Replace the old input rules plugin.
45 * 3. Update the plugins used in the state (triggers an editor update).
46 */
47 private rebuildInputRules;
48}
49declare global {
50 namespace Remirror {
51 interface ExcludeOptions {
52 /**
53 * Whether to use the inputRules for this particular extension.
54 *
55 * @defaultValue undefined
56 */
57 inputRules?: boolean;
58 }
59 interface ExtensionStore {
60 /**
61 * When called this will run through every `createInputRules` method on every
62 * extension to recreate input rules.
63 *
64 * @remarks
65 *
66 * Under the hood it updates the plugin which is used to insert the
67 * input rules into the editor. This causes the state to be updated and
68 * will cause a rerender in your ui framework.
69 */
70 rebuildInputRules: () => void;
71 }
72 interface BaseExtension {
73 /**
74 * Register input rules which are activated if the regex matches as a user is
75 * typing.
76 *
77 * @param parameter - schema parameter with type included
78 */
79 createInputRules?(): InputRule[];
80 }
81 interface AllExtensions {
82 inputRules: InputRulesExtension;
83 }
84 }
85}