@yomotech/view-toolkit 1.0.42 → 1.0.43
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.
- package/fesm2022/yomotech-view-toolkit-catalog.mjs +659 -1
- package/fesm2022/yomotech-view-toolkit-catalog.mjs.map +1 -1
- package/fesm2022/yomotech-view-toolkit.mjs +921 -93
- package/fesm2022/yomotech-view-toolkit.mjs.map +1 -1
- package/package.json +1 -1
- package/types/yomotech-view-toolkit-catalog.d.ts +205 -2
- package/types/yomotech-view-toolkit.d.ts +247 -7
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-24
|
|
2
|
+
// - new: controlChoicesFor - the controls a field can be switched to in the Designer (plain text also as check box,
|
|
3
|
+
// switch, radio buttons, dropdown); the editor keeps no list of its own (review of Shuaib's c157aa5c)
|
|
4
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-24
|
|
5
|
+
// - new: DATA_OBJECT_NAME_PLACES / renameDataObject - where a page names a data object, a rename changes all
|
|
6
|
+
// - new: DATA_OBJECT_KEYS / DATA_OBJECT_PLACES - a data object holds names and types; where the rest is set
|
|
1
7
|
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-18
|
|
2
8
|
// - new: the period - type dateRange (stored [from, to]) with its control dateRangepicker, the date
|
|
3
9
|
// keyboard, placeholder and the date display settings (#166 E4)
|
|
@@ -100,11 +106,134 @@ function controlsFor(schema, fallback, option) {
|
|
|
100
106
|
const labels = { textInput: 'Text field', textArea: 'Text area', dateTimepicker: 'Date and time picker', dateRangepicker: 'Date range picker', radiobutton: 'Radio buttons', datepicker: 'Date picker', timepicker: 'Time picker', output: 'Read-only output', creditCard: 'Credit card', quantity: 'Quantity' };
|
|
101
107
|
return values.map(value => ({ value, label: labels[value] || value[0].toUpperCase() + value.slice(1) }));
|
|
102
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The controls a field can be switched to in the Designer (decision 2026-10-24: the editor keeps no list of its
|
|
111
|
+
* own): those that fit now (controlsFor) and those that fit once the field is set up for them - a plain text as
|
|
112
|
+
* check box or switch (it then becomes a two-state flag) or as radio buttons or dropdown (it then needs its
|
|
113
|
+
* values); a list of two texts as check box or switch. "Read-only output" is no choice here - read only is set
|
|
114
|
+
* with protected.
|
|
115
|
+
*/
|
|
116
|
+
function controlChoicesFor(schema, fallback, option) {
|
|
117
|
+
const s = schema || {};
|
|
118
|
+
const declared = String(s["type"] || fallback || '').toLowerCase();
|
|
119
|
+
const plainText = declared === 'string' && baseType(s, fallback) === 'string' && !effectiveFormat(s, fallback, {});
|
|
120
|
+
const fieldData = { ...((option || {}).fieldData || {}) };
|
|
121
|
+
if (plainText)
|
|
122
|
+
delete fieldData.format; // the choices of the field itself, not of a choice already made
|
|
123
|
+
const choices = controlsFor(s, fallback, { ...(option || {}), fieldData }).filter(c => c.value !== 'output');
|
|
124
|
+
const add = (...values) => {
|
|
125
|
+
for (const value of values)
|
|
126
|
+
if (!choices.some(c => c.value === value))
|
|
127
|
+
choices.push(controlLabel(value));
|
|
128
|
+
};
|
|
129
|
+
if (plainText && Array.isArray(s["enum"])) {
|
|
130
|
+
if (s["enum"].length === 2 && s["enum"].every((v) => typeof v === 'string'))
|
|
131
|
+
add('checkbox', 'switch');
|
|
132
|
+
}
|
|
133
|
+
else if (plainText) {
|
|
134
|
+
add('checkbox', 'switch', 'radiobutton', 'dropdown');
|
|
135
|
+
}
|
|
136
|
+
return choices;
|
|
137
|
+
}
|
|
138
|
+
/** A control with its label as the catalog names it. */
|
|
139
|
+
function controlLabel(value) {
|
|
140
|
+
const labels = { textInput: 'Text field', textArea: 'Text area', dateTimepicker: 'Date and time picker', dateRangepicker: 'Date range picker', radiobutton: 'Radio buttons', datepicker: 'Date picker', timepicker: 'Time picker', output: 'Read-only output', creditCard: 'Credit card', quantity: 'Quantity' };
|
|
141
|
+
return { value, label: labels[value] || value[0].toUpperCase() + value.slice(1) };
|
|
142
|
+
}
|
|
103
143
|
const canonicalControl = (c) => ({ textfield: 'textInput', textarea: 'textArea', radioButton: 'radiobutton', datetimepicker: 'dateTimepicker', daterangepicker: 'dateRangepicker', date: 'datepicker', time: 'timepicker' }[c] || c);
|
|
104
144
|
// ---------------------------------------------------------------------------------------------
|
|
105
145
|
// Data types, controls, placeholder and keyboard
|
|
106
146
|
// ---------------------------------------------------------------------------------------------
|
|
107
147
|
/** The data types of a property after its aliases. */
|
|
148
|
+
/**
|
|
149
|
+
* A data object (objects/*.json) holds names and types only (decision 2026-10-24): each property has
|
|
150
|
+
* just these keys. Everything else is set on the layout field - DATA_OBJECT_PLACES says where.
|
|
151
|
+
*/
|
|
152
|
+
const DATA_OBJECT_KEYS = ['type'];
|
|
153
|
+
/** Where what older data objects carried is set now: on the layout field that shows the property. */
|
|
154
|
+
const DATA_OBJECT_PLACES = {
|
|
155
|
+
caption: 'label.caption',
|
|
156
|
+
placeholder: 'option.placeholder',
|
|
157
|
+
tooltip: 'option.tooltip',
|
|
158
|
+
required: 'option.required',
|
|
159
|
+
validation: 'option.required, option.fieldData.validation (minLength, maxLength, pattern, minimum, maximum)',
|
|
160
|
+
value: 'option.fieldData.default (start value; a placeholder such as {{quantity}} or {{id}} too)',
|
|
161
|
+
default: 'option.fieldData.default',
|
|
162
|
+
data: 'option.fieldData.validation.enum and option.labels (a fixed list of choices)',
|
|
163
|
+
loginUser: 'option.fromUser (the placeholder is taken from the signed-in user)',
|
|
164
|
+
currency: 'option.numberStyle "currency" and option.fieldData.currency',
|
|
165
|
+
decimalPoint: 'option.decimals',
|
|
166
|
+
format: 'option.displayFormat "custom" and option.customDisplayFormat (a date pattern)',
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Where a page names a data object (objects/<name>.json) - a rename has to change every one of them,
|
|
170
|
+
* the Designer's rename and the AI contract use this list. The app's test flows name fields by their
|
|
171
|
+
* property alone, without the data object.
|
|
172
|
+
*/
|
|
173
|
+
const DATA_OBJECT_NAME_PLACES = {
|
|
174
|
+
'scope.reference': 'a field or column: #/<name>/properties/<property>',
|
|
175
|
+
'option.property_url': 'the data objects a page loads: objects/<name>.json (one text or a list)',
|
|
176
|
+
'option.propertyKey': 'the data object a sign-in or register form sends',
|
|
177
|
+
'option.innerAction.from / to': 'the data objects of a calculation such as copy ({ action, from, to })',
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Renames the data object oldName to newName at every place of DATA_OBJECT_NAME_PLACES inside a page
|
|
181
|
+
* layout (changed in place). Returns how many values were changed.
|
|
182
|
+
*/
|
|
183
|
+
function renameDataObject(layout, oldName, newName) {
|
|
184
|
+
if (!oldName || !newName || oldName === newName)
|
|
185
|
+
return 0;
|
|
186
|
+
const file = `objects/${oldName}.json`;
|
|
187
|
+
const fileNew = `objects/${newName}.json`;
|
|
188
|
+
const refOld = `#/${oldName}/`;
|
|
189
|
+
let changed = 0;
|
|
190
|
+
const renameFile = (value) => value.endsWith(file) && (value === file || value.endsWith('/' + file))
|
|
191
|
+
? value.slice(0, value.length - file.length) + fileNew : value;
|
|
192
|
+
const walk = (node) => {
|
|
193
|
+
if (Array.isArray(node)) {
|
|
194
|
+
node.forEach(walk);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (!node || typeof node !== 'object')
|
|
198
|
+
return;
|
|
199
|
+
for (const key of Object.keys(node)) {
|
|
200
|
+
const value = node[key];
|
|
201
|
+
if (key === 'reference' && typeof value === 'string' && value.startsWith(refOld)) {
|
|
202
|
+
node[key] = `#/${newName}/` + value.slice(refOld.length);
|
|
203
|
+
changed++;
|
|
204
|
+
}
|
|
205
|
+
else if (key === 'property_url' && typeof value === 'string' && renameFile(value) !== value) {
|
|
206
|
+
node[key] = renameFile(value);
|
|
207
|
+
changed++;
|
|
208
|
+
}
|
|
209
|
+
else if (key === 'property_url' && Array.isArray(value)) {
|
|
210
|
+
value.forEach((item, i) => {
|
|
211
|
+
if (typeof item === 'string' && renameFile(item) !== item) {
|
|
212
|
+
value[i] = renameFile(item);
|
|
213
|
+
changed++;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else if (key === 'propertyKey' && value === oldName) {
|
|
218
|
+
node[key] = newName;
|
|
219
|
+
changed++;
|
|
220
|
+
}
|
|
221
|
+
else if ((key === 'innerAction' || key === 'action') && value && typeof value === 'object' && !Array.isArray(value)) {
|
|
222
|
+
for (const end of ['from', 'to'])
|
|
223
|
+
if (value[end] === oldName) {
|
|
224
|
+
value[end] = newName;
|
|
225
|
+
changed++;
|
|
226
|
+
}
|
|
227
|
+
walk(value);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
walk(value);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
walk(layout);
|
|
235
|
+
return changed;
|
|
236
|
+
}
|
|
108
237
|
const BASIC_TYPES = ['string', 'number', 'integer', 'bigdecimal', 'boolean', 'date', 'time', 'datetime', 'dateRange', 'media', 'array'];
|
|
109
238
|
/** Older or other names of a data type and the type they mean. */
|
|
110
239
|
const TYPE_ALIASES = { daterange: 'dateRange', image: 'media', checkbox: 'boolean', 'date-time': 'datetime', 'date&time': 'datetime', decimal: 'bigdecimal' };
|
|
@@ -660,6 +789,535 @@ function checkExpect(e, n, add) {
|
|
|
660
789
|
add('unknownFramePart', n, { part: String(e.inFrame) });
|
|
661
790
|
}
|
|
662
791
|
|
|
792
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-23
|
|
793
|
+
// - new: start page, roles and storage of the sign-in (OFFENE-PUNKTE 109): the start page is center.option
|
|
794
|
+
// and holds for every sign-in setting; a role may have its own start page (login.roles, in the
|
|
795
|
+
// Designer's order), without one - or an unknown role - the general start page holds. roleKey says where
|
|
796
|
+
// the role stands: a field of the sign-in answer (JWT) or a claim of the token (Keycloak
|
|
797
|
+
// "realm_access.roles", Okta "groups"); several roles: the first role in login.roles that the user has.
|
|
798
|
+
// loginPage is the page before the sign-in (hotel: the sign-in form), no role. storage: localStorage
|
|
799
|
+
// (stay signed in) or sessionStorage (signed out when the app closes). login written as a plain string
|
|
800
|
+
// ('optional', the first form) is still read.
|
|
801
|
+
// - new: pagination for the whole app with the page overriding single values (decision 2026-10-23):
|
|
802
|
+
// placement (top | bottom), align (left | center | right | split), defaultPageSize, pageSizeOptions,
|
|
803
|
+
// pageSize (offer the size choice). paginationFor(main, page): page, then Main, then the default; the old
|
|
804
|
+
// page keys top / bottom / position are read until the apps are converted
|
|
805
|
+
// - new: startPage, startPageFor, rolesOf, paginationFor
|
|
806
|
+
// - change: a language entry has no icon (flag is not registered in the app, and a flag is no language)
|
|
807
|
+
// - new: appSettings.menu (decision 2026-10-24, "variant 3"): the setting entries stay automatic, but Main
|
|
808
|
+
// decides the folder's caption (menu.caption, default "Setting", a text of the app) and every entry's order
|
|
809
|
+
// and on/off (menu.entries, MENU_ENTRY_KINDS), and an entry's own caption instead of its fixed text; on/off
|
|
810
|
+
// only for Home, Languages, Project Version - Login, Pagination Type and Terms are decided in their own
|
|
811
|
+
// building block (MENU_SWITCHABLE, MENU_DECIDED_BY: one place per decision);
|
|
812
|
+
// appSettingsMenu follows it
|
|
813
|
+
// - new: appSettingsMenu - the entries the library adds to the side menu by itself (OFFENE-PUNKTE 106/108):
|
|
814
|
+
// Home, Project Version, Languages (more than one), Login (sign-in at any time, not signed in), Pagination
|
|
815
|
+
// Type (the user may choose), Terms & Conditions (switched on) - into the top-level folder "Setting", or a
|
|
816
|
+
// folder "Setting" at the end. Captions are the English keys the language files translate
|
|
817
|
+
// - new: pagination.caption, the label beside the size choice, for the whole app and per page (the page's own wins)
|
|
818
|
+
// - change: the default type of a list is scroll (decision of the user 2026-10-23)
|
|
819
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-23
|
|
820
|
+
// - new: the app settings catalog - the ONE place that says which app-wide settings an app has, which
|
|
821
|
+
// values they take, their defaults and where they stand in the Main layout (main/layout_schema.json),
|
|
822
|
+
// like the field catalog for the fields (#166, OFFENE-PUNKTE 106/108). The Designer (Main: Login,
|
|
823
|
+
// Pagination, Terms & Conditions), the runtime and the AI contract (capabilities.json, validator) are to
|
|
824
|
+
// read it from here instead of keeping their own copies. No Angular, no texts - the Designer keeps its
|
|
825
|
+
// texts under these keys.
|
|
826
|
+
// Taken over from the Designer's app-settings.store.ts (shuaib 56615e0 / 4627a44):
|
|
827
|
+
// - center.appSettings: login, pagination, terms
|
|
828
|
+
// - the sign-in method comes from the Configuration (environment.login.type) and writes its flag into
|
|
829
|
+
// center.option (keycloakLogin / oktaLogin / jwtLogin) when the sign-in is required at the start
|
|
830
|
+
// It only describes, reads and checks; nothing renders from it yet.
|
|
831
|
+
/** The building blocks of the app settings in Main, in the order they are shown. */
|
|
832
|
+
const APP_SETTING_BLOCKS = ['startPage', 'login', 'pagination', 'terms', 'menu'];
|
|
833
|
+
/** The entries the library may add to the side menu, in their default order (appSettings.menu.entries). */
|
|
834
|
+
const MENU_ENTRY_KINDS = ['home', 'languages', 'login', 'paginationType', 'terms', 'projectVersion'];
|
|
835
|
+
/**
|
|
836
|
+
* The entries Main switches on or off in the menu settings. The others are decided where they belong - one
|
|
837
|
+
* place per decision: Login by login.when (at any time), Pagination Type by pagination.userChoice, Terms &
|
|
838
|
+
* Conditions by terms.enabled; their "on" in menu.entries is not read.
|
|
839
|
+
*/
|
|
840
|
+
const MENU_SWITCHABLE = ['home', 'languages', 'projectVersion'];
|
|
841
|
+
/** Where the other entries are decided: the building block of the app settings. */
|
|
842
|
+
const MENU_DECIDED_BY = { login: 'login', paginationType: 'pagination', terms: 'terms' };
|
|
843
|
+
/** When the user signs in: never, at any time (menu entry), required at the start. */
|
|
844
|
+
const LOGIN_WHEN = ['none', 'optional', 'start'];
|
|
845
|
+
/** Where the sign-in answer is kept: stay signed in, or signed out when the app closes. */
|
|
846
|
+
const LOGIN_STORAGES = ['localStorage', 'sessionStorage'];
|
|
847
|
+
/** The sign-in methods of the Configuration (environment.login.type) and the flag each writes into center.option. */
|
|
848
|
+
const LOGIN_METHODS = {
|
|
849
|
+
keycloak: { method: 'keycloak', flag: 'keycloakLogin' },
|
|
850
|
+
oktaAuth: { method: 'okta', flag: 'oktaLogin' },
|
|
851
|
+
jwtToken: { method: 'jwt', flag: 'jwtLogin' },
|
|
852
|
+
};
|
|
853
|
+
/** All flags a sign-in at the start may set in center.option. */
|
|
854
|
+
const LOGIN_FLAGS = Object.values(LOGIN_METHODS).map(m => m.flag);
|
|
855
|
+
/** The keys of center.option that describe a page (the start page, a role's page, the page before the sign-in). */
|
|
856
|
+
const START_PAGE_KEYS = [
|
|
857
|
+
'action', 'visible', 'layout_url', 'property_url', 'data_url', 'dataKey', 'storageType',
|
|
858
|
+
'protected', 'setImageUrl', 'passToken', 'form', 'card', 'grid', 'modal',
|
|
859
|
+
];
|
|
860
|
+
/** How a list pages: page by page with a bar, or loading the next page while scrolling. */
|
|
861
|
+
const PAGINATION_TYPES = ['numbered', 'scroll'];
|
|
862
|
+
/** Where the page bar stands and how it is aligned. */
|
|
863
|
+
const PAGINATION_PLACEMENTS = ['top', 'bottom'];
|
|
864
|
+
const PAGINATION_ALIGNS = ['left', 'center', 'right', 'split'];
|
|
865
|
+
/** The documents of Terms & Conditions and how each is given: written text, a link, a PDF. */
|
|
866
|
+
const TERMS_DOCUMENTS = ['imprint', 'privacy', 'agb'];
|
|
867
|
+
const DOCUMENT_KINDS = ['text', 'link', 'pdf'];
|
|
868
|
+
/** Where the app settings stand in main/layout_schema.json; the start page is center.option. */
|
|
869
|
+
const APP_SETTINGS_PATH = 'center.appSettings';
|
|
870
|
+
const START_PAGE_PATH = 'center.option';
|
|
871
|
+
/** Every app setting, with its values and default. The start page itself is center.option (START_PAGE_KEYS). */
|
|
872
|
+
const APP_SETTINGS = [
|
|
873
|
+
{ block: 'login', key: 'login.when', kind: 'choice', values: LOGIN_WHEN, default: 'none' },
|
|
874
|
+
{ block: 'login', key: 'login.storage', kind: 'choice', values: LOGIN_STORAGES, default: 'localStorage' },
|
|
875
|
+
{ block: 'login', key: 'login.roleKey', kind: 'text', default: '' },
|
|
876
|
+
{ block: 'login', key: 'login.roles', kind: 'pages', default: {} },
|
|
877
|
+
{ block: 'login', key: 'login.loginPage', kind: 'page', default: null },
|
|
878
|
+
// scroll: the user's decision 2026-10-23 for every app
|
|
879
|
+
{ block: 'pagination', key: 'pagination.default', kind: 'choice', values: PAGINATION_TYPES, default: 'scroll' },
|
|
880
|
+
{ block: 'pagination', key: 'pagination.userChoice', kind: 'flag', default: false },
|
|
881
|
+
{ block: 'pagination', key: 'pagination.placement', kind: 'choice', values: PAGINATION_PLACEMENTS, default: 'bottom' },
|
|
882
|
+
{ block: 'pagination', key: 'pagination.align', kind: 'choice', values: PAGINATION_ALIGNS, default: 'center' },
|
|
883
|
+
// the sizes the reference apps use (luv2shop, tm-test)
|
|
884
|
+
{ block: 'pagination', key: 'pagination.defaultPageSize', kind: 'number', default: 5 },
|
|
885
|
+
{ block: 'pagination', key: 'pagination.pageSizeOptions', kind: 'numbers', default: [5, 10, 15, 20] },
|
|
886
|
+
{ block: 'pagination', key: 'pagination.pageSize', kind: 'flag', default: true },
|
|
887
|
+
// the label beside the size choice ("Page Size") - a text of the app, translated in the language editor
|
|
888
|
+
{ block: 'pagination', key: 'pagination.caption', kind: 'text', default: '' },
|
|
889
|
+
{ block: 'terms', key: 'terms.enabled', kind: 'flag', default: false },
|
|
890
|
+
{ block: 'terms', key: 'terms.confirmOnStart', kind: 'flag', default: false },
|
|
891
|
+
{ block: 'terms', key: 'terms.documents', kind: 'documents', values: TERMS_DOCUMENTS, default: {} },
|
|
892
|
+
// the state of the terms - a new one asks everybody again (without a backend this one counts)
|
|
893
|
+
{ block: 'terms', key: 'terms.version', kind: 'text', default: '' },
|
|
894
|
+
// keep the acceptance in the app's backend too (after the sign-in): ask for the state, send an acceptance
|
|
895
|
+
{ block: 'terms', key: 'terms.backend.enabled', kind: 'flag', default: false },
|
|
896
|
+
{ block: 'terms', key: 'terms.backend.statusUrl', kind: 'text', default: '' },
|
|
897
|
+
{ block: 'terms', key: 'terms.backend.acceptUrl', kind: 'text', default: '' },
|
|
898
|
+
// the folder of the entries the library adds - its caption is a text of the app like any caption
|
|
899
|
+
{ block: 'menu', key: 'menu.caption', kind: 'text', default: 'Setting' },
|
|
900
|
+
{ block: 'menu', key: 'menu.entries', kind: 'entries', values: MENU_ENTRY_KINDS, default: MENU_ENTRY_KINDS.map(kind => ({ kind, on: true, caption: '' })) },
|
|
901
|
+
];
|
|
902
|
+
const defaultOf = (key) => APP_SETTINGS.find(s => s.key === key)?.default;
|
|
903
|
+
const isIn = (list, value) => list.includes(value);
|
|
904
|
+
// a plain check, no type guard: the values stay `any`, so the library's noPropertyAccessFromIndexSignature
|
|
905
|
+
// does not demand ['key'] for every setting read
|
|
906
|
+
const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
907
|
+
const isSize = (value) => Number.isInteger(value) && value > 0;
|
|
908
|
+
const isSizes = (value) => Array.isArray(value) && value.length > 0 && value.every(isSize);
|
|
909
|
+
/** The sign-in method of a Configuration (environment.json "environment") and its flag; null without one. */
|
|
910
|
+
function loginMethod(environment) {
|
|
911
|
+
return LOGIN_METHODS[environment?.login?.type] ?? null;
|
|
912
|
+
}
|
|
913
|
+
/** Only the page keys of an option object (center.option, a role's page, the page before the sign-in). */
|
|
914
|
+
function pageOf(option) {
|
|
915
|
+
const page = {};
|
|
916
|
+
if (!isObject(option))
|
|
917
|
+
return page;
|
|
918
|
+
for (const key of START_PAGE_KEYS)
|
|
919
|
+
if (option[key] !== undefined)
|
|
920
|
+
page[key] = option[key];
|
|
921
|
+
return page;
|
|
922
|
+
}
|
|
923
|
+
/** The general start page of a Main layout: the page keys of center.option. */
|
|
924
|
+
function startPage(layout) {
|
|
925
|
+
return pageOf(layout?.center?.option);
|
|
926
|
+
}
|
|
927
|
+
/** A value at a dotted path ("realm_access.roles"); undefined when a step is missing. */
|
|
928
|
+
function valueAt(source, path) {
|
|
929
|
+
return String(path || '').split('.').filter(Boolean).reduce((node, part) => node?.[part], source);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* The roles of a signed-in user: what stands at roleKey in the sign-in answer or the token's claims - a
|
|
933
|
+
* text or a list. Empty without roleKey or user.
|
|
934
|
+
*/
|
|
935
|
+
function rolesOf(user, roleKey) {
|
|
936
|
+
if (!user || !roleKey)
|
|
937
|
+
return [];
|
|
938
|
+
const value = valueAt(user, roleKey);
|
|
939
|
+
const list = Array.isArray(value) ? value : value === undefined || value === null || value === '' ? [] : [value];
|
|
940
|
+
return list.map(v => String(v));
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* The start page for a signed-in user: the page of the first role in login.roles (the Designer's order) the
|
|
944
|
+
* user has, compared without case; else the general start page.
|
|
945
|
+
*/
|
|
946
|
+
function startPageFor(layout, user) {
|
|
947
|
+
const { login } = readAppSettings(layout);
|
|
948
|
+
const mine = rolesOf(user, login.roleKey).map(r => r.toLowerCase());
|
|
949
|
+
for (const [role, page] of Object.entries(login.roles)) {
|
|
950
|
+
if (mine.includes(role.toLowerCase()))
|
|
951
|
+
return { action: 'get', visible: true, ...pageOf(page) };
|
|
952
|
+
}
|
|
953
|
+
return startPage(layout);
|
|
954
|
+
}
|
|
955
|
+
/** The pagination keys a page or Main writes - the old page keys top / bottom / position translated. */
|
|
956
|
+
function paginationValues(source) {
|
|
957
|
+
const values = {};
|
|
958
|
+
if (!isObject(source))
|
|
959
|
+
return values;
|
|
960
|
+
if (isIn(PAGINATION_TYPES, source.default))
|
|
961
|
+
values.default = source.default;
|
|
962
|
+
if (typeof source.userChoice === 'boolean')
|
|
963
|
+
values.userChoice = source.userChoice;
|
|
964
|
+
if (isIn(PAGINATION_PLACEMENTS, source.placement))
|
|
965
|
+
values.placement = source.placement;
|
|
966
|
+
else if (source.top === true)
|
|
967
|
+
values.placement = 'top';
|
|
968
|
+
else if (source.bottom === true)
|
|
969
|
+
values.placement = 'bottom';
|
|
970
|
+
if (isIn(PAGINATION_ALIGNS, source.align))
|
|
971
|
+
values.align = source.align;
|
|
972
|
+
else if (source.position === 'space-between')
|
|
973
|
+
values.align = 'split';
|
|
974
|
+
else if (isIn(PAGINATION_ALIGNS, source.position))
|
|
975
|
+
values.align = source.position;
|
|
976
|
+
if (isSize(source.defaultPageSize))
|
|
977
|
+
values.defaultPageSize = source.defaultPageSize;
|
|
978
|
+
else if (isSize(source.pageSize))
|
|
979
|
+
values.defaultPageSize = source.pageSize;
|
|
980
|
+
if (isSizes(source.pageSizeOptions))
|
|
981
|
+
values.pageSizeOptions = [...source.pageSizeOptions];
|
|
982
|
+
if (typeof source.pageSize === 'boolean')
|
|
983
|
+
values.pageSize = source.pageSize;
|
|
984
|
+
if (typeof source.caption === 'string' && source.caption.trim())
|
|
985
|
+
values.caption = source.caption.trim();
|
|
986
|
+
return values;
|
|
987
|
+
}
|
|
988
|
+
/** The pagination of the whole app (Main), every missing or unknown value replaced by its default. */
|
|
989
|
+
function appPagination(raw) {
|
|
990
|
+
return {
|
|
991
|
+
default: defaultOf('pagination.default'),
|
|
992
|
+
userChoice: defaultOf('pagination.userChoice'),
|
|
993
|
+
placement: defaultOf('pagination.placement'),
|
|
994
|
+
align: defaultOf('pagination.align'),
|
|
995
|
+
defaultPageSize: defaultOf('pagination.defaultPageSize'),
|
|
996
|
+
pageSizeOptions: [...defaultOf('pagination.pageSizeOptions')],
|
|
997
|
+
pageSize: defaultOf('pagination.pageSize'),
|
|
998
|
+
caption: defaultOf('pagination.caption'),
|
|
999
|
+
...paginationValues(raw),
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* The pagination of one list: each value from the page (center.pagination of its layout) if it is there,
|
|
1004
|
+
* else from Main, else the default. visible: a page with center.pagination pages unless it says
|
|
1005
|
+
* visible false; a page without it does not page.
|
|
1006
|
+
*/
|
|
1007
|
+
function paginationFor(main, page) {
|
|
1008
|
+
const own = page?.center?.pagination;
|
|
1009
|
+
return {
|
|
1010
|
+
...readAppSettings(main).pagination,
|
|
1011
|
+
...paginationValues(own),
|
|
1012
|
+
visible: isObject(own) && own.visible !== false,
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* The app settings of a Main layout (main/layout_schema.json), every missing or unknown value replaced by
|
|
1017
|
+
* its default. A Main whose center.option carries a sign-in flag counts as "required at the start".
|
|
1018
|
+
*/
|
|
1019
|
+
function readAppSettings(layout) {
|
|
1020
|
+
const center = layout?.center ?? {};
|
|
1021
|
+
const raw = isObject(center.appSettings) ? center.appSettings : {};
|
|
1022
|
+
const option = center.option ?? {};
|
|
1023
|
+
// the first form wrote login as a plain string
|
|
1024
|
+
const rawLogin = typeof raw.login === 'string' ? { when: raw.login } : isObject(raw.login) ? raw.login : {};
|
|
1025
|
+
const when = LOGIN_FLAGS.some(flag => option[flag])
|
|
1026
|
+
? 'start'
|
|
1027
|
+
: isIn(LOGIN_WHEN, rawLogin.when) ? rawLogin.when : 'none';
|
|
1028
|
+
const roles = {};
|
|
1029
|
+
if (isObject(rawLogin.roles)) {
|
|
1030
|
+
for (const [role, page] of Object.entries(rawLogin.roles))
|
|
1031
|
+
if (role.trim() && isObject(page))
|
|
1032
|
+
roles[role] = pageOf(page);
|
|
1033
|
+
}
|
|
1034
|
+
const documents = {};
|
|
1035
|
+
for (const key of TERMS_DOCUMENTS) {
|
|
1036
|
+
const doc = raw.terms?.documents?.[key];
|
|
1037
|
+
const value = typeof doc?.value === 'string' ? doc.value.trim() : '';
|
|
1038
|
+
if (value)
|
|
1039
|
+
documents[key] = { kind: isIn(DOCUMENT_KINDS, doc.kind) ? doc.kind : 'text', value };
|
|
1040
|
+
}
|
|
1041
|
+
return {
|
|
1042
|
+
login: {
|
|
1043
|
+
when,
|
|
1044
|
+
storage: isIn(LOGIN_STORAGES, rawLogin.storage) ? rawLogin.storage : 'localStorage',
|
|
1045
|
+
roleKey: typeof rawLogin.roleKey === 'string' ? rawLogin.roleKey.trim() : '',
|
|
1046
|
+
roles,
|
|
1047
|
+
loginPage: isObject(rawLogin.loginPage) ? pageOf(rawLogin.loginPage) : null,
|
|
1048
|
+
},
|
|
1049
|
+
pagination: appPagination(raw.pagination),
|
|
1050
|
+
terms: {
|
|
1051
|
+
enabled: raw.terms?.enabled === true,
|
|
1052
|
+
confirmOnStart: raw.terms?.confirmOnStart === true,
|
|
1053
|
+
documents,
|
|
1054
|
+
version: typeof raw.terms?.version === 'string' ? raw.terms.version.trim() : '',
|
|
1055
|
+
backend: {
|
|
1056
|
+
enabled: raw.terms?.backend?.enabled === true,
|
|
1057
|
+
statusUrl: typeof raw.terms?.backend?.statusUrl === 'string' ? raw.terms.backend.statusUrl.trim() : '',
|
|
1058
|
+
acceptUrl: typeof raw.terms?.backend?.acceptUrl === 'string' ? raw.terms.backend.acceptUrl.trim() : '',
|
|
1059
|
+
},
|
|
1060
|
+
},
|
|
1061
|
+
menu: readMenu(raw.menu),
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
/** The setting entries in the given order; unknown kinds are left out, missing ones follow switched on. */
|
|
1065
|
+
function readMenu(raw) {
|
|
1066
|
+
const caption = typeof raw?.caption === 'string' && raw.caption.trim() ? raw.caption.trim() : 'Setting';
|
|
1067
|
+
const entries = [];
|
|
1068
|
+
for (const entry of Array.isArray(raw?.entries) ? raw.entries : []) {
|
|
1069
|
+
if (isIn(MENU_ENTRY_KINDS, entry?.kind) && !entries.some(e => e.kind === entry.kind)) {
|
|
1070
|
+
const on = MENU_SWITCHABLE.includes(entry.kind) ? entry.on !== false : true;
|
|
1071
|
+
entries.push({ kind: entry.kind, on, caption: typeof entry.caption === 'string' ? entry.caption.trim() : '' });
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
for (const kind of MENU_ENTRY_KINDS)
|
|
1075
|
+
if (!entries.some(e => e.kind === kind))
|
|
1076
|
+
entries.push({ kind, on: true, caption: '' });
|
|
1077
|
+
return { caption, entries };
|
|
1078
|
+
}
|
|
1079
|
+
const LAYOUT_URL = /^pages\/.+\/layout_schema\.json$/;
|
|
1080
|
+
/** What is wrong with a page description (start page, role page, page before the sign-in). */
|
|
1081
|
+
function checkPage(page, key, problems) {
|
|
1082
|
+
if (!isObject(page)) {
|
|
1083
|
+
problems.push({ code: 'notAPage', key });
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
if (typeof page.layout_url !== 'string' || !LAYOUT_URL.test(page.layout_url))
|
|
1087
|
+
problems.push({ code: 'pageWithoutLayout', key });
|
|
1088
|
+
}
|
|
1089
|
+
/** What is wrong with a pagination (Main's or a page's override). */
|
|
1090
|
+
function checkPagination(pagination, key, problems) {
|
|
1091
|
+
if (pagination.default !== undefined && !isIn(PAGINATION_TYPES, pagination.default))
|
|
1092
|
+
problems.push({ code: 'unknownValue', key: `${key}.default` });
|
|
1093
|
+
if (pagination.userChoice !== undefined && typeof pagination.userChoice !== 'boolean')
|
|
1094
|
+
problems.push({ code: 'notAFlag', key: `${key}.userChoice` });
|
|
1095
|
+
if (pagination.placement !== undefined && !isIn(PAGINATION_PLACEMENTS, pagination.placement))
|
|
1096
|
+
problems.push({ code: 'unknownValue', key: `${key}.placement` });
|
|
1097
|
+
if (pagination.align !== undefined && !isIn(PAGINATION_ALIGNS, pagination.align))
|
|
1098
|
+
problems.push({ code: 'unknownValue', key: `${key}.align` });
|
|
1099
|
+
if (pagination.defaultPageSize !== undefined && !isSize(pagination.defaultPageSize))
|
|
1100
|
+
problems.push({ code: 'notASize', key: `${key}.defaultPageSize` });
|
|
1101
|
+
if (pagination.pageSizeOptions !== undefined && !isSizes(pagination.pageSizeOptions))
|
|
1102
|
+
problems.push({ code: 'notSizes', key: `${key}.pageSizeOptions` });
|
|
1103
|
+
if (pagination.caption !== undefined && typeof pagination.caption !== 'string')
|
|
1104
|
+
problems.push({ code: 'notAText', key: `${key}.caption` });
|
|
1105
|
+
if (isSize(pagination.defaultPageSize) && isSizes(pagination.pageSizeOptions) && !pagination.pageSizeOptions.includes(pagination.defaultPageSize)) {
|
|
1106
|
+
problems.push({ code: 'sizeNotOffered', key: `${key}.defaultPageSize` });
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* What is wrong with the app settings of a Main layout - an empty list when nothing is. The environment
|
|
1111
|
+
* (environment.json "environment") is needed for the sign-in checks; without it they are skipped.
|
|
1112
|
+
*/
|
|
1113
|
+
function checkAppSettings(layout, environment) {
|
|
1114
|
+
const problems = [];
|
|
1115
|
+
const center = layout?.center ?? {};
|
|
1116
|
+
const raw = center.appSettings;
|
|
1117
|
+
const option = center.option ?? {};
|
|
1118
|
+
const flags = LOGIN_FLAGS.filter(flag => option[flag]);
|
|
1119
|
+
if (raw !== undefined && !isObject(raw))
|
|
1120
|
+
return [{ code: 'notAnObject', key: APP_SETTINGS_PATH }];
|
|
1121
|
+
const settings = raw ?? {};
|
|
1122
|
+
checkPage(startPage(layout), START_PAGE_PATH, problems);
|
|
1123
|
+
const login = typeof settings.login === 'string' ? { when: settings.login } : settings.login;
|
|
1124
|
+
if (login !== undefined && !isObject(login))
|
|
1125
|
+
problems.push({ code: 'notAnObject', key: 'login' });
|
|
1126
|
+
const loginBag = isObject(login) ? login : {};
|
|
1127
|
+
const when = loginBag.when;
|
|
1128
|
+
if (when !== undefined && !isIn(LOGIN_WHEN, when))
|
|
1129
|
+
problems.push({ code: 'unknownValue', key: 'login.when' });
|
|
1130
|
+
if (loginBag.storage !== undefined && !isIn(LOGIN_STORAGES, loginBag.storage))
|
|
1131
|
+
problems.push({ code: 'unknownValue', key: 'login.storage' });
|
|
1132
|
+
if (loginBag.roleKey !== undefined && typeof loginBag.roleKey !== 'string')
|
|
1133
|
+
problems.push({ code: 'notAText', key: 'login.roleKey' });
|
|
1134
|
+
if (loginBag.roles !== undefined) {
|
|
1135
|
+
if (!isObject(loginBag.roles))
|
|
1136
|
+
problems.push({ code: 'notAnObject', key: 'login.roles' });
|
|
1137
|
+
else {
|
|
1138
|
+
for (const [role, page] of Object.entries(loginBag.roles))
|
|
1139
|
+
checkPage(page, `login.roles.${role}`, problems);
|
|
1140
|
+
if (Object.keys(loginBag.roles).length && !String(loginBag.roleKey ?? '').trim())
|
|
1141
|
+
problems.push({ code: 'rolesWithoutRoleKey', key: 'login.roleKey' });
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
if (loginBag.loginPage !== undefined)
|
|
1145
|
+
checkPage(loginBag.loginPage, 'login.loginPage', problems);
|
|
1146
|
+
if (flags.length > 1)
|
|
1147
|
+
problems.push({ code: 'severalLoginFlags', key: 'login.when' });
|
|
1148
|
+
if (when === 'start' && !flags.length)
|
|
1149
|
+
problems.push({ code: 'startWithoutLoginFlag', key: 'login.when' });
|
|
1150
|
+
if (flags.length && when !== undefined && when !== 'start')
|
|
1151
|
+
problems.push({ code: 'loginFlagWithoutStart', key: 'login.when' });
|
|
1152
|
+
if (environment) {
|
|
1153
|
+
const method = loginMethod(environment);
|
|
1154
|
+
const wantsLogin = flags.length || when === 'start' || when === 'optional';
|
|
1155
|
+
if (wantsLogin && !method)
|
|
1156
|
+
problems.push({ code: 'noLoginMethod', key: 'login.when' });
|
|
1157
|
+
if (method && flags.length && !flags.includes(method.flag))
|
|
1158
|
+
problems.push({ code: 'loginFlagNotMethod', key: 'login.when' });
|
|
1159
|
+
}
|
|
1160
|
+
if (settings.pagination !== undefined) {
|
|
1161
|
+
if (!isObject(settings.pagination))
|
|
1162
|
+
problems.push({ code: 'notAnObject', key: 'pagination' });
|
|
1163
|
+
else
|
|
1164
|
+
checkPagination(settings.pagination, 'pagination', problems);
|
|
1165
|
+
}
|
|
1166
|
+
const terms = settings.terms;
|
|
1167
|
+
if (terms !== undefined) {
|
|
1168
|
+
for (const key of ['enabled', 'confirmOnStart']) {
|
|
1169
|
+
if (terms[key] !== undefined && typeof terms[key] !== 'boolean')
|
|
1170
|
+
problems.push({ code: 'notAFlag', key: `terms.${key}` });
|
|
1171
|
+
}
|
|
1172
|
+
const documents = terms.documents ?? {};
|
|
1173
|
+
for (const [name, doc] of Object.entries(documents)) {
|
|
1174
|
+
const key = `terms.documents.${name}`;
|
|
1175
|
+
if (!isIn(TERMS_DOCUMENTS, name)) {
|
|
1176
|
+
problems.push({ code: 'unknownDocument', key });
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (!isIn(DOCUMENT_KINDS, doc?.kind))
|
|
1180
|
+
problems.push({ code: 'unknownValue', key: `${key}.kind` });
|
|
1181
|
+
if (typeof doc?.value !== 'string' || !doc.value.trim())
|
|
1182
|
+
problems.push({ code: 'emptyDocument', key });
|
|
1183
|
+
}
|
|
1184
|
+
if (terms.enabled === true && !TERMS_DOCUMENTS.some(name => documents[name]?.value?.trim?.())) {
|
|
1185
|
+
problems.push({ code: 'termsWithoutDocument', key: 'terms.documents' });
|
|
1186
|
+
}
|
|
1187
|
+
if (terms.confirmOnStart === true && terms.enabled !== true)
|
|
1188
|
+
problems.push({ code: 'confirmWithoutTerms', key: 'terms.confirmOnStart' });
|
|
1189
|
+
if (terms.version !== undefined && typeof terms.version !== 'string')
|
|
1190
|
+
problems.push({ code: 'notAText', key: 'terms.version' });
|
|
1191
|
+
const backend = terms.backend;
|
|
1192
|
+
if (backend !== undefined) {
|
|
1193
|
+
if (!isObject(backend))
|
|
1194
|
+
problems.push({ code: 'notAnObject', key: 'terms.backend' });
|
|
1195
|
+
else {
|
|
1196
|
+
if (backend.enabled !== undefined && typeof backend.enabled !== 'boolean')
|
|
1197
|
+
problems.push({ code: 'notAFlag', key: 'terms.backend.enabled' });
|
|
1198
|
+
if (backend.enabled === true) {
|
|
1199
|
+
for (const key of ['statusUrl', 'acceptUrl']) {
|
|
1200
|
+
if (typeof backend[key] !== 'string' || !backend[key].trim())
|
|
1201
|
+
problems.push({ code: 'backendWithoutUrl', key: `terms.backend.${key}` });
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
const menu = settings.menu;
|
|
1208
|
+
if (menu !== undefined) {
|
|
1209
|
+
if (!isObject(menu))
|
|
1210
|
+
problems.push({ code: 'notAnObject', key: 'menu' });
|
|
1211
|
+
else {
|
|
1212
|
+
if (menu.caption !== undefined && (typeof menu.caption !== 'string' || !menu.caption.trim()))
|
|
1213
|
+
problems.push({ code: 'notAText', key: 'menu.caption' });
|
|
1214
|
+
if (menu.entries !== undefined && !Array.isArray(menu.entries))
|
|
1215
|
+
problems.push({ code: 'notAList', key: 'menu.entries' });
|
|
1216
|
+
const seen = new Set();
|
|
1217
|
+
for (const [i, entry] of (Array.isArray(menu.entries) ? menu.entries : []).entries()) {
|
|
1218
|
+
const key = `menu.entries.${i}`;
|
|
1219
|
+
if (!isIn(MENU_ENTRY_KINDS, entry?.kind)) {
|
|
1220
|
+
problems.push({ code: 'unknownValue', key: `${key}.kind` });
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
if (seen.has(entry.kind))
|
|
1224
|
+
problems.push({ code: 'duplicateEntry', key: `${key}.kind` });
|
|
1225
|
+
seen.add(entry.kind);
|
|
1226
|
+
if (entry.on !== undefined && typeof entry.on !== 'boolean')
|
|
1227
|
+
problems.push({ code: 'notAFlag', key: `${key}.on` });
|
|
1228
|
+
else if (entry.on !== undefined && !MENU_SWITCHABLE.includes(entry.kind))
|
|
1229
|
+
problems.push({ code: 'decidedElsewhere', key: `${key}.on` });
|
|
1230
|
+
if (entry.caption !== undefined && typeof entry.caption !== 'string')
|
|
1231
|
+
problems.push({ code: 'notAText', key: `${key}.caption` });
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return problems;
|
|
1236
|
+
}
|
|
1237
|
+
/** What is wrong with the page bar of one page (center.pagination of its layout): the same values as Main's. */
|
|
1238
|
+
function checkPagePagination(page) {
|
|
1239
|
+
const problems = [];
|
|
1240
|
+
const own = page?.center?.pagination;
|
|
1241
|
+
if (own === undefined)
|
|
1242
|
+
return problems;
|
|
1243
|
+
if (!isObject(own))
|
|
1244
|
+
return [{ code: 'notAnObject', key: 'center.pagination' }];
|
|
1245
|
+
checkPagination(own, 'center.pagination', problems);
|
|
1246
|
+
for (const old of ['top', 'bottom', 'position'])
|
|
1247
|
+
if (own[old] !== undefined)
|
|
1248
|
+
problems.push({ code: 'oldKey', key: `center.pagination.${old}` });
|
|
1249
|
+
if (isSize(own.pageSize))
|
|
1250
|
+
problems.push({ code: 'oldKey', key: 'center.pagination.pageSize' });
|
|
1251
|
+
return problems;
|
|
1252
|
+
}
|
|
1253
|
+
/** The captions of the entries the library adds - keys of the app's language files (English text). */
|
|
1254
|
+
const SETTING_MENU_TEXTS = {
|
|
1255
|
+
setting: 'Setting', home: 'Home', projectVersion: 'Project Version', languages: 'Languages', login: 'Login',
|
|
1256
|
+
paginationType: 'Pagination Type', scroll: 'Scroll', numbered: 'Numbered', terms: 'Terms & Conditions',
|
|
1257
|
+
imprint: 'Imprint', privacy: 'Privacy', agb: 'Terms',
|
|
1258
|
+
};
|
|
1259
|
+
/** The name of a language in that language ("de" -> "Deutsch"); the code when it is unknown. */
|
|
1260
|
+
function languageName(code) {
|
|
1261
|
+
try {
|
|
1262
|
+
const name = new Intl.DisplayNames([code], { type: 'language' }).of(code);
|
|
1263
|
+
return name ? name.charAt(0).toUpperCase() + name.slice(1) : code;
|
|
1264
|
+
}
|
|
1265
|
+
catch {
|
|
1266
|
+
return code;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* The side menu with the entries the library adds by itself for an app with app settings: into the
|
|
1271
|
+
* top-level folder "Setting" (caption, any case), else a folder "Setting" at the end. languages: the codes
|
|
1272
|
+
* of the project's language files ("en", "de"); signedIn: whether a user is signed in. The given menu is
|
|
1273
|
+
* not changed; without app settings it comes back as it is.
|
|
1274
|
+
*/
|
|
1275
|
+
function appSettingsMenu(menu, center, context = {}) {
|
|
1276
|
+
const items = Array.isArray(menu) ? menu : [];
|
|
1277
|
+
if (!isObject(center?.appSettings))
|
|
1278
|
+
return items;
|
|
1279
|
+
const settings = readAppSettings({ center });
|
|
1280
|
+
const t = SETTING_MENU_TEXTS;
|
|
1281
|
+
const entry = (caption, icon, option) => ({ label: { caption }, icon, option: { visible: true, ...option } });
|
|
1282
|
+
const languages = [...new Set(context.languages ?? [])];
|
|
1283
|
+
const documents = TERMS_DOCUMENTS.filter(name => settings.terms.documents[name]);
|
|
1284
|
+
// each kind: its entry, or null when it does not apply (one language, signed in, switched off in Main …)
|
|
1285
|
+
const build = {
|
|
1286
|
+
home: () => entry(t.home, 'home', { home: true }),
|
|
1287
|
+
languages: () => languages.length > 1 ? {
|
|
1288
|
+
label: { caption: t.languages }, icon: 'global', option: { visible: true },
|
|
1289
|
+
// no icon: a country's flag does not stand for a language
|
|
1290
|
+
submenu: languages.map(code => entry(languageName(code), '', { changeLang: true, data_url: `${code}.json` })),
|
|
1291
|
+
} : null,
|
|
1292
|
+
login: () => settings.login.when === 'optional' && !context.signedIn ? entry(t.login, 'login', { action: 'login', form: true }) : null,
|
|
1293
|
+
paginationType: () => settings.pagination.userChoice ? {
|
|
1294
|
+
label: { caption: t.paginationType }, icon: 'ordered-list', option: { visible: true },
|
|
1295
|
+
submenu: [entry(t.scroll, 'down', { scrollPagination: true }), entry(t.numbered, 'ordered-list', { numberedPagination: true })],
|
|
1296
|
+
} : null,
|
|
1297
|
+
terms: () => settings.terms.enabled && documents.length ? {
|
|
1298
|
+
label: { caption: t.terms }, icon: 'file-text', option: { visible: true },
|
|
1299
|
+
submenu: documents.map(name => entry(t[name], 'file-text', { terms: true, document: { ...settings.terms.documents[name] } })),
|
|
1300
|
+
} : null,
|
|
1301
|
+
projectVersion: () => entry(t.projectVersion, 'info-circle', { projectVersion: true }),
|
|
1302
|
+
};
|
|
1303
|
+
// an entry's own caption (Main) wins over the fixed text; it is a text of the app like any caption
|
|
1304
|
+
const added = settings.menu.entries.filter(e => e.on).map(e => {
|
|
1305
|
+
const item = build[e.kind]();
|
|
1306
|
+
return item && e.caption ? { ...item, label: { ...item.label, caption: e.caption } } : item;
|
|
1307
|
+
}).filter(Boolean);
|
|
1308
|
+
if (!added.length)
|
|
1309
|
+
return items;
|
|
1310
|
+
const caption = settings.menu.caption;
|
|
1311
|
+
const at = items.findIndex(item => Array.isArray(item?.submenu) && String(item?.label?.caption ?? '').trim().toLowerCase() === caption.toLowerCase());
|
|
1312
|
+
if (at >= 0) {
|
|
1313
|
+
const folder = items[at];
|
|
1314
|
+
return items.map((item, i) => (i === at ? { ...folder, submenu: [...folder.submenu, ...added] } : item));
|
|
1315
|
+
}
|
|
1316
|
+
return [...items, { label: { caption }, icon: 'setting', option: { visible: true }, submenu: added }];
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-23
|
|
1320
|
+
// - new: the app settings catalog - Login, Pagination, Terms & Conditions of Main (#166)
|
|
663
1321
|
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-19
|
|
664
1322
|
// - new: the test flow format of an app's .liveforge/tests (#166)
|
|
665
1323
|
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-18
|
|
@@ -670,5 +1328,5 @@ function checkExpect(e, n, add) {
|
|
|
670
1328
|
* Generated bundle index. Do not edit.
|
|
671
1329
|
*/
|
|
672
1330
|
|
|
673
|
-
export { BASIC_TYPES, CONTROLS, CONTROL_TYPES, DATA_FORMATS, DEFAULT_DEVICES, DISPLAY_FORMATS, EXPECT_KINDS, FRAME_PARTS, KEYBOARD_CONTROLS, KEYBOARD_TYPES, LIST_STATES, NUMBER_STYLES, ORIENTATIONS, PLACEHOLDER_CONTROLS, RESULTS_DIR, RESULTS_KEEP, STEP_KINDS, SYSTEM_KEYBOARDS, TEMPORAL_TRANSFER, TESTS_DIR, TEST_DEVICES, TYPE_ALIASES, assertFieldSettings, baseType, basicType, canonicalControl, checkTestFlow, clone, controlsFor, dataSettings, defaultKeyboard, displaySettings, effectiveControl, effectiveFormat, flowDevices, keyboardFor, normalizeFormat, parseDevice, resolveProperty, resultsToDelete, rulesFor, stepKind, temporalPart, validateSettings, validationSettings };
|
|
1331
|
+
export { APP_SETTINGS, APP_SETTINGS_PATH, APP_SETTING_BLOCKS, BASIC_TYPES, CONTROLS, CONTROL_TYPES, DATA_FORMATS, DATA_OBJECT_KEYS, DATA_OBJECT_NAME_PLACES, DATA_OBJECT_PLACES, DEFAULT_DEVICES, DISPLAY_FORMATS, DOCUMENT_KINDS, EXPECT_KINDS, FRAME_PARTS, KEYBOARD_CONTROLS, KEYBOARD_TYPES, LIST_STATES, LOGIN_FLAGS, LOGIN_METHODS, LOGIN_STORAGES, LOGIN_WHEN, MENU_DECIDED_BY, MENU_ENTRY_KINDS, MENU_SWITCHABLE, NUMBER_STYLES, ORIENTATIONS, PAGINATION_ALIGNS, PAGINATION_PLACEMENTS, PAGINATION_TYPES, PLACEHOLDER_CONTROLS, RESULTS_DIR, RESULTS_KEEP, SETTING_MENU_TEXTS, START_PAGE_KEYS, START_PAGE_PATH, STEP_KINDS, SYSTEM_KEYBOARDS, TEMPORAL_TRANSFER, TERMS_DOCUMENTS, TESTS_DIR, TEST_DEVICES, TYPE_ALIASES, appSettingsMenu, assertFieldSettings, baseType, basicType, canonicalControl, checkAppSettings, checkPagePagination, checkTestFlow, clone, controlChoicesFor, controlsFor, dataSettings, defaultKeyboard, displaySettings, effectiveControl, effectiveFormat, flowDevices, keyboardFor, languageName, loginMethod, normalizeFormat, pageOf, paginationFor, parseDevice, readAppSettings, renameDataObject, resolveProperty, resultsToDelete, rolesOf, rulesFor, startPage, startPageFor, stepKind, temporalPart, validateSettings, validationSettings };
|
|
674
1332
|
//# sourceMappingURL=yomotech-view-toolkit-catalog.mjs.map
|