@selfhelp/shared 1.21.2 → 1.21.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +2 -1
  3. package/dist/index.d.mts +427 -20
  4. package/dist/index.d.ts +427 -20
  5. package/dist/index.js +560 -13
  6. package/dist/index.mjs +518 -13
  7. package/dist/plugin-sdk/index.d.mts +1 -1
  8. package/dist/plugin-sdk/index.d.ts +1 -1
  9. package/dist/plugin-sdk/index.js +2 -1
  10. package/dist/plugin-sdk/index.mjs +2 -1
  11. package/dist/registry/index.d.mts +2 -2
  12. package/dist/registry/index.d.ts +2 -2
  13. package/dist/registry/index.js +2 -1
  14. package/dist/registry/index.mjs +2 -1
  15. package/dist/{styles.registry-DEDEZ8l3.d.ts → styles.registry-DX79oirw.d.ts} +93 -16
  16. package/dist/{styles.registry-DHM4M77N.d.mts → styles.registry-ffw0MH3r.d.mts} +93 -16
  17. package/package.json +1 -1
  18. package/src/content/__tests__/fieldsMapLabels.test.ts +55 -0
  19. package/src/content/__tests__/optionLabels.test.ts +100 -0
  20. package/src/content/fieldsMapLabels.ts +103 -0
  21. package/src/content/index.ts +2 -0
  22. package/src/content/optionLabels.ts +200 -0
  23. package/src/navigation/__tests__/navigation.test.ts +296 -6
  24. package/src/navigation/activeTrail.ts +99 -0
  25. package/src/navigation/branchNav.ts +155 -6
  26. package/src/navigation/footerPreset.ts +109 -0
  27. package/src/navigation/headerLayers.ts +56 -0
  28. package/src/navigation/headerPreset.ts +9 -2
  29. package/src/navigation/index.ts +4 -0
  30. package/src/navigation/menuDepth.ts +73 -37
  31. package/src/navigation/mobileRoute.ts +25 -0
  32. package/src/navigation/navLinks.ts +0 -4
  33. package/src/navigation/navigationBundle.ts +81 -0
  34. package/src/navigation/navigationPayload.ts +96 -17
  35. package/src/registry/__tests__/platform.test.ts +11 -10
  36. package/src/registry/styles.registry.ts +2 -1
  37. package/src/types/__tests__/preview-bridge.test.ts +7 -0
  38. package/src/types/auth.ts +4 -0
  39. package/src/types/cms-app.ts +74 -0
  40. package/src/types/index.ts +1 -0
  41. package/src/types/mobile-adapters.ts +1 -0
  42. package/src/types/pages.ts +6 -0
  43. package/src/types/preview-bridge.ts +12 -1
  44. package/src/types/styles/composite.ts +21 -0
  45. package/src/types/styles/forms.ts +57 -10
  46. package/src/types/styles/interactive.ts +1 -1
  47. package/src/types/styles/unknown.ts +2 -2
@@ -2,7 +2,12 @@
2
2
  SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
- import type { INavigationMenuItem, INavigationPayload } from './navigationPayload';
5
+ import type {
6
+ INavigationMenu,
7
+ INavigationMenuItem,
8
+ INavigationPayload,
9
+ TNavigationChildrenNavMode,
10
+ } from './navigationPayload';
6
11
  import { collectPageIdsFromMenuItems } from './menuMembership';
7
12
  import { pageUrlToMobileRoute } from './mobileRoute';
8
13
 
@@ -28,8 +33,8 @@ function toSegment(item: INavigationMenuItem): IBranchNavSegment | null {
28
33
  keyword: item.page.keyword,
29
34
  url: item.page.url,
30
35
  label: itemLabel(item),
31
- icon: item.icon ?? item.page.icon,
32
- mobile_icon: item.page.mobile_icon,
36
+ icon: item.icon ?? null,
37
+ mobile_icon: item.mobile_icon ?? null,
33
38
  };
