@atlaskit/editor-common 82.13.0 → 83.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/afm-jira/tsconfig.json +150 -0
- package/dist/cjs/hooks/useSharedPluginState.js +1 -4
- package/dist/cjs/i18n/cs.js +2 -1
- package/dist/cjs/i18n/da.js +2 -1
- package/dist/cjs/i18n/de.js +2 -1
- package/dist/cjs/i18n/en.js +1 -0
- package/dist/cjs/i18n/en_GB.js +1 -0
- package/dist/cjs/i18n/en_ZZ.js +1 -0
- package/dist/cjs/i18n/es.js +2 -1
- package/dist/cjs/i18n/fi.js +2 -1
- package/dist/cjs/i18n/fr.js +2 -1
- package/dist/cjs/i18n/hu.js +2 -1
- package/dist/cjs/i18n/it.js +2 -1
- package/dist/cjs/i18n/ja.js +2 -1
- package/dist/cjs/i18n/ko.js +2 -1
- package/dist/cjs/i18n/nb.js +2 -1
- package/dist/cjs/i18n/nl.js +2 -1
- package/dist/cjs/i18n/pl.js +2 -1
- package/dist/cjs/i18n/pt_BR.js +2 -1
- package/dist/cjs/i18n/ru.js +2 -1
- package/dist/cjs/i18n/sv.js +2 -1
- package/dist/cjs/i18n/th.js +7 -3
- package/dist/cjs/i18n/tr.js +4 -3
- package/dist/cjs/i18n/uk.js +2 -1
- package/dist/cjs/i18n/vi.js +2 -1
- package/dist/cjs/i18n/zh.js +3 -2
- package/dist/cjs/i18n/zh_TW.js +2 -1
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/preset/builder.js +491 -0
- package/dist/cjs/styles/shared/annotation.js +20 -18
- package/dist/cjs/types/index.js +6 -1
- package/dist/cjs/ui/DropList/index.js +1 -1
- package/dist/cjs/ui/Mention/mention-with-profilecard.js +3 -1
- package/dist/es2019/hooks/useSharedPluginState.js +1 -6
- package/dist/es2019/i18n/cs.js +2 -1
- package/dist/es2019/i18n/da.js +2 -1
- package/dist/es2019/i18n/de.js +2 -1
- package/dist/es2019/i18n/en.js +1 -0
- package/dist/es2019/i18n/en_GB.js +1 -0
- package/dist/es2019/i18n/en_ZZ.js +1 -0
- package/dist/es2019/i18n/es.js +2 -1
- package/dist/es2019/i18n/fi.js +2 -1
- package/dist/es2019/i18n/fr.js +2 -1
- package/dist/es2019/i18n/hu.js +2 -1
- package/dist/es2019/i18n/it.js +2 -1
- package/dist/es2019/i18n/ja.js +2 -1
- package/dist/es2019/i18n/ko.js +2 -1
- package/dist/es2019/i18n/nb.js +2 -1
- package/dist/es2019/i18n/nl.js +2 -1
- package/dist/es2019/i18n/pl.js +2 -1
- package/dist/es2019/i18n/pt_BR.js +2 -1
- package/dist/es2019/i18n/ru.js +2 -1
- package/dist/es2019/i18n/sv.js +2 -1
- package/dist/es2019/i18n/th.js +7 -3
- package/dist/es2019/i18n/tr.js +4 -3
- package/dist/es2019/i18n/uk.js +2 -1
- package/dist/es2019/i18n/vi.js +2 -1
- package/dist/es2019/i18n/zh.js +3 -2
- package/dist/es2019/i18n/zh_TW.js +2 -1
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/preset/builder.js +528 -0
- package/dist/es2019/preset/core-plugin/index.js +1 -0
- package/dist/es2019/styles/shared/annotation.js +54 -29
- package/dist/es2019/types/index.js +9 -1
- package/dist/es2019/ui/DropList/index.js +1 -1
- package/dist/es2019/ui/Mention/mention-with-profilecard.js +2 -0
- package/dist/esm/hooks/useSharedPluginState.js +1 -4
- package/dist/esm/i18n/cs.js +2 -1
- package/dist/esm/i18n/da.js +2 -1
- package/dist/esm/i18n/de.js +2 -1
- package/dist/esm/i18n/en.js +1 -0
- package/dist/esm/i18n/en_GB.js +1 -0
- package/dist/esm/i18n/en_ZZ.js +1 -0
- package/dist/esm/i18n/es.js +2 -1
- package/dist/esm/i18n/fi.js +2 -1
- package/dist/esm/i18n/fr.js +2 -1
- package/dist/esm/i18n/hu.js +2 -1
- package/dist/esm/i18n/it.js +2 -1
- package/dist/esm/i18n/ja.js +2 -1
- package/dist/esm/i18n/ko.js +2 -1
- package/dist/esm/i18n/nb.js +2 -1
- package/dist/esm/i18n/nl.js +2 -1
- package/dist/esm/i18n/pl.js +2 -1
- package/dist/esm/i18n/pt_BR.js +2 -1
- package/dist/esm/i18n/ru.js +2 -1
- package/dist/esm/i18n/sv.js +2 -1
- package/dist/esm/i18n/th.js +7 -3
- package/dist/esm/i18n/tr.js +4 -3
- package/dist/esm/i18n/uk.js +2 -1
- package/dist/esm/i18n/vi.js +2 -1
- package/dist/esm/i18n/zh.js +3 -2
- package/dist/esm/i18n/zh_TW.js +2 -1
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/preset/builder.js +528 -0
- package/dist/esm/preset/core-plugin/index.js +1 -0
- package/dist/esm/styles/shared/annotation.js +20 -18
- package/dist/esm/types/index.js +9 -1
- package/dist/esm/ui/DropList/index.js +1 -1
- package/dist/esm/ui/Mention/mention-with-profilecard.js +3 -1
- package/dist/types/hooks/useSharedPluginState.d.ts +5 -5
- package/dist/types/i18n/cs.d.ts +1 -0
- package/dist/types/i18n/da.d.ts +1 -0
- package/dist/types/i18n/de.d.ts +1 -0
- package/dist/types/i18n/en.d.ts +1 -0
- package/dist/types/i18n/en_GB.d.ts +1 -0
- package/dist/types/i18n/en_ZZ.d.ts +1 -0
- package/dist/types/i18n/es.d.ts +1 -0
- package/dist/types/i18n/fi.d.ts +1 -0
- package/dist/types/i18n/fr.d.ts +1 -0
- package/dist/types/i18n/hu.d.ts +1 -0
- package/dist/types/i18n/it.d.ts +1 -0
- package/dist/types/i18n/ja.d.ts +1 -0
- package/dist/types/i18n/ko.d.ts +1 -0
- package/dist/types/i18n/nb.d.ts +1 -0
- package/dist/types/i18n/nl.d.ts +1 -0
- package/dist/types/i18n/pl.d.ts +1 -0
- package/dist/types/i18n/pt_BR.d.ts +1 -0
- package/dist/types/i18n/ru.d.ts +1 -0
- package/dist/types/i18n/sv.d.ts +1 -0
- package/dist/types/i18n/th.d.ts +4 -0
- package/dist/types/i18n/tr.d.ts +1 -0
- package/dist/types/i18n/uk.d.ts +1 -0
- package/dist/types/i18n/vi.d.ts +1 -0
- package/dist/types/i18n/zh.d.ts +1 -0
- package/dist/types/i18n/zh_TW.d.ts +1 -0
- package/dist/types/portal/PortalManager.d.ts +3 -3
- package/dist/types/preset/builder.d.ts +550 -11
- package/dist/types/preset/core-plugin/index.d.ts +1 -1
- package/dist/types/preset/core-plugin/requestDocument.d.ts +1 -2
- package/dist/types/preset/index.d.ts +1 -0
- package/dist/types/preset/plugin-injection-api.d.ts +9 -3
- package/dist/types/styles/shared/annotation.d.ts +17 -0
- package/dist/types/types/index.d.ts +8 -7
- package/dist/types/types/next-editor-plugin.d.ts +641 -98
- package/dist/types/ui/Mention/mention-with-profilecard.d.ts +2 -1
- package/dist/types-ts4.5/hooks/useSharedPluginState.d.ts +5 -5
- package/dist/types-ts4.5/i18n/cs.d.ts +1 -0
- package/dist/types-ts4.5/i18n/da.d.ts +1 -0
- package/dist/types-ts4.5/i18n/de.d.ts +1 -0
- package/dist/types-ts4.5/i18n/en.d.ts +1 -0
- package/dist/types-ts4.5/i18n/en_GB.d.ts +1 -0
- package/dist/types-ts4.5/i18n/en_ZZ.d.ts +1 -0
- package/dist/types-ts4.5/i18n/es.d.ts +1 -0
- package/dist/types-ts4.5/i18n/fi.d.ts +1 -0
- package/dist/types-ts4.5/i18n/fr.d.ts +1 -0
- package/dist/types-ts4.5/i18n/hu.d.ts +1 -0
- package/dist/types-ts4.5/i18n/it.d.ts +1 -0
- package/dist/types-ts4.5/i18n/ja.d.ts +1 -0
- package/dist/types-ts4.5/i18n/ko.d.ts +1 -0
- package/dist/types-ts4.5/i18n/nb.d.ts +1 -0
- package/dist/types-ts4.5/i18n/nl.d.ts +1 -0
- package/dist/types-ts4.5/i18n/pl.d.ts +1 -0
- package/dist/types-ts4.5/i18n/pt_BR.d.ts +1 -0
- package/dist/types-ts4.5/i18n/ru.d.ts +1 -0
- package/dist/types-ts4.5/i18n/sv.d.ts +1 -0
- package/dist/types-ts4.5/i18n/th.d.ts +4 -0
- package/dist/types-ts4.5/i18n/tr.d.ts +1 -0
- package/dist/types-ts4.5/i18n/uk.d.ts +1 -0
- package/dist/types-ts4.5/i18n/vi.d.ts +1 -0
- package/dist/types-ts4.5/i18n/zh.d.ts +1 -0
- package/dist/types-ts4.5/i18n/zh_TW.d.ts +1 -0
- package/dist/types-ts4.5/portal/PortalManager.d.ts +3 -3
- package/dist/types-ts4.5/preset/builder.d.ts +577 -13
- package/dist/types-ts4.5/preset/core-plugin/index.d.ts +1 -1
- package/dist/types-ts4.5/preset/core-plugin/requestDocument.d.ts +1 -2
- package/dist/types-ts4.5/preset/index.d.ts +1 -0
- package/dist/types-ts4.5/preset/plugin-injection-api.d.ts +9 -8
- package/dist/types-ts4.5/styles/shared/annotation.d.ts +17 -0
- package/dist/types-ts4.5/types/index.d.ts +8 -7
- package/dist/types-ts4.5/types/next-editor-plugin.d.ts +673 -127
- package/dist/types-ts4.5/ui/Mention/mention-with-profilecard.d.ts +2 -1
- package/package.json +4 -4
- package/dist/cjs/preset/core-plugin/types.js +0 -5
- package/dist/cjs/types/editor-public-api.js +0 -5
- package/dist/es2019/preset/core-plugin/types.js +0 -1
- package/dist/es2019/types/editor-public-api.js +0 -1
- package/dist/esm/preset/core-plugin/types.js +0 -1
- package/dist/esm/types/editor-public-api.js +0 -1
- package/dist/types/preset/core-plugin/types.d.ts +0 -59
- package/dist/types/types/editor-public-api.d.ts +0 -3
- package/dist/types-ts4.5/preset/core-plugin/types.d.ts +0 -59
- package/dist/types-ts4.5/types/editor-public-api.d.ts +0 -4
|
@@ -1,16 +1,582 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CorePlugin, DefaultEditorPlugin, DependencyPlugin, NextEditorPlugin, NextEditorPluginMetadata, OptionalPlugin, PluginDependenciesAPI } from '../types';
|
|
2
2
|
import type { EditorPlugin } from '../types/editor-plugin';
|
|
3
3
|
import type { EditorPluginInjectionAPI } from './plugin-injection-api';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/*********************
|
|
5
|
+
* *
|
|
6
|
+
* BASE TYPES *
|
|
7
|
+
* *
|
|
8
|
+
**********************/
|
|
9
|
+
/**
|
|
10
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
type MaybePlugin<T extends PresetPlugin> = T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
type DependencyErrorMessage<Message extends string> = {
|
|
19
|
+
errorMessage: Message;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
type PluginWithConfiguration<Plugin> = undefined extends ExtractPluginConfiguration<Plugin> ? [
|
|
26
|
+
Plugin,
|
|
27
|
+
ExtractPluginConfiguration<Plugin>?
|
|
28
|
+
] : [
|
|
29
|
+
Plugin,
|
|
30
|
+
ExtractPluginConfiguration<Plugin>
|
|
31
|
+
];
|
|
32
|
+
/****************************************************
|
|
33
|
+
* *
|
|
34
|
+
* METADATA PROPERTIES EXTRACTION TYPES *
|
|
35
|
+
* *
|
|
36
|
+
****************************************************/
|
|
37
|
+
/**
|
|
38
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
39
|
+
*
|
|
40
|
+
* Extracts the configuration type from a given plugin.
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
* @returns The extracted plugin configuration type if applicable, or `never`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* type DogPlugin = NextEditorPlugin<'dog'>;
|
|
48
|
+
*
|
|
49
|
+
* // it returns never, since Dog has no configuration
|
|
50
|
+
* type MyPluginConfiguration = ExtractPluginConfiguration<MyPlugin>;
|
|
51
|
+
*
|
|
52
|
+
*
|
|
53
|
+
* type CatPlugin = NextEditorPlugin<'cat', { configuration: { color: 'red' | 'blue' } }>;
|
|
54
|
+
*
|
|
55
|
+
* // it returns this type { color: 'red' | 'blue' }
|
|
56
|
+
* type MyPluginConfiguration = ExtractPluginConfiguration<MyPlugin>;
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
type ExtractPluginConfiguration<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (props: {
|
|
60
|
+
config: any;
|
|
61
|
+
api: any;
|
|
62
|
+
}) => DefaultEditorPlugin<any, infer Metadata> ? ExtractPluginConfigurationFromMetadata<Metadata> : never : never;
|
|
63
|
+
/**
|
|
64
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
65
|
+
*
|
|
66
|
+
* Extracts and filters the plugin dependencies from the plugin metadata, excluding
|
|
67
|
+
* optional dependencies.
|
|
68
|
+
*
|
|
69
|
+
* This type first checks if the `dependencies` property in the given `Metadata` type
|
|
70
|
+
* is an array of `DependencyPlugin`. If true, it applies `FilterOptionalPlugins` to
|
|
71
|
+
* filter out the optional dependencies. If the `dependencies` property does not exist
|
|
72
|
+
* or is not an array of `DependencyPlugin`, the type resolves to an empty array.
|
|
73
|
+
*
|
|
74
|
+
* @returns An array of filtered plugin dependencies or an empty array.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* type DogPlugin = NextEditorPlugin<'dog'>;
|
|
79
|
+
* type LoudPlugin = NextEditorPlugin<'loud'>;
|
|
80
|
+
* type BarkMetadata = {dependencies: [
|
|
81
|
+
* OptionalPlugin<LoudPlugin>,
|
|
82
|
+
* DogPlugin,
|
|
83
|
+
* ]}
|
|
84
|
+
* type BarkPlugin = NextEditorPlugin<'bark', BarkMetadata>;
|
|
85
|
+
*
|
|
86
|
+
* // It returns [DogPlugin]
|
|
87
|
+
* type RequiredDependencies = ExtractPluginDependenciesFromMetadataWithoutOptionals<BarkMetadata>;
|
|
88
|
+
*
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* You probably wants to use this other type util @see ExtractPluginDependencies
|
|
92
|
+
* since you wouldn't need to infer the Metadata twice
|
|
93
|
+
*/
|
|
94
|
+
type ExtractPluginDependenciesFromMetadataWithoutOptionals<Metadata extends NextEditorPluginMetadata> = Metadata['dependencies'] extends DependencyPlugin[] ? FilterOptionalPlugins<Metadata['dependencies']> : [
|
|
95
|
+
];
|
|
96
|
+
/**
|
|
97
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
98
|
+
*
|
|
99
|
+
* Extracts the plugin configuration from the given plugin metadata if the
|
|
100
|
+
* `pluginConfiguration` property exists.
|
|
101
|
+
*
|
|
102
|
+
* This type conditionally checks if the `Metadata` type includes a `pluginConfiguration`
|
|
103
|
+
* key. If such a key exists, the type of `pluginConfiguration` is returned. If not,
|
|
104
|
+
* the type resolves to `never`.
|
|
105
|
+
*/
|
|
106
|
+
type ExtractPluginConfigurationFromMetadata<Metadata> = 'pluginConfiguration' extends keyof Metadata ? Metadata['pluginConfiguration'] : never;
|
|
107
|
+
/********************************
|
|
108
|
+
* *
|
|
109
|
+
* TYPE INFER *
|
|
110
|
+
* *
|
|
111
|
+
*********************************/
|
|
112
|
+
/**
|
|
113
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
114
|
+
*
|
|
115
|
+
* Extracts the NextEditorPlugin type from a PresetPuglin,
|
|
116
|
+
* this is useful because the EditorPresetBuilder can accept the plugin in multiple ways:
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```
|
|
120
|
+
* preset
|
|
121
|
+
* // valid
|
|
122
|
+
* .add([plugin, { myConfiguration }] // Type: [NextEditorPlugin, Configuration]
|
|
123
|
+
*
|
|
124
|
+
* // valid
|
|
125
|
+
* .add([plugin]) // Type: [NextEditorPlugin, Configuration?]
|
|
126
|
+
*
|
|
127
|
+
* // valid
|
|
128
|
+
* .add(plugin) // Type: NextEditorPlugin
|
|
129
|
+
*
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* This type conditionally checks if `Plugin` is an array. If it is an array, it then checks if the first element
|
|
133
|
+
* (`MPlugin`) extends `NextEditorPlugin`. But if `Plugin` directly extends `NextEditorPlugin`, it returns the `Plugin`
|
|
134
|
+
* type itself. Otherwise, it resolves to `never`.
|
|
135
|
+
*
|
|
136
|
+
* You probably wants to use this if you need to extract the NextEditorPlugin from a @see PresetPlugin .
|
|
137
|
+
* Since the PresetPlugin is an union between a tuple and a plugin.
|
|
138
|
+
*/
|
|
139
|
+
type ExtractPluginAllBuilderPlugins<Plugin extends PresetPlugin> = Plugin extends Array<any> ? Plugin extends [
|
|
140
|
+
infer MPlugin,
|
|
141
|
+
...any
|
|
142
|
+
] ? MPlugin extends NextEditorPlugin<infer Name, any> ? MPlugin : never : never : Plugin extends NextEditorPlugin<infer Name, any> ? Plugin : never;
|
|
143
|
+
/**
|
|
144
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
145
|
+
*
|
|
146
|
+
* Extracts non-optional plugin dependencies, excluding any optional dependencies, from a given plugin's metadata.
|
|
147
|
+
*
|
|
148
|
+
* We can declare the depencies like this:
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* NextEditorPlugin<'bark', {
|
|
153
|
+
* dependencies: [DogPlugin, Optional<LoudPlugin>]
|
|
154
|
+
* }>
|
|
155
|
+
*
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
*
|
|
159
|
+
* This tyope is similar to @see ExtractPluginDependenciesFromMetadataWithoutOptionals
|
|
160
|
+
* but you can use it to extract the non-optional-dependencies from any NextEditorPlugin without infer the metadata
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* type BarkPlugin = NextEditorPlugin<'bark', {
|
|
165
|
+
* dependencies: [DogPlugin, Optional<LoudPlugin>]
|
|
166
|
+
* }>
|
|
167
|
+
*
|
|
168
|
+
* type PluginDependencies = ExtractPluginDependencies<BarkPlugin>; // Type: [DogPlugin]
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
type ExtractPluginDependencies<Plugin> = Plugin extends NextEditorPlugin<any, infer Metadata> ? ExtractPluginDependenciesFromMetadataWithoutOptionals<Metadata> : never;
|
|
172
|
+
/**
|
|
173
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
174
|
+
*
|
|
175
|
+
* Extracts the NextEditorPlugin type from a PluginWithConfiguration.
|
|
176
|
+
*
|
|
177
|
+
*
|
|
178
|
+
* You probably wants to use this if you need to extract the NextEditorPlugin from a @see PresetPlugin .
|
|
179
|
+
* Since the PresetPlugin is an union between a tuple and a plugin.
|
|
180
|
+
*/
|
|
181
|
+
type ExtractNextEditorPluginFromPluginWithConfiguration<Plugin> = Plugin extends PluginWithConfiguration<any> ? Plugin[0] : never;
|
|
182
|
+
/**
|
|
183
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
184
|
+
*
|
|
185
|
+
* Extracts the plugin name from a PresetPlugins.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* ExtractPluginNameFromAllBuilderPlugins<NextEditorPlugin<'bark'>> // 'bark'
|
|
190
|
+
*
|
|
191
|
+
* ExtractPluginNameFromAllBuilderPlugins<[NextEditorPlugin<'dog'>, { configuration: {} }> // 'dog'
|
|
192
|
+
*
|
|
193
|
+
* ```
|
|
194
|
+
* Similar to @see ExtractPluginAllBuilderPlugins, this type conditionally checks if `Plugin` is an array. If it is,
|
|
195
|
+
* it attempts to extract the name of the first plugin (`MPlugin`) in the array that extends `NextEditorPlugin` with
|
|
196
|
+
* a name and any metadata. If `Plugin` itself directly extends `NextEditorPlugin`, it extracts the plugin's name.
|
|
197
|
+
* If none of these conditions are met, it resolves to `never`.
|
|
198
|
+
*
|
|
199
|
+
*/
|
|
200
|
+
type ExtractPluginNameFromAllBuilderPlugins<Plugin extends PresetPlugin> = Plugin extends Array<any> ? Plugin extends [
|
|
201
|
+
infer MPlugin,
|
|
202
|
+
...any
|
|
203
|
+
] ? MPlugin extends NextEditorPlugin<infer Name, any> ? Name : never : never : Plugin extends NextEditorPlugin<infer Name, any> ? Name : never;
|
|
204
|
+
/******************************
|
|
205
|
+
* *
|
|
206
|
+
* MAPPED TUPLES *
|
|
207
|
+
* *
|
|
208
|
+
******************************/
|
|
209
|
+
/**
|
|
210
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
211
|
+
*
|
|
212
|
+
* Filters out optional plugins from a tuple of dependency plugins.
|
|
213
|
+
*
|
|
214
|
+
*
|
|
215
|
+
* This type is using the Tail Head trick to map a tuple to another one.
|
|
216
|
+
* It does this by conditionally iterating over each element in the tuple: if the head of the tuple (the first element)
|
|
217
|
+
* is an optional plugin, it is excluded from the resulting tuple; otherwise, it is included. This process is repeated
|
|
218
|
+
* for the tail (the remaining elements) of the tuple until all elements have been evaluated.
|
|
219
|
+
*
|
|
220
|
+
*/
|
|
221
|
+
type FilterOptionalPlugins<T extends DependencyPlugin[]> = T extends [
|
|
222
|
+
infer Head,
|
|
223
|
+
...infer Tail
|
|
224
|
+
] ? Tail extends DependencyPlugin[] ? Head extends OptionalPlugin<NextEditorPlugin<any, any>> ? FilterOptionalPlugins<Tail> : [
|
|
225
|
+
Head,
|
|
226
|
+
...FilterOptionalPlugins<Tail>
|
|
227
|
+
] : T : T;
|
|
228
|
+
/**
|
|
229
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
230
|
+
*
|
|
231
|
+
* One of the main type system for the EditorPresetBuilder.
|
|
232
|
+
*
|
|
233
|
+
* Verifies if a given plugin's dependencies are satisfied within a provided stack of plugins.
|
|
234
|
+
*
|
|
235
|
+
* Usually, the stack of plugins are coming from a generic parameter in the EditorPresetBuilder<PluginNames, PluginStack>.
|
|
236
|
+
*
|
|
237
|
+
* This type checks if the dependencies of the given `Plugin` are included in the provided `PluginsStack`.
|
|
238
|
+
*
|
|
239
|
+
* - If the plugin has no dependencies, it simply returns the plugin itself, (provided it is either a `PluginWithConfiguration` or `NextEditorPlugin`, in case someone tries to add a non-NextEditorPlugin to the Preset)
|
|
240
|
+
*
|
|
241
|
+
* - If the plugin has dependencies, it verifies each dependency against the `PluginsStack` to ensure
|
|
242
|
+
* they are present. This includes checking direct dependencies as well as dependencies hidden inside tuples (by unwrapping
|
|
243
|
+
* them). If all dependencies are satisfied, it returns the plugin; otherwise, it resolves to `never`.
|
|
244
|
+
*
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* type DogPlugin = NextEditorPlugin<'dog'>;
|
|
249
|
+
* type LoudPlugin = NextEditorPlugin<'loud'>;
|
|
250
|
+
* type BarkPlugin = NextEditorPlugin<'bark', { dependencies: [DogPlugin, LoudPlugin] }>;
|
|
251
|
+
*
|
|
252
|
+
*
|
|
253
|
+
* // When there we are missing dependencies
|
|
254
|
+
* VerifyPluginDependencies<BarkPlugin, [DogPlugin]> // Type: never
|
|
255
|
+
*
|
|
256
|
+
*
|
|
257
|
+
* // When there all dependencies are already added on the stack
|
|
258
|
+
* VerifyPluginDependencies<BarkPlugin, [DogPlugin, LoudPlugin]> // Type: BarkPlugin
|
|
259
|
+
*
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
type VerifyPluginDependencies<Plugin, PluginsStack extends AllEditorPresetPluginTypes[]> = ExtractPluginDependencies<Plugin> extends [
|
|
263
|
+
] ? Plugin extends PluginWithConfiguration<any> | NextEditorPlugin<any, any> ? Plugin : never :
|
|
264
|
+
/**
|
|
265
|
+
* case 1: We're looking for its dependent plugins indexed on `AllEditorPresetPluginTypes`
|
|
266
|
+
*/
|
|
267
|
+
ExtractPluginDependencies<Plugin>[number] extends (ExtractPluginDependencies<Plugin>[number] & PluginsStack[number])
|
|
268
|
+
/**
|
|
269
|
+
* case 2:
|
|
270
|
+
* Otherwise check whether the dependent-plugin, is hidden inside a tuple,
|
|
271
|
+
* unwrapping `Plugins` via `ExtractNextEditorPluginFromPluginWithConfiguration`
|
|
272
|
+
*/
|
|
273
|
+
| (ExtractPluginDependencies<Plugin>[number] & ExtractNextEditorPluginFromPluginWithConfiguration<PluginsStack[number]>) ? Plugin : never;
|
|
274
|
+
/********************************
|
|
275
|
+
* *
|
|
276
|
+
* BETTER ERROR MESSAGE TYPES *
|
|
277
|
+
* *
|
|
278
|
+
*********************************/
|
|
279
|
+
/**
|
|
280
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
281
|
+
*
|
|
282
|
+
* TypeScript doesn't allow custom error messages (yet). So, use this type to force a specific error message to the user.
|
|
283
|
+
*
|
|
284
|
+
* This is useful because in a situation where a Preset has too many plugins, its become really hard to understand what the error message is.
|
|
285
|
+
*
|
|
286
|
+
* Extracts the names of required dependencies for a given plugin, or provides an error message if dependencies are
|
|
287
|
+
* missing, invalid, or if the plugin itself is not a recognized NextEditorPlugin.
|
|
288
|
+
*
|
|
289
|
+
* This type evaluates whether a given `Plugin` has defined dependencies. If dependencies are absent, it returns
|
|
290
|
+
* a message indicating no dependencies were found. If dependencies are present but do not conform to expected types,
|
|
291
|
+
* or if an unspecified issue occurs, appropriate error messages are generated. Valid dependencies result in the
|
|
292
|
+
* extraction of their names; otherwise, an error message specific to the situation is returned.
|
|
293
|
+
*
|
|
294
|
+
* It is used by the @see GetDependencyErrorMessage to group all error messages when a new plugin is being added into a preset.
|
|
295
|
+
*/
|
|
296
|
+
type ExtractRequiredDependencies<Plugin, PluginsStack extends AllEditorPresetPluginTypes[]> = Plugin extends NextEditorPlugin<infer PluginName, infer Metadata> ? Metadata['dependencies'] extends undefined ? DependencyErrorMessage<'No found dependencies'> : Metadata['dependencies'] extends DependencyPlugin[] ? FilterOptionalPlugins<FilterExistingPlugins<Metadata['dependencies'], PluginsStack>>[number] extends NextEditorPlugin<infer Name, any> ? Name : DependencyErrorMessage<`Invalid dependency for ${PluginName}`> : DependencyErrorMessage<`Invalid dependencies for ${PluginName}`> : DependencyErrorMessage<'Plugin is not NextEditorPlugin'>;
|
|
297
|
+
/**
|
|
298
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
299
|
+
*
|
|
300
|
+
* Retrieves an error message if any dependency-related issues are detected for a given plugin within a specified
|
|
301
|
+
* plugin stack. This includes missing dependencies or other errors as identified by `ExtractRequiredDependencies`.
|
|
302
|
+
*
|
|
303
|
+
* It attempts to extract required dependencies for the `Plugin` from the `StackPlugins`. If the result is a string,
|
|
304
|
+
* it indicates a missing dependency and constructs an error message accordingly. Otherwise, it directly returns the
|
|
305
|
+
* result from `ExtractRequiredDependencies`, which could be an error message detailing the issue encountered.
|
|
306
|
+
*
|
|
307
|
+
* It is used by the @see SafePresetCheck to make improve the error message
|
|
308
|
+
*/
|
|
309
|
+
type GetDependencyErrorMessage<Plugin, StackPlugins extends AllEditorPresetPluginTypes[]> = ExtractRequiredDependencies<Plugin, StackPlugins> extends string ? DependencyErrorMessage<`Missing dependency: ${ExtractRequiredDependencies<Plugin, StackPlugins>}Plugin`> : ExtractRequiredDependencies<Plugin, StackPlugins>;
|
|
310
|
+
/**
|
|
311
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
312
|
+
*
|
|
313
|
+
* Filters through an array of dependency plugins, removing any that do not exist in the provided plugins stack.
|
|
314
|
+
*
|
|
315
|
+
* This type recursively checks each plugin dependency against the provided `PluginsStack`. If a dependency is found
|
|
316
|
+
* within the stack, it is included in the result; otherwise, it is excluded. This process helps in identifying
|
|
317
|
+
* missing plugins from a set of required dependencies.
|
|
318
|
+
*
|
|
319
|
+
*/
|
|
320
|
+
type FilterExistingPlugins<T extends DependencyPlugin[], PluginsStack extends AllEditorPresetPluginTypes[]> = T extends [
|
|
321
|
+
infer CurrentPluginDependency,
|
|
322
|
+
...infer RemainingPluginDependencies
|
|
323
|
+
] ? RemainingPluginDependencies extends DependencyPlugin[] ? CurrentPluginDependency extends PluginsStack[number] ? FilterExistingPlugins<RemainingPluginDependencies, PluginsStack> : [
|
|
324
|
+
CurrentPluginDependency,
|
|
325
|
+
...FilterExistingPlugins<RemainingPluginDependencies, PluginsStack>
|
|
326
|
+
] : T : T;
|
|
327
|
+
/*****************************
|
|
328
|
+
* *
|
|
329
|
+
* VALIDATION HELPER TYPES *
|
|
330
|
+
* *
|
|
331
|
+
******************************/
|
|
332
|
+
/**
|
|
333
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
334
|
+
*
|
|
335
|
+
* Checks for duplicate plugin entries within a stack of plugins. If a duplicate is found, it returns an error message;
|
|
336
|
+
* otherwise, it proceeds without error.
|
|
337
|
+
*
|
|
338
|
+
* This type primarily serves to ensure that each plugin in the plugin stack is unique, preventing issues related to
|
|
339
|
+
* duplicate plugin registration. It also includes a check to accommodate scenarios where strict typing is bypassed.
|
|
340
|
+
*
|
|
341
|
+
* If the plugin is used with other configuration this type will not complain.
|
|
342
|
+
*/
|
|
343
|
+
type CheckDuplicatePlugin<Plugin, StackPlugins extends AllEditorPresetPluginTypes[]> = Plugin extends NextEditorPlugin<infer PluginName, any> ? Plugin extends StackPlugins[number] ? unknown extends StackPlugins[number] ? unknown : DependencyErrorMessage<`Duplicate plugin: ${PluginName}`> : unknown : unknown;
|
|
344
|
+
/**
|
|
345
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
346
|
+
*
|
|
347
|
+
* Verifies if a given plugin meets basic requirements to be considered a valid editor plugin.
|
|
348
|
+
*
|
|
349
|
+
* This type checks if the plugin is a function that matches the expected signature for an next editor plugin. If it does,
|
|
350
|
+
* it further checks the plugin's configuration requirements to ensure compatibility and adherence to expected
|
|
351
|
+
* configurations.
|
|
352
|
+
*
|
|
353
|
+
*/
|
|
354
|
+
type CheckBasicPlugin<Plugin> = Plugin extends (args: any, api: any) => EditorPlugin ? CheckTupleRequirements<Plugin, ExtractPluginConfiguration<Plugin>, PluginWithConfiguration<Plugin>> : never;
|
|
355
|
+
/**
|
|
356
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
357
|
+
*
|
|
358
|
+
* Evaluates whether a plugin's configuration meets the requirements to be used either as a standalone plugin or
|
|
359
|
+
* as part of a plugin-with-configuration tuple.
|
|
360
|
+
*
|
|
361
|
+
* This type assesses the plugin configuration's status—whether it's optional, mandatory, or not present—and determines
|
|
362
|
+
* the valid ways in which the plugin can be registered or used. This is crucial for maintaining backward compatibility
|
|
363
|
+
* and ensuring plugins are correctly configured upon registration into the Preset
|
|
364
|
+
*
|
|
365
|
+
*/
|
|
366
|
+
type CheckTupleRequirements<Plugin, Config, ArrayType> = unknown extends Config ? Plugin | ArrayType : undefined extends Config ? Plugin | ArrayType : [
|
|
367
|
+
Config
|
|
368
|
+
] extends [
|
|
369
|
+
never
|
|
370
|
+
] ? Plugin : ArrayType;
|
|
371
|
+
/*****************************
|
|
372
|
+
* *
|
|
373
|
+
* EDITOR API HELPER TYPES *
|
|
374
|
+
* *
|
|
375
|
+
******************************/
|
|
376
|
+
/**
|
|
377
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
378
|
+
*
|
|
379
|
+
* Extracts the numeric indices as literal types from a tuple.
|
|
380
|
+
*
|
|
381
|
+
* This utility type takes a tuple and produces a union of its numeric indices as literal types. It's useful for
|
|
382
|
+
* iterating over tuples with TypeScript's mapped types, allowing for operations on each tuple element based on its index.
|
|
383
|
+
*
|
|
384
|
+
* It is being used to separate plugins registred with `preset.maybeAdd` and `preset.add`.
|
|
385
|
+
*/
|
|
386
|
+
type TupleIndices<T extends readonly any[]> = Extract<keyof T, `${number}`> extends `${infer N extends number}` ? N : never;
|
|
387
|
+
/**
|
|
388
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
389
|
+
*
|
|
390
|
+
* Constructs a plugin api type with optional properties based on the optional plugins from a given tuple of plugins.
|
|
391
|
+
*
|
|
392
|
+
* This type iterates over a tuple of plugins and checks for plugins marked as optional (indicated by the presence
|
|
393
|
+
* of `undefined`). For each optional plugin, it attempts to extract the plugin's name and corresponding
|
|
394
|
+
* `PluginDependenciesAPI` type. The resulting object type has properties with these plugin names as keys and their
|
|
395
|
+
* respective APIs as optional values.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```typescript
|
|
399
|
+
* type DogPlugin = NextEditorPlugin<'dog'>;
|
|
400
|
+
* type CatPlugin = NextEditorPlugin<'cat'>;
|
|
401
|
+
*
|
|
402
|
+
*
|
|
403
|
+
* BuildOptionalAPIEntry<[DogPlugin, MaybePlugin<CatPlugin>]> // Type: { cat?: { } }
|
|
404
|
+
*
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
type BuildOptionalAPIEntry<T extends AllEditorPresetPluginTypes[]> = {
|
|
408
|
+
[K in TupleIndices<T> as undefined extends T[K] ? T[K] extends MaybePlugin<infer P> ? ExtractPluginNameFromAllBuilderPlugins<P> : never : never]?: undefined extends T[K] ? T[K] extends MaybePlugin<infer P> ? PluginDependenciesAPI<ExtractPluginAllBuilderPlugins<P>> | undefined : never : never;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
412
|
+
* Generates a plugin api type with properties based on the required plugins from a given tuple of plugins.
|
|
413
|
+
*
|
|
414
|
+
* This type traverses a tuple of plugins, focusing on those not marked as optional. For each required plugin,
|
|
415
|
+
* it extracts the plugin's name to use as a key and determines the corresponding `PluginDependenciesAPI` type
|
|
416
|
+
* for the value. The resulting object type includes these key-value pairs, ensuring that each required plugin
|
|
417
|
+
* has a defined API entry in the object.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```typescript
|
|
421
|
+
* type DogPlugin = NextEditorPlugin<'dog'>;
|
|
422
|
+
* type CatPlugin = NextEditorPlugin<'cat'>;
|
|
423
|
+
*
|
|
424
|
+
*
|
|
425
|
+
* BuildOptionalAPIEntry<[DogPlugin, MaybePlugin<CatPlugin>]> // Type: { dog?: { } }
|
|
426
|
+
*
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
type BuildRequiredAPIEntry<T extends AllEditorPresetPluginTypes[]> = {
|
|
430
|
+
[K in TupleIndices<T> as undefined extends T[K] ? never : T[K] extends PresetPlugin ? ExtractPluginNameFromAllBuilderPlugins<T[K]> : never]: undefined extends T[K] ? never : T[K] extends PresetPlugin ? PluginDependenciesAPI<ExtractPluginAllBuilderPlugins<T[K]>> : never;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
434
|
+
*
|
|
435
|
+
* Forces the expansion (simplification/normalization) of conditional and mapped types.
|
|
436
|
+
* This can be particularly useful for making the types more readable and manageable in
|
|
437
|
+
* environments like IntelliSense or when generating type documentation.
|
|
438
|
+
*
|
|
439
|
+
* More info {@link https://github.com/microsoft/TypeScript/issues/47980 TypeScript/issues/47980}
|
|
440
|
+
*/
|
|
441
|
+
type Expand<T> = T extends Function ? T : T extends unknown ? {
|
|
442
|
+
[K in keyof T]: Expand<T[K]>;
|
|
443
|
+
} : never;
|
|
444
|
+
/*************************
|
|
445
|
+
* *
|
|
446
|
+
* PUBLIC TYPES *
|
|
447
|
+
* *
|
|
448
|
+
*************************/
|
|
449
|
+
/**
|
|
450
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
451
|
+
*
|
|
452
|
+
* Represents a utility type that wraps a string type in a tuple, often used to denote
|
|
453
|
+
* plugin names that might be optionally included or excluded in certain contexts within
|
|
454
|
+
* the editor preset builder.
|
|
455
|
+
*/
|
|
456
|
+
export type MaybePluginName<T extends string> = [
|
|
457
|
+
T
|
|
458
|
+
];
|
|
459
|
+
/**
|
|
460
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
461
|
+
*
|
|
462
|
+
* A union type that represents a plugin which could either be a standalone `NextEditorPlugin`
|
|
463
|
+
* or a `PluginWithConfiguration` that bundles a plugin with its specific configuration.
|
|
464
|
+
*
|
|
465
|
+
* This type is fundamental in managing plugins within presets, allowing for flexible plugin
|
|
466
|
+
* registration that accommodates plugins with or without explicit configurations.
|
|
467
|
+
*/
|
|
468
|
+
export type PresetPlugin = PluginWithConfiguration<NextEditorPlugin<any, any>> | NextEditorPlugin<any, any>;
|
|
469
|
+
/**
|
|
470
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
471
|
+
*
|
|
472
|
+
* A union type that aggregates all possible plugin name representations within the editor preset builder,
|
|
473
|
+
* including simple strings for direct plugin names and wrapped strings in tuples when a plugin is registred with `maybeAdd`.
|
|
474
|
+
*
|
|
475
|
+
*/
|
|
476
|
+
export type AllPluginNames = string | MaybePluginName<string>;
|
|
477
|
+
/**
|
|
478
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
479
|
+
*
|
|
480
|
+
* Represents all possible types of plugins that can be included within an editor preset.
|
|
481
|
+
* This includes both `PresetPlugin` types and `MaybePlugin` types, accommodating a wide range
|
|
482
|
+
* of plugin registration scenarios likw:
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* preset
|
|
487
|
+
* .add([plugin, { myConfiguration }]
|
|
488
|
+
* .add([plugin])
|
|
489
|
+
* .add(plugin)
|
|
490
|
+
* .maybeAdd(plugin, () => true);
|
|
491
|
+
* .maybeAdd([plugin], () => true);
|
|
492
|
+
* .maybeAdd([plugin, { myConfiguration }], () => true);
|
|
493
|
+
*
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
export type AllEditorPresetPluginTypes = PresetPlugin | MaybePlugin<NextEditorPlugin<any, any>>;
|
|
497
|
+
/**
|
|
498
|
+
* 🧱 Internal Type: Editor FE Platform
|
|
499
|
+
*
|
|
500
|
+
* Performs a series of checks to ensure that a given plugin can be safely added to a preset.
|
|
501
|
+
* This includes verifying the plugin's dependencies, checking for duplicate registrations, and ensuring
|
|
502
|
+
* the plugin meets basic criteria for being considered a valid plugin.
|
|
503
|
+
*
|
|
504
|
+
* @returns The plugin type if all checks pass, or error messages detailing why the plugin cannot be added.
|
|
505
|
+
*/
|
|
506
|
+
export type SafePresetCheck<Plugin, StackPlugins extends AllEditorPresetPluginTypes[]> = Plugin extends Plugin & VerifyPluginDependencies<Plugin, StackPlugins> ? Plugin extends NextEditorPlugin<any, any> ? CheckDuplicatePlugin<Plugin, StackPlugins> & CheckBasicPlugin<Plugin> : never : GetDependencyErrorMessage<Plugin, StackPlugins>;
|
|
507
|
+
/**
|
|
508
|
+
* 📢 Public Type API
|
|
509
|
+
*
|
|
510
|
+
* Extracts the complete API surface for a given editor preset, including both core and plugin-specific APIs.
|
|
511
|
+
* This type dynamically assembles the API object based on the included plugins, differentiating between
|
|
512
|
+
* optional and required plugins to accurately reflect the available API calls.
|
|
513
|
+
*
|
|
514
|
+
* @template Preset The editor preset builder instance from which to extract the API.
|
|
515
|
+
* @returns An object type representing the complete API surface for the given preset.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* const dogPlugin: NextEditorPlugin<'dog'>;
|
|
520
|
+
* const catPlugin: NextEditorPlugin<'cat'>;
|
|
521
|
+
*
|
|
522
|
+
* const myPreset = new EditorPresetBuilder()
|
|
523
|
+
* .add(dogPlugin)
|
|
524
|
+
* .maybeAdd(catPlugin, () => true)
|
|
525
|
+
*
|
|
526
|
+
* const api: ExtractPresetAPI<typeof myPreset>;
|
|
527
|
+
*
|
|
528
|
+
*
|
|
529
|
+
* // Core is always available
|
|
530
|
+
* api.core.actions
|
|
531
|
+
*
|
|
532
|
+
* // Dog was registred with `add`, so it will always be available
|
|
533
|
+
* api.dog.actions
|
|
534
|
+
*
|
|
535
|
+
* // Cat was registred with `maybeAdd`, so it may not be available on runtime
|
|
536
|
+
* api.cat?.actions
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
export type ExtractPresetAPI<Preset extends EditorPresetBuilder<any, any>> = Preset extends EditorPresetBuilder<any, infer Plugins> ? Expand<{
|
|
540
|
+
core: PluginDependenciesAPI<CorePlugin>;
|
|
541
|
+
} & BuildOptionalAPIEntry<Plugins> & BuildRequiredAPIEntry<Plugins>> : never;
|
|
542
|
+
/*************************
|
|
543
|
+
* *
|
|
544
|
+
* PROP TYPES *
|
|
545
|
+
* *
|
|
546
|
+
*************************/
|
|
547
|
+
type OldAndDeprecatedAddFunction<T> = (pluginToAdd: T, builder: EditorPresetBuilder<any, any>) => EditorPresetBuilder<any, any>;
|
|
548
|
+
type BuildProps = {
|
|
9
549
|
excludePlugins?: Set<string>;
|
|
10
550
|
pluginInjectionAPI?: EditorPluginInjectionAPI;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* This class is the main way to build an Editor.
|
|
554
|
+
*
|
|
555
|
+
* A Preset is an immutable object, any modification like `.add` or `.maybeAdd`
|
|
556
|
+
* will always result in a new preset instance.
|
|
557
|
+
*
|
|
558
|
+
* ⚠️⚠️⚠️ ATTENTION ⚠️⚠️⚠️
|
|
559
|
+
* For ComposableEditor, a new Preset means a full redraw,
|
|
560
|
+
* it is one of the most expensive operation.
|
|
561
|
+
* Please make sure you aren't recreating this all the time.
|
|
562
|
+
*
|
|
563
|
+
* EditorAPI:
|
|
564
|
+
* In case you need access to the EditorAPI type definition based in the preset you have.
|
|
565
|
+
* Please use the util type exported in this package: @see ExtractPresetAPI<Preset>
|
|
566
|
+
*
|
|
567
|
+
* ```typescript
|
|
568
|
+
* const myPreset = new EditorPresetBuilder()
|
|
569
|
+
* .add(pluginDog)
|
|
570
|
+
* .add(pluginCat);
|
|
571
|
+
*
|
|
572
|
+
*
|
|
573
|
+
* function someFunc(myApi: ExtractPresetAPI<typeof myPreset>) {
|
|
574
|
+
*
|
|
575
|
+
* }
|
|
576
|
+
* ```
|
|
577
|
+
*
|
|
578
|
+
* If your code is inside an EditorPlugin you should be using the @see ExtractInjectionAPI.
|
|
579
|
+
*/
|
|
14
580
|
export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] = [
|
|
15
581
|
], StackPlugins extends AllEditorPresetPluginTypes[] = [
|
|
16
582
|
]> {
|
|
@@ -19,7 +585,7 @@ export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] =
|
|
|
19
585
|
* Returns the editor API when resolved.
|
|
20
586
|
* This occurs when the preset is initially built.
|
|
21
587
|
*/
|
|
22
|
-
apiPromise: Promise<
|
|
588
|
+
apiPromise: Promise<unknown>;
|
|
23
589
|
private resolver;
|
|
24
590
|
constructor(...more: [
|
|
25
591
|
...StackPlugins
|
|
@@ -28,9 +594,7 @@ export declare class EditorPresetBuilder<PluginNames extends AllPluginNames[] =
|
|
|
28
594
|
ExtractPluginNameFromAllBuilderPlugins<NewPlugin>,
|
|
29
595
|
...PluginNames
|
|
30
596
|
], [
|
|
31
|
-
|
|
32
|
-
NewPlugin
|
|
33
|
-
],
|
|
597
|
+
NewPlugin,
|
|
34
598
|
...StackPlugins
|
|
35
599
|
]>;
|
|
36
600
|
maybeAdd<ToAddPlugin extends PresetPlugin>(pluginToAdd: SafePresetCheck<ToAddPlugin, StackPlugins>, shouldAdd: boolean | (() => boolean) | OldAndDeprecatedAddFunction<ToAddPlugin>): EditorPresetBuilder<[
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
|
|
2
2
|
import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import type { Transformer } from '../../types';
|
|
5
|
-
import type { InferTransformerResultCallback } from './types';
|
|
4
|
+
import type { InferTransformerResultCallback, Transformer } from '../../types';
|
|
6
5
|
export declare function toJSON(node: PMNode): JSONDocNode;
|
|
7
6
|
export declare const scheduleDocumentRequest: <GenericTransformer extends Transformer<any> | undefined>(editorView: EditorView | null, callback: InferTransformerResultCallback<Transformer<any>>, transformer?: Transformer<any> | undefined) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { EditorPresetBuilder } from './builder';
|
|
2
2
|
export { EditorPluginInjectionAPI } from './plugin-injection-api';
|
|
3
3
|
export { editorCommandToPMCommand, PassiveTransaction } from './editor-commands';
|
|
4
|
+
export type { ExtractPresetAPI, AllEditorPresetPluginTypes, AllPluginNames, MaybePluginName, } from './builder';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import type { NextEditorPlugin, PluginDependenciesAPI
|
|
3
|
+
import type { BasePluginDependenciesAPI, CorePlugin, NextEditorPlugin, PluginDependenciesAPI } from '../types/next-editor-plugin';
|
|
4
4
|
type NextEditorPluginInitializedType = ReturnType<NextEditorPlugin<any>>;
|
|
5
5
|
type SharedStateAPIProps = {
|
|
6
6
|
getEditorState: () => EditorState | undefined;
|
|
@@ -29,10 +29,16 @@ type EditorStateDelta = {
|
|
|
29
29
|
readonly oldEditorState: EditorState;
|
|
30
30
|
};
|
|
31
31
|
interface PluginInjectionAPIDefinition {
|
|
32
|
-
api:
|
|
32
|
+
api: () => {
|
|
33
|
+
[key: string]: BasePluginDependenciesAPI<any>;
|
|
34
|
+
};
|
|
33
35
|
onEditorViewUpdated: (props: EditorStateDelta) => void;
|
|
34
36
|
onEditorPluginInitialized: (plugin: NextEditorPluginInitializedType) => void;
|
|
35
37
|
}
|
|
38
|
+
type GenericAPIWithCore = {
|
|
39
|
+
core: PluginDependenciesAPI<CorePlugin>;
|
|
40
|
+
[key: string]: BasePluginDependenciesAPI<any>;
|
|
41
|
+
};
|
|
36
42
|
export declare class EditorPluginInjectionAPI implements PluginInjectionAPIDefinition {
|
|
37
43
|
private sharedStateAPI;
|
|
38
44
|
private actionsAPI;
|
|
@@ -40,12 +46,7 @@ export declare class EditorPluginInjectionAPI implements PluginInjectionAPIDefin
|
|
|
40
46
|
private plugins;
|
|
41
47
|
constructor({ getEditorState, getEditorView }: PluginInjectionAPIProps);
|
|
42
48
|
private createAPI;
|
|
43
|
-
api
|
|
44
|
-
NextEditorPlugin<T extends import("../types/next-editor-plugin").NextEditorPluginFunctionOptionalConfigDefinition<infer Name extends string, any, any> ? Name : never, T extends NextEditorPlugin<any, infer Metadata extends import("../types/next-editor-plugin").NextEditorPluginMetadata> ? Metadata : never>,
|
|
45
|
-
..."dependencies" extends keyof (T extends NextEditorPlugin<any, infer Metadata extends import("../types/next-editor-plugin").NextEditorPluginMetadata> ? Metadata : never) ? (T extends NextEditorPlugin<any, infer Metadata extends import("../types/next-editor-plugin").NextEditorPluginMetadata> ? Metadata : never)["dependencies"] extends (import("../types/next-editor-plugin").NextEditorPluginFunctionOptionalConfigDefinition<any, any, any> | import("../types/next-editor-plugin").OptionalPlugin<import("../types/next-editor-plugin").NextEditorPluginFunctionOptionalConfigDefinition<any, any, any>>)[] ? Exclude<(T extends NextEditorPlugin<any, infer Metadata extends import("../types/next-editor-plugin").NextEditorPluginMetadata> ? Metadata : never)["dependencies"], undefined> : [
|
|
46
|
-
] : [
|
|
47
|
-
]
|
|
48
|
-
]>;
|
|
49
|
+
api(): GenericAPIWithCore;
|
|
49
50
|
onEditorViewUpdated: ({ newEditorState, oldEditorState }: EditorStateDiff) => void;
|
|
50
51
|
onEditorPluginInitialized: (plugin: NextEditorPluginInitializedType) => void;
|
|
51
52
|
private addPlugin;
|