@selfhelp/shared 1.15.2 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/dist/index.d.mts +60 -8
- package/dist/index.d.ts +60 -8
- package/dist/index.js +23 -1
- package/dist/index.mjs +22 -1
- package/dist/plugin-sdk/index.d.mts +107 -2
- package/dist/plugin-sdk/index.d.ts +107 -2
- package/dist/plugin-sdk/index.js +14 -1
- package/dist/plugin-sdk/index.mjs +12 -1
- package/package.json +1 -1
- package/src/plugin-sdk/__tests__/host-services.test.ts +136 -0
- package/src/plugin-sdk/host-services.ts +115 -0
- package/src/plugin-sdk/index.ts +8 -0
- package/src/plugin-sdk/version.ts +6 -1
- package/src/types/__tests__/preview-bridge.test.ts +85 -0
- package/src/types/preview-bridge.ts +91 -7
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,46 @@ All notable changes to `@selfhelp/shared` will be documented in this file.
|
|
|
9
9
|
|
|
10
10
|
This project follows semantic versioning.
|
|
11
11
|
|
|
12
|
+
## v1.16.0
|
|
13
|
+
|
|
14
|
+
**Mobile host-services bridge** — a typed contract so a plugin's mobile package
|
|
15
|
+
routes protected API calls through the native host (which owns the access token,
|
|
16
|
+
the single 401-refresh round-trip, and session-expiry) instead of injecting raw
|
|
17
|
+
tokens into plugin/WebView code. Additive only — new `plugin-sdk` module +
|
|
18
|
+
exports — so `^1.x` consumers are unaffected; the SurveyJS mobile WebView
|
|
19
|
+
renderer (`@selfhelp/sh2-shp-survey-js-mobile`) and the mobile host adopt it.
|
|
20
|
+
|
|
21
|
+
### Added (additive, non-breaking)
|
|
22
|
+
|
|
23
|
+
- **`plugin-sdk/host-services.ts`** new exports (via `@selfhelp/shared/plugin-sdk`):
|
|
24
|
+
- `IMobileHostServices` (`apiBaseUrl()`, `getAccessToken()`, `request()`),
|
|
25
|
+
`IMobileHostRequest`, `IMobileHostResponse<TData>`, `TMobileHostMethod`;
|
|
26
|
+
- the singleton registry `setMobileHostServices()` / `getMobileHostServices()`
|
|
27
|
+
(host registers at boot; the plugin consumes at runtime).
|
|
28
|
+
- **`MOBILE_RENDERER_VERSION`** bumped `0.1.0 -> 0.2.0` (additive renderer
|
|
29
|
+
feature). Plugins declaring `compatibility.mobile: ^0.2.0` gate against it
|
|
30
|
+
through `isMobileRendererCompatible`.
|
|
31
|
+
|
|
32
|
+
## v1.15.3
|
|
33
|
+
|
|
34
|
+
**Live Preview shared theme + language sync** — extends the bridge contract so a
|
|
35
|
+
colour-scheme / language change in either preview pane (the inline web pane or
|
|
36
|
+
the embedded mobile frame) is mirrored in the other. Additive only — two new
|
|
37
|
+
message types + payload — so `^1.15.x` consumers are unaffected; the frontend
|
|
38
|
+
(`>=0.1.39`) and mobile (`>=0.1.17`) Live Preview adopt it.
|
|
39
|
+
|
|
40
|
+
### Added (additive, non-breaking)
|
|
41
|
+
|
|
42
|
+
- **`types/preview-bridge.ts`** new exports:
|
|
43
|
+
- message types `PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES` (shell → frame) and
|
|
44
|
+
`PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED` (frame → shell);
|
|
45
|
+
- the shared payload `IPreviewPreferences` (`colorScheme` +
|
|
46
|
+
cross-platform `locale`) and `TPreviewColorScheme` (`light` / `dark` /
|
|
47
|
+
`auto`, 1:1 with Mantine + the mobile theme store);
|
|
48
|
+
- the message shapes `IPreviewSetPreferencesCommand` /
|
|
49
|
+
`IPreviewPreferencesChangedMessage`, both added to the `TPreviewBridgeMessage`
|
|
50
|
+
union and validated by `isPreviewBridgeMessage`. Covered by the bridge tests.
|
|
51
|
+
|
|
12
52
|
## v1.15.2
|
|
13
53
|
|
|
14
54
|
**Live Preview bridge contract** — the `postMessage` protocol that keeps the CMS
|
package/dist/index.d.mts
CHANGED
|
@@ -855,10 +855,12 @@ type IMobilePreviewExchangeResponse = IBaseApiResponse<IMobilePreviewExchangeDat
|
|
|
855
855
|
* The shell owns the canonical preview page. Each frame runs a small bridge that
|
|
856
856
|
* (a) reports its in-app navigations up to the shell and (b) accepts a
|
|
857
857
|
* "navigate to keyword" command down from the shell, so clicking a link in one
|
|
858
|
-
* frame keeps the other frame on the same page. The
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
858
|
+
* frame keeps the other frame on the same page. The same channel also carries
|
|
859
|
+
* the shared colour-scheme + language preferences both ways (SET_PREFERENCES
|
|
860
|
+
* down, PREFERENCES_CHANGED up) so the two panes stay in the same theme/locale.
|
|
861
|
+
* The shell prevents sync loops with a per-frame "expected value" guard (it
|
|
862
|
+
* ignores the echo of a command it just sent). See the frontend `LivePreview`
|
|
863
|
+
* shell + `PreviewShellBridge` and the mobile `PreviewSyncBridge`.
|
|
862
864
|
*
|
|
863
865
|
* This module is the SINGLE SOURCE OF TRUTH for the message `type` strings, the
|
|
864
866
|
* activation/origin query-param names, the payload shapes, and the runtime type
|
|
@@ -872,6 +874,23 @@ type IMobilePreviewExchangeResponse = IBaseApiResponse<IMobilePreviewExchangeDat
|
|
|
872
874
|
*/
|
|
873
875
|
/** Which embedded preview frame a bridge message refers to. */
|
|
874
876
|
type TPreviewFrameSource = 'web' | 'mobile';
|
|
877
|
+
/**
|
|
878
|
+
* Three-way colour-scheme choice, shared VERBATIM across both panes — it maps
|
|
879
|
+
* 1:1 onto the web's Mantine `useMantineColorScheme` and the mobile theme store
|
|
880
|
+
* (`'auto'` = follow the OS on both).
|
|
881
|
+
*/
|
|
882
|
+
type TPreviewColorScheme = 'light' | 'dark' | 'auto';
|
|
883
|
+
/**
|
|
884
|
+
* The shared, cross-pane preview preferences. `locale` (e.g. `de-CH`) is the
|
|
885
|
+
* cross-platform language key — each pane maps it to its own language id from
|
|
886
|
+
* its languages list; `null` means "unknown / leave as-is". Carried by both the
|
|
887
|
+
* shell→frame {@link IPreviewSetPreferencesCommand} and the frame→shell
|
|
888
|
+
* {@link IPreviewPreferencesChangedMessage} so theme + language stay in sync.
|
|
889
|
+
*/
|
|
890
|
+
interface IPreviewPreferences {
|
|
891
|
+
colorScheme: TPreviewColorScheme;
|
|
892
|
+
locale: string | null;
|
|
893
|
+
}
|
|
875
894
|
/**
|
|
876
895
|
* Query param the shell appends to a frame URL to ACTIVATE its bridge
|
|
877
896
|
* (`previewShell=1`). Absent (normal public browsing) → the bridge stays dormant
|
|
@@ -894,6 +913,13 @@ declare const PREVIEW_BRIDGE_MESSAGE: {
|
|
|
894
913
|
readonly NAVIGATED: "selfhelp-preview:navigated";
|
|
895
914
|
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
896
915
|
readonly NAVIGATE: "selfhelp-preview:navigate";
|
|
916
|
+
/**
|
|
917
|
+
* shell → frame: apply the shared colour-scheme + language preferences (no
|
|
918
|
+
* reload), so the web pane and the mobile frame stay in the same theme/locale.
|
|
919
|
+
*/
|
|
920
|
+
readonly SET_PREFERENCES: "selfhelp-preview:set-preferences";
|
|
921
|
+
/** frame → shell: the user changed the colour scheme / language in the frame. */
|
|
922
|
+
readonly PREFERENCES_CHANGED: "selfhelp-preview:preferences-changed";
|
|
897
923
|
};
|
|
898
924
|
type TPreviewBridgeMessageType = (typeof PREVIEW_BRIDGE_MESSAGE)[keyof typeof PREVIEW_BRIDGE_MESSAGE];
|
|
899
925
|
/** frame → shell: emitted once when the bridge mounts. */
|
|
@@ -904,8 +930,8 @@ interface IPreviewReadyMessage {
|
|
|
904
930
|
/**
|
|
905
931
|
* frame → shell: the frame moved to a new page. `keyword` is the CMS keyword of
|
|
906
932
|
* the current page (the cross-platform sync unit), or `null` for home / a
|
|
907
|
-
* non-CMS location. `locale` is the frame's active locale when known
|
|
908
|
-
*
|
|
933
|
+
* non-CMS location. `locale` is the frame's active locale when known (a toolbar
|
|
934
|
+
* indicator); active cross-pane language sync rides {@link PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED}.
|
|
909
935
|
*/
|
|
910
936
|
interface IPreviewNavigatedMessage {
|
|
911
937
|
type: typeof PREVIEW_BRIDGE_MESSAGE.NAVIGATED;
|
|
@@ -924,14 +950,40 @@ interface IPreviewNavigateCommand {
|
|
|
924
950
|
type: typeof PREVIEW_BRIDGE_MESSAGE.NAVIGATE;
|
|
925
951
|
keyword: string | null;
|
|
926
952
|
}
|
|
953
|
+
/**
|
|
954
|
+
* shell → frame: apply the shared colour-scheme + language {@link IPreviewPreferences}
|
|
955
|
+
* with NO reload, so a theme/language change in one pane (or the toolbar) is
|
|
956
|
+
* mirrored in the other. Idempotent — re-applying the current values is a no-op.
|
|
957
|
+
*/
|
|
958
|
+
interface IPreviewSetPreferencesCommand {
|
|
959
|
+
type: typeof PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES;
|
|
960
|
+
preferences: IPreviewPreferences;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* frame → shell: the user changed the colour scheme and/or language inside the
|
|
964
|
+
* frame; the shell applies it to the other pane. The shell guards against the
|
|
965
|
+
* echo of a value it just pushed so the two panes never ping-pong.
|
|
966
|
+
*/
|
|
967
|
+
interface IPreviewPreferencesChangedMessage {
|
|
968
|
+
type: typeof PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED;
|
|
969
|
+
source: TPreviewFrameSource;
|
|
970
|
+
preferences: IPreviewPreferences;
|
|
971
|
+
}
|
|
927
972
|
/** Every message that can cross the preview bridge, in either direction. */
|
|
928
|
-
type TPreviewBridgeMessage = IPreviewReadyMessage | IPreviewNavigatedMessage | IPreviewNavigateCommand;
|
|
973
|
+
type TPreviewBridgeMessage = IPreviewReadyMessage | IPreviewNavigatedMessage | IPreviewNavigateCommand | IPreviewSetPreferencesCommand | IPreviewPreferencesChangedMessage;
|
|
929
974
|
/**
|
|
930
975
|
* Runtime guard: is `value` a well-formed preview-bridge message? Use it on the
|
|
931
976
|
* receiving end of a `message` event (AFTER the `event.origin` allow-list check)
|
|
932
977
|
* to safely narrow `event.data`. Defensive against arbitrary cross-frame noise.
|
|
933
978
|
*/
|
|
934
979
|
declare function isPreviewBridgeMessage(value: unknown): value is TPreviewBridgeMessage;
|
|
980
|
+
/**
|
|
981
|
+
* Loop-guard equality for the shared preferences. Both bridges keep the last
|
|
982
|
+
* value they pushed to / received from the other pane and skip re-emitting (or
|
|
983
|
+
* re-applying) an equal one, so a theme/language change never ping-pongs. Shared
|
|
984
|
+
* so the two panes compare preferences identically.
|
|
985
|
+
*/
|
|
986
|
+
declare function arePreviewPreferencesEqual(a: IPreviewPreferences | null | undefined, b: IPreviewPreferences | null | undefined): boolean;
|
|
935
987
|
/**
|
|
936
988
|
* Normalize an in-app path to its CMS keyword (the sync unit): strip the leading
|
|
937
989
|
* slash and any query/hash, decode segments; an empty path (home) → `null`.
|
|
@@ -1988,4 +2040,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
|
|
|
1988
2040
|
*/
|
|
1989
2041
|
declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
|
|
1990
2042
|
|
|
1991
|
-
export { API_VERSION_PREFIX, type AdvisoryAffected, type AdvisoryFeed, type AdvisorySeverity, type BackupManifest, type BackupRetentionPolicy, type BackupSchedulePolicy, type BundledPluginRef, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, type CheckSeverity, type CompatibilityRules, type CoreRelease, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type ICompatibilityError, type IConditionContext, IContentField, type IEvaluatedCondition, type IForgotPasswordRequest, type IForgotPasswordResponse, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IFrontendUpdatePreflight, type IFrontendUpdatePreflightResponse, type IFrontendUpdateReleases, type IFrontendUpdateReleasesResponse, type IFrontendUpdateRequest, type IFrontendUpdateRequestResponse, type IGetPageResponse, type IGetPagesResponse, type IInlineNode, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMaintenanceSetRequest, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileInputProps, type IMobileModalProps, type IMobilePreviewExchangeData, type IMobilePreviewExchangeRequest, type IMobilePreviewExchangeResponse, type IMobilePreviewSessionData, type IMobilePreviewSessionRequest, type IMobilePreviewSessionResponse, type IMobilePreviewUpdatePreflight, type IMobilePreviewUpdatePreflightResponse, type IMobilePreviewUpdateReleases, type IMobilePreviewUpdateReleasesResponse, type IMobilePreviewUpdateRequest, type IMobilePreviewUpdateRequestResponse, type IMobileSelectOption, type IMobileSelectProps, type IMobileSwitchProps, type IMobileTextProps, type IMobileTextareaProps, type IMobileUiAdapters, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IPreviewNavigateCommand, type IPreviewNavigatedMessage, type IPreviewReadyMessage, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type ISpacingValue, type ISystemAdvisories, type ISystemAdvisoriesResponse, type ISystemAdvisory, type ISystemAdvisoryAffected, type ISystemHealth, type ISystemHealthComponent, type ISystemHealthResponse, type ISystemInstalledPlugin, type ISystemMaintenance, type ISystemMaintenanceResponse, type ISystemVersion, type ISystemVersionResponse, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUpdatePreflight, type IUpdatePreflightCheck, type IUpdatePreflightOption, type IUpdatePreflightResponse, type IUpdateRelease, type IUpdateReleases, type IUpdateReleasesResponse, type IUpdateRequest, type IUpdateRequestResponse, type IUpdateStatus, type IUpdateStatusManager, type IUpdateStatusResponse, type IUpdateStep, type IUserData, type IUserDataResponse, type ImageRef, type InstalledPlugin, type InstanceImages, type InstanceLock, type InstanceManifest, type InstanceMode, type InstanceResourceConfig, type InstanceRouting, type InstanceStatus, type InstanceVersions, type InventoryInstanceEntry, LITERAL_CLASSES, type LockPluginEntry, type LockServiceEntry, MOBILE_PREVIEW_ENDPOINTS, type MobilePreviewRelease, PERMISSIONS, PREVIEW_BRIDGE_MESSAGE, PREVIEW_PARENT_ORIGIN_PARAM, PREVIEW_SHELL_PARAM, type PluginRelease, type PreflightCheck, type PreflightOption, type PreflightStatus, RELEASE_CHANNELS, type RegistryIndex, type RegistryReleaseRef, type ReleaseChannel, type RuntimeServicePolicy, type RuntimeServiceRange, SIZE_VALUES, SPACING_VALUES, SYSTEM_ENDPOINTS, type SchedulerRelease, type SecurityAdvisory, type ServerInventory, type ServiceBackendCompatibility, type SignatureBlock, type SupportBundleMeta, type TCalcedValues, type TClassDecision, type TClientType, THeroUiButtonVariant, THeroUiSize, TMobileButtonFeedback, TMobileFieldVariant, TMobileSelectPresentation, type TPermission, type TPlatform, type TPreviewBridgeMessage, type TPreviewBridgeMessageType, type TPreviewFrameSource, TStyleName, type TSystemAdvisorySeverity, type TSystemComponentStatus, type TSystemDeployment, type TSystemHealthOverall, type TUpdateCheckSeverity, type TUpdateKind, type TUpdateOperationStatus, type TUpdatePreflightStatus, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, type WorkerRelease, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, hasInlineFormatting, isPreviewBridgeMessage, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
|
2043
|
+
export { API_VERSION_PREFIX, type AdvisoryAffected, type AdvisoryFeed, type AdvisorySeverity, type BackupManifest, type BackupRetentionPolicy, type BackupSchedulePolicy, type BundledPluginRef, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, type CheckSeverity, type CompatibilityRules, type CoreRelease, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type ICompatibilityError, type IConditionContext, IContentField, type IEvaluatedCondition, type IForgotPasswordRequest, type IForgotPasswordResponse, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IFrontendUpdatePreflight, type IFrontendUpdatePreflightResponse, type IFrontendUpdateReleases, type IFrontendUpdateReleasesResponse, type IFrontendUpdateRequest, type IFrontendUpdateRequestResponse, type IGetPageResponse, type IGetPagesResponse, type IInlineNode, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMaintenanceSetRequest, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileInputProps, type IMobileModalProps, type IMobilePreviewExchangeData, type IMobilePreviewExchangeRequest, type IMobilePreviewExchangeResponse, type IMobilePreviewSessionData, type IMobilePreviewSessionRequest, type IMobilePreviewSessionResponse, type IMobilePreviewUpdatePreflight, type IMobilePreviewUpdatePreflightResponse, type IMobilePreviewUpdateReleases, type IMobilePreviewUpdateReleasesResponse, type IMobilePreviewUpdateRequest, type IMobilePreviewUpdateRequestResponse, type IMobileSelectOption, type IMobileSelectProps, type IMobileSwitchProps, type IMobileTextProps, type IMobileTextareaProps, type IMobileUiAdapters, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IPreviewNavigateCommand, type IPreviewNavigatedMessage, type IPreviewPreferences, type IPreviewPreferencesChangedMessage, type IPreviewReadyMessage, type IPreviewSetPreferencesCommand, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type ISpacingValue, type ISystemAdvisories, type ISystemAdvisoriesResponse, type ISystemAdvisory, type ISystemAdvisoryAffected, type ISystemHealth, type ISystemHealthComponent, type ISystemHealthResponse, type ISystemInstalledPlugin, type ISystemMaintenance, type ISystemMaintenanceResponse, type ISystemVersion, type ISystemVersionResponse, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUpdatePreflight, type IUpdatePreflightCheck, type IUpdatePreflightOption, type IUpdatePreflightResponse, type IUpdateRelease, type IUpdateReleases, type IUpdateReleasesResponse, type IUpdateRequest, type IUpdateRequestResponse, type IUpdateStatus, type IUpdateStatusManager, type IUpdateStatusResponse, type IUpdateStep, type IUserData, type IUserDataResponse, type ImageRef, type InstalledPlugin, type InstanceImages, type InstanceLock, type InstanceManifest, type InstanceMode, type InstanceResourceConfig, type InstanceRouting, type InstanceStatus, type InstanceVersions, type InventoryInstanceEntry, LITERAL_CLASSES, type LockPluginEntry, type LockServiceEntry, MOBILE_PREVIEW_ENDPOINTS, type MobilePreviewRelease, PERMISSIONS, PREVIEW_BRIDGE_MESSAGE, PREVIEW_PARENT_ORIGIN_PARAM, PREVIEW_SHELL_PARAM, type PluginRelease, type PreflightCheck, type PreflightOption, type PreflightStatus, RELEASE_CHANNELS, type RegistryIndex, type RegistryReleaseRef, type ReleaseChannel, type RuntimeServicePolicy, type RuntimeServiceRange, SIZE_VALUES, SPACING_VALUES, SYSTEM_ENDPOINTS, type SchedulerRelease, type SecurityAdvisory, type ServerInventory, type ServiceBackendCompatibility, type SignatureBlock, type SupportBundleMeta, type TCalcedValues, type TClassDecision, type TClientType, THeroUiButtonVariant, THeroUiSize, TMobileButtonFeedback, TMobileFieldVariant, TMobileSelectPresentation, type TPermission, type TPlatform, type TPreviewBridgeMessage, type TPreviewBridgeMessageType, type TPreviewColorScheme, type TPreviewFrameSource, TStyleName, type TSystemAdvisorySeverity, type TSystemComponentStatus, type TSystemDeployment, type TSystemHealthOverall, type TUpdateCheckSeverity, type TUpdateKind, type TUpdateOperationStatus, type TUpdatePreflightStatus, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, type WorkerRelease, arePreviewPreferencesEqual, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, hasInlineFormatting, isPreviewBridgeMessage, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
package/dist/index.d.ts
CHANGED
|
@@ -855,10 +855,12 @@ type IMobilePreviewExchangeResponse = IBaseApiResponse<IMobilePreviewExchangeDat
|
|
|
855
855
|
* The shell owns the canonical preview page. Each frame runs a small bridge that
|
|
856
856
|
* (a) reports its in-app navigations up to the shell and (b) accepts a
|
|
857
857
|
* "navigate to keyword" command down from the shell, so clicking a link in one
|
|
858
|
-
* frame keeps the other frame on the same page. The
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
*
|
|
858
|
+
* frame keeps the other frame on the same page. The same channel also carries
|
|
859
|
+
* the shared colour-scheme + language preferences both ways (SET_PREFERENCES
|
|
860
|
+
* down, PREFERENCES_CHANGED up) so the two panes stay in the same theme/locale.
|
|
861
|
+
* The shell prevents sync loops with a per-frame "expected value" guard (it
|
|
862
|
+
* ignores the echo of a command it just sent). See the frontend `LivePreview`
|
|
863
|
+
* shell + `PreviewShellBridge` and the mobile `PreviewSyncBridge`.
|
|
862
864
|
*
|
|
863
865
|
* This module is the SINGLE SOURCE OF TRUTH for the message `type` strings, the
|
|
864
866
|
* activation/origin query-param names, the payload shapes, and the runtime type
|
|
@@ -872,6 +874,23 @@ type IMobilePreviewExchangeResponse = IBaseApiResponse<IMobilePreviewExchangeDat
|
|
|
872
874
|
*/
|
|
873
875
|
/** Which embedded preview frame a bridge message refers to. */
|
|
874
876
|
type TPreviewFrameSource = 'web' | 'mobile';
|
|
877
|
+
/**
|
|
878
|
+
* Three-way colour-scheme choice, shared VERBATIM across both panes — it maps
|
|
879
|
+
* 1:1 onto the web's Mantine `useMantineColorScheme` and the mobile theme store
|
|
880
|
+
* (`'auto'` = follow the OS on both).
|
|
881
|
+
*/
|
|
882
|
+
type TPreviewColorScheme = 'light' | 'dark' | 'auto';
|
|
883
|
+
/**
|
|
884
|
+
* The shared, cross-pane preview preferences. `locale` (e.g. `de-CH`) is the
|
|
885
|
+
* cross-platform language key — each pane maps it to its own language id from
|
|
886
|
+
* its languages list; `null` means "unknown / leave as-is". Carried by both the
|
|
887
|
+
* shell→frame {@link IPreviewSetPreferencesCommand} and the frame→shell
|
|
888
|
+
* {@link IPreviewPreferencesChangedMessage} so theme + language stay in sync.
|
|
889
|
+
*/
|
|
890
|
+
interface IPreviewPreferences {
|
|
891
|
+
colorScheme: TPreviewColorScheme;
|
|
892
|
+
locale: string | null;
|
|
893
|
+
}
|
|
875
894
|
/**
|
|
876
895
|
* Query param the shell appends to a frame URL to ACTIVATE its bridge
|
|
877
896
|
* (`previewShell=1`). Absent (normal public browsing) → the bridge stays dormant
|
|
@@ -894,6 +913,13 @@ declare const PREVIEW_BRIDGE_MESSAGE: {
|
|
|
894
913
|
readonly NAVIGATED: "selfhelp-preview:navigated";
|
|
895
914
|
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
896
915
|
readonly NAVIGATE: "selfhelp-preview:navigate";
|
|
916
|
+
/**
|
|
917
|
+
* shell → frame: apply the shared colour-scheme + language preferences (no
|
|
918
|
+
* reload), so the web pane and the mobile frame stay in the same theme/locale.
|
|
919
|
+
*/
|
|
920
|
+
readonly SET_PREFERENCES: "selfhelp-preview:set-preferences";
|
|
921
|
+
/** frame → shell: the user changed the colour scheme / language in the frame. */
|
|
922
|
+
readonly PREFERENCES_CHANGED: "selfhelp-preview:preferences-changed";
|
|
897
923
|
};
|
|
898
924
|
type TPreviewBridgeMessageType = (typeof PREVIEW_BRIDGE_MESSAGE)[keyof typeof PREVIEW_BRIDGE_MESSAGE];
|
|
899
925
|
/** frame → shell: emitted once when the bridge mounts. */
|
|
@@ -904,8 +930,8 @@ interface IPreviewReadyMessage {
|
|
|
904
930
|
/**
|
|
905
931
|
* frame → shell: the frame moved to a new page. `keyword` is the CMS keyword of
|
|
906
932
|
* the current page (the cross-platform sync unit), or `null` for home / a
|
|
907
|
-
* non-CMS location. `locale` is the frame's active locale when known
|
|
908
|
-
*
|
|
933
|
+
* non-CMS location. `locale` is the frame's active locale when known (a toolbar
|
|
934
|
+
* indicator); active cross-pane language sync rides {@link PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED}.
|
|
909
935
|
*/
|
|
910
936
|
interface IPreviewNavigatedMessage {
|
|
911
937
|
type: typeof PREVIEW_BRIDGE_MESSAGE.NAVIGATED;
|
|
@@ -924,14 +950,40 @@ interface IPreviewNavigateCommand {
|
|
|
924
950
|
type: typeof PREVIEW_BRIDGE_MESSAGE.NAVIGATE;
|
|
925
951
|
keyword: string | null;
|
|
926
952
|
}
|
|
953
|
+
/**
|
|
954
|
+
* shell → frame: apply the shared colour-scheme + language {@link IPreviewPreferences}
|
|
955
|
+
* with NO reload, so a theme/language change in one pane (or the toolbar) is
|
|
956
|
+
* mirrored in the other. Idempotent — re-applying the current values is a no-op.
|
|
957
|
+
*/
|
|
958
|
+
interface IPreviewSetPreferencesCommand {
|
|
959
|
+
type: typeof PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES;
|
|
960
|
+
preferences: IPreviewPreferences;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* frame → shell: the user changed the colour scheme and/or language inside the
|
|
964
|
+
* frame; the shell applies it to the other pane. The shell guards against the
|
|
965
|
+
* echo of a value it just pushed so the two panes never ping-pong.
|
|
966
|
+
*/
|
|
967
|
+
interface IPreviewPreferencesChangedMessage {
|
|
968
|
+
type: typeof PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED;
|
|
969
|
+
source: TPreviewFrameSource;
|
|
970
|
+
preferences: IPreviewPreferences;
|
|
971
|
+
}
|
|
927
972
|
/** Every message that can cross the preview bridge, in either direction. */
|
|
928
|
-
type TPreviewBridgeMessage = IPreviewReadyMessage | IPreviewNavigatedMessage | IPreviewNavigateCommand;
|
|
973
|
+
type TPreviewBridgeMessage = IPreviewReadyMessage | IPreviewNavigatedMessage | IPreviewNavigateCommand | IPreviewSetPreferencesCommand | IPreviewPreferencesChangedMessage;
|
|
929
974
|
/**
|
|
930
975
|
* Runtime guard: is `value` a well-formed preview-bridge message? Use it on the
|
|
931
976
|
* receiving end of a `message` event (AFTER the `event.origin` allow-list check)
|
|
932
977
|
* to safely narrow `event.data`. Defensive against arbitrary cross-frame noise.
|
|
933
978
|
*/
|
|
934
979
|
declare function isPreviewBridgeMessage(value: unknown): value is TPreviewBridgeMessage;
|
|
980
|
+
/**
|
|
981
|
+
* Loop-guard equality for the shared preferences. Both bridges keep the last
|
|
982
|
+
* value they pushed to / received from the other pane and skip re-emitting (or
|
|
983
|
+
* re-applying) an equal one, so a theme/language change never ping-pongs. Shared
|
|
984
|
+
* so the two panes compare preferences identically.
|
|
985
|
+
*/
|
|
986
|
+
declare function arePreviewPreferencesEqual(a: IPreviewPreferences | null | undefined, b: IPreviewPreferences | null | undefined): boolean;
|
|
935
987
|
/**
|
|
936
988
|
* Normalize an in-app path to its CMS keyword (the sync unit): strip the leading
|
|
937
989
|
* slash and any query/hash, decode segments; an empty path (home) → `null`.
|
|
@@ -1988,4 +2040,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
|
|
|
1988
2040
|
*/
|
|
1989
2041
|
declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
|
|
1990
2042
|
|
|
1991
|
-
export { API_VERSION_PREFIX, type AdvisoryAffected, type AdvisoryFeed, type AdvisorySeverity, type BackupManifest, type BackupRetentionPolicy, type BackupSchedulePolicy, type BundledPluginRef, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, type CheckSeverity, type CompatibilityRules, type CoreRelease, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type ICompatibilityError, type IConditionContext, IContentField, type IEvaluatedCondition, type IForgotPasswordRequest, type IForgotPasswordResponse, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IFrontendUpdatePreflight, type IFrontendUpdatePreflightResponse, type IFrontendUpdateReleases, type IFrontendUpdateReleasesResponse, type IFrontendUpdateRequest, type IFrontendUpdateRequestResponse, type IGetPageResponse, type IGetPagesResponse, type IInlineNode, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMaintenanceSetRequest, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileInputProps, type IMobileModalProps, type IMobilePreviewExchangeData, type IMobilePreviewExchangeRequest, type IMobilePreviewExchangeResponse, type IMobilePreviewSessionData, type IMobilePreviewSessionRequest, type IMobilePreviewSessionResponse, type IMobilePreviewUpdatePreflight, type IMobilePreviewUpdatePreflightResponse, type IMobilePreviewUpdateReleases, type IMobilePreviewUpdateReleasesResponse, type IMobilePreviewUpdateRequest, type IMobilePreviewUpdateRequestResponse, type IMobileSelectOption, type IMobileSelectProps, type IMobileSwitchProps, type IMobileTextProps, type IMobileTextareaProps, type IMobileUiAdapters, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IPreviewNavigateCommand, type IPreviewNavigatedMessage, type IPreviewReadyMessage, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type ISpacingValue, type ISystemAdvisories, type ISystemAdvisoriesResponse, type ISystemAdvisory, type ISystemAdvisoryAffected, type ISystemHealth, type ISystemHealthComponent, type ISystemHealthResponse, type ISystemInstalledPlugin, type ISystemMaintenance, type ISystemMaintenanceResponse, type ISystemVersion, type ISystemVersionResponse, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUpdatePreflight, type IUpdatePreflightCheck, type IUpdatePreflightOption, type IUpdatePreflightResponse, type IUpdateRelease, type IUpdateReleases, type IUpdateReleasesResponse, type IUpdateRequest, type IUpdateRequestResponse, type IUpdateStatus, type IUpdateStatusManager, type IUpdateStatusResponse, type IUpdateStep, type IUserData, type IUserDataResponse, type ImageRef, type InstalledPlugin, type InstanceImages, type InstanceLock, type InstanceManifest, type InstanceMode, type InstanceResourceConfig, type InstanceRouting, type InstanceStatus, type InstanceVersions, type InventoryInstanceEntry, LITERAL_CLASSES, type LockPluginEntry, type LockServiceEntry, MOBILE_PREVIEW_ENDPOINTS, type MobilePreviewRelease, PERMISSIONS, PREVIEW_BRIDGE_MESSAGE, PREVIEW_PARENT_ORIGIN_PARAM, PREVIEW_SHELL_PARAM, type PluginRelease, type PreflightCheck, type PreflightOption, type PreflightStatus, RELEASE_CHANNELS, type RegistryIndex, type RegistryReleaseRef, type ReleaseChannel, type RuntimeServicePolicy, type RuntimeServiceRange, SIZE_VALUES, SPACING_VALUES, SYSTEM_ENDPOINTS, type SchedulerRelease, type SecurityAdvisory, type ServerInventory, type ServiceBackendCompatibility, type SignatureBlock, type SupportBundleMeta, type TCalcedValues, type TClassDecision, type TClientType, THeroUiButtonVariant, THeroUiSize, TMobileButtonFeedback, TMobileFieldVariant, TMobileSelectPresentation, type TPermission, type TPlatform, type TPreviewBridgeMessage, type TPreviewBridgeMessageType, type TPreviewFrameSource, TStyleName, type TSystemAdvisorySeverity, type TSystemComponentStatus, type TSystemDeployment, type TSystemHealthOverall, type TUpdateCheckSeverity, type TUpdateKind, type TUpdateOperationStatus, type TUpdatePreflightStatus, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, type WorkerRelease, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, hasInlineFormatting, isPreviewBridgeMessage, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
|
2043
|
+
export { API_VERSION_PREFIX, type AdvisoryAffected, type AdvisoryFeed, type AdvisorySeverity, type BackupManifest, type BackupRetentionPolicy, type BackupSchedulePolicy, type BundledPluginRef, CLASS_PATTERNS, CLASS_REMAP, CLIENT_TYPE_MOBILE, CLIENT_TYPE_MOBILE_AND_WEB, CLIENT_TYPE_WEB, COLOR_NAMES, type CheckSeverity, type CompatibilityRules, type CoreRelease, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IClassPattern, type IClassRemap, type ICompatibilityError, type IConditionContext, IContentField, type IEvaluatedCondition, type IForgotPasswordRequest, type IForgotPasswordResponse, type IFormDeleteRequest, type IFormDeleteResponse, type IFormResultLegacyFields, type IFormSubmitData, type IFormSubmitRequest, type IFormSubmitResponse, type IFormUpdateData, type IFormUpdateRequest, type IFormUpdateResponse, type IFrontendUpdatePreflight, type IFrontendUpdatePreflightResponse, type IFrontendUpdateReleases, type IFrontendUpdateReleasesResponse, type IFrontendUpdateRequest, type IFrontendUpdateRequestResponse, type IGetPageResponse, type IGetPagesResponse, type IInlineNode, type IJwtPayload, type ILanguage, type ILanguageItem, type ILanguagePreference, type ILanguagePreferenceUpdateResponse, type ILanguagesResponse, type ILoginRequest, type ILoginSuccessData, type ILoginSuccessResponse, type ILogoutSuccessResponse, type IMaintenanceSetRequest, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileInputProps, type IMobileModalProps, type IMobilePreviewExchangeData, type IMobilePreviewExchangeRequest, type IMobilePreviewExchangeResponse, type IMobilePreviewSessionData, type IMobilePreviewSessionRequest, type IMobilePreviewSessionResponse, type IMobilePreviewUpdatePreflight, type IMobilePreviewUpdatePreflightResponse, type IMobilePreviewUpdateReleases, type IMobilePreviewUpdateReleasesResponse, type IMobilePreviewUpdateRequest, type IMobilePreviewUpdateRequestResponse, type IMobileSelectOption, type IMobileSelectProps, type IMobileSwitchProps, type IMobileTextProps, type IMobileTextareaProps, type IMobileUiAdapters, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageSectionWithFields, type IPageSectionsData, type IPreviewNavigateCommand, type IPreviewNavigatedMessage, type IPreviewPreferences, type IPreviewPreferencesChangedMessage, type IPreviewReadyMessage, type IPreviewSetPreferencesCommand, type IRefreshRequest, type IRefreshSuccessResponse, type IResetPasswordRequest, type IResetPasswordResponse, type ISpacingValue, type ISystemAdvisories, type ISystemAdvisoriesResponse, type ISystemAdvisory, type ISystemAdvisoryAffected, type ISystemHealth, type ISystemHealthComponent, type ISystemHealthResponse, type ISystemInstalledPlugin, type ISystemMaintenance, type ISystemMaintenanceResponse, type ISystemVersion, type ISystemVersionResponse, type ITwoFactorRequiredData, type ITwoFactorRequiredResponse, type ITwoFactorVerifyRequest, type ITwoFactorVerifySuccessResponse, type IUpdatePreflight, type IUpdatePreflightCheck, type IUpdatePreflightOption, type IUpdatePreflightResponse, type IUpdateRelease, type IUpdateReleases, type IUpdateReleasesResponse, type IUpdateRequest, type IUpdateRequestResponse, type IUpdateStatus, type IUpdateStatusManager, type IUpdateStatusResponse, type IUpdateStep, type IUserData, type IUserDataResponse, type ImageRef, type InstalledPlugin, type InstanceImages, type InstanceLock, type InstanceManifest, type InstanceMode, type InstanceResourceConfig, type InstanceRouting, type InstanceStatus, type InstanceVersions, type InventoryInstanceEntry, LITERAL_CLASSES, type LockPluginEntry, type LockServiceEntry, MOBILE_PREVIEW_ENDPOINTS, type MobilePreviewRelease, PERMISSIONS, PREVIEW_BRIDGE_MESSAGE, PREVIEW_PARENT_ORIGIN_PARAM, PREVIEW_SHELL_PARAM, type PluginRelease, type PreflightCheck, type PreflightOption, type PreflightStatus, RELEASE_CHANNELS, type RegistryIndex, type RegistryReleaseRef, type ReleaseChannel, type RuntimeServicePolicy, type RuntimeServiceRange, SIZE_VALUES, SPACING_VALUES, SYSTEM_ENDPOINTS, type SchedulerRelease, type SecurityAdvisory, type ServerInventory, type ServiceBackendCompatibility, type SignatureBlock, type SupportBundleMeta, type TCalcedValues, type TClassDecision, type TClientType, THeroUiButtonVariant, THeroUiSize, TMobileButtonFeedback, TMobileFieldVariant, TMobileSelectPresentation, type TPermission, type TPlatform, type TPreviewBridgeMessage, type TPreviewBridgeMessageType, type TPreviewColorScheme, type TPreviewFrameSource, TStyleName, type TSystemAdvisorySeverity, type TSystemComponentStatus, type TSystemDeployment, type TSystemHealthOverall, type TUpdateCheckSeverity, type TUpdateKind, type TUpdateOperationStatus, type TUpdatePreflightStatus, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, type WorkerRelease, arePreviewPreferencesEqual, buildConditionContext, classifyClass, classifyClassString, evaluateCondition, findRemap, hasInlineFormatting, isPreviewBridgeMessage, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ __export(index_exports, {
|
|
|
61
61
|
STYLE_REGISTRY: () => STYLE_REGISTRY,
|
|
62
62
|
SYSTEM_ENDPOINTS: () => SYSTEM_ENDPOINTS,
|
|
63
63
|
_resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
|
|
64
|
+
arePreviewPreferencesEqual: () => arePreviewPreferencesEqual,
|
|
64
65
|
buildConditionContext: () => buildConditionContext,
|
|
65
66
|
classifyClass: () => classifyClass,
|
|
66
67
|
classifyClassString: () => classifyClassString,
|
|
@@ -225,8 +226,20 @@ var PREVIEW_BRIDGE_MESSAGE = {
|
|
|
225
226
|
/** frame → shell: the frame navigated to a new in-app location. */
|
|
226
227
|
NAVIGATED: "selfhelp-preview:navigated",
|
|
227
228
|
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
228
|
-
NAVIGATE: "selfhelp-preview:navigate"
|
|
229
|
+
NAVIGATE: "selfhelp-preview:navigate",
|
|
230
|
+
/**
|
|
231
|
+
* shell → frame: apply the shared colour-scheme + language preferences (no
|
|
232
|
+
* reload), so the web pane and the mobile frame stay in the same theme/locale.
|
|
233
|
+
*/
|
|
234
|
+
SET_PREFERENCES: "selfhelp-preview:set-preferences",
|
|
235
|
+
/** frame → shell: the user changed the colour scheme / language in the frame. */
|
|
236
|
+
PREFERENCES_CHANGED: "selfhelp-preview:preferences-changed"
|
|
229
237
|
};
|
|
238
|
+
function isPreviewPreferences(value) {
|
|
239
|
+
if (typeof value !== "object" || value === null) return false;
|
|
240
|
+
const record = value;
|
|
241
|
+
return (record.colorScheme === "light" || record.colorScheme === "dark" || record.colorScheme === "auto") && (typeof record.locale === "string" || record.locale === null);
|
|
242
|
+
}
|
|
230
243
|
function isPreviewBridgeMessage(value) {
|
|
231
244
|
if (typeof value !== "object" || value === null) return false;
|
|
232
245
|
const record = value;
|
|
@@ -237,10 +250,18 @@ function isPreviewBridgeMessage(value) {
|
|
|
237
250
|
return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string";
|
|
238
251
|
case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
|
|
239
252
|
return typeof record.keyword === "string" || record.keyword === null;
|
|
253
|
+
case PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES:
|
|
254
|
+
return isPreviewPreferences(record.preferences);
|
|
255
|
+
case PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED:
|
|
256
|
+
return (record.source === "web" || record.source === "mobile") && isPreviewPreferences(record.preferences);
|
|
240
257
|
default:
|
|
241
258
|
return false;
|
|
242
259
|
}
|
|
243
260
|
}
|
|
261
|
+
function arePreviewPreferencesEqual(a, b) {
|
|
262
|
+
if (!a || !b) return false;
|
|
263
|
+
return a.colorScheme === b.colorScheme && a.locale === b.locale;
|
|
264
|
+
}
|
|
244
265
|
function previewKeywordFromPath(path) {
|
|
245
266
|
if (!path) return null;
|
|
246
267
|
const withoutQuery = path.split(/[?#]/, 1)[0] ?? "";
|
|
@@ -1597,6 +1618,7 @@ function transformPagesData(pages) {
|
|
|
1597
1618
|
STYLE_REGISTRY,
|
|
1598
1619
|
SYSTEM_ENDPOINTS,
|
|
1599
1620
|
_resetPluginStyleRegistry,
|
|
1621
|
+
arePreviewPreferencesEqual,
|
|
1600
1622
|
buildConditionContext,
|
|
1601
1623
|
classifyClass,
|
|
1602
1624
|
classifyClassString,
|
package/dist/index.mjs
CHANGED
|
@@ -99,8 +99,20 @@ var PREVIEW_BRIDGE_MESSAGE = {
|
|
|
99
99
|
/** frame → shell: the frame navigated to a new in-app location. */
|
|
100
100
|
NAVIGATED: "selfhelp-preview:navigated",
|
|
101
101
|
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
102
|
-
NAVIGATE: "selfhelp-preview:navigate"
|
|
102
|
+
NAVIGATE: "selfhelp-preview:navigate",
|
|
103
|
+
/**
|
|
104
|
+
* shell → frame: apply the shared colour-scheme + language preferences (no
|
|
105
|
+
* reload), so the web pane and the mobile frame stay in the same theme/locale.
|
|
106
|
+
*/
|
|
107
|
+
SET_PREFERENCES: "selfhelp-preview:set-preferences",
|
|
108
|
+
/** frame → shell: the user changed the colour scheme / language in the frame. */
|
|
109
|
+
PREFERENCES_CHANGED: "selfhelp-preview:preferences-changed"
|
|
103
110
|
};
|
|
111
|
+
function isPreviewPreferences(value) {
|
|
112
|
+
if (typeof value !== "object" || value === null) return false;
|
|
113
|
+
const record = value;
|
|
114
|
+
return (record.colorScheme === "light" || record.colorScheme === "dark" || record.colorScheme === "auto") && (typeof record.locale === "string" || record.locale === null);
|
|
115
|
+
}
|
|
104
116
|
function isPreviewBridgeMessage(value) {
|
|
105
117
|
if (typeof value !== "object" || value === null) return false;
|
|
106
118
|
const record = value;
|
|
@@ -111,10 +123,18 @@ function isPreviewBridgeMessage(value) {
|
|
|
111
123
|
return (record.source === "web" || record.source === "mobile") && (typeof record.keyword === "string" || record.keyword === null) && typeof record.href === "string";
|
|
112
124
|
case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
|
|
113
125
|
return typeof record.keyword === "string" || record.keyword === null;
|
|
126
|
+
case PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES:
|
|
127
|
+
return isPreviewPreferences(record.preferences);
|
|
128
|
+
case PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED:
|
|
129
|
+
return (record.source === "web" || record.source === "mobile") && isPreviewPreferences(record.preferences);
|
|
114
130
|
default:
|
|
115
131
|
return false;
|
|
116
132
|
}
|
|
117
133
|
}
|
|
134
|
+
function arePreviewPreferencesEqual(a, b) {
|
|
135
|
+
if (!a || !b) return false;
|
|
136
|
+
return a.colorScheme === b.colorScheme && a.locale === b.locale;
|
|
137
|
+
}
|
|
118
138
|
function previewKeywordFromPath(path) {
|
|
119
139
|
if (!path) return null;
|
|
120
140
|
const withoutQuery = path.split(/[?#]/, 1)[0] ?? "";
|
|
@@ -1470,6 +1490,7 @@ export {
|
|
|
1470
1490
|
STYLE_REGISTRY,
|
|
1471
1491
|
SYSTEM_ENDPOINTS,
|
|
1472
1492
|
_resetPluginStyleRegistry,
|
|
1493
|
+
arePreviewPreferencesEqual,
|
|
1473
1494
|
buildConditionContext,
|
|
1474
1495
|
classifyClass,
|
|
1475
1496
|
classifyClassString,
|
|
@@ -30,8 +30,13 @@ declare const PLUGIN_API_VERSION: "0.1.0";
|
|
|
30
30
|
*
|
|
31
31
|
* Bump rules mirror the SDK contract: patch = additive fix, minor = additive
|
|
32
32
|
* renderer feature, major = breaking mobile renderer change.
|
|
33
|
+
*
|
|
34
|
+
* `0.2.0` adds the typed mobile host-services bridge (`IMobileHostServices` +
|
|
35
|
+
* `set/getMobileHostServices`) so a plugin's mobile package routes protected
|
|
36
|
+
* API calls through the native host (token + 401-refresh owned host-side)
|
|
37
|
+
* instead of injecting raw tokens — an additive renderer feature.
|
|
33
38
|
*/
|
|
34
|
-
declare const MOBILE_RENDERER_VERSION: "0.
|
|
39
|
+
declare const MOBILE_RENDERER_VERSION: "0.2.0";
|
|
35
40
|
interface ISemver {
|
|
36
41
|
major: number;
|
|
37
42
|
minor: number;
|
|
@@ -692,6 +697,106 @@ declare function defineMobilePlugin(registration: IMobilePluginRegistration): IM
|
|
|
692
697
|
*/
|
|
693
698
|
declare function definePluginRealtimeTopic<TPayload>(descriptor: IPluginRealtimeTopic<TPayload>): IPluginRealtimeTopic<TPayload>;
|
|
694
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Mobile host-services bridge (mobile renderer contract, `MOBILE_RENDERER_VERSION`).
|
|
702
|
+
*
|
|
703
|
+
* A plugin's mobile package renders its UI (commonly inside an isolated
|
|
704
|
+
* WebView), but it MUST NOT own authenticated backend access. Instead the
|
|
705
|
+
* native mobile host registers an `IMobileHostServices` implementation at
|
|
706
|
+
* boot, and the plugin performs every protected API call through it. This
|
|
707
|
+
* keeps the access token, the 401-refresh round-trip, session-expiry, the
|
|
708
|
+
* API base URL, and client headers (`X-Client-Type: mobile`, locale) in the
|
|
709
|
+
* host — never inside plugin/WebView code.
|
|
710
|
+
*
|
|
711
|
+
* Design constraints:
|
|
712
|
+
* - Framework-agnostic: no `react` / `react-native` / `axios` imports here.
|
|
713
|
+
* The host wires its own HTTP client (e.g. the shared axios singleton)
|
|
714
|
+
* into `request`.
|
|
715
|
+
* - Singleton: the host calls {@link setMobileHostServices} once during
|
|
716
|
+
* boot; the plugin calls {@link getMobileHostServices} at runtime.
|
|
717
|
+
* - The token is intentionally NOT a required input to plugin calls. A
|
|
718
|
+
* plugin may read {@link IMobileHostServices.getAccessToken} only for
|
|
719
|
+
* non-sensitive bootstrapping; it must never implement its own refresh.
|
|
720
|
+
*/
|
|
721
|
+
/** HTTP method accepted by the host request bridge. */
|
|
722
|
+
type TMobileHostMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
723
|
+
/**
|
|
724
|
+
* A protected backend request the plugin asks the host to perform. The
|
|
725
|
+
* host prepends {@link IMobileHostServices.apiBaseUrl}, attaches the bearer
|
|
726
|
+
* token + client headers, and handles a single 401-refresh retry.
|
|
727
|
+
*/
|
|
728
|
+
interface IMobileHostRequest {
|
|
729
|
+
/**
|
|
730
|
+
* Path relative to the host API base, e.g.
|
|
731
|
+
* `/cms-api/v1/plugins/<id>/published/<key>`. Absolute URLs are rejected
|
|
732
|
+
* by the host so a plugin cannot redirect protected calls off-origin.
|
|
733
|
+
*/
|
|
734
|
+
path: string;
|
|
735
|
+
/** HTTP method. Defaults to `GET`. */
|
|
736
|
+
method?: TMobileHostMethod;
|
|
737
|
+
/** JSON-serialisable request body (sent as `application/json`). */
|
|
738
|
+
body?: unknown;
|
|
739
|
+
/** Extra request headers (e.g. a plugin runtime-config echo header). */
|
|
740
|
+
headers?: Record<string, string>;
|
|
741
|
+
/** Query parameters appended to the path. */
|
|
742
|
+
query?: Record<string, string | number | boolean>;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Result of a host request. `data` is the parsed response body (the SelfHelp
|
|
746
|
+
* API envelope `{ status, message, data, ... }` for API routes), so the
|
|
747
|
+
* plugin reads `response.data.data` for the inner payload. `reason` mirrors
|
|
748
|
+
* the backend error discriminator (e.g. `already_submitted_once`) so the
|
|
749
|
+
* plugin can branch on lifecycle errors without re-parsing the body.
|
|
750
|
+
*/
|
|
751
|
+
interface IMobileHostResponse<TData = unknown> {
|
|
752
|
+
/** True for 2xx responses. */
|
|
753
|
+
ok: boolean;
|
|
754
|
+
/** HTTP status code (0 when the request never reached the server). */
|
|
755
|
+
status: number;
|
|
756
|
+
/** Parsed response body, or `null` when there is no JSON body. */
|
|
757
|
+
data: TData | null;
|
|
758
|
+
/** Backend error `reason` discriminator, when present. */
|
|
759
|
+
reason?: string;
|
|
760
|
+
/** Human-readable error message for non-ok responses. */
|
|
761
|
+
error?: string;
|
|
762
|
+
/**
|
|
763
|
+
* True when the call failed because the session could not be
|
|
764
|
+
* authenticated even after the host's refresh attempt (a 401 the host
|
|
765
|
+
* could not recover). The plugin should surface a "session expired"
|
|
766
|
+
* state rather than a generic error.
|
|
767
|
+
*/
|
|
768
|
+
sessionExpired?: boolean;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Authenticated host services exposed to a plugin's mobile package. The
|
|
772
|
+
* host owns the token + refresh; the plugin only describes the request.
|
|
773
|
+
*/
|
|
774
|
+
interface IMobileHostServices {
|
|
775
|
+
/** Resolved API base URL the host calls (e.g. `https://cms.example.com`). */
|
|
776
|
+
apiBaseUrl(): string;
|
|
777
|
+
/**
|
|
778
|
+
* Current access token, or `null` when unauthenticated. Exposed only for
|
|
779
|
+
* non-sensitive bootstrapping (e.g. deciding whether to show a login
|
|
780
|
+
* prompt). Plugins must route protected calls through {@link request},
|
|
781
|
+
* which attaches the token host-side, instead of injecting this value.
|
|
782
|
+
*/
|
|
783
|
+
getAccessToken(): string | null;
|
|
784
|
+
/** Perform an authenticated request with host-managed 401 refresh. */
|
|
785
|
+
request<TData = unknown>(req: IMobileHostRequest): Promise<IMobileHostResponse<TData>>;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Register the host services implementation. Called once by the native
|
|
789
|
+
* mobile host during boot (before any plugin renders). Re-registering
|
|
790
|
+
* replaces the previous implementation (e.g. on a server switch).
|
|
791
|
+
*/
|
|
792
|
+
declare function setMobileHostServices(services: IMobileHostServices | null): void;
|
|
793
|
+
/**
|
|
794
|
+
* Read the registered host services. Returns `null` when no host has
|
|
795
|
+
* registered yet — a plugin must treat that as "host too old / not ready"
|
|
796
|
+
* and degrade gracefully (it must never fall back to its own token logic).
|
|
797
|
+
*/
|
|
798
|
+
declare function getMobileHostServices(): IMobileHostServices | null;
|
|
799
|
+
|
|
695
800
|
/**
|
|
696
801
|
* `usePluginRealtime` — universal React hook for plugin Mercure topic
|
|
697
802
|
* subscription.
|
|
@@ -874,4 +979,4 @@ declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginR
|
|
|
874
979
|
*/
|
|
875
980
|
declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
|
|
876
981
|
|
|
877
|
-
export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, 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 TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, usePluginRealtime };
|
|
982
|
+
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 };
|