@atlaskit/editor-common 82.14.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.
Files changed (180) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/hooks/useSharedPluginState.js +1 -4
  3. package/dist/cjs/i18n/cs.js +2 -1
  4. package/dist/cjs/i18n/da.js +2 -1
  5. package/dist/cjs/i18n/de.js +2 -1
  6. package/dist/cjs/i18n/en.js +1 -0
  7. package/dist/cjs/i18n/en_GB.js +1 -0
  8. package/dist/cjs/i18n/en_ZZ.js +1 -0
  9. package/dist/cjs/i18n/es.js +2 -1
  10. package/dist/cjs/i18n/fi.js +2 -1
  11. package/dist/cjs/i18n/fr.js +2 -1
  12. package/dist/cjs/i18n/hu.js +2 -1
  13. package/dist/cjs/i18n/it.js +2 -1
  14. package/dist/cjs/i18n/ja.js +2 -1
  15. package/dist/cjs/i18n/ko.js +2 -1
  16. package/dist/cjs/i18n/nb.js +2 -1
  17. package/dist/cjs/i18n/nl.js +2 -1
  18. package/dist/cjs/i18n/pl.js +2 -1
  19. package/dist/cjs/i18n/pt_BR.js +2 -1
  20. package/dist/cjs/i18n/ru.js +2 -1
  21. package/dist/cjs/i18n/sv.js +2 -1
  22. package/dist/cjs/i18n/th.js +7 -3
  23. package/dist/cjs/i18n/tr.js +4 -3
  24. package/dist/cjs/i18n/uk.js +2 -1
  25. package/dist/cjs/i18n/vi.js +2 -1
  26. package/dist/cjs/i18n/zh.js +3 -2
  27. package/dist/cjs/i18n/zh_TW.js +2 -1
  28. package/dist/cjs/monitoring/error.js +1 -1
  29. package/dist/cjs/preset/builder.js +491 -0
  30. package/dist/cjs/styles/shared/annotation.js +20 -18
  31. package/dist/cjs/types/index.js +6 -1
  32. package/dist/cjs/ui/DropList/index.js +1 -1
  33. package/dist/cjs/ui/Mention/mention-with-profilecard.js +3 -1
  34. package/dist/es2019/hooks/useSharedPluginState.js +1 -6
  35. package/dist/es2019/i18n/cs.js +2 -1
  36. package/dist/es2019/i18n/da.js +2 -1
  37. package/dist/es2019/i18n/de.js +2 -1
  38. package/dist/es2019/i18n/en.js +1 -0
  39. package/dist/es2019/i18n/en_GB.js +1 -0
  40. package/dist/es2019/i18n/en_ZZ.js +1 -0
  41. package/dist/es2019/i18n/es.js +2 -1
  42. package/dist/es2019/i18n/fi.js +2 -1
  43. package/dist/es2019/i18n/fr.js +2 -1
  44. package/dist/es2019/i18n/hu.js +2 -1
  45. package/dist/es2019/i18n/it.js +2 -1
  46. package/dist/es2019/i18n/ja.js +2 -1
  47. package/dist/es2019/i18n/ko.js +2 -1
  48. package/dist/es2019/i18n/nb.js +2 -1
  49. package/dist/es2019/i18n/nl.js +2 -1
  50. package/dist/es2019/i18n/pl.js +2 -1
  51. package/dist/es2019/i18n/pt_BR.js +2 -1
  52. package/dist/es2019/i18n/ru.js +2 -1
  53. package/dist/es2019/i18n/sv.js +2 -1
  54. package/dist/es2019/i18n/th.js +7 -3
  55. package/dist/es2019/i18n/tr.js +4 -3
  56. package/dist/es2019/i18n/uk.js +2 -1
  57. package/dist/es2019/i18n/vi.js +2 -1
  58. package/dist/es2019/i18n/zh.js +3 -2
  59. package/dist/es2019/i18n/zh_TW.js +2 -1
  60. package/dist/es2019/monitoring/error.js +1 -1
  61. package/dist/es2019/preset/builder.js +528 -0
  62. package/dist/es2019/preset/core-plugin/index.js +1 -0
  63. package/dist/es2019/styles/shared/annotation.js +54 -29
  64. package/dist/es2019/types/index.js +9 -1
  65. package/dist/es2019/ui/DropList/index.js +1 -1
  66. package/dist/es2019/ui/Mention/mention-with-profilecard.js +2 -0
  67. package/dist/esm/hooks/useSharedPluginState.js +1 -4
  68. package/dist/esm/i18n/cs.js +2 -1
  69. package/dist/esm/i18n/da.js +2 -1
  70. package/dist/esm/i18n/de.js +2 -1
  71. package/dist/esm/i18n/en.js +1 -0
  72. package/dist/esm/i18n/en_GB.js +1 -0
  73. package/dist/esm/i18n/en_ZZ.js +1 -0
  74. package/dist/esm/i18n/es.js +2 -1
  75. package/dist/esm/i18n/fi.js +2 -1
  76. package/dist/esm/i18n/fr.js +2 -1
  77. package/dist/esm/i18n/hu.js +2 -1
  78. package/dist/esm/i18n/it.js +2 -1
  79. package/dist/esm/i18n/ja.js +2 -1
  80. package/dist/esm/i18n/ko.js +2 -1
  81. package/dist/esm/i18n/nb.js +2 -1
  82. package/dist/esm/i18n/nl.js +2 -1
  83. package/dist/esm/i18n/pl.js +2 -1
  84. package/dist/esm/i18n/pt_BR.js +2 -1
  85. package/dist/esm/i18n/ru.js +2 -1
  86. package/dist/esm/i18n/sv.js +2 -1
  87. package/dist/esm/i18n/th.js +7 -3
  88. package/dist/esm/i18n/tr.js +4 -3
  89. package/dist/esm/i18n/uk.js +2 -1
  90. package/dist/esm/i18n/vi.js +2 -1
  91. package/dist/esm/i18n/zh.js +3 -2
  92. package/dist/esm/i18n/zh_TW.js +2 -1
  93. package/dist/esm/monitoring/error.js +1 -1
  94. package/dist/esm/preset/builder.js +528 -0
  95. package/dist/esm/preset/core-plugin/index.js +1 -0
  96. package/dist/esm/styles/shared/annotation.js +20 -18
  97. package/dist/esm/types/index.js +9 -1
  98. package/dist/esm/ui/DropList/index.js +1 -1
  99. package/dist/esm/ui/Mention/mention-with-profilecard.js +3 -1
  100. package/dist/types/hooks/useSharedPluginState.d.ts +5 -5
  101. package/dist/types/i18n/cs.d.ts +1 -0
  102. package/dist/types/i18n/da.d.ts +1 -0
  103. package/dist/types/i18n/de.d.ts +1 -0
  104. package/dist/types/i18n/en.d.ts +1 -0
  105. package/dist/types/i18n/en_GB.d.ts +1 -0
  106. package/dist/types/i18n/en_ZZ.d.ts +1 -0
  107. package/dist/types/i18n/es.d.ts +1 -0
  108. package/dist/types/i18n/fi.d.ts +1 -0
  109. package/dist/types/i18n/fr.d.ts +1 -0
  110. package/dist/types/i18n/hu.d.ts +1 -0
  111. package/dist/types/i18n/it.d.ts +1 -0
  112. package/dist/types/i18n/ja.d.ts +1 -0
  113. package/dist/types/i18n/ko.d.ts +1 -0
  114. package/dist/types/i18n/nb.d.ts +1 -0
  115. package/dist/types/i18n/nl.d.ts +1 -0
  116. package/dist/types/i18n/pl.d.ts +1 -0
  117. package/dist/types/i18n/pt_BR.d.ts +1 -0
  118. package/dist/types/i18n/ru.d.ts +1 -0
  119. package/dist/types/i18n/sv.d.ts +1 -0
  120. package/dist/types/i18n/th.d.ts +4 -0
  121. package/dist/types/i18n/tr.d.ts +1 -0
  122. package/dist/types/i18n/uk.d.ts +1 -0
  123. package/dist/types/i18n/vi.d.ts +1 -0
  124. package/dist/types/i18n/zh.d.ts +1 -0
  125. package/dist/types/i18n/zh_TW.d.ts +1 -0
  126. package/dist/types/preset/builder.d.ts +550 -11
  127. package/dist/types/preset/core-plugin/index.d.ts +1 -1
  128. package/dist/types/preset/core-plugin/requestDocument.d.ts +1 -2
  129. package/dist/types/preset/index.d.ts +1 -0
  130. package/dist/types/preset/plugin-injection-api.d.ts +9 -3
  131. package/dist/types/styles/shared/annotation.d.ts +17 -0
  132. package/dist/types/types/index.d.ts +8 -7
  133. package/dist/types/types/next-editor-plugin.d.ts +641 -98
  134. package/dist/types/ui/Mention/mention-with-profilecard.d.ts +2 -1
  135. package/dist/types-ts4.5/hooks/useSharedPluginState.d.ts +5 -5
  136. package/dist/types-ts4.5/i18n/cs.d.ts +1 -0
  137. package/dist/types-ts4.5/i18n/da.d.ts +1 -0
  138. package/dist/types-ts4.5/i18n/de.d.ts +1 -0
  139. package/dist/types-ts4.5/i18n/en.d.ts +1 -0
  140. package/dist/types-ts4.5/i18n/en_GB.d.ts +1 -0
  141. package/dist/types-ts4.5/i18n/en_ZZ.d.ts +1 -0
  142. package/dist/types-ts4.5/i18n/es.d.ts +1 -0
  143. package/dist/types-ts4.5/i18n/fi.d.ts +1 -0
  144. package/dist/types-ts4.5/i18n/fr.d.ts +1 -0
  145. package/dist/types-ts4.5/i18n/hu.d.ts +1 -0
  146. package/dist/types-ts4.5/i18n/it.d.ts +1 -0
  147. package/dist/types-ts4.5/i18n/ja.d.ts +1 -0
  148. package/dist/types-ts4.5/i18n/ko.d.ts +1 -0
  149. package/dist/types-ts4.5/i18n/nb.d.ts +1 -0
  150. package/dist/types-ts4.5/i18n/nl.d.ts +1 -0
  151. package/dist/types-ts4.5/i18n/pl.d.ts +1 -0
  152. package/dist/types-ts4.5/i18n/pt_BR.d.ts +1 -0
  153. package/dist/types-ts4.5/i18n/ru.d.ts +1 -0
  154. package/dist/types-ts4.5/i18n/sv.d.ts +1 -0
  155. package/dist/types-ts4.5/i18n/th.d.ts +4 -0
  156. package/dist/types-ts4.5/i18n/tr.d.ts +1 -0
  157. package/dist/types-ts4.5/i18n/uk.d.ts +1 -0
  158. package/dist/types-ts4.5/i18n/vi.d.ts +1 -0
  159. package/dist/types-ts4.5/i18n/zh.d.ts +1 -0
  160. package/dist/types-ts4.5/i18n/zh_TW.d.ts +1 -0
  161. package/dist/types-ts4.5/preset/builder.d.ts +577 -13
  162. package/dist/types-ts4.5/preset/core-plugin/index.d.ts +1 -1
  163. package/dist/types-ts4.5/preset/core-plugin/requestDocument.d.ts +1 -2
  164. package/dist/types-ts4.5/preset/index.d.ts +1 -0
  165. package/dist/types-ts4.5/preset/plugin-injection-api.d.ts +9 -8
  166. package/dist/types-ts4.5/styles/shared/annotation.d.ts +17 -0
  167. package/dist/types-ts4.5/types/index.d.ts +8 -7
  168. package/dist/types-ts4.5/types/next-editor-plugin.d.ts +673 -127
  169. package/dist/types-ts4.5/ui/Mention/mention-with-profilecard.d.ts +2 -1
  170. package/package.json +2 -2
  171. package/dist/cjs/preset/core-plugin/types.js +0 -5
  172. package/dist/cjs/types/editor-public-api.js +0 -5
  173. package/dist/es2019/preset/core-plugin/types.js +0 -1
  174. package/dist/es2019/types/editor-public-api.js +0 -1
  175. package/dist/esm/preset/core-plugin/types.js +0 -1
  176. package/dist/esm/types/editor-public-api.js +0 -1
  177. package/dist/types/preset/core-plugin/types.d.ts +0 -59
  178. package/dist/types/types/editor-public-api.d.ts +0 -3
  179. package/dist/types-ts4.5/preset/core-plugin/types.d.ts +0 -59
  180. package/dist/types-ts4.5/types/editor-public-api.d.ts +0 -4
