@ebertjendustries/cswrapper 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.
package/dist/index.js ADDED
@@ -0,0 +1,2147 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CSAlert: () => CSAlert,
24
+ CSBox: () => CSBox,
25
+ CSButton: () => CSButton,
26
+ CSCheckbox: () => CSCheckbox,
27
+ CSDatePicker: () => CSDatePicker,
28
+ CSEnumMultiselect: () => CSEnumMultiselect,
29
+ CSEnumSegmentedControl: () => CSEnumSegmentedControl,
30
+ CSEnumSelect: () => CSEnumSelect,
31
+ CSEnumTiles: () => CSEnumTiles,
32
+ CSExternalLink: () => CSExternalLink,
33
+ CSFormField: () => CSFormField,
34
+ CSHeader: () => CSHeader,
35
+ CSInput: () => CSInput,
36
+ CSLink: () => CSLink,
37
+ CSMultiselect: () => CSMultiselect,
38
+ CSNumericInput: () => CSNumericInput,
39
+ CSSegmentedControl: () => CSSegmentedControl,
40
+ CSSelect: () => CSSelect,
41
+ CSStatusIndicator: () => CSStatusIndicator,
42
+ CSTextContent: () => CSTextContent,
43
+ CSTextarea: () => CSTextarea,
44
+ CSTimeInput: () => CSTimeInput,
45
+ CSToggle: () => CSToggle,
46
+ CSVEnumRatingView: () => CSVEnumRatingView,
47
+ CSVNoItemsView: () => CSVNoItemsView,
48
+ CSVPriceInputView: () => CSVPriceInputView,
49
+ CSVSearchFilterView: () => CSVSearchFilterView,
50
+ CSVTextPromptModalView: () => CSVTextPromptModalView,
51
+ CSV_ENUM_RATING_VIEW_SPEC: () => CSV_ENUM_RATING_VIEW_SPEC,
52
+ CSV_NO_ITEMS_VIEW_SPEC: () => CSV_NO_ITEMS_VIEW_SPEC,
53
+ CSV_PRICE_INPUT_VIEW_SPEC: () => CSV_PRICE_INPUT_VIEW_SPEC,
54
+ CSV_SEARCH_FILTER_VIEW_SPEC: () => CSV_SEARCH_FILTER_VIEW_SPEC,
55
+ CSV_TEXT_PROMPT_MODAL_VIEW_SPEC: () => CSV_TEXT_PROMPT_MODAL_VIEW_SPEC,
56
+ ChildUtils: () => ChildUtils,
57
+ ControllerState: () => ControllerState,
58
+ DateUtils: () => DateUtils,
59
+ ELEMENT_VALIDITY_LEVEL_FACTORY: () => ELEMENT_VALIDITY_LEVEL_FACTORY,
60
+ ElementValidityLevel: () => ElementValidityLevel,
61
+ EnumFactory: () => EnumFactory,
62
+ FORM_FIELD_ID_SUFFIX: () => FORM_FIELD_ID_SUFFIX,
63
+ FieldProperties: () => FieldProperties,
64
+ FieldSpec: () => FieldSpec,
65
+ FixedWidth: () => FixedWidth,
66
+ FromPropsHelper: () => FromPropsHelper,
67
+ LocalStorageService: () => LocalStorageService,
68
+ LocalisationNamespace: () => LocalisationNamespace,
69
+ Localiser: () => Localiser,
70
+ Log: () => Log,
71
+ MESSAGE_SEVERITY_FACTORY: () => MESSAGE_SEVERITY_FACTORY,
72
+ MessageCTO: () => MessageCTO,
73
+ MessageCodeTO: () => MessageCodeTO,
74
+ MessageService: () => MessageService,
75
+ MessageSeverity: () => MessageSeverity,
76
+ NO_HTTP_CODE: () => NO_HTTP_CODE,
77
+ NSK_CONTENT: () => NSK_CONTENT,
78
+ ObjectWithId: () => ObjectWithId,
79
+ PriceUtils: () => PriceUtils,
80
+ QUERY_SEP: () => QUERY_SEP,
81
+ QUERY_START: () => QUERY_START,
82
+ QueryParamHelper: () => QueryParamHelper,
83
+ REST_CLIENT_LOGGER: () => REST_CLIENT_LOGGER,
84
+ RestClient: () => RestClient,
85
+ RunFunctionResult: () => RunFunctionResult,
86
+ SelectHelper: () => SelectHelper,
87
+ TECHNICAL_CONTROLLER_ID: () => TECHNICAL_CONTROLLER_ID,
88
+ ViewSpec: () => ViewSpec,
89
+ createRestClient: () => createRestClient,
90
+ fatalRunErrorFunction: () => fatalRunErrorFunction,
91
+ filterArrayByIndices: () => filterArrayByIndices,
92
+ getEnumRatingLabel: () => getEnumRatingLabel,
93
+ getEnumRatingValues: () => getEnumRatingValues,
94
+ indexRangeArray: () => indexRangeArray,
95
+ isContentWithMessages: () => isContentWithMessages,
96
+ openInNewTab: () => openInNewTab,
97
+ singleChangeHandlerToMulti: () => singleChangeHandlerToMulti,
98
+ sleep: () => sleep,
99
+ sortArrayByIndices: () => sortArrayByIndices,
100
+ useAWSUIRef: () => useAWSUIRef,
101
+ useControllerDisplayState: () => useControllerDisplayState,
102
+ useHotkey: () => useHotkey,
103
+ useMessages: () => useMessages,
104
+ useTOArrayChangeHandler: () => useTOArrayChangeHandler,
105
+ useTOChangeHandler: () => useTOChangeHandler,
106
+ warnWhenTabIsClosed: () => warnWhenTabIsClosed
107
+ });
108
+ module.exports = __toCommonJS(index_exports);
109
+
110
+ // src/components/CSAlert.tsx
111
+ var import_components2 = require("@cloudscape-design/components");
112
+
113
+ // src/types/CSFormProps.ts
114
+ var FromPropsHelper = class {
115
+ static getBasicProps = (props) => {
116
+ const localisationObject = props.localiser.localiseField(props.fieldSpec.getLocalisationKey(), props.localisationVariables, props.alternateNs);
117
+ const uniqueId = props.fieldSpec.getDataTestId();
118
+ return { localisationObject, uniqueId };
119
+ };
120
+ static usesFormField = (props) => {
121
+ const localisation = props.localiser.localiseField(props.fieldSpec.getLocalisationKey(), props.localisationVariables, props.alternateNs);
122
+ return props.formField !== void 0 || localisation?.formField !== void 0;
123
+ };
124
+ static getLocalisedErrorText = (props, value, localiseValidity) => {
125
+ if (props.formField?.errorText !== void 0) {
126
+ return props.formField?.errorText;
127
+ }
128
+ const validityLevel = props.fieldSpec.getValueValidityLevel(value);
129
+ return localiseValidity(props.fieldSpec, validityLevel);
130
+ };
131
+ static sanitizeValueToString = (value) => {
132
+ if (value === null || value === void 0) {
133
+ return "";
134
+ }
135
+ return value;
136
+ };
137
+ };
138
+
139
+ // src/components/CSFormField.tsx
140
+ var import_components = require("@cloudscape-design/components");
141
+ var import_jsx_runtime = (
142
+ // IMPORTANT: Order of props determines which one "wins". You can override Elements that are present in the
143
+ // localisation texts via the additional props. For instance, you can pass in
144
+ // non-static localisations that require variable values dynamically.
145
+ require("react/jsx-runtime")
146
+ );
147
+ var FORM_FIELD_ID_SUFFIX = "_FORM_FIELD";
148
+ function CSFormField(props) {
149
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
150
+ const formFieldId = uniqueId + FORM_FIELD_ID_SUFFIX;
151
+ if (!FromPropsHelper.usesFormField(props)) {
152
+ return props.children;
153
+ }
154
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FormField, { "data-testid": formFieldId, ...localisationObject?.formField, ...props.formField, children: props.children });
155
+ }
156
+
157
+ // src/components/ChildUtils.tsx
158
+ var import_jsx_runtime2 = require("react/jsx-runtime");
159
+ var ChildUtils = class {
160
+ static getChildren = (props, localisationObject) => {
161
+ const childrenRaw = props.children ?? localisationObject?.children;
162
+ const children = props.childrenWrapper ? props.childrenWrapper(childrenRaw) : childrenRaw;
163
+ let finalChildren = props.preventOverflow ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: {
164
+ whiteSpace: "nowrap",
165
+ overflow: "hidden",
166
+ textOverflow: "ellipsis"
167
+ }, children }) : children;
168
+ let formFieldProps = props.formField ?? localisationObject?.formField;
169
+ if (props.inlineLabel && FromPropsHelper.usesFormField(props)) {
170
+ finalChildren = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexWrap: "nowrap" }, children: [
171
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: {
172
+ flex: "none",
173
+ fontWeight: "bold",
174
+ paddingRight: "5px"
175
+ }, children: formFieldProps.label + ":" }),
176
+ finalChildren
177
+ ] });
178
+ formFieldProps = { ...formFieldProps, label: void 0 };
179
+ }
180
+ return { children: finalChildren, formProps: { ...props, formField: formFieldProps } };
181
+ };
182
+ };
183
+
184
+ // src/components/CSAlert.tsx
185
+ var import_jsx_runtime3 = require("react/jsx-runtime");
186
+ function CSAlert(props) {
187
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
188
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
189
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
190
+ import_components2.Alert,
191
+ {
192
+ "data-testid": uniqueId,
193
+ ...props,
194
+ ...localisationObject,
195
+ children
196
+ }
197
+ ) });
198
+ }
199
+
200
+ // src/components/CSBox.tsx
201
+ var import_components3 = require("@cloudscape-design/components");
202
+ var import_jsx_runtime4 = require("react/jsx-runtime");
203
+ function CSBox(props) {
204
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
205
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
206
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
207
+ import_components3.Box,
208
+ {
209
+ "data-testid": uniqueId,
210
+ ...props,
211
+ ...localisationObject,
212
+ children
213
+ }
214
+ ) });
215
+ }
216
+
217
+ // src/components/CSButton.tsx
218
+ var import_components4 = require("@cloudscape-design/components");
219
+ var import_jsx_runtime5 = require("react/jsx-runtime");
220
+ function CSButton(props) {
221
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
222
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
223
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
224
+ import_components4.Button,
225
+ {
226
+ "data-testid": uniqueId,
227
+ ...props,
228
+ ...localisationObject,
229
+ children
230
+ }
231
+ ) });
232
+ }
233
+
234
+ // src/components/CSCheckbox.tsx
235
+ var import_components5 = require("@cloudscape-design/components");
236
+ var import_jsx_runtime6 = require("react/jsx-runtime");
237
+ function CSCheckbox(props) {
238
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
239
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
240
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
241
+ import_components5.Checkbox,
242
+ {
243
+ "data-testid": uniqueId,
244
+ name: uniqueId,
245
+ controlId: uniqueId,
246
+ onChange: props.onChange ? props.onChange : ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.checked),
247
+ ...props,
248
+ ...localisationObject,
249
+ children
250
+ }
251
+ ) });
252
+ }
253
+
254
+ // src/components/CSDatePicker.tsx
255
+ var import_components6 = require("@cloudscape-design/components");
256
+ var import_jsx_runtime7 = require("react/jsx-runtime");
257
+ function CSDatePicker(props) {
258
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
259
+ const sanitizeValue = () => {
260
+ return new Date(FromPropsHelper.sanitizeValueToString(props.value)).toISOString().split("T")[0];
261
+ };
262
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CSFormField, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
263
+ import_components6.DatePicker,
264
+ {
265
+ "data-testid": uniqueId,
266
+ controlId: uniqueId,
267
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.value),
268
+ ...props,
269
+ ...localisationObject,
270
+ value: sanitizeValue()
271
+ }
272
+ ) });
273
+ }
274
+
275
+ // src/components/CSMultiselect.tsx
276
+ var import_components7 = require("@cloudscape-design/components");
277
+ var import_jsx_runtime8 = require("react/jsx-runtime");
278
+ function CSMultiselect(props) {
279
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
280
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
281
+ const adaptedOnChange = ({ detail }) => {
282
+ if (props.enableSelectAll || props.enforceSelection) {
283
+ if (detail.selectedOptions.length === 0) {
284
+ props.onChangeValue(props.fieldSpec.key, [props.selectedOptions[0].value]);
285
+ } else {
286
+ props.onChangeValue(props.fieldSpec.key, detail.selectedOptions.map((sel) => sel.value));
287
+ }
288
+ } else {
289
+ props.onChangeValue(props.fieldSpec.key, detail.selectedOptions.map((sel) => sel.value));
290
+ }
291
+ };
292
+ const hideTokens = props.hideTokens ?? (props.tokenLimit !== void 0 && props.tokenLimit === 0);
293
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
294
+ import_components7.Multiselect,
295
+ {
296
+ "data-testid": uniqueId,
297
+ controlId: uniqueId,
298
+ filteringType: props.filteringType ?? "auto",
299
+ onChange: adaptedOnChange,
300
+ enableSelectAll: true,
301
+ ...props,
302
+ ...localisationObject,
303
+ hideTokens,
304
+ options: props.options
305
+ }
306
+ ) });
307
+ }
308
+
309
+ // src/types/ObjectWithId.ts
310
+ var ObjectWithId = class {
311
+ id;
312
+ static idToString = (objectWithId) => {
313
+ return objectWithId.id ? objectWithId.id.toString() : "<N/A>";
314
+ };
315
+ static toObjectWithId = (array, idExtractor) => {
316
+ return array.map((object) => ({
317
+ ...object,
318
+ id: idExtractor(object)
319
+ }));
320
+ };
321
+ };
322
+
323
+ // src/utils/SelectHelper.ts
324
+ var SelectHelper = class _SelectHelper {
325
+ static singleSelectOptionWithId = (objects, selectedObjectId, toOptionDefinition) => {
326
+ return this.singleSelectOption(objects, objects.find((importObject) => ObjectWithId.idToString(importObject) === selectedObjectId?.toString()), toOptionDefinition);
327
+ };
328
+ static singleSelectOption = (objects, selectedObject, toOptionDefinition) => {
329
+ const options = objects.map((object) => ({
330
+ value: ObjectWithId.idToString(object),
331
+ ...toOptionDefinition(object)
332
+ }));
333
+ const selectedOption = selectedObject === void 0 ? null : _SelectHelper.getSelectedOptions(options, [selectedObject.id])[0];
334
+ return {
335
+ options,
336
+ selectedOption
337
+ };
338
+ };
339
+ static singleSelectEnum = (enumFactory, selectedEnum, localiser, exclude) => {
340
+ const options = enumFactory.values.filter((enumInstance) => exclude === void 0 || !exclude.includes(enumInstance)).map((enumInstance) => {
341
+ const enumTranslation = localiser.getEnumLocalisation(enumFactory, enumInstance);
342
+ return {
343
+ value: enumInstance.toString(),
344
+ label: enumTranslation.label,
345
+ description: enumTranslation.description
346
+ };
347
+ });
348
+ const selectedOption = selectedEnum === void 0 ? null : _SelectHelper.getSelectedEnumOptions(options, [selectedEnum.toString()])[0];
349
+ return {
350
+ options,
351
+ selectedOption
352
+ };
353
+ };
354
+ static multiSelectOptions = (objects, selectedObjects, toOptionDefinition) => {
355
+ const options = objects.map((object) => ({
356
+ value: ObjectWithId.idToString(object),
357
+ ...toOptionDefinition(object)
358
+ }));
359
+ const selectedOptions = _SelectHelper.getSelectedOptions(options, selectedObjects.map((s) => s.id));
360
+ return {
361
+ options,
362
+ selectedOptions
363
+ };
364
+ };
365
+ static multiSelectEnums = (enumFactory, selectedEnums, localiser) => {
366
+ const options = enumFactory.values.map((enumInstance) => {
367
+ const enumTranslation = localiser.getEnumLocalisation(enumFactory, enumInstance);
368
+ return {
369
+ value: enumInstance.toString(),
370
+ label: enumTranslation.label,
371
+ description: enumTranslation.description
372
+ };
373
+ });
374
+ const selectedOptions = _SelectHelper.getSelectedEnumOptions(options, selectedEnums);
375
+ return {
376
+ options,
377
+ selectedOptions
378
+ };
379
+ };
380
+ static getSelectedOptions = (options, selectedIds) => {
381
+ const selectedIdsSet = {};
382
+ selectedIds.forEach((selId) => selId !== void 0 ? selectedIdsSet[selId] = true : null);
383
+ return options.filter((option) => option.value && selectedIdsSet[parseInt(option.value)]);
384
+ };
385
+ static getSelectedEnumOptions = (options, selectedEnums) => {
386
+ const selectedIdsSet = {};
387
+ selectedEnums.forEach((selId) => selId !== void 0 ? selectedIdsSet[selId.toString()] = true : null);
388
+ return options.filter((option) => option.value && selectedIdsSet[option.value]);
389
+ };
390
+ };
391
+
392
+ // src/components/CSEnumMultiselect.tsx
393
+ var import_jsx_runtime9 = require("react/jsx-runtime");
394
+ function CSEnumMultiselect(props) {
395
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
396
+ CSMultiselect,
397
+ {
398
+ ...SelectHelper.multiSelectEnums(props.factory, props.selectedEnums, props.localiser),
399
+ ...props
400
+ }
401
+ );
402
+ }
403
+
404
+ // src/components/CSSegmentedControl.tsx
405
+ var import_components8 = require("@cloudscape-design/components");
406
+ var import_jsx_runtime10 = require("react/jsx-runtime");
407
+ function CSSegmentedControl(props) {
408
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
409
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
410
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
411
+ import_components8.SegmentedControl,
412
+ {
413
+ "data-testid": uniqueId,
414
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.selectedId),
415
+ ...props,
416
+ ...localisationObject
417
+ }
418
+ ) });
419
+ }
420
+
421
+ // src/components/CSEnumSegmentedControl.tsx
422
+ var import_jsx_runtime11 = require("react/jsx-runtime");
423
+ function CSEnumSegmentedControl(props) {
424
+ const options = props.factory.values.filter((e) => props.exclude === void 0 || !props.exclude.includes(e)).map((e) => ({
425
+ text: props.localiser.getEnumLabel(props.factory, e),
426
+ id: e.toString()
427
+ }));
428
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
429
+ CSSegmentedControl,
430
+ {
431
+ selectedId: props.selectedEnum === void 0 ? null : props.selectedEnum.toString(),
432
+ options,
433
+ label: props.formField ? props.formField.label : void 0,
434
+ ...props
435
+ }
436
+ );
437
+ }
438
+
439
+ // src/components/CSSelect.tsx
440
+ var import_components9 = require("@cloudscape-design/components");
441
+ var import_jsx_runtime12 = require("react/jsx-runtime");
442
+ function CSSelect(props) {
443
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
444
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
445
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
446
+ import_components9.Select,
447
+ {
448
+ "data-testid": uniqueId,
449
+ controlId: uniqueId,
450
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.selectedOption.value),
451
+ ...props,
452
+ ...localisationObject
453
+ }
454
+ ) });
455
+ }
456
+
457
+ // src/components/CSEnumSelect.tsx
458
+ var import_jsx_runtime13 = require("react/jsx-runtime");
459
+ function CSEnumSelect(props) {
460
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
461
+ CSSelect,
462
+ {
463
+ ...SelectHelper.singleSelectEnum(props.factory, props.selectedEnum, props.localiser, props.exclude),
464
+ ...props
465
+ }
466
+ );
467
+ }
468
+
469
+ // src/components/CSEnumTiles.tsx
470
+ var import_components10 = require("@cloudscape-design/components");
471
+ var import_jsx_runtime14 = require("react/jsx-runtime");
472
+ function CSEnumTiles(props) {
473
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
474
+ const items = props.factory.values.filter((enumInstance) => props.exclude === void 0 || !props.exclude.includes(enumInstance)).map((enumInstance) => {
475
+ const enumTranslation = props.localiser.getEnumLocalisation(props.factory, enumInstance);
476
+ return {
477
+ value: enumInstance.toString(),
478
+ label: enumTranslation.label,
479
+ description: enumTranslation.description
480
+ };
481
+ });
482
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
483
+ import_components10.Tiles,
484
+ {
485
+ "data-testid": uniqueId,
486
+ controlId: uniqueId,
487
+ name: uniqueId,
488
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.value),
489
+ value: props.selectedEnum ? props.selectedEnum.toString() : null,
490
+ items,
491
+ ...props,
492
+ ...localisationObject
493
+ }
494
+ );
495
+ }
496
+
497
+ // src/components/CSLink.tsx
498
+ var import_components11 = require("@cloudscape-design/components");
499
+
500
+ // src/utils/BrowserUtils.ts
501
+ var openInNewTab = (link) => {
502
+ const newWindow = window.open(link, "_blank", "noopener,noreferrer");
503
+ if (newWindow) newWindow.opener = null;
504
+ };
505
+ var warnWhenTabIsClosed = (isDirty) => {
506
+ const handleTabClose = (event) => {
507
+ if (isDirty !== void 0 && !isDirty()) {
508
+ return void 0;
509
+ }
510
+ event.preventDefault();
511
+ return event.returnValue = "Are you sure you want to exit?";
512
+ };
513
+ window.addEventListener("beforeunload", handleTabClose);
514
+ return () => {
515
+ window.removeEventListener("beforeunload", handleTabClose);
516
+ };
517
+ };
518
+
519
+ // src/components/CSLink.tsx
520
+ var import_jsx_runtime15 = require("react/jsx-runtime");
521
+ function CSLink(props) {
522
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
523
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
524
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
525
+ import_components11.Link,
526
+ {
527
+ "data-testid": uniqueId,
528
+ ...props,
529
+ ...localisationObject,
530
+ children
531
+ }
532
+ ) });
533
+ }
534
+ function CSExternalLink(props) {
535
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(CSLink, { ...props, external: true, onFollow: (detail) => detail.preventDefault(), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { onClick: () => openInNewTab(props.link), children: props.children }) });
536
+ }
537
+
538
+ // src/components/CSHeader.tsx
539
+ var import_components12 = require("@cloudscape-design/components");
540
+ var import_jsx_runtime16 = require("react/jsx-runtime");
541
+ function CSHeader(props) {
542
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
543
+ const { children } = ChildUtils.getChildren(props, localisationObject);
544
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
545
+ import_components12.Header,
546
+ {
547
+ "data-testid": uniqueId,
548
+ ...props,
549
+ ...localisationObject,
550
+ children
551
+ }
552
+ );
553
+ }
554
+
555
+ // src/components/CSInput.tsx
556
+ var import_components13 = require("@cloudscape-design/components");
557
+ var import_jsx_runtime17 = require("react/jsx-runtime");
558
+ function CSInput(props) {
559
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
560
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
561
+ const sanitizedValue = FromPropsHelper.sanitizeValueToString(props.value);
562
+ const errorText = FromPropsHelper.getLocalisedErrorText(props, sanitizedValue, props.localiser.getFieldValidityLocalisationFunction());
563
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CSFormField, { ...props, formField: { ...formProps, errorText }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
564
+ import_components13.Input,
565
+ {
566
+ "data-testid": uniqueId,
567
+ controlId: uniqueId,
568
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.value),
569
+ ...props,
570
+ ...localisationObject,
571
+ value: sanitizedValue
572
+ }
573
+ ) });
574
+ }
575
+
576
+ // src/components/CSNumericInput.tsx
577
+ var import_components14 = require("@cloudscape-design/components");
578
+ var import_jsx_runtime18 = require("react/jsx-runtime");
579
+ function CSNumericInput(props) {
580
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
581
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
582
+ const sanitizeValue = () => {
583
+ if (props.value === void 0 || props.value === null || isNaN(props.value)) {
584
+ return "";
585
+ }
586
+ return FromPropsHelper.sanitizeValueToString(props.value);
587
+ };
588
+ const sanitizedValue = sanitizeValue();
589
+ const errorText = FromPropsHelper.getLocalisedErrorText(props, sanitizedValue, props.localiser.getFieldValidityLocalisationFunction());
590
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(CSFormField, { ...formProps, formField: { ...props.formField, errorText }, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
591
+ import_components14.Input,
592
+ {
593
+ "data-testid": uniqueId,
594
+ controlId: uniqueId,
595
+ onChange: ({ detail }) => {
596
+ props.onChangeValue(props.fieldSpec.key, props.step && props.step !== "any" && props.step % 1 === 0 ? parseInt(detail.value) : parseFloat(detail.value));
597
+ },
598
+ ...props,
599
+ ...localisationObject,
600
+ value: sanitizedValue,
601
+ type: "number",
602
+ inputMode: "numeric"
603
+ }
604
+ ) });
605
+ }
606
+
607
+ // src/components/CSStatusIndicator.tsx
608
+ var import_components15 = require("@cloudscape-design/components");
609
+ var import_jsx_runtime19 = require("react/jsx-runtime");
610
+ function CSStatusIndicator(props) {
611
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
612
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
613
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
614
+ import_components15.StatusIndicator,
615
+ {
616
+ "data-testid": uniqueId,
617
+ ...props,
618
+ ...localisationObject,
619
+ children
620
+ }
621
+ ) });
622
+ }
623
+
624
+ // src/components/CSTextContent.tsx
625
+ var import_components16 = require("@cloudscape-design/components");
626
+ var import_jsx_runtime20 = require("react/jsx-runtime");
627
+ function CSTextContent(props) {
628
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
629
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
630
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
631
+ import_components16.TextContent,
632
+ {
633
+ "data-testid": uniqueId,
634
+ ...props,
635
+ ...localisationObject,
636
+ children
637
+ }
638
+ ) });
639
+ }
640
+
641
+ // src/components/CSTextarea.tsx
642
+ var import_components17 = require("@cloudscape-design/components");
643
+ var import_jsx_runtime21 = require("react/jsx-runtime");
644
+ function CSTextarea(props) {
645
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
646
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
647
+ const sanitizedValue = FromPropsHelper.sanitizeValueToString(props.value);
648
+ const errorText = FromPropsHelper.getLocalisedErrorText(props, sanitizedValue, props.localiser.getFieldValidityLocalisationFunction());
649
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CSFormField, { ...props, formField: { ...formProps, errorText }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
650
+ import_components17.Textarea,
651
+ {
652
+ "data-testid": uniqueId,
653
+ controlId: uniqueId,
654
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.value),
655
+ ...props,
656
+ ...localisationObject,
657
+ value: sanitizedValue
658
+ }
659
+ ) });
660
+ }
661
+
662
+ // src/components/CSTimeInput.tsx
663
+ var import_components18 = require("@cloudscape-design/components");
664
+ var import_jsx_runtime22 = require("react/jsx-runtime");
665
+ function CSTimeInput(props) {
666
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
667
+ const { formProps } = ChildUtils.getChildren(props, localisationObject);
668
+ const defaultFormat = "hh:mm";
669
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
670
+ import_components18.TimeInput,
671
+ {
672
+ "data-testid": uniqueId,
673
+ autoFocus: props.autoFocus,
674
+ onChange: ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.value),
675
+ format: props.format ? props.format : defaultFormat,
676
+ placeholder: props.placeholder ? props.placeholder : defaultFormat,
677
+ ...props,
678
+ ...localisationObject
679
+ }
680
+ ) });
681
+ }
682
+
683
+ // src/components/CSToggle.tsx
684
+ var import_components19 = require("@cloudscape-design/components");
685
+ var import_jsx_runtime23 = require("react/jsx-runtime");
686
+ function CSToggle(props) {
687
+ const { localisationObject, uniqueId } = FromPropsHelper.getBasicProps(props);
688
+ const { children, formProps } = ChildUtils.getChildren(props, localisationObject);
689
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(CSFormField, { ...formProps, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
690
+ import_components19.Toggle,
691
+ {
692
+ "data-testid": uniqueId,
693
+ name: uniqueId,
694
+ controlId: uniqueId,
695
+ onChange: props.onChange ? props.onChange : ({ detail }) => props.onChangeValue(props.fieldSpec.key, detail.checked),
696
+ ...props,
697
+ ...localisationObject,
698
+ children
699
+ }
700
+ ) });
701
+ }
702
+
703
+ // src/views/CSVEnumRatingView.tsx
704
+ var import_react_rating = require("@smastrom/react-rating");
705
+ var import_react = require("react");
706
+
707
+ // src/utils/EnumFactory.ts
708
+ var EnumFactory = class {
709
+ constructor(enumName, values) {
710
+ this.enumName = enumName;
711
+ this.values = values;
712
+ if (this.values.length === 0) {
713
+ throw new Error("Empty localized enum array is not allowed here");
714
+ }
715
+ }
716
+ getEnumIndex(instance) {
717
+ return this.values.indexOf(instance);
718
+ }
719
+ };
720
+
721
+ // src/types/ElementValidityLevel.ts
722
+ var ElementValidityLevel = /* @__PURE__ */ ((ElementValidityLevel2) => {
723
+ ElementValidityLevel2["VALID"] = "VALID";
724
+ ElementValidityLevel2["REQUIRED_VALUE_IS_NOT_PRESENT"] = "REQUIRED_VALUE_IS_NOT_PRESENT";
725
+ ElementValidityLevel2["MAX_LENGTH_EXCEEDED"] = "MAX_LENGTH_EXCEEDED";
726
+ ElementValidityLevel2["LOWER_BOUND_ONLY_TOO_SMALL"] = "LOWER_BOUND_ONLY_TOO_SMALL";
727
+ ElementValidityLevel2["UPPER_BOUND_ONLY_TOO_BIG"] = "UPPER_BOUND_ONLY_TOO_BIG";
728
+ ElementValidityLevel2["BOTH_BOUNDS_OUT_OF_BOUNDS"] = "BOTH_BOUNDS_OUT_OF_BOUNDS";
729
+ return ElementValidityLevel2;
730
+ })(ElementValidityLevel || {});
731
+ var ELEMENT_VALIDITY_LEVEL_FACTORY = new EnumFactory("ElementValidityLevel", Object.values(ElementValidityLevel));
732
+
733
+ // src/logging/Log.ts
734
+ var DISABLE_LOGGING = false;
735
+ var Log = class _Log {
736
+ prefix;
737
+ debugLogging;
738
+ constructor(prefix) {
739
+ this.prefix = prefix ? "[" + prefix + "] " : "";
740
+ this.debugLogging = true;
741
+ }
742
+ static toReadableObjectString(object) {
743
+ return this.toObjectStr(object, (object2) => JSON.stringify(object2, null, 2));
744
+ }
745
+ static toCompactReadableObjectString(object, dependencyCharLimit) {
746
+ const str = this.toObjectStr(object, (object2) => JSON.stringify(object2));
747
+ const maxLen = Math.min(str.length, dependencyCharLimit);
748
+ if (maxLen < str.length) {
749
+ return str.substring(0, maxLen) + " ( ... continued)";
750
+ }
751
+ return str;
752
+ }
753
+ static toObjectStr(object, stringify) {
754
+ if (object === null) {
755
+ return "null";
756
+ }
757
+ if (object === void 0) {
758
+ return "undefined";
759
+ }
760
+ let s = stringify(object);
761
+ if (s === void 0) {
762
+ return "function";
763
+ }
764
+ return s.replaceAll("\\", "");
765
+ }
766
+ /**
767
+ * log at debugging level
768
+ */
769
+ debug(msg, ...supportingDetails) {
770
+ this.emitLogMessage("debug", msg, supportingDetails);
771
+ }
772
+ /**
773
+ * log at information level
774
+ */
775
+ info(msg, ...supportingDetails) {
776
+ this.emitLogMessage("info", msg, supportingDetails);
777
+ }
778
+ /**
779
+ * log at warning level
780
+ */
781
+ warn(msg, ...supportingDetails) {
782
+ this.emitLogMessage("warn", msg, supportingDetails);
783
+ }
784
+ /**
785
+ * log at error level
786
+ */
787
+ error(msg, ...supportingDetails) {
788
+ this.emitLogMessage("error", msg, supportingDetails);
789
+ }
790
+ object(prefixMsg, object) {
791
+ this.debug(prefixMsg + " " + _Log.toReadableObjectString(object));
792
+ }
793
+ effectStart(effectName, msg, dependencies, dependencyCharLimit) {
794
+ let dependenciesSuffix = "";
795
+ if (dependencies) {
796
+ let dependenciesStr = "";
797
+ for (let i = 0; i < dependencies.length; i++) {
798
+ const dependency = dependencies[i];
799
+ dependenciesStr = `${dependenciesStr} Dep[${i}]=<${_Log.toCompactReadableObjectString(dependency, dependencyCharLimit || 60)}>`;
800
+ }
801
+ dependenciesSuffix = (msg.length > 0 ? ", " : "") + "DEPS:" + dependenciesStr;
802
+ }
803
+ this.effect(`start - ${effectName}`, `${msg}${dependenciesSuffix}`);
804
+ }
805
+ effectEnd(effectName) {
806
+ this.debug(`EFFECT(end - ${effectName})`);
807
+ }
808
+ effect(effectName, msg) {
809
+ this.debug(`EFFECT(${effectName}): ${msg}`);
810
+ }
811
+ /**
812
+ * creates a log message with some detailed information
813
+ * @param msgType type of message (debug, info, warn, error)
814
+ * @param msg the message as string
815
+ * @param supportingDetails details that should be logged
816
+ */
817
+ emitLogMessage(msgType, msg, supportingDetails) {
818
+ if (DISABLE_LOGGING) {
819
+ return;
820
+ }
821
+ const logTS = (/* @__PURE__ */ new Date()).toISOString();
822
+ if (!this.debugLogging && msgType === "debug") {
823
+ return;
824
+ }
825
+ if (supportingDetails.length > 0) {
826
+ console[msgType](`${logTS} ${this.prefix}${msg}${supportingDetails}`);
827
+ } else {
828
+ console[msgType](`${logTS} ${this.prefix}${msg}`);
829
+ }
830
+ }
831
+ };
832
+
833
+ // src/types/ViewSpec.ts
834
+ var LOGGER = new Log("ViewSpec");
835
+ var ViewElementSpec = class {
836
+ constructor(key, instanceId) {
837
+ this.key = key;
838
+ this.instanceId = instanceId;
839
+ }
840
+ parent;
841
+ ns;
842
+ dataTestId;
843
+ localisationKey;
844
+ keyHierarchy;
845
+ getDataTestId() {
846
+ if (this.dataTestId === void 0) {
847
+ const parentDataTestId = this.parent ? this.parent.getDataTestId() : "";
848
+ this.dataTestId = this.instanceId ? `${parentDataTestId}${this.key}${this.instanceId}END` : `${parentDataTestId}${this.key}END`;
849
+ }
850
+ return this.dataTestId;
851
+ }
852
+ getLocalisationKey() {
853
+ if (this.localisationKey === void 0) {
854
+ const keys = this.getKeyHierarchy();
855
+ this.localisationKey = this.ns.createKey(...keys);
856
+ }
857
+ return this.localisationKey;
858
+ }
859
+ getKeyHierarchy() {
860
+ if (this.keyHierarchy === void 0) {
861
+ const parentHierarchy = this.parent ? this.parent.getKeyHierarchy() : [];
862
+ this.keyHierarchy = [...parentHierarchy, this.key];
863
+ }
864
+ return this.keyHierarchy;
865
+ }
866
+ };
867
+ var FieldSpec = class _FieldSpec extends ViewElementSpec {
868
+ constructor(key, required, maxLength, minValue, maxValue, customFieldValidator, instanceId) {
869
+ super(key, instanceId);
870
+ this.required = required;
871
+ this.maxLength = maxLength;
872
+ this.minValue = minValue;
873
+ this.maxValue = maxValue;
874
+ this.customFieldValidator = customFieldValidator;
875
+ }
876
+ static getTOValidityLevel(transportObject, elements) {
877
+ if (elements.length === 0) {
878
+ throw Error("At least one field property must be given");
879
+ }
880
+ for (let index = 0; index < elements.length; index++) {
881
+ const field = elements[index];
882
+ const fieldValidity = field.getValueValidityLevel(transportObject[field.key]);
883
+ if (fieldValidity !== "VALID" /* VALID */) {
884
+ return fieldValidity;
885
+ }
886
+ }
887
+ return "VALID" /* VALID */;
888
+ }
889
+ static isTOValid(transportObject, Elements) {
890
+ return this.getTOValidityLevel(transportObject, Elements) === "VALID" /* VALID */;
891
+ }
892
+ static debugLogElementValidityArray(elements, Elements) {
893
+ for (let index = 0; index < elements.length; index++) {
894
+ const element = elements[index];
895
+ _FieldSpec.debugLogElementValidity(element, "idx=" + index.toString(), Elements);
896
+ }
897
+ }
898
+ static debugLogElementValidity(element, elementId, Elements) {
899
+ for (const field of Elements) {
900
+ const fieldValidity = _FieldSpec.getTOValidityLevel(element, [field]);
901
+ LOGGER.info(`Field validity level, element id = <${elementId}>, field name = <${field.getDataTestId()}>, validity level = <${fieldValidity.toString()}>.`);
902
+ }
903
+ }
904
+ getValueValidityLevel(value) {
905
+ if (this.customFieldValidator) {
906
+ return this.customFieldValidator(this, value);
907
+ }
908
+ const isString = value !== void 0 && value !== null && (typeof value === "string" || value instanceof String);
909
+ const isNumber = value !== void 0 && value !== null && typeof value === "number";
910
+ if (this.required && (value === void 0 || value === null || isString && value.trim().length === 0 || isNumber && isNaN(value))) {
911
+ return "REQUIRED_VALUE_IS_NOT_PRESENT" /* REQUIRED_VALUE_IS_NOT_PRESENT */;
912
+ }
913
+ if (isString && this.maxLength !== void 0 && value.length > this.getMaxLength()) {
914
+ return "MAX_LENGTH_EXCEEDED" /* MAX_LENGTH_EXCEEDED */;
915
+ }
916
+ if (isNumber) {
917
+ if (this.minValue !== void 0 && this.maxValue === void 0 && this.minValue > value) {
918
+ return "LOWER_BOUND_ONLY_TOO_SMALL" /* LOWER_BOUND_ONLY_TOO_SMALL */;
919
+ }
920
+ if (this.maxValue !== void 0 && this.minValue === void 0 && this.maxValue < value) {
921
+ return "UPPER_BOUND_ONLY_TOO_BIG" /* UPPER_BOUND_ONLY_TOO_BIG */;
922
+ }
923
+ if (this.minValue !== void 0 && this.maxValue !== void 0 && (this.minValue > value || this.maxValue < value)) {
924
+ return "BOTH_BOUNDS_OUT_OF_BOUNDS" /* BOTH_BOUNDS_OUT_OF_BOUNDS */;
925
+ }
926
+ }
927
+ return "VALID" /* VALID */;
928
+ }
929
+ getMaxLength() {
930
+ return this.maxLength ? this.maxLength : Number.MAX_SAFE_INTEGER;
931
+ }
932
+ };
933
+ var ViewSpec = class _ViewSpec extends ViewElementSpec {
934
+ constructor(key, ns, instanceId, customViewValidator) {
935
+ super(key, instanceId);
936
+ this.ns = ns;
937
+ if (!customViewValidator) {
938
+ this.viewValidator = () => "VALID" /* VALID */;
939
+ } else {
940
+ this.viewValidator = customViewValidator;
941
+ }
942
+ }
943
+ elements;
944
+ viewValidator;
945
+ static create(key, ns, elementDefinition, instanceId, parent, customViewValidator) {
946
+ const viewSpec = new _ViewSpec(key, ns, instanceId, customViewValidator);
947
+ viewSpec.parent = parent;
948
+ viewSpec.elements = elementDefinition(viewSpec);
949
+ return viewSpec;
950
+ }
951
+ addField(fieldSpec) {
952
+ fieldSpec.parent = this;
953
+ fieldSpec.ns = this.ns;
954
+ return fieldSpec;
955
+ }
956
+ addFieldFromProps(fieldProps, customFieldValidator, instanceId) {
957
+ const fieldSpec = new FieldSpec(fieldProps.key, fieldProps.required, fieldProps.maxLength, fieldProps.minValue, fieldProps.maxValue, customFieldValidator, instanceId);
958
+ fieldSpec.parent = this;
959
+ fieldSpec.ns = this.ns;
960
+ return fieldSpec;
961
+ }
962
+ addView(viewSpecProvider, key, instanceId) {
963
+ const viewSpec = viewSpecProvider(this, key, instanceId);
964
+ viewSpec.ns = this.ns;
965
+ return viewSpec;
966
+ }
967
+ getAllElements() {
968
+ return Object.values(this.elements);
969
+ }
970
+ getValueValidityLevel(value) {
971
+ return this.viewValidator(this, value);
972
+ }
973
+ };
974
+
975
+ // src/views/CSVEnumRatingView.tsx
976
+ var import_jsx_runtime24 = require("react/jsx-runtime");
977
+ var CSV_ENUM_RATING_VIEW_SPEC = (parent, key, instanceId) => ViewSpec.create(key, parent.ns, (spec) => ({
978
+ rating: spec.addField(new FieldSpec("rating")),
979
+ boxRatingName: spec.addField(new FieldSpec("boxRatingName"))
980
+ }), instanceId, parent);
981
+ function getEnumRatingValues(factory, toOrderNumber) {
982
+ return toOrderNumber ? factory.values.sort((e1, e2) => toOrderNumber(e1) - toOrderNumber(e2)) : factory.values;
983
+ }
984
+ function getEnumRatingLabel(enumInstance, instanceId) {
985
+ return `${instanceId}_${enumInstance.toString()}`;
986
+ }
987
+ function CSVEnumRatingView(props) {
988
+ const spec = props.viewSpec;
989
+ const { elements } = spec;
990
+ const [hoveredValue, setHoveredValue] = (0, import_react.useState)(props.selectedEnum);
991
+ const valuesInOrder = getEnumRatingValues(props.factory, props.toOrderNumber);
992
+ const onHover = (hoveredIndex) => {
993
+ if (hoveredIndex === 0) {
994
+ setHoveredValue(props.selectedEnum);
995
+ } else {
996
+ setHoveredValue(valuesInOrder[hoveredIndex]);
997
+ }
998
+ };
999
+ const itemCount = Math.max(1, Math.min(valuesInOrder.length - 1, 10));
1000
+ (0, import_react.useEffect)(() => {
1001
+ setHoveredValue(props.selectedEnum);
1002
+ }, [props.selectedEnum]);
1003
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(CSFormField, { fieldSpec: elements.rating, localiser: props.localiser, children: [
1004
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1005
+ import_react_rating.Rating,
1006
+ {
1007
+ "data-testid": elements.rating.getDataTestId(),
1008
+ isDisabled: props.disabled,
1009
+ style: { maxWidth: 100 },
1010
+ items: itemCount,
1011
+ value: !props.disabled ? valuesInOrder.indexOf(props.selectedEnum) : 0,
1012
+ onHoverChange: onHover,
1013
+ onChange: (selectedIndex) => props.onChangeValue(spec.key, valuesInOrder[selectedIndex]),
1014
+ invisibleItemLabels: valuesInOrder.slice(1).map((e) => getEnumRatingLabel(e, spec.instanceId))
1015
+ }
1016
+ ),
1017
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { style: { textAlign: "left", paddingLeft: "5px" }, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1018
+ CSBox,
1019
+ {
1020
+ fieldSpec: elements.boxRatingName,
1021
+ localiser: props.localiser,
1022
+ variant: !props.disabled ? "div" : "small",
1023
+ children: hoveredValue !== void 0 ? props.localiser.getEnumLabel(props.factory, hoveredValue) : void 0
1024
+ }
1025
+ ) })
1026
+ ] });
1027
+ }
1028
+
1029
+ // src/views/CSVNoItemsView.tsx
1030
+ var import_components20 = require("@cloudscape-design/components");
1031
+ var import_jsx_runtime25 = require("react/jsx-runtime");
1032
+ var CSV_NO_ITEMS_VIEW_SPEC = (ns) => ViewSpec.create("CSVNoItemsView", ns, (spec) => ({
1033
+ boxHeading: spec.addField(new FieldSpec("boxHeading")),
1034
+ boxBody: spec.addField(new FieldSpec("boxBody"))
1035
+ }));
1036
+ function CSVNoItemsView(props) {
1037
+ const spec = props.viewSpec;
1038
+ const { elements } = spec;
1039
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { "data-testid": spec.getDataTestId(), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_components20.Box, { textAlign: "center", color: "inherit", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_components20.SpaceBetween, { size: "xxs", direction: "vertical", children: [
1040
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1041
+ CSBox,
1042
+ {
1043
+ fieldSpec: elements.boxHeading,
1044
+ localiser: props.localiser,
1045
+ alternateNs: spec.ns,
1046
+ variant: "strong",
1047
+ color: "inherit",
1048
+ children: props.headingText
1049
+ }
1050
+ ),
1051
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1052
+ CSBox,
1053
+ {
1054
+ fieldSpec: elements.boxBody,
1055
+ localiser: props.localiser,
1056
+ alternateNs: spec.ns,
1057
+ localisationVariables: { itemType: props.localiser.getEnumLabel(props.factory, props.itemType) },
1058
+ variant: "p",
1059
+ color: "inherit",
1060
+ children: props.bodyText
1061
+ }
1062
+ ),
1063
+ props.bodyNode
1064
+ ] }) }) });
1065
+ }
1066
+
1067
+ // src/views/CSVPriceInputView.tsx
1068
+ var import_components21 = require("@cloudscape-design/components");
1069
+
1070
+ // src/utils/PriceUtils.ts
1071
+ var LOGGER2 = new Log("PriceUtils");
1072
+ var PriceUtils = class {
1073
+ static getFormattedPrice = (locale, price) => {
1074
+ if (isNaN(price.priceInCents)) {
1075
+ return "-";
1076
+ }
1077
+ return new Intl.NumberFormat(locale, {
1078
+ style: "currency",
1079
+ currency: price.currency.toString()
1080
+ }).format(price.priceInCents / 100);
1081
+ };
1082
+ static sumPrices = (prices, defaultCurrency) => {
1083
+ if (prices.length === 0) {
1084
+ return { priceInCents: 0, currency: defaultCurrency };
1085
+ }
1086
+ const currencySet = this.getCurrenciesFromPrices(prices);
1087
+ if (currencySet.size > 1) {
1088
+ LOGGER2.warn("Different currencies found in price array to be summed - the final price is incorrect!", currencySet);
1089
+ }
1090
+ const summedPrice = prices.map((pr) => pr.priceInCents).reduce((sum, current) => sum + current);
1091
+ return { priceInCents: summedPrice, currency: prices[0].currency };
1092
+ };
1093
+ static getCurrenciesFromPrices = (prices) => {
1094
+ const currencySet = /* @__PURE__ */ new Set();
1095
+ prices.forEach((pr) => currencySet.add(pr.currency));
1096
+ return currencySet;
1097
+ };
1098
+ static getPriceValidityLevel = (spec, value) => {
1099
+ const centsValidity = spec.elements.inputPrice.getValueValidityLevel(value.priceInCents);
1100
+ if (centsValidity !== "VALID" /* VALID */) {
1101
+ return centsValidity;
1102
+ }
1103
+ return spec.elements.selectCurrency.getValueValidityLevel(value.currency);
1104
+ };
1105
+ static parseFormattedPrice = (locale, formattedPrice, currency) => {
1106
+ const thousandSeparator = Intl.NumberFormat(locale).format(11111).replace(/\p{Number}/gu, "");
1107
+ const decimalSeparator = Intl.NumberFormat(locale).format(1.1).replace(/\p{Number}/gu, "");
1108
+ const sanitizedPrice = formattedPrice.replace(new RegExp("\\" + thousandSeparator, "g"), "").replace(new RegExp("\\" + decimalSeparator), ".").replace(new RegExp("[^0-9.]", "g"), "").trim();
1109
+ const parsedPriceCents = Math.round(100 * parseFloat(sanitizedPrice));
1110
+ return { priceInCents: parsedPriceCents, currency };
1111
+ };
1112
+ static parseFormattedPriceWithCurrency = (locale, formattedPrice, currencySymbolMapping) => {
1113
+ const thousandSeparator = Intl.NumberFormat(locale).format(11111).replace(/\p{Number}/gu, "");
1114
+ const decimalSeparator = Intl.NumberFormat(locale).format(1.1).replace(/\p{Number}/gu, "");
1115
+ const sanitizedPrice = formattedPrice.replace(new RegExp("\\" + thousandSeparator, "g"), "").replace(new RegExp("\\" + decimalSeparator), ".").replace(new RegExp("[^0-9.]", "g"), "").trim();
1116
+ const parsedPriceCents = Math.round(100 * parseFloat(sanitizedPrice));
1117
+ const supportedCurrencies = Object.keys(currencySymbolMapping);
1118
+ const currencySymbolsFound = supportedCurrencies.filter((symbol) => formattedPrice.includes(symbol));
1119
+ if (currencySymbolsFound.length > 1) {
1120
+ throw new Error(`Multiple currency symbols found in formatter price string ${formattedPrice}, here are the supported currencies: ${supportedCurrencies}`);
1121
+ }
1122
+ return {
1123
+ priceInCents: parsedPriceCents,
1124
+ currency: currencySymbolMapping[currencySymbolsFound[0]]
1125
+ };
1126
+ };
1127
+ };
1128
+
1129
+ // src/views/CSVPriceInputView.tsx
1130
+ var import_jsx_runtime26 = require("react/jsx-runtime");
1131
+ var CSV_PRICE_INPUT_VIEW_SPEC = (parent, key) => ViewSpec.create(key, parent.ns, (spec) => ({
1132
+ inputPrice: spec.addField(new FieldSpec("inputPrice", true, void 0, 0)),
1133
+ selectCurrency: spec.addField(new FieldSpec("currency", true)),
1134
+ boxPriceDisplay: spec.addField(new FieldSpec("boxPriceDisplay"))
1135
+ }), key, parent, PriceUtils.getPriceValidityLevel);
1136
+ function CSVPriceInputView(props) {
1137
+ const spec = props.viewSpec;
1138
+ const { elements } = spec;
1139
+ const priceInCents = props.value ? props.value.priceInCents : 0;
1140
+ const currency = props.value ? props.value.currency : props.defaultCurrency;
1141
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
1142
+ import_components21.Grid,
1143
+ {
1144
+ gridDefinition: [{ colspan: 4 }, { colspan: { default: 4, xxs: 3 } }, { colspan: { default: 4, xxs: 5 } }],
1145
+ disableGutters: true,
1146
+ children: [
1147
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1148
+ CSNumericInput,
1149
+ {
1150
+ fieldSpec: elements.inputPrice,
1151
+ value: priceInCents / 100,
1152
+ step: 0.01,
1153
+ disabled: props.disabled,
1154
+ localiser: props.localiser,
1155
+ onChangeValue: (propertyName, changedValue) => props.onChange(props.viewSpec.key, {
1156
+ priceInCents: parseFloat(changedValue) * 100,
1157
+ currency
1158
+ })
1159
+ }
1160
+ ),
1161
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { style: { paddingLeft: "8px" }, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1162
+ CSEnumSelect,
1163
+ {
1164
+ fieldSpec: elements.selectCurrency,
1165
+ localiser: props.localiser,
1166
+ factory: props.currencyFactory,
1167
+ selectedEnum: currency,
1168
+ disabled: props.disabled,
1169
+ onChangeValue: (propertyName, changedValue) => props.onChange(props.viewSpec.key, {
1170
+ priceInCents,
1171
+ currency: changedValue
1172
+ }),
1173
+ expandToViewport: props.expandToViewport
1174
+ }
1175
+ ) }),
1176
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { style: { paddingTop: "30px", paddingLeft: "8px" }, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1177
+ CSBox,
1178
+ {
1179
+ fieldSpec: elements.boxPriceDisplay,
1180
+ localiser: props.localiser,
1181
+ fontSize: "heading-s",
1182
+ fontWeight: "heavy",
1183
+ variant: "awsui-key-label",
1184
+ children: PriceUtils.getFormattedPrice(props.localiser.language(), { priceInCents, currency })
1185
+ }
1186
+ ) })
1187
+ ]
1188
+ }
1189
+ );
1190
+ }
1191
+
1192
+ // src/views/CSVSearchFilterView.tsx
1193
+ var import_components22 = require("@cloudscape-design/components");
1194
+ var import_jsx_runtime27 = require("react/jsx-runtime");
1195
+ var CSV_SEARCH_FILTER_VIEW_SPEC = (parent, key) => ViewSpec.create(key, parent.ns, (spec) => ({
1196
+ inputSearch: spec.addField(new FieldSpec("inputSearch")),
1197
+ buttonSearch: spec.addField(new FieldSpec("buttonSearch"))
1198
+ }), void 0, parent);
1199
+ function CSVSearchFilterView(props) {
1200
+ const spec = props.viewSpec;
1201
+ const { elements } = spec;
1202
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(import_components22.SpaceBetween, { size: "s", direction: "horizontal", children: [
1203
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { style: { minWidth: "320px" }, children: props.inputSearch === void 0 || typeof props.inputSearch === "string" ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
1204
+ CSInput,
1205
+ {
1206
+ fieldSpec: elements.inputSearch,
1207
+ localiser: props.localiser,
1208
+ autoFocus: true,
1209
+ placeholder: props.inputSearch,
1210
+ onChangeValue: props.onChangeValue,
1211
+ value: props.searchString,
1212
+ type: "search"
1213
+ }
1214
+ ) : props.inputSearch }),
1215
+ props.buttonSearch === void 0 || typeof props.buttonSearch === "string" ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
1216
+ CSButton,
1217
+ {
1218
+ fieldSpec: elements.buttonSearch,
1219
+ localiser: props.localiser,
1220
+ variant: "primary",
1221
+ iconName: "search",
1222
+ onClick: props.onConfirmSearch,
1223
+ formAction: "submit",
1224
+ loading: props.loading,
1225
+ disabled: props.searchDisabled,
1226
+ children: props.buttonSearch
1227
+ }
1228
+ ) : props.buttonSearch
1229
+ ] });
1230
+ }
1231
+
1232
+ // src/views/CSVTextPromptModalView.tsx
1233
+ var import_components23 = require("@cloudscape-design/components");
1234
+ var import_jsx_runtime28 = require("react/jsx-runtime");
1235
+ var CSV_TEXT_PROMPT_MODAL_VIEW_SPEC = (parent, key) => ViewSpec.create(key, parent.ns, (spec) => ({
1236
+ headerHeading: spec.addField(new FieldSpec("headerHeading")),
1237
+ boxBodyText: spec.addField(new FieldSpec("boxBodyText")),
1238
+ buttonPrimary: spec.addField(new FieldSpec("buttonPrimary")),
1239
+ buttonSecondary: spec.addField(new FieldSpec("buttonSecondary"))
1240
+ }), void 0, parent);
1241
+ function CSVTextPromptModalView(props) {
1242
+ const spec = props.viewSpec;
1243
+ const { elements } = spec;
1244
+ const secondaryAction = props.onSecondaryAction ? props.buttonSecondary === void 0 || typeof props.buttonSecondary === "string" ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1245
+ CSButton,
1246
+ {
1247
+ fieldSpec: elements.buttonSecondary,
1248
+ localiser: props.localiser,
1249
+ variant: "normal",
1250
+ onClick: props.onSecondaryAction,
1251
+ children: props.buttonSecondary
1252
+ }
1253
+ ) : props.buttonSecondary : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, {});
1254
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1255
+ import_components23.Modal,
1256
+ {
1257
+ "data-testid": props.viewSpec.getDataTestId(),
1258
+ onDismiss: props.onDismiss,
1259
+ visible: props.visible,
1260
+ header: props.headerHeading === void 0 || typeof props.headerHeading === "string" ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1261
+ CSHeader,
1262
+ {
1263
+ fieldSpec: elements.headerHeading,
1264
+ localiser: props.localiser,
1265
+ children: props.headerHeading
1266
+ }
1267
+ ) : props.headerHeading,
1268
+ footer: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_components23.Box, { float: "right", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_components23.SpaceBetween, { direction: "horizontal", size: "l", children: [
1269
+ props.buttonPrimary === void 0 || typeof props.buttonPrimary === "string" ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1270
+ CSButton,
1271
+ {
1272
+ fieldSpec: elements.buttonPrimary,
1273
+ localiser: props.localiser,
1274
+ variant: "primary",
1275
+ onClick: props.onPrimaryAction,
1276
+ children: props.buttonPrimary
1277
+ }
1278
+ ) : props.buttonPrimary,
1279
+ secondaryAction
1280
+ ] }) }),
1281
+ children: props.boxBodyText === void 0 || typeof props.boxBodyText === "string" ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(CSBox, { fieldSpec: elements.boxBodyText, localiser: props.localiser, children: props.boxBodyText }) : props.boxBodyText
1282
+ }
1283
+ );
1284
+ }
1285
+
1286
+ // src/hooks/ControllerState.ts
1287
+ var ControllerState = /* @__PURE__ */ ((ControllerState2) => {
1288
+ ControllerState2[ControllerState2["UNMOUNTED"] = 0] = "UNMOUNTED";
1289
+ ControllerState2[ControllerState2["INITIALIZING"] = 1] = "INITIALIZING";
1290
+ ControllerState2[ControllerState2["NORMAL"] = 2] = "NORMAL";
1291
+ ControllerState2[ControllerState2["FATAL_ERROR"] = 3] = "FATAL_ERROR";
1292
+ return ControllerState2;
1293
+ })(ControllerState || {});
1294
+
1295
+ // src/utils/DateUtils.ts
1296
+ var DateUtils = class _DateUtils {
1297
+ static dateAsString(date) {
1298
+ const dd = String(date.getDate()).padStart(2, "0");
1299
+ const mm = String(date.getMonth() + 1).padStart(2, "0");
1300
+ const yyyy = date.getFullYear();
1301
+ return yyyy + "-" + mm + "-" + dd;
1302
+ }
1303
+ static dateAsDateTimeString(date, language) {
1304
+ return date.toLocaleDateString(language) + " " + date.toLocaleTimeString(language);
1305
+ }
1306
+ static nextSundayAt(hour, minute, second) {
1307
+ const today = /* @__PURE__ */ new Date();
1308
+ const addDays = 7 - today.getDay();
1309
+ const nextSunday = new Date(today.getTime() + addDays * 24 * 60 * 60 * 1e3);
1310
+ nextSunday.setHours(hour, minute, second, 0);
1311
+ return nextSunday;
1312
+ }
1313
+ static getCurrentUserTimezone() {
1314
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
1315
+ }
1316
+ static dateTimeAsUTCISO8601String(date) {
1317
+ const hh = String(date.getHours()).padStart(2, "0");
1318
+ const MM = String(date.getMinutes()).padStart(2, "0");
1319
+ const ss = String(date.getSeconds()).padStart(2, "0");
1320
+ return _DateUtils.dateAsString(date) + "T" + hh + ":" + MM + ":" + ss + "Z";
1321
+ }
1322
+ static currentDateTimeAsUTCISO8601String() {
1323
+ const now = /* @__PURE__ */ new Date();
1324
+ return _DateUtils.dateTimeAsUTCISO8601String(now);
1325
+ }
1326
+ static currentDateAsISO8601String() {
1327
+ const now = /* @__PURE__ */ new Date();
1328
+ return _DateUtils.dateAsString(now);
1329
+ }
1330
+ static toFormattedLocalizedDate(locale, inputInUTCISO8601, timezone) {
1331
+ if (inputInUTCISO8601 === void 0 || inputInUTCISO8601 === null) {
1332
+ return "";
1333
+ }
1334
+ return new Intl.DateTimeFormat(locale, {
1335
+ year: "numeric",
1336
+ month: "2-digit",
1337
+ day: "2-digit",
1338
+ hour: "2-digit",
1339
+ minute: "2-digit",
1340
+ second: "2-digit",
1341
+ hour12: false,
1342
+ timeZone: timezone
1343
+ }).format(new Date(inputInUTCISO8601));
1344
+ }
1345
+ };
1346
+
1347
+ // src/types/FieldProperties.ts
1348
+ var FieldProperties = class {
1349
+ constructor(key, required, maxLength, minValue, maxValue) {
1350
+ this.key = key;
1351
+ this.required = required;
1352
+ this.maxLength = maxLength;
1353
+ this.minValue = minValue;
1354
+ this.maxValue = maxValue;
1355
+ }
1356
+ };
1357
+
1358
+ // src/utils/FixedWidth.tsx
1359
+ var import_jsx_runtime29 = require("react/jsx-runtime");
1360
+ function FixedWidth(props) {
1361
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { style: { minWidth: props.minWidth, maxWidth: props.maxWidth }, children: props.children });
1362
+ }
1363
+
1364
+ // src/utils/LocalStorageService.ts
1365
+ var ITEM_SEP = ",";
1366
+ var LocalStorageService = class {
1367
+ static getItemStringArrayWithDefault(key, defaultValue) {
1368
+ const result = this.safeGetItem(key);
1369
+ if (result === null) {
1370
+ return defaultValue;
1371
+ }
1372
+ return result.split(ITEM_SEP);
1373
+ }
1374
+ static getItemEnumArrayWithDefault(enumClass, key, defaultValue) {
1375
+ const enumConstantsAsStrings = this.getItemStringArrayWithDefault(key, defaultValue.map((s) => s.toString()));
1376
+ const keys = Object.keys(enumClass);
1377
+ const values = Object.values(enumClass);
1378
+ const dict = {};
1379
+ for (let index = 0; index < keys.length; index++) {
1380
+ dict[values[index]] = keys[index];
1381
+ }
1382
+ return enumConstantsAsStrings.map((val) => dict[val]);
1383
+ }
1384
+ static setItemEnumArray(key, value) {
1385
+ this.setItemStringArray(key, value.map((e) => e.toString()));
1386
+ }
1387
+ static setItemStringArray(key, value) {
1388
+ this.safeSetItem(key, value.join(","));
1389
+ }
1390
+ static getItemWithDefault(key, defaultValue) {
1391
+ const result = this.safeGetItem(key);
1392
+ if (result === null) {
1393
+ return defaultValue;
1394
+ }
1395
+ return result;
1396
+ }
1397
+ static setItem(key, value) {
1398
+ return this.safeSetItem(key, value);
1399
+ }
1400
+ static clear() {
1401
+ window.localStorage.clear();
1402
+ }
1403
+ static setObject(key, value) {
1404
+ return this.safeSetItem(key, JSON.stringify(value));
1405
+ }
1406
+ static getObjectWithDefault(key, defaultValue) {
1407
+ const result = this.safeGetItem(key);
1408
+ if (result === null) {
1409
+ return defaultValue;
1410
+ }
1411
+ return JSON.parse(result);
1412
+ }
1413
+ static safeGetItem(key) {
1414
+ try {
1415
+ return localStorage.getItem(key);
1416
+ } catch (error) {
1417
+ console.log(`WARNING: could not get item with key ${key} from local storage due to exception: ${error}`);
1418
+ return null;
1419
+ }
1420
+ }
1421
+ static safeSetItem(key, value) {
1422
+ try {
1423
+ return localStorage.setItem(key, value);
1424
+ } catch (error) {
1425
+ console.log(`WARNING: could not set item with key ${key} and value ${value} in local storage due to exception: ${error}`);
1426
+ return null;
1427
+ }
1428
+ }
1429
+ };
1430
+
1431
+ // src/localisation/LocalisationNamespace.ts
1432
+ var LocalisationNamespace = class {
1433
+ constructor(name) {
1434
+ this.name = name;
1435
+ }
1436
+ /**
1437
+ *
1438
+ * @param parts The parts. Call this with comma-separated args, e.g. createKey(arg1, arg2, arg3) or with array using following syntax:
1439
+ * createKey(...[arg1, arg2, arg3]). DO NOT call it directly with an array!
1440
+ * This is WRONG: createKey([arg1, arg2, arg3]). It will treat the array as single arg and call toString() on it.
1441
+ */
1442
+ createKey(...parts) {
1443
+ return this.name + "." + parts.join(".");
1444
+ }
1445
+ };
1446
+ var NSK_CONTENT = "content";
1447
+
1448
+ // src/localisation/Localiser.ts
1449
+ var Localiser = class {
1450
+ constructor(translate, ns) {
1451
+ this.translate = translate;
1452
+ this.ns = ns;
1453
+ }
1454
+ getEnumLabel(factory, instance) {
1455
+ return this.getEnumLocalisation(factory, instance).label;
1456
+ }
1457
+ getAllEnumLabels(factory) {
1458
+ return factory.values.map((instance) => this.getEnumLabel(factory, instance));
1459
+ }
1460
+ };
1461
+
1462
+ // src/types/messaging/MessageSeverity.ts
1463
+ var MessageSeverity = /* @__PURE__ */ ((MessageSeverity2) => {
1464
+ MessageSeverity2["INFO"] = "INFO";
1465
+ MessageSeverity2["WARN"] = "WARN";
1466
+ MessageSeverity2["ERR"] = "ERR";
1467
+ MessageSeverity2["SUCCESS"] = "SUCCESS";
1468
+ return MessageSeverity2;
1469
+ })(MessageSeverity || {});
1470
+ var MESSAGE_SEVERITY_FACTORY = new EnumFactory("MessageSeverity", Object.values(MessageSeverity));
1471
+
1472
+ // src/types/messaging/MessageCTO.ts
1473
+ var MessageCTO = class {
1474
+ static TIMESTAMP_PROPS = new FieldProperties("timestamp", true);
1475
+ static DETAIL_MESSAGE_PROPS = new FieldProperties("detailMessage", true);
1476
+ static CORRELATION_ID_PROPS = new FieldProperties("correlationId", true);
1477
+ static OPERATION_PROPS = new FieldProperties("operation", true);
1478
+ code;
1479
+ timestamp;
1480
+ detailMessage;
1481
+ correlationId;
1482
+ operation;
1483
+ };
1484
+
1485
+ // src/types/messaging/MessageCodeTO.ts
1486
+ var MessageCodeTO = class {
1487
+ static CONTROLLER_ID_PROPS = new FieldProperties("componentId", true);
1488
+ static HTTP_STATUS_CODE_PROPS = new FieldProperties("httpStatusCode", true);
1489
+ static LOCAL_CODE_PROPS = new FieldProperties("localCode", true);
1490
+ static MESSAGE_SEVERITY_PROPS = new FieldProperties("messageSeverity", true);
1491
+ static UNIQUE_CODE_PROPS = new FieldProperties("uniqueCode", true);
1492
+ componentId;
1493
+ httpStatusCode;
1494
+ localCode;
1495
+ messageSeverity;
1496
+ uniqueCode;
1497
+ };
1498
+
1499
+ // src/types/messaging/MessageService.ts
1500
+ var TECHNICAL_CONTROLLER_ID = "T";
1501
+ var NO_HTTP_CODE = 0;
1502
+ var MessageService = class _MessageService {
1503
+ static getResponseTOWithMessagesFromUnknownResponse(json, op, status) {
1504
+ const response = json !== void 0 && json !== null && json.hasOwnProperty("messages") ? json : _MessageService.createGenericErrorMessageTO(status, op);
1505
+ response.messages.forEach((m) => m.operation = op);
1506
+ return response;
1507
+ }
1508
+ static getSuccessContentWithMessagesCTO(json, op) {
1509
+ let result = { content: void 0, messages: [] };
1510
+ if (json.hasOwnProperty("content")) {
1511
+ result.content = json.content;
1512
+ }
1513
+ if (json.hasOwnProperty("messages")) {
1514
+ result.messages = json.messages;
1515
+ }
1516
+ result.messages.forEach((m) => m.operation = op);
1517
+ return result;
1518
+ }
1519
+ static createContentWithSuccessMessage = (operation, message) => {
1520
+ return this.createContentWithMessage(this.createMessageTO(
1521
+ TECHNICAL_CONTROLLER_ID,
1522
+ NO_HTTP_CODE.toString(),
1523
+ 0,
1524
+ message,
1525
+ operation,
1526
+ "SUCCESS" /* SUCCESS */
1527
+ ));
1528
+ };
1529
+ static createContentWithoutMessages = (content) => {
1530
+ return {
1531
+ messages: [],
1532
+ content
1533
+ };
1534
+ };
1535
+ static createContentWithInfoMessage = (operation, message) => {
1536
+ return this.createContentWithMessage(this.createMessageTO(
1537
+ TECHNICAL_CONTROLLER_ID,
1538
+ NO_HTTP_CODE.toString(),
1539
+ 0,
1540
+ message,
1541
+ operation,
1542
+ "INFO" /* INFO */
1543
+ ));
1544
+ };
1545
+ static createGenericErrorMessageTO = (httpStatusCode, operation) => {
1546
+ if (this.isAPIClientCallError(httpStatusCode)) {
1547
+ return this.createContentWithMessage(this.createMessageTO(TECHNICAL_CONTROLLER_ID, "998", httpStatusCode, "Generic API call client error", operation));
1548
+ } else if (this.isBackendError(httpStatusCode)) {
1549
+ return this.createContentWithMessage(this.createMessageTO(TECHNICAL_CONTROLLER_ID, "999", httpStatusCode, "Generic backend error", operation));
1550
+ } else {
1551
+ throw new Error("Calling this methods with any http status code outside 400-599 is not allowed.");
1552
+ }
1553
+ };
1554
+ static createCriticalErrorFrontendProcessingMessageTO = (operation, message) => {
1555
+ return this.createMessageTO(TECHNICAL_CONTROLLER_ID, "997", -1, message, operation);
1556
+ };
1557
+ static isAPIClientCallError = (httpStatusCode) => {
1558
+ return httpStatusCode >= 400 && httpStatusCode <= 499;
1559
+ };
1560
+ static isBackendError = (httpStatusCode) => {
1561
+ return httpStatusCode >= 500 && httpStatusCode <= 599;
1562
+ };
1563
+ static createContentWithMessage(message) {
1564
+ return {
1565
+ messages: [message],
1566
+ content: void 0
1567
+ };
1568
+ }
1569
+ static createMessageTO = (componentId, localCode, httpStatusCode, detailMessage, operation, severity) => {
1570
+ const message = new MessageCTO();
1571
+ message.code = new MessageCodeTO();
1572
+ message.code.httpStatusCode = httpStatusCode;
1573
+ message.code.componentId = componentId;
1574
+ message.code.localCode = localCode;
1575
+ message.code.uniqueCode = componentId + localCode;
1576
+ message.code.messageSeverity = severity ? severity : "ERR" /* ERR */;
1577
+ message.operation = operation;
1578
+ message.correlationId = "N/A";
1579
+ message.timestamp = DateUtils.currentDateTimeAsUTCISO8601String();
1580
+ message.detailMessage = detailMessage;
1581
+ return message;
1582
+ };
1583
+ };
1584
+
1585
+ // src/utils/QueryParamHelper.ts
1586
+ var QUERY_START = "?";
1587
+ var QUERY_SEP = "&";
1588
+ var QueryParamHelper = class {
1589
+ static appendQueryParam(query, key, value) {
1590
+ let result = query;
1591
+ if (!query.includes(QUERY_START)) {
1592
+ result = result + QUERY_START;
1593
+ }
1594
+ if (result[result.length - 1] !== QUERY_START) {
1595
+ result = result + QUERY_SEP;
1596
+ }
1597
+ return result + encodeURIComponent(key) + "=" + encodeURIComponent(value);
1598
+ }
1599
+ static getQueryParams(queryString) {
1600
+ const returnedParams = {};
1601
+ if (queryString === void 0 || queryString.length === 0 || !queryString.startsWith(QUERY_START)) {
1602
+ return returnedParams;
1603
+ }
1604
+ queryString = queryString.substring(1);
1605
+ const params = queryString.split(QUERY_SEP);
1606
+ if (params.length === 0 || params.length === 1 && params[0] === "") {
1607
+ return returnedParams;
1608
+ }
1609
+ params.forEach((param) => {
1610
+ const paramRegex = /^(?<key>.*?)=(?<value>.*?)$/;
1611
+ const matchArray = param.match(paramRegex);
1612
+ if (matchArray !== null && matchArray.groups) {
1613
+ const key = decodeURIComponent(matchArray.groups["key"]);
1614
+ returnedParams[key] = decodeURIComponent(matchArray.groups["value"]);
1615
+ }
1616
+ });
1617
+ return returnedParams;
1618
+ }
1619
+ };
1620
+
1621
+ // src/utils/RestClient.ts
1622
+ var REST_CLIENT_LOGGER = new Log("RestClient");
1623
+ function logStart(logMsg, url) {
1624
+ REST_CLIENT_LOGGER.debug("START " + logMsg + " using URL <" + url + "> ...");
1625
+ }
1626
+ function logDone(logMsg, url) {
1627
+ REST_CLIENT_LOGGER.debug("DONE " + logMsg + " using URL <" + url + "> .");
1628
+ }
1629
+ function logError(logMsg, url) {
1630
+ REST_CLIENT_LOGGER.debug("ERROR: ", logMsg, ", using URL <" + url + "> .");
1631
+ }
1632
+ function createRestClient() {
1633
+ return new RestClient("");
1634
+ }
1635
+ var RestClient = class {
1636
+ // Base URL. May be empty.
1637
+ baseUrl = "";
1638
+ prepareFetchConfig(method, payload, header = {}) {
1639
+ let headers = {
1640
+ Accept: "application/json",
1641
+ "Content-Type": "application/json",
1642
+ ...header
1643
+ };
1644
+ let config;
1645
+ if (payload) {
1646
+ config = {
1647
+ method,
1648
+ headers,
1649
+ body: JSON.stringify(payload)
1650
+ };
1651
+ } else {
1652
+ config = {
1653
+ method,
1654
+ headers
1655
+ };
1656
+ }
1657
+ return config;
1658
+ }
1659
+ /**
1660
+ * Creates a new REST client.
1661
+ * @param baseUrl base URL, so client can be called with relative URLs.
1662
+ */
1663
+ constructor(baseUrl) {
1664
+ if (baseUrl != null) {
1665
+ this.baseUrl = baseUrl;
1666
+ }
1667
+ }
1668
+ /**
1669
+ * Make a GET request on the specified endpoint
1670
+ *
1671
+ * @param {string} endpoint the endpoint relative to the baseUrl with a preceeding slash. e.g. '/users'.
1672
+ * @param {string} operation the operation name for logging.
1673
+ * @param {string} headers the HTTP headers to pass.
1674
+ */
1675
+ get(endpoint, operation, headers) {
1676
+ return this.callApi("get", endpoint, null, operation, headers);
1677
+ }
1678
+ /**
1679
+ * Make a PUT request on the specified endpoint
1680
+ *
1681
+ * @param {string} endpoint the endpoint relative to the baseUrl with a preceeding slash. e.g. '/users'.
1682
+ * @param {object} payload the request payload as object.
1683
+ * @param {string} operation the operation name for logging.
1684
+ */
1685
+ put(endpoint, payload, operation) {
1686
+ return this.callApi("put", endpoint, payload, operation);
1687
+ }
1688
+ /**
1689
+ * Make a POST request on the specified endpoint
1690
+ *
1691
+ * @param {string} endpoint the endpoint relative to the baseUrl with a preceeding slash. e.g. '/users'.
1692
+ * @param {object} payload the request payload as object.
1693
+ * @param {string} operation the operation name for logging.
1694
+ */
1695
+ post(endpoint, payload, operation) {
1696
+ return this.callApi("post", endpoint, payload, operation);
1697
+ }
1698
+ /**
1699
+ * Make a DELETE request on the specified endpoint
1700
+ *
1701
+ * @param {string} endpoint the endpoint relative to the baseUrl with a preceeding slash. e.g. '/users'.
1702
+ * @param {object} payload the request payload as object.
1703
+ * @param {string} operation the operation name for logging.
1704
+ */
1705
+ del(endpoint, payload, operation) {
1706
+ return this.callApi("delete", endpoint, payload, operation);
1707
+ }
1708
+ callApi(method, endpoint = "", payload = null, operation, header) {
1709
+ const url = `${this.baseUrl}${endpoint}`;
1710
+ const config = this.prepareFetchConfig(method, payload, header);
1711
+ const op = operation ? operation : "Unknown operation";
1712
+ logStart(op, url);
1713
+ REST_CLIENT_LOGGER.debug("Calling API - " + method + "," + url);
1714
+ REST_CLIENT_LOGGER.object("Payload", payload);
1715
+ return new Promise((resolve, reject) => {
1716
+ fetch(url, config).then((response) => {
1717
+ const contentType = response.headers.get("content-type");
1718
+ if (contentType && contentType.indexOf("application/json") !== -1) {
1719
+ return response.json().then((json) => ({
1720
+ status: response.status,
1721
+ json
1722
+ }));
1723
+ } else {
1724
+ return response.text().then((text) => ({
1725
+ status: response.status,
1726
+ json: {}
1727
+ }));
1728
+ }
1729
+ }).then((result) => {
1730
+ const { status, json } = result;
1731
+ if (status >= 400) {
1732
+ logError(op, url);
1733
+ REST_CLIENT_LOGGER.error("Api call failed with response code " + status + ", response body=" + Log.toReadableObjectString(json));
1734
+ const responseWithMessages = MessageService.getResponseTOWithMessagesFromUnknownResponse(json, op, status);
1735
+ return reject(responseWithMessages);
1736
+ } else {
1737
+ logDone(op, url);
1738
+ REST_CLIENT_LOGGER.debug("Api call successful " + status + ", response body=" + Log.toReadableObjectString(json));
1739
+ if (json === null || json === void 0) {
1740
+ const msg = "Invalid response body - must never be null or undefined";
1741
+ REST_CLIENT_LOGGER.error(msg);
1742
+ const responseWithMessages2 = {
1743
+ content: void 0,
1744
+ messages: [MessageService.createCriticalErrorFrontendProcessingMessageTO(op, msg)]
1745
+ };
1746
+ return reject(responseWithMessages2);
1747
+ }
1748
+ const responseWithMessages = MessageService.getSuccessContentWithMessagesCTO(json, op);
1749
+ return resolve(responseWithMessages);
1750
+ }
1751
+ }).catch((error) => {
1752
+ const msg = "Api call failed with unknown/network error during promise processing " + error;
1753
+ REST_CLIENT_LOGGER.error(msg);
1754
+ const responseWithMessages = {
1755
+ content: void 0,
1756
+ messages: [MessageService.createCriticalErrorFrontendProcessingMessageTO(op, msg)]
1757
+ };
1758
+ return reject(responseWithMessages);
1759
+ });
1760
+ });
1761
+ }
1762
+ };
1763
+
1764
+ // src/hooks/useControllerDisplayState.ts
1765
+ var import_react2 = require("react");
1766
+ var RunFunctionResult = class {
1767
+ constructor(success, messages, result, resultHistory) {
1768
+ this.success = success;
1769
+ this.messages = messages;
1770
+ this.result = result;
1771
+ this.resultHistory = resultHistory;
1772
+ }
1773
+ };
1774
+ var fatalRunErrorFunction = (reason) => {
1775
+ throw new Error(`Fatal error - could not handle run failure - reason: ${reason}`);
1776
+ };
1777
+ function useControllerDisplayState(initialDisplayMode, messages, logger) {
1778
+ const [state, setState] = (0, import_react2.useState)(0 /* UNMOUNTED */);
1779
+ const [loadingIndication, setLoadingIndication] = (0, import_react2.useState)({});
1780
+ const [modified, setModified] = (0, import_react2.useState)(false);
1781
+ const [displayMode, setDisplayMode] = (0, import_react2.useState)(initialDisplayMode);
1782
+ const [modalState, setModalState] = (0, import_react2.useState)({
1783
+ show: (modalId, confirmFunction) => showModal(modalId, true, confirmFunction),
1784
+ hide: (modalId) => showModal(modalId, false)
1785
+ });
1786
+ const { addMessages } = messages;
1787
+ const isLoading = (0, import_react2.useCallback)((service) => {
1788
+ return loadingIndication.hasOwnProperty(service.name) && loadingIndication[service.name] === true;
1789
+ }, [loadingIndication]);
1790
+ const load = (0, import_react2.useCallback)((service) => {
1791
+ setLoadingIndication((oldIndication) => ({ ...oldIndication, [service.name]: true }));
1792
+ }, []);
1793
+ const doneLoading = (0, import_react2.useCallback)((service) => {
1794
+ setLoadingIndication((oldIndication) => {
1795
+ return { ...oldIndication, [service.name]: false };
1796
+ });
1797
+ }, []);
1798
+ const enterDisplayMode = (0, import_react2.useCallback)((mode) => {
1799
+ setDisplayMode((previousMode) => {
1800
+ if (mode !== displayMode) {
1801
+ logger.info("Entering display mode: ", mode);
1802
+ return mode;
1803
+ }
1804
+ return previousMode;
1805
+ });
1806
+ }, [displayMode, logger]);
1807
+ const showModal = (0, import_react2.useCallback)((modalId, show, confirmFunction) => {
1808
+ if (show) {
1809
+ setModalState((originalModalState) => {
1810
+ if (originalModalState.modalId !== void 0) {
1811
+ throw Error("Cannot show multiple modals at the same time");
1812
+ }
1813
+ return { ...originalModalState, modalId, confirmFunction };
1814
+ });
1815
+ } else {
1816
+ setModalState((originalModalState) => {
1817
+ if (originalModalState.modalId === void 0 || originalModalState.modalId !== modalId) {
1818
+ throw Error("Cannot hide modal that isn't currently shown");
1819
+ }
1820
+ return { ...originalModalState, modalId: void 0, confirmFunction: void 0 };
1821
+ });
1822
+ }
1823
+ }, []);
1824
+ const run = (0, import_react2.useCallback)(function(service, execute, failureIsFatal, resultHistory) {
1825
+ load(service);
1826
+ return execute().then((result) => {
1827
+ addMessages(result);
1828
+ return Promise.resolve(new RunFunctionResult(
1829
+ true,
1830
+ result.messages,
1831
+ result.content,
1832
+ resultHistory
1833
+ ));
1834
+ }).catch((error) => {
1835
+ if (failureIsFatal) {
1836
+ setState(3 /* FATAL_ERROR */);
1837
+ }
1838
+ addMessages(error);
1839
+ return Promise.resolve(new RunFunctionResult(false, error.messages, void 0, resultHistory));
1840
+ }).finally(() => doneLoading(service));
1841
+ }, [addMessages, doneLoading, load]);
1842
+ return {
1843
+ state,
1844
+ setState,
1845
+ setDirty: (0, import_react2.useCallback)(setModified, [setModified]),
1846
+ isDirty: () => modified,
1847
+ isLoading,
1848
+ displayMode,
1849
+ enterDisplayMode,
1850
+ modalState,
1851
+ run
1852
+ };
1853
+ }
1854
+
1855
+ // src/utils/MiscUtils.ts
1856
+ var indexRangeArray = (length) => {
1857
+ return Array.from({ length }, (x, i) => i);
1858
+ };
1859
+ function filterArrayByIndices(items, indices) {
1860
+ return items.filter((value, index) => indices.includes(index));
1861
+ }
1862
+ function sortArrayByIndices(items, indices) {
1863
+ return items.filter((value, index) => indices.includes(index)).sort((left, right) => indices.indexOf(items.indexOf(left)) - indices.indexOf(items.indexOf(right)));
1864
+ }
1865
+ var sleep = (delaySeconds) => new Promise((resolve) => setTimeout(resolve, delaySeconds));
1866
+
1867
+ // src/types/messaging/ContentWithMessagesCTO.ts
1868
+ function isContentWithMessages(object) {
1869
+ return object.hasOwnProperty("messages");
1870
+ }
1871
+
1872
+ // src/hooks/useTOChangeHandler.ts
1873
+ var import_react3 = require("react");
1874
+ var ArrayStateHandler = class {
1875
+ static updateFieldsOfArrayElement(elementToUpdate, currentArrayContent, properties, onChangedArrayElement) {
1876
+ const newArrayValue = [...currentArrayContent];
1877
+ const affectedElementIndex = newArrayValue.indexOf(elementToUpdate);
1878
+ newArrayValue[affectedElementIndex] = { ...elementToUpdate, ...properties };
1879
+ if (onChangedArrayElement) {
1880
+ onChangedArrayElement([newArrayValue[affectedElementIndex]], newArrayValue);
1881
+ }
1882
+ return newArrayValue;
1883
+ }
1884
+ static removeArrayElements(elementsToRemove, currentArrayContent, onRemovedArrayElement) {
1885
+ const newArrayValue = [...currentArrayContent.filter((element) => elementsToRemove.indexOf(element) === -1)];
1886
+ if (onRemovedArrayElement) {
1887
+ onRemovedArrayElement(elementsToRemove, newArrayValue);
1888
+ }
1889
+ return newArrayValue;
1890
+ }
1891
+ static addArrayElements(elementsToAdd, currentArrayContent, onAddedArrayElements) {
1892
+ const newArrayValue = [...currentArrayContent, ...elementsToAdd];
1893
+ if (onAddedArrayElements) {
1894
+ onAddedArrayElements(elementsToAdd, newArrayValue);
1895
+ }
1896
+ return newArrayValue;
1897
+ }
1898
+ };
1899
+ function useTOChangeHandler(logger, toName, setTOState, notifications, setDirty) {
1900
+ const onPropertyChangeMulti = (0, import_react3.useCallback)((properties, automaticChange) => {
1901
+ logger.debug(`Changing state of the ${toName} Elements ${Object.keys(properties)} for affected element, using change object:`, JSON.stringify(properties));
1902
+ setTOState((previousValue) => {
1903
+ const newValue = { ...previousValue, ...properties };
1904
+ if (notifications && notifications.onChange) {
1905
+ for (const propertyName of Object.keys(properties)) {
1906
+ const changedValue = properties[propertyName];
1907
+ notifications.onChange(newValue, propertyName, changedValue);
1908
+ }
1909
+ }
1910
+ if (previousValue !== void 0 && setDirty !== void 0 && !automaticChange) {
1911
+ setDirty(true);
1912
+ }
1913
+ return newValue;
1914
+ });
1915
+ }, [logger, notifications, setDirty, setTOState, toName]);
1916
+ const onPropertyChange = (0, import_react3.useCallback)((propertyName, changedValue, automaticChange) => {
1917
+ onPropertyChangeMulti({ [propertyName]: changedValue }, automaticChange);
1918
+ }, [onPropertyChangeMulti]);
1919
+ return { onPropertyChange, onPropertyChangeMulti };
1920
+ }
1921
+ var singleChangeHandlerToMulti = (onPropertyChangeMulti) => {
1922
+ return (propertyName, changedValue) => onPropertyChangeMulti({ [propertyName]: changedValue });
1923
+ };
1924
+ function useTOArrayChangeHandler(logger, toName, setArrayState, handlers, setDirty) {
1925
+ const onChangeElement = (0, import_react3.useCallback)((element, properties) => {
1926
+ if (element !== void 0) {
1927
+ logger.debug(`Changing state of the ${toName} Elements ${Object.keys(properties)} for affected element, using change object:`, JSON.stringify(properties));
1928
+ setArrayState((previousValue) => ArrayStateHandler.updateFieldsOfArrayElement(
1929
+ element,
1930
+ previousValue,
1931
+ properties,
1932
+ handlers.onChange
1933
+ ));
1934
+ if (setDirty !== void 0) {
1935
+ setDirty(true);
1936
+ }
1937
+ }
1938
+ }, [logger, toName, setArrayState, setDirty, handlers.onChange]);
1939
+ const onRemoveElements = (0, import_react3.useCallback)((removedElements) => {
1940
+ if (removedElements.length > 0) {
1941
+ logger.debug(`Removing ${removedElements.length} elements from array`);
1942
+ setArrayState((previousValue) => ArrayStateHandler.removeArrayElements(
1943
+ removedElements,
1944
+ previousValue,
1945
+ handlers.onRemove
1946
+ ));
1947
+ if (setDirty !== void 0) {
1948
+ setDirty(true);
1949
+ }
1950
+ }
1951
+ }, [logger, setArrayState, setDirty, handlers.onRemove]);
1952
+ const onAddElements = (0, import_react3.useCallback)((newElements) => {
1953
+ if (newElements.length === 0) {
1954
+ logger.debug(`Adding no new elements to array`);
1955
+ } else {
1956
+ logger.debug(`Adding ${newElements.length} elements to array`);
1957
+ setArrayState((previousValue) => ArrayStateHandler.addArrayElements(
1958
+ newElements,
1959
+ previousValue,
1960
+ handlers.onAdd
1961
+ ));
1962
+ if (setDirty !== void 0) {
1963
+ setDirty(true);
1964
+ }
1965
+ }
1966
+ }, [logger, setArrayState, setDirty, handlers.onAdd]);
1967
+ return { onChangeElement, onRemoveElements, onAddElements };
1968
+ }
1969
+
1970
+ // src/hooks/useAWSUIRef.ts
1971
+ var import_react4 = require("react");
1972
+ function useAWSUIRef() {
1973
+ const customRef = (0, import_react4.useRef)(null);
1974
+ const isValidRef = () => {
1975
+ return customRef !== void 0 && customRef !== null && customRef.current !== void 0 && customRef.current !== null;
1976
+ };
1977
+ const focus = (0, import_react4.useCallback)(() => {
1978
+ if (isValidRef() && customRef.current.focus) {
1979
+ customRef.current.focus();
1980
+ }
1981
+ }, [customRef]);
1982
+ const scrollToView = (0, import_react4.useCallback)(() => {
1983
+ if (isValidRef() && customRef.current.scrollIntoView) {
1984
+ customRef.current.scrollIntoView(true);
1985
+ }
1986
+ }, [customRef]);
1987
+ const scrollToViewRef = (0, import_react4.useCallback)((element) => {
1988
+ if (element !== void 0 && element !== null && element.scrollIntoView) {
1989
+ element.scrollIntoView({ block: "nearest", behavior: "smooth" });
1990
+ }
1991
+ }, []);
1992
+ return {
1993
+ customRef,
1994
+ focus,
1995
+ scrollToView,
1996
+ scrollToViewRef
1997
+ };
1998
+ }
1999
+
2000
+ // src/hooks/useHotkeys.ts
2001
+ var import_react5 = require("react");
2002
+ var useHotkey = (key, shift, ctrl, alt, callback, node = null) => {
2003
+ const callbackRef = (0, import_react5.useRef)(callback);
2004
+ (0, import_react5.useLayoutEffect)(() => {
2005
+ callbackRef.current = callback;
2006
+ });
2007
+ const handleKeyPress = (0, import_react5.useCallback)(
2008
+ (event) => {
2009
+ if (event.key === key && (!shift || event.shiftKey) && (!ctrl || event.ctrlKey) && (!alt || event.altKey)) {
2010
+ callbackRef.current(event);
2011
+ }
2012
+ },
2013
+ [alt, ctrl, key, shift]
2014
+ );
2015
+ (0, import_react5.useEffect)(() => {
2016
+ const targetNode = node ?? document;
2017
+ targetNode && targetNode.addEventListener("keydown", handleKeyPress);
2018
+ return () => targetNode && targetNode.removeEventListener("keydown", handleKeyPress);
2019
+ }, [handleKeyPress, node]);
2020
+ };
2021
+
2022
+ // src/hooks/useMessages.ts
2023
+ var import_react6 = require("react");
2024
+ function useMessages(LOGGER3) {
2025
+ const [messages, setMessages] = (0, import_react6.useState)([]);
2026
+ const onDismissMessage = (0, import_react6.useCallback)((message) => {
2027
+ const newMessages = messages.filter((existingMsg) => message !== existingMsg);
2028
+ setMessages(newMessages);
2029
+ }, [messages]);
2030
+ const onToggleMessageDetail = (0, import_react6.useCallback)((message) => {
2031
+ const idx = messages.indexOf(message);
2032
+ const newMessages = [...messages];
2033
+ newMessages[idx].showDetails = !newMessages[idx].showDetails;
2034
+ setMessages(newMessages);
2035
+ }, [messages]);
2036
+ const addMessages = (0, import_react6.useCallback)((newMessages) => {
2037
+ if (!newMessages.hasOwnProperty("messages")) {
2038
+ LOGGER3.error("Given response data structure does not contain messages - probably another runtime error occurred: ", newMessages);
2039
+ if (newMessages.hasOwnProperty("stack")) {
2040
+ LOGGER3.error("Stack trace: ", newMessages.stack);
2041
+ }
2042
+ } else {
2043
+ const addedMessages = newMessages.messages.map((msg) => {
2044
+ return { ...msg, showDetails: false };
2045
+ });
2046
+ addedMessages.forEach((msg) => LOGGER3.info(`New message = <${msg.detailMessage}`));
2047
+ setMessages((oldMessages) => [...oldMessages, ...addedMessages]);
2048
+ }
2049
+ }, [LOGGER3]);
2050
+ const clearMessages = (0, import_react6.useCallback)(() => {
2051
+ setMessages([]);
2052
+ }, []);
2053
+ return {
2054
+ messages,
2055
+ addMessages,
2056
+ onDismissMessage,
2057
+ onToggleMessageDetail,
2058
+ clearMessages
2059
+ };
2060
+ }
2061
+ // Annotate the CommonJS export names for ESM import in node:
2062
+ 0 && (module.exports = {
2063
+ CSAlert,
2064
+ CSBox,
2065
+ CSButton,
2066
+ CSCheckbox,
2067
+ CSDatePicker,
2068
+ CSEnumMultiselect,
2069
+ CSEnumSegmentedControl,
2070
+ CSEnumSelect,
2071
+ CSEnumTiles,
2072
+ CSExternalLink,
2073
+ CSFormField,
2074
+ CSHeader,
2075
+ CSInput,
2076
+ CSLink,
2077
+ CSMultiselect,
2078
+ CSNumericInput,
2079
+ CSSegmentedControl,
2080
+ CSSelect,
2081
+ CSStatusIndicator,
2082
+ CSTextContent,
2083
+ CSTextarea,
2084
+ CSTimeInput,
2085
+ CSToggle,
2086
+ CSVEnumRatingView,
2087
+ CSVNoItemsView,
2088
+ CSVPriceInputView,
2089
+ CSVSearchFilterView,
2090
+ CSVTextPromptModalView,
2091
+ CSV_ENUM_RATING_VIEW_SPEC,
2092
+ CSV_NO_ITEMS_VIEW_SPEC,
2093
+ CSV_PRICE_INPUT_VIEW_SPEC,
2094
+ CSV_SEARCH_FILTER_VIEW_SPEC,
2095
+ CSV_TEXT_PROMPT_MODAL_VIEW_SPEC,
2096
+ ChildUtils,
2097
+ ControllerState,
2098
+ DateUtils,
2099
+ ELEMENT_VALIDITY_LEVEL_FACTORY,
2100
+ ElementValidityLevel,
2101
+ EnumFactory,
2102
+ FORM_FIELD_ID_SUFFIX,
2103
+ FieldProperties,
2104
+ FieldSpec,
2105
+ FixedWidth,
2106
+ FromPropsHelper,
2107
+ LocalStorageService,
2108
+ LocalisationNamespace,
2109
+ Localiser,
2110
+ Log,
2111
+ MESSAGE_SEVERITY_FACTORY,
2112
+ MessageCTO,
2113
+ MessageCodeTO,
2114
+ MessageService,
2115
+ MessageSeverity,
2116
+ NO_HTTP_CODE,
2117
+ NSK_CONTENT,
2118
+ ObjectWithId,
2119
+ PriceUtils,
2120
+ QUERY_SEP,
2121
+ QUERY_START,
2122
+ QueryParamHelper,
2123
+ REST_CLIENT_LOGGER,
2124
+ RestClient,
2125
+ RunFunctionResult,
2126
+ SelectHelper,
2127
+ TECHNICAL_CONTROLLER_ID,
2128
+ ViewSpec,
2129
+ createRestClient,
2130
+ fatalRunErrorFunction,
2131
+ filterArrayByIndices,
2132
+ getEnumRatingLabel,
2133
+ getEnumRatingValues,
2134
+ indexRangeArray,
2135
+ isContentWithMessages,
2136
+ openInNewTab,
2137
+ singleChangeHandlerToMulti,
2138
+ sleep,
2139
+ sortArrayByIndices,
2140
+ useAWSUIRef,
2141
+ useControllerDisplayState,
2142
+ useHotkey,
2143
+ useMessages,
2144
+ useTOArrayChangeHandler,
2145
+ useTOChangeHandler,
2146
+ warnWhenTabIsClosed
2147
+ });