@selfhelp/shared 1.21.0 → 1.21.2
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 +21 -0
- package/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +88 -1
- package/dist/index.mjs +82 -1
- package/package.json +1 -1
- package/src/navigation/__tests__/navigation.test.ts +85 -0
- package/src/navigation/branchNav.ts +45 -0
- package/src/navigation/index.ts +1 -0
- package/src/navigation/menuDepth.ts +37 -0
- package/src/navigation/menuMembership.ts +27 -1
- package/src/navigation/menuSearch.ts +2 -1
- package/src/navigation/navLinks.ts +9 -0
- package/src/navigation/navigationPayload.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,27 @@ 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.21.2
|
|
13
|
+
|
|
14
|
+
**Menu-builder navigation depth and accessibility (patch)** — additive helpers for
|
|
15
|
+
menu depth limits and item labelling. `resolveMenuMaxDepth` and
|
|
16
|
+
`clampMenuItemsAtDepth` normalise `INavigationMenu.max_depth` (null/0 = unlimited)
|
|
17
|
+
and strip nested children beyond the configured depth for dropdown/mega renderers.
|
|
18
|
+
`getNavigationItemAriaLabel` resolves `aria_label` with a fallback to the visible
|
|
19
|
+
label. `INavigationMenu` gains optional `config` for menu-level presentation
|
|
20
|
+
settings from the backend payload.
|
|
21
|
+
|
|
22
|
+
## v1.21.1
|
|
23
|
+
|
|
24
|
+
**Menu-builder navigation helpers (patch)** — additive navigation utilities for
|
|
25
|
+
mobile bottom tabs and cross-menu page lookup. `findPageRefInNavigationPayload`
|
|
26
|
+
resolves `INavigationResolvedPageRef` metadata from any public menu tree;
|
|
27
|
+
`findNearestBottomTabMenuItemForPage` and `isBottomTabMenuItemActive` drive
|
|
28
|
+
nested bottom-tab active state (ancestor tab stays active for descendant paths).
|
|
29
|
+
`searchMenuPagesInPayload` now honours `payload.search.min_chars` before
|
|
30
|
+
returning hits. Regression tests assert legacy `TWebNavRender` /
|
|
31
|
+
`TMobileNavRender` option lists are not re-exported from the package root.
|
|
32
|
+
|
|
12
33
|
## v1.21.0
|
|
13
34
|
|
|
14
35
|
**Menu-builder navigation contract (breaking cleanup)** — replaces the page-level
|
package/dist/index.d.mts
CHANGED
|
@@ -2088,6 +2088,7 @@ interface INavigationMenu {
|
|
|
2088
2088
|
preset?: TWebHeaderPreset | string | null;
|
|
2089
2089
|
max_depth?: number | null;
|
|
2090
2090
|
item_limit?: number | null;
|
|
2091
|
+
config?: Record<string, unknown> | null;
|
|
2091
2092
|
items: INavigationMenuItem[];
|
|
2092
2093
|
}
|
|
2093
2094
|
interface INavigationStartupConfig {
|
|
@@ -2119,6 +2120,8 @@ declare function isPageInMenuTree(items: INavigationMenuItem[], pageId: number):
|
|
|
2119
2120
|
declare function isPageInResolvedMenus(menus: Partial<Record<TNavigationMenuKey, INavigationMenu>>, menuKeys: TNavigationMenuKey[], pageId: number): boolean;
|
|
2120
2121
|
declare function isOnAnyMobileMenu(menus: Partial<Record<TNavigationMenuKey, INavigationMenu>>, pageId: number): boolean;
|
|
2121
2122
|
declare function findMenuItemByPageId(items: INavigationMenuItem[], pageId: number): INavigationMenuItem | null;
|
|
2123
|
+
/** Resolved page metadata from any public menu tree (for holder redirects, etc.). */
|
|
2124
|
+
declare function findPageRefInNavigationPayload(payload: INavigationPayload, pageId: number): INavigationResolvedPageRef | null;
|
|
2122
2125
|
|
|
2123
2126
|
interface IBranchNavSegment {
|
|
2124
2127
|
pageId: number;
|
|
@@ -2146,8 +2149,17 @@ declare function isOnAnyMobileMenuFromPayload(payload: INavigationPayload, pageI
|
|
|
2146
2149
|
* return the first child route to auto-select.
|
|
2147
2150
|
*/
|
|
2148
2151
|
declare function resolveHolderRedirectPath(payload: INavigationPayload, currentPageId: number, platform: 'web' | 'mobile', hasContent: boolean): string | null;
|
|
2152
|
+
/**
|
|
2153
|
+
* Returns the top-level bottom-tab item that owns a nested page, if any.
|
|
2154
|
+
*/
|
|
2155
|
+
declare function findNearestBottomTabMenuItemForPage(tabs: INavigationMenuItem[], pageId: number): INavigationMenuItem | null;
|
|
2156
|
+
/**
|
|
2157
|
+
* Active state for a flat bottom-tab item, including descendants on the current path.
|
|
2158
|
+
*/
|
|
2159
|
+
declare function isBottomTabMenuItemActive(item: INavigationMenuItem, pathname: string): boolean;
|
|
2149
2160
|
|
|
2150
2161
|
declare function getNavigationItemLabel(item: INavigationMenuItem): string;
|
|
2162
|
+
declare function getNavigationItemAriaLabel(item: INavigationMenuItem): string | undefined;
|
|
2151
2163
|
declare function getNavigationItemHref(item: INavigationMenuItem): string;
|
|
2152
2164
|
declare function flattenNavigationMenuItems(items: INavigationMenuItem[]): INavigationMenuItem[];
|
|
2153
2165
|
declare function getNavigationItemKeyword(item: INavigationMenuItem): string | null;
|
|
@@ -2215,6 +2227,21 @@ interface IMenuSearchHit {
|
|
|
2215
2227
|
*/
|
|
2216
2228
|
declare function searchMenuPagesInPayload(payload: INavigationPayload, query: string, limit?: number): IMenuSearchHit[];
|
|
2217
2229
|
|
|
2230
|
+
/**
|
|
2231
|
+
|
|
2232
|
+
* Normalises menu max_depth: null/undefined/0 means unlimited.
|
|
2233
|
+
|
|
2234
|
+
*/
|
|
2235
|
+
declare function resolveMenuMaxDepth(maxDepth: number | null | undefined): number | null;
|
|
2236
|
+
/**
|
|
2237
|
+
|
|
2238
|
+
* Strips nested children beyond the configured depth so renderers do not
|
|
2239
|
+
|
|
2240
|
+
* expand deeper levels in dropdown/mega panels.
|
|
2241
|
+
|
|
2242
|
+
*/
|
|
2243
|
+
declare function clampMenuItemsAtDepth(items: INavigationMenuItem[], maxDepth: number | null, depth?: number): INavigationMenuItem[];
|
|
2244
|
+
|
|
2218
2245
|
/**
|
|
2219
2246
|
* Parse the unified `spacing` field. The CMS
|
|
2220
2247
|
* stores this as a JSON string with optional keys for each side:
|
|
@@ -2279,4 +2306,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
|
|
|
2279
2306
|
*/
|
|
2280
2307
|
declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
|
|
2281
2308
|
|
|
2282
|
-
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, DEFAULT_MOBILE_ICON, DEFAULT_WEB_HEADER_PRESET, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IBranchNavSegment, 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 IMenuSearchHit, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileIconEntry, 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 INavigationMenu, type INavigationMenuItem, type INavigationPayload, type INavigationResolvedPageRef, type INavigationSearchConfig, type INavigationStartupConfig, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageRoute, 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 IResolvePageResponse, 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 IWebHeaderPresetOption, 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_ICON_NAMES, MOBILE_ICON_SET, 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, type TMobilePagePresentation, TMobileSelectPresentation, type TNavigationChildSource, type TNavigationMenuItemType, type TNavigationMenuKey, type TNavigationMobileStartSource, type TNavigationSearchMode, type TNavigationStartMode, 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 TWebHeaderPreset, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, WEB_HEADER_PRESET_OPTIONS, WEB_HEADER_PRESET_VALUES, type WorkerRelease, arePreviewPreferencesEqual, buildConditionContext, classifyClass, classifyClassString, collectPageIdsFromMenuItems, evaluateCondition, findMenuItemByPageId, findRemap, flattenMenuItems, flattenNavigationMenuItems, getNavigationItemHref, getNavigationItemKeyword, getNavigationItemLabel, hasInlineFormatting, isMobileIconName, isOnAnyMobileMenu, isOnAnyMobileMenuFromPayload, isPageInMenuTree, isPageInResolvedMenus, isPageOnAnyMenu, isPageOnMobileMenu, isPageOnWebMenu, isPreviewBridgeMessage, isWebHeaderPreset, pageUrlToMobileRoute, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, resolveBranchNavGroup, resolveHolderRedirectPath, resolveMobileIcon, resolveMobilePagePresentation, resolveMobileSegmentGroup, resolveMobileStartupKeyword, resolveMobileStartupRoute, resolveWebBranchNavGroup, resolveWebHeaderPreset, resolveWebStartupPath, searchMenuPagesInPayload, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
|
2309
|
+
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, DEFAULT_MOBILE_ICON, DEFAULT_WEB_HEADER_PRESET, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IBranchNavSegment, 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 IMenuSearchHit, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileIconEntry, 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 INavigationMenu, type INavigationMenuItem, type INavigationPayload, type INavigationResolvedPageRef, type INavigationSearchConfig, type INavigationStartupConfig, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageRoute, 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 IResolvePageResponse, 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 IWebHeaderPresetOption, 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_ICON_NAMES, MOBILE_ICON_SET, 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, type TMobilePagePresentation, TMobileSelectPresentation, type TNavigationChildSource, type TNavigationMenuItemType, type TNavigationMenuKey, type TNavigationMobileStartSource, type TNavigationSearchMode, type TNavigationStartMode, 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 TWebHeaderPreset, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, WEB_HEADER_PRESET_OPTIONS, WEB_HEADER_PRESET_VALUES, type WorkerRelease, arePreviewPreferencesEqual, buildConditionContext, clampMenuItemsAtDepth, classifyClass, classifyClassString, collectPageIdsFromMenuItems, evaluateCondition, findMenuItemByPageId, findNearestBottomTabMenuItemForPage, findPageRefInNavigationPayload, findRemap, flattenMenuItems, flattenNavigationMenuItems, getNavigationItemAriaLabel, getNavigationItemHref, getNavigationItemKeyword, getNavigationItemLabel, hasInlineFormatting, isBottomTabMenuItemActive, isMobileIconName, isOnAnyMobileMenu, isOnAnyMobileMenuFromPayload, isPageInMenuTree, isPageInResolvedMenus, isPageOnAnyMenu, isPageOnMobileMenu, isPageOnWebMenu, isPreviewBridgeMessage, isWebHeaderPreset, pageUrlToMobileRoute, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, resolveBranchNavGroup, resolveHolderRedirectPath, resolveMenuMaxDepth, resolveMobileIcon, resolveMobilePagePresentation, resolveMobileSegmentGroup, resolveMobileStartupKeyword, resolveMobileStartupRoute, resolveWebBranchNavGroup, resolveWebHeaderPreset, resolveWebStartupPath, searchMenuPagesInPayload, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
package/dist/index.d.ts
CHANGED
|
@@ -2088,6 +2088,7 @@ interface INavigationMenu {
|
|
|
2088
2088
|
preset?: TWebHeaderPreset | string | null;
|
|
2089
2089
|
max_depth?: number | null;
|
|
2090
2090
|
item_limit?: number | null;
|
|
2091
|
+
config?: Record<string, unknown> | null;
|
|
2091
2092
|
items: INavigationMenuItem[];
|
|
2092
2093
|
}
|
|
2093
2094
|
interface INavigationStartupConfig {
|
|
@@ -2119,6 +2120,8 @@ declare function isPageInMenuTree(items: INavigationMenuItem[], pageId: number):
|
|
|
2119
2120
|
declare function isPageInResolvedMenus(menus: Partial<Record<TNavigationMenuKey, INavigationMenu>>, menuKeys: TNavigationMenuKey[], pageId: number): boolean;
|
|
2120
2121
|
declare function isOnAnyMobileMenu(menus: Partial<Record<TNavigationMenuKey, INavigationMenu>>, pageId: number): boolean;
|
|
2121
2122
|
declare function findMenuItemByPageId(items: INavigationMenuItem[], pageId: number): INavigationMenuItem | null;
|
|
2123
|
+
/** Resolved page metadata from any public menu tree (for holder redirects, etc.). */
|
|
2124
|
+
declare function findPageRefInNavigationPayload(payload: INavigationPayload, pageId: number): INavigationResolvedPageRef | null;
|
|
2122
2125
|
|
|
2123
2126
|
interface IBranchNavSegment {
|
|
2124
2127
|
pageId: number;
|
|
@@ -2146,8 +2149,17 @@ declare function isOnAnyMobileMenuFromPayload(payload: INavigationPayload, pageI
|
|
|
2146
2149
|
* return the first child route to auto-select.
|
|
2147
2150
|
*/
|
|
2148
2151
|
declare function resolveHolderRedirectPath(payload: INavigationPayload, currentPageId: number, platform: 'web' | 'mobile', hasContent: boolean): string | null;
|
|
2152
|
+
/**
|
|
2153
|
+
* Returns the top-level bottom-tab item that owns a nested page, if any.
|
|
2154
|
+
*/
|
|
2155
|
+
declare function findNearestBottomTabMenuItemForPage(tabs: INavigationMenuItem[], pageId: number): INavigationMenuItem | null;
|
|
2156
|
+
/**
|
|
2157
|
+
* Active state for a flat bottom-tab item, including descendants on the current path.
|
|
2158
|
+
*/
|
|
2159
|
+
declare function isBottomTabMenuItemActive(item: INavigationMenuItem, pathname: string): boolean;
|
|
2149
2160
|
|
|
2150
2161
|
declare function getNavigationItemLabel(item: INavigationMenuItem): string;
|
|
2162
|
+
declare function getNavigationItemAriaLabel(item: INavigationMenuItem): string | undefined;
|
|
2151
2163
|
declare function getNavigationItemHref(item: INavigationMenuItem): string;
|
|
2152
2164
|
declare function flattenNavigationMenuItems(items: INavigationMenuItem[]): INavigationMenuItem[];
|
|
2153
2165
|
declare function getNavigationItemKeyword(item: INavigationMenuItem): string | null;
|
|
@@ -2215,6 +2227,21 @@ interface IMenuSearchHit {
|
|
|
2215
2227
|
*/
|
|
2216
2228
|
declare function searchMenuPagesInPayload(payload: INavigationPayload, query: string, limit?: number): IMenuSearchHit[];
|
|
2217
2229
|
|
|
2230
|
+
/**
|
|
2231
|
+
|
|
2232
|
+
* Normalises menu max_depth: null/undefined/0 means unlimited.
|
|
2233
|
+
|
|
2234
|
+
*/
|
|
2235
|
+
declare function resolveMenuMaxDepth(maxDepth: number | null | undefined): number | null;
|
|
2236
|
+
/**
|
|
2237
|
+
|
|
2238
|
+
* Strips nested children beyond the configured depth so renderers do not
|
|
2239
|
+
|
|
2240
|
+
* expand deeper levels in dropdown/mega panels.
|
|
2241
|
+
|
|
2242
|
+
*/
|
|
2243
|
+
declare function clampMenuItemsAtDepth(items: INavigationMenuItem[], maxDepth: number | null, depth?: number): INavigationMenuItem[];
|
|
2244
|
+
|
|
2218
2245
|
/**
|
|
2219
2246
|
* Parse the unified `spacing` field. The CMS
|
|
2220
2247
|
* stores this as a JSON string with optional keys for each side:
|
|
@@ -2279,4 +2306,4 @@ declare function transformPageData(apiPage: IRawPage): IPageItem;
|
|
|
2279
2306
|
*/
|
|
2280
2307
|
declare function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[];
|
|
2281
2308
|
|
|
2282
|
-
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, DEFAULT_MOBILE_ICON, DEFAULT_WEB_HEADER_PRESET, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IBranchNavSegment, 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 IMenuSearchHit, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileIconEntry, 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 INavigationMenu, type INavigationMenuItem, type INavigationPayload, type INavigationResolvedPageRef, type INavigationSearchConfig, type INavigationStartupConfig, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageRoute, 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 IResolvePageResponse, 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 IWebHeaderPresetOption, 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_ICON_NAMES, MOBILE_ICON_SET, 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, type TMobilePagePresentation, TMobileSelectPresentation, type TNavigationChildSource, type TNavigationMenuItemType, type TNavigationMenuKey, type TNavigationMobileStartSource, type TNavigationSearchMode, type TNavigationStartMode, 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 TWebHeaderPreset, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, WEB_HEADER_PRESET_OPTIONS, WEB_HEADER_PRESET_VALUES, type WorkerRelease, arePreviewPreferencesEqual, buildConditionContext, classifyClass, classifyClassString, collectPageIdsFromMenuItems, evaluateCondition, findMenuItemByPageId, findRemap, flattenMenuItems, flattenNavigationMenuItems, getNavigationItemHref, getNavigationItemKeyword, getNavigationItemLabel, hasInlineFormatting, isMobileIconName, isOnAnyMobileMenu, isOnAnyMobileMenuFromPayload, isPageInMenuTree, isPageInResolvedMenus, isPageOnAnyMenu, isPageOnMobileMenu, isPageOnWebMenu, isPreviewBridgeMessage, isWebHeaderPreset, pageUrlToMobileRoute, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, resolveBranchNavGroup, resolveHolderRedirectPath, resolveMobileIcon, resolveMobilePagePresentation, resolveMobileSegmentGroup, resolveMobileStartupKeyword, resolveMobileStartupRoute, resolveWebBranchNavGroup, resolveWebHeaderPreset, resolveWebStartupPath, searchMenuPagesInPayload, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
|
2309
|
+
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, DEFAULT_MOBILE_ICON, DEFAULT_WEB_HEADER_PRESET, type DatabaseMigrationMetadata, ENDPOINTS, type FrontendRelease, HEADER_CLIENT_TYPE, type IApiError, type IApiMeta, type IAssetSource, type IBaseApiResponse, type IBasePageInfo, type IBasePageSection, type IBranchNavSegment, 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 IMenuSearchHit, type IMeta, type IMobileAdapterBaseProps, type IMobileButtonProps, type IMobileCardProps, type IMobileCheckboxProps, type IMobileContainerProps, type IMobileIconEntry, 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 INavigationMenu, type INavigationMenuItem, type INavigationPayload, type INavigationResolvedPageRef, type INavigationSearchConfig, type INavigationStartupConfig, type IPageAccessTypeInfo, type IPageContent, type IPageField, type IPageFieldTranslation, type IPageFieldsData, type IPageItem, type IPageRoute, 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 IResolvePageResponse, 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 IWebHeaderPresetOption, 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_ICON_NAMES, MOBILE_ICON_SET, 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, type TMobilePagePresentation, TMobileSelectPresentation, type TNavigationChildSource, type TNavigationMenuItemType, type TNavigationMenuKey, type TNavigationMobileStartSource, type TNavigationSearchMode, type TNavigationStartMode, 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 TWebHeaderPreset, type TrustLevel, type TrustedKey, type TrustedKeysFile, type UpdatePreflightResult, WEB_HEADER_PRESET_OPTIONS, WEB_HEADER_PRESET_VALUES, type WorkerRelease, arePreviewPreferencesEqual, buildConditionContext, clampMenuItemsAtDepth, classifyClass, classifyClassString, collectPageIdsFromMenuItems, evaluateCondition, findMenuItemByPageId, findNearestBottomTabMenuItemForPage, findPageRefInNavigationPayload, findRemap, flattenMenuItems, flattenNavigationMenuItems, getNavigationItemAriaLabel, getNavigationItemHref, getNavigationItemKeyword, getNavigationItemLabel, hasInlineFormatting, isBottomTabMenuItemActive, isMobileIconName, isOnAnyMobileMenu, isOnAnyMobileMenuFromPayload, isPageInMenuTree, isPageInResolvedMenus, isPageOnAnyMenu, isPageOnMobileMenu, isPageOnWebMenu, isPreviewBridgeMessage, isWebHeaderPreset, pageUrlToMobileRoute, parseInlineRich, parseSpacing, previewKeywordFromPath, replaceCalcedValues, resolveAssetSources, resolveAssetUrl, resolveBranchNavGroup, resolveHolderRedirectPath, resolveMenuMaxDepth, resolveMobileIcon, resolveMobilePagePresentation, resolveMobileSegmentGroup, resolveMobileStartupKeyword, resolveMobileStartupRoute, resolveWebBranchNavGroup, resolveWebHeaderPreset, resolveWebStartupPath, searchMenuPagesInPayload, spacingToClasses, stripHtmlToText, transformPageData, transformPagesData };
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ __export(index_exports, {
|
|
|
69
69
|
_resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
|
|
70
70
|
arePreviewPreferencesEqual: () => arePreviewPreferencesEqual,
|
|
71
71
|
buildConditionContext: () => buildConditionContext,
|
|
72
|
+
clampMenuItemsAtDepth: () => clampMenuItemsAtDepth,
|
|
72
73
|
classifyClass: () => classifyClass,
|
|
73
74
|
classifyClassString: () => classifyClassString,
|
|
74
75
|
collectPageIdsFromMenuItems: () => collectPageIdsFromMenuItems,
|
|
@@ -76,10 +77,13 @@ __export(index_exports, {
|
|
|
76
77
|
evaluateCondition: () => evaluateCondition,
|
|
77
78
|
extendStyleRegistry: () => extendStyleRegistry,
|
|
78
79
|
findMenuItemByPageId: () => findMenuItemByPageId,
|
|
80
|
+
findNearestBottomTabMenuItemForPage: () => findNearestBottomTabMenuItemForPage,
|
|
81
|
+
findPageRefInNavigationPayload: () => findPageRefInNavigationPayload,
|
|
79
82
|
findRemap: () => findRemap,
|
|
80
83
|
flattenMenuItems: () => flattenMenuItems,
|
|
81
84
|
flattenNavigationMenuItems: () => flattenNavigationMenuItems,
|
|
82
85
|
getMergedStyleRegistry: () => getMergedStyleRegistry,
|
|
86
|
+
getNavigationItemAriaLabel: () => getNavigationItemAriaLabel,
|
|
83
87
|
getNavigationItemHref: () => getNavigationItemHref,
|
|
84
88
|
getNavigationItemKeyword: () => getNavigationItemKeyword,
|
|
85
89
|
getNavigationItemLabel: () => getNavigationItemLabel,
|
|
@@ -91,6 +95,7 @@ __export(index_exports, {
|
|
|
91
95
|
getStylePluginId: () => getStylePluginId,
|
|
92
96
|
gridSpanToReactNativeColumn: () => gridSpanToReactNativeColumn,
|
|
93
97
|
hasInlineFormatting: () => hasInlineFormatting,
|
|
98
|
+
isBottomTabMenuItemActive: () => isBottomTabMenuItemActive,
|
|
94
99
|
isKnownStyleName: () => isKnownStyleName,
|
|
95
100
|
isMobileIconName: () => isMobileIconName,
|
|
96
101
|
isOnAnyMobileMenu: () => isOnAnyMobileMenu,
|
|
@@ -130,6 +135,7 @@ __export(index_exports, {
|
|
|
130
135
|
resolveBranchNavGroup: () => resolveBranchNavGroup,
|
|
131
136
|
resolveHolderRedirectPath: () => resolveHolderRedirectPath,
|
|
132
137
|
resolveMantineVariant: () => resolveMantineVariant,
|
|
138
|
+
resolveMenuMaxDepth: () => resolveMenuMaxDepth,
|
|
133
139
|
resolveMobileIcon: () => resolveMobileIcon,
|
|
134
140
|
resolveMobilePagePresentation: () => resolveMobilePagePresentation,
|
|
135
141
|
resolveMobileSegmentGroup: () => resolveMobileSegmentGroup,
|
|
@@ -1634,6 +1640,25 @@ function findMenuItemByPageId(items, pageId) {
|
|
|
1634
1640
|
}
|
|
1635
1641
|
return null;
|
|
1636
1642
|
}
|
|
1643
|
+
function findPageRefInNavigationPayload(payload, pageId) {
|
|
1644
|
+
const menuKeys = [
|
|
1645
|
+
"web_header",
|
|
1646
|
+
"web_footer",
|
|
1647
|
+
"mobile_drawer",
|
|
1648
|
+
"mobile_bottom_tabs"
|
|
1649
|
+
];
|
|
1650
|
+
for (const key of menuKeys) {
|
|
1651
|
+
const menu = payload.menus[key];
|
|
1652
|
+
if (!menu?.items?.length) {
|
|
1653
|
+
continue;
|
|
1654
|
+
}
|
|
1655
|
+
const item = findMenuItemByPageId(menu.items, pageId);
|
|
1656
|
+
if (item?.page) {
|
|
1657
|
+
return item.page;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
return null;
|
|
1661
|
+
}
|
|
1637
1662
|
|
|
1638
1663
|
// src/navigation/mobileRoute.ts
|
|
1639
1664
|
function pageUrlToMobileRoute(url, keyword) {
|
|
@@ -1785,11 +1810,48 @@ function resolveHolderRedirectPath(payload, currentPageId, platform, hasContent)
|
|
|
1785
1810
|
}
|
|
1786
1811
|
return target.keyword === "home" ? "/" : `/${target.keyword}`;
|
|
1787
1812
|
}
|
|
1813
|
+
function findNearestBottomTabMenuItemForPage(tabs, pageId) {
|
|
1814
|
+
for (const tab of tabs) {
|
|
1815
|
+
if (tab.page?.id === pageId) {
|
|
1816
|
+
return tab;
|
|
1817
|
+
}
|
|
1818
|
+
if (findMenuItemByPageId2(tab.children ?? [], pageId)) {
|
|
1819
|
+
return tab;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return null;
|
|
1823
|
+
}
|
|
1824
|
+
function navigationPathMatches(item, pathname) {
|
|
1825
|
+
const href = pageUrlToMobileRoute(item.page?.url ?? null, item.page?.keyword ?? "");
|
|
1826
|
+
if (pathname === href) {
|
|
1827
|
+
return true;
|
|
1828
|
+
}
|
|
1829
|
+
if (href !== "/" && pathname.startsWith(`${href}/`)) {
|
|
1830
|
+
return true;
|
|
1831
|
+
}
|
|
1832
|
+
return false;
|
|
1833
|
+
}
|
|
1834
|
+
function isBottomTabMenuItemActive(item, pathname) {
|
|
1835
|
+
if (navigationPathMatches(item, pathname)) {
|
|
1836
|
+
return true;
|
|
1837
|
+
}
|
|
1838
|
+
return (item.children ?? []).some(
|
|
1839
|
+
(child) => navigationPathMatches(child, pathname) || isBottomTabMenuItemActive(child, pathname)
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1788
1842
|
|
|
1789
1843
|
// src/navigation/navLinks.ts
|
|
1790
1844
|
function getNavigationItemLabel(item) {
|
|
1791
1845
|
return item.label || item.page?.title || item.page?.keyword || "";
|
|
1792
1846
|
}
|
|
1847
|
+
function getNavigationItemAriaLabel(item) {
|
|
1848
|
+
const aria = item.aria_label?.trim();
|
|
1849
|
+
if (aria) {
|
|
1850
|
+
return aria;
|
|
1851
|
+
}
|
|
1852
|
+
const label = getNavigationItemLabel(item);
|
|
1853
|
+
return label || void 0;
|
|
1854
|
+
}
|
|
1793
1855
|
function getNavigationItemHref(item) {
|
|
1794
1856
|
if (item.item_type === "external_url" && item.external_url) {
|
|
1795
1857
|
return item.external_url;
|
|
@@ -1959,7 +2021,8 @@ function haystacksForItem(item) {
|
|
|
1959
2021
|
}
|
|
1960
2022
|
function searchMenuPagesInPayload(payload, query, limit = 8) {
|
|
1961
2023
|
const needle = query.trim().toLowerCase();
|
|
1962
|
-
|
|
2024
|
+
const minChars = payload.search?.min_chars ?? 2;
|
|
2025
|
+
if (needle === "" || needle.length < minChars) {
|
|
1963
2026
|
return [];
|
|
1964
2027
|
}
|
|
1965
2028
|
const hits = [];
|
|
@@ -1991,6 +2054,24 @@ function searchMenuPagesInPayload(payload, query, limit = 8) {
|
|
|
1991
2054
|
return hits;
|
|
1992
2055
|
}
|
|
1993
2056
|
|
|
2057
|
+
// src/navigation/menuDepth.ts
|
|
2058
|
+
function resolveMenuMaxDepth(maxDepth) {
|
|
2059
|
+
if (maxDepth === null || maxDepth === void 0 || maxDepth <= 0) {
|
|
2060
|
+
return null;
|
|
2061
|
+
}
|
|
2062
|
+
return maxDepth;
|
|
2063
|
+
}
|
|
2064
|
+
function clampMenuItemsAtDepth(items, maxDepth, depth = 0) {
|
|
2065
|
+
return items.map((item) => {
|
|
2066
|
+
const atLimit = maxDepth !== null && depth >= maxDepth;
|
|
2067
|
+
const children = item.children ?? [];
|
|
2068
|
+
return {
|
|
2069
|
+
...item,
|
|
2070
|
+
children: atLimit ? [] : clampMenuItemsAtDepth(children, maxDepth, depth + 1)
|
|
2071
|
+
};
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
|
|
1994
2075
|
// src/utils/spacing.ts
|
|
1995
2076
|
var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
|
|
1996
2077
|
function parseSpacing(raw) {
|
|
@@ -2099,6 +2180,7 @@ function transformPagesData(pages) {
|
|
|
2099
2180
|
_resetPluginStyleRegistry,
|
|
2100
2181
|
arePreviewPreferencesEqual,
|
|
2101
2182
|
buildConditionContext,
|
|
2183
|
+
clampMenuItemsAtDepth,
|
|
2102
2184
|
classifyClass,
|
|
2103
2185
|
classifyClassString,
|
|
2104
2186
|
collectPageIdsFromMenuItems,
|
|
@@ -2106,10 +2188,13 @@ function transformPagesData(pages) {
|
|
|
2106
2188
|
evaluateCondition,
|
|
2107
2189
|
extendStyleRegistry,
|
|
2108
2190
|
findMenuItemByPageId,
|
|
2191
|
+
findNearestBottomTabMenuItemForPage,
|
|
2192
|
+
findPageRefInNavigationPayload,
|
|
2109
2193
|
findRemap,
|
|
2110
2194
|
flattenMenuItems,
|
|
2111
2195
|
flattenNavigationMenuItems,
|
|
2112
2196
|
getMergedStyleRegistry,
|
|
2197
|
+
getNavigationItemAriaLabel,
|
|
2113
2198
|
getNavigationItemHref,
|
|
2114
2199
|
getNavigationItemKeyword,
|
|
2115
2200
|
getNavigationItemLabel,
|
|
@@ -2121,6 +2206,7 @@ function transformPagesData(pages) {
|
|
|
2121
2206
|
getStylePluginId,
|
|
2122
2207
|
gridSpanToReactNativeColumn,
|
|
2123
2208
|
hasInlineFormatting,
|
|
2209
|
+
isBottomTabMenuItemActive,
|
|
2124
2210
|
isKnownStyleName,
|
|
2125
2211
|
isMobileIconName,
|
|
2126
2212
|
isOnAnyMobileMenu,
|
|
@@ -2160,6 +2246,7 @@ function transformPagesData(pages) {
|
|
|
2160
2246
|
resolveBranchNavGroup,
|
|
2161
2247
|
resolveHolderRedirectPath,
|
|
2162
2248
|
resolveMantineVariant,
|
|
2249
|
+
resolveMenuMaxDepth,
|
|
2163
2250
|
resolveMobileIcon,
|
|
2164
2251
|
resolveMobilePagePresentation,
|
|
2165
2252
|
resolveMobileSegmentGroup,
|
package/dist/index.mjs
CHANGED
|
@@ -1473,6 +1473,25 @@ function findMenuItemByPageId(items, pageId) {
|
|
|
1473
1473
|
}
|
|
1474
1474
|
return null;
|
|
1475
1475
|
}
|
|
1476
|
+
function findPageRefInNavigationPayload(payload, pageId) {
|
|
1477
|
+
const menuKeys = [
|
|
1478
|
+
"web_header",
|
|
1479
|
+
"web_footer",
|
|
1480
|
+
"mobile_drawer",
|
|
1481
|
+
"mobile_bottom_tabs"
|
|
1482
|
+
];
|
|
1483
|
+
for (const key of menuKeys) {
|
|
1484
|
+
const menu = payload.menus[key];
|
|
1485
|
+
if (!menu?.items?.length) {
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
const item = findMenuItemByPageId(menu.items, pageId);
|
|
1489
|
+
if (item?.page) {
|
|
1490
|
+
return item.page;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1476
1495
|
|
|
1477
1496
|
// src/navigation/mobileRoute.ts
|
|
1478
1497
|
function pageUrlToMobileRoute(url, keyword) {
|
|
@@ -1624,11 +1643,48 @@ function resolveHolderRedirectPath(payload, currentPageId, platform, hasContent)
|
|
|
1624
1643
|
}
|
|
1625
1644
|
return target.keyword === "home" ? "/" : `/${target.keyword}`;
|
|
1626
1645
|
}
|
|
1646
|
+
function findNearestBottomTabMenuItemForPage(tabs, pageId) {
|
|
1647
|
+
for (const tab of tabs) {
|
|
1648
|
+
if (tab.page?.id === pageId) {
|
|
1649
|
+
return tab;
|
|
1650
|
+
}
|
|
1651
|
+
if (findMenuItemByPageId2(tab.children ?? [], pageId)) {
|
|
1652
|
+
return tab;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return null;
|
|
1656
|
+
}
|
|
1657
|
+
function navigationPathMatches(item, pathname) {
|
|
1658
|
+
const href = pageUrlToMobileRoute(item.page?.url ?? null, item.page?.keyword ?? "");
|
|
1659
|
+
if (pathname === href) {
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
if (href !== "/" && pathname.startsWith(`${href}/`)) {
|
|
1663
|
+
return true;
|
|
1664
|
+
}
|
|
1665
|
+
return false;
|
|
1666
|
+
}
|
|
1667
|
+
function isBottomTabMenuItemActive(item, pathname) {
|
|
1668
|
+
if (navigationPathMatches(item, pathname)) {
|
|
1669
|
+
return true;
|
|
1670
|
+
}
|
|
1671
|
+
return (item.children ?? []).some(
|
|
1672
|
+
(child) => navigationPathMatches(child, pathname) || isBottomTabMenuItemActive(child, pathname)
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1627
1675
|
|
|
1628
1676
|
// src/navigation/navLinks.ts
|
|
1629
1677
|
function getNavigationItemLabel(item) {
|
|
1630
1678
|
return item.label || item.page?.title || item.page?.keyword || "";
|
|
1631
1679
|
}
|
|
1680
|
+
function getNavigationItemAriaLabel(item) {
|
|
1681
|
+
const aria = item.aria_label?.trim();
|
|
1682
|
+
if (aria) {
|
|
1683
|
+
return aria;
|
|
1684
|
+
}
|
|
1685
|
+
const label = getNavigationItemLabel(item);
|
|
1686
|
+
return label || void 0;
|
|
1687
|
+
}
|
|
1632
1688
|
function getNavigationItemHref(item) {
|
|
1633
1689
|
if (item.item_type === "external_url" && item.external_url) {
|
|
1634
1690
|
return item.external_url;
|
|
@@ -1798,7 +1854,8 @@ function haystacksForItem(item) {
|
|
|
1798
1854
|
}
|
|
1799
1855
|
function searchMenuPagesInPayload(payload, query, limit = 8) {
|
|
1800
1856
|
const needle = query.trim().toLowerCase();
|
|
1801
|
-
|
|
1857
|
+
const minChars = payload.search?.min_chars ?? 2;
|
|
1858
|
+
if (needle === "" || needle.length < minChars) {
|
|
1802
1859
|
return [];
|
|
1803
1860
|
}
|
|
1804
1861
|
const hits = [];
|
|
@@ -1830,6 +1887,24 @@ function searchMenuPagesInPayload(payload, query, limit = 8) {
|
|
|
1830
1887
|
return hits;
|
|
1831
1888
|
}
|
|
1832
1889
|
|
|
1890
|
+
// src/navigation/menuDepth.ts
|
|
1891
|
+
function resolveMenuMaxDepth(maxDepth) {
|
|
1892
|
+
if (maxDepth === null || maxDepth === void 0 || maxDepth <= 0) {
|
|
1893
|
+
return null;
|
|
1894
|
+
}
|
|
1895
|
+
return maxDepth;
|
|
1896
|
+
}
|
|
1897
|
+
function clampMenuItemsAtDepth(items, maxDepth, depth = 0) {
|
|
1898
|
+
return items.map((item) => {
|
|
1899
|
+
const atLimit = maxDepth !== null && depth >= maxDepth;
|
|
1900
|
+
const children = item.children ?? [];
|
|
1901
|
+
return {
|
|
1902
|
+
...item,
|
|
1903
|
+
children: atLimit ? [] : clampMenuItemsAtDepth(children, maxDepth, depth + 1)
|
|
1904
|
+
};
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1833
1908
|
// src/utils/spacing.ts
|
|
1834
1909
|
var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
|
|
1835
1910
|
function parseSpacing(raw) {
|
|
@@ -1937,6 +2012,7 @@ export {
|
|
|
1937
2012
|
_resetPluginStyleRegistry,
|
|
1938
2013
|
arePreviewPreferencesEqual,
|
|
1939
2014
|
buildConditionContext,
|
|
2015
|
+
clampMenuItemsAtDepth,
|
|
1940
2016
|
classifyClass,
|
|
1941
2017
|
classifyClassString,
|
|
1942
2018
|
collectPageIdsFromMenuItems,
|
|
@@ -1944,10 +2020,13 @@ export {
|
|
|
1944
2020
|
evaluateCondition,
|
|
1945
2021
|
extendStyleRegistry,
|
|
1946
2022
|
findMenuItemByPageId,
|
|
2023
|
+
findNearestBottomTabMenuItemForPage,
|
|
2024
|
+
findPageRefInNavigationPayload,
|
|
1947
2025
|
findRemap,
|
|
1948
2026
|
flattenMenuItems,
|
|
1949
2027
|
flattenNavigationMenuItems,
|
|
1950
2028
|
getMergedStyleRegistry,
|
|
2029
|
+
getNavigationItemAriaLabel,
|
|
1951
2030
|
getNavigationItemHref,
|
|
1952
2031
|
getNavigationItemKeyword,
|
|
1953
2032
|
getNavigationItemLabel,
|
|
@@ -1959,6 +2038,7 @@ export {
|
|
|
1959
2038
|
getStylePluginId,
|
|
1960
2039
|
gridSpanToReactNativeColumn,
|
|
1961
2040
|
hasInlineFormatting,
|
|
2041
|
+
isBottomTabMenuItemActive,
|
|
1962
2042
|
isKnownStyleName,
|
|
1963
2043
|
isMobileIconName,
|
|
1964
2044
|
isOnAnyMobileMenu,
|
|
@@ -1998,6 +2078,7 @@ export {
|
|
|
1998
2078
|
resolveBranchNavGroup,
|
|
1999
2079
|
resolveHolderRedirectPath,
|
|
2000
2080
|
resolveMantineVariant,
|
|
2081
|
+
resolveMenuMaxDepth,
|
|
2001
2082
|
resolveMobileIcon,
|
|
2002
2083
|
resolveMobilePagePresentation,
|
|
2003
2084
|
resolveMobileSegmentGroup,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.2",
|
|
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",
|
|
@@ -22,12 +22,16 @@ import {
|
|
|
22
22
|
isPageOnMobileMenu,
|
|
23
23
|
isPageOnWebMenu,
|
|
24
24
|
} from '../menuVisibility';
|
|
25
|
+
import { findPageRefInNavigationPayload } from '../menuMembership';
|
|
25
26
|
import {
|
|
27
|
+
findNearestBottomTabMenuItemForPage,
|
|
28
|
+
isBottomTabMenuItemActive,
|
|
26
29
|
resolveHolderRedirectPath,
|
|
27
30
|
resolveMobileSegmentGroup,
|
|
28
31
|
resolveWebBranchNavGroup,
|
|
29
32
|
} from '../branchNav';
|
|
30
33
|
import { searchMenuPagesInPayload } from '../menuSearch';
|
|
34
|
+
import { clampMenuItemsAtDepth, resolveMenuMaxDepth } from '../menuDepth';
|
|
31
35
|
|
|
32
36
|
function menuItem(partial: Partial<INavigationMenuItem>): INavigationMenuItem {
|
|
33
37
|
return {
|
|
@@ -191,4 +195,85 @@ describe('menu search', () => {
|
|
|
191
195
|
expect(hits).toHaveLength(1);
|
|
192
196
|
expect(hits[0]?.keyword).toBe('about');
|
|
193
197
|
});
|
|
198
|
+
|
|
199
|
+
it('honours payload.search.min_chars before returning hits', () => {
|
|
200
|
+
const payload = navigationPayload([
|
|
201
|
+
menuItem({
|
|
202
|
+
id: 1,
|
|
203
|
+
page: { id: 10, keyword: 'about', url: '/about', title: 'About us' },
|
|
204
|
+
}),
|
|
205
|
+
]);
|
|
206
|
+
payload.search.min_chars = 4;
|
|
207
|
+
|
|
208
|
+
expect(searchMenuPagesInPayload(payload, 'abo')).toHaveLength(0);
|
|
209
|
+
expect(searchMenuPagesInPayload(payload, 'about')).toHaveLength(1);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe('page ref lookup', () => {
|
|
214
|
+
it('finds resolved page metadata across menu trees', () => {
|
|
215
|
+
const payload = navigationPayload([
|
|
216
|
+
menuItem({
|
|
217
|
+
id: 1,
|
|
218
|
+
page: { id: 42, keyword: 'team', url: '/team', title: 'Team', has_content: false },
|
|
219
|
+
}),
|
|
220
|
+
]);
|
|
221
|
+
const ref = findPageRefInNavigationPayload(payload, 42);
|
|
222
|
+
expect(ref?.keyword).toBe('team');
|
|
223
|
+
expect(ref?.has_content).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('menu depth helpers', () => {
|
|
228
|
+
it('treats null/zero max depth as unlimited', () => {
|
|
229
|
+
expect(resolveMenuMaxDepth(null)).toBeNull();
|
|
230
|
+
expect(resolveMenuMaxDepth(0)).toBeNull();
|
|
231
|
+
expect(resolveMenuMaxDepth(2)).toBe(2);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('strips nested children beyond max depth', () => {
|
|
235
|
+
const nested = menuItem({
|
|
236
|
+
id: 1,
|
|
237
|
+
children: [
|
|
238
|
+
menuItem({
|
|
239
|
+
id: 2,
|
|
240
|
+
children: [menuItem({ id: 3 })],
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
243
|
+
});
|
|
244
|
+
const clamped = clampMenuItemsAtDepth([nested], 1);
|
|
245
|
+
expect(clamped[0]?.children?.length).toBe(1);
|
|
246
|
+
expect(clamped[0]?.children?.[0]?.children?.length).toBe(0);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('legacy nav-render exports', () => {
|
|
251
|
+
it('does not export removed web/mobile nav render option lists', async () => {
|
|
252
|
+
const mod = await import('../../index');
|
|
253
|
+
expect('WEB_NAV_RENDER_OPTIONS' in mod).toBe(false);
|
|
254
|
+
expect('MOBILE_NAV_RENDER_OPTIONS' in mod).toBe(false);
|
|
255
|
+
expect('TWebNavRender' in mod).toBe(false);
|
|
256
|
+
expect('TMobileNavRender' in mod).toBe(false);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe('bottom tab active state', () => {
|
|
261
|
+
it('marks the nearest ancestor tab active for nested paths', () => {
|
|
262
|
+
const tabs = [
|
|
263
|
+
menuItem({
|
|
264
|
+
id: 1,
|
|
265
|
+
page: { id: 10, keyword: 'team', url: '/team', title: 'Team' },
|
|
266
|
+
children: [
|
|
267
|
+
menuItem({
|
|
268
|
+
id: 2,
|
|
269
|
+
page: { id: 11, keyword: 'alice', url: '/team/alice', title: 'Alice' },
|
|
270
|
+
}),
|
|
271
|
+
],
|
|
272
|
+
}),
|
|
273
|
+
];
|
|
274
|
+
expect(findNearestBottomTabMenuItemForPage(tabs, 11)?.page?.keyword).toBe('team');
|
|
275
|
+
expect(isBottomTabMenuItemActive(tabs[0], '/alice')).toBe(true);
|
|
276
|
+
expect(isBottomTabMenuItemActive(tabs[0], '/team')).toBe(true);
|
|
277
|
+
expect(isBottomTabMenuItemActive(tabs[0], '/other')).toBe(false);
|
|
278
|
+
});
|
|
194
279
|
});
|
|
@@ -214,3 +214,48 @@ export function resolveHolderRedirectPath(
|
|
|
214
214
|
|
|
215
215
|
return target.keyword === 'home' ? '/' : `/${target.keyword}`;
|
|
216
216
|
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Returns the top-level bottom-tab item that owns a nested page, if any.
|
|
220
|
+
*/
|
|
221
|
+
export function findNearestBottomTabMenuItemForPage(
|
|
222
|
+
tabs: INavigationMenuItem[],
|
|
223
|
+
pageId: number,
|
|
224
|
+
): INavigationMenuItem | null {
|
|
225
|
+
for (const tab of tabs) {
|
|
226
|
+
if (tab.page?.id === pageId) {
|
|
227
|
+
return tab;
|
|
228
|
+
}
|
|
229
|
+
if (findMenuItemByPageId(tab.children ?? [], pageId)) {
|
|
230
|
+
return tab;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function navigationPathMatches(item: INavigationMenuItem, pathname: string): boolean {
|
|
238
|
+
const href = pageUrlToMobileRoute(item.page?.url ?? null, item.page?.keyword ?? '');
|
|
239
|
+
if (pathname === href) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
if (href !== '/' && pathname.startsWith(`${href}/`)) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Active state for a flat bottom-tab item, including descendants on the current path.
|
|
251
|
+
*/
|
|
252
|
+
export function isBottomTabMenuItemActive(item: INavigationMenuItem, pathname: string): boolean {
|
|
253
|
+
if (navigationPathMatches(item, pathname)) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return (item.children ?? []).some(
|
|
258
|
+
(child) => navigationPathMatches(child, pathname)
|
|
259
|
+
|| isBottomTabMenuItemActive(child, pathname),
|
|
260
|
+
);
|
|
261
|
+
}
|
package/src/navigation/index.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { INavigationMenuItem } from './navigationPayload';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Normalises menu max_depth: null/undefined/0 means unlimited.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveMenuMaxDepth(maxDepth: number | null | undefined): number | null {
|
|
11
|
+
if (maxDepth === null || maxDepth === undefined || maxDepth <= 0) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return maxDepth;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Strips nested children beyond the configured depth so renderers do not
|
|
20
|
+
* expand deeper levels in dropdown/mega panels.
|
|
21
|
+
*/
|
|
22
|
+
export function clampMenuItemsAtDepth(
|
|
23
|
+
items: INavigationMenuItem[],
|
|
24
|
+
maxDepth: number | null,
|
|
25
|
+
depth = 0,
|
|
26
|
+
): INavigationMenuItem[] {
|
|
27
|
+
return items.map((item) => {
|
|
28
|
+
const atLimit = maxDepth !== null && depth >= maxDepth;
|
|
29
|
+
const children = item.children ?? [];
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
...item,
|
|
33
|
+
children: atLimit ? [] : clampMenuItemsAtDepth(children, maxDepth, depth + 1),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
3
|
SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
*/
|
|
5
|
-
import type { INavigationMenu, INavigationMenuItem, TNavigationMenuKey } from './navigationPayload';
|
|
5
|
+
import type { INavigationMenu, INavigationMenuItem, INavigationPayload, INavigationResolvedPageRef, TNavigationMenuKey } from './navigationPayload';
|
|
6
6
|
|
|
7
7
|
function flattenItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
|
|
8
8
|
const out: INavigationMenuItem[] = [];
|
|
@@ -61,3 +61,29 @@ export function findMenuItemByPageId(
|
|
|
61
61
|
}
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
/** Resolved page metadata from any public menu tree (for holder redirects, etc.). */
|
|
66
|
+
export function findPageRefInNavigationPayload(
|
|
67
|
+
payload: INavigationPayload,
|
|
68
|
+
pageId: number,
|
|
69
|
+
): INavigationResolvedPageRef | null {
|
|
70
|
+
const menuKeys: TNavigationMenuKey[] = [
|
|
71
|
+
'web_header',
|
|
72
|
+
'web_footer',
|
|
73
|
+
'mobile_drawer',
|
|
74
|
+
'mobile_bottom_tabs',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
for (const key of menuKeys) {
|
|
78
|
+
const menu = payload.menus[key];
|
|
79
|
+
if (!menu?.items?.length) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const item = findMenuItemByPageId(menu.items, pageId);
|
|
83
|
+
if (item?.page) {
|
|
84
|
+
return item.page;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
@@ -32,7 +32,8 @@ export function searchMenuPagesInPayload(
|
|
|
32
32
|
limit = 8,
|
|
33
33
|
): IMenuSearchHit[] {
|
|
34
34
|
const needle = query.trim().toLowerCase();
|
|
35
|
-
|
|
35
|
+
const minChars = payload.search?.min_chars ?? 2;
|
|
36
|
+
if (needle === '' || needle.length < minChars) {
|
|
36
37
|
return [];
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -8,6 +8,15 @@ export function getNavigationItemLabel(item: INavigationMenuItem): string {
|
|
|
8
8
|
return item.label || item.page?.title || item.page?.keyword || '';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export function getNavigationItemAriaLabel(item: INavigationMenuItem): string | undefined {
|
|
12
|
+
const aria = item.aria_label?.trim();
|
|
13
|
+
if (aria) {
|
|
14
|
+
return aria;
|
|
15
|
+
}
|
|
16
|
+
const label = getNavigationItemLabel(item);
|
|
17
|
+
return label || undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
export function getNavigationItemHref(item: INavigationMenuItem): string {
|
|
12
21
|
if (item.item_type === 'external_url' && item.external_url) {
|
|
13
22
|
return item.external_url;
|