@@ -4,137 +4,680 @@
4
4
  * `Presets` - if the generics get too unwieldy, we may redesign how presets
5
5
  * are put together - but for now `Builder` & `Preset` aim to beinterchangeable.
6
6
  */
7
+ import type { JSONDocNode } from '@atlaskit/editor-json-transformer';
8
+ import type { Node, Schema } from '@atlaskit/editor-prosemirror/model';
7
9
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
8
- import type { CorePlugin } from '../preset/core-plugin/types';
10
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
11
  import type { EditorCommand, EditorCommandWithMetadata } from './editor-command';
10
12
  import type { EditorPlugin } from './editor-plugin';
11
- type IsAny<T> = 0 extends 1 & T ? true : false;
12
- type PickSharedStatePropertyName<Metadata extends NextEditorPluginMetadata> = IsAny<Metadata> extends true ? never : ExtractSharedStateFromMetadata<Metadata> extends never ? never : 'getSharedState';
13
+ export interface Transformer<T> {
14
+ encode(node: Node): T;
15
+ parse(content: T): Node;
16
+ }
17
+ export type CorePlugin = NextEditorPlugin<'core', {
18
+ pluginConfiguration: {
19
+ getEditorView: () => EditorView | undefined;
20
+ };
21
+ actions: {
22
+ /**
23
+ * Dispatches an EditorCommand to ProseMirror
24
+ *
25
+ * @param command A function (EditorCommand | undefined) that takes an object containing a `Transaction` and returns a `Transaction` if it
26
+ * is successful or `null` if it shouldn't be dispatched.
27
+ * @returns (boolean) if the command was successful in dispatching
28
+ */
29
+ execute: (command: EditorCommand | undefined) => boolean;
30
+ /**
31
+ * Focuses the editor.
32
+ *
33
+ * Calls the focus method of the `EditorView` and scrolls the
34
+ * current selection into view.
35
+ *
36
+ * @returns (boolean) if the focus was successful
37
+ */
38
+ focus: () => boolean;
39
+ /**
40
+ * Blurs the editor.
41
+ *
42
+ * Calls blur on the editor DOM element.
43
+ *
44
+ * @returns (boolean) if the blur was successful
45
+ */
46
+ blur: () => boolean;
47
+ /**
48
+ * Request the editor document.
49
+ * The document will return when available. If called multiple times it will throttle and return the
50
+ * latest document when ready.
51
+ *
52
+ * A transformer can be created using `createTransformer`.
53
+ *
54
+ * @param onReceive Callback to handle the document. Document type based on the transformer.
55
+ * @param options Pass a transformer for the document to be transformed into a different format.
56
+ */
57
+ requestDocument<GenericTransformer extends Transformer<any> = Transformer<JSONDocNode>>(onReceive: (document: TransformerResult<GenericTransformer> | undefined) => void, options?: {
58
+ transformer?: GenericTransformer;
59
+ }): void;
60
+ /**
61
+ * Create a transformer
62
+ *
63
+ * @param schema Schema of the document
64
+ * @returns Transformer which can be used to request a document
65
+ */
66
+ createTransformer<Format>(cb: (schema: Schema) => Transformer<Format>): Transformer<Format> | undefined;
67
+ };
68
+ }>;
69
+ export type TransformerResult<GenericTransformer = Transformer<JSONDocNode>> = GenericTransformer extends Transformer<infer Content> ? Content : JSONDocNode;
70
+ export type InferTransformerResultCallback<T extends Transformer<any> | undefined> = (doc: T extends Transformer<infer U> ? TransformerResult<U> : TransformerResult<JSONDocNode>) => void;
71
+ export type DefaultTransformerResultCallback = (doc: TransformerResult<JSONDocNode> | undefined) => void;
72
+ /*********************
73
+ * *
74
+ * BASE TYPES *
75
+ * *
76
+ **********************/
77
+ type MaybeAction = ((...agrs: any) => any) | ((...agrs: any) => void);
78
+ type NextEditorPluginActions = Record<string, MaybeAction>;
79
+ type NextEditorEditorCommands = Record<string, EditorCommandWithMetadata | EditorCommand>;
80
+ type OptionalPrivateProperty = {
81
+ __optionalPluginType: true;
82
+ };
83
+ /**
84
+ * 🧱 Internal Type: Editor FE Platform
85
+ *
86
+ * Conditionally picks the property name 'getSharedState' if the Metadata contains a sharedState definition.
87
+ *
88
+ * This type checks if the generic Metadata type for a plugin has a shared state. If it does, it enables
89
+ * the inclusion of the 'getSharedState' method name in the plugin's API type. Otherwise, it results in `never`,
90
+ * indicating the absence of shared state functionality in the plugin.
91
+ *
92
+ * @returns 'getSharedState' if shared state is defined in Metadata, otherwise `never`.
93
+ */
13
94
  type WithSharedState<Metadata extends NextEditorPluginMetadata> = {
14
95
  [Property in keyof Pick<Metadata, 'sharedState'> as PickSharedStatePropertyName<Metadata>]: (editorState: EditorState | undefined) => ExtractSharedStateFromMetadata<Metadata>;
15
96
  };