34
39
  }
35
40
 
@@ -106,9 +111,9 @@ export function resolveBranchNavGroup(
106
111
  }
107
112
  const located = findParentItem([root], currentPageId);
108
113
  if (located) {
109
- const directChildren = menuVisibleChildItems(
110
- located.parent ?? { id: 0, item_type: 'group', label: '', position: 0, children: located.siblings },
111
- );
114
+ const directChildren = located.parent
115
+ ? menuVisibleChildItems(located.parent)
116
+ : located.siblings.filter((sibling) => sibling.page != null && sibling.is_active !== false);
112
117
  if (located.parent && located.parent.page?.id === currentPageId && directChildren.length > 0) {
113
118
  const segments = directChildren.map(toSegment).filter((s): s is IBranchNavSegment => s != null);
114
119
  return segments.length > 0 ? segments : null;
@@ -163,6 +168,150 @@ export function resolveWebBranchNavGroup(
163
168
  return resolveBranchNavGroup(payload, currentPageId, ['web_header', 'web_footer']);
164
169
  }
165
170
 
171
+ /** One breadcrumb step; group items produce unlinked crumbs (`pageId === null`). */
172
+ export interface IBreadcrumbEntry {
173
+ label: string;
174
+ pageId: number | null;
175
+ keyword: string | null;
176
+ url: string | null;
177
+ }
178
+
179
+ /**
180
+ * Everything a web renderer needs to present the branch of the current page:
181
+ * resolved presentation mode, the sidebar group, breadcrumbs, and the
182
+ * prev/next pager. `null` when the page is a top-level leaf (no branch UI).
183
+ */
184
+ export interface IBranchNavContext {
185
+ /** `sidebar` | `pills` | `none` — parent-item override, else menu default, else `sidebar`. */
186
+ mode: TNavigationChildrenNavMode;
187
+ /** Menu-level toggle for the breadcrumb trail. */
188
+ showBreadcrumbs: boolean;
189
+ /** Prev/next pager — parent-item override, else menu default, else on. */
190
+ showPager: boolean;
191
+ /** Label of the branch parent (page or group), used as the sidebar heading. */
192
+ heading: string | null;
193
+ /** Branch parent as a navigable segment when the parent is a page. */
194
+ parent: IBranchNavSegment | null;
195
+ /** Ordered current-level group: children of the branch parent. */
196
+ segments: IBranchNavSegment[];
197
+ /** Menu path root → current page (current page is the last entry). */
198
+ breadcrumbs: IBreadcrumbEntry[];
199
+ /** Neighbours of the current page inside `segments`. */
200
+ pager: { prev: IBranchNavSegment | null; next: IBranchNavSegment | null };
201
+ }
202
+
203
+ function findMenuItemPath(
204
+ items: INavigationMenuItem[],
205
+ pageId: number,
206
+ trail: INavigationMenuItem[] = [],
207
+ ): INavigationMenuItem[] | null {
208
+ for (const item of items) {
209
+ const nextTrail = [...trail, item];
210
+ if (item.page?.id === pageId) {
211
+ return nextTrail;
212
+ }
213
+ if (item.children?.length) {
214
+ const found = findMenuItemPath(item.children, pageId, nextTrail);
215
+ if (found) {
216
+ return found;
217
+ }
218
+ }
219
+ }
220
+ return null;
221
+ }
222
+
223
+ function toBreadcrumb(item: INavigationMenuItem): IBreadcrumbEntry {
224
+ return {
225
+ label: itemLabel(item),
226
+ pageId: item.page?.id ?? null,
227
+ keyword: item.page?.keyword ?? null,
228
+ url: item.page?.url ?? null,
229
+ };
230
+ }
231
+
232
+ function resolveModeForBranch(
233
+ branchParent: INavigationMenuItem | null,
234
+ menu: INavigationMenu,
235
+ ): TNavigationChildrenNavMode {
236
+ return branchParent?.children_nav ?? menu.children_nav ?? 'sidebar';
237
+ }
238
+
239
+ function resolvePagerForBranch(
240
+ branchParent: INavigationMenuItem | null,
241
+ menu: INavigationMenu,
242
+ ): boolean {
243
+ return branchParent?.show_pager ?? menu.show_pager ?? true;
244
+ }
245
+
246
+ /**
247
+ * Resolve the full branch-navigation context of a web page: which presentation
248
+ * to use (menu default + per-parent override), the sidebar group, breadcrumbs,
249
+ * and prev/next neighbours.
250
+ *
251
+ * - Page with menu-visible children → the page is the branch parent, its
252
+ * children are the group (no pager: the parent is the overview).
253
+ * - Nested page → the parent item owns the branch, the siblings are the group,
254
+ * the pager walks the group.
255
+ * - Top-level leaf → `null` (no generated branch UI).
256
+ */
257
+ export function resolveWebBranchNavContext(
258
+ payload: INavigationPayload,
259
+ currentPageId: number,
260
+ ): IBranchNavContext | null {
261
+ for (const key of ['web_header', 'web_footer'] as const) {
262
+ const menu = payload.menus[key];
263
+ if (!menu?.items?.length) {
264
+ continue;
265
+ }
266
+ const path = findMenuItemPath(menu.items, currentPageId);
267
+ if (!path) {
268
+ continue;
269
+ }
270
+
271
+ const currentItem = path[path.length - 1];
272
+ const ownChildren = menuVisibleChildItems(currentItem);
273
+
274
+ let branchParent: INavigationMenuItem | null = null;
275
+ let group: INavigationMenuItem[];
276
+ if (ownChildren.length > 0) {
277
+ branchParent = currentItem;
278
+ group = ownChildren;
279
+ } else if (path.length >= 2) {
280
+ branchParent = path[path.length - 2];
281
+ group = menuVisibleChildItems(branchParent);
282
+ } else {
283
+ // Top-level leaf: the header already covers this level.
284
+ return null;
285
+ }
286
+
287
+ const segments = group
288
+ .map(toSegment)
289
+ .filter((segment): segment is IBranchNavSegment => segment != null);
290
+ if (segments.length === 0) {
291
+ return null;
292
+ }
293
+
294
+ const currentIndex = segments.findIndex((segment) => segment.pageId === currentPageId);
295
+ const pager = {
296
+ prev: currentIndex > 0 ? segments[currentIndex - 1] : null,
297
+ next: currentIndex >= 0 && currentIndex < segments.length - 1 ? segments[currentIndex + 1] : null,
298
+ };
299
+
300
+ return {
301
+ mode: resolveModeForBranch(branchParent, menu),
302
+ showBreadcrumbs: menu.show_breadcrumbs ?? false,
303
+ showPager: resolvePagerForBranch(branchParent, menu),
304
+ heading: branchParent ? itemLabel(branchParent) : null,
305
+ parent: branchParent ? toSegment(branchParent) : null,
306
+ segments,
307
+ breadcrumbs: path.map(toBreadcrumb),
308
+ pager,
309
+ };
310
+ }
311
+
312
+ return null;
313
+ }
314
+
166
315
  export type TMobilePagePresentation = 'route' | 'modal';
167
316
 
168
317
  export function resolveMobilePagePresentation(
@@ -0,0 +1,109 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Global web footer presentation presets (menu-builder `web_footer` menu).
7
+ *
8
+ * Footer layout uses the same preset mechanism as the web header: the value is
9
+ * stored on `navigation_menus.id_preset` and switching presets never mutates
10
+ * menu items — `inline` flattens groups at render time only, so switching back
11
+ * to `columns` restores the exact same groups.
12
+ */
13
+ import type { INavigationMenuItem } from './navigationPayload';
14
+
15
+ export type TWebFooterPreset = 'columns' | 'inline';
16
+
17
+ export const WEB_FOOTER_PRESET_VALUES: readonly TWebFooterPreset[] = [
18
+ 'columns',
19
+ 'inline',
20
+ ] as const;
21
+
22
+ export const DEFAULT_WEB_FOOTER_PRESET: TWebFooterPreset = 'columns';
23
+
24
+ export interface IWebFooterPresetOption {
25
+ value: TWebFooterPreset;
26
+ label: string;
27
+ description: string;
28
+ }
29
+
30
+ export const WEB_FOOTER_PRESET_OPTIONS: readonly IWebFooterPresetOption[] = [
31
+ {
32
+ value: 'columns',
33
+ label: 'Columns (grouped)',
34
+ description: 'Group headings become footer columns with their links below.',
35
+ },
36
+ {
37
+ value: 'inline',
38
+ label: 'Inline links',
39
+ description: 'One flat centered link row; group links are shown inline, headings hidden. Groups are kept and restored when switching back.',
40
+ },
41
+ ] as const;
42
+
43
+ export function isWebFooterPreset(value: unknown): value is TWebFooterPreset {
44
+ return typeof value === 'string' && (WEB_FOOTER_PRESET_VALUES as readonly string[]).includes(value);
45
+ }
46
+
47
+ export function resolveWebFooterPreset(
48
+ value: unknown,
49
+ fallback: TWebFooterPreset = DEFAULT_WEB_FOOTER_PRESET,
50
+ ): TWebFooterPreset {
51
+ return isWebFooterPreset(value) ? value : fallback;
52
+ }
53
+
54
+ function isRenderableFooterLeaf(item: INavigationMenuItem): boolean {
55
+ if (!item.is_active) {
56
+ return false;
57
+ }
58
+ if (item.item_type === 'external_url') {
59
+ return item.external_url != null && item.external_url !== '';
60
+ }
61
+ return item.item_type === 'page' && item.page != null;
62
+ }
63
+
64
+ /**
65
+ * Flatten a footer tree for the `inline` preset: active page/external links are
66
+ * kept in order, group children are promoted in place of their heading, and
67
+ * inactive items or empty groups are dropped. Data is never mutated.
68
+ */
69
+ export function flattenFooterItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
70
+ const out: INavigationMenuItem[] = [];
71
+ for (const item of items) {
72
+ if (!item.is_active) {
73
+ continue;
74
+ }
75
+ if (item.item_type === 'group') {
76
+ out.push(...flattenFooterItems(item.children));
77
+ continue;
78
+ }
79
+ if (isRenderableFooterLeaf(item)) {
80
+ out.push(item);
81
+ // Non-group items may still carry nested links; promote them too.
82
+ out.push(...flattenFooterItems(item.children));
83
+ }
84
+ }
85
+ return out;
86
+ }
87
+
88
+ /**
89
+ * Footer columns for the `columns` preset: top-level groups that contain at
90
+ * least one renderable link. Standalone (non-group) top-level links are not
91
+ * columns — render them separately via {@link footerStandaloneItems}.
92
+ */
93
+ export function footerColumnItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
94
+ return items.filter(
95
+ (item) => item.is_active
96
+ && item.item_type === 'group'
97
+ && item.children.some(isRenderableFooterLeaf),
98
+ );
99
+ }
100
+
101
+ /** Active top-level non-group links (rendered as a trailing meta row in `columns` mode). */
102
+ export function footerStandaloneItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
103
+ return items.filter((item) => item.item_type !== 'group' && isRenderableFooterLeaf(item));
104
+ }
105
+
106
+ /** Renderable links inside one footer column/group. */
107
+ export function footerGroupLinks(group: INavigationMenuItem): INavigationMenuItem[] {
108
+ return group.children.filter(isRenderableFooterLeaf);
109
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Web header layer helpers for double-header presets.
7
+ *
8
+ * `web_header` root items carry `layer: 'top' | null` (`null` = main row).
9
+ * Double presets render two rows; single presets ignore the layer and merge
10
+ * every root item into one row. Layer assignments are data, never destroyed by
11
+ * switching presets — switching back to a double preset restores the split.
12
+ */
13
+ import type { INavigationMenuItem, TNavigationHeaderLayer } from './navigationPayload';
14
+
15
+ export const NAVIGATION_HEADER_LAYER_TOP: TNavigationHeaderLayer = 'top';
16
+
17
+ export interface IHeaderLayerSplit {
18
+ /** Flat links for the top utility row (double presets only). */
19
+ top: INavigationMenuItem[];
20
+ /** Main navigation row items (preset-specific children rendering). */
21
+ main: INavigationMenuItem[];
22
+ }
23
+
24
+ function byPosition(a: INavigationMenuItem, b: INavigationMenuItem): number {
25
+ return a.position - b.position || a.id - b.id;
26
+ }
27
+
28
+ /**
29
+ * Split root header items into top and main rows for double presets.
30
+ * Top-row items are rendered as flat links; their children are ignored by design.
31
+ */
32
+ export function splitHeaderLayers(items: INavigationMenuItem[]): IHeaderLayerSplit {
33
+ const top: INavigationMenuItem[] = [];
34
+ const main: INavigationMenuItem[] = [];
35
+ for (const item of items) {
36
+ if (item.layer === NAVIGATION_HEADER_LAYER_TOP) {
37
+ top.push(item);
38
+ } else {
39
+ main.push(item);
40
+ }
41
+ }
42
+ top.sort(byPosition);
43
+ main.sort(byPosition);
44
+ return { top, main };
45
+ }
46
+
47
+ /**
48
+ * Merge root header items into one ordered row for single-layer presets:
49
+ * main-row items first (position order), then top-row items appended
50
+ * (position order). Deterministic and non-destructive — `layer` values stay
51
+ * on the items so switching back to a double preset restores the split.
52
+ */
53
+ export function mergeHeaderLayers(items: INavigationMenuItem[]): INavigationMenuItem[] {
54
+ const { top, main } = splitHeaderLayers(items);
55
+ return [...main, ...top];
56
+ }
@@ -36,14 +36,21 @@ export const WEB_HEADER_PRESET_OPTIONS: readonly IWebHeaderPresetOption[] = [
36
36
  { value: 'dropdown', label: 'Dropdown', description: 'Default — nested dropdown menus.' },
37
37
  { value: 'mega-menu', label: 'Mega menu', description: 'Rich sections with descriptions and icons.' },
38
38
  { value: 'tabs', label: 'Tabs', description: 'Top-level sections as tabs.' },
39
- { value: 'double-dropdown', label: 'Double header (dropdown)', description: 'Utility row plus main dropdown nav.' },
40
- { value: 'double-mega-menu', label: 'Double header (mega menu)', description: 'Utility row plus mega menu.' },
39
+ { value: 'double-dropdown', label: 'Double header (dropdown)', description: 'Top row with flat links and utilities above the main dropdown nav.' },
40
+ { value: 'double-mega-menu', label: 'Double header (mega menu)', description: 'Top row with flat links and utilities above the mega menu.' },
41
41
  ] as const;
42
42
 
43
+ const DOUBLE_WEB_HEADER_PRESETS: readonly TWebHeaderPreset[] = ['double-dropdown', 'double-mega-menu'];
44
+
43
45
  export function isWebHeaderPreset(value: unknown): value is TWebHeaderPreset {
44
46
  return typeof value === 'string' && (WEB_HEADER_PRESET_VALUES as readonly string[]).includes(value);
45
47
  }
46
48
 
49
+ /** True for presets that render the two-row (top layer + main layer) header. */
50
+ export function isDoubleWebHeaderPreset(value: unknown): boolean {
51
+ return isWebHeaderPreset(value) && (DOUBLE_WEB_HEADER_PRESETS as readonly string[]).includes(value);
52
+ }
53
+
47
54
  export function resolveWebHeaderPreset(
48
55
  value: unknown,
49
56
  fallback: TWebHeaderPreset = DEFAULT_WEB_HEADER_PRESET,
@@ -3,7 +3,10 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  export * from './headerPreset';
6
+ export * from './footerPreset';
7
+ export * from './headerLayers';
6
8
  export * from './navigationPayload';
9
+ export * from './navigationBundle';
7
10
  export * from './menuMembership';
8
11
  export * from './branchNav';
9
12
  export * from './navLinks';
@@ -13,3 +16,4 @@ export * from './mobileIcons';
13
16
  export * from './startup';
14
17
  export * from './menuSearch';
15
18
  export * from './menuDepth';
19
+ export * from './activeTrail';
@@ -1,37 +1,73 @@
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
-
1
+ /*
2
+
3
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
4
+
5
+ SPDX-License-Identifier: MPL-2.0
6
+
7
+ */
8
+
9
+ import type { INavigationMenuItem } from './navigationPayload';
10
+
11
+
12
+
13
+ /**
14
+
15
+ * Normalises menu max_depth: null/undefined/0 means unlimited.
16
+
17
+ */
18
+
19
+ export function resolveMenuMaxDepth(maxDepth: number | null | undefined): number | null {
20
+
21
+ if (maxDepth === null || maxDepth === undefined || maxDepth <= 0) {
22
+
23
+ return null;
24
+
25
+ }
26
+
27
+
28
+
29
+ return maxDepth;
30
+
31
+ }
32
+
33
+
34
+
35
+ /**
36
+
37
+ * Strips nested children beyond the configured depth so renderers do not
38
+
39
+ * expand deeper levels in dropdown/mega panels.
40
+
41
+ */
42
+
43
+ export function clampMenuItemsAtDepth(
44
+
45
+ items: INavigationMenuItem[],
46
+
47
+ maxDepth: number | null,
48
+
49
+ depth = 0,
50
+
51
+ ): INavigationMenuItem[] {
52
+
53
+ return items.map((item) => {
54
+
55
+ const atLimit = maxDepth !== null && depth >= maxDepth;
56
+
57
+ const children = item.children ?? [];
58
+
59
+
60
+
61
+ return {
62
+
63
+ ...item,
64
+
65
+ children: atLimit ? [] : clampMenuItemsAtDepth(children, maxDepth, depth + 1),
66
+
67
+ };
68
+
69
+ });
70
+
71
+ }
72
+
73
+
@@ -8,6 +8,31 @@ SPDX-License-Identifier: MPL-2.0
8
8
  * Wave 1 uses keyword-based routes (`[keyword].tsx`), not file `[...slug]`
9
9
  * segments. Nested public URLs (`/parent/child`) still navigate by keyword.
10
10
  */
11
+ /**
12
+ * Substitute `{param}` placeholders in a CMS page URL template using route
13
+ * params (snake_case keys). Returns null when the template or params are
14
+ * incomplete.
15
+ */
16
+ export function buildPublicPathFromRoute(
17
+ urlTemplate: string | null | undefined,
18
+ routeParams: Record<string, string | undefined>,
19
+ ): string | null {
20
+ if (!urlTemplate || !urlTemplate.includes('{')) {
21
+ return null;
22
+ }
23
+ let path = urlTemplate;
24
+ for (const [key, value] of Object.entries(routeParams)) {
25
+ if (value === undefined || value === '') {
26
+ continue;
27
+ }
28
+ path = path.replaceAll(`{${key}}`, value);
29
+ }
30
+ if (path.includes('{')) {
31
+ return null;
32
+ }
33
+ return path.replace(/\/+$/, '') || '/';
34
+ }
35
+
11
36
  export function pageUrlToMobileRoute(url: string | null | undefined, keyword: string): string {
12
37
  const normalizedKeyword = keyword.trim().toLowerCase();
13
38
  if (normalizedKeyword === 'profile') {
@@ -9,10 +9,6 @@ export function getNavigationItemLabel(item: INavigationMenuItem): string {
9
9
  }
10
10
 
11
11
  export function getNavigationItemAriaLabel(item: INavigationMenuItem): string | undefined {
12
- const aria = item.aria_label?.trim();
13
- if (aria) {
14
- return aria;
15
- }
16
12
  const label = getNavigationItemLabel(item);
17
13
  return label || undefined;
18
14
  }
@@ -0,0 +1,81 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * `selfhelp/navigation-bundle` v2.0 — the only supported navigation bundle
7
+ * schema. Bundles are an authoring/transfer format: optional keys mean "not
8
+ * set" (unlike the strict runtime payload where every key is present).
9
+ *
10
+ * v2.0 replaces v1.0 entirely: menu `config` is gone (footer layout is a
11
+ * preset), items carry `layer`, and translations use `aria_label` (the legacy
12
+ * `n` key is not accepted). Imports reject any other version.
13
+ */
14
+ import type {
15
+ TNavigationHeaderLayer,
16
+ TNavigationMenuItemType,
17
+ TNavigationMenuKey,
18
+ } from './navigationPayload';
19
+
20
+ export const NAVIGATION_BUNDLE_FORMAT = 'selfhelp/navigation-bundle';
21
+ export const NAVIGATION_BUNDLE_VERSION = '2.0';
22
+
23
+ export interface INavigationBundleItemTranslation {
24
+ locale: string;
25
+ label: string;
26
+ description?: string | null;
27
+ aria_label?: string | null;
28
+ }
29
+
30
+ export interface INavigationBundleItem {
31
+ /** Stable in-bundle reference used by children via `parent_ref`. */
32
+ ref: string;
33
+ parent_ref: string | null;
34
+ item_type: TNavigationMenuItemType;
35
+ position: number;
36
+ is_active?: boolean;
37
+ /** Top header row assignment (`web_header` root items only). */
38
+ layer?: TNavigationHeaderLayer | null;
39
+ /** Page items: target page keyword (resolved on import). */
40
+ page_keyword?: string | null;
41
+ /** External items: absolute URL. */
42
+ external_url?: string | null;
43
+ icon?: string | null;
44
+ mobile_icon?: string | null;
45
+ /** Default-language label cache for group/external items. */
46
+ label?: string | null;
47
+ translations?: INavigationBundleItemTranslation[];
48
+ }
49
+
50
+ export interface INavigationBundleMenu {
51
+ preset?: string | null;
52
+ max_depth?: number | null;
53
+ item_limit?: number | null;
54
+ items: INavigationBundleItem[];
55
+ }
56
+
57
+ export type TNavigationBundleExportMode = 'full_snapshot' | 'branch';
58
+
59
+ export interface INavigationBundleImportHints {
60
+ default_keyword_prefix?: string;
61
+ default_route_prefix?: string;
62
+ }
63
+
64
+ export interface INavigationBundle {
65
+ format: typeof NAVIGATION_BUNDLE_FORMAT;
66
+ version: string;
67
+ title?: string;
68
+ description?: string;
69
+ min_core_version?: string;
70
+ exported_at?: string;
71
+ core_version?: string;
72
+ export_mode?: TNavigationBundleExportMode;
73
+ import_hints?: INavigationBundleImportHints;
74
+ menus: Partial<Record<TNavigationMenuKey, INavigationBundleMenu>>;
75
+ /** Optional embedded `selfhelp/page-bundle` pages payload. */
76
+ pages?: unknown[];
77
+ }
78
+
79
+ export function isNavigationBundleVersionSupported(version: unknown): boolean {
80
+ return version === NAVIGATION_BUNDLE_VERSION;
81
+ }