@selfhelp/shared 1.19.0 → 1.21.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.
@@ -5,32 +5,10 @@ SPDX-License-Identifier: MPL-2.0
5
5
  /**
6
6
  * Backend → frontend page-shape transformer.
7
7
  *
8
- * The Symfony backend projects pages with canonical `snake_case` keys
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,
@@ -1,132 +0,0 @@
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
- }