@selfhelp/shared 1.3.0 → 1.3.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +341 -341
  2. package/LICENSE +381 -381
  3. package/README.md +57 -57
  4. package/package.json +102 -102
  5. package/src/api/__tests__/endpoints.test.ts +45 -45
  6. package/src/api/index.ts +5 -5
  7. package/src/assets/__tests__/resolveAssetUrl.test.ts +61 -61
  8. package/src/assets/index.ts +5 -5
  9. package/src/assets/resolveAssetUrl.ts +44 -44
  10. package/src/cms-classes/__tests__/classify.test.ts +63 -63
  11. package/src/cms-classes/allow-list.ts +158 -158
  12. package/src/cms-classes/classify.ts +90 -90
  13. package/src/cms-classes/index.ts +7 -7
  14. package/src/cms-classes/remap.ts +44 -44
  15. package/src/condition/__tests__/evaluate.test.ts +54 -54
  16. package/src/condition/evaluate.ts +121 -121
  17. package/src/condition/index.ts +5 -5
  18. package/src/index.ts +25 -25
  19. package/src/interpolation/__tests__/replaceCalcedValues.test.ts +41 -41
  20. package/src/interpolation/index.ts +5 -5
  21. package/src/interpolation/replaceCalcedValues.ts +27 -27
  22. package/src/plugin-sdk/define.ts +89 -89
  23. package/src/plugin-sdk/index.ts +103 -103
  24. package/src/plugin-sdk/lock.ts +124 -124
  25. package/src/plugin-sdk/manifest.ts +307 -307
  26. package/src/plugin-sdk/realtime.ts +277 -277
  27. package/src/plugin-sdk/registry.ts +105 -105
  28. package/src/plugin-sdk/runtime-shim.ts +140 -140
  29. package/src/plugin-sdk/types.ts +315 -315
  30. package/src/plugin-sdk/version.ts +209 -209
  31. package/src/registry/__tests__/registry.test.ts +135 -135
  32. package/src/registry/index.ts +94 -94
  33. package/src/registry/styles.registry.ts +295 -295
  34. package/src/testing/__tests__/testing-kit.test.ts +228 -228
  35. package/src/testing/index.ts +483 -483
  36. package/src/theme/index.ts +6 -6
  37. package/src/theme/tailwind.ts +73 -73
  38. package/src/theme/tokens.ts +177 -177
  39. package/src/types/api/envelope.ts +34 -34
  40. package/src/types/api/forms.ts +76 -76
  41. package/src/types/api/index.ts +9 -9
  42. package/src/types/api/language.ts +12 -12
  43. package/src/types/api/page.ts +9 -9
  44. package/src/types/index.ts +17 -17
  45. package/src/types/mantine/common.ts +142 -142
  46. package/src/types/pages.ts +107 -107
  47. package/src/types/styles/auth.ts +184 -184
  48. package/src/types/styles/base.ts +72 -72
  49. package/src/types/styles/composite.ts +131 -131
  50. package/src/types/styles/forms.ts +439 -439
  51. package/src/types/styles/interactive.ts +165 -165
  52. package/src/types/styles/layout.ts +184 -184
  53. package/src/types/styles/media.ts +68 -68
  54. package/src/types/styles/typography.ts +118 -118
  55. package/src/types/styles/unknown.ts +220 -220
  56. package/src/utils/__tests__/transformPageData.test.ts +69 -69
  57. package/src/utils/spacing.ts +64 -64
  58. package/src/utils/transformPageData.ts +99 -99
@@ -1,72 +1,72 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- /**
6
- * Base interfaces shared by every CMS style. Mirrors what the backend
7
- * `PageService` returns per section: a `style_name` discriminator, a
8
- * `fields` map, and a handful of side-channel fields (css, condition, debug).
9
- *
10
- * The per-style interfaces (in `auth.ts`, `layout.ts`, …) extend these.
11
- */
12
-
13
- import type { TStyle } from './unknown';
14
-
15
- /**
16
- * One translatable / typed field as returned by the backend. The backend
17
- * stores `{ content, meta?, type?, id?, default? }` per field; we keep
18
- * the same shape so the renderer can simply read `field.content`.
19
- */
20
- export interface IContentField<T> {
21
- content: T;
22
- meta?: string;
23
- type?: string;
24
- id?: string;
25
- default?: string;
26
- }
27
-
28
- /**
29
- * Common fields every style has. The discriminator is `style_name`.
30
- *
31
- * - `id` / `id_styles` / `position` / `path` come from the section row.
32
- * - `fields` is the field map (some styles also expose specific fields
33
- * directly at the top level — those are typed in the per-style interfaces).
34
- * - `css` is the web-only CSS class string. Mobile renderer reads ONLY
35
- * `css_mobile` per the project decision.
36
- * - `condition` is a JSON-Logic expression evaluated client-side for
37
- * visibility (mirrors backend `ConditionService`).
38
- * - `data_config` is an optional JSON config string used by data-bound
39
- * styles (entryList, formUserInputRecord, …).
40
- */
41
- export interface IBaseStyle {
42
- id: number;
43
- id_styles: number;
44
- style_name: string;
45
- can_have_children: number | null;
46
- position: number;
47
- path: string;
48
- children?: TStyle[];
49
- section_name: string;
50
- section_data?: unknown[];
51
- fields: Record<string, IContentField<unknown>>;
52
- condition: string | null;
53
- css: string | null;
54
- css_mobile: string | null;
55
- debug: number | null;
56
- data_config: string | number | null;
57
- condition_debug?: {
58
- condition?: string;
59
- result: boolean;
60
- error?: unknown[];
61
- variables?: Record<string, unknown>;
62
- condition_object?: unknown;
63
- } | null;
64
- }
65
-
66
- /** Styles that support the unified spacing field. */
67
- export interface IStyleWithSpacing extends IBaseStyle {
68
- /** Legacy / margin-only field still used by many Mantine styles in the DB. */
69
- mantine_spacing_margin?: IContentField<string>;
70
- /** Newer box-model field that supports both margin and padding. */
71
- mantine_spacing_margin_padding?: IContentField<string>;
72
- }
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Base interfaces shared by every CMS style. Mirrors what the backend
7
+ * `PageService` returns per section: a `style_name` discriminator, a
8
+ * `fields` map, and a handful of side-channel fields (css, condition, debug).
9
+ *
10
+ * The per-style interfaces (in `auth.ts`, `layout.ts`, …) extend these.
11
+ */
12
+
13
+ import type { TStyle } from './unknown';
14
+
15
+ /**
16
+ * One translatable / typed field as returned by the backend. The backend
17
+ * stores `{ content, meta?, type?, id?, default? }` per field; we keep
18
+ * the same shape so the renderer can simply read `field.content`.
19
+ */
20
+ export interface IContentField<T> {
21
+ content: T;
22
+ meta?: string;
23
+ type?: string;
24
+ id?: string;
25
+ default?: string;
26
+ }
27
+
28
+ /**
29
+ * Common fields every style has. The discriminator is `style_name`.
30
+ *
31
+ * - `id` / `id_styles` / `position` / `path` come from the section row.
32
+ * - `fields` is the field map (some styles also expose specific fields
33
+ * directly at the top level — those are typed in the per-style interfaces).
34
+ * - `css` is the web-only CSS class string. Mobile renderer reads ONLY
35
+ * `css_mobile` per the project decision.
36
+ * - `condition` is a JSON-Logic expression evaluated client-side for
37
+ * visibility (mirrors backend `ConditionService`).
38
+ * - `data_config` is an optional JSON config string used by data-bound
39
+ * styles (entryList, formUserInputRecord, …).
40
+ */
41
+ export interface IBaseStyle {
42
+ id: number;
43
+ id_styles: number;
44
+ style_name: string;
45
+ can_have_children: number | null;
46
+ position: number;
47
+ path: string;
48
+ children?: TStyle[];
49
+ section_name: string;
50
+ section_data?: unknown[];
51
+ fields: Record<string, IContentField<unknown>>;
52
+ condition: string | null;
53
+ css: string | null;
54
+ css_mobile: string | null;
55
+ debug: number | null;
56
+ data_config: string | number | null;
57
+ condition_debug?: {
58
+ condition?: string;
59
+ result: boolean;
60
+ error?: unknown[];
61
+ variables?: Record<string, unknown>;
62
+ condition_object?: unknown;
63
+ } | null;
64
+ }
65
+
66
+ /** Styles that support the unified spacing field. */
67
+ export interface IStyleWithSpacing extends IBaseStyle {
68
+ /** Legacy / margin-only field still used by many Mantine styles in the DB. */
69
+ mantine_spacing_margin?: IContentField<string>;
70
+ /** Newer box-model field that supports both margin and padding. */
71
+ mantine_spacing_margin_padding?: IContentField<string>;
72
+ }
@@ -1,131 +1,131 @@
1
- /*
2
- SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
- SPDX-License-Identifier: MPL-2.0
4
- */
5
- import type { IBaseStyle, IContentField, IStyleWithSpacing } from './base';
6
- import type {
7
- TMantineSize,
8
- TMantineColor,
9
- TMantineRadius,
10
- TMantineSpacing,
11
- TMantineOrientation,
12
- TMantineAccordionVariant,
13
- TMantineTabsVariant,
14
- TMantineTimelineLineVariant,
15
- } from '../mantine/common';
16
- import type { TMantineWidth, TMantineHeight } from './layout';
17
- import type { TMantineLineClamp } from './typography';
18
-
19
- export type TMantineAccordionMultiple = '0' | '1';
20
- export type TMantineAccordionChevronPosition = 'left' | 'right';
21
- export type TMantineAccordionDisableChevronRotation = '0' | '1';
22
- export type TMantineAccordionLoop = '0' | '1';
23
- export type TMantineTimelineAlign = 'left' | 'right';
24
- export type TMantineListType = 'ordered' | 'unordered';
25
- export type TMantineListStyleType =
26
- | 'none'
27
- | 'disc'
28
- | 'circle'
29
- | 'square'
30
- | 'decimal'
31
- | 'decimal-leading-zero'
32
- | 'lower-roman'
33
- | 'upper-roman'
34
- | 'lower-alpha'
35
- | 'upper-alpha'
36
- | string;
37
- export type TMantineListWithPadding = '0' | '1';
38
- export type TMantineListCenter = '0' | '1';
39
-
40
- export interface IAccordionStyle extends IStyleWithSpacing {
41
- style_name: 'accordion';
42
- mantine_accordion_variant?: IContentField<TMantineAccordionVariant>;
43
- mantine_accordion_multiple?: IContentField<TMantineAccordionMultiple>;
44
- mantine_accordion_chevron_position?: IContentField<TMantineAccordionChevronPosition>;
45
- mantine_accordion_chevron_size?: IContentField<string>;
46
- mantine_accordion_disable_chevron_rotation?: IContentField<TMantineAccordionDisableChevronRotation>;
47
- mantine_accordion_loop?: IContentField<TMantineAccordionLoop>;
48
- mantine_accordion_transition_duration?: IContentField<string>;
49
- mantine_accordion_default_value?: IContentField<string>;
50
- mantine_radius?: IContentField<TMantineRadius>;
51
- use_mantine_style?: IContentField<string>;
52
- }
53
-
54
- export interface IAccordionItemStyle extends IStyleWithSpacing {
55
- style_name: 'accordion-item';
56
- mantine_accordion_item_value?: IContentField<string>;
57
- label?: IContentField<string>;
58
- mantine_accordion_item_icon?: IContentField<string>;
59
- disabled?: IContentField<string>;
60
- use_mantine_style?: IContentField<string>;
61
- }
62
-
63
- export interface ITabsStyle extends IStyleWithSpacing {
64
- style_name: 'tabs';
65
- mantine_tabs_variant?: IContentField<TMantineTabsVariant>;
66
- mantine_tabs_orientation?: IContentField<TMantineOrientation>;
67
- mantine_tabs_radius?: IContentField<TMantineRadius>;
68
- mantine_color?: IContentField<TMantineColor>;
69
- mantine_width?: IContentField<TMantineWidth>;
70
- mantine_height?: IContentField<TMantineHeight>;
71
- use_mantine_style?: IContentField<string>;
72
- }
73
-
74
- export interface ITabStyle extends IBaseStyle {
75
- style_name: 'tab';
76
- label?: IContentField<string>;
77
- mantine_left_icon?: IContentField<string>;
78
- mantine_right_icon?: IContentField<string>;
79
- mantine_tab_disabled?: IContentField<string>;
80
- mantine_width?: IContentField<TMantineWidth>;
81
- mantine_height?: IContentField<TMantineHeight>;
82
- use_mantine_style?: IContentField<string>;
83
- }
84
-
85
- export interface ITimelineStyle extends IStyleWithSpacing {
86
- style_name: 'timeline';
87
- mantine_timeline_bullet_size?: IContentField<string>;
88
- mantine_timeline_line_width?: IContentField<string>;
89
- mantine_timeline_active?: IContentField<string>;
90
- mantine_timeline_align?: IContentField<TMantineTimelineAlign>;
91
- mantine_timeline_line_variant?: IContentField<TMantineTimelineLineVariant>;
92
- mantine_color?: IContentField<TMantineColor>;
93
- use_mantine_style?: IContentField<string>;
94
- }
95
-
96
- export interface IListStyle extends IStyleWithSpacing {
97
- style_name: 'list';
98
- mantine_list_type?: IContentField<TMantineListType>;
99
- mantine_spacing?: IContentField<TMantineSpacing>;
100
- mantine_size?: IContentField<TMantineSize>;
101
- use_mantine_style?: IContentField<string>;
102
- mantine_list_list_style_type?: IContentField<TMantineListStyleType>;
103
- mantine_list_with_padding?: IContentField<TMantineListWithPadding>;
104
- mantine_list_center?: IContentField<TMantineListCenter>;
105
- mantine_list_icon?: IContentField<string>;
106
- }
107
-
108
- export interface IListItemStyle extends IStyleWithSpacing {
109
- style_name: 'list-item';
110
- mantine_list_item_content?: IContentField<string>;
111
- mantine_list_item_icon?: IContentField<string>;
112
- use_mantine_style?: IContentField<string>;
113
- }
114
-
115
- export interface IEntryListStyle extends IBaseStyle {
116
- style_name: 'entryList';
117
- line_clamp?: IContentField<TMantineLineClamp>;
118
- }
119
-
120
- export interface IEntryRecordStyle extends IBaseStyle {
121
- style_name: 'entryRecord';
122
- }
123
-
124
- export interface IEntryRecordDeleteStyle extends IBaseStyle {
125
- style_name: 'entryRecordDelete';
126
- }
127
-
128
- export interface ILoopStyle extends IBaseStyle {
129
- style_name: 'loop';
130
- loop?: IContentField<unknown[]>;
131
- }
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import type { IBaseStyle, IContentField, IStyleWithSpacing } from './base';
6
+ import type {
7
+ TMantineSize,
8
+ TMantineColor,
9
+ TMantineRadius,
10
+ TMantineSpacing,
11
+ TMantineOrientation,
12
+ TMantineAccordionVariant,
13
+ TMantineTabsVariant,
14
+ TMantineTimelineLineVariant,
15
+ } from '../mantine/common';
16
+ import type { TMantineWidth, TMantineHeight } from './layout';
17
+ import type { TMantineLineClamp } from './typography';
18
+
19
+ export type TMantineAccordionMultiple = '0' | '1';
20
+ export type TMantineAccordionChevronPosition = 'left' | 'right';
21
+ export type TMantineAccordionDisableChevronRotation = '0' | '1';
22
+ export type TMantineAccordionLoop = '0' | '1';
23
+ export type TMantineTimelineAlign = 'left' | 'right';
24
+ export type TMantineListType = 'ordered' | 'unordered';
25
+ export type TMantineListStyleType =
26
+ | 'none'
27
+ | 'disc'
28
+ | 'circle'
29
+ | 'square'
30
+ | 'decimal'
31
+ | 'decimal-leading-zero'
32
+ | 'lower-roman'
33
+ | 'upper-roman'
34
+ | 'lower-alpha'
35
+ | 'upper-alpha'
36
+ | string;
37
+ export type TMantineListWithPadding = '0' | '1';
38
+ export type TMantineListCenter = '0' | '1';
39
+
40
+ export interface IAccordionStyle extends IStyleWithSpacing {
41
+ style_name: 'accordion';
42
+ mantine_accordion_variant?: IContentField<TMantineAccordionVariant>;
43
+ mantine_accordion_multiple?: IContentField<TMantineAccordionMultiple>;
44
+ mantine_accordion_chevron_position?: IContentField<TMantineAccordionChevronPosition>;
45
+ mantine_accordion_chevron_size?: IContentField<string>;
46
+ mantine_accordion_disable_chevron_rotation?: IContentField<TMantineAccordionDisableChevronRotation>;
47
+ mantine_accordion_loop?: IContentField<TMantineAccordionLoop>;
48
+ mantine_accordion_transition_duration?: IContentField<string>;
49
+ mantine_accordion_default_value?: IContentField<string>;
50
+ mantine_radius?: IContentField<TMantineRadius>;
51
+ use_mantine_style?: IContentField<string>;
52
+ }
53
+
54
+ export interface IAccordionItemStyle extends IStyleWithSpacing {
55
+ style_name: 'accordion-item';
56
+ mantine_accordion_item_value?: IContentField<string>;
57
+ label?: IContentField<string>;
58
+ mantine_accordion_item_icon?: IContentField<string>;
59
+ disabled?: IContentField<string>;
60
+ use_mantine_style?: IContentField<string>;
61
+ }
62
+
63
+ export interface ITabsStyle extends IStyleWithSpacing {
64
+ style_name: 'tabs';
65
+ mantine_tabs_variant?: IContentField<TMantineTabsVariant>;
66
+ mantine_tabs_orientation?: IContentField<TMantineOrientation>;
67
+ mantine_tabs_radius?: IContentField<TMantineRadius>;
68
+ mantine_color?: IContentField<TMantineColor>;
69
+ mantine_width?: IContentField<TMantineWidth>;
70
+ mantine_height?: IContentField<TMantineHeight>;
71
+ use_mantine_style?: IContentField<string>;
72
+ }
73
+
74
+ export interface ITabStyle extends IBaseStyle {
75
+ style_name: 'tab';
76
+ label?: IContentField<string>;
77
+ mantine_left_icon?: IContentField<string>;
78
+ mantine_right_icon?: IContentField<string>;
79
+ mantine_tab_disabled?: IContentField<string>;
80
+ mantine_width?: IContentField<TMantineWidth>;
81
+ mantine_height?: IContentField<TMantineHeight>;
82
+ use_mantine_style?: IContentField<string>;
83
+ }
84
+
85
+ export interface ITimelineStyle extends IStyleWithSpacing {
86
+ style_name: 'timeline';
87
+ mantine_timeline_bullet_size?: IContentField<string>;
88
+ mantine_timeline_line_width?: IContentField<string>;
89
+ mantine_timeline_active?: IContentField<string>;
90
+ mantine_timeline_align?: IContentField<TMantineTimelineAlign>;
91
+ mantine_timeline_line_variant?: IContentField<TMantineTimelineLineVariant>;
92
+ mantine_color?: IContentField<TMantineColor>;
93
+ use_mantine_style?: IContentField<string>;
94
+ }
95
+
96
+ export interface IListStyle extends IStyleWithSpacing {
97
+ style_name: 'list';
98
+ mantine_list_type?: IContentField<TMantineListType>;
99
+ mantine_spacing?: IContentField<TMantineSpacing>;
100
+ mantine_size?: IContentField<TMantineSize>;
101
+ use_mantine_style?: IContentField<string>;
102
+ mantine_list_list_style_type?: IContentField<TMantineListStyleType>;
103
+ mantine_list_with_padding?: IContentField<TMantineListWithPadding>;
104
+ mantine_list_center?: IContentField<TMantineListCenter>;
105
+ mantine_list_icon?: IContentField<string>;
106
+ }
107
+
108
+ export interface IListItemStyle extends IStyleWithSpacing {
109
+ style_name: 'list-item';
110
+ mantine_list_item_content?: IContentField<string>;
111
+ mantine_list_item_icon?: IContentField<string>;
112
+ use_mantine_style?: IContentField<string>;
113
+ }
114
+
115
+ export interface IEntryListStyle extends IBaseStyle {
116
+ style_name: 'entryList';
117
+ line_clamp?: IContentField<TMantineLineClamp>;
118
+ }
119
+
120
+ export interface IEntryRecordStyle extends IBaseStyle {
121
+ style_name: 'entryRecord';
122
+ }
123
+
124
+ export interface IEntryRecordDeleteStyle extends IBaseStyle {
125
+ style_name: 'entryRecordDelete';
126
+ }
127
+
128
+ export interface ILoopStyle extends IBaseStyle {
129
+ style_name: 'loop';
130
+ loop?: IContentField<unknown[]>;
131
+ }