@selfhelp/shared 1.3.0 → 1.3.1

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 (58) hide show
  1. package/CHANGELOG.md +341 -341
  2. package/LICENSE +381 -381
  3. package/README.md +57 -57
  4. package/package.json +102 -102
  5. package/src/api/__tests__/endpoints.test.ts +45 -45
  6. package/src/api/index.ts +5 -5
  7. package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
  8. package/src/assets/index.ts +5 -5
  9. package/src/assets/resolveAssetUrl.ts +44 -44
  10. package/src/cms-classes/__tests__/classify.test.ts +63 -63
  11. package/src/cms-classes/allow-list.ts +158 -158
  12. package/src/cms-classes/classify.ts +90 -90
  13. package/src/cms-classes/index.ts +7 -7
  14. package/src/cms-classes/remap.ts +44 -44
  15. package/src/condition/__tests__/evaluate.test.ts +54 -54
  16. package/src/condition/evaluate.ts +121 -121
  17. package/src/condition/index.ts +5 -5
  18. package/src/index.ts +25 -25
  19. package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
  20. package/src/interpolation/index.ts +5 -5
  21. package/src/interpolation/replaceCalcedValues.ts +27 -27
  22. package/src/plugin-sdk/define.ts +89 -89
  23. package/src/plugin-sdk/index.ts +103 -103
  24. package/src/plugin-sdk/lock.ts +124 -124
  25. package/src/plugin-sdk/manifest.ts +307 -307
  26. package/src/plugin-sdk/realtime.ts +277 -277
  27. package/src/plugin-sdk/registry.ts +105 -105
  28. package/src/plugin-sdk/runtime-shim.ts +140 -140
  29. package/src/plugin-sdk/types.ts +315 -315
  30. package/src/plugin-sdk/version.ts +209 -209
  31. package/src/registry/__tests__/registry.test.ts +135 -135
  32. package/src/registry/index.ts +94 -94
  33. package/src/registry/styles.registry.ts +295 -295
  34. package/src/testing/__tests__/testing-kit.test.ts +228 -228
  35. package/src/testing/index.ts +483 -483
  36. package/src/theme/index.ts +6 -6
  37. package/src/theme/tailwind.ts +73 -73
  38. package/src/theme/tokens.ts +177 -177
  39. package/src/types/api/envelope.ts +34 -34
  40. package/src/types/api/forms.ts +76 -76
  41. package/src/types/api/index.ts +9 -9
  42. package/src/types/api/language.ts +12 -12
  43. package/src/types/api/page.ts +9 -9
  44. package/src/types/index.ts +17 -17
  45. package/src/types/mantine/common.ts +142 -142
  46. package/src/types/pages.ts +107 -107
  47. package/src/types/styles/auth.ts +184 -184
  48. package/src/types/styles/base.ts +72 -72
  49. package/src/types/styles/composite.ts +131 -131
  50. package/src/types/styles/forms.ts +439 -439
  51. package/src/types/styles/interactive.ts +165 -165
  52. package/src/types/styles/layout.ts +184 -184
  53. package/src/types/styles/media.ts +68 -68
  54. package/src/types/styles/typography.ts +118 -118
  55. package/src/types/styles/unknown.ts +220 -220
  56. package/src/utils/__tests__/transformPageData.test.ts +69 -69
  57. package/src/utils/spacing.ts +64 -64
  58. package/src/utils/transformPageData.ts +99 -99
