@selfhelp/shared 1.0.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENSE +381 -0
  3. package/README.md +266 -0
  4. package/dist/common-B96dASgu.d.mts +80 -0
  5. package/dist/common-B96dASgu.d.ts +80 -0
  6. package/dist/index-Bg60YTsF.d.mts +1743 -0
  7. package/dist/index-DEOVT86P.d.ts +1743 -0
  8. package/dist/index.d.mts +597 -0
  9. package/dist/index.d.ts +597 -0
  10. package/dist/index.js +796 -0
  11. package/dist/index.mjs +718 -0
  12. package/dist/registry/index.d.mts +2 -0
  13. package/dist/registry/index.d.ts +2 -0
  14. package/dist/registry/index.js +134 -0
  15. package/dist/registry/index.mjs +105 -0
  16. package/dist/theme/index.d.mts +63 -0
  17. package/dist/theme/index.d.ts +63 -0
  18. package/dist/theme/index.js +202 -0
  19. package/dist/theme/index.mjs +162 -0
  20. package/dist/theme/tailwind.d.mts +36 -0
  21. package/dist/theme/tailwind.d.ts +36 -0
  22. package/dist/theme/tailwind.js +125 -0
  23. package/dist/theme/tailwind.mjs +97 -0
  24. package/package.json +69 -0
  25. package/src/api/endpoints.ts +58 -0
  26. package/src/api/index.ts +5 -0
  27. package/src/assets/index.ts +5 -0
  28. package/src/assets/resolveAssetUrl.ts +44 -0
  29. package/src/cms-classes/allow-list.ts +158 -0
  30. package/src/cms-classes/classify.ts +90 -0
  31. package/src/cms-classes/index.ts +7 -0
  32. package/src/cms-classes/remap.ts +44 -0
  33. package/src/condition/evaluate.ts +121 -0
  34. package/src/condition/index.ts +5 -0
  35. package/src/index.ts +25 -0
  36. package/src/interpolation/index.ts +5 -0
  37. package/src/interpolation/replaceCalcedValues.ts +27 -0
  38. package/src/registry/index.ts +37 -0
  39. package/src/registry/styles.registry.ts +158 -0
  40. package/src/theme/index.ts +6 -0
  41. package/src/theme/tailwind.ts +73 -0
  42. package/src/theme/tokens.ts +177 -0
  43. package/src/types/api/auth.ts +46 -0
  44. package/src/types/api/envelope.ts +34 -0
  45. package/src/types/api/forms.ts +38 -0
  46. package/src/types/api/index.ts +9 -0
  47. package/src/types/api/language.ts +12 -0
  48. package/src/types/api/page.ts +9 -0
  49. package/src/types/auth.ts +110 -0
  50. package/src/types/index.ts +17 -0
  51. package/src/types/mantine/common.ts +142 -0
  52. package/src/types/pages.ts +107 -0
  53. package/src/types/styles/auth.ts +165 -0
  54. package/src/types/styles/base.ts +72 -0
  55. package/src/types/styles/composite.ts +131 -0
  56. package/src/types/styles/forms.ts +439 -0
  57. package/src/types/styles/interactive.ts +165 -0
  58. package/src/types/styles/layout.ts +184 -0
  59. package/src/types/styles/media.ts +68 -0
  60. package/src/types/styles/typography.ts +118 -0
  61. package/src/types/styles/unknown.ts +220 -0
  62. package/src/utils/index.ts +6 -0
  63. package/src/utils/spacing.ts +64 -0
  64. package/src/utils/transformPageData.ts +93 -0
