/
PluginState.ts
38 lines (32 loc) · 1.02 KB
/
PluginState.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { PluginWithState } from '../editor/PluginWithState';
import type { EditorCorePlugins } from '../editor/EditorCorePlugins';
/**
* Names of core plugins
*/
export type PluginKey = keyof EditorCorePlugins;
/**
* Names of the core plugins that have plugin state
*/
export type KeyOfStatePlugin<
Key extends PluginKey
> = EditorCorePlugins[Key] extends PluginWithState<infer U> ? Key : never;
/**
* Get type of a plugin with state
*/
export type TypeOfStatePlugin<
Key extends PluginKey
> = EditorCorePlugins[Key] extends PluginWithState<infer U> ? U : never;
/**
* All names of plugins with plugin state
*/
export type StatePluginKeys<Key extends PluginKey> = { [P in Key]: KeyOfStatePlugin<P> }[Key];
/**
* A type map from name of plugin with state to its plugin type
*/
export type GenericPluginState<Key extends PluginKey> = {
[P in StatePluginKeys<Key>]: TypeOfStatePlugin<P>;
};
/**
* Auto-calculated State object type for plugin with states
*/
export type PluginState = GenericPluginState<PluginKey>;