@selfhelp/shared 1.18.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * The single "is this page on the menu?" predicate, shared by web + mobile menu
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.
14
+ */
15
+
16
+ import type { IPageItem } from '../types/pages';
17
+
18
+ export function isMenuVisible(page: Pick<IPageItem, 'is_headless' | 'navPosition'>): boolean {
19
+ if (page.is_headless) return false;
20
+ return page.navPosition !== null && page.navPosition !== undefined;
21
+ }
22
+
23
+ /** Children of `page` that should appear in a navigation block, in nav order. */
24
+ export function getMenuVisibleChildren(page: IPageItem): IPageItem[] {
25
+ const children = page.children ?? [];
26
+ return children
27
+ .filter(isMenuVisible)
28
+ .sort((a, b) => (a.navPosition ?? 0) - (b.navPosition ?? 0));
29
+ }
30
+
31
+ /**
32
+ * A "navigation page" is a page whose children act as its menu. The hybrid
33
+ * auto-render rule additionally requires the page to have no visible body
34
+ * sections (decided by the caller, which has the resolved page content).
35
+ */
36
+ export function isNavigationPage(page: IPageItem): boolean {
37
+ return getMenuVisibleChildren(page).length > 0;
38
+ }
@@ -0,0 +1,86 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Curated mobile icon set — the SINGLE source of truth shared by the admin
7
+ * `select-icon-mobile` picker (web frontend, drawn with `lucide-react`) and the
8
+ * mobile menu renderers (drawn with `lucide-react-native`).
9
+ *
10
+ * Storing the lucide PascalCase export name keeps the contract stable: both
11
+ * `lucide-react` and `lucide-react-native` expose identical named exports, so a
12
+ * renderer maps `name -> (LucideIcons as Record<string, Component>)[name]`.
13
+ *
14
+ * Keep this list to icons that read well at small sizes in a tab bar / drawer
15
+ * and that exist in BOTH lucide packages. Add entries here (never per-app) so
16
+ * the picker and the renderer never drift.
17
+ */
18
+
19
+ export interface IMobileIconEntry {
20
+ /** lucide PascalCase export name, e.g. `Home`, `Users`, `LayoutDashboard`. */
21
+ name: string;
22
+ /** Friendly label for the admin picker. */
23
+ label: string;
24
+ }
25
+
26
+ export const MOBILE_ICON_SET: readonly IMobileIconEntry[] = [
27
+ { name: 'House', label: 'Home' },
28
+ { name: 'LayoutDashboard', label: 'Dashboard' },
29
+ { name: 'User', label: 'User' },
30
+ { name: 'Users', label: 'Users / Team' },
31
+ { name: 'Settings', label: 'Settings' },
32
+ { name: 'FileText', label: 'Document' },
33
+ { name: 'Files', label: 'Files' },
34
+ { name: 'Folder', label: 'Folder' },
35
+ { name: 'Info', label: 'Info' },
36
+ { name: 'CircleQuestionMark', label: 'Help' },
37
+ { name: 'Mail', label: 'Mail' },
38
+ { name: 'Phone', label: 'Phone' },
39
+ { name: 'Calendar', label: 'Calendar' },
40
+ { name: 'Bell', label: 'Notifications' },
41
+ { name: 'Search', label: 'Search' },
42
+ { name: 'Star', label: 'Star' },
43
+ { name: 'Heart', label: 'Heart' },
44
+ { name: 'Bookmark', label: 'Bookmark' },
45
+ { name: 'Map', label: 'Map' },
46
+ { name: 'MapPin', label: 'Location' },
47
+ { name: 'Image', label: 'Image' },
48
+ { name: 'Video', label: 'Video' },
49
+ { name: 'Music', label: 'Music' },
50
+ { name: 'ShoppingCart', label: 'Shopping cart' },
51
+ { name: 'CreditCard', label: 'Payment' },
52
+ { name: 'ChartBar', label: 'Bar chart' },
53
+ { name: 'ChartPie', label: 'Pie chart' },
54
+ { name: 'Activity', label: 'Activity' },
55
+ { name: 'Shield', label: 'Shield' },
56
+ { name: 'Lock', label: 'Lock' },
57
+ { name: 'Globe', label: 'Globe' },
58
+ { name: 'Compass', label: 'Compass' },
59
+ { name: 'Flag', label: 'Flag' },
60
+ { name: 'Award', label: 'Award' },
61
+ { name: 'Briefcase', label: 'Work' },
62
+ { name: 'Building', label: 'Building' },
63
+ { name: 'BookOpen', label: 'Book' },
64
+ { name: 'MessageSquare', label: 'Messages' },
65
+ { name: 'ClipboardList', label: 'Tasks' },
66
+ { name: 'CircleCheck', label: 'Check' },
67
+ { name: 'List', label: 'List' },
68
+ { name: 'LayoutGrid', label: 'Grid' },
69
+ { name: 'Menu', label: 'Menu' },
70
+ { name: 'Database', label: 'Data' },
71
+ ] as const;
72
+
73
+ /** All valid mobile icon names (for validation / membership checks). */
74
+ export const MOBILE_ICON_NAMES: readonly string[] = MOBILE_ICON_SET.map((entry) => entry.name);
75
+
76
+ /** Neutral fallback used when a page has no `mobile_icon` or an unknown value. */
77
+ export const DEFAULT_MOBILE_ICON = 'Circle';
78
+
79
+ export function isMobileIconName(value: unknown): value is string {
80
+ return typeof value === 'string' && MOBILE_ICON_NAMES.includes(value);
81
+ }
82
+
83
+ /** Resolve a stored `mobile_icon` to a drawable name, falling back to the default. */
84
+ export function resolveMobileIcon(value: unknown): string {
85
+ return isMobileIconName(value) ? value : DEFAULT_MOBILE_ICON;
86
+ }
@@ -0,0 +1,132 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Navigation rendering contract (shared by web + mobile).
7
+ *
8
+ * The page TREE defines navigation STRUCTURE (parent/child + `nav_position`).
9
+ * A per-page render type controls PRESENTATION only — it never changes the
10
+ * structure or the URLs. Web and mobile each pick their own renderer from the
11
+ * stored value, so the same subtree can render differently per platform.
12
+ *
13
+ * - `web_nav_render` selects the web renderer for a page's children.
14
+ * - `mobile_nav_render` selects the mobile renderer for a page's children.
15
+ *
16
+ * Both fields are OPTIONAL on a page; when unset the platform applies its
17
+ * default (web `tabs`, mobile `segmented-tabs` for a navigation page's
18
+ * children; the GLOBAL app menu defaults to web `header-dropdown` and mobile
19
+ * `bottom-tabs`).
20
+ */
21
+
22
+ export type TWebNavRender = 'header-dropdown' | 'tabs' | 'sidebar-drawer' | 'hero-cards';
23
+
24
+ export type TMobileNavRender = 'segmented-tabs' | 'bottom-tabs' | 'drawer' | 'hero-cards';
25
+
26
+ export const WEB_NAV_RENDER_VALUES: readonly TWebNavRender[] = [
27
+ 'header-dropdown',
28
+ 'tabs',
29
+ 'sidebar-drawer',
30
+ 'hero-cards',
31
+ ] as const;
32
+
33
+ export const MOBILE_NAV_RENDER_VALUES: readonly TMobileNavRender[] = [
34
+ 'segmented-tabs',
35
+ 'bottom-tabs',
36
+ 'drawer',
37
+ 'hero-cards',
38
+ ] as const;
39
+
40
+ /** Default renderer for a navigation page's CHILDREN. */
41
+ export const DEFAULT_WEB_NAV_RENDER: TWebNavRender = 'tabs';
42
+ export const DEFAULT_MOBILE_NAV_RENDER: TMobileNavRender = 'segmented-tabs';
43
+
44
+ /** Default renderer for the GLOBAL app menu (header / shell). */
45
+ export const DEFAULT_WEB_GLOBAL_NAV_RENDER: TWebNavRender = 'header-dropdown';
46
+ export const DEFAULT_MOBILE_GLOBAL_NAV_RENDER: TMobileNavRender = 'bottom-tabs';
47
+
48
+ export interface INavRenderOption<T extends string> {
49
+ value: T;
50
+ /** Friendly label for the admin select. */
51
+ label: string;
52
+ /** Short, plain-language explanation shown under the select. */
53
+ description: string;
54
+ }
55
+
56
+ /** Option metadata for the admin "Web menu style" select. */
57
+ export const WEB_NAV_RENDER_OPTIONS: readonly INavRenderOption<TWebNavRender>[] = [
58
+ {
59
+ value: 'header-dropdown',
60
+ label: 'Header dropdown',
61
+ description: 'Classic top menu; child pages appear in a dropdown. Best for the global website menu.',
62
+ },
63
+ {
64
+ value: 'tabs',
65
+ label: 'Tabs',
66
+ description: 'Show child pages as horizontal tabs. Best for a navigation page with a few children.',
67
+ },
68
+ {
69
+ value: 'sidebar-drawer',
70
+ label: 'Sidebar drawer',
71
+ description: 'Side drawer / hamburger menu. Best for large or deep navigation.',
72
+ },
73
+ {
74
+ value: 'hero-cards',
75
+ label: 'Hero cards',
76
+ description: 'Dashboard-style card grid. Best for landing pages and CMS app dashboards.',
77
+ },
78
+ ] as const;
79
+
80
+ /** Option metadata for the admin "Mobile menu style" select. */
81
+ export const MOBILE_NAV_RENDER_OPTIONS: readonly INavRenderOption<TMobileNavRender>[] = [
82
+ {
83
+ value: 'segmented-tabs',
84
+ label: 'Segmented tabs',
85
+ description: 'Top segmented control for first-level children. Best for a few child pages.',
86
+ },
87
+ {
88
+ value: 'bottom-tabs',
89
+ label: 'Bottom tabs',
90
+ description: 'Bottom tab bar for 3–5 main app-like destinations.',
91
+ },
92
+ {
93
+ value: 'drawer',
94
+ label: 'Drawer',
95
+ description: 'Hamburger / side drawer for larger navigation.',
96
+ },
97
+ {
98
+ value: 'hero-cards',
99
+ label: 'Hero cards',
100
+ description: 'Card grid for dashboards and CMS app pages.',
101
+ },
102
+ ] as const;
103
+
104
+ export function isWebNavRender(value: unknown): value is TWebNavRender {
105
+ return typeof value === 'string' && (WEB_NAV_RENDER_VALUES as readonly string[]).includes(value);
106
+ }
107
+
108
+ export function isMobileNavRender(value: unknown): value is TMobileNavRender {
109
+ return typeof value === 'string' && (MOBILE_NAV_RENDER_VALUES as readonly string[]).includes(value);
110
+ }
111
+
112
+ /**
113
+ * Resolve a stored `web_nav_render` value to a concrete renderer, falling back
114
+ * to the supplied default (page-children default by default).
115
+ */
116
+ export function resolveWebNavRender(
117
+ value: unknown,
118
+ fallback: TWebNavRender = DEFAULT_WEB_NAV_RENDER,
119
+ ): TWebNavRender {
120
+ return isWebNavRender(value) ? value : fallback;
121
+ }
122
+
123
+ /**
124
+ * Resolve a stored `mobile_nav_render` value to a concrete renderer, falling
125
+ * back to the supplied default (page-children default by default).
126
+ */
127
+ export function resolveMobileNavRender(
128
+ value: unknown,
129
+ fallback: TMobileNavRender = DEFAULT_MOBILE_NAV_RENDER,
130
+ ): TMobileNavRender {
131
+ return isMobileNavRender(value) ? value : fallback;
132
+ }
@@ -4,6 +4,7 @@ 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';
7
8
 