@@ -1,315 +1,315 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- /**
6
- * Runtime types used by `definePlugin()` / `defineMobilePlugin()` calls.
7
- *
8
- * Plugins are loaded by `PluginRuntime` at boot. The runtime imports the
9
- * plugin's npm package, calls its exported `register()` function and
10
- * passes it an `IPluginApi` instance. The plugin returns an
11
- * `IPluginRegistration` describing what it contributes (styles, admin
12
- * pages, menu items, health checks, etc.).
13
- *
14
- * Frontend (`react`) and mobile (`react-native`) plugins share most of
15
- * the surface; mobile-only types are suffixed with `Mobile`.
16
- */
17
-
18
- import type { IStyleRegistryEntry } from '../registry/styles.registry';
19
-
20
- /**
21
- * Generic component renderer. We avoid pulling in React types here to
22
- * keep the SDK framework-agnostic; the runtime casts to the appropriate
23
- * component type at registration time.
24
- */
25
- export type TPluginComponent<TProps = unknown> = (props: TProps) => unknown;
26
-
27
- /**
28
- * Definition of a CMS style contributed by a plugin.
29
- */
30
- export interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'> {
31
- /** Style name (becomes the `style_name` discriminator). */
32
- name: string;
33
- /**
34
- * Category. Plugins should usually pick `'plugin'`, but may opt into
35
- * an existing category (e.g. `'forms'`) when the style is a
36
- * drop-in replacement.
37
- */
38
- category: IStyleRegistryEntry['category'];
39
- /** Style implementation component (React or React Native). */
40
- component: TPluginComponent;
41
- }
42
-
43
- /**
44
- * Props passed by the host's section-field editor to a plugin-supplied
45
- * field renderer. The host owns the surrounding label / help tooltip /
46
- * type badge; the plugin only owns the actual input control.
47
- *
48
- * `field` is intentionally typed as a loose record because the host's
49
- * `IFieldData` lives in the frontend repo and must not leak into the
50
- * shared SDK contract — plugins read only what they need (id, name,
51
- * config, default_value, etc.).
52
- */
53
- export interface IPluginFieldRendererProps {
54
- /** Field id (database row id). */
55
- fieldId: number;
56
- /** Field name (DB `fields.name`). */
57
- fieldName: string;
58
- /** Field type (`fields.type`, e.g. `select-survey-js`). */
59
- fieldType: string;
60
- /** Current string value bound to the section_field translation. */
61
- value: string;
62
- /** Persist a new string value on the section_field translation. */
63
- onChange: (value: string) => void;
64
- /** Whether the input is disabled by the host. */
65
- disabled?: boolean;
66
- /** Loose pass-through of the host field row (config, default, help, ...). */
67
- field?: Record<string, unknown>;
68
- }
69
-
70
- /**
71
- * Field renderer contributed by a plugin. Replaces the host default
72
- * editor control for the given `fieldType`. Used by the CMS
73
- * section-field editor in the frontend repo so plugins can ship custom
74
- * pickers (e.g. SurveyJS survey select) without the host having to
75
- * hardcode plugin-specific UI in `FieldRenderer.tsx`.
76
- *
77
- * The component receives {@link IPluginFieldRendererProps}.
78
- */
79
- export interface IFieldRendererDefinition {
80
- /** Field type discriminator (`fields.type`, e.g. `select-survey-js`). */
81
- fieldType: string;
82
- /** React component that renders the input control. */
83
- component: TPluginComponent<IPluginFieldRendererProps>;
84
- }
85
-
86
- /**
87
- * Admin page contributed by a plugin. Mounted under
88
- * `/admin/plugins-host/{pluginId}/{slug}` in the frontend.
89
- */
90
- export interface IAdminPageDefinition {
91
- /** URL slug relative to the host shell. */
92
- slug: string;
93
- /** Display title in tabs / breadcrumbs. */
94
- title: string;
95
- /** Required permission key. */
96
- permission?: string;
97
- /** Page component (React). */
98
- component: TPluginComponent;
99
- /** Optional preloader hook called during SSR/prefetch. */
100
- prefetch?: () => Promise<void>;
101
- }
102
-
103
- /**
104
- * Menu item contributed by a plugin.
105
- */
106
- export interface IMenuItemDefinition {
107
- /** Stable key. */
108
- key: string;
109
- /** Display label. */
110
- label: string;
111
- /** Optional Tabler icon name. */
112
- icon?: string;
113
- /** Target href; defaults to the admin page slug. */
114
- href?: string;
115
- /** Required permission key. */
116
- permission?: string;
117
- /** Position relative to existing host menus. */
118
- position?: { section: 'admin' | 'cms' | 'tools'; order: number };
119
- }
120
-
121
- /**
122
- * Health-check declaration. Invoked through the doctor command and the
123
- * Plugin detail page's Health tab.
124
- */
125
- export interface IPluginHealthCheck {
126
- /** Stable key (e.g. `surveyjs.license`). */
127
- key: string;
128
- /** Display label. */
129
- label: string;
130
- /** Optional severity threshold. */
131
- severity?: 'info' | 'warning' | 'error';
132
- /** Runs the check; returns ok/warn/error + detail. */
133
- run: () => Promise<{ status: 'ok' | 'warn' | 'error'; detail?: string }>;
134
- }
135
-
136
- /**
137
- * Feature-flag declaration. The host installer seeds the flag based on
138
- * `defaultEnabled`; admins toggle through the Plugin detail page.
139
- */
140
- export interface IPluginFeatureFlag {
141
- key: string;
142
- label: string;
143
- description?: string;
144
- defaultEnabled: boolean;
145
- }
146
-
147
- /**
148
- * Realtime topic declared by the plugin. Wraps Mercure topics under the
149
- * scoped path `selfhelp/plugin/{pluginId}/{topicKey}`. Plugins never
150
- * talk to Mercure directly.
151
- */
152
- export interface IPluginRealtimeTopic<TPayload = unknown> {
153
- /** Topic key, unique within the plugin. */
154
- key: string;
155
- /** Optional permission required to subscribe. */
156
- requiredPermission?: string;
157
- /**
158
- * Optional payload validator. Receives the SSE event data and must
159
- * either return the typed payload or throw. The SDK runs this on
160
- * the receiving side; the publisher runs the same validator before
161
- * publishing.
162
- */
163
- validate?: (raw: unknown) => TPayload;
164
- }
165
-
166
- /**
167
- * Realtime publisher exposed to plugin server-side code (mostly inside
168
- * the plugin's Symfony bundle). Plugins must never instantiate Mercure
169
- * clients directly.
170
- */
171
- export interface IPluginRealtimePublisher {
172
- /** Publish a payload to a topic registered by the plugin. */
173
- publish<TPayload>(topicKey: string, payload: TPayload, options?: {
174
- /** Audience scope. Defaults to `permission`. */
175
- audience?: 'permission' | 'broadcast' | 'admins';
176
- /** Per-publish topic parameters (e.g. survey id). */
177
- topicParams?: Record<string, string | number>;
178
- }): Promise<void>;
179
- }
180
-
181
- /**
182
- * Rich text editor adapter. Both the SurveyJS plugin's `rich-text`
183
- * question type and the CMS core's `rich-text-editor` style consume
184
- * this adapter so a single Tiptap-based editor backs both.
185
- *
186
- * Plugins must provide a sanitization step on the backend; this
187
- * adapter only owns the editor UI.
188
- */
189
- export interface IRichTextEditorAdapterOptions {
190
- /** Optional editor mode hint. */
191
- mode?: 'inline' | 'block';
192
- /**
193
- * Allowed format for the stored value:
194
- * - `markdown` — string of Markdown.
195
- * - `sanitized-html` — HTML string passed through DOMPurify on the
196
- * backend.
197
- * - `prosemirror-json` — JSON shape produced by Tiptap.
198
- */
199
- format: 'markdown' | 'sanitized-html' | 'prosemirror-json';
200
- /** Optional toolbar restriction. */
201
- toolbar?: ('bold' | 'italic' | 'underline' | 'strike' | 'code' | 'link' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'image')[];
202
- /** Whether to allow image upload. */
203
- allowImages?: boolean;
204
- /** Whether to allow links. */
205
- allowLinks?: boolean;
206
- /** Custom placeholder text. */
207
- placeholder?: string;
208
- }
209
-
210
- export interface IRichTextEditorValue {
211
- /** Versioned format token, matches the adapter `format`. */
212
- format: 'markdown' | 'sanitized-html' | 'prosemirror-json';
213
- /** Stringified content (Markdown / HTML) or stringified JSON. */
214
- content: string;
215
- }
216
-
217
- /**
218
- * The host-side editor adapter passed to plugins through `IPluginApi`.
219
- */
220
- export interface IRichTextEditorAdapter {
221
- /**
222
- * Mount the editor at the given DOM node (web) or component node
223
- * (mobile) with the initial value. The returned object exposes a
224
- * setter and a destroyer.
225
- */
226
- mount(target: unknown, options: IRichTextEditorAdapterOptions & {
227
- initialValue?: IRichTextEditorValue;
228
- onChange?: (value: IRichTextEditorValue) => void;
229
- }): {
230
- setValue(value: IRichTextEditorValue): void;
231
- destroy(): void;
232
- };
233
- }
234
-
235
- /**
236
- * Host API passed to plugins at registration time.
237
- */
238
- export interface IPluginApi {
239
- /** Plugin id (provided by the host so the plugin does not duplicate it). */
240
- pluginId: string;
241
- /** Plugin version, mirrored from the manifest. */
242
- pluginVersion: string;
243
- /** Live feature-flag accessor. */
244
- isFeatureEnabled(flagKey: string): boolean;
245
- /** Host realtime publisher (only available on the backend side). */
246
- realtime?: IPluginRealtimePublisher;
247
- /** Host rich-text editor adapter. */
248
- richTextEditor: IRichTextEditorAdapter;
249
- /**
250
- * Logger that respects the host's debug config. Avoid `console.log`
251
- * in plugin code; route everything through this.
252
- */
253
- log: {
254
- debug(message: string, context?: Record<string, unknown>): void;
255
- info(message: string, context?: Record<string, unknown>): void;
256
- warn(message: string, context?: Record<string, unknown>): void;
257
- error(message: string, context?: Record<string, unknown>): void;
258
- };
259
- }
260
-
261
- /**
262
- * Same shape on mobile, minus the rich-text editor adapter when the
263
- * plugin only supports read-only mobile rendering.
264
- */
265
- export interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor'> {
266
- /** Mobile builds without rich-text support set this to `null`. */
267
- richTextEditor: IRichTextEditorAdapter | null;
268
- }
269
-
270
- /**
271
- * Returned by `definePlugin()` for the frontend / admin side of a
272
- * plugin.
273
- */
274
- export interface IPluginRegistration {
275
- /** Plugin id, must match the manifest. */
276
- id: string;
277
- /** Plugin version, must match the manifest. */
278
- version: string;
279
- /** SDK contract version the plugin targets. */
280
- pluginApiVersion: string;
281
- /** CMS styles the plugin contributes. */
282
- styles?: IStyleDefinition[];
283
- /** Admin pages the plugin contributes. */
284
- adminPages?: IAdminPageDefinition[];
285
- /** Menu items the plugin contributes. */
286
- menuItems?: IMenuItemDefinition[];
287
- /** Health checks the plugin exposes to the host. */
288
- healthChecks?: IPluginHealthCheck[];
289
- /** Feature flags the plugin declares. */
290
- featureFlags?: IPluginFeatureFlag[];
291
- /** Realtime topics the plugin publishes / subscribes to. */
292
- realtimeTopics?: IPluginRealtimeTopic[];
293
- /**
294
- * CMS section-field editor renderers contributed by the plugin.
295
- * Allows plugins to ship custom pickers for plugin-owned field types
296
- * (declared in the plugin's Doctrine migration as new rows in
297
- * `field_types`) without the host having to hardcode the renderer.
298
- */
299
- fieldRenderers?: IFieldRendererDefinition[];
300
- }
301
-
302
- /**
303
- * Returned by `defineMobilePlugin()` for the mobile side of a plugin.
304
- */
305
- export interface IMobilePluginRegistration {
306
- id: string;
307
- version: string;
308
- pluginApiVersion: string;
309
- /** Mobile-only style implementations. */
310
- styles?: IStyleDefinition[];
311
- /** Mobile-only realtime topics. */
312
- realtimeTopics?: IPluginRealtimeTopic[];
313
- /** Mobile feature flags (mirror of the manifest flags). */
314
- featureFlags?: IPluginFeatureFlag[];
315
- }
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Runtime types used by `definePlugin()` / `defineMobilePlugin()` calls.
7
+ *
8
+ * Plugins are loaded by `PluginRuntime` at boot. The runtime imports the
9
+ * plugin's npm package, calls its exported `register()` function and
10
+ * passes it an `IPluginApi` instance. The plugin returns an
11
+ * `IPluginRegistration` describing what it contributes (styles, admin
12
+ * pages, menu items, health checks, etc.).
13
+ *
14
+ * Frontend (`react`) and mobile (`react-native`) plugins share most of
15
+ * the surface; mobile-only types are suffixed with `Mobile`.
16
+ */
17
+
18
+ import type { IStyleRegistryEntry } from '../registry/styles.registry';
19
+
20
+ /**
21
+ * Generic component renderer. We avoid pulling in React types here to
22
+ * keep the SDK framework-agnostic; the runtime casts to the appropriate
23
+ * component type at registration time.
24
+ */
25
+ export type TPluginComponent<TProps = unknown> = (props: TProps) => unknown;
26
+
27
+ /**
28
+ * Definition of a CMS style contributed by a plugin.
29
+ */
30
+ export interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'> {
31
+ /** Style name (becomes the `style_name` discriminator). */
32
+ name: string;
33
+ /**
34
+ * Category. Plugins should usually pick `'plugin'`, but may opt into
35
+ * an existing category (e.g. `'forms'`) when the style is a
36
+ * drop-in replacement.
37
+ */
38
+ category: IStyleRegistryEntry['category'];
39
+ /** Style implementation component (React or React Native). */
40
+ component: TPluginComponent;
41
+ }
42
+
43
+ /**
44
+ * Props passed by the host's section-field editor to a plugin-supplied
45
+ * field renderer. The host owns the surrounding label / help tooltip /
46
+ * type badge; the plugin only owns the actual input control.
47
+ *
48
+ * `field` is intentionally typed as a loose record because the host's
49
+ * `IFieldData` lives in the frontend repo and must not leak into the
50
+ * shared SDK contract — plugins read only what they need (id, name,
51
+ * config, default_value, etc.).
52
+ */
53
+ export interface IPluginFieldRendererProps {
54
+ /** Field id (database row id). */
55
+ fieldId: number;
56
+ /** Field name (DB `fields.name`). */
57
+ fieldName: string;
58
+ /** Field type (`fields.type`, e.g. `select-survey-js`). */
59
+ fieldType: string;
60
+ /** Current string value bound to the section_field translation. */
61
+ value: string;
62
+ /** Persist a new string value on the section_field translation. */
63
+ onChange: (value: string) => void;
64
+ /** Whether the input is disabled by the host. */
65
+ disabled?: boolean;
66
+ /** Loose pass-through of the host field row (config, default, help, ...). */
67
+ field?: Record<string, unknown>;
68
+ }
69
+
70
+ /**
71
+ * Field renderer contributed by a plugin. Replaces the host default
72
+ * editor control for the given `fieldType`. Used by the CMS
73
+ * section-field editor in the frontend repo so plugins can ship custom
74
+ * pickers (e.g. SurveyJS survey select) without the host having to
75
+ * hardcode plugin-specific UI in `FieldRenderer.tsx`.
76
+ *
77
+ * The component receives {@link IPluginFieldRendererProps}.
78
+ */
79
+ export interface IFieldRendererDefinition {
80
+ /** Field type discriminator (`fields.type`, e.g. `select-survey-js`). */
81
+ fieldType: string;
82
+ /** React component that renders the input control. */
83
+ component: TPluginComponent<IPluginFieldRendererProps>;
84
+ }
85
+
86
+ /**
87
+ * Admin page contributed by a plugin. Mounted under
88
+ * `/admin/plugins-host/{pluginId}/{slug}` in the frontend.
89
+ */
90
+ export interface IAdminPageDefinition {
91
+ /** URL slug relative to the host shell. */
92
+ slug: string;
93
+ /** Display title in tabs / breadcrumbs. */
94
+ title: string;
95
+ /** Required permission key. */
96
+ permission?: string;
97
+ /** Page component (React). */
98
+ component: TPluginComponent;
99
+ /** Optional preloader hook called during SSR/prefetch. */
100
+ prefetch?: () => Promise<void>;
101
+ }
102
+
103
+ /**
104
+ * Menu item contributed by a plugin.
105
+ */
106
+ export interface IMenuItemDefinition {
107
+ /** Stable key. */
108
+ key: string;
109
+ /** Display label. */
110
+ label: string;
111
+ /** Optional Tabler icon name. */
112
+ icon?: string;
113
+ /** Target href; defaults to the admin page slug. */
114
+ href?: string;
115
+ /** Required permission key. */
116
+ permission?: string;
117
+ /** Position relative to existing host menus. */
118
+ position?: { section: 'admin' | 'cms' | 'tools'; order: number };
119
+ }
120
+
121
+ /**
122
+ * Health-check declaration. Invoked through the doctor command and the
123
+ * Plugin detail page's Health tab.
124
+ */
125
+ export interface IPluginHealthCheck {
126
+ /** Stable key (e.g. `surveyjs.license`). */
127
+ key: string;
128
+ /** Display label. */
129
+ label: string;
130
+ /** Optional severity threshold. */
131
+ severity?: 'info' | 'warning' | 'error';
132
+ /** Runs the check; returns ok/warn/error + detail. */
133
+ run: () => Promise<{ status: 'ok' | 'warn' | 'error'; detail?: string }>;
134
+ }
135
+
136
+ /**
137
+ * Feature-flag declaration. The host installer seeds the flag based on
138
+ * `defaultEnabled`; admins toggle through the Plugin detail page.
139
+ */
140
+ export interface IPluginFeatureFlag {
141
+ key: string;
142
+ label: string;
143
+ description?: string;
144
+ defaultEnabled: boolean;
145
+ }
146
+
147
+ /**
148
+ * Realtime topic declared by the plugin. Wraps Mercure topics under the
149
+ * scoped path `selfhelp/plugin/{pluginId}/{topicKey}`. Plugins never
150
+ * talk to Mercure directly.
151
+ */
152
+ export interface IPluginRealtimeTopic<TPayload = unknown> {
153
+ /** Topic key, unique within the plugin. */
154
+ key: string;
155
+ /** Optional permission required to subscribe. */
156
+ requiredPermission?: string;
157
+ /**
158
+ * Optional payload validator. Receives the SSE event data and must
159
+ * either return the typed payload or throw. The SDK runs this on
160
+ * the receiving side; the publisher runs the same validator before
161
+ * publishing.
162
+ */
163
+ validate?: (raw: unknown) => TPayload;
164
+ }
165
+
166
+ /**
167
+ * Realtime publisher exposed to plugin server-side code (mostly inside
168
+ * the plugin's Symfony bundle). Plugins must never instantiate Mercure
169
+ * clients directly.
170
+ */
171
+ export interface IPluginRealtimePublisher {
172
+ /** Publish a payload to a topic registered by the plugin. */
173
+ publish<TPayload>(topicKey: string, payload: TPayload, options?: {
174
+ /** Audience scope. Defaults to `permission`. */
175
+ audience?: 'permission' | 'broadcast' | 'admins';
176
+ /** Per-publish topic parameters (e.g. survey id). */
177
+ topicParams?: Record<string, string | number>;
178
+ }): Promise<void>;
179
+ }
180
+
181
+ /**
182
+ * Rich text editor adapter. Both the SurveyJS plugin's `rich-text`
183
+ * question type and the CMS core's `rich-text-editor` style consume
184
+ * this adapter so a single Tiptap-based editor backs both.
185
+ *
186
+ * Plugins must provide a sanitization step on the backend; this
187
+ * adapter only owns the editor UI.
188
+ */
189
+ export interface IRichTextEditorAdapterOptions {
190
+ /** Optional editor mode hint. */
191
+ mode?: 'inline' | 'block';
192
+ /**
193
+ * Allowed format for the stored value:
194
+ * - `markdown` — string of Markdown.
195
+ * - `sanitized-html` — HTML string passed through DOMPurify on the
196
+ * backend.
197
+ * - `prosemirror-json` — JSON shape produced by Tiptap.
198
+ */
199
+ format: 'markdown' | 'sanitized-html' | 'prosemirror-json';
200
+ /** Optional toolbar restriction. */
201
+ toolbar?: ('bold' | 'italic' | 'underline' | 'strike' | 'code' | 'link' | 'heading' | 'bulletList' | 'orderedList' | 'blockquote' | 'image')[];
202
+ /** Whether to allow image upload. */
203
+ allowImages?: boolean;
204
+ /** Whether to allow links. */
205
+ allowLinks?: boolean;
206
+ /** Custom placeholder text. */
207
+ placeholder?: string;
208
+ }
209
+
210
+ export interface IRichTextEditorValue {
211
+ /** Versioned format token, matches the adapter `format`. */
212
+ format: 'markdown' | 'sanitized-html' | 'prosemirror-json';
213
+ /** Stringified content (Markdown / HTML) or stringified JSON. */
214
+ content: string;
215
+ }
216
+
217
+ /**
218
+ * The host-side editor adapter passed to plugins through `IPluginApi`.
219
+ */
220
+ export interface IRichTextEditorAdapter {
221
+ /**
222
+ * Mount the editor at the given DOM node (web) or component node
223
+ * (mobile) with the initial value. The returned object exposes a
224
+ * setter and a destroyer.
225
+ */
226
+ mount(target: unknown, options: IRichTextEditorAdapterOptions & {
227
+ initialValue?: IRichTextEditorValue;
228
+ onChange?: (value: IRichTextEditorValue) => void;
229
+ }): {
230
+ setValue(value: IRichTextEditorValue): void;
231
+ destroy(): void;
232
+ };
233
+ }
234
+
235
+ /**
236
+ * Host API passed to plugins at registration time.
237
+ */
238
+ export interface IPluginApi {
239
+ /** Plugin id (provided by the host so the plugin does not duplicate it). */
240
+ pluginId: string;
241
+ /** Plugin version, mirrored from the manifest. */
242
+ pluginVersion: string;
243
+ /** Live feature-flag accessor. */
244
+ isFeatureEnabled(flagKey: string): boolean;
245
+ /** Host realtime publisher (only available on the backend side). */
246
+ realtime?: IPluginRealtimePublisher;
247
+ /** Host rich-text editor adapter. */
248
+ richTextEditor: IRichTextEditorAdapter;
249
+ /**
250
+ * Logger that respects the host's debug config. Avoid `console.log`
251
+ * in plugin code; route everything through this.
252
+ */
253
+ log: {
254
+ debug(message: string, context?: Record<string, unknown>): void;
255
+ info(message: string, context?: Record<string, unknown>): void;
256
+ warn(message: string, context?: Record<string, unknown>): void;
257
+ error(message: string, context?: Record<string, unknown>): void;
258
+ };
259
+ }
260
+
261
+ /**
262
+ * Same shape on mobile, minus the rich-text editor adapter when the
263
+ * plugin only supports read-only mobile rendering.
264
+ */
265
+ export interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor'> {
266
+ /** Mobile builds without rich-text support set this to `null`. */
267
+ richTextEditor: IRichTextEditorAdapter | null;
268
+ }
269
+
270
+ /**
271
+ * Returned by `definePlugin()` for the frontend / admin side of a
272
+ * plugin.
273
+ */
274
+ export interface IPluginRegistration {
275
+ /** Plugin id, must match the manifest. */
276
+ id: string;
277
+ /** Plugin version, must match the manifest. */
278
+ version: string;
279
+ /** SDK contract version the plugin targets. */
280
+ pluginApiVersion: string;
281
+ /** CMS styles the plugin contributes. */
282
+ styles?: IStyleDefinition[];
283
+ /** Admin pages the plugin contributes. */
284
+ adminPages?: IAdminPageDefinition[];
285
+ /** Menu items the plugin contributes. */
286
+ menuItems?: IMenuItemDefinition[];
287
+ /** Health checks the plugin exposes to the host. */
288
+ healthChecks?: IPluginHealthCheck[];
289
+ /** Feature flags the plugin declares. */
290
+ featureFlags?: IPluginFeatureFlag[];
291
+ /** Realtime topics the plugin publishes / subscribes to. */
292
+ realtimeTopics?: IPluginRealtimeTopic[];
293
+ /**
294
+ * CMS section-field editor renderers contributed by the plugin.
295
+ * Allows plugins to ship custom pickers for plugin-owned field types
296
+ * (declared in the plugin's Doctrine migration as new rows in
297
+ * `field_types`) without the host having to hardcode the renderer.
298
+ */
299
+ fieldRenderers?: IFieldRendererDefinition[];
300
+ }
301
+
302
+ /**
303
+ * Returned by `defineMobilePlugin()` for the mobile side of a plugin.
304
+ */
305
+ export interface IMobilePluginRegistration {
306
+ id: string;
307
+ version: string;
308
+ pluginApiVersion: string;
309
+ /** Mobile-only style implementations. */
310
+ styles?: IStyleDefinition[];
311
+ /** Mobile-only realtime topics. */
312
+ realtimeTopics?: IPluginRealtimeTopic[];
313
+ /** Mobile feature flags (mirror of the manifest flags). */
314
+ featureFlags?: IPluginFeatureFlag[];
315
+ }