@selfhelp/shared 1.28.0 → 1.30.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.
@@ -127,6 +127,16 @@ interface IPluginManifestPermission {
127
127
  /** Optional default role keys the permission is granted to. */
128
128
  defaultRoles?: string[];
129
129
  }
130
+ /** A field linked to a plugin style, with its editor metadata. */
131
+ interface IPluginManifestStyleField {
132
+ /** A field of the plugin (`fields`) or a core field such as `own_entries_only`. */
133
+ name: string;
134
+ title?: string;
135
+ help?: string;
136
+ default?: string | null;
137
+ hidden?: boolean;
138
+ disabled?: boolean;
139
+ }
130
140
  interface IPluginManifestStyle {
131
141
  /** Style name (used as `style_name` discriminator). */
132
142
  name: string;
@@ -134,6 +144,34 @@ interface IPluginManifestStyle {
134
144
  canHaveChildren: boolean;
135
145
  /** Optional capability requirement (e.g. `frontendStyles`). */
136
146
  capability?: IPluginManifestCapability;
147
+ /** Style group name; required when the installer creates the style. */
148
+ group?: string;
149
+ /** Earlier names of this style; the installer renames the row in place. */
150
+ renamedFrom?: string[];
151
+ /** When present, the installer makes the style's field links match this list. */
152
+ fields?: IPluginManifestStyleField[];
153
+ }
154
+ /** Style group written into `style_groups` by the host installer (rule 7.8). */
155
+ interface IPluginManifestStyleGroup {
156
+ name: string;
157
+ description?: string;
158
+ position?: number;
159
+ }
160
+ /** Field type (editor control) written into `field_types`; kebab-case name. */
161
+ interface IPluginManifestFieldType {
162
+ name: string;
163
+ position?: number;
164
+ }
165
+ /** Plugin-owned field written into `fields`; snake_case name. */
166
+ interface IPluginManifestField {
167
+ name: string;
168
+ /** A core field type or one declared under `fieldTypes`. */
169
+ type: string;
170
+ /** True for participant-facing content stored per language. */
171
+ translatable?: boolean;
172
+ config?: Record<string, unknown> | null;
173
+ /** Earlier names of this field; the installer renames the row in place. */
174
+ renamedFrom?: string[];
137
175
  }
138
176
  interface IPluginManifestAdminPage {
139
177
  /** Slug under `/admin/plugins-host/{pluginId}/`. */
@@ -249,6 +287,12 @@ interface IPluginManifest {
249
287
  };
250
288
  /** Styles contributed to the registry. */
251
289
  styles?: IPluginManifestStyle[];
290
+ /** Style groups the host installer writes (rule 7.8). */
291
+ styleGroups?: IPluginManifestStyleGroup[];
292
+ /** Field types the host installer writes (rule 7.8). */
293
+ fieldTypes?: IPluginManifestFieldType[];
294
+ /** Plugin-owned fields the host installer writes (rule 7.8). */
295
+ fields?: IPluginManifestField[];
252
296
  /** Admin pages mounted under `/admin/plugins-host/{pluginId}/`. */
253
297
  adminPages?: IPluginManifestAdminPage[];
254
298
  /** Plugin-owned API routes. */
@@ -263,4 +307,4 @@ interface IPluginManifest {
263
307
  labels?: Record<string, string>;
264
308
  }
265
309
 
266
- export type { IPluginManifest as I, IPluginManifestAdminPage as a, IPluginManifestApiRoute as b, IPluginManifestAsset as c, IPluginManifestCapability as d, IPluginManifestCompatibility as e, IPluginManifestConflict as f, IPluginManifestDataAccess as g, IPluginManifestDependency as h, IPluginManifestExternalHost as i, IPluginManifestFeatureFlag as j, IPluginManifestHealth as k, IPluginManifestLookupExtension as l, IPluginManifestMobile as m, IPluginManifestPermission as n, IPluginManifestRealtimeTopic as o, IPluginManifestScheduledJob as p, IPluginManifestSecurity as q, IPluginManifestStyle as r, IPluginManifestTrustLevel as s };
310
+ export type { IPluginManifest as I, IPluginManifestAdminPage as a, IPluginManifestApiRoute as b, IPluginManifestAsset as c, IPluginManifestCapability as d, IPluginManifestCompatibility as e, IPluginManifestConflict as f, IPluginManifestDataAccess as g, IPluginManifestDependency as h, IPluginManifestExternalHost as i, IPluginManifestFeatureFlag as j, IPluginManifestField as k, IPluginManifestFieldType as l, IPluginManifestHealth as m, IPluginManifestLookupExtension as n, IPluginManifestMobile as o, IPluginManifestPermission as p, IPluginManifestRealtimeTopic as q, IPluginManifestScheduledJob as r, IPluginManifestSecurity as s, IPluginManifestStyle as t, IPluginManifestStyleField as u, IPluginManifestStyleGroup as v, IPluginManifestTrustLevel as w };
@@ -1,4 +1,4 @@
1
- export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestHealth, l as IPluginManifestLookupExtension, m as IPluginManifestMobile, n as IPluginManifestPermission, o as IPluginManifestRealtimeTopic, p as IPluginManifestScheduledJob, q as IPluginManifestSecurity, r as IPluginManifestStyle, s as IPluginManifestTrustLevel } from '../manifest-BNnCN1Qo.mjs';
1
+ export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestField, l as IPluginManifestFieldType, m as IPluginManifestHealth, n as IPluginManifestLookupExtension, o as IPluginManifestMobile, p as IPluginManifestPermission, q as IPluginManifestRealtimeTopic, r as IPluginManifestScheduledJob, s as IPluginManifestSecurity, t as IPluginManifestStyle, u as IPluginManifestStyleField, v as IPluginManifestStyleGroup, w as IPluginManifestTrustLevel } from '../manifest-DRlcSvvy.mjs';
2
2
  import { I as IStyleRegistryEntry } from '../styles.registry-DnIJqEzM.mjs';