16
- type PickActionsPropertyName<Metadata extends NextEditorPluginMetadata> = IsAny<Metadata> extends true ? never : ExtractActionsFromMetadata<Metadata> extends never ? never : 'actions';
17
- type PickCommandsPropertyName<Metadata extends NextEditorPluginMetadata> = IsAny<Metadata> extends true ? never : ExtractCommandsFromMetadata<Metadata> extends never ? never : 'commands';
97
+ /**
98
+ * 🧱 Internal Type: Editor FE Platform
99
+ *
100
+ * Conditionally picks the property name 'actions' if the Metadata contains action definitions.
101
+ *
102
+ * This type evaluates whether the given Metadata for a plugin defines any actions. If actions are present,
103
+ * the 'actions' property name is included in the plugin's API type, enabling action handling. If there are no
104
+ * actions, it results in `never`.
105
+ *
106
+ * @returns 'actions' if actions are defined in Metadata, otherwise `never`.
107
+ */
18
108
  type WithActions<Metadata extends NextEditorPluginMetadata> = {
19
109
  [Property in keyof Pick<Metadata, 'actions'> as PickActionsPropertyName<Metadata>]: ExtractActionsFromMetadata<Metadata>;
20
110
  };
111
+ /**
112
+ * 🧱 Internal Type: Editor FE Platform
113
+ *
114
+ * Conditionally picks the property name 'commands' if the Metadata contains command definitions.
115
+ *
116
+ * This type assesses whether the provided Metadata for a plugin includes commands. If commands exist,
117
+ * it allows for the inclusion of the 'commands' property name in the plugin's API type, facilitating command
118
+ * execution. If no commands are defined, the result is `never`.
119
+ *
120
+ * @returns 'commands' if commands are defined in Metadata, otherwise `never`.
121
+ */
21
122
  type WithCommands<Metadata extends NextEditorPluginMetadata> = {
22
123
  [Property in keyof Pick<Metadata, 'commands'> as PickCommandsPropertyName<Metadata>]: ExtractCommandsFromMetadata<Metadata>;
23
124
  };
