@selfhelp/shared 1.15.2 → 1.15.3
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 +20 -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/package.json +1 -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,26 @@ 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.15.3
|
|
13
|
+
|
|
14
|
+
**Live Preview shared theme + language sync** — extends the bridge contract so a
|
|
15
|
+
colour-scheme / language change in either preview pane (the inline web pane or
|
|
16
|
+
the embedded mobile frame) is mirrored in the other. Additive only — two new
|
|
17
|
+
message types + payload — so `^1.15.x` consumers are unaffected; the frontend
|
|
18
|
+
(`>=0.1.39`) and mobile (`>=0.1.17`) Live Preview adopt it.
|
|
19
|
+
|
|
20
|
+
### Added (additive, non-breaking)
|
|
21
|
+
|
|
22
|
+
- **`types/preview-bridge.ts`** new exports:
|
|
23
|
+
- message types `PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES` (shell → frame) and
|
|
24
|
+
`PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED` (frame → shell);
|
|
25
|
+
- the shared payload `IPreviewPreferences` (`colorScheme` +
|
|
26
|
+
cross-platform `locale`) and `TPreviewColorScheme` (`light` / `dark` /
|
|
27
|
+
`auto`, 1:1 with Mantine + the mobile theme store);
|
|
28
|
+
- the message shapes `IPreviewSetPreferencesCommand` /
|
|
29
|
+
`IPreviewPreferencesChangedMessage`, both added to the `TPreviewBridgeMessage`
|
|
30
|
+
union and validated by `isPreviewBridgeMessage`. Covered by the bridge tests.
|
|
31
|
+
|
|
12
32
|
## v1.15.2
|
|
13
33
|
|
|
14
34
|
**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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.3",
|
|
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",
|
|
@@ -14,6 +14,7 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
14
14
|
import { describe, expect, it } from 'vitest';
|
|
15
15
|
import {
|
|
16
16
|
PREVIEW_BRIDGE_MESSAGE,
|
|
17
|
+
arePreviewPreferencesEqual,
|
|
17
18
|
isPreviewBridgeMessage,
|
|
18
19
|
previewKeywordFromPath,
|
|
19
20
|
type TPreviewBridgeMessage,
|
|
@@ -54,6 +55,51 @@ describe('isPreviewBridgeMessage', () => {
|
|
|
54
55
|
).toBe(true);
|
|
55
56
|
});
|
|
56
57
|
|
|
58
|
+
it('accepts a shell->frame set-preferences command (theme + locale)', () => {
|
|
59
|
+
const msg: TPreviewBridgeMessage = {
|
|
60
|
+
type: PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES,
|
|
61
|
+
preferences: { colorScheme: 'dark', locale: 'de-CH' },
|
|
62
|
+
};
|
|
63
|
+
expect(isPreviewBridgeMessage(msg)).toBe(true);
|
|
64
|
+
// `auto` scheme + unknown locale (null) is valid too.
|
|
65
|
+
expect(
|
|
66
|
+
isPreviewBridgeMessage({
|
|
67
|
+
type: PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES,
|
|
68
|
+
preferences: { colorScheme: 'auto', locale: null },
|
|
69
|
+
}),
|
|
70
|
+
).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('accepts a frame->shell preferences-changed message', () => {
|
|
74
|
+
const msg: TPreviewBridgeMessage = {
|
|
75
|
+
type: PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED,
|
|
76
|
+
source: 'mobile',
|
|
77
|
+
preferences: { colorScheme: 'light', locale: 'en-GB' },
|
|
78
|
+
};
|
|
79
|
+
expect(isPreviewBridgeMessage(msg)).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('rejects preference messages with an invalid scheme or missing payload', () => {
|
|
83
|
+
// unknown colour scheme
|
|
84
|
+
expect(
|
|
85
|
+
isPreviewBridgeMessage({
|
|
86
|
+
type: PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES,
|
|
87
|
+
preferences: { colorScheme: 'sepia', locale: 'de-CH' },
|
|
88
|
+
}),
|
|
89
|
+
).toBe(false);
|
|
90
|
+
// preferences-changed without a source
|
|
91
|
+
expect(
|
|
92
|
+
isPreviewBridgeMessage({
|
|
93
|
+
type: PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED,
|
|
94
|
+
preferences: { colorScheme: 'dark', locale: null },
|
|
95
|
+
}),
|
|
96
|
+
).toBe(false);
|
|
97
|
+
// missing payload entirely
|
|
98
|
+
expect(
|
|
99
|
+
isPreviewBridgeMessage({ type: PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES }),
|
|
100
|
+
).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
57
103
|
it('rejects foreign / malformed messages so cross-frame noise is ignored', () => {
|
|
58
104
|
expect(isPreviewBridgeMessage(null)).toBe(false);
|
|
59
105
|
expect(isPreviewBridgeMessage('selfhelp-preview:navigate')).toBe(false);
|
|
@@ -77,6 +123,45 @@ describe('isPreviewBridgeMessage', () => {
|
|
|
77
123
|
});
|
|
78
124
|
});
|
|
79
125
|
|
|
126
|
+
describe('arePreviewPreferencesEqual (loop guard)', () => {
|
|
127
|
+
it('treats same scheme + locale as equal so an echo is skipped', () => {
|
|
128
|
+
expect(
|
|
129
|
+
arePreviewPreferencesEqual(
|
|
130
|
+
{ colorScheme: 'dark', locale: 'de-CH' },
|
|
131
|
+
{ colorScheme: 'dark', locale: 'de-CH' },
|
|
132
|
+
),
|
|
133
|
+
).toBe(true);
|
|
134
|
+
expect(
|
|
135
|
+
arePreviewPreferencesEqual(
|
|
136
|
+
{ colorScheme: 'auto', locale: null },
|
|
137
|
+
{ colorScheme: 'auto', locale: null },
|
|
138
|
+
),
|
|
139
|
+
).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('treats a differing scheme or locale as not equal so the change propagates', () => {
|
|
143
|
+
expect(
|
|
144
|
+
arePreviewPreferencesEqual(
|
|
145
|
+
{ colorScheme: 'dark', locale: 'de-CH' },
|
|
146
|
+
{ colorScheme: 'light', locale: 'de-CH' },
|
|
147
|
+
),
|
|
148
|
+
).toBe(false);
|
|
149
|
+
expect(
|
|
150
|
+
arePreviewPreferencesEqual(
|
|
151
|
+
{ colorScheme: 'dark', locale: 'de-CH' },
|
|
152
|
+
{ colorScheme: 'dark', locale: 'en-GB' },
|
|
153
|
+
),
|
|
154
|
+
).toBe(false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('treats a null/undefined side as not equal (no last value yet → always emit)', () => {
|
|
158
|
+
const prefs = { colorScheme: 'light', locale: 'en-GB' } as const;
|
|
159
|
+
expect(arePreviewPreferencesEqual(null, prefs)).toBe(false);
|
|
160
|
+
expect(arePreviewPreferencesEqual(prefs, undefined)).toBe(false);
|
|
161
|
+
expect(arePreviewPreferencesEqual(null, null)).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
80
165
|
describe('previewKeywordFromPath', () => {
|
|
81
166
|
it('reduces web and mobile paths to the same keyword (no drift)', () => {
|
|
82
167
|
expect(previewKeywordFromPath('/impressum')).toBe('impressum');
|
|
@@ -11,10 +11,12 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
11
11
|
* The shell owns the canonical preview page. Each frame runs a small bridge that
|
|
12
12
|
* (a) reports its in-app navigations up to the shell and (b) accepts a
|
|
13
13
|
* "navigate to keyword" command down from the shell, so clicking a link in one
|
|
14
|
-
* frame keeps the other frame on the same page. The
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* frame keeps the other frame on the same page. The same channel also carries
|
|
15
|
+
* the shared colour-scheme + language preferences both ways (SET_PREFERENCES
|
|
16
|
+
* down, PREFERENCES_CHANGED up) so the two panes stay in the same theme/locale.
|
|
17
|
+
* The shell prevents sync loops with a per-frame "expected value" guard (it
|
|
18
|
+
* ignores the echo of a command it just sent). See the frontend `LivePreview`
|
|
19
|
+
* shell + `PreviewShellBridge` and the mobile `PreviewSyncBridge`.
|
|
18
20
|
*
|
|
19
21
|
* This module is the SINGLE SOURCE OF TRUTH for the message `type` strings, the
|
|
20
22
|
* activation/origin query-param names, the payload shapes, and the runtime type
|
|
@@ -30,6 +32,25 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
30
32
|
/** Which embedded preview frame a bridge message refers to. */
|
|
31
33
|
export type TPreviewFrameSource = 'web' | 'mobile';
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Three-way colour-scheme choice, shared VERBATIM across both panes — it maps
|
|
37
|
+
* 1:1 onto the web's Mantine `useMantineColorScheme` and the mobile theme store
|
|
38
|
+
* (`'auto'` = follow the OS on both).
|
|
39
|
+
*/
|
|
40
|
+
export type TPreviewColorScheme = 'light' | 'dark' | 'auto';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The shared, cross-pane preview preferences. `locale` (e.g. `de-CH`) is the
|
|
44
|
+
* cross-platform language key — each pane maps it to its own language id from
|
|
45
|
+
* its languages list; `null` means "unknown / leave as-is". Carried by both the
|
|
46
|
+
* shell→frame {@link IPreviewSetPreferencesCommand} and the frame→shell
|
|
47
|
+
* {@link IPreviewPreferencesChangedMessage} so theme + language stay in sync.
|
|
48
|
+
*/
|
|
49
|
+
export interface IPreviewPreferences {
|
|
50
|
+
colorScheme: TPreviewColorScheme;
|
|
51
|
+
locale: string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
33
54
|
/**
|
|
34
55
|
* Query param the shell appends to a frame URL to ACTIVATE its bridge
|
|
35
56
|
* (`previewShell=1`). Absent (normal public browsing) → the bridge stays dormant
|
|
@@ -54,6 +75,13 @@ export const PREVIEW_BRIDGE_MESSAGE = {
|
|
|
54
75
|
NAVIGATED: 'selfhelp-preview:navigated',
|
|
55
76
|
/** shell → frame: navigate the frame to a CMS keyword (soft, no reload). */
|
|
56
77
|
NAVIGATE: 'selfhelp-preview:navigate',
|
|
78
|
+
/**
|
|
79
|
+
* shell → frame: apply the shared colour-scheme + language preferences (no
|
|
80
|
+
* reload), so the web pane and the mobile frame stay in the same theme/locale.
|
|
81
|
+
*/
|
|
82
|
+
SET_PREFERENCES: 'selfhelp-preview:set-preferences',
|
|
83
|
+
/** frame → shell: the user changed the colour scheme / language in the frame. */
|
|
84
|
+
PREFERENCES_CHANGED: 'selfhelp-preview:preferences-changed',
|
|
57
85
|
} as const;
|
|
58
86
|
|
|
59
87
|
export type TPreviewBridgeMessageType =
|
|
@@ -68,8 +96,8 @@ export interface IPreviewReadyMessage {
|
|
|
68
96
|
/**
|
|
69
97
|
* frame → shell: the frame moved to a new page. `keyword` is the CMS keyword of
|
|
70
98
|
* the current page (the cross-platform sync unit), or `null` for home / a
|
|
71
|
-
* non-CMS location. `locale` is the frame's active locale when known
|
|
72
|
-
*
|
|
99
|
+
* non-CMS location. `locale` is the frame's active locale when known (a toolbar
|
|
100
|
+
* indicator); active cross-pane language sync rides {@link PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED}.
|
|
73
101
|
*/
|
|
74
102
|
export interface IPreviewNavigatedMessage {
|
|
75
103
|
type: typeof PREVIEW_BRIDGE_MESSAGE.NAVIGATED;
|
|
@@ -90,11 +118,46 @@ export interface IPreviewNavigateCommand {
|
|
|
90
118
|
keyword: string | null;
|
|
91
119
|
}
|
|
92
120
|
|
|
121
|
+
/**
|
|
122
|
+
* shell → frame: apply the shared colour-scheme + language {@link IPreviewPreferences}
|
|
123
|
+
* with NO reload, so a theme/language change in one pane (or the toolbar) is
|
|
124
|
+
* mirrored in the other. Idempotent — re-applying the current values is a no-op.
|
|
125
|
+
*/
|
|
126
|
+
export interface IPreviewSetPreferencesCommand {
|
|
127
|
+
type: typeof PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES;
|
|
128
|
+
preferences: IPreviewPreferences;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* frame → shell: the user changed the colour scheme and/or language inside the
|
|
133
|
+
* frame; the shell applies it to the other pane. The shell guards against the
|
|
134
|
+
* echo of a value it just pushed so the two panes never ping-pong.
|
|
135
|
+
*/
|
|
136
|
+
export interface IPreviewPreferencesChangedMessage {
|
|
137
|
+
type: typeof PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED;
|
|
138
|
+
source: TPreviewFrameSource;
|
|
139
|
+
preferences: IPreviewPreferences;
|
|
140
|
+
}
|
|
141
|
+
|
|
93
142
|
/** Every message that can cross the preview bridge, in either direction. */
|
|
94
143
|
export type TPreviewBridgeMessage =
|
|
95
144
|
| IPreviewReadyMessage
|
|
96
145
|
| IPreviewNavigatedMessage
|
|
97
|
-
| IPreviewNavigateCommand
|
|
146
|
+
| IPreviewNavigateCommand
|
|
147
|
+
| IPreviewSetPreferencesCommand
|
|
148
|
+
| IPreviewPreferencesChangedMessage;
|
|
149
|
+
|
|
150
|
+
/** Runtime guard for the shared preferences payload. */
|
|
151
|
+
function isPreviewPreferences(value: unknown): value is IPreviewPreferences {
|
|
152
|
+
if (typeof value !== 'object' || value === null) return false;
|
|
153
|
+
const record = value as Record<string, unknown>;
|
|
154
|
+
return (
|
|
155
|
+
(record.colorScheme === 'light' ||
|
|
156
|
+
record.colorScheme === 'dark' ||
|
|
157
|
+
record.colorScheme === 'auto') &&
|
|
158
|
+
(typeof record.locale === 'string' || record.locale === null)
|
|
159
|
+
);
|
|
160
|
+
}
|
|
98
161
|
|
|
99
162
|
/**
|
|
100
163
|
* Runtime guard: is `value` a well-formed preview-bridge message? Use it on the
|
|
@@ -115,11 +178,32 @@ export function isPreviewBridgeMessage(value: unknown): value is TPreviewBridgeM
|
|
|
115
178
|
);
|
|
116
179
|
case PREVIEW_BRIDGE_MESSAGE.NAVIGATE:
|
|
117
180
|
return typeof record.keyword === 'string' || record.keyword === null;
|
|
181
|
+
case PREVIEW_BRIDGE_MESSAGE.SET_PREFERENCES:
|
|
182
|
+
return isPreviewPreferences(record.preferences);
|
|
183
|
+
case PREVIEW_BRIDGE_MESSAGE.PREFERENCES_CHANGED:
|
|
184
|
+
return (
|
|
185
|
+
(record.source === 'web' || record.source === 'mobile') &&
|
|
186
|
+
isPreviewPreferences(record.preferences)
|
|
187
|
+
);
|
|
118
188
|
default:
|
|
119
189
|
return false;
|
|
120
190
|
}
|
|
121
191
|
}
|
|
122
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Loop-guard equality for the shared preferences. Both bridges keep the last
|
|
195
|
+
* value they pushed to / received from the other pane and skip re-emitting (or
|
|
196
|
+
* re-applying) an equal one, so a theme/language change never ping-pongs. Shared
|
|
197
|
+
* so the two panes compare preferences identically.
|
|
198
|
+
*/
|
|
199
|
+
export function arePreviewPreferencesEqual(
|
|
200
|
+
a: IPreviewPreferences | null | undefined,
|
|
201
|
+
b: IPreviewPreferences | null | undefined,
|
|
202
|
+
): boolean {
|
|
203
|
+
if (!a || !b) return false;
|
|
204
|
+
return a.colorScheme === b.colorScheme && a.locale === b.locale;
|
|
205
|
+
}
|
|
206
|
+
|
|
123
207
|
/**
|
|
124
208
|
* Normalize an in-app path to its CMS keyword (the sync unit): strip the leading
|
|
125
209
|
* slash and any query/hash, decode segments; an empty path (home) → `null`.
|