3
3
  import '../common-qaDIAYS3.mjs';
4
4
 
@@ -404,6 +404,49 @@ interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'> {
404
404
  /** Style implementation component (React or React Native). */
405
405
  component: TPluginComponent;
406
406
  }
407
+ /**
408
+ * The popup a page is shown in, as the host sees it. Outside a popup
409
+ * `inModal` is false and `closeModal()` does nothing, so a plugin can call
410
+ * it unconditionally (for example after a save, like the core form's
411
+ * `close_modal_on_save`).
412
+ */
413
+ interface IPluginPageModal {
414
+ inModal: boolean;
415
+ closeModal: () => void;
416
+ }
417
+ /**
418
+ * The page a plugin section is drawn on. A plugin endpoint that serves or
419
+ * accepts data for the section names the page and the section in every call
420
+ * (with this language, preview state and route), so the server can check
421
+ * access and read the section's settings itself (rule 7.7), like the core
422
+ * form and form list do.
423
+ */
424
+ interface IPluginStylePage {
425
+ /** Page id; null while the page content is not known yet. */
426
+ id: number | null;
427
+ languageId: number | null;
428
+ /** Whether the page is shown as the editor's draft (preview mode). */
429
+ preview: boolean;
430
+ /** The page's declared route parameters (`page.route_params`). */
431
+ routeParams: Record<string, string>;
432
+ }
433
+ /**
434
+ * Props the host passes to a plugin style component (the `component` of an
435
+ * {@link IStyleDefinition}). `style` is the section as the page payload
436
+ * carries it (fields keyed by name).
437
+ */
438
+ interface IPluginStyleProps {
439
+ style: Record<string, unknown>;
440
+ styleProps: Record<string, string>;
441
+ cssClass: string;
442
+ parentActive?: number;
443
+ childIndex?: number;
444
+ parentColor?: string;
445
+ /** The popup the page is shown in; a no-op outside one. */
446
+ pageModal: IPluginPageModal;
447
+ /** The page the section is on, to name in plugin calls. */
448
+ page: IPluginStylePage;
449
+ }
407
450
  /**
408
451
  * Props passed by the host's section-field editor to a plugin-supplied
409
452
  * field renderer. The host owns the surrounding label / help tooltip /
@@ -605,6 +648,13 @@ interface IPluginApi {
605
648
  realtime?: IPluginRealtimePublisher;
606
649
  /** Host rich-text editor adapter. */