125
+ /****************************************************
126
+ * *
127
+ * METADATA PROPERTIES EXTRACTION TYPES *
128
+ * *
129
+ ****************************************************/
130
+ /**
131
+ * 🧱 Internal Type: Editor FE Platform
132
+ *
133
+ * Conditionally picks the property name 'getSharedState' if the Metadata contains a sharedState definition.
134
+ *
135
+ * This type checks if the generic Metadata type for a plugin has a shared state. If it does, it enables
136
+ * the inclusion of the 'getSharedState' method name in the plugin's API type. Otherwise, it results in `never`,
137
+ * indicating the absence of shared state functionality in the plugin.
138
+ *
139
+ * @template Metadata The metadata type to check for shared state.
140
+ * @returns 'getSharedState' if shared state is defined in Metadata, otherwise `never`.
141
+ */
142
+ type PickSharedStatePropertyName<Metadata extends NextEditorPluginMetadata> = IsAny<Metadata> extends true ? never : ExtractSharedStateFromMetadata<Metadata> extends never ? never : 'getSharedState';
143
+ /**
144
+ * 🧱 Internal Type: Editor FE Platform
145
+ *
146
+ * Conditionally picks the property name 'actions' if the Metadata contains action definitions.
147
+ *
148
+ * This type evaluates whether the given Metadata for a plugin defines any actions. If actions are present,
149
+ * the 'actions' property name is included in the plugin's API type, enabling action handling. If there are no
150
+ * actions, it results in `never`.
151
+ *
152
+ * @returns 'actions' if actions are defined in Metadata, otherwise `never`.
153
+ */
154
+ type PickActionsPropertyName<Metadata extends NextEditorPluginMetadata> = IsAny<Metadata> extends true ? never : ExtractActionsFromMetadata<Metadata> extends never ? never : 'actions';
155
+ /**
156
+ * 🧱 Internal Type: Editor FE Platform
157
+ *
158
+ * Conditionally picks the property name 'commands' if the Metadata contains command definitions.
159
+ *
160
+ * This type assesses whether the provided Metadata for a plugin includes commands. If commands exist,
161
+ * it allows for the inclusion of the 'commands' property name in the plugin's API type, facilitating command
162
+ * execution. If no commands are defined, the result is `never`.
163
+ *
164
+ * @returns 'commands' if commands are defined in Metadata, otherwise `never`.
165
+ */
166
+ type PickCommandsPropertyName<Metadata extends NextEditorPluginMetadata> = IsAny<Metadata> extends true ? never : ExtractCommandsFromMetadata<Metadata> extends never ? never : 'commands';
167
+ /**
168
+ * 🧱 Internal Type: Editor FE Platform
169
+ *
170
+ * Extracts the dependencies from the plugin Metadata, if any are defined.
171
+ *
172
+ * This type checks the Metadata for a 'dependencies' key and ensures it is a list of DependencyPlugin types.
173
+ * If dependencies are present, they are returned, excluding any potential `undefined` values. If no dependencies
174
+ * are defined, an empty array is returned.
175
+ *
176
+ * @returns An array of DependencyPlugin types if defined, otherwise an empty array.
177
+ */
178
+ type ExtractPluginDependenciesFromMetadata<Metadata> = 'dependencies' extends keyof Metadata ? Metadata['dependencies'] extends DependencyPlugin[] ? Exclude<Metadata['dependencies'], undefined> : [] : [];
179
+ /**
180
+ * 🧱 Internal Type: Editor FE Platform
181
+ *
182
+ * Extracts the shared state definition from the plugin Metadata, if present.
183
+ *
184
+ * This type looks for a 'sharedState' key within the Metadata. If found, it returns the associated type of the
185
+ * shared state. If the 'sharedState' key is not present, the result is `never`.
186
+ *
187
+ * @returns The shared state type if defined, otherwise `never`.
188
+ */
189
+ type ExtractSharedStateFromMetadata<Metadata> = 'sharedState' extends keyof Metadata ? Metadata['sharedState'] : never;
190
+ /**
191
+ * 🧱 Internal Type: Editor FE Platform
192
+ *
193
+ * Extracts the actions definition from the plugin Metadata, if available.
194
+ *
195
+ * This type queries the Metadata for an 'actions' key. If such a key exists, it returns the type of the
196
+ * defined actions. If there are no actions defined in the Metadata, the result is `never`.
197
+ *
198
+ * @returns The actions type if defined, otherwise `never`.
199
+ */
200
+ type ExtractActionsFromMetadata<Metadata> = 'actions' extends keyof Metadata ? Metadata['actions'] : never;
201
+ /**
202
+ * 🧱 Internal Type: Editor FE Platform
203
+ *
204
+ * Extracts the commands definition from the plugin Metadata, if it exists.
205
+ *
206
+ * By checking for a 'commands' key within the Metadata, this type determines if any commands are defined.
207
+ * If commands are present, their type is returned. If not, the result is `never`.
208
+ *
209
+ * @returns The commands type if defined, otherwise `never`.
210
+ */
211
+ type ExtractCommandsFromMetadata<Metadata> = 'commands' extends keyof Metadata ? Metadata['commands'] : never;
212
+ /**
213
+ * 🧱 Internal Type: Editor FE Platform
214
+ *
215
+ * Extracts the plugin name from a NextEditorPlugin type.
216
+ *
217
+ * This type attempts to derive the plugin name from a given NextEditorPlugin type by checking if the plugin
218
+ * is a function returning `DefaultEditorPlugin` with a specific name. If the name can be inferred, it is returned;
219
+ * otherwise, the result is `never`.
220
+ *
221
+ * @returns The inferred plugin name if possible, otherwise `never`.
222
+ */
223
+ type ExtractPluginName<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (...args: any) => DefaultEditorPlugin<infer PluginName, any> ? PluginName : never : never;
224
+ /********************************
225
+ * *
226
+ * TYPE INFER *
227
+ * *
228
+ *********************************/
229
+ /**
230
+ * 🧱 Internal Type: Editor FE Platform
231
+ *
232
+ * Utility type to check if a given type T is 'any'.
233
+ *
234
+ * This type exploits TypeScript's behavior to determine if a type is 'any'. It leverages the fact that
235
+ * 'any' is the only type assignable to both '1 & T' and '0'. If T is 'any', the type resolves to true;
236
+ * otherwise, it resolves to false.
237
+ *
238
+ * @returns `true` if T is 'any', otherwise `false`.
239
+ */
240
+ type IsAny<T> = 0 extends 1 & T ? true : false;
241
+ /******************************
242
+ * *
243
+ * EDITOR API MAPPED TUPLES *
244
+ * *
245
+ ******************************/
246
+ /**
247
+ * 🧱 Internal Type: Editor FE Platform
248
+ *
249
+ * Extracts and lists all required plugins from a tuple list of plugins, excluding any that are marked as optional.
250
+ *
251
+ * This recursive type iterates through a tuple of plugins, filtering out any plugins that are either undefined or
252
+ * explicitly marked as optional (using `OptionalPlugin`). The result is a new tuple containing only the required
253
+ * plugins. This is useful for determining the set of plugins that must be present for a certain feature or
254
+ * configuration to work.
255
+ *
256
+ * @returns A tuple of required plugins, with optional plugins removed.
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * type MyRequiredPlugins = ExtractRequiredPlugins<[OptionalPlugin<MyPlugin>, MyPlugin2]>;
261
+ *
262
+ * // Type: [MyPlugin2].
263
+ * ```
264
+ */
265
+ type ExtractRequiredPlugins<TuplePluginList extends [...any[]]> = TuplePluginList extends [
266
+ infer First,
267
+ ...infer Rest
268
+ ] ? undefined extends First ? ExtractRequiredPlugins<Rest> : First extends OptionalPlugin<NextEditorPlugin<any, any>> ? ExtractRequiredPlugins<Rest> : First extends NextEditorPlugin<any, any> ? [First, ...ExtractRequiredPlugins<[...Rest]>] : ExtractRequiredPlugins<Rest> : [];
269
+ /**
270
+ * 🧱 Internal Type: Editor FE Platform
271
+ *
272
+ * Extracts and lists all optional plugins from a tuple list of plugins, including any that are explicitly marked as
273
+ * optional or are undefined.
274
+ *
275
+ * This type recursively scans through a tuple of plugins, collecting plugins that are either marked as `undefined`
276
+ * or wrapped with `OptionalPlugin`. The result is a new tuple consisting solely of these optional plugins, effectively
277
+ * separating them from the required ones. This type is instrumental in configurations where optional dependencies
278
+ * need to be distinguished from required ones for conditional loading or initialization.
279
+ *
280
+ * @returns A tuple of optional plugins, excluding required ones.
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * type MyOptionalPlugins = ExtractOptionalPlugins<[OptionalPlugin<MyPlugin>, MyPlugin2]>;
285
+ *
286
+ * // Type: [MyPlugin].
287
+ * ```
288
+ */
289
+ type ExtractOptionalPlugins<TuplePluginList extends [...any[]]> = TuplePluginList extends [
290
+ infer First,
291
+ ...infer Rest
292
+ ] ? undefined extends First ? [First, ...ExtractOptionalPlugins<[...Rest]>] : First extends OptionalPlugin<infer Plugin> ? [Plugin, ...ExtractOptionalPlugins<[...Rest]>] : ExtractOptionalPlugins<[...Rest]> : [];
293
+ /**
294
+ * 🧱 Internal Type: Editor FE Platform
295
+ *
296
+ * Extracts the shared state type from a plugin or its metadata.
297
+ *
298
+ * This type conditionally checks whether the input is a NextEditorPlugin instance or directly NextEditorPluginMetadata.
299
+ * If the input is a plugin instance, it attempts to infer the Metadata type from the plugin's constructor function signature,
300
+ * specifically looking for a shared state definition. If the input is directly plugin metadata, it extracts the shared state
301
+ * definition directly from the metadata.
302
+ *
303
+ * @returns The type of the shared state if defined, otherwise `never`.
304
+ */
305
+ export type ExtractPluginSharedState<PluginOrMetadata> = PluginOrMetadata extends NextEditorPlugin<any, any> ? PluginOrMetadata extends (props: {
306
+ config: any;
307
+ api: any;
308
+ }) => DefaultEditorPlugin<any, infer Metadata> ? ExtractSharedStateFromMetadata<Metadata> : never : PluginOrMetadata extends NextEditorPluginMetadata ? ExtractSharedStateFromMetadata<PluginOrMetadata> : never;
309
+ /**
310
+ * 🧱 Internal Type: Editor FE Platform
311
+ *
312
+ * Extracts the actions definition from a plugin or its metadata.
313
+ *
314
+ * Similar to `ExtractPluginSharedState`, this type discerns whether it is dealing with a NextEditorPlugin instance
315
+ * or its metadata. It then attempts to extract or infer the actions defined within. For a plugin instance, it looks
316
+ * into the plugin's constructor function signature to infer the Metadata and subsequently extracts any actions defined.
317
+ * If dealing with plugin metadata directly, it extracts the actions from there.
318
+ *
319
+ * @returns The actions definition if available, otherwise `never`.
320
+ */
321
+ export type ExtractPluginActions<PluginOrMetadata> = PluginOrMetadata extends NextEditorPlugin<any, any> ? PluginOrMetadata extends (props: {
322
+ config: any;
323
+ api: any;
324
+ }) => DefaultEditorPlugin<any, infer Metadata> ? ExtractActionsFromMetadata<Metadata> : never : PluginOrMetadata extends NextEditorPluginMetadata ? ExtractActionsFromMetadata<PluginOrMetadata> : never;
325
+ /*****************************
326
+ * *
327
+ * MAPPED TYPES *
328
+ * *
329
+ ******************************/
330
+ /**
331
+ * 🧱 Internal Type: Editor FE Platform
332
+ *
333
+ * Constructs a unified API object from a list of plugins, combining the optional injection APIs of each.
334
+ *
335
+ * This type recursively processes a list of plugins, extracting the name and metadata from each to construct
336
+ * an `EditorOptionalInjectionAPI` for it. These APIs are then combined into a single object, allowing for
337
+ * a comprehensive API interface that includes all provided plugins.
338
+ *
339
+ * @returns An object representing the combined API of all plugins in the list.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * type MyEditorAPI = PublicPluginAPIFromPlugins<[PluginA, PluginB]>;
344
+ * ```
345
+ */
346
+ type PublicPluginAPIFromPlugins<PluginList extends NextEditorPlugin<any, any>[]> = PluginList extends [infer Head, ...infer Tail] ? Head extends NextEditorPlugin<infer Name, infer Metadata> ? EditorOptionalInjectionAPI<Name, Metadata> & PublicPluginAPIFromPlugins<Tail extends NextEditorPlugin<any, any>[] ? Tail : []> : {} : {};
347
+ /**
348
+ * 🧱 Internal Type: Editor FE Platform
349
+ *
350
+ * Generates an object type mapping each plugin's name to its dependencies API, ensuring all dependencies are required.
351
+ *
352
+ * This type iterates over a list of plugins, extracting each plugin's name and associating it with its respective
353
+ * dependencies API (`PluginDependenciesAPI`). The resulting object type requires all listed plugins to have their
354
+ * dependencies satisfied, making this useful for constructing contexts where all plugin dependencies are mandatory.
355
+ *
356
+ * @returns An object type with a required dependencies API for each plugin.
357
+ */
358
+ type RequiredPluginDependenciesAPI<PluginList extends NextEditorPlugin<any, any>[]> = {
359
+ [Plugin in PluginList[number] as `${ExtractPluginName<Plugin>}`]: PluginDependenciesAPI<Plugin>;
360
+ };
361
+ /**
362
+ * 🧱 Internal Type: Editor FE Platform
363
+ *
364
+ * Creates an object type mapping each plugin's name to its dependencies API, marking all dependencies as optional.
365
+ *
366
+ * Similar to `RequiredPluginDependenciesAPI`, but marks each plugin's dependencies API as optional. This is particularly
367
+ * useful in scenarios where plugins may have optional functionality that should not enforce the presence of certain
368
+ * dependencies.
369
+ *
370
+ * @returns An object type with an optional dependencies API for each plugin.
371
+ */
372
+ type OptionalPluginDependenciesAPI<PluginList extends NextEditorPlugin<any, any>[]> = {
373
+ [Plugin in PluginList[number] as `${ExtractPluginName<Plugin>}`]+?: PluginDependenciesAPI<Plugin> | undefined;
374
+ };
375
+ /**
376
+ * 🧱 Internal Type: Editor FE Platform
377
+ *
378
+ * Constructs a dependencies API object for a plugin itself, identified by its name, using its metadata.
379
+ *
380
+ * This type maps the plugin's name to its own `BasePluginDependenciesAPI` based on its metadata. It's useful for
381
+ * creating a self-reference within the plugin's API, allowing the plugin to access its own shared state, actions,
382
+ * and commands.
383
+ *
384
+ * @returns An object with the plugin's own dependencies API.
385
+ */
386
+ type SelfPluginDependenciesAPI<Name extends string, Metadata extends NextEditorPluginMetadata> = {
387
+ [Plugin in Name]: BasePluginDependenciesAPI<Metadata>;
388
+ };
389
+ /**
390
+ * 🧱 Internal Type: Editor FE Platform
391
+ *
392
+ * Similar to `SelfPluginDependenciesAPI`, but marks the plugin's own dependencies API as optional.
393
+ */
394
+ type SelfOptionalPluginDependenciesAPI<Name extends string, Metadata extends NextEditorPluginMetadata> = {
395
+ [Plugin in Name]?: BasePluginDependenciesAPI<Metadata> | undefined;
396
+ };
397
+ /*************************
398
+ * *
399
+ * PUBLIC TYPES *
400
+ * *
401
+ *************************/
402
+ /**
403
+ * 🧱 Internal Type: Editor FE Platform
404
+ *
405
+ * ⚠️⚠️⚠️ Any breaking change here will have a massive impact across all Editor Plugin packages ⚠️⚠️⚠️
406
+ *
407
+ * The runtime implementation for NextEditorPlugin.
408
+ *
409
+ * All types prefixed `With` are being used in the EditorInjectionAPI.
410
+ * Some infer operations required this intersection approach.
411
+ *
412
+ * @example
413
+ * For instance, when a `sharedState` is declared in NextEditorPluginMetadata
414
+ * then the plugin needs to implement a `getSharedState` function.
415
+ *
416
+ * @see WithSharedState
417
+ * @see WithActions
418
+ * @see WithCommands
419
+ */
24
420
  export type DefaultEditorPlugin<Name extends string, Metadata extends NextEditorPluginMetadata> = EditorPlugin & WithSharedState<Metadata> & WithActions<Metadata> & WithCommands<Metadata> & {
25
421
  name: Name;
26
422
  };
