UNPKG

3.54 kBTypeScriptView Raw
1import type { CustomHandler, EditorState, ProsemirrorPlugin } from '@remirror/core-types';
2import { Suggester, SuggestState } from '@remirror/pm/suggest';
3import { Helper, PlainExtension } from '../extension';
4import type { AddCustomHandler } from '../extension/base-class';
5export interface SuggestOptions {
6 /**
7 * The custom handler which enables adding `suggesters`.
8 */
9 suggester: CustomHandler<Suggester>;
10}
11/**
12 * This extension allows others extension to add the `createSuggesters` method
13 * for adding the prosemirror-suggest functionality to your editor.
14 *
15 * @remarks
16 *
17 * This is an example of adding custom functionality to an extension via the
18 * `ExtensionParameterMethods`.
19 *
20 * @category Builtin Extension
21 */
22export declare class SuggestExtension extends PlainExtension<SuggestOptions> {
23 get name(): "suggest";
24 /**
25 * Create the `addSuggester` method and `removeSuggester` methods to the
26 * extension store.
27 *
28 * This can be used by extensions to conditionally add suggestion support.
29 */
30 onCreate(): void;
31 /**
32 * Add the `prosemirror-suggest` plugin to the editor.
33 */
34 createExternalPlugins(): ProsemirrorPlugin[];
35 /**
36 * Allow additional `Suggesters` to be added to the editor. This can be used
37 * by `React` to create hooks.
38 */
39 onAddCustomHandler: AddCustomHandler<SuggestOptions>;
40 /**
41 * Get the suggest plugin state.
42 *
43 * This may be removed at a later time.
44 *
45 * @experimental
46 */
47 getSuggestState(state?: EditorState): Helper<SuggestState>;
48 /**
49 * Get some helpful methods from the SuggestPluginState.
50 */
51 getSuggestMethods(): Helper<Pick<SuggestState, 'addIgnored' | 'clearIgnored' | 'removeIgnored' | 'ignoreNextExit' | 'setMarkRemoved' | 'findMatchAtPosition' | 'findNextTextSelection' | 'setLastChangeFromAppend'>>;
52 /**
53 * Check to see whether the provided name is the currently active
54 * suggester.
55 *
56 * @param name - the name of the suggester to include
57 */
58 isSuggesterActive(name: string | string[]): Helper<boolean>;
59}
60declare global {
61 namespace Remirror {
62 interface ExcludeOptions {
63 /**
64 * Whether to exclude the suggesters plugin configuration for the
65 * extension.
66 *
67 * @default undefined
68 */
69 suggesters?: boolean;
70 }
71 interface BaseExtension {
72 /**
73 * Create suggesters which respond to an activation `char` or regex
74 * pattern within the editor instance. The onChange handler provided is
75 * called with the data around the matching text.
76 *
77 * @remarks
78 *
79 * Suggesters are a powerful way of building up the editors
80 * functionality. They can support `@` mentions, `#` tagging, `/` special
81 * command keys which trigger action menus and much more.
82 */
83 createSuggesters?(): Suggester[] | Suggester;
84 }
85 interface AllExtensions {
86 suggest: SuggestExtension;
87 }
88 interface ExtensionStore {
89 /**
90 * Add a suggester.
91 */
92 addSuggester(suggester: Suggester): void;
93 /**
94 * Remove a suggester.
95 */
96 removeSuggester(suggester: Suggester | string): void;
97 }
98 interface AllExtensions {
99 suggest: SuggestExtension;
100 }
101 }
102}