607
650
  richTextEditor: IRichTextEditorAdapter;
651
+ /**
652
+ * The host's HTML sanitizer, with the same rules core pages use (web:
653
+ * DOMPurify, plus the host's link rewrites). Call it before rendering any
654
+ * CMS or user HTML; never bundle a sanitizer of your own. `inline` keeps
655
+ * inline markup only, `block` also keeps headings, lists and paragraphs.
656
+ */
657
+ sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
608
658
  /**
609
659
  * Logger that respects the host's debug config. Avoid `console.log`
610
660
  * in plugin code; route everything through this.
@@ -618,9 +668,12 @@ interface IPluginApi {
618
668
  }
619
669
  /**
620
670
  * Same shape on mobile, minus the rich-text editor adapter when the
621
- * plugin only supports read-only mobile rendering.
671
+ * plugin only supports read-only mobile rendering. React Native does not
672
+ * render HTML, so there is no `sanitizeHtml`: mobile plugins show CMS text
673
+ * with `parseInlineRich` / `stripHtmlToText`. A plugin that renders HTML in
674
+ * a WebView sanitizes it there itself.
622
675
  */
623
- interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor'> {
676
+ interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml'> {
624
677
  /** Mobile builds without rich-text support set this to `null`. */
625
678
  richTextEditor: IRichTextEditorAdapter | null;
626
679
  }
@@ -1006,4 +1059,4 @@ declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginR
1006
1059
  */
1007
1060
  declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
1008
1061
 
1009
- export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
1062
+ export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginStylePage, type IPluginStyleProps, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
@@ -1,4 +1,4 @@
1
- export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestHealth, l as IPluginManifestLookupExtension, m as IPluginManifestMobile, n as IPluginManifestPermission, o as IPluginManifestRealtimeTopic, p as IPluginManifestScheduledJob, q as IPluginManifestSecurity, r as IPluginManifestStyle, s as IPluginManifestTrustLevel } from '../manifest-BNnCN1Qo.js';
1
+ export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestField, l as IPluginManifestFieldType, m as IPluginManifestHealth, n as IPluginManifestLookupExtension, o as IPluginManifestMobile, p as IPluginManifestPermission, q as IPluginManifestRealtimeTopic, r as IPluginManifestScheduledJob, s as IPluginManifestSecurity, t as IPluginManifestStyle, u as IPluginManifestStyleField, v as IPluginManifestStyleGroup, w as IPluginManifestTrustLevel } from '../manifest-DRlcSvvy.js';
2
2
  import { I as IStyleRegistryEntry } from '../styles.registry-C2ACy7H0.js';
3
3
  import '../common-qaDIAYS3.js';
4
4
 
@@ -404,6 +404,49 @@ interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'> {
404
404
  /** Style implementation component (React or React Native). */
405
405
  component: TPluginComponent;
406
406
  }