27
- type MaybeAction = ((...agrs: any) => any) | ((...agrs: any) => void);
28
- type NextEditorPluginActions = Record<string, MaybeAction>;
29
- type NextEditorEditorCommands = Record<string, EditorCommandWithMetadata | EditorCommand>;
423
+ /**
424
+ * 🧱 Internal Type: Editor FE Platform
425
+ *
426
+ * ⚠️⚠️⚠️ Any breaking change here will have a massive impact across all Editor Plugin packages ⚠️⚠️⚠️
427
+ *
428
+ * If you are not from Editor Platform FE, you shouldn't be using or changing this.
429
+ */
30
430
  export interface NextEditorPluginMetadata {
431
+ /**
432
+ * The real implementation will be infered by BasePluginDependenciesAPI and other
433
+ * internal types.
434
+ */
31
435
  readonly sharedState?: any;
436
+ /**
437
+ * The real implementation will be infered by Preset internal types and @see NextEditorPluginFunctionOptionalConfigDefinition
438
+ */
32
439
  readonly pluginConfiguration?: any;
440
+ /**
441
+ * This is used only on compile time. There is no runtime implementation for the dependencies
442
+ * @see DependencyPlugin
443
+ */
33
444
  readonly dependencies?: DependencyPlugin[];
445
+ /**
446
+ * @see NextEditorPluginActions
447
+ */
34
448
  readonly actions?: NextEditorPluginActions;
449
+ /**
450
+ *
451
+ * @see NextEditorEditorCommands
452
+ */
35
453
  readonly commands?: NextEditorEditorCommands;
36
454
  }