8
9
  /**
9
10
  * Comprehensive page type system, single source of truth for both apps.
@@ -62,6 +63,14 @@ export interface IPageItem extends IBasePageInfo {
62
63
  id_page_access_types?: number;
63
64
  title?: string | null;
64
65
  description?: string | null;
66
+ /** Web menu icon (Tabler component name, e.g. `IconHome`). Page property field `icon`. */
67
+ icon?: string | null;
68
+ /** Mobile menu icon (curated lucide name, e.g. `Home`). Page property field `mobile_icon`. */
69
+ 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;
65
74
  children?: IPageItem[];
66
75
  }
67
76
 
@@ -75,6 +84,14 @@ export interface IPageContent {
75
84
  footer_position: number | null;
76
85
  title?: string | null;
77
86
  description?: string | null;
87
+ /** Web menu icon (Tabler component name). Mirrors the `icon` page property field. */
88
+ icon?: string | null;
89
+ /** Mobile menu icon (curated lucide name). Mirrors the `mobile_icon` page property field. */
90
+ mobile_icon?: string | null;
91
+ /** Web child-navigation render type. Mirrors the `web_nav_render` page property field. */
92
+ web_nav_render?: TWebNavRender | null;
93
+ /** Mobile child-navigation render type. Mirrors the `mobile_nav_render` page property field. */
94
+ mobile_nav_render?: TMobileNavRender | null;
78
95
  /**
79
96
  * Snake_case route params extracted from the matched public URL pattern
80
97
  * (e.g. `{ user_id: '42', token: 'abc' }` or `{ record_id: '7' }`). Present
@@ -48,6 +48,29 @@ describe('transformPageData', () => {
48
48
  expect(result.children[0].navPosition).toBe(5);
49
49
  });
50
50
 
51
+ it('passes through the navigation icon + render fields', () => {
52
+ const result = transformPageData({
53
+ id: 1,
54
+ keyword: 'team',
55
+ icon: 'IconUsers',
56
+ mobile_icon: 'Users',
57
+ web_nav_render: 'hero-cards',
58
+ mobile_nav_render: 'bottom-tabs',
59
+ });
60
+ expect(result.icon).toBe('IconUsers');
61
+ 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
+ });
65
+
66
+ it('defaults the navigation fields to null when absent', () => {
67
+ const result = transformPageData({ id: 1, keyword: 'plain' });
68
+ expect(result.icon).toBeNull();
69
+ expect(result.mobile_icon).toBeNull();
70
+ expect(result.web_nav_render).toBeNull();
71
+ expect(result.mobile_nav_render).toBeNull();
72
+ });
73
+
51
74
  it('defaults missing id/keyword safely', () => {
52
75
  const result = transformPageData({});
53
76
  expect(result.id).toBe(0);
@@ -19,9 +19,18 @@ SPDX-License-Identifier: MPL-2.0
19
19
  * removed all legacy aliases (`parent`, `id_type`,
20
20
  * `id_pageAccessTypes`). The backend is the single source of canonical
21
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.
22
30
  */
23
31
 
24
32
  import type { IPageItem } from '../types/pages';
33
+ import type { TWebNavRender, TMobileNavRender } from '../navigation/navRender';
25
34
 
26
35
  interface IRawPage {
27
36
  id?: number;
@@ -39,6 +48,10 @@ interface IRawPage {
39
48
  is_open_access?: number | boolean | null;
40
49
  title?: string | null;
41
50
  description?: string | null;
51
+ icon?: string | null;
52
+ mobile_icon?: string | null;
53
+ web_nav_render?: TWebNavRender | string | null;
54
+ mobile_nav_render?: TMobileNavRender | string | null;
42
55
  id_users?: number;
43
56
  acl_select?: 0 | 1;
44
57
  acl_insert?: 0 | 1;
@@ -76,6 +89,10 @@ export function transformPageData(apiPage: IRawPage): IPageItem {
76
89
  is_system: apiPage.is_system !== undefined ? toBool(apiPage.is_system) : undefined,
77
90
  title: apiPage.title ?? null,
78
91
  description: apiPage.description ?? null,
92
+ icon: apiPage.icon ?? null,
93
+ 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,
79
96
  children: apiPage.children?.map(transformPageData) ?? [],
80
97
 
81
98
  id_users: apiPage.id_users,