407
+ /**
408
+ * The popup a page is shown in, as the host sees it. Outside a popup
409
+ * `inModal` is false and `closeModal()` does nothing, so a plugin can call
410
+ * it unconditionally (for example after a save, like the core form's
411
+ * `close_modal_on_save`).
412
+ */
413
+ interface IPluginPageModal {
414
+ inModal: boolean;
415
+ closeModal: () => void;
416
+ }
417
+ /**
418
+ * The page a plugin section is drawn on. A plugin endpoint that serves or
419
+ * accepts data for the section names the page and the section in every call
420
+ * (with this language, preview state and route), so the server can check
421
+ * access and read the section's settings itself (rule 7.7), like the core
422
+ * form and form list do.
423
+ */
424
+ interface IPluginStylePage {
425
+ /** Page id; null while the page content is not known yet. */
426
+ id: number | null;
427
+ languageId: number | null;
428
+ /** Whether the page is shown as the editor's draft (preview mode). */
429
+ preview: boolean;
430
+ /** The page's declared route parameters (`page.route_params`). */
431
+ routeParams: Record<string, string>;
432
+ }
433
+ /**
434
+ * Props the host passes to a plugin style component (the `component` of an
435
+ * {@link IStyleDefinition}). `style` is the section as the page payload
436
+ * carries it (fields keyed by name).
437
+ */
438
+ interface IPluginStyleProps {
439
+ style: Record<string, unknown>;
440
+ styleProps: Record<string, string>;
441
+ cssClass: string;
442
+ parentActive?: number;
443
+ childIndex?: number;
444
+ parentColor?: string;
445
+ /** The popup the page is shown in; a no-op outside one. */
446
+ pageModal: IPluginPageModal;
447
+ /** The page the section is on, to name in plugin calls. */
448
+ page: IPluginStylePage;
449
+ }
407
450
  /**
408
451
  * Props passed by the host's section-field editor to a plugin-supplied
409
452
  * field renderer. The host owns the surrounding label / help tooltip /
@@ -605,6 +648,13 @@ interface IPluginApi {
605
648
  realtime?: IPluginRealtimePublisher;
606
649
  /** Host rich-text editor adapter. */
607
650
  richTextEditor: IRichTextEditorAdapter;
651
+ /**
652
+ * The host's HTML sanitizer, with the same rules core pages use (web:
653
+ * DOMPurify, plus the host's link rewrites). Call it before rendering any
654
+ * CMS or user HTML; never bundle a sanitizer of your own. `inline` keeps
655
+ * inline markup only, `block` also keeps headings, lists and paragraphs.
656
+ */
657
+ sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
608
658
  /**
609
659
  * Logger that respects the host's debug config. Avoid `console.log`
610
660
  * in plugin code; route everything through this.
@@ -618,9 +668,12 @@ interface IPluginApi {
618
668
  }
619
669
  /**
620
670
  * Same shape on mobile, minus the rich-text editor adapter when the
621
- * plugin only supports read-only mobile rendering.
671
+ * plugin only supports read-only mobile rendering. React Native does not
672
+ * render HTML, so there is no `sanitizeHtml`: mobile plugins show CMS text
673
+ * with `parseInlineRich` / `stripHtmlToText`. A plugin that renders HTML in
674
+ * a WebView sanitizes it there itself.
622
675
  */
623
- interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor'> {
676
+ interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml'> {
624
677
  /** Mobile builds without rich-text support set this to `null`. */
625
678
  richTextEditor: IRichTextEditorAdapter | null;
626
679
  }
@@ -1006,4 +1059,4 @@ declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginR
1006
1059
  */
1007
1060
  declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
1008
1061
 
1009
- export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
1062
+ export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginStylePage, type IPluginStyleProps, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
@@ -1,4 +1,4 @@
1
- import { I as IPluginManifest } from '../manifest-BNnCN1Qo.mjs';
1
+ import { I as IPluginManifest } from '../manifest-DRlcSvvy.mjs';
2
2
 