37
455
  /**
38
- * `PluginInjectionAPI` doesn't actually use `dependencies`,
39
- * we should use it as PluginInjectionAPI< ... >['dependencies']
40
- * it is only here because otherwise typescript blows up
41
- * trying to compare `PluginInjectionAPI` to `PublicPluginAPI`
456
+ * 🧱 Internal Type: Editor FE Platform
457
+ *
458
+ * ⚠️⚠️⚠️ Any breaking change here will have a massive impact across all Editor Plugin packages ⚠️⚠️⚠️
42
459
  */
43
- export type PluginInjectionAPI<Name extends string, Metadata extends NextEditorPluginMetadata> = {
44
- dependencies: PublicPluginAPI<[
45
- NextEditorPlugin<Name, Metadata>,
46
- ...ExtractPluginDependenciesFromMetadata<Metadata>
47
- ]>;
48
- };
49
- export type PluginInjectionAPIWithDependencies<Plugins extends NextEditorPlugin<any, any>[]> = PublicPluginAPI<Plugins>;
50
460
  export type NextEditorPluginFunctionOptionalConfigDefinition<Name extends string, Metadata extends NextEditorPluginMetadata, Configuration = undefined> = (props: {
51
461
  config: Configuration;
52
- api?: PluginInjectionAPI<Name, Metadata>['dependencies'];
462
+ api?: {
463
+ [Plugin in Name]: BasePluginDependenciesAPI<Metadata>;
464
+ } & RequiredPluginDependenciesAPI<ExtractRequiredPlugins<[CorePlugin, ...ExtractPluginDependenciesFromMetadata<Metadata>]>> & OptionalPluginDependenciesAPI<ExtractOptionalPlugins<ExtractPluginDependenciesFromMetadata<Metadata>>>;
53
465
  }) => DefaultEditorPlugin<Name, Metadata>;
54
- type OptionalPrivateProperty = {
55
- __optionalPluginType: true;
56
- };
466
+ /**
467
+ * 📢 Public Type API: Helps Editor Plugin developers to defined optional dependencies for their plugins.
468
+ *
469
+ * You shouldn't be using this in any other place outside the `NextEditorPlugin`.
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * const toolbarPlugin: NextEditorPlugin<'toolbar', {
474
+ * dependencies: [
475
+ * OptionalPlugin<TablePlugin>,
476
+ * ListsPlugin,
477
+ * ]
478
+ * }>
479
+ * ```
480
+ *
481
+ * Later on, this will be used by
482
+ *
483
+ * @see ExtractInjectionAPI - Optional dependencies will need can be undefined on runtime. So, a null-check is required
484
+ */
57
485
  export type OptionalPlugin<EditorPlugin extends NextEditorPlugin<any, any>> = EditorPlugin & OptionalPrivateProperty;
58
- type DependencyPlugin = OptionalPlugin<NextEditorPlugin<any, any>> | NextEditorPlugin<any, any>;
486
+ /**
487
+ * 🧱 Internal Type: Editor FE Platform
488
+ *
489
+ * @see NextEditorPluginMetadata
490
+ */
491
+ export type DependencyPlugin = OptionalPlugin<NextEditorPlugin<any, any>> | NextEditorPlugin<any, any>;
492
+ /**
493
+ * 📢 Public Type API
494
+ *
495
+ * The base type for the entire Editor Plugin Ecosystem.
496
+ *
497
+ * The first parameter is the only one required,
498
+ * it used to force the plugin to have a runtime string:
499
+ *
500
+ * ```typescript
501
+ * const plugin: NextEditorPlugin<'hello'> = () => ({
502
+ * // This string should match the name declared in the `NextEditorPlugin`
503
+ * name: 'hello',
504
+ * })
505
+ *
506
+ * // Later, this name is how other plugins will be able access your plugin API:
507
+ * // api?.hello?.actions
508
+ * ```
509
+ *
510
+ * @see NextEditorPluginMetadata for the second parameter
511
+ */
59
512
  export type NextEditorPlugin<Name extends string, Metadata extends NextEditorPluginMetadata = {}> = Metadata extends NextEditorPluginMetadata ? 'pluginConfiguration' extends keyof Metadata ? NextEditorPluginFunctionOptionalConfigDefinition<Name, Metadata, Metadata['pluginConfiguration']> : NextEditorPluginFunctionOptionalConfigDefinition<Name, Metadata> : never;
60
- type FilterOptionalPlugins<T extends DependencyPlugin[]> = T extends [infer Head, ...infer Tail] ? Tail extends DependencyPlugin[] ? Head extends OptionalPlugin<NextEditorPlugin<any, any>> ? FilterOptionalPlugins<Tail> : [Head, ...FilterOptionalPlugins<Tail>] : T : T;
61
- type ExtractPluginDependenciesFromMetadataWithoutOptionals<Metadata extends NextEditorPluginMetadata> = Metadata['dependencies'] extends DependencyPlugin[] ? FilterOptionalPlugins<Metadata['dependencies']> : [];
62
- type ExtractPluginDependenciesFromMetadata<Metadata> = 'dependencies' extends keyof Metadata ? Metadata['dependencies'] extends DependencyPlugin[] ? Exclude<Metadata['dependencies'], undefined> : [] : [];
63
- type ExtractSharedStateFromMetadata<Metadata> = 'sharedState' extends keyof Metadata ? Metadata['sharedState'] : never;
64
- type ExtractActionsFromMetadata<Metadata> = 'actions' extends keyof Metadata ? Metadata['actions'] : never;
65
- type ExtractCommandsFromMetadata<Metadata> = 'commands' extends keyof Metadata ? Metadata['commands'] : never;
66
- type ExtractPluginConfigurationFromMetadata<Metadata> = 'pluginConfiguration' extends keyof Metadata ? Metadata['pluginConfiguration'] : never;
67
- export type ExtractPluginDependencies<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (props: {
68
- config: any;
69
- api: any;
70
- }) => DefaultEditorPlugin<any, infer Metadata> ? ExtractPluginDependenciesFromMetadataWithoutOptionals<Metadata> : never : never;
71
- type ExtractPluginConfiguration<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (props: {
72
- config: any;
73
- api: any;
74
- }) => DefaultEditorPlugin<any, infer Metadata> ? ExtractPluginConfigurationFromMetadata<Metadata> : never : never;
75
- export type ExtractPluginSharedState<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (props: {
76
- config: any;
77
- api: any;
78
- }) => DefaultEditorPlugin<any, infer Metadata> ? ExtractSharedStateFromMetadata<Metadata> : never : never;
79
- export type ExtractPluginActions<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (props: {
80
- config: any;
81
- api: any;
82
- }) => DefaultEditorPlugin<any, infer Metadata> ? ExtractActionsFromMetadata<Metadata> : never : never;
83
- type ExtractPluginName<Plugin> = Plugin extends NextEditorPlugin<any, any> ? Plugin extends (...args: any) => DefaultEditorPlugin<infer PluginName, any> ? PluginName : never : never;
84
513
  type Unsubscribe = () => void;
