1 | import { ExtensionTagType } from '@remirror/core-constants';
|
2 | import type { UseDefault } from '@remirror/core-types';
|
3 | import { AnyExtension, GetMarkNameUnion, GetNameUnion, GetNodeNameUnion, GetPlainNameUnion, PlainExtension } from '../extension';
|
4 | /**
|
5 | * Create the extension tags which are passed into each extensions method to
|
6 | * enable dynamically generated rules and commands.
|
7 | *
|
8 | * Tags on nodes and marks are automatically added to the schema as groups.
|
9 | *
|
10 | * @category Builtin Extension
|
11 | */
|
12 | export declare class TagsExtension extends PlainExtension {
|
13 | get name(): "tags";
|
14 | /**
|
15 | * Track the tags which have been applied to the extensions in this editor.
|
16 | */
|
17 | private allTags;
|
18 | /**
|
19 | * The tags for plain extensions.
|
20 | */
|
21 | private plainTags;
|
22 | /**
|
23 | * The tags for mark extensions.
|
24 | */
|
25 | private markTags;
|
26 | /**
|
27 | * The tags for node extensions.
|
28 | */
|
29 | private nodeTags;
|
30 | /**
|
31 | * Create the tags which are used to identify extension with particular
|
32 | * behavioral traits.
|
33 | */
|
34 | onCreate(): void;
|
35 | /**
|
36 | * Reset the tags to the empty object with empty arrays.
|
37 | */
|
38 | private resetTags;
|
39 | /**
|
40 | * Update the tags object for each extension.
|
41 | */
|
42 | private updateTagForExtension;
|
43 | }
|
44 | /**
|
45 | * Check if the provided string is an extension tag.
|
46 | */
|
47 | export declare function isExtensionTag(value: string): value is ExtensionTagType;
|
48 | /**
|
49 | * The shape of the tag data stored by the extension manager.
|
50 | *
|
51 | * This data can be used by other extensions to dynamically determine which
|
52 | * nodes should affected by commands / plugins / keys etc...
|
53 | */
|
54 | export type CombinedTags<Name extends string = string> = Record<ExtensionTagType, Name[]>;
|
55 | declare global {
|
56 | namespace Remirror {
|
57 | interface ManagerSettings {
|
58 | /**
|
59 | * Add extra tags to the extensions by name. This can be used to add
|
60 | * behavior traits to certain extensions.
|
61 | *
|
62 | * Please note this will change the schema since the tags are added to the
|
63 | * node and mark groups.
|
64 | *
|
65 | * ```ts
|
66 | * RemirrorManager.create(
|
67 | * [],
|
68 | * { extraTags: { bold: [ExtensionTag.Awesome] } }
|
69 | * );
|
70 | * ```
|
71 | */
|
72 | extraTags?: Record<string, ExtensionTagType[]>;
|
73 | }
|
74 | interface BaseExtension {
|
75 | /**
|
76 | * The generated tags for this extension are added here. Do not add this
|
77 | * property to your extensions as it will be overridden.
|
78 | */
|
79 | tags: ExtensionTagType[];
|
80 | /**
|
81 | * Dynamically create tags for the extension.
|
82 | *
|
83 | * Tags are a helpful tool for categorizing the behavior of an extension.
|
84 | * This behavior is later grouped in the `Manager` and passed to the
|
85 | * `extensionStore`. Tags can be used by commands that need to remove all
|
86 | * formatting and use the tag to identify which registered extensions are
|
87 | * formatters.
|
88 | *
|
89 | * @remarks
|
90 | *
|
91 | * Tags are also automatically added to the node and mark extensions as a
|
92 | * group when they are found there.
|
93 | *
|
94 | * There are internally defined tags but it's also possible to define any
|
95 | * custom string as a tag. See [[`ExtensionTag`]].
|
96 | */
|
97 | createTags?(): ExtensionTagType[];
|
98 | }
|
99 | type A = UseDefault<never, string>;
|
100 | interface ManagerStore<Extension extends AnyExtension> {
|
101 | /**
|
102 | * All the tags provided by the configured extensions.
|
103 | */
|
104 | tags: Readonly<CombinedTags<GetNameUnion<Extension> extends never ? string : GetNameUnion<Extension>>>;
|
105 | /**
|
106 | * All the plain extension tags provided for the editor.
|
107 | */
|
108 | plainTags: Readonly<CombinedTags<GetPlainNameUnion<Extension> extends never ? string : GetPlainNameUnion<Extension>>>;
|
109 | /**
|
110 | * All the node extension tags provided for the editor.
|
111 | */
|
112 | nodeTags: Readonly<CombinedTags<GetNodeNameUnion<Extension> extends never ? string : GetNodeNameUnion<Extension>>>;
|
113 | /**
|
114 | * All the mark extension tags provided for the editor.
|
115 | */
|
116 | markTags: Readonly<CombinedTags<GetMarkNameUnion<Extension> extends never ? string : GetMarkNameUnion<Extension>>>;
|
117 | }
|
118 | interface ExtensionStore {
|
119 | /**
|
120 | * All the tags provided by the configured extensions.
|
121 | */
|
122 | tags: CombinedTags;
|
123 | /**
|
124 | * All the plain extension tags provided for the editor.
|
125 | */
|
126 | plainTags: CombinedTags;
|
127 | /**
|
128 | * All the node extension tags provided for the editor.
|
129 | */
|
130 | nodeTags: CombinedTags;
|
131 | /**
|
132 | * All the mark extension tags provided for the editor.
|
133 | */
|
134 | markTags: CombinedTags;
|
135 | }
|
136 | interface BaseExtensionOptions {
|
137 | /**
|
138 | * Add extra tags to the extension.
|
139 | *
|
140 | * Tags can be used to unlock certain behavioural traits for nodes and
|
141 | * marks.
|
142 | *
|
143 | * Please note this will change the schema since the tags are added to the
|
144 | * node and mark groups.
|
145 | */
|
146 | extraTags?: ExtensionTagType[];
|
147 | }
|
148 | interface AllExtensions {
|
149 | tags: TagsExtension;
|
150 | }
|
151 | }
|
152 | }
|