@@ -0,0 +1,220 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import type { IContentField } from './base';
6
+ import type {
7
+ ILoginStyle,
8
+ IRegisterStyle,
9
+ IValidateStyle,
10
+ IResetPasswordStyle,
11
+ ITwoFactorAuthStyle,
12
+ IProfileStyle,
13
+ } from './auth';
14
+ import type {
15
+ IContainerStyle,
16
+ IBoxStyle,
17
+ IFlexStyle,
18
+ IGroupStyle,
19
+ IStackStyle,
20
+ ISimpleGridStyle,
21
+ IGridStyle,
22
+ IGridColumnStyle,
23
+ ISpaceStyle,
24
+ IDividerStyle,
25
+ IPaperStyle,
26
+ ICenterStyle,
27
+ IScrollAreaStyle,
28
+ ICardStyle,
29
+ ICardSegmentStyle,
30
+ IAspectRatioStyle,
31
+ IBackgroundImageStyle,
32
+ } from './layout';
33
+ import type {
34
+ ITitleStyle,
35
+ ITextStyle,
36
+ ICodeStyle,
37
+ IHighlightStyle,
38
+ IBlockquoteStyle,
39
+ IHtmlTagStyle,
40
+ IKbdStyle,
41
+ ITypographyStyle,
42
+ IFieldsetStyle,
43
+ ISpoilerStyle,
44
+ } from './typography';
45
+ import type {
46
+ IImageStyle,
47
+ IVideoStyle,
48
+ IAudioStyle,
49
+ IFigureStyle,
50
+ ICarouselStyle,
51
+ } from './media';
52
+ import type {
53
+ IButtonStyle,
54
+ ILinkStyle,
55
+ IActionIconStyle,
56
+ IAlertStyle,
57
+ IBadgeStyle,
58
+ IAvatarStyle,
59
+ IChipStyle,
60
+ IIndicatorStyle,
61
+ IThemeIconStyle,
62
+ INotificationStyle,
63
+ } from './interactive';
64
+ import type {
65
+ IFormLogStyle,
66
+ IFormRecordStyle,
67
+ IInputStyle,
68
+ ITextInputStyle,
69
+ ITextareaStyle,
70
+ IRichTextEditorStyle,
71
+ ISelectStyle,
72
+ IRadioStyle,
73
+ ICheckboxStyle,
74
+ ISliderStyle,
75
+ IRangeSliderStyle,
76
+ IDatePickerStyle,
77
+ ISwitchStyle,
78
+ IComboboxStyle,
79
+ IColorInputStyle,
80
+ IColorPickerStyle,
81
+ IFileInputStyle,
82
+ INumberInputStyle,
83
+ ISegmentedControlStyle,
84
+ IRatingStyle,
85
+ IProgressStyle,
86
+ IProgressRootStyle,
87
+ IProgressSectionStyle,
88
+ } from './forms';
89
+ import type {
90
+ IAccordionStyle,
91
+ IAccordionItemStyle,
92
+ ITabsStyle,
93
+ ITabStyle,
94
+ ITimelineStyle,
95
+ IListStyle,
96
+ IListItemStyle,
97
+ IEntryListStyle,
98
+ IEntryRecordStyle,
99
+ IEntryRecordDeleteStyle,
100
+ ILoopStyle,
101
+ } from './composite';
102
+
103
+ /**
104
+ * Discriminated union of every supported user-facing style. Adding a new
105
+ * style means adding its interface AND extending this union AND registering
106
+ * it in `STYLE_REGISTRY`.
107
+ *
108
+ * Admin/CMS-only styles are intentionally NOT in this union — the mobile
109
+ * app does not render them.
110
+ */
111
+ export type TStyle =
112
+ | ILoginStyle
113
+ | IRegisterStyle
114
+ | IValidateStyle
115
+ | IResetPasswordStyle
116
+ | ITwoFactorAuthStyle
117
+ | IProfileStyle
118
+ | IContainerStyle
119
+ | IBoxStyle
120
+ | IFlexStyle
121
+ | IGroupStyle
122
+ | IStackStyle
123
+ | ISimpleGridStyle
124
+ | IGridStyle
125
+ | IGridColumnStyle
126
+ | ISpaceStyle
127
+ | IDividerStyle
128
+ | IPaperStyle
129
+ | ICenterStyle
130
+ | IScrollAreaStyle
131
+ | ICardStyle
132
+ | ICardSegmentStyle
133
+ | IAspectRatioStyle
134
+ | IBackgroundImageStyle
135
+ | ITitleStyle
136
+ | ITextStyle
137
+ | ICodeStyle
138
+ | IHighlightStyle
139
+ | IBlockquoteStyle
140
+ | IHtmlTagStyle
141
+ | IKbdStyle
142
+ | ITypographyStyle
143
+ | IFieldsetStyle
144
+ | ISpoilerStyle
145
+ | IImageStyle
146
+ | IVideoStyle
147
+ | IAudioStyle
148
+ | IFigureStyle
149
+ | ICarouselStyle
150
+ | IButtonStyle
151
+ | ILinkStyle
152
+ | IActionIconStyle
153
+ | IAlertStyle
154
+ | IBadgeStyle
155
+ | IAvatarStyle
156
+ | IChipStyle
157
+ | IIndicatorStyle
158
+ | IThemeIconStyle
159
+ | INotificationStyle
160
+ | IFormLogStyle
161
+ | IFormRecordStyle
162
+ | IInputStyle
163
+ | ITextInputStyle
164
+ | ITextareaStyle
165
+ | IRichTextEditorStyle
166
+ | ISelectStyle
167
+ | IRadioStyle
168
+ | ICheckboxStyle
169
+ | ISliderStyle
170
+ | IRangeSliderStyle
171
+ | IDatePickerStyle
172
+ | ISwitchStyle
173
+ | IComboboxStyle
174
+ | IColorInputStyle
175
+ | IColorPickerStyle
176
+ | IFileInputStyle
177
+ | INumberInputStyle
178
+ | ISegmentedControlStyle
179
+ | IRatingStyle
180
+ | IProgressStyle
181
+ | IProgressRootStyle
182
+ | IProgressSectionStyle
183
+ | IAccordionStyle
184
+ | IAccordionItemStyle
185
+ | ITabsStyle
186
+ | ITabStyle
187
+ | ITimelineStyle
188
+ | IListStyle
189
+ | IListItemStyle
190
+ | IEntryListStyle
191
+ | IEntryRecordStyle
192
+ | IEntryRecordDeleteStyle
193
+ | ILoopStyle;
194
+
195
+ /**
196
+ * Discriminator — name of every supported style. Derived from the
197
+ * `STYLE_REGISTRY` keys (declared in `src/registry/styles.registry.ts`).
198
+ *
199
+ * NOTE: Keep in sync with `STYLE_REGISTRY`. The registry is the source of
200
+ * truth at runtime; this type is the source of truth at compile time.
201
+ */
202
+ export type TStyleName = TStyle['style_name'];
203
+
204
+ /**
205
+ * Catch-all for styles a renderer doesn't know about (yet). Keeps the
206
+ * tree alive and lets the renderer surface debug info.
207
+ */
208
+ export interface IUnknownStyle {
209
+ id: number;
210
+ id_styles: number;
211
+ style_name: string;
212
+ can_have_children: number | null;
213
+ position: number;
214
+ path: string;
215
+ children?: TStyle[];
216
+ fields: Record<string, IContentField<unknown>>;
217
+ css?: string;
218
+ css_mobile?: string;
219
+ use_mantine_style?: IContentField<string>;
220
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ export * from './spacing';
6
+ export * from './transformPageData';
@@ -0,0 +1,64 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Parse the unified `mantine_spacing_margin_padding` field. The CMS
7
+ * stores this as a JSON string with optional keys for each side:
8
+ *
9
+ * { "mt": "md", "mb": "lg", "ms": "0", "me": "auto",
10
+ * "pt": "sm", "pb": "sm", "ps": "md", "pe": "md" }
11
+ *
12
+ * Empty/null/missing values are filtered out so downstream renderers
13
+ * can call e.g. `Object.entries(parsed)` without seeing falsy entries.
14
+ */
15
+
16
+ export interface ISpacingValue {
17
+ mt?: string;
18
+ mb?: string;
19
+ ms?: string;
20
+ me?: string;
21
+ pt?: string;
22
+ pb?: string;
23
+ ps?: string;
24
+ pe?: string;
25
+ }
26
+
27
+ const ALLOWED_KEYS: ReadonlyArray<keyof ISpacingValue> = ['mt', 'mb', 'ms', 'me', 'pt', 'pb', 'ps', 'pe'];
28
+
29
+ export function parseSpacing(raw: string | null | undefined): ISpacingValue {
30
+ if (!raw) return {};
31
+ let parsed: unknown;
32
+ try {
33
+ parsed = JSON.parse(raw);
34
+ } catch {
35
+ return {};
36
+ }
37
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
38
+
39
+ const result: ISpacingValue = {};
40
+ const obj = parsed as Record<string, unknown>;
41
+ for (const key of ALLOWED_KEYS) {
42
+ const value = obj[key];
43
+ if (value === undefined || value === null || value === '') continue;
44
+ result[key] = String(value);
45
+ }
46
+ return result;
47
+ }
48
+
49
+ /**
50
+ * Convert spacing values to Tailwind classes via `SPACING_TO_TAILWIND`
51
+ * mapping. Numeric values pass through as `mt-{n}` etc.
52
+ */
53
+ export function spacingToClasses(
54
+ spacing: ISpacingValue,
55
+ spacingToTailwind: Record<string, string>
56
+ ): string[] {
57
+ const classes: string[] = [];
58
+ for (const [key, raw] of Object.entries(spacing)) {
59
+ if (!raw) continue;
60
+ const tail = spacingToTailwind[raw] ?? raw;
61
+ classes.push(`${key}-${tail}`);
62
+ }
63
+ return classes;
64
+ }
@@ -0,0 +1,93 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Backend → frontend page-shape transformer.
7
+ *
8
+ * The Symfony repositories project pages with snake_case keys
9
+ * (`nav_position`, `footer_position`, `id_pages`, `parent`) for legacy
10
+ * reasons. Both the web and the mobile app prefer camelCase
11
+ * (`navPosition`, `footerPosition`) at the type-system level. This
12
+ * helper bridges the two so consumers don't have to know about the
13
+ * 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
+
19
+ import type { IPageItem } from '../types/pages';
20
+
21
+ interface IRawPage {
22
+ id?: number;
23
+ id_pages?: number;
24
+ keyword?: string;
25
+ url?: string | null;
26
+ parent?: number | null;
27
+ parent_page_id?: number | null;
28
+ is_headless?: number | boolean | null;
29
+ nav_position?: number | null;
30
+ navPosition?: number | null;
31
+ footer_position?: number | null;
32
+ footerPosition?: number | null;
33
+ is_system?: number | boolean | null;
34
+ is_open_access?: number | boolean | null;
35
+ title?: string | null;
36
+ description?: string | null;
37
+ id_users?: number;
38
+ acl_select?: 0 | 1;
39
+ acl_insert?: 0 | 1;
40
+ acl_update?: 0 | 1;
41
+ acl_delete?: 0 | 1;
42
+ id_type?: number;
43
+ id_pageAccessTypes?: number;
44
+ children?: IRawPage[];
45
+ [key: string]: unknown;
46
+ }
47
+
48
+ function toBool(value: unknown): boolean {
49
+ if (value === null || value === undefined) return false;
50
+ if (typeof value === 'boolean') return value;
51
+ if (typeof value === 'number') return value === 1;
52
+ if (typeof value === 'string') return value === '1' || value === 'true';
53
+ return false;
54
+ }
55
+
56
+ export function transformPageData(apiPage: IRawPage): IPageItem {
57
+ const id = apiPage.id ?? apiPage.id_pages ?? 0;
58
+ return {
59
+ id,
60
+ keyword: apiPage.keyword ?? '',
61
+ url: apiPage.url ?? null,
62
+ parent_page_id: apiPage.parent_page_id ?? apiPage.parent ?? null,
63
+ is_headless: toBool(apiPage.is_headless),
64
+ navPosition:
65
+ apiPage.navPosition !== undefined ? apiPage.navPosition : (apiPage.nav_position ?? null),
66
+ footerPosition:
67
+ apiPage.footerPosition !== undefined
68
+ ? apiPage.footerPosition
69
+ : (apiPage.footer_position ?? null),
70
+ is_system: apiPage.is_system !== undefined ? toBool(apiPage.is_system) : undefined,
71
+ title: apiPage.title ?? null,
72
+ description: apiPage.description ?? null,
73
+ children: apiPage.children?.map(transformPageData) ?? [],
74
+
75
+ id_users: apiPage.id_users,
76
+ id_pages: apiPage.id_pages ?? id,
77
+ acl_select: apiPage.acl_select,
78
+ acl_insert: apiPage.acl_insert,
79
+ acl_update: apiPage.acl_update,
80
+ acl_delete: apiPage.acl_delete,
81
+ id_type: apiPage.id_type,
82
+ id_pageAccessTypes: apiPage.id_pageAccessTypes,
83
+ };
84
+ }
85
+
86
+ /**
87
+ * Same as `transformPageData` but for an array. Convenience helper
88
+ * because almost every consumer fetches a list of pages.
89
+ */
90
+ export function transformPagesData(pages: IRawPage[] | null | undefined): IPageItem[] {
91
+ if (!pages) return [];
92
+ return pages.map(transformPageData);
93
+ }