85
- export type PluginDependenciesAPI<Plugin extends NextEditorPlugin<any, any>> = {
514
+ /**
515
+ * 🧱 Internal Type: Editor FE Platform
516
+ *
517
+ */
518
+ export type BasePluginDependenciesAPI<Metadata extends NextEditorPluginMetadata> = {
86
519
  sharedState: {
87
- currentState: () => ExtractPluginSharedState<Plugin> | undefined;
520
+ currentState: () => ExtractPluginSharedState<Metadata> | undefined;
88
521
  onChange: (sub: (props: {
89
- nextSharedState: ExtractPluginSharedState<Plugin>;
90
- prevSharedState: ExtractPluginSharedState<Plugin>;
522
+ nextSharedState: ExtractPluginSharedState<Metadata>;
523
+ prevSharedState: ExtractPluginSharedState<Metadata>;
91
524
  }) => void) => Unsubscribe;
92
525
  };
93
- actions: ExtractPluginActions<Plugin>;
94
- commands: Plugin extends NextEditorPlugin<any, infer Metadata> ? ExtractCommandsFromMetadata<Metadata> : never;
95
- };
96
- export type CreatePluginDependenciesAPI<PluginList extends NextEditorPlugin<any, any>[]> = {
97
- [Plugin in PluginList[number] as `${ExtractPluginName<Plugin>}`]: Plugin extends OptionalPlugin<NextEditorPlugin<any, any>> ? PluginDependenciesAPI<Plugin> | undefined : Plugin extends NextEditorPlugin<'core', any> ? PluginDependenciesAPI<Plugin> : Plugin extends NextEditorPlugin<any, any> ? PluginDependenciesAPI<Plugin> | undefined : never;
98
- };
99
- export type PluginWithConfiguration<Plugin> = undefined extends ExtractPluginConfiguration<Plugin> ? [Plugin, ExtractPluginConfiguration<Plugin>?] : [Plugin, ExtractPluginConfiguration<Plugin>];
100
- export type MaybePluginName<T extends string> = [T];
101
- export type PresetPlugin = PluginWithConfiguration<any> | NextEditorPlugin<any, any>;
102
- export type MaybePlugin<T extends PresetPlugin> = T | undefined;
103
- export type AllEditorPresetPluginTypes = PresetPlugin | MaybePlugin<NextEditorPlugin<any, any>>;
104
- type ExtractNextEditorPlugin<Plugin> = Plugin extends PluginWithConfiguration<any> ? Plugin[0] : never;
105
- export type VerifyPluginDependencies<Plugin, PluginsStack extends AllEditorPresetPluginTypes[]> = ExtractPluginDependencies<Plugin> extends [] ? Plugin extends PluginWithConfiguration<any> | NextEditorPlugin<any, any> ? Plugin : never :
106
- /**
107
- * case 1: We're looking for its dependent plugins indexed on `AllEditorPresetPluginTypes`
108
- */
109
- ExtractPluginDependencies<Plugin>[number] extends (ExtractPluginDependencies<Plugin>[number] & PluginsStack[number])
110
- /**
111
- * case 2:
112
- * Otherwise check whether the dependent-plugin, is hidden inside a tuple,
113
- * unwrapping `Plugins` via `ExtractNextEditorPlugin`
114
- */
115
- | (ExtractPluginDependencies<Plugin>[number] & ExtractNextEditorPlugin<PluginsStack[number]>) ? Plugin : never;
116
- type FilterExistingPlugins<T extends DependencyPlugin[], PluginsStack extends AllEditorPresetPluginTypes[]> = T extends [infer CurrentPluginDependency, ...infer RemainingPluginDependencies] ? RemainingPluginDependencies extends DependencyPlugin[] ? CurrentPluginDependency extends PluginsStack[number] ? FilterExistingPlugins<RemainingPluginDependencies, PluginsStack> : [
117
- CurrentPluginDependency,
118
- ...FilterExistingPlugins<RemainingPluginDependencies, PluginsStack>
119
- ] : T : T;
120
- type DependencyErrorMessage<Message extends string> = {
121
- errorMessage: Message;
122
- };
123
- 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'>;
124
- type GetDependencyErrorMessage<Plugin, StackPlugins extends AllEditorPresetPluginTypes[]> = ExtractRequiredDependencies<Plugin, StackPlugins> extends string ? DependencyErrorMessage<`Missing dependency: ${ExtractRequiredDependencies<Plugin, StackPlugins>}Plugin`> : ExtractRequiredDependencies<Plugin, StackPlugins>;
125
- export 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;
126
- /**
127
- * Used to check if a plugin being added can be added to a Preset/builder
128
- */
129
- 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>;
130
- type CheckTupleRequirements<Plugin, Config, ArrayType> = unknown extends Config ? Plugin | ArrayType : undefined extends Config ? Plugin | ArrayType : [
131
- Config
132
- ] extends [never] ? Plugin : ArrayType;
133
- type CheckBasicPlugin<Plugin> = Plugin extends (args: any, api: any) => EditorPlugin ? CheckTupleRequirements<Plugin, ExtractPluginConfiguration<Plugin>, PluginWithConfiguration<Plugin>> : never;
134
- export type ExtractPluginNameFromAllBuilderPlugins<Plugin extends PresetPlugin> = Plugin extends Array<any> ? Plugin extends [infer MPlugin, ...any] ? MPlugin extends NextEditorPlugin<any, any> ? ExtractPluginName<MPlugin> : never : never : Plugin extends NextEditorPlugin<any, any> ? ExtractPluginName<Plugin> : never;
135
- export type ExtractInjectionAPI<Plugin> = Plugin extends NextEditorPlugin<infer Name, infer Metadata> ? PluginInjectionAPI<Name, Metadata>['dependencies'] : never;
136
- export type PublicPluginAPI<PluginList extends NextEditorPlugin<any, any>[]> = CreatePluginDependenciesAPI<[...PluginList, CorePlugin]>;
137
- export type ExtractNextEditorPlugins<Plugins extends AllEditorPresetPluginTypes[]> = {
138
- [PluginNumber in keyof Plugins]: Plugins[PluginNumber] extends MaybePlugin<NextEditorPlugin<infer Name, infer Metadata>> ? NextEditorPlugin<Name, Metadata> : Plugins[PluginNumber] extends MaybePlugin<NextEditorPlugin<infer Name, infer Metadata>> ? NextEditorPlugin<Name, Metadata> : never;
526
+ actions: ExtractPluginActions<Metadata>;
527
+ commands: ExtractCommandsFromMetadata<Metadata>;
139
528
  };
529
+ /**
530
+ * 🧱 Internal Type: Editor FE Platform
531
+ *
532
+ * Type that defines a Editor API based on a NextEditorPlugin.
533
+ *
534
+ *
535
+ * If you are not from Editor Platform FE, you shouldn't be using or changing this.
536
+ */
537
+ export type PluginDependenciesAPI<Plugin extends NextEditorPlugin<any, any>> = Plugin extends NextEditorPlugin<any, infer Metadata> ? BasePluginDependenciesAPI<Metadata> : never;
538
+ /**
539
+ * 🧱 Internal Type: Editor FE Platform
540
+ *
541
+ *
542
+ * Type to enable thats create a API based ona single plugin:
543
+ *
544
+ * - The plugin itself will become a required property
545
+ * - Its optional dependencies will become a non-required property
546
+ * - Its required dependencies will become a required property
547
+ * - Core will be a required property
548
+ */
549
+ export type EditorInjectionAPI<Name extends string, Metadata extends NextEditorPluginMetadata> = {
550
+ core: PluginDependenciesAPI<CorePlugin>;
551
+ } & SelfPluginDependenciesAPI<Name, Metadata> & RequiredPluginDependenciesAPI<ExtractRequiredPlugins<ExtractPluginDependenciesFromMetadata<Metadata>>> & OptionalPluginDependenciesAPI<ExtractOptionalPlugins<ExtractPluginDependenciesFromMetadata<Metadata>>>;
552
+ /**
553
+ * 🧱 Internal Type: Editor FE Platform
554
+ *
555
+ * Helper type to enable thats create a fully optional API based ona single plugin:
556
+ *
557
+ * - The plugin itself will become a non-required property
558
+ * - Its optional dependencies will become a non-required property
559
+ * - Its required dependencies will become a non-required property
560
+ * - Core will be a required property
561
+ */
562
+ export type EditorOptionalInjectionAPI<Name extends string, Metadata extends NextEditorPluginMetadata> = {
563
+ core: PluginDependenciesAPI<CorePlugin>;
564
+ } & SelfOptionalPluginDependenciesAPI<Name, Metadata> & OptionalPluginDependenciesAPI<ExtractRequiredPlugins<ExtractPluginDependenciesFromMetadata<Metadata>>> & OptionalPluginDependenciesAPI<ExtractOptionalPlugins<ExtractPluginDependenciesFromMetadata<Metadata>>>;
565
+ /**
566
+ * 📢 Public Type API: Helps Editor Plugin developers to build the EditorInjectAPI type for their internal plugin development.
567
+ *
568
+ * You should use this API if you are:
569
+ * - Working inside a EditorPlugin package, e.g.: `@atlaskit/editor-table-plugin`.
570
+ * - Trying to use it to receive an API from the NextEditorPlugin argument.
571
+ *
572
+ * You should not use this API if you are:
573
+ *
574
+ * - Using it outside an EditorPlugin package
575
+ * - Trying to use it to receive an API directly from EditorPresetBuilder
576
+ *
577
+ * This type will used the base plugin dependencies to build the type.
578
+ * ```typescript
579
+ *
580
+ * type PluginDog = NextEditorPlugin<'dog'>;
581
+ * type PluginBark = NextEditorPlugin<'bark', { dependencies: [PluginDog], actions: { doBark: () => void }}>;
582
+ *
583
+ * type MyPlugin = NextEditorPlugin<'myPlugin', { dependencies: [PluginBark] }>;
584
+ * type MyAPI = ExtractInjectionAPI<MyPlugin>;
585
+ *
586
+ * const somePluginInternalFunction = (api?: MyAPI) => {
587
+ * api?.bark.actions.doBark();
588
+ * }
589
+ * ```
590
+ *
591
+ * If the dependency is marked as OptionalPlugin then the API will return it as optional property too:
592
+ *
593
+ *```typescript
594
+ *
595
+ * type PluginDog = NextEditorPlugin<'dog'>;
596
+ * type PluginBark = NextEditorPlugin<'bark', { dependencies: [PluginDog], actions: { doBark: () => void }}>;
597
+ *
598
+ * type MyPlugin = NextEditorPlugin<'myPlugin', { dependencies: [OptionalPlugin<PluginBark>] }>;
599
+ * type MyAPI = ExtractInjectionAPI<MyPlugin>;
600
+ *
601
+ * const somePluginInternalFunction = (api?: MyAPI) => {
602
+ * // Now, you will need to do a null check
603
+ * api?.bark?.actions.doBark();
604
+ * }
605
+ * ```
606
+ *
607
+ * A `NextEditorPlugin` will receive an `api` argument that match with this helper type:
608
+ * ```typescript
609
+ *
610
+ * type PluginDog = NextEditorPlugin<'dog'>;
611
+ *
612
+ * const dogPlugin: PluginDog = ({ api }) => {
613
+ * type ReceivedAPI = typeof api;
614
+ * type BuiltAPI = ExtractInjectionAPI<PluginDog>;
615
+ *
616
+ * type AssertTrue = BuiltAPI extends ReceivedAPI ? true : false;
617
+ * return {
618
+ * name: 'dog';
619
+ * }
620
+ * };
621
+ * ```
622
+ *
623
+ * However, this is not compatible with the EditorPresetBuilder API
624
+ * due to possibility some plugins maybe be not be available on runtime.
625
+ *
626
+ * ```typescript
627
+ *
628
+ * type PluginDog = NextEditorPlugin<'dog'>;
629
+ *
630
+ * const dogPlugin: PluginDog = ({ api }) => ({ name: 'dog' });
631
+ * const preset = new EditorPresetBuilder()
632
+ * .maybeAdd(dogPlugin, false);
633
+ *
634
+ * type BuiltAPI = ExtractInjectionAPI<typeof dogPlugin>;
635
+ * type PresetAPI = ExtractPresetAPI<typeof preset>;
636
+ *
637
+ *
638
+ * type AssertFalse = BuiltAPI extends PresetAPI ? true : false;
639
+ * // If you need to match the API from a Preset, you should use `PublicPluginAPI`
640
+ *
641
+ * ```
642
+ *
643
+ * P.S.: This type will implicitly inject the CorePlugin as required attribute.
644
+ */
645
+ export type ExtractInjectionAPI<Plugin extends NextEditorPlugin<any, any>> = Plugin extends NextEditorPlugin<infer Name, infer Metadata> ? EditorInjectionAPI<Name, Metadata> : never;
646
+ /**
647
+ * 📢 Public Type API: Helps Product developers to build the EditorInjectAPI type for external use in the product codebase.
648
+ *
649
+ * You may use more than one plugin:
650
+ * ```typescript
651
+ * PublicPluginAPI<[PluginDog, PluginCat]>
652
+ * ```
653
+ *
654
+ * You should use this API if you are:
655
+ * - Working inside a non EditorPlugin, e.g.: `@atlaskit/chat-ai-mate`.
656
+ * - Trying to use it to receive an API directly from EditorPresetBuilder
657
+ *
658
+ * - Working
659
+ *
660
+ * The API type will consider all plugins as optional. That means,
661
+ * you will need to do the null safe check when using the type implementation,
662
+ *
663
+ * ```typescript
664
+ *
665
+ * type MyCustomEditorPlugin = NextEditorPlugin<'custom', { actions: { something: () => boolean } }>;
666
+ * const myPlugin: MyCustomEditorPlugin = () => ({ name: 'custom', actions: { something: () => true }});
667
+ *
668
+ * type Props = {
669
+ * api?: PublicPluginAPI<[MyCustomEditorPlugin]>
670
+ * }
671
+ *
672
+ * // There is no way to guarantee the API will have the plugin requested.
673
+ * // So, this will force developers to do the safe check.
674
+ * function useMyHook({ api }: Props) {
675
+ * api?.custom?.actions.something();
676
+ * return null;
677
+ * }
678
+ * ```
679
+ *
680
+ * P.S.: This type will implicitly inject the CorePlugin as required attribute.
681
+ */
682
+ export type PublicPluginAPI<MaybePlugin extends NextEditorPlugin<any, any>[] | NextEditorPlugin<any, any>> = MaybePlugin extends NextEditorPlugin<infer Name, infer Metadata> ? EditorOptionalInjectionAPI<Name, Metadata> : PublicPluginAPIFromPlugins<MaybePlugin extends NextEditorPlugin<any, any>[] ? MaybePlugin : never>;
140
683
  export {};