@selfhelp/shared 1.20.0 → 1.21.1
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 +23 -0
- package/dist/index.d.mts +168 -108
- package/dist/index.d.ts +168 -108
- package/dist/index.js +476 -107
- package/dist/index.mjs +444 -92
- package/package.json +1 -1
- package/src/api/endpoints.ts +8 -0
- package/src/navigation/__tests__/navigation.test.ts +217 -68
- package/src/navigation/__tests__/startup.test.ts +33 -0
- package/src/navigation/branchNav.ts +261 -0
- package/src/navigation/headerPreset.ts +52 -0
- package/src/navigation/index.ts +9 -7
- package/src/navigation/menuMembership.ts +89 -0
- package/src/navigation/menuSearch.ts +69 -0
- package/src/navigation/menuVisibility.ts +24 -25
- package/src/navigation/mobileRoute.ts +20 -0
- package/src/navigation/navLinks.ts +38 -0
- package/src/navigation/navigationPayload.ts +84 -0
- package/src/navigation/startup.ts +87 -0
- package/src/types/api/__tests__/page-routing.test.ts +0 -6
- package/src/types/pages.ts +0 -13
- package/src/utils/__tests__/transformPageData.test.ts +3 -19
- package/src/utils/transformPageData.ts +1 -37
- package/src/navigation/navRender.ts +0 -132
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { INavigationMenu, INavigationMenuItem, INavigationPayload, INavigationResolvedPageRef, TNavigationMenuKey } from './navigationPayload';
|
|
6
|
+
|
|
7
|
+
function flattenItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
|
|
8
|
+
const out: INavigationMenuItem[] = [];
|
|
9
|
+
for (const item of items) {
|
|
10
|
+
out.push(item);
|
|
11
|
+
if (item.children?.length) {
|
|
12
|
+
out.push(...flattenItems(item.children));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function collectPageIdsFromMenuItems(items: INavigationMenuItem[]): Set<number> {
|
|
19
|
+
const ids = new Set<number>();
|
|
20
|
+
for (const item of flattenItems(items)) {
|
|
21
|
+
if (item.page?.id != null) {
|
|
22
|
+
ids.add(item.page.id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return ids;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isPageInMenuTree(items: INavigationMenuItem[], pageId: number): boolean {
|
|
29
|
+
return collectPageIdsFromMenuItems(items).has(pageId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isPageInResolvedMenus(
|
|
33
|
+
menus: Partial<Record<TNavigationMenuKey, INavigationMenu>>,
|
|
34
|
+
menuKeys: TNavigationMenuKey[],
|
|
35
|
+
pageId: number,
|
|
36
|
+
): boolean {
|
|
37
|
+
for (const key of menuKeys) {
|
|
38
|
+
const menu = menus[key];
|
|
39
|
+
if (menu && isPageInMenuTree(menu.items, pageId)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function isOnAnyMobileMenu(
|
|
47
|
+
menus: Partial<Record<TNavigationMenuKey, INavigationMenu>>,
|
|
48
|
+
pageId: number,
|
|
49
|
+
): boolean {
|
|
50
|
+
return isPageInResolvedMenus(menus, ['mobile_drawer', 'mobile_bottom_tabs'], pageId);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function findMenuItemByPageId(
|
|
54
|
+
items: INavigationMenuItem[],
|
|
55
|
+
pageId: number,
|
|
56
|
+
): INavigationMenuItem | null {
|
|
57
|
+
for (const item of flattenItems(items)) {
|
|
58
|
+
if (item.page?.id === pageId) {
|
|
59
|
+
return item;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
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
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { INavigationMenuItem, INavigationPayload } from './navigationPayload';
|
|
6
|
+
import { flattenMenuItems } from './menuVisibility';
|
|
7
|
+
import { getNavigationItemHref, getNavigationItemLabel } from './navLinks';
|
|
8
|
+
|
|
9
|
+
export interface IMenuSearchHit {
|
|
10
|
+
page_id: number;
|
|
11
|
+
keyword: string;
|
|
12
|
+
url: string | null;
|
|
13
|
+
title: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function haystacksForItem(item: INavigationMenuItem): string[] {
|
|
17
|
+
const page = item.page;
|
|
18
|
+
const label = getNavigationItemLabel(item);
|
|
19
|
+
const values = [label];
|
|
20
|
+
if (page) {
|
|
21
|
+
values.push(page.title ?? '', page.keyword ?? '', page.url ?? '');
|
|
22
|
+
}
|
|
23
|
+
return values.map((value) => value.trim().toLowerCase()).filter((value) => value !== '');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Client-side search over resolved menu trees (`menu_pages` search mode).
|
|
28
|
+
*/
|
|
29
|
+
export function searchMenuPagesInPayload(
|
|
30
|
+
payload: INavigationPayload,
|
|
31
|
+
query: string,
|
|
32
|
+
limit = 8,
|
|
33
|
+
): IMenuSearchHit[] {
|
|
34
|
+
const needle = query.trim().toLowerCase();
|
|
35
|
+
const minChars = payload.search?.min_chars ?? 2;
|
|
36
|
+
if (needle === '' || needle.length < minChars) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const hits: IMenuSearchHit[] = [];
|
|
41
|
+
const seen = new Set<number>();
|
|
42
|
+
|
|
43
|
+
for (const menu of Object.values(payload.menus)) {
|
|
44
|
+
if (!menu?.items?.length) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
for (const item of flattenMenuItems(menu.items)) {
|
|
48
|
+
if (!item.page || seen.has(item.page.id)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const matched = haystacksForItem(item).some((haystack) => haystack.includes(needle));
|
|
52
|
+
if (!matched) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
seen.add(item.page.id);
|
|
56
|
+
hits.push({
|
|
57
|
+
page_id: item.page.id,
|
|
58
|
+
keyword: item.page.keyword,
|
|
59
|
+
url: getNavigationItemHref(item),
|
|
60
|
+
title: getNavigationItemLabel(item),
|
|
61
|
+
});
|
|
62
|
+
if (hits.length >= limit) {
|
|
63
|
+
return hits;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return hits;
|
|
69
|
+
}
|
|
@@ -3,36 +3,35 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
|
3
3
|
SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* renderers AND by the automatic virtual-navigation decision. A page is on the
|
|
8
|
-
* menu when the author placed it there (`navPosition != null`) and it is not a
|
|
9
|
-
* headless content-only fragment.
|
|
10
|
-
*
|
|
11
|
-
* Footer-only pages (`footerPosition != null && navPosition == null`), headless
|
|
12
|
-
* pages, and ACL-pruned pages (never in the tree to begin with) are NOT menu
|
|
13
|
-
* pages, so they never appear in a navigation block.
|
|
6
|
+
* Menu visibility helpers for the menu-builder model.
|
|
14
7
|
*/
|
|
15
8
|
|
|
16
|
-
import type {
|
|
9
|
+
import type { INavigationMenuItem, INavigationPayload, TNavigationMenuKey } from './navigationPayload';
|
|
10
|
+
import { isPageInResolvedMenus } from './menuMembership';
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
const WEB_MENU_KEYS: TNavigationMenuKey[] = ['web_header', 'web_footer'];
|
|
13
|
+
const MOBILE_MENU_KEYS: TNavigationMenuKey[] = ['mobile_drawer', 'mobile_bottom_tabs'];
|
|
14
|
+
const ALL_MENU_KEYS: TNavigationMenuKey[] = [...WEB_MENU_KEYS, ...MOBILE_MENU_KEYS];
|
|
15
|
+
|
|
16
|
+
export function isPageOnAnyMenu(payload: INavigationPayload, pageId: number): boolean {
|
|
17
|
+
return isPageInResolvedMenus(payload.menus, ALL_MENU_KEYS, pageId);
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const children = page.children ?? [];
|
|
26
|
-
return children
|
|
27
|
-
.filter(isMenuVisible)
|
|
28
|
-
.sort((a, b) => (a.navPosition ?? 0) - (b.navPosition ?? 0));
|
|
20
|
+
export function isPageOnWebMenu(payload: INavigationPayload, pageId: number): boolean {
|
|
21
|
+
return isPageInResolvedMenus(payload.menus, WEB_MENU_KEYS, pageId);
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
export function isPageOnMobileMenu(payload: INavigationPayload, pageId: number): boolean {
|
|
25
|
+
return isPageInResolvedMenus(payload.menus, MOBILE_MENU_KEYS, pageId);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function flattenMenuItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
|
|
29
|
+
const out: INavigationMenuItem[] = [];
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
out.push(item);
|
|
32
|
+
if (item.children?.length) {
|
|
33
|
+
out.push(...flattenMenuItems(item.children));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
38
37
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Map a CMS page canonical URL + keyword to an Expo Router path.
|
|
7
|
+
*
|
|
8
|
+
* Wave 1 uses keyword-based routes (`[keyword].tsx`), not file `[...slug]`
|
|
9
|
+
* segments. Nested public URLs (`/parent/child`) still navigate by keyword.
|
|
10
|
+
*/
|
|
11
|
+
export function pageUrlToMobileRoute(url: string | null | undefined, keyword: string): string {
|
|
12
|
+
const normalizedKeyword = keyword.trim().toLowerCase();
|
|
13
|
+
if (normalizedKeyword === 'profile') {
|
|
14
|
+
return '/profile';
|
|
15
|
+
}
|
|
16
|
+
if (normalizedKeyword === 'home' || url === '/' || url === '' || url == null) {
|
|
17
|
+
return '/index';
|
|
18
|
+
}
|
|
19
|
+
return `/${normalizedKeyword}`;
|
|
20
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
export function getNavigationItemLabel(item: INavigationMenuItem): string {
|
|
8
|
+
return item.label || item.page?.title || item.page?.keyword || '';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getNavigationItemHref(item: INavigationMenuItem): string {
|
|
12
|
+
if (item.item_type === 'external_url' && item.external_url) {
|
|
13
|
+
return item.external_url;
|
|
14
|
+
}
|
|
15
|
+
const page = item.page;
|
|
16
|
+
if (!page) {
|
|
17
|
+
return '#';
|
|
18
|
+
}
|
|
19
|
+
if (page.url) {
|
|
20
|
+
return page.url;
|
|
21
|
+
}
|
|
22
|
+
return page.keyword === 'home' ? '/' : `/${page.keyword}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function flattenNavigationMenuItems(items: INavigationMenuItem[]): INavigationMenuItem[] {
|
|
26
|
+
const out: INavigationMenuItem[] = [];
|
|
27
|
+
for (const item of items) {
|
|
28
|
+
out.push(item);
|
|
29
|
+
if (item.children?.length) {
|
|
30
|
+
out.push(...flattenNavigationMenuItems(item.children));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getNavigationItemKeyword(item: INavigationMenuItem): string | null {
|
|
37
|
+
return item.page?.keyword ?? null;
|
|
38
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { TWebHeaderPreset } from './headerPreset';
|
|
6
|
+
|
|
7
|
+
export type TNavigationMenuKey =
|
|
8
|
+
| 'web_header'
|
|
9
|
+
| 'web_footer'
|
|
10
|
+
| 'mobile_drawer'
|
|
11
|
+
| 'mobile_bottom_tabs';
|
|
12
|
+
|
|
13
|
+
export type TNavigationMenuItemType = 'page' | 'external_url' | 'group';
|
|
14
|
+
|
|
15
|
+
export type TNavigationChildSource = 'manual' | 'page_children' | 'manual_plus_suggestions';
|
|
16
|
+
|
|
17
|
+
export type TNavigationSearchMode = 'off' | 'menu_pages' | 'searchable_pages' | 'content_index';
|
|
18
|
+
|
|
19
|
+
export type TNavigationStartMode = 'fixed_page' | 'last_visited_then_fixed_page';
|
|
20
|
+
|
|
21
|
+
export type TNavigationMobileStartSource = 'same_as_web' | 'custom_mobile_pages';
|
|
22
|
+
|
|
23
|
+
export interface INavigationResolvedPageRef {
|
|
24
|
+
id: number;
|
|
25
|
+
keyword: string;
|
|
26
|
+
url: string | null;
|
|
27
|
+
title: string | null;
|
|
28
|
+
icon?: string | null;
|
|
29
|
+
mobile_icon?: string | null;
|
|
30
|
+
has_content?: boolean;
|
|
31
|
+
section_count?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface INavigationMenuItem {
|
|
35
|
+
id: number | string;
|
|
36
|
+
item_type: TNavigationMenuItemType;
|
|
37
|
+
label: string;
|
|
38
|
+
description?: string | null;
|
|
39
|
+
aria_label?: string | null;
|
|
40
|
+
icon?: string | null;
|
|
41
|
+
position: number;
|
|
42
|
+
external_url?: string | null;
|
|
43
|
+
page?: INavigationResolvedPageRef | null;
|
|
44
|
+
is_virtual?: boolean;
|
|
45
|
+
is_active?: boolean;
|
|
46
|
+
child_source?: TNavigationChildSource;
|
|
47
|
+
children?: INavigationMenuItem[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface INavigationMenu {
|
|
51
|
+
key: TNavigationMenuKey;
|
|
52
|
+
platform: 'web' | 'mobile';
|
|
53
|
+
surface: 'header' | 'footer' | 'drawer' | 'bottom_tabs';
|
|
54
|
+
preset?: TWebHeaderPreset | string | null;
|
|
55
|
+
max_depth?: number | null;
|
|
56
|
+
item_limit?: number | null;
|
|
57
|
+
items: INavigationMenuItem[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface INavigationStartupConfig {
|
|
61
|
+
web_guest_start_page: INavigationResolvedPageRef | null;
|
|
62
|
+
web_user_start_page: INavigationResolvedPageRef | null;
|
|
63
|
+
web_user_start_mode: TNavigationStartMode;
|
|
64
|
+
web_user_last_visited_page?: INavigationResolvedPageRef | null;
|
|
65
|
+
mobile_guest_start_page: INavigationResolvedPageRef | null;
|
|
66
|
+
mobile_user_start_page: INavigationResolvedPageRef | null;
|
|
67
|
+
mobile_user_start_mode: TNavigationStartMode;
|
|
68
|
+
mobile_user_last_visited_page?: INavigationResolvedPageRef | null;
|
|
69
|
+
mobile_start_page_source: TNavigationMobileStartSource;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface INavigationSearchConfig {
|
|
73
|
+
mode: TNavigationSearchMode;
|
|
74
|
+
min_chars: number;
|
|
75
|
+
result_limit: number;
|
|
76
|
+
default_visibility: string;
|
|
77
|
+
field_policy: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface INavigationPayload {
|
|
81
|
+
menus: Record<TNavigationMenuKey, INavigationMenu>;
|
|
82
|
+
startup: INavigationStartupConfig;
|
|
83
|
+
search: INavigationSearchConfig;
|
|
84
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { INavigationResolvedPageRef, INavigationStartupConfig } from './navigationPayload';
|
|
6
|
+
import { pageUrlToMobileRoute } from './mobileRoute';
|
|
7
|
+
|
|
8
|
+
function pickStartPage(
|
|
9
|
+
startup: INavigationStartupConfig,
|
|
10
|
+
isLoggedIn: boolean,
|
|
11
|
+
platform: 'web' | 'mobile',
|
|
12
|
+
): INavigationResolvedPageRef | null {
|
|
13
|
+
const useMobileCustom = startup.mobile_start_page_source === 'custom_mobile_pages';
|
|
14
|
+
|
|
15
|
+
if (isLoggedIn) {
|
|
16
|
+
const lastVisited = platform === 'mobile'
|
|
17
|
+
? startup.mobile_user_last_visited_page
|
|
18
|
+
: startup.web_user_last_visited_page;
|
|
19
|
+
const startMode = platform === 'mobile'
|
|
20
|
+
? startup.mobile_user_start_mode
|
|
21
|
+
: startup.web_user_start_mode;
|
|
22
|
+
|
|
23
|
+
if (startMode === 'last_visited_then_fixed_page' && lastVisited) {
|
|
24
|
+
return lastVisited;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (platform === 'mobile' && useMobileCustom) {
|
|
28
|
+
return startup.mobile_user_start_page;
|
|
29
|
+
}
|
|
30
|
+
if (platform === 'mobile') {
|
|
31
|
+
return startup.mobile_user_start_page ?? startup.web_user_start_page;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return startup.web_user_start_page;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (platform === 'mobile' && useMobileCustom) {
|
|
38
|
+
return startup.mobile_guest_start_page;
|
|
39
|
+
}
|
|
40
|
+
if (platform === 'mobile') {
|
|
41
|
+
return startup.mobile_guest_start_page ?? startup.web_guest_start_page;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return startup.web_guest_start_page;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Resolve the mobile Expo Router path for cold start / index redirect. */
|
|
48
|
+
export function resolveMobileStartupRoute(
|
|
49
|
+
startup: INavigationStartupConfig,
|
|
50
|
+
isLoggedIn: boolean,
|
|
51
|
+
): string {
|
|
52
|
+
const page = pickStartPage(startup, isLoggedIn, 'mobile');
|
|
53
|
+
if (!page) {
|
|
54
|
+
return '/index';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return pageUrlToMobileRoute(page.url, page.keyword);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Keyword for the CMS page rendered on `/index` when startup maps to home. */
|
|
61
|
+
export function resolveMobileStartupKeyword(
|
|
62
|
+
startup: INavigationStartupConfig,
|
|
63
|
+
isLoggedIn: boolean,
|
|
64
|
+
): string {
|
|
65
|
+
const page = pickStartPage(startup, isLoggedIn, 'mobile');
|
|
66
|
+
|
|
67
|
+
return page?.keyword ?? 'home';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Resolve a public web path for guest/user startup (leading slash). */
|
|
71
|
+
export function resolveWebStartupPath(
|
|
72
|
+
startup: INavigationStartupConfig,
|
|
73
|
+
isLoggedIn: boolean,
|
|
74
|
+
): string | null {
|
|
75
|
+
const page = pickStartPage(startup, isLoggedIn, 'web');
|
|
76
|
+
if (!page) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (page.url && page.url !== '') {
|
|
80
|
+
return page.url.startsWith('/') ? page.url : `/${page.url}`;
|
|
81
|
+
}
|
|
82
|
+
if (page.keyword === 'home') {
|
|
83
|
+
return '/';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return `/${page.keyword}`;
|
|
87
|
+
}
|
|
@@ -23,8 +23,6 @@ describe('IPageContent route metadata (resolve responses)', () => {
|
|
|
23
23
|
url: '/reset',
|
|
24
24
|
parent_page_id: null,
|
|
25
25
|
is_headless: true,
|
|
26
|
-
nav_position: null,
|
|
27
|
-
footer_position: null,
|
|
28
26
|
route_params: { user_id: '42', token: 'abc.def~1' },
|
|
29
27
|
matched_url_pattern: '/reset/{user_id}/{token}',
|
|
30
28
|
canonical_url: '/reset',
|
|
@@ -44,8 +42,6 @@ describe('IPageContent route metadata (resolve responses)', () => {
|
|
|
44
42
|
url: '/',
|
|
45
43
|
parent_page_id: null,
|
|
46
44
|
is_headless: false,
|
|
47
|
-
nav_position: 1,
|
|
48
|
-
footer_position: null,
|
|
49
45
|
sections: [],
|
|
50
46
|
};
|
|
51
47
|
|
|
@@ -67,8 +63,6 @@ describe('IPageContent route metadata (resolve responses)', () => {
|
|
|
67
63
|
url: '/team/7',
|
|
68
64
|
parent_page_id: null,
|
|
69
65
|
is_headless: false,
|
|
70
|
-
nav_position: null,
|
|
71
|
-
footer_position: null,
|
|
72
66
|
route_params: { record_id: '7' },
|
|
73
67
|
sections: [],
|
|
74
68
|
},
|
package/src/types/pages.ts
CHANGED
|
@@ -4,7 +4,6 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
4
4
|
*/
|
|
5
5
|
import type { IContentField } from './styles/base';
|
|
6
6
|
import type { TStyleName } from './styles/unknown';
|
|
7
|
-
import type { TWebNavRender, TMobileNavRender } from '../navigation/navRender';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Comprehensive page type system, single source of truth for both apps.
|
|
@@ -39,8 +38,6 @@ export interface IBasePageInfo {
|
|
|
39
38
|
url: string | null;
|
|
40
39
|
parent_page_id: number | null;
|
|
41
40
|
is_headless: boolean;
|
|
42
|
-
navPosition: number | null;
|
|
43
|
-
footerPosition: number | null;
|
|
44
41
|
is_system?: boolean;
|
|
45
42
|
}
|
|
46
43
|
|
|
@@ -67,10 +64,6 @@ export interface IPageItem extends IBasePageInfo {
|
|
|
67
64
|
icon?: string | null;
|
|
68
65
|
/** Mobile menu icon (curated lucide name, e.g. `Home`). Page property field `mobile_icon`. */
|
|
69
66
|
mobile_icon?: string | null;
|
|
70
|
-
/** How this page renders its children as navigation on web. Page property field `web_nav_render`. */
|
|
71
|
-
web_nav_render?: TWebNavRender | null;
|
|
72
|
-
/** How this page renders its children as navigation on mobile. Page property field `mobile_nav_render`. */
|
|
73
|
-
mobile_nav_render?: TMobileNavRender | null;
|
|
74
67
|
children?: IPageItem[];
|
|
75
68
|
}
|
|
76
69
|
|
|
@@ -102,18 +95,12 @@ export interface IPageContent {
|
|
|
102
95
|
* `modal_height` page property field.
|
|
103
96
|
*/
|
|
104
97
|
modal_height?: string | null;
|
|
105
|
-
nav_position: number | null;
|
|
106
|
-
footer_position: number | null;
|
|
107
98
|
title?: string | null;
|
|
108
99
|
description?: string | null;
|
|
109
100
|
/** Web menu icon (Tabler component name). Mirrors the `icon` page property field. */
|
|
110
101
|
icon?: string | null;
|
|
111
102
|
/** Mobile menu icon (curated lucide name). Mirrors the `mobile_icon` page property field. */
|
|
112
103
|
mobile_icon?: string | null;
|
|
113
|
-
/** Web child-navigation render type. Mirrors the `web_nav_render` page property field. */
|
|
114
|
-
web_nav_render?: TWebNavRender | null;
|
|
115
|
-
/** Mobile child-navigation render type. Mirrors the `mobile_nav_render` page property field. */
|
|
116
|
-
mobile_nav_render?: TMobileNavRender | null;
|
|
117
104
|
/**
|
|
118
105
|
* Snake_case route params extracted from the matched public URL pattern
|
|
119
106
|
* (e.g. `{ user_id: '42', token: 'abc' }` or `{ record_id: '7' }`). Present
|
|
@@ -11,8 +11,6 @@ describe('transformPageData', () => {
|
|
|
11
11
|
id_pages: 7,
|
|
12
12
|
keyword: 'qa-home',
|
|
13
13
|
url: '/qa-home',
|
|
14
|
-
nav_position: 3,
|
|
15
|
-
footer_position: null,
|
|
16
14
|
is_headless: 1,
|
|
17
15
|
is_system: 0,
|
|
18
16
|
});
|
|
@@ -20,17 +18,10 @@ describe('transformPageData', () => {
|
|
|
20
18
|
expect(result.id).toBe(7);
|
|
21
19
|
expect(result.id_pages).toBe(7);
|
|
22
20
|
expect(result.keyword).toBe('qa-home');
|
|
23
|
-
expect(result.navPosition).toBe(3);
|
|
24
|
-
expect(result.footerPosition).toBeNull();
|
|
25
21
|
expect(result.is_headless).toBe(true);
|
|
26
22
|
expect(result.is_system).toBe(false);
|
|
27
23
|
});
|
|
28
24
|
|
|
29
|
-
it('prefers an explicit camelCase navPosition over the snake_case key', () => {
|
|
30
|
-
const result = transformPageData({ id: 1, keyword: 'k', navPosition: 9, nav_position: 1 });
|
|
31
|
-
expect(result.navPosition).toBe(9);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
25
|
it('coerces boolean-like is_headless values (number/string/boolean)', () => {
|
|
35
26
|
expect(transformPageData({ id: 1, keyword: 'k', is_headless: '1' }).is_headless).toBe(true);
|
|
36
27
|
expect(transformPageData({ id: 1, keyword: 'k', is_headless: true }).is_headless).toBe(true);
|
|
@@ -41,34 +32,27 @@ describe('transformPageData', () => {
|
|
|
41
32
|
const result = transformPageData({
|
|
42
33
|
id: 1,
|
|
43
34
|
keyword: 'parent',
|
|
44
|
-
children: [{ id_pages: 2, keyword: 'child'
|
|
35
|
+
children: [{ id_pages: 2, keyword: 'child' }],
|
|
45
36
|
});
|
|
46
37
|
expect(result.children).toHaveLength(1);
|
|
47
38
|
expect(result.children[0].id).toBe(2);
|
|
48
|
-
expect(result.children[0].navPosition).toBe(5);
|
|
49
39
|
});
|
|
50
40
|
|
|
51
|
-
it('passes through
|
|
41
|
+
it('passes through icon fields', () => {
|
|
52
42
|
const result = transformPageData({
|
|
53
43
|
id: 1,
|
|
54
44
|
keyword: 'team',
|
|
55
45
|
icon: 'IconUsers',
|
|
56
46
|
mobile_icon: 'Users',
|
|
57
|
-
web_nav_render: 'hero-cards',
|
|
58
|
-
mobile_nav_render: 'bottom-tabs',
|
|
59
47
|
});
|
|
60
48
|
expect(result.icon).toBe('IconUsers');
|
|
61
49
|
expect(result.mobile_icon).toBe('Users');
|
|
62
|
-
expect(result.web_nav_render).toBe('hero-cards');
|
|
63
|
-
expect(result.mobile_nav_render).toBe('bottom-tabs');
|
|
64
50
|
});
|
|
65
51
|
|
|
66
|
-
it('defaults
|
|
52
|
+
it('defaults icon fields to null when absent', () => {
|
|
67
53
|
const result = transformPageData({ id: 1, keyword: 'plain' });
|
|
68
54
|
expect(result.icon).toBeNull();
|
|
69
55
|
expect(result.mobile_icon).toBeNull();
|
|
70
|
-
expect(result.web_nav_render).toBeNull();
|
|
71
|
-
expect(result.mobile_nav_render).toBeNull();
|
|
72
56
|
});
|
|
73
57
|
|
|
74
58
|
it('defaults missing id/keyword safely', () => {
|
|
@@ -5,32 +5,10 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
5
5
|
/**
|
|
6
6
|
* Backend → frontend page-shape transformer.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* (`nav_position`, `footer_position`, `id_pages`, `id_parent_page`,
|
|
10
|
-
* `id_page_types`, `id_page_access_types`). The web and mobile apps
|
|
11
|
-
* prefer camelCase (`navPosition`, `footerPosition`) at the type-system
|
|
12
|
-
* level. This helper bridges the two so consumers don't have to know
|
|
13
|
-
* about the snake-case wire format.
|
|
14
|
-
*
|
|
15
|
-
* It is the single source of truth for the conversion. Web frontend
|
|
16
|
-
* and mobile both import it from `@selfhelp/shared`.
|
|
17
|
-
*
|
|
18
|
-
* NOTE: Pre-release breaking-change cutover (`db_naming_cutover_*`)
|
|
19
|
-
* removed all legacy aliases (`parent`, `id_type`,
|
|
20
|
-
* `id_pageAccessTypes`). The backend is the single source of canonical
|
|
21
|
-
* keys; the transformer no longer accepts the legacy shapes.
|
|
22
|
-
*
|
|
23
|
-
* ROUTE METADATA (issue #30): this transformer deliberately does NOT carry
|
|
24
|
-
* `route_params` / `matched_url_pattern` / `canonical_url`. Those are
|
|
25
|
-
* resolve-time fields of a single page's full content (`IPageContent`, returned
|
|
26
|
-
* by `GET /pages/resolve`) and are consumed directly off that type. `IPageItem`
|
|
27
|
-
* is the navigation/menu projection of the page tree (keyword, url,
|
|
28
|
-
* nav/footer position, parent/children) and never participates in URL
|
|
29
|
-
* resolution, so adding a route passthrough here would be dead weight.
|
|
8
|
+
* Menu membership is no longer projected on pages. Use `GET /navigation` for menus.
|
|
30
9
|
*/
|
|
31
10
|
|
|
32
11
|
import type { IPageItem } from '../types/pages';
|
|
33
|
-
import type { TWebNavRender, TMobileNavRender } from '../navigation/navRender';
|
|
34
12
|
|
|
35
13
|
interface IRawPage {
|
|
36
14
|
id?: number;
|
|
@@ -40,18 +18,12 @@ interface IRawPage {
|
|
|
40
18
|
id_parent_page?: number | null;
|
|
41
19
|
parent_page_id?: number | null;
|
|
42
20
|
is_headless?: number | boolean | null;
|
|
43
|
-
nav_position?: number | null;
|
|
44
|
-
navPosition?: number | null;
|
|
45
|
-
footer_position?: number | null;
|
|
46
|
-
footerPosition?: number | null;
|
|
47
21
|
is_system?: number | boolean | null;
|
|
48
22
|
is_open_access?: number | boolean | null;
|
|
49
23
|
title?: string | null;
|
|
50
24
|
description?: string | null;
|
|
51
25
|
icon?: string | null;
|
|
52
26
|
mobile_icon?: string | null;
|
|
53
|
-
web_nav_render?: TWebNavRender | string | null;
|
|
54
|
-
mobile_nav_render?: TMobileNavRender | string | null;
|
|
55
27
|
id_users?: number;
|
|
56
28
|
acl_select?: 0 | 1;
|
|
57
29
|
acl_insert?: 0 | 1;
|
|
@@ -80,19 +52,11 @@ export function transformPageData(apiPage: IRawPage): IPageItem {
|
|
|
80
52
|
url: apiPage.url ?? null,
|
|
81
53
|
parent_page_id: parentPageId,
|
|
82
54
|
is_headless: toBool(apiPage.is_headless),
|
|
83
|
-
navPosition:
|
|
84
|
-
apiPage.navPosition !== undefined ? apiPage.navPosition : (apiPage.nav_position ?? null),
|
|
85
|
-
footerPosition:
|
|
86
|
-
apiPage.footerPosition !== undefined
|
|
87
|
-
? apiPage.footerPosition
|
|
88
|
-
: (apiPage.footer_position ?? null),
|
|
89
55
|
is_system: apiPage.is_system !== undefined ? toBool(apiPage.is_system) : undefined,
|
|
90
56
|
title: apiPage.title ?? null,
|
|
91
57
|
description: apiPage.description ?? null,
|
|
92
58
|
icon: apiPage.icon ?? null,
|
|
93
59
|
mobile_icon: apiPage.mobile_icon ?? null,
|
|
94
|
-
web_nav_render: (apiPage.web_nav_render as TWebNavRender | null) ?? null,
|
|
95
|
-
mobile_nav_render: (apiPage.mobile_nav_render as TMobileNavRender | null) ?? null,
|
|
96
60
|
children: apiPage.children?.map(transformPageData) ?? [],
|
|
97
61
|
|
|
98
62
|
id_users: apiPage.id_users,
|