3
3
  /**
4
4
  * `@selfhelp/shared/testing` — the plugin certification kit.
@@ -1,4 +1,4 @@
1
- import { I as IPluginManifest } from '../manifest-BNnCN1Qo.js';
1
+ import { I as IPluginManifest } from '../manifest-DRlcSvvy.js';
2
2
 
3
3
  /**
4
4
  * `@selfhelp/shared/testing` — the plugin certification kit.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfhelp/shared",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,26 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { describe, expect, it } from 'vitest';
7
+ import {
8
+ LANGUAGE_INDEPENDENT_ID,
9
+ LANGUAGE_INDEPENDENT_LOCALE,
10
+ isLanguageIndependent,
11
+ } from '../languageIndependent';
12
+
13
+ describe('isLanguageIndependent', () => {
14
+ it('is true only for the sentinel id 1', () => {
15
+ expect(LANGUAGE_INDEPENDENT_ID).toBe(1);
16
+ expect(LANGUAGE_INDEPENDENT_LOCALE).toBe('all');
17
+ expect(isLanguageIndependent(1)).toBe(true);
18
+ expect(isLanguageIndependent(LANGUAGE_INDEPENDENT_ID)).toBe(true);
19
+ });
20
+
21
+ it('is false for a real language, null and undefined', () => {
22
+ expect(isLanguageIndependent(2)).toBe(false);
23
+ expect(isLanguageIndependent(null)).toBe(false);
24
+ expect(isLanguageIndependent(undefined)).toBe(false);
25
+ });
26
+ });
@@ -0,0 +1,62 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
7
+ import { join, relative, sep } from 'node:path';
8
+ import { describe, expect, it } from 'vitest';
9
+
10
+ /**
11
+ * Fails when source under `src/` still compares against bare language id 1 or
12
+ * locale `all`. The constant module itself and every `__tests__` folder are
13
+ * excluded; clients must import `LANGUAGE_INDEPENDENT_*` / `isLanguageIndependent`.
14
+ */
15
+ const SRC_ROOT = join(__dirname, '..', '..');
16
+ const OWN_MODULE = join('content', 'languageIndependent.ts');
17
+
18
+ const FORBIDDEN = [
19
+ /language_id\s*===\s*1\b/,
20
+ /language_id\s*!==\s*1\b/,
21
+ /languageId\s*===\s*1\b/,
22
+ /language_id\s*>\s*1\b/,
23
+ /locale\s*===\s*['"]all['"]/,
24
+ ] as const;
25
+
26
+ function listSourceFiles(dir: string): string[] {
27
+ const out: string[] = [];
28
+ for (const name of readdirSync(dir)) {
29
+ const full = join(dir, name);
30
+ const st = statSync(full);
31
+ if (st.isDirectory()) {
32
+ if (name === '__tests__' || name === 'node_modules' || name === 'dist') {
33
+ continue;
34
+ }
35
+ out.push(...listSourceFiles(full));
36
+ continue;
37
+ }
38
+ if (/\.(ts|tsx|js|mjs|cjs)$/.test(name) && !name.endsWith('.d.ts')) {
39
+ out.push(full);
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+
45
+ describe('language-independent literals in src/', () => {
46
+ it('uses LANGUAGE_INDEPENDENT_* / isLanguageIndependent instead of bare 1 or locale all', () => {
47
+ const hits: string[] = [];
48
+ for (const file of listSourceFiles(SRC_ROOT)) {
49
+ const rel = relative(SRC_ROOT, file).split(sep).join('/');
50
+ if (rel === OWN_MODULE.replace(/\\/g, '/')) {
51
+ continue;
52
+ }
53
+ const text = readFileSync(file, 'utf8');
54
+ for (const pattern of FORBIDDEN) {
55
+ if (pattern.test(text)) {
56
+ hits.push(`${rel} matches ${pattern}`);
57
+ }
58
+ }
59
+ }
60
+ expect(hits).toEqual([]);
61
+ });
62
+ });
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import type { IFormListFilesCell, IFormListFileValue } from '../types/api/form-lists';
15
+ import { isLanguageIndependent } from './languageIndependent';
15
16
 
16
17
  /** Per-language value for a translatable form field. */
17
18
  export interface IFormRecordPrefillTranslatedValue {
@@ -142,9 +143,10 @@ export function asFilesCell(value: unknown): TFormRecordPrefillFileValue | null
142
143
  *
143
144
  * - Missing / empty / non-array `section_data` → empty create state.
144
145
  * - Rows without a numeric `record_id` are ignored.
145
- * - Translatable fields accumulate `{ language_id, value }[]` (language id `1`
146
- * is an Independent seed kept only until a public-language row arrives).
147
- * - Non-translatable fields prefer language id `1`, else the first seen value.
146
+ * - Translatable fields accumulate `{ language_id, value }[]` (the
147
+ * language-independent seed is kept only until a public-language row arrives).
148
+ * - Non-translatable fields prefer the language-independent row, else the first
149
+ * seen value.
148
150
  */
149
151
  export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFormRecordPrefill {
150
152
  const sectionDataArray = section?.section_data;
@@ -194,7 +196,7 @@ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFor
194
196
  }
195
197
  const filesCell = asFilesCell(fieldValue);
196
198
  if (filesCell !== null) {
197
- if (languageId === 1 || !recordGroups[recordId][fieldName]) {
199
+ if (isLanguageIndependent(languageId) || !recordGroups[recordId][fieldName]) {
198
200
  recordGroups[recordId][fieldName] = filesCell;
199
201
  }
200
202
  continue;
@@ -207,7 +209,7 @@ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFor
207
209
  const translatable = isTranslatableChild(section.children, fieldName);
208
210
 
209
211
  if (translatable) {
210
- if (languageId === 1) {
212
+ if (isLanguageIndependent(languageId)) {
211
213
  if (!recordGroups[recordId][fieldName]) {
212
214
  recordGroups[recordId][fieldName] = value;
213
215
  }
@@ -229,7 +231,7 @@ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFor
229
231
  }
230
232
  }
231
233
  }
232
- } else if (languageId === 1 || !recordGroups[recordId][fieldName]) {
234
+ } else if (isLanguageIndependent(languageId) || !recordGroups[recordId][fieldName]) {
233
235
  recordGroups[recordId][fieldName] = value;
234
236
  }
235
237
  }
@@ -287,7 +289,7 @@ export function flattenFormRecordPrefillValues(
287
289
  continue;
288
290
  }
289
291
  }
290
- const nonIndependent = value.find((entry) => entry.language_id !== 1);
292
+ const nonIndependent = value.find((entry) => !isLanguageIndependent(entry.language_id));
291
293
  out[key] = (nonIndependent ?? value[0]).value;
292
294
  }
293
295
  return out;
@@ -5,5 +5,6 @@ SPDX-License-Identifier: MPL-2.0
5
5
  export * from './inlineFormat';
6
6
  export * from './optionLabels';
7
7
  export * from './fieldsMapLabels';
8
+ export * from './languageIndependent';
8
9
  export * from './formRecordPrefill';
9
10
  export * from './formListState';
@@ -0,0 +1,28 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ /**
7
+ * Language-independent sentinel (backend `languages` row id 1, locale `all`).
8
+ *
9
+ * That row holds values that are the same in every language: page and section
10
+ * properties, plain-text form cells, and the `all` entries of bundles. It is
11
+ * not a real language and must not be chosen as a user's language or the CMS
12
+ * default. Clients refer to it only through these constants — never a bare `1`.
13
+ *
14
+ * Mirrors backend `App\Entity\Language::INDEPENDENT_ID` / `INDEPENDENT_LOCALE`.
15
+ */
16
+
17
+ /** Fixed id of the language-independent sentinel row. */
18
+ export const LANGUAGE_INDEPENDENT_ID = 1;
19
+
20
+ /** Locale token of the language-independent sentinel row (`all` in bundles). */
21
+ export const LANGUAGE_INDEPENDENT_LOCALE = 'all';
22
+
23
+ /** True when `languageId` is the language-independent sentinel. */
24
+ export function isLanguageIndependent(
25
+ languageId: number | null | undefined,
26
+ ): boolean {
27
+ return languageId === LANGUAGE_INDEPENDENT_ID;
28
+ }
@@ -41,6 +41,10 @@ export type {
41
41
  IPluginManifestLookupExtension,
42
42
  IPluginManifestPermission,
43
43
  IPluginManifestStyle,
44
+ IPluginManifestStyleField,
45
+ IPluginManifestStyleGroup,
46
+ IPluginManifestFieldType,
47
+ IPluginManifestField,
44
48
  IPluginManifestAdminPage,
45
49
  IPluginManifestApiRoute,
46
50
  IPluginManifestScheduledJob,
@@ -73,6 +77,9 @@ export type {
73
77
  IStyleDefinition,
74
78
  IFieldRendererDefinition,
75
79
  IPluginFieldRendererProps,
80
+ IPluginPageModal,
81
+ IPluginStylePage,
82
+ IPluginStyleProps,
76
83
  IAdminPageDefinition,
77
84
  IMenuItemDefinition,
78
85
  IPluginApi,
@@ -163,6 +163,17 @@ export interface IPluginManifestPermission {
163
163
  defaultRoles?: string[];
164
164
  }
165
165
 
166
+ /** A field linked to a plugin style, with its editor metadata. */
167
+ export interface IPluginManifestStyleField {
168
+ /** A field of the plugin (`fields`) or a core field such as `own_entries_only`. */
169
+ name: string;
170
+ title?: string;
171
+ help?: string;
172
+ default?: string | null;
173
+ hidden?: boolean;
174
+ disabled?: boolean;
175
+ }
176
+
166
177
  export interface IPluginManifestStyle {
167
178
  /** Style name (used as `style_name` discriminator). */
168
179
  name: string;
@@ -170,6 +181,37 @@ export interface IPluginManifestStyle {
170
181
  canHaveChildren: boolean;
171
182
  /** Optional capability requirement (e.g. `frontendStyles`). */
172
183
  capability?: IPluginManifestCapability;
184
+ /** Style group name; required when the installer creates the style. */
185
+ group?: string;
186
+ /** Earlier names of this style; the installer renames the row in place. */
187
+ renamedFrom?: string[];
188
+ /** When present, the installer makes the style's field links match this list. */
189
+ fields?: IPluginManifestStyleField[];
190
+ }
191
+
192
+ /** Style group written into `style_groups` by the host installer (rule 7.8). */
193
+ export interface IPluginManifestStyleGroup {
194
+ name: string;
195
+ description?: string;
196
+ position?: number;
197
+ }
198
+
199
+ /** Field type (editor control) written into `field_types`; kebab-case name. */
200
+ export interface IPluginManifestFieldType {
201
+ name: string;
202
+ position?: number;
203
+ }
204
+
205
+ /** Plugin-owned field written into `fields`; snake_case name. */
206
+ export interface IPluginManifestField {
207
+ name: string;
208
+ /** A core field type or one declared under `fieldTypes`. */
209
+ type: string;
210
+ /** True for participant-facing content stored per language. */
211
+ translatable?: boolean;
212
+ config?: Record<string, unknown> | null;
213
+ /** Earlier names of this field; the installer renames the row in place. */
214
+ renamedFrom?: string[];
173
215
  }
174
216
 
175
217
  export interface IPluginManifestAdminPage {
@@ -302,6 +344,15 @@ export interface IPluginManifest {
302
344
  /** Styles contributed to the registry. */
303
345
  styles?: IPluginManifestStyle[];
304
346
 
347
+ /** Style groups the host installer writes (rule 7.8). */
348
+ styleGroups?: IPluginManifestStyleGroup[];
349
+
350
+ /** Field types the host installer writes (rule 7.8). */
351
+ fieldTypes?: IPluginManifestFieldType[];
352
+
353
+ /** Plugin-owned fields the host installer writes (rule 7.8). */
354
+ fields?: IPluginManifestField[];
355
+
305
356
  /** Admin pages mounted under `/admin/plugins-host/{pluginId}/`. */
306
357
  adminPages?: IPluginManifestAdminPage[];
307
358
 
@@ -40,6 +40,52 @@ export interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'>
40
40
  component: TPluginComponent;
41
41
  }
42
42
 
43
+ /**
44
+ * The popup a page is shown in, as the host sees it. Outside a popup
45
+ * `inModal` is false and `closeModal()` does nothing, so a plugin can call
46
+ * it unconditionally (for example after a save, like the core form's
47
+ * `close_modal_on_save`).
48
+ */
49
+ export interface IPluginPageModal {
50
+ inModal: boolean;
51
+ closeModal: () => void;
52
+ }
53
+
54
+ /**
55
+ * The page a plugin section is drawn on. A plugin endpoint that serves or
56
+ * accepts data for the section names the page and the section in every call
57
+ * (with this language, preview state and route), so the server can check
58
+ * access and read the section's settings itself (rule 7.7), like the core
59
+ * form and form list do.
60
+ */
61
+ export interface IPluginStylePage {
62
+ /** Page id; null while the page content is not known yet. */
63
+ id: number | null;
64
+ languageId: number | null;
65
+ /** Whether the page is shown as the editor's draft (preview mode). */
66
+ preview: boolean;
67
+ /** The page's declared route parameters (`page.route_params`). */
68
+ routeParams: Record<string, string>;
69
+ }
70
+
71
+ /**
72
+ * Props the host passes to a plugin style component (the `component` of an
73
+ * {@link IStyleDefinition}). `style` is the section as the page payload
74
+ * carries it (fields keyed by name).
75
+ */
76
+ export interface IPluginStyleProps {
77
+ style: Record<string, unknown>;
78
+ styleProps: Record<string, string>;
79
+ cssClass: string;
80
+ parentActive?: number;
81
+ childIndex?: number;
82
+ parentColor?: string;
83
+ /** The popup the page is shown in; a no-op outside one. */
84
+ pageModal: IPluginPageModal;
85
+ /** The page the section is on, to name in plugin calls. */
86
+ page: IPluginStylePage;
87
+ }
88
+
43
89
  /**
44
90
  * Props passed by the host's section-field editor to a plugin-supplied
45
91
  * field renderer. The host owns the surrounding label / help tooltip /
@@ -246,6 +292,13 @@ export interface IPluginApi {
246
292
  realtime?: IPluginRealtimePublisher;
247
293
  /** Host rich-text editor adapter. */
248
294
  richTextEditor: IRichTextEditorAdapter;
295
+ /**
296
+ * The host's HTML sanitizer, with the same rules core pages use (web:
297
+ * DOMPurify, plus the host's link rewrites). Call it before rendering any
298
+ * CMS or user HTML; never bundle a sanitizer of your own. `inline` keeps
299
+ * inline markup only, `block` also keeps headings, lists and paragraphs.
300
+ */
301
+ sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
249
302
  /**
250
303
  * Logger that respects the host's debug config. Avoid `console.log`
251
304
  * in plugin code; route everything through this.
@@ -260,9 +313,12 @@ export interface IPluginApi {
260
313
 
261
314
  /**
262
315
  * Same shape on mobile, minus the rich-text editor adapter when the
263
- * plugin only supports read-only mobile rendering.
316
+ * plugin only supports read-only mobile rendering. React Native does not
317
+ * render HTML, so there is no `sanitizeHtml`: mobile plugins show CMS text
318
+ * with `parseInlineRich` / `stripHtmlToText`. A plugin that renders HTML in
319
+ * a WebView sanitizes it there itself.
264
320
  */
265
- export interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor'> {
321
+ export interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml'> {
266
322
  /** Mobile builds without rich-text support set this to `null`. */
267
323
  richTextEditor: IRichTextEditorAdapter | null;
268
324
  }