@selfhelp/shared 1.21.3 → 1.21.6

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 (53) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +2 -1
  3. package/dist/index.d.mts +519 -24
  4. package/dist/index.d.ts +519 -24
  5. package/dist/index.js +723 -18
  6. package/dist/index.mjs +674 -18
  7. package/dist/plugin-sdk/index.d.mts +1 -1
  8. package/dist/plugin-sdk/index.d.ts +1 -1
  9. package/dist/plugin-sdk/index.js +2 -1
  10. package/dist/plugin-sdk/index.mjs +2 -1
  11. package/dist/registry/index.d.mts +2 -2
  12. package/dist/registry/index.d.ts +2 -2
  13. package/dist/registry/index.js +2 -1
  14. package/dist/registry/index.mjs +2 -1
  15. package/dist/{styles.registry-DEDEZ8l3.d.ts → styles.registry-DX79oirw.d.ts} +93 -16
  16. package/dist/{styles.registry-DHM4M77N.d.mts → styles.registry-ffw0MH3r.d.mts} +93 -16
  17. package/package.json +1 -1
  18. package/src/api/__tests__/endpoints.test.ts +37 -12
  19. package/src/api/endpoints.ts +5 -5
  20. package/src/api/index.ts +1 -0
  21. package/src/api/pagesResolve.ts +78 -0
  22. package/src/content/__tests__/fieldsMapLabels.test.ts +55 -0
  23. package/src/content/__tests__/formRecordPrefill.test.ts +104 -0
  24. package/src/content/__tests__/optionLabels.test.ts +100 -0
  25. package/src/content/fieldsMapLabels.ts +103 -0
  26. package/src/content/formRecordPrefill.ts +191 -0
  27. package/src/content/index.ts +3 -0
  28. package/src/content/optionLabels.ts +200 -0
  29. package/src/navigation/__tests__/navigation.test.ts +296 -6
  30. package/src/navigation/activeTrail.ts +99 -0
  31. package/src/navigation/branchNav.ts +155 -6
  32. package/src/navigation/footerPreset.ts +109 -0
  33. package/src/navigation/headerLayers.ts +56 -0
  34. package/src/navigation/headerPreset.ts +9 -2
  35. package/src/navigation/index.ts +4 -0
  36. package/src/navigation/menuDepth.ts +73 -37
  37. package/src/navigation/mobileRoute.ts +25 -0
  38. package/src/navigation/navLinks.ts +0 -4
  39. package/src/navigation/navigationBundle.ts +81 -0
  40. package/src/navigation/navigationPayload.ts +96 -17
  41. package/src/registry/__tests__/platform.test.ts +11 -10
  42. package/src/registry/styles.registry.ts +2 -1
  43. package/src/types/__tests__/preview-bridge.test.ts +7 -0
  44. package/src/types/auth.ts +4 -0
  45. package/src/types/cms-app.ts +74 -0
  46. package/src/types/index.ts +1 -0
  47. package/src/types/mobile-adapters.ts +1 -0
  48. package/src/types/pages.ts +6 -0
  49. package/src/types/preview-bridge.ts +22 -2
  50. package/src/types/styles/composite.ts +21 -0
  51. package/src/types/styles/forms.ts +57 -10
  52. package/src/types/styles/interactive.ts +1 -1
  53. package/src/types/styles/unknown.ts +2 -2
@@ -0,0 +1,100 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import { describe, expect, it } from 'vitest';
6
+ import {
7
+ parseOptionCatalog,
8
+ parseOptionCodes,
9
+ parseOptionLabels,
10
+ resolveOptionLabel,
11
+ resolveOptionValueLabels,
12
+ resolveOptions,
13
+ } from '../optionLabels';
14
+
15
+ describe('option labels helpers', () => {
16
+ it('parses language-neutral option catalog and keeps metadata', () => {
17
+ const raw = JSON.stringify([
18
+ { value: 'release', sort: 1, disabled: false, meta: { color: 'blue' } },
19
+ { value: 'feature', sort: 2 },
20
+ ]);
21
+ expect(parseOptionCatalog(raw)).toEqual([
22
+ { value: 'release', sort: 1, disabled: false, meta: { color: 'blue' } },
23
+ { value: 'feature', sort: 2 },
24
+ ]);
25
+ });
26
+
27
+ it('parses per-language labels map and ignores invalid entries', () => {
28
+ const raw = JSON.stringify({
29
+ release: 'Freigabe',
30
+ feature: ' Funktion ',
31
+ notice: '',
32
+ invalid: 12,
33
+ });
34
+ expect(parseOptionLabels(raw)).toEqual({
35
+ release: 'Freigabe',
36
+ feature: 'Funktion',
37
+ });
38
+ });
39
+
40
+ it('resolves options with label fallback to code', () => {
41
+ const catalog = JSON.stringify([
42
+ { value: 'release' },
43
+ { value: 'feature' },
44
+ ]);
45
+ const labels = JSON.stringify({
46
+ release: 'Freigabe',
47
+ });
48
+ expect(resolveOptions(catalog, labels)).toEqual([
49
+ { value: 'release', label: 'Freigabe' },
50
+ { value: 'feature', label: 'feature' },
51
+ ]);
52
+ expect(resolveOptionLabel('release', { release: 'Release' })).toBe('Release');
53
+ expect(resolveOptionLabel('notice', { release: 'Release' })).toBe('notice');
54
+ });
55
+
56
+ it('supports legacy option array with text/label while labels map is empty', () => {
57
+ const legacy = JSON.stringify([
58
+ { value: 'release', text: 'Release', description: 'Release notes' },
59
+ { value: 'feature', label: 'Feature' },
60
+ ]);
61
+ expect(resolveOptions(legacy, null)).toEqual([
62
+ {
63
+ value: 'release',
64
+ label: 'Release',
65
+ meta: { description: 'Release notes' },
66
+ },
67
+ { value: 'feature', label: 'Feature' },
68
+ ]);
69
+ });
70
+
71
+ it('uses active language, fallback language, legacy label, then code', () => {
72
+ const catalog = [
73
+ { value: 'release', text: 'Legacy release' },
74
+ { value: 'feature', label: 'Legacy feature' },
75
+ { value: 'notice' },
76
+ { value: 'other' },
77
+ ];
78
+
79
+ expect(resolveOptions(
80
+ catalog,
81
+ { release: 'Freigabe' },
82
+ { release: 'Release', feature: 'Feature', notice: 'Notice' },
83
+ )).toEqual([
84
+ { value: 'release', label: 'Freigabe' },
85
+ { value: 'feature', label: 'Feature' },
86
+ { value: 'notice', label: 'Notice' },
87
+ { value: 'other', label: 'other' },
88
+ ]);
89
+ });
90
+
91
+ it('resolves stored single and multi codes without persisting labels', () => {
92
+ expect(parseOptionCodes('release, notice')).toEqual(['release', 'notice']);
93
+ expect(parseOptionCodes(['release', '', 'notice'])).toEqual(['release', 'notice']);
94
+ expect(resolveOptionValueLabels(
95
+ 'release,notice',
96
+ { release: 'Freigabe' },
97
+ { notice: 'Notice' },
98
+ )).toEqual(['Freigabe', 'Notice']);
99
+ });
100
+ });
@@ -0,0 +1,103 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * entry-table column catalog + per-language header labels (select-style split).
7
+ */
8
+
9
+ export interface IFieldsMapStyleConfig {
10
+ catalogField: 'fields_map';
11
+ labelsField: 'fields_map_labels';
12
+ }
13
+
14
+ export const FIELDS_MAP_STYLE_CONFIG: IFieldsMapStyleConfig = {
15
+ catalogField: 'fields_map',
16
+ labelsField: 'fields_map_labels',
17
+ };
18
+
19
+ function parseJson(raw: unknown): unknown {
20
+ if (typeof raw !== 'string' || raw.trim() === '') {
21
+ return raw;
22
+ }
23
+ try {
24
+ return JSON.parse(raw);
25
+ } catch {
26
+ return raw;
27
+ }
28
+ }
29
+
30
+ /** Parse ordered field_key catalog from property `fields_map`. */
31
+ export function parseFieldsMapCatalog(raw: unknown): string[] {
32
+ const parsed = parseJson(raw);
33
+ if (!Array.isArray(parsed)) {
34
+ return [];
35
+ }
36
+
37
+ const keys: string[] = [];
38
+ for (const item of parsed) {
39
+ if (typeof item === 'string' && item.trim() !== '') {
40
+ keys.push(item.trim());
41
+ continue;
42
+ }
43
+ if (item && typeof item === 'object' && !Array.isArray(item)) {
44
+ const record = item as Record<string, unknown>;
45
+ const legacy = typeof record.field_name === 'string' ? record.field_name.trim() : '';
46
+ if (legacy !== '') {
47
+ keys.push(legacy);
48
+ }
49
+ }
50
+ }
51
+
52
+ return keys;
53
+ }
54
+
55
+ export function parseFieldsMapLabels(raw: unknown): Record<string, string> {
56
+ const parsed = parseJson(raw);
57
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
58
+ return {};
59
+ }
60
+
61
+ const labels: Record<string, string> = {};
62
+ for (const [key, value] of Object.entries(parsed)) {
63
+ if (!key || typeof value !== 'string') {
64
+ continue;
65
+ }
66
+ const trimmed = value.trim();
67
+ if (trimmed !== '') {
68
+ labels[key] = trimmed;
69
+ }
70
+ }
71
+
72
+ return labels;
73
+ }
74
+
75
+ export function resolveFieldsMapLabel(
76
+ fieldKey: string,
77
+ labels: Record<string, string>,
78
+ fallbackLabels: Record<string, string> = {},
79
+ ): string {
80
+ return labels[fieldKey] ?? fallbackLabels[fieldKey] ?? fieldKey;
81
+ }
82
+
83
+ export function serializeFieldsMapCatalog(fieldKeys: string[]): string {
84
+ const keys = fieldKeys.map((key) => key.trim()).filter((key) => key !== '');
85
+ if (keys.length === 0) {
86
+ return '';
87
+ }
88
+ return JSON.stringify(keys);
89
+ }
90
+
91
+ export function serializeFieldsMapLabels(labels: Record<string, string>): string {
92
+ const clean: Record<string, string> = {};
93
+ for (const [key, value] of Object.entries(labels)) {
94
+ const trimmed = value.trim();
95
+ if (key && trimmed !== '') {
96
+ clean[key] = trimmed;
97
+ }
98
+ }
99
+ if (Object.keys(clean).length === 0) {
100
+ return '';
101
+ }
102
+ return JSON.stringify(clean);
103
+ }
@@ -0,0 +1,191 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ /**
7
+ * Flatten server-hydrated form `section_data` into a form-record prefill map.
8
+ *
9
+ * Used by web `FormStyle` and mobile `FormUserInput` so create/edit hydration
10
+ * cannot drift between clients. The backend owns which row is present
11
+ * (`load_record_from`); this helper only reshapes that payload.
12
+ */
13
+
14
+ /** Per-language value for a translatable form field. */
15
+ export interface IFormRecordPrefillTranslatedValue {
16
+ language_id: number;
17
+ value: string;
18
+ }
19
+
20
+ export type TFormRecordPrefillFieldValue = string | IFormRecordPrefillTranslatedValue[];
21
+
22
+ export interface IFormRecordPrefill {
23
+ recordId: number | null;
24
+ values: Record<string, TFormRecordPrefillFieldValue>;
25
+ }
26
+
27
+ /** Metadata fields that are never form inputs. */
28
+ export const FORM_RECORD_PREFILL_SKIP_FIELDS: ReadonlySet<string> = new Set([
29
+ 'record_id',
30
+ 'entry_date',
31
+ 'id_users',
32
+ 'user_name',
33
+ 'user_code',
34
+ 'id_actionTriggerTypes',
35
+ 'triggerType',
36
+ 'id_languages',
37
+ 'language_locale',
38
+ 'language_name',
39
+ ]);
40
+
41
+ export interface IFormRecordPrefillChild {
42
+ name?: { content?: string } | null;
43
+ translatable?: { content?: string } | null;
44
+ }
45
+
46
+ export interface IFormRecordPrefillSection {
47
+ section_data?: unknown;
48
+ children?: IFormRecordPrefillChild[] | null;
49
+ }
50
+
51
+ function isTranslatableChild(
52
+ children: IFormRecordPrefillChild[] | null | undefined,
53
+ fieldName: string,
54
+ ): boolean {
55
+ if (!Array.isArray(children)) {
56
+ return false;
57
+ }
58
+ const child = children.find((item) => item?.name?.content === fieldName);
59
+ return child?.translatable?.content === '1';
60
+ }
61
+
62
+ function asScalarString(value: unknown): string | null {
63
+ if (value === null || value === undefined) {
64
+ return null;
65
+ }
66
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
67
+ return String(value);
68
+ }
69
+ // Nested objects/arrays are not form field values — skip.
70
+ return null;
71
+ }
72
+
73
+ /**
74
+ * Parse hydrated `section_data` rows into `{ recordId, values }`.
75
+ *
76
+ * - Missing / empty / non-array `section_data` → empty create state.
77
+ * - Rows without a numeric `record_id` are ignored.
78
+ * - Translatable fields accumulate `{ language_id, value }[]` (language id `1`
79
+ * is an Independent seed kept only until a public-language row arrives).
80
+ * - Non-translatable fields prefer language id `1`, else the first seen value.
81
+ */
82
+ export function parseFormRecordPrefill(section: IFormRecordPrefillSection): IFormRecordPrefill {
83
+ const sectionDataArray = section?.section_data;
84
+ if (!Array.isArray(sectionDataArray) || sectionDataArray.length === 0) {
85
+ return { recordId: null, values: {} };
86
+ }
87
+
88
+ const recordGroups: Record<number, Record<string, TFormRecordPrefillFieldValue>> = {};
89
+
90
+ for (const row of sectionDataArray) {
91
+ if (!row || typeof row !== 'object' || Array.isArray(row)) {
92
+ continue;
93
+ }
94
+ const record = row as Record<string, unknown>;
95
+ const rawRecordId = record.record_id;
96
+ const recordId =
97
+ typeof rawRecordId === 'number'
98
+ ? rawRecordId
99
+ : typeof rawRecordId === 'string' && rawRecordId.trim() !== '' && Number.isFinite(Number(rawRecordId))
100
+ ? Number(rawRecordId)
101
+ : null;
102
+ if (recordId === null) {
103
+ continue;
104
+ }
105
+
106
+ if (!recordGroups[recordId]) {
107
+ recordGroups[recordId] = {};
108
+ }
109
+
110
+ const languageId =
111
+ typeof record.id_languages === 'number'
112
+ ? record.id_languages
113
+ : typeof record.id_languages === 'string' && Number.isFinite(Number(record.id_languages))
114
+ ? Number(record.id_languages)
115
+ : undefined;
116
+
117
+ for (const [fieldName, fieldValue] of Object.entries(record)) {
118
+ if (FORM_RECORD_PREFILL_SKIP_FIELDS.has(fieldName)) {
119
+ continue;
120
+ }
121
+ const value = asScalarString(fieldValue);
122
+ if (value === null) {
123
+ continue;
124
+ }
125
+
126
+ const translatable = isTranslatableChild(section.children, fieldName);
127
+
128
+ if (translatable) {
129
+ if (languageId === 1) {
130
+ if (!recordGroups[recordId][fieldName]) {
131
+ recordGroups[recordId][fieldName] = value;
132
+ }
133
+ } else if (typeof languageId === 'number') {
134
+ const current = recordGroups[recordId][fieldName];
135
+ if (typeof current === 'string' || !current) {
136
+ recordGroups[recordId][fieldName] = [{ language_id: languageId, value }];
137
+ } else {
138
+ const langValues = current;
139
+ const existingIndex = langValues.findIndex((v) => v.language_id === languageId);
140
+ if (existingIndex >= 0) {
141
+ langValues[existingIndex] = { language_id: languageId, value };
142
+ } else {
143
+ langValues.push({ language_id: languageId, value });
144
+ }
145
+ }
146
+ }
147
+ } else if (languageId === 1 || !recordGroups[recordId][fieldName]) {
148
+ recordGroups[recordId][fieldName] = value;
149
+ }
150
+ }
151
+ }
152
+
153
+ const firstRecordId = Object.keys(recordGroups)[0];
154
+ if (!firstRecordId) {
155
+ return { recordId: null, values: {} };
156
+ }
157
+
158
+ const id = Number(firstRecordId);
159
+ return { recordId: id, values: recordGroups[id] ?? {} };
160
+ }
161
+
162
+ /**
163
+ * Flatten rich prefill values to plain strings for clients that do not keep
164
+ * per-language arrays (mobile). Prefers `languageId` when present, else the
165
+ * first translated entry, else the Independent seed string.
166
+ */
167
+ export function flattenFormRecordPrefillValues(
168
+ values: Record<string, TFormRecordPrefillFieldValue>,
169
+ languageId?: number | null,
170
+ ): Record<string, string> {
171
+ const out: Record<string, string> = {};
172
+ for (const [key, value] of Object.entries(values)) {
173
+ if (typeof value === 'string') {
174
+ out[key] = value;
175
+ continue;
176
+ }
177
+ if (!Array.isArray(value) || value.length === 0) {
178
+ continue;
179
+ }
180
+ if (languageId != null) {
181
+ const match = value.find((entry) => entry.language_id === languageId);
182
+ if (match) {
183
+ out[key] = match.value;
184
+ continue;
185
+ }
186
+ }
187
+ const nonIndependent = value.find((entry) => entry.language_id !== 1);
188
+ out[key] = (nonIndependent ?? value[0]).value;
189
+ }
190
+ return out;
191
+ }
@@ -3,3 +3,6 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  export * from './inlineFormat';
6
+ export * from './optionLabels';
7
+ export * from './fieldsMapLabels';
8
+ export * from './formRecordPrefill';
@@ -0,0 +1,200 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Cross-platform helpers for user-owned option catalogs in CMS styles.
7
+ *
8
+ * The selected data row stores only stable option codes; labels are resolved
9
+ * per language from translatable style config fields.
10
+ */
11
+
12
+ export interface IOptionCatalogEntry {
13
+ value: string;
14
+ sort?: number;
15
+ disabled?: boolean;
16
+ meta?: Record<string, unknown>;
17
+ /**
18
+ * Compatibility-only label carried by legacy `{ value, text|label }`
19
+ * catalogs. New catalogs keep labels in the translatable `option_labels`
20
+ * field instead.
21
+ */
22
+ legacyLabel?: string;
23
+ }
24
+
25
+ export interface IOptionLabelMap {
26
+ [code: string]: string;
27
+ }
28
+
29
+ export interface IResolvedOption {
30
+ value: string;
31
+ label: string;
32
+ sort?: number;
33
+ disabled?: boolean;
34
+ meta?: Record<string, unknown>;
35
+ }
36
+
37
+ export interface IOptionStyleConfig {
38
+ catalogField: 'options' | 'radio_options' | 'combobox_options' | 'segmented_control_data';
39
+ multipleField?: 'is_multiple' | 'web_combobox_multi_select';
40
+ }
41
+
42
+ /**
43
+ * Option-bearing core styles and the fields that define their catalogs.
44
+ * Boolean `checkbox` is intentionally absent because it is not an enum group.
45
+ */
46
+ export const OPTION_STYLE_CONFIGS = {
47
+ select: {
48
+ catalogField: 'options',
49
+ multipleField: 'is_multiple',
50
+ },
51
+ radio: {
52
+ catalogField: 'radio_options',
53
+ },
54
+ combobox: {
55
+ catalogField: 'combobox_options',
56
+ multipleField: 'web_combobox_multi_select',
57
+ },
58
+ 'segmented-control': {
59
+ catalogField: 'segmented_control_data',
60
+ },
61
+ } as const satisfies Record<string, IOptionStyleConfig>;
62
+
63
+ export type TOptionStyleName = keyof typeof OPTION_STYLE_CONFIGS;
64
+
65
+ function parseJson(raw: unknown): unknown {
66
+ if (typeof raw !== 'string' || raw.trim() === '') {
67
+ return raw;
68
+ }
69
+ try {
70
+ return JSON.parse(raw);
71
+ } catch {
72
+ return raw;
73
+ }
74
+ }
75
+
76
+ function toString(value: unknown): string | null {
77
+ if (typeof value !== 'string') return null;
78
+ const trimmed = value.trim();
79
+ return trimmed === '' ? null : trimmed;
80
+ }
81
+
82
+ /**
83
+ * Parse option catalog from style field content.
84
+ *
85
+ * Supports both current legacy shape (`[{ value, text|label }]`) and the new
86
+ * language-neutral base shape (`[{ value, sort, disabled, meta }]`).
87
+ */
88
+ export function parseOptionCatalog(raw: unknown): IOptionCatalogEntry[] {
89
+ const parsed = parseJson(raw);
90
+ if (!Array.isArray(parsed)) return [];
91
+
92
+ const entries: IOptionCatalogEntry[] = [];
93
+ for (const item of parsed) {
94
+ if (item == null || typeof item !== 'object') continue;
95
+ const record = item as Record<string, unknown>;
96
+ const value = toString(record.value);
97
+ if (!value) continue;
98
+ const explicitMeta = record.meta
99
+ && typeof record.meta === 'object'
100
+ && !Array.isArray(record.meta)
101
+ ? record.meta as Record<string, unknown>
102
+ : {};
103
+ const legacyDescription = toString(record.description);
104
+ const meta = legacyDescription && explicitMeta.description === undefined
105
+ ? { ...explicitMeta, description: legacyDescription }
106
+ : explicitMeta;
107
+ entries.push({
108
+ value,
109
+ ...(typeof record.sort === 'number' ? { sort: record.sort } : {}),
110
+ ...(typeof record.disabled === 'boolean' ? { disabled: record.disabled } : {}),
111
+ ...(Object.keys(meta).length > 0 ? { meta } : {}),
112
+ ...(toString(record.label) ?? toString(record.text)
113
+ ? { legacyLabel: toString(record.label) ?? toString(record.text) ?? undefined }
114
+ : {}),
115
+ });
116
+ }
117
+ return entries;
118
+ }
119
+
120
+ /**
121
+ * Parse per-language labels map (`code -> label`) from a translatable style
122
+ * field value.
123
+ */
124
+ export function parseOptionLabels(raw: unknown): IOptionLabelMap {
125
+ const parsed = parseJson(raw);
126
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
127
+ return {};
128
+ }
129
+ const labels: IOptionLabelMap = {};
130
+ for (const [key, value] of Object.entries(parsed)) {
131
+ if (!key || typeof value !== 'string') continue;
132
+ const trimmed = value.trim();
133
+ if (trimmed !== '') {
134
+ labels[key] = trimmed;
135
+ }
136
+ }
137
+ return labels;
138
+ }
139
+
140
+ export function resolveOptionLabel(
141
+ code: string | null | undefined,
142
+ labels: IOptionLabelMap,
143
+ fallbackLabels: IOptionLabelMap = {},
144
+ legacyLabel?: string,
145
+ ): string {
146
+ if (!code) return '';
147
+ return labels[code] ?? fallbackLabels[code] ?? legacyLabel ?? code;
148
+ }
149
+
150
+ export function resolveOptions(
151
+ catalogRaw: unknown,
152
+ labelsRaw: unknown,
153
+ fallbackLabelsRaw?: unknown,
154
+ ): IResolvedOption[] {
155
+ const catalog = parseOptionCatalog(catalogRaw);
156
+ const labels = parseOptionLabels(labelsRaw);
157
+ const fallbackLabels = parseOptionLabels(fallbackLabelsRaw);
158
+
159
+ return catalog.map((entry) => ({
160
+ value: entry.value,
161
+ label: resolveOptionLabel(entry.value, labels, fallbackLabels, entry.legacyLabel),
162
+ ...(entry.sort !== undefined ? { sort: entry.sort } : {}),
163
+ ...(entry.disabled !== undefined ? { disabled: entry.disabled } : {}),
164
+ ...(entry.meta ? { meta: entry.meta } : {}),
165
+ }));
166
+ }
167
+
168
+ export function resolveOptionCodesLabels(
169
+ codes: string[],
170
+ labels: IOptionLabelMap,
171
+ fallbackLabels: IOptionLabelMap = {},
172
+ ): string[] {
173
+ return codes
174
+ .map((code) => resolveOptionLabel(code, labels, fallbackLabels))
175
+ .filter((label) => label !== '');
176
+ }
177
+
178
+ /** Normalize a stored single value, comma-separated multi value, or array. */
179
+ export function parseOptionCodes(value: unknown): string[] {
180
+ const rawCodes = Array.isArray(value)
181
+ ? value
182
+ : (typeof value === 'string' ? value.split(',') : []);
183
+
184
+ return rawCodes
185
+ .filter((code): code is string => typeof code === 'string')
186
+ .map((code) => code.trim())
187
+ .filter((code) => code !== '');
188
+ }
189
+
190
+ export function resolveOptionValueLabels(
191
+ value: unknown,
192
+ labelsRaw: unknown,
193
+ fallbackLabelsRaw?: unknown,
194
+ ): string[] {
195
+ return resolveOptionCodesLabels(
196
+ parseOptionCodes(value),
197
+ parseOptionLabels(labelsRaw),
198
+ parseOptionLabels(fallbackLabelsRaw),
199
+ );
200
+ }