1 | import type { AnyFunction, CommandFunction, ConditionalPick, ConditionalReturnPick, EditorSchema, Flavoring, LiteralUnion, NonChainableCommandFunction, ProsemirrorAttributes, StringKey, Transaction, UnionToIntersection } from '@remirror/core-types';
|
2 | import type { CommandShape, GetCommands, GetHelpers } from '../types';
|
3 | import type { AnyExtension, AnyMarkExtension, AnyNodeExtension, AnyPlainExtension } from './extension';
|
4 | export interface ExtensionListProps<Extension extends AnyExtension = AnyExtension> {
|
5 | |
6 |
|
7 |
|
8 | readonly extensions: readonly Extension[];
|
9 | }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export declare type MapToUnchainedCommand<RawCommands extends Record<string, AnyFunction>> = {
|
15 | [Command in keyof RawCommands]: CommandShape<Parameters<RawCommands[Command]>>;
|
16 | };
|
17 |
|
18 |
|
19 |
|
20 | export declare type MapToChainedCommand<RawCommands extends Record<string, AnyFunction>> = {
|
21 | [Command in keyof RawCommands]: ReturnType<RawCommands[Command]> extends NonChainableCommandFunction ? void : (...args: Parameters<RawCommands[Command]>) => any;
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | export declare type CommandsFromExtensions<Extension extends AnyExtension, Expanded extends AnyExtension = GetExtensions<Extension>> = UnionToIntersection<MapToUnchainedCommand<GetCommands<Expanded> | GetDecoratedCommands<Expanded>>>;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | declare type GetDecoratedCommands<Type> = Type extends AnyExtension ? ConditionalPick<Type, AnyFunction<CommandFunction>> : never;
|
44 | interface UiAnnotation {
|
45 | __uiAnnotation?: never;
|
46 | }
|
47 | export declare type UiCommandFunction = CommandFunction & UiAnnotation;
|
48 | declare type GetDecoratedUiCommands<Type> = Type extends AnyExtension ? ConditionalPick<Type, AnyFunction<UiCommandFunction>> : never;
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | export declare type UiCommandNames<Extension extends AnyExtension> = StringKey<ConditionalPick<{
|
55 | [P in keyof UnionToIntersection<GetDecoratedUiCommands<Extension>>]: keyof UnionToIntersection<GetDecoratedUiCommands<Extension>>[P] extends '__uiAnnotation' ? true : false;
|
56 | }, true>>;
|
57 | export interface ChainedCommandProps {
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | run: (options?: {
|
72 | exitEarly?: boolean;
|
73 | }) => void;
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 | tr: () => Transaction;
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | enabled: () => boolean;
|
91 | }
|
92 | export declare type ChainedIntersection<Extension extends AnyExtension> = UnionToIntersection<MapToChainedCommand<GetCommands<Extension> | GetDecoratedCommands<Extension>>>;
|
93 | export declare type ChainedFromExtensions<Extension extends AnyExtension, Chained extends ChainedIntersection<Extension> = ChainedIntersection<Extension>> = _ChainedFromExtensions<Extension, Chained> & ((tr: Transaction) => _ChainedFromExtensions<Extension, Chained>);
|
94 | declare type _ChainedFromExtensions<Extension extends AnyExtension, Chained extends ChainedIntersection<Extension> = ChainedIntersection<Extension>> = ChainedCommandProps & {
|
95 | [Command in keyof Chained]: Chained[Command] extends (...args: any[]) => any ? (...args: Parameters<Chained[Command]>) => ChainedFromExtensions<Extension> : never;
|
96 | };
|
97 |
|
98 |
|
99 |
|
100 | export declare type CommandNames<Extension extends AnyExtension> = StringKey<CommandsFromExtensions<Extension>>;
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export declare type MapHelpers<RawHelpers extends Record<string, AnyFunction>> = {
|
106 | [Helper in keyof RawHelpers]: RawHelpers[Helper];
|
107 | };
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | export declare type HelpersFromExtensions<Extension extends AnyExtension, Expanded extends AnyExtension = GetExtensions<Extension>> = UnionToIntersection<MapHelpers<GetHelpers<Expanded> | GetDecoratedHelpers<Expanded>>>;
|
118 | export declare type HelperAnnotation = Flavoring<'HelperAnnotation'>;
|
119 |
|
120 |
|
121 |
|
122 | export declare type Helper<Type> = Type extends null | undefined ? Type : Type & HelperAnnotation;
|
123 |
|
124 |
|
125 |
|
126 | declare type RemoveHelper<Type> = Type extends Helper<infer T> ? T : Type;
|
127 | declare type RemoveHelpers<Type extends Record<string, AnyFunction>> = {
|
128 | [Key in keyof Type]: (...args: Parameters<Type[Key]>) => RemoveHelper<ReturnType<Type[Key]>>;
|
129 | };
|
130 |
|
131 |
|
132 |
|
133 | export declare type HelperFunction<Type extends HelperAnnotation = HelperAnnotation> = AnyFunction<Type>;
|
134 | declare type GetDecoratedHelpers<Type> = Type extends object ? RemoveHelpers<ConditionalReturnPick<Type, HelperAnnotation>> : never;
|
135 |
|
136 |
|
137 |
|
138 | export declare type HelperNames<Extension extends AnyExtension> = StringKey<HelpersFromExtensions<Extension>>;
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | export declare type RemoveAny<Extension> = Extension extends Extension ? AnyExtension extends Extension ? never : Extension : never;
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | export declare type GetExtensions<Extension> = AnyExtension extends Extension ? AnyExtension : Extension extends AnyExtension ?
|
155 | Extension | GetExtensions<Extension['~E']> : AnyExtension;
|
156 |
|
157 |
|
158 |
|
159 | export declare type ActiveFromExtensions<Extension extends AnyExtension> = Record<GetNodeNameUnion<Extension> extends never ? string : GetNodeNameUnion<Extension>, (attrs?: ProsemirrorAttributes) => boolean> & Record<GetMarkNameUnion<Extension> extends never ? string : GetMarkNameUnion<Extension>, (attrs?: ProsemirrorAttributes) => boolean>;
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | export declare type AttrsFromExtensions<Extension extends AnyExtension> = Record<GetNodeNameUnion<Extension> extends never ? string : GetNodeNameUnion<Extension>, (attrs?: ProsemirrorAttributes) => ProsemirrorAttributes | undefined> & Record<GetMarkNameUnion<Extension> extends never ? string : GetMarkNameUnion<Extension>, (attrs?: ProsemirrorAttributes) => ProsemirrorAttributes | undefined>;
|
165 |
|
166 |
|
167 |
|
168 | export declare type GetNameUnion<Extension extends AnyExtension> = GetExtensions<Extension>['name'];
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | export declare type GetPlainNameUnion<Extension extends AnyExtension, Expanded extends AnyExtension = GetExtensions<Extension>> = Expanded extends AnyPlainExtension ? Expanded['name'] : never;
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | export declare type GetMarkNameUnion<Extension extends AnyExtension, Expanded extends AnyExtension = GetExtensions<Extension>> = Expanded extends AnyMarkExtension ? Expanded['name'] : never;
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | export declare type GetNodeNameUnion<Extension extends AnyExtension, Expanded extends AnyExtension = GetExtensions<Extension>> = Expanded extends AnyNodeExtension ? Expanded['name'] : never;
|
199 |
|
200 |
|
201 |
|
202 | export declare type GetSchema<Extension extends AnyExtension> = EditorSchema<LiteralUnion<GetNodeNameUnion<Extension>, string>, LiteralUnion<GetMarkNameUnion<Extension>, string>>;
|
203 | declare global {
|
204 | namespace Remirror {
|
205 | |
206 |
|
207 |
|
208 |
|
209 | type NameUnion = LiteralUnion<GetNameUnion<Extensions>, string>;
|
210 | |
211 |
|
212 |
|
213 |
|
214 | type PlainNameUnion = LiteralUnion<GetPlainNameUnion<Extensions>, string>;
|
215 | |
216 |
|
217 |
|
218 |
|
219 | type NodeNameUnion = LiteralUnion<GetNodeNameUnion<Extensions>, string>;
|
220 | |
221 |
|
222 |
|
223 |
|
224 | type MarkNameUnion = LiteralUnion<GetMarkNameUnion<Extensions>, string>;
|
225 | }
|
226 | }
|
227 | export {};
|