dynamic-formik-form 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.mjs ADDED
@@ -0,0 +1,3611 @@
1
+ import React7, { createContext, useContext, useState, useCallback, useRef, useEffect } from 'react';
2
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
+
4
+ // src/components/DynamicForm.tsx
5
+ var FormContext = createContext(null);
6
+ var FormProvider = ({
7
+ children,
8
+ uiLibrary,
9
+ formik
10
+ }) => {
11
+ return /* @__PURE__ */ jsx(FormContext.Provider, { value: { uiLibrary, formik }, children });
12
+ };
13
+ var useFormContext = () => {
14
+ const context = useContext(FormContext);
15
+ if (!context) {
16
+ throw new Error("useFormContext must be used within FormProvider");
17
+ }
18
+ return context;
19
+ };
20
+ var defaultAdapter = {
21
+ Input: ({ className, disabled, error, ...props }) => /* @__PURE__ */ jsx(
22
+ "input",
23
+ {
24
+ className: `${className || ""} ${error ? "error" : ""}`,
25
+ disabled,
26
+ ...props
27
+ }
28
+ ),
29
+ Textarea: ({ className, disabled, error, ...props }) => /* @__PURE__ */ jsx(
30
+ "textarea",
31
+ {
32
+ className: `${className || ""} ${error ? "error" : ""}`,
33
+ disabled,
34
+ ...props
35
+ }
36
+ ),
37
+ Select: ({ className, disabled, error, children, ...props }) => /* @__PURE__ */ jsx(
38
+ "select",
39
+ {
40
+ className: `${className || ""} ${error ? "error" : ""}`,
41
+ disabled,
42
+ ...props,
43
+ children
44
+ }
45
+ ),
46
+ Checkbox: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsxs("label", { className, children: [
47
+ /* @__PURE__ */ jsx("input", { type: "checkbox", disabled, ...props }),
48
+ label
49
+ ] }),
50
+ Radio: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsxs("label", { className, children: [
51
+ /* @__PURE__ */ jsx("input", { type: "radio", disabled, ...props }),
52
+ label
53
+ ] }),
54
+ Switch: ({ className, disabled, ...props }) => /* @__PURE__ */ jsx(
55
+ "input",
56
+ {
57
+ type: "checkbox",
58
+ className: `switch ${className || ""}`,
59
+ disabled,
60
+ ...props
61
+ }
62
+ ),
63
+ Button: ({ className, disabled, children, ...props }) => /* @__PURE__ */ jsx("button", { className, disabled, ...props, children }),
64
+ FormControl: ({ className, children }) => /* @__PURE__ */ jsx("div", { className: `form-control ${className || ""}`, children }),
65
+ FormHelperText: ({ className, children }) => /* @__PURE__ */ jsx("small", { className: `form-helper-text ${className || ""}`, children }),
66
+ Label: ({ className, htmlFor, children }) => /* @__PURE__ */ jsx("label", { className, htmlFor, children }),
67
+ Box: ({ className, children, ...props }) => /* @__PURE__ */ jsx("div", { className, ...props, children }),
68
+ Paper: ({ className, children }) => /* @__PURE__ */ jsx("div", { className: `paper ${className || ""}`, children }),
69
+ Popover: ({ open, anchorEl, onClose, children, anchorOrigin }) => {
70
+ if (!open || !anchorEl) return null;
71
+ const rect = anchorEl.getBoundingClientRect();
72
+ const style = {
73
+ position: "fixed",
74
+ top: `${rect.bottom}px`,
75
+ left: `${rect.left}px`,
76
+ zIndex: 1e3
77
+ };
78
+ return /* @__PURE__ */ jsx("div", { className: "popover", style, onClick: onClose, children });
79
+ },
80
+ MenuItem: ({ className, onClick, children }) => /* @__PURE__ */ jsx("div", { className: `menu-item ${className || ""}`, onClick, children }),
81
+ Typography: ({ className, variant, children }) => /* @__PURE__ */ jsx("div", { className: `typography typography-${variant || "body1"} ${className || ""}`, children }),
82
+ IconButton: ({ className, size, onClick, children, ...props }) => /* @__PURE__ */ jsx(
83
+ "button",
84
+ {
85
+ type: "button",
86
+ className: `icon-button icon-button-${size || "medium"} ${className || ""}`,
87
+ onClick,
88
+ ...props,
89
+ children
90
+ }
91
+ )
92
+ };
93
+ var createMUIAdapter = (Box, Button, Checkbox, FormControl, FormControlLabel, FormHelperText, IconButton, MenuItem, Paper, Popover, Radio, RadioGroup, Switch, TextField2, Typography, DatePicker, DateTimePicker) => {
94
+ return {
95
+ Input: ({ className, disabled, error, type, ...props }) => /* @__PURE__ */ jsx(
96
+ TextField2,
97
+ {
98
+ ...props,
99
+ type,
100
+ disabled,
101
+ error: !!error,
102
+ className,
103
+ fullWidth: true,
104
+ variant: "outlined"
105
+ }
106
+ ),
107
+ Textarea: ({ className, disabled, error, rows, ...props }) => /* @__PURE__ */ jsx(
108
+ TextField2,
109
+ {
110
+ ...props,
111
+ multiline: true,
112
+ rows: rows || 4,
113
+ disabled,
114
+ error: !!error,
115
+ className,
116
+ fullWidth: true,
117
+ variant: "outlined"
118
+ }
119
+ ),
120
+ Select: ({ className, disabled, error, children, ...props }) => /* @__PURE__ */ jsx(
121
+ TextField2,
122
+ {
123
+ ...props,
124
+ select: true,
125
+ disabled,
126
+ error: !!error,
127
+ className,
128
+ fullWidth: true,
129
+ variant: "outlined",
130
+ children
131
+ }
132
+ ),
133
+ Checkbox: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsx(
134
+ FormControlLabel,
135
+ {
136
+ control: /* @__PURE__ */ jsx(
137
+ Checkbox,
138
+ {
139
+ ...props,
140
+ disabled,
141
+ className,
142
+ color: "primary"
143
+ }
144
+ ),
145
+ label
146
+ }
147
+ ),
148
+ Radio: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsx(
149
+ FormControlLabel,
150
+ {
151
+ control: /* @__PURE__ */ jsx(
152
+ Radio,
153
+ {
154
+ ...props,
155
+ disabled,
156
+ className,
157
+ color: "primary"
158
+ }
159
+ ),
160
+ label
161
+ }
162
+ ),
163
+ Switch: ({ className, disabled, ...props }) => /* @__PURE__ */ jsx(
164
+ Switch,
165
+ {
166
+ ...props,
167
+ disabled,
168
+ className,
169
+ color: "primary"
170
+ }
171
+ ),
172
+ Button: ({ className, disabled, children, variant, ...props }) => /* @__PURE__ */ jsx(
173
+ Button,
174
+ {
175
+ ...props,
176
+ disabled,
177
+ className,
178
+ variant: variant || "contained",
179
+ color: "primary",
180
+ children
181
+ }
182
+ ),
183
+ FormControl: ({ className, required, error, children }) => /* @__PURE__ */ jsx(
184
+ FormControl,
185
+ {
186
+ className,
187
+ required,
188
+ error: !!error,
189
+ fullWidth: true,
190
+ children
191
+ }
192
+ ),
193
+ FormHelperText: ({ className, children }) => /* @__PURE__ */ jsx(FormHelperText, { className, children }),
194
+ Label: ({ className, htmlFor, children }) => /* @__PURE__ */ jsx(
195
+ Typography,
196
+ {
197
+ component: "label",
198
+ htmlFor,
199
+ className,
200
+ variant: "body2",
201
+ fontWeight: "medium",
202
+ children
203
+ }
204
+ ),
205
+ Box: ({ className, sx, children, ...props }) => /* @__PURE__ */ jsx(Box, { className, sx, ...props, children }),
206
+ Paper: ({ className, elevation, children }) => /* @__PURE__ */ jsx(Paper, { className, elevation: elevation || 3, children }),
207
+ Popover: ({ open, anchorEl, onClose, anchorOrigin, children }) => /* @__PURE__ */ jsx(
208
+ Popover,
209
+ {
210
+ open,
211
+ anchorEl,
212
+ onClose,
213
+ anchorOrigin: anchorOrigin || { vertical: "bottom", horizontal: "left" },
214
+ children
215
+ }
216
+ ),
217
+ MenuItem: ({ className, onClick, children }) => /* @__PURE__ */ jsx(MenuItem, { className, onClick, children }),
218
+ Typography: ({ className, variant, color, children }) => /* @__PURE__ */ jsx(Typography, { className, variant, color, children }),
219
+ IconButton: ({ className, size, onClick, children, ...props }) => /* @__PURE__ */ jsx(
220
+ IconButton,
221
+ {
222
+ className,
223
+ size,
224
+ onClick,
225
+ ...props,
226
+ children
227
+ }
228
+ ),
229
+ DatePicker: DatePicker ? ({ value, onChange, format, disabled, ...props }) => /* @__PURE__ */ jsx(
230
+ DatePicker,
231
+ {
232
+ value,
233
+ onChange,
234
+ format,
235
+ disabled,
236
+ ...props
237
+ }
238
+ ) : void 0,
239
+ DateTimePicker: DateTimePicker ? ({ value, onChange, format, disabled, views, ...props }) => /* @__PURE__ */ jsx(
240
+ DateTimePicker,
241
+ {
242
+ value,
243
+ onChange,
244
+ format,
245
+ disabled,
246
+ views,
247
+ ...props
248
+ }
249
+ ) : void 0,
250
+ TextField: TextField2 ? ({ inputRef, inputProps, label, id, error, helperText, ...props }) => /* @__PURE__ */ jsx(
251
+ TextField2,
252
+ {
253
+ inputRef,
254
+ inputProps,
255
+ label,
256
+ id,
257
+ error: !!error,
258
+ helperText,
259
+ ...props,
260
+ fullWidth: true,
261
+ variant: "outlined"
262
+ }
263
+ ) : void 0
264
+ };
265
+ };
266
+ var createBootstrapAdapter = (Form, FormControl, FormLabel, FormText, FormCheck, FormSelect, ButtonComponent, InputGroup, OverlayTrigger, Popover, ListGroup, ListGroupItem) => {
267
+ return {
268
+ Input: ({ className, disabled, error, type, ...props }) => /* @__PURE__ */ jsx(
269
+ FormControl,
270
+ {
271
+ ...props,
272
+ type,
273
+ disabled,
274
+ isInvalid: !!error,
275
+ className
276
+ }
277
+ ),
278
+ Textarea: ({ className, disabled, error, rows, ...props }) => /* @__PURE__ */ jsx(
279
+ FormControl,
280
+ {
281
+ ...props,
282
+ as: "textarea",
283
+ rows: rows || 4,
284
+ disabled,
285
+ isInvalid: !!error,
286
+ className
287
+ }
288
+ ),
289
+ Select: ({ className, disabled, error, children, ...props }) => /* @__PURE__ */ jsx(
290
+ FormSelect,
291
+ {
292
+ ...props,
293
+ disabled,
294
+ isInvalid: !!error,
295
+ className,
296
+ children
297
+ }
298
+ ),
299
+ Checkbox: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsx(
300
+ FormCheck,
301
+ {
302
+ ...props,
303
+ type: "checkbox",
304
+ disabled,
305
+ className,
306
+ label
307
+ }
308
+ ),
309
+ Radio: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsx(
310
+ FormCheck,
311
+ {
312
+ ...props,
313
+ type: "radio",
314
+ disabled,
315
+ className,
316
+ label
317
+ }
318
+ ),
319
+ Switch: ({ className, disabled, ...props }) => /* @__PURE__ */ jsx(
320
+ FormCheck,
321
+ {
322
+ ...props,
323
+ type: "switch",
324
+ disabled,
325
+ className
326
+ }
327
+ ),
328
+ Button: ({ className, disabled, children, variant, ...props }) => /* @__PURE__ */ jsx(
329
+ ButtonComponent,
330
+ {
331
+ ...props,
332
+ disabled,
333
+ className,
334
+ variant: variant || "primary",
335
+ children
336
+ }
337
+ ),
338
+ FormControl: ({ className, required, error, children }) => /* @__PURE__ */ jsx(Form, { className, children }),
339
+ FormHelperText: ({ className, children }) => /* @__PURE__ */ jsx(FormText, { className, children }),
340
+ Label: ({ className, htmlFor, children }) => /* @__PURE__ */ jsx(FormLabel, { htmlFor, className, children }),
341
+ Box: ({ className, children, ...props }) => /* @__PURE__ */ jsx("div", { className, ...props, children }),
342
+ Paper: ({ className, children }) => /* @__PURE__ */ jsx("div", { className: `card ${className || ""}`, children }),
343
+ Popover: ({ open, anchorEl, onClose, children, anchorOrigin }) => {
344
+ if (!open || !anchorEl) return null;
345
+ const rect = anchorEl.getBoundingClientRect();
346
+ const style = {
347
+ position: "fixed",
348
+ top: `${rect.bottom}px`,
349
+ left: `${rect.left}px`,
350
+ zIndex: 1e3,
351
+ backgroundColor: "white",
352
+ border: "1px solid #ccc",
353
+ borderRadius: "4px",
354
+ padding: "8px",
355
+ boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
356
+ };
357
+ return /* @__PURE__ */ jsx("div", { style, onClick: onClose, children });
358
+ },
359
+ MenuItem: ({ className, onClick, children }) => /* @__PURE__ */ jsx(
360
+ ListGroupItem,
361
+ {
362
+ className,
363
+ onClick,
364
+ action: true,
365
+ children
366
+ }
367
+ ),
368
+ Typography: ({ className, variant, children }) => {
369
+ const Tag = variant === "h6" ? "h6" : variant === "subtitle2" ? "h6" : "p";
370
+ return /* @__PURE__ */ jsx(Tag, { className, children });
371
+ },
372
+ IconButton: ({ className, size, onClick, children }) => /* @__PURE__ */ jsx(
373
+ ButtonComponent,
374
+ {
375
+ variant: "link",
376
+ className: `${className || ""} p-0`,
377
+ onClick,
378
+ size,
379
+ children
380
+ }
381
+ )
382
+ };
383
+ };
384
+ var createAntDesignAdapter = (Input, Button, Checkbox, Radio, Switch, Select, Form, Typography, Popover, DatePicker, DateTimePicker, Space, Card) => {
385
+ const TextArea = Input.TextArea || Input;
386
+ const { TextArea: AntDTextArea } = Input;
387
+ const { Text: TypographyText } = Typography;
388
+ const { Group: RadioGroup } = Radio;
389
+ const SpaceComponent = Space || (({ children, ...props }) => /* @__PURE__ */ jsx("div", { ...props, children }));
390
+ const CardComponent = Card || (({ children, className }) => /* @__PURE__ */ jsx("div", { className: `ant-card ${className || ""}`, children }));
391
+ return {
392
+ Input: ({ className, disabled, error, type, ...props }) => /* @__PURE__ */ jsx(
393
+ Input,
394
+ {
395
+ ...props,
396
+ type,
397
+ disabled,
398
+ status: error ? "error" : void 0,
399
+ className
400
+ }
401
+ ),
402
+ Textarea: ({ className, disabled, error, rows, ...props }) => /* @__PURE__ */ jsx(
403
+ TextArea,
404
+ {
405
+ ...props,
406
+ rows: rows || 4,
407
+ disabled,
408
+ status: error ? "error" : void 0,
409
+ className
410
+ }
411
+ ),
412
+ Select: ({ className, disabled, error, children, ...props }) => /* @__PURE__ */ jsx(
413
+ Select,
414
+ {
415
+ ...props,
416
+ disabled,
417
+ status: error ? "error" : void 0,
418
+ className,
419
+ children
420
+ }
421
+ ),
422
+ Checkbox: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsx(
423
+ Checkbox,
424
+ {
425
+ ...props,
426
+ disabled,
427
+ className,
428
+ children: label
429
+ }
430
+ ),
431
+ Radio: ({ className, disabled, label, ...props }) => /* @__PURE__ */ jsx(
432
+ Radio,
433
+ {
434
+ ...props,
435
+ disabled,
436
+ className,
437
+ children: label
438
+ }
439
+ ),
440
+ Switch: ({ className, disabled, ...props }) => /* @__PURE__ */ jsx(
441
+ Switch,
442
+ {
443
+ ...props,
444
+ disabled,
445
+ className
446
+ }
447
+ ),
448
+ Button: ({ className, disabled, children, variant, type, onClick, ...props }) => /* @__PURE__ */ jsx(
449
+ Button,
450
+ {
451
+ ...props,
452
+ disabled,
453
+ type: variant === "primary" ? "primary" : variant === "secondary" ? "default" : variant || "default",
454
+ htmlType: type,
455
+ onClick,
456
+ className,
457
+ children
458
+ }
459
+ ),
460
+ FormControl: ({ className, children }) => {
461
+ const FormComponent = Form;
462
+ const FormItem = FormComponent.Item || FormComponent;
463
+ return /* @__PURE__ */ jsx(FormItem, { className, children });
464
+ },
465
+ FormHelperText: ({ className, children }) => /* @__PURE__ */ jsx(TypographyText, { type: "secondary", className, children }),
466
+ Label: ({ className, htmlFor, children }) => /* @__PURE__ */ jsx("label", { className, htmlFor, children }),
467
+ Box: ({ className, children, ...props }) => /* @__PURE__ */ jsx(SpaceComponent, { className, ...props, children }),
468
+ Paper: ({ className, children }) => /* @__PURE__ */ jsx(CardComponent, { className, children }),
469
+ Popover: ({ open, anchorEl, onClose, children, anchorOrigin, ...props }) => {
470
+ if (!open) return null;
471
+ return /* @__PURE__ */ jsx(
472
+ Popover,
473
+ {
474
+ open,
475
+ onOpenChange: (visible) => !visible && onClose(),
476
+ placement: anchorOrigin?.vertical === "bottom" ? "bottom" : "top",
477
+ ...props,
478
+ children
479
+ }
480
+ );
481
+ },
482
+ MenuItem: ({ className, onClick, children }) => /* @__PURE__ */ jsx("div", { className: `ant-menu-item ${className || ""}`, onClick, children }),
483
+ Typography: ({ className, variant, children, ...props }) => {
484
+ const TypographyComponent = Typography;
485
+ return /* @__PURE__ */ jsx(TypographyComponent, { className, ...props, children });
486
+ },
487
+ IconButton: ({ className, size, onClick, children, ...props }) => /* @__PURE__ */ jsx(
488
+ Button,
489
+ {
490
+ type: "text",
491
+ size,
492
+ onClick,
493
+ className,
494
+ icon: children,
495
+ ...props
496
+ }
497
+ ),
498
+ DatePicker: DatePicker ? ({ value, onChange, format, disabled, ...props }) => /* @__PURE__ */ jsx(
499
+ DatePicker,
500
+ {
501
+ value,
502
+ onChange,
503
+ format,
504
+ disabled,
505
+ ...props
506
+ }
507
+ ) : void 0,
508
+ DateTimePicker: DateTimePicker ? ({ value, onChange, format, disabled, views, ...props }) => /* @__PURE__ */ jsx(
509
+ DateTimePicker,
510
+ {
511
+ value,
512
+ onChange,
513
+ format,
514
+ disabled,
515
+ showTime: true,
516
+ ...props
517
+ }
518
+ ) : void 0
519
+ };
520
+ };
521
+ var DefaultInfoIcon = ({
522
+ className,
523
+ size = 16
524
+ }) => /* @__PURE__ */ jsx(
525
+ "svg",
526
+ {
527
+ width: size,
528
+ height: size,
529
+ viewBox: "0 0 24 24",
530
+ fill: "currentColor",
531
+ className,
532
+ children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" })
533
+ }
534
+ );
535
+ var DefaultVisibilityIcon = ({ className, size = 16 }) => /* @__PURE__ */ jsx(
536
+ "svg",
537
+ {
538
+ width: size,
539
+ height: size,
540
+ viewBox: "0 0 24 24",
541
+ fill: "currentColor",
542
+ className,
543
+ children: /* @__PURE__ */ jsx("path", { d: "M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" })
544
+ }
545
+ );
546
+ var DefaultVisibilityOffIcon = ({ className, size = 16 }) => /* @__PURE__ */ jsx(
547
+ "svg",
548
+ {
549
+ width: size,
550
+ height: size,
551
+ viewBox: "0 0 24 24",
552
+ fill: "currentColor",
553
+ className,
554
+ children: /* @__PURE__ */ jsx("path", { d: "M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46C3.08 8.3 1.78 10.02 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z" })
555
+ }
556
+ );
557
+ var DefaultCopyIcon = ({
558
+ className,
559
+ size = 16
560
+ }) => /* @__PURE__ */ jsx(
561
+ "svg",
562
+ {
563
+ width: size,
564
+ height: size,
565
+ viewBox: "0 0 24 24",
566
+ fill: "currentColor",
567
+ className,
568
+ children: /* @__PURE__ */ jsx("path", { d: "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" })
569
+ }
570
+ );
571
+ var DefaultAddIcon = ({
572
+ className,
573
+ size = 16
574
+ }) => /* @__PURE__ */ jsx(
575
+ "svg",
576
+ {
577
+ width: size,
578
+ height: size,
579
+ viewBox: "0 0 24 24",
580
+ fill: "currentColor",
581
+ className,
582
+ children: /* @__PURE__ */ jsx("path", { d: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" })
583
+ }
584
+ );
585
+ var DefaultDeleteIcon = ({
586
+ className,
587
+ size = 16
588
+ }) => /* @__PURE__ */ jsx(
589
+ "svg",
590
+ {
591
+ width: size,
592
+ height: size,
593
+ viewBox: "0 0 24 24",
594
+ fill: "currentColor",
595
+ className,
596
+ children: /* @__PURE__ */ jsx("path", { d: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" })
597
+ }
598
+ );
599
+ var defaultIcons = {
600
+ Info: DefaultInfoIcon,
601
+ Visibility: DefaultVisibilityIcon,
602
+ VisibilityOff: DefaultVisibilityOffIcon,
603
+ Copy: DefaultCopyIcon,
604
+ Add: DefaultAddIcon,
605
+ Delete: DefaultDeleteIcon
606
+ };
607
+
608
+ // src/utils/formik.utils.ts
609
+ var getNestedProperty = (obj, path) => {
610
+ if (!path || !obj) {
611
+ return void 0;
612
+ }
613
+ const keys = path.split(/[.[\]]+/).filter(Boolean);
614
+ return keys.reduce((acc, key) => {
615
+ if (acc && typeof acc === "object" && key in acc) {
616
+ return acc[key];
617
+ }
618
+ return void 0;
619
+ }, obj);
620
+ };
621
+ var getNestedValueNew = (obj, path) => {
622
+ if (!obj || !path) {
623
+ return void 0;
624
+ }
625
+ return path.split(".").reduce(
626
+ (acc, key) => acc && typeof acc === "object" && key in acc ? acc[key] : void 0,
627
+ obj
628
+ );
629
+ };
630
+ var getFieldValue = (formik, name) => {
631
+ if (!name) return null;
632
+ if (name.includes(".")) {
633
+ if (name.includes("[")) {
634
+ return getNestedProperty(formik.values, name);
635
+ }
636
+ return name.split(".").reduce(
637
+ (acc, key) => acc && typeof acc === "object" && key in acc ? acc[key] : "",
638
+ formik.values
639
+ );
640
+ }
641
+ return formik.values[name];
642
+ };
643
+ var getFieldError = (formik, name) => {
644
+ if (!name) return void 0;
645
+ if (name.includes(".")) {
646
+ if (name.includes("[")) {
647
+ return getNestedProperty(formik.errors, name);
648
+ }
649
+ return name.split(".").reduce(
650
+ (acc, key) => acc && typeof acc === "object" && key in acc ? acc[key] : "",
651
+ formik.errors
652
+ );
653
+ }
654
+ return formik.errors[name];
655
+ };
656
+ var getFieldTouched = (formik, name) => {
657
+ if (!name) return false;
658
+ if (name.includes(".")) {
659
+ if (name.includes("[")) {
660
+ return !!getNestedProperty(formik.touched, name);
661
+ }
662
+ return !!name.split(".").reduce(
663
+ (acc, key) => acc && typeof acc === "object" && key in acc ? acc[key] : false,
664
+ formik.touched
665
+ );
666
+ }
667
+ return !!formik.touched[name];
668
+ };
669
+ var EmptyField = ({
670
+ name,
671
+ customHandleChange,
672
+ formik: formikProp
673
+ }) => {
674
+ const { uiLibrary, formik } = useFormContext();
675
+ const { adapter } = uiLibrary;
676
+ const Input = adapter.Input;
677
+ const activeFormik = formikProp || formik;
678
+ const fieldValue = getFieldValue(activeFormik, name) || "";
679
+ return /* @__PURE__ */ jsx(
680
+ Input,
681
+ {
682
+ id: name,
683
+ type: "hidden",
684
+ name,
685
+ className: "d-none",
686
+ value: fieldValue,
687
+ onChange: (event) => {
688
+ if (customHandleChange) {
689
+ customHandleChange(event, "emptyField");
690
+ } else {
691
+ activeFormik.handleChange(event);
692
+ }
693
+ },
694
+ onBlur: activeFormik.handleBlur
695
+ }
696
+ );
697
+ };
698
+ var FieldWrapper = ({
699
+ children,
700
+ className,
701
+ customClass,
702
+ isChild,
703
+ noIndent,
704
+ hidden,
705
+ index
706
+ }) => {
707
+ if (hidden) {
708
+ return /* @__PURE__ */ jsx("div", { className: "d-none", children });
709
+ }
710
+ const wrapperClasses = [
711
+ customClass || "mb-4",
712
+ isChild && !noIndent ? "ps-5" : "",
713
+ className || ""
714
+ ].filter(Boolean).join(" ");
715
+ return /* @__PURE__ */ jsx("div", { className: wrapperClasses, children }, index);
716
+ };
717
+ var IconRenderer = ({
718
+ Icon,
719
+ size = 16,
720
+ className
721
+ }) => {
722
+ if (!Icon) return null;
723
+ return React7.createElement(Icon, { size, className });
724
+ };
725
+ var FieldLabel = ({
726
+ name,
727
+ label,
728
+ required,
729
+ showOptional,
730
+ info,
731
+ htmlFor,
732
+ className,
733
+ customLabelClass
734
+ }) => {
735
+ const { uiLibrary } = useFormContext();
736
+ const { adapter, icons } = uiLibrary;
737
+ const Label = adapter.Label;
738
+ const IconButton = adapter.IconButton;
739
+ if (!label) return null;
740
+ const InfoIcon = icons?.Info;
741
+ return /* @__PURE__ */ jsxs(
742
+ Label,
743
+ {
744
+ htmlFor: htmlFor || name,
745
+ className: `${customLabelClass || className || ""}`,
746
+ children: [
747
+ /* @__PURE__ */ jsx("span", { children: label }),
748
+ required && /* @__PURE__ */ jsx("span", { className: "text-danger", children: " *" }),
749
+ showOptional && /* @__PURE__ */ jsx("span", { className: "text-12 ps-1 text-body-tertiary", children: " (Optional)" }),
750
+ info && InfoIcon && /* @__PURE__ */ jsx(
751
+ IconButton,
752
+ {
753
+ size: "small",
754
+ className: "p-0",
755
+ "aria-label": "show info",
756
+ tabIndex: -1,
757
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: InfoIcon, size: 16 })
758
+ }
759
+ )
760
+ ]
761
+ }
762
+ );
763
+ };
764
+
765
+ // src/utils/field.utils.ts
766
+ var formatString = (inputStr, ignoreChar = false) => {
767
+ if (!inputStr) return "";
768
+ let result = inputStr.replace(/_/g, "-").toLowerCase();
769
+ result = result.replace(/\s+/g, "-");
770
+ result = result.replace(/([a-z])([A-Z])/g, "$1-$2");
771
+ if (!ignoreChar) {
772
+ result = result.replace(/\//g, "-");
773
+ }
774
+ return result;
775
+ };
776
+ var camelToKebabCase = (str) => {
777
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
778
+ };
779
+ var sanitizeLabelForCSS = (label) => {
780
+ return label?.replace(/\s+/g, "_") || "";
781
+ };
782
+ var isBlank = (value) => {
783
+ return value === null || value === void 0 || value === "";
784
+ };
785
+ var isNotBlank = (value) => {
786
+ return !isBlank(value);
787
+ };
788
+ var FieldError = ({
789
+ name,
790
+ error,
791
+ touched,
792
+ showCustomError,
793
+ dataTestId,
794
+ className
795
+ }) => {
796
+ if (!showCustomError && (!error || !touched)) {
797
+ return null;
798
+ }
799
+ return /* @__PURE__ */ jsx(
800
+ "small",
801
+ {
802
+ id: "error",
803
+ "data-testid": dataTestId || `${formatString(name)}-error`,
804
+ className: className || "d-flex text-danger mt-1 text-12",
805
+ children: error
806
+ }
807
+ );
808
+ };
809
+ var TextField = ({
810
+ name,
811
+ label,
812
+ required,
813
+ customClass,
814
+ isChild,
815
+ noIndent,
816
+ hidden,
817
+ dataTestId,
818
+ showCustomError,
819
+ error: customError,
820
+ index,
821
+ formik: formikProp
822
+ }) => {
823
+ const { formik } = useFormContext();
824
+ const activeFormik = formikProp || formik;
825
+ const fieldValue = getFieldValue(activeFormik, name);
826
+ const fieldError = getFieldError(activeFormik, name);
827
+ const fieldTouched = getFieldTouched(activeFormik, name);
828
+ const isGroupHeading = typeof name === "string" && name.endsWith("__heading");
829
+ const groupKeyForHeading = isGroupHeading ? name.split("__")[0] : null;
830
+ const groupLevelError = groupKeyForHeading ? getFieldError(activeFormik, groupKeyForHeading) : null;
831
+ const resolvedTextError = showCustomError && customError ? customError : groupLevelError || fieldError;
832
+ const showErrorNow = !!resolvedTextError && (fieldTouched || activeFormik.submitCount > 0 || showCustomError);
833
+ return /* @__PURE__ */ jsxs(
834
+ FieldWrapper,
835
+ {
836
+ customClass,
837
+ isChild,
838
+ noIndent,
839
+ hidden,
840
+ index,
841
+ children: [
842
+ label && /* @__PURE__ */ jsx(
843
+ FieldLabel,
844
+ {
845
+ name,
846
+ label,
847
+ required
848
+ }
849
+ ),
850
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("p", { onClick: () => {
851
+ }, children: fieldValue }) }),
852
+ (showCustomError || showErrorNow) && /* @__PURE__ */ jsx(
853
+ FieldError,
854
+ {
855
+ name,
856
+ error: resolvedTextError,
857
+ touched: fieldTouched,
858
+ showCustomError,
859
+ dataTestId
860
+ }
861
+ )
862
+ ]
863
+ }
864
+ );
865
+ };
866
+ var FieldDescription = ({
867
+ desc,
868
+ className,
869
+ customDescClass
870
+ }) => {
871
+ const { uiLibrary } = useFormContext();
872
+ const { adapter } = uiLibrary;
873
+ const FormHelperText = adapter.FormHelperText;
874
+ if (!desc) return null;
875
+ return /* @__PURE__ */ jsx(FormHelperText, { className: customDescClass || className || "", children: desc });
876
+ };
877
+ var LinkField = ({
878
+ name,
879
+ label,
880
+ desc,
881
+ required,
882
+ customClass,
883
+ customComponentClass,
884
+ isChild,
885
+ noIndent,
886
+ hidden,
887
+ onClickLink,
888
+ component,
889
+ targetType,
890
+ index
891
+ }) => {
892
+ const handleClick = () => {
893
+ if (onClickLink) {
894
+ onClickLink();
895
+ }
896
+ };
897
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
898
+ /* @__PURE__ */ jsxs(
899
+ FieldWrapper,
900
+ {
901
+ customClass,
902
+ isChild,
903
+ noIndent,
904
+ hidden,
905
+ index,
906
+ children: [
907
+ label && /* @__PURE__ */ jsxs(
908
+ "a",
909
+ {
910
+ href: targetType === "blank" ? "#" : void 0,
911
+ target: targetType === "blank" ? "_blank" : void 0,
912
+ onClick: (e) => {
913
+ e.preventDefault();
914
+ handleClick();
915
+ },
916
+ style: { cursor: "pointer" },
917
+ children: [
918
+ label,
919
+ required && /* @__PURE__ */ jsx("span", { className: "text-danger", children: " *" })
920
+ ]
921
+ }
922
+ ),
923
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc })
924
+ ]
925
+ }
926
+ ),
927
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
928
+ ] });
929
+ };
930
+ var ComponentField = ({
931
+ customClass,
932
+ isChild,
933
+ noIndent,
934
+ component,
935
+ blockComponent,
936
+ index
937
+ }) => {
938
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
939
+ component && /* @__PURE__ */ jsx(
940
+ FieldWrapper,
941
+ {
942
+ customClass,
943
+ isChild,
944
+ noIndent,
945
+ index,
946
+ children: component
947
+ }
948
+ ),
949
+ blockComponent && /* @__PURE__ */ jsx(
950
+ FieldWrapper,
951
+ {
952
+ customClass,
953
+ isChild,
954
+ noIndent,
955
+ index,
956
+ children: blockComponent
957
+ }
958
+ )
959
+ ] });
960
+ };
961
+ var CustomField = ({
962
+ name,
963
+ label,
964
+ desc,
965
+ required,
966
+ customClass,
967
+ isChild,
968
+ noIndent,
969
+ hidden,
970
+ component,
971
+ index
972
+ }) => {
973
+ return /* @__PURE__ */ jsxs(
974
+ FieldWrapper,
975
+ {
976
+ customClass,
977
+ isChild,
978
+ noIndent,
979
+ hidden,
980
+ index,
981
+ children: [
982
+ label && /* @__PURE__ */ jsx(
983
+ FieldLabel,
984
+ {
985
+ name,
986
+ label,
987
+ required
988
+ }
989
+ ),
990
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
991
+ /* @__PURE__ */ jsx("div", { children: component })
992
+ ]
993
+ }
994
+ );
995
+ };
996
+ var InputField = ({
997
+ name,
998
+ type,
999
+ label,
1000
+ placeholder,
1001
+ desc,
1002
+ info,
1003
+ required,
1004
+ disabled,
1005
+ hidden,
1006
+ readonly,
1007
+ fieldType = "text",
1008
+ autocomplete,
1009
+ customClass,
1010
+ customLabelClass,
1011
+ dataTestId,
1012
+ isVisibleEnable,
1013
+ isCopyEnable,
1014
+ customIcon,
1015
+ customHandleChange,
1016
+ customFormChange,
1017
+ component,
1018
+ blockComponent,
1019
+ showCustomError,
1020
+ ref: inputRef,
1021
+ onBlur,
1022
+ isChild,
1023
+ noIndent,
1024
+ index,
1025
+ formik: formikProp
1026
+ }) => {
1027
+ const { uiLibrary, formik } = useFormContext();
1028
+ const { adapter, icons } = uiLibrary;
1029
+ const Input = adapter.Input;
1030
+ adapter.IconButton;
1031
+ const activeFormik = formikProp || formik;
1032
+ const [showField, setShowField] = useState({});
1033
+ const fieldValue = getFieldValue(activeFormik, name);
1034
+ const fieldError = getFieldError(activeFormik, name);
1035
+ const fieldTouched = getFieldTouched(activeFormik, name);
1036
+ const showFieldHandler = useCallback((fieldName) => {
1037
+ setShowField((prev) => ({
1038
+ ...prev,
1039
+ [fieldName]: !prev[fieldName]
1040
+ }));
1041
+ }, []);
1042
+ const handleCopy = useCallback(() => {
1043
+ if (typeof window !== "undefined" && document) {
1044
+ const input = document.getElementById(name);
1045
+ if (input) {
1046
+ input.select();
1047
+ document.execCommand("copy");
1048
+ }
1049
+ }
1050
+ }, [name]);
1051
+ const VisibilityIcon = icons?.Visibility;
1052
+ const VisibilityOffIcon = icons?.VisibilityOff;
1053
+ const CopyIcon = icons?.Copy;
1054
+ const inputType = fieldType === "password" ? !showField[name] ? "password" : "text" : fieldType;
1055
+ return /* @__PURE__ */ jsxs(
1056
+ FieldWrapper,
1057
+ {
1058
+ customClass,
1059
+ isChild,
1060
+ noIndent,
1061
+ hidden,
1062
+ index,
1063
+ children: [
1064
+ label && /* @__PURE__ */ jsx(
1065
+ FieldLabel,
1066
+ {
1067
+ name,
1068
+ label,
1069
+ required,
1070
+ info,
1071
+ customLabelClass
1072
+ }
1073
+ ),
1074
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
1075
+ /* @__PURE__ */ jsxs(
1076
+ "div",
1077
+ {
1078
+ className: `input-group ${isCopyEnable || isVisibleEnable ? "" : "rounded"}`,
1079
+ children: [
1080
+ /* @__PURE__ */ jsx(
1081
+ Input,
1082
+ {
1083
+ className: `form-control font-14 ${isCopyEnable || isVisibleEnable || customIcon ? "border border-end-0" : "rounded"} ${fieldError && fieldTouched ? "border-danger" : ""}`,
1084
+ id: name,
1085
+ "data-testid": dataTestId || `${formatString(name)}-input`,
1086
+ ref: inputRef,
1087
+ autoComplete: autocomplete || fieldType === "password" ? "new-password" : "off",
1088
+ type: inputType,
1089
+ disabled: disabled || false,
1090
+ name,
1091
+ placeholder,
1092
+ value: fieldValue || "",
1093
+ onChange: (event) => {
1094
+ if (customHandleChange) {
1095
+ customHandleChange(event, type);
1096
+ } else if (customFormChange) {
1097
+ customFormChange(event, type);
1098
+ } else {
1099
+ activeFormik.handleChange(event);
1100
+ }
1101
+ },
1102
+ onBlur: onBlur || activeFormik.handleBlur,
1103
+ readOnly: readonly || false,
1104
+ error: !!(fieldError && fieldTouched)
1105
+ }
1106
+ ),
1107
+ customIcon && /* @__PURE__ */ jsx(
1108
+ "div",
1109
+ {
1110
+ className: `z-0 bg-transparent btn btn-outline-secondary border-0 border-top border-bottom px-3 ${!isCopyEnable && !isVisibleEnable ? "border-end rounded-end" : ""} ${fieldError && fieldTouched ? "border-danger" : ""}`,
1111
+ style: { cursor: "default" },
1112
+ children: customIcon
1113
+ }
1114
+ ),
1115
+ isVisibleEnable && VisibilityIcon && VisibilityOffIcon && /* @__PURE__ */ jsx(
1116
+ "button",
1117
+ {
1118
+ className: `z-0 btn btn-outline-secondary border-0 rounded-0 border-top border-bottom ${!isCopyEnable ? "border-end rounded-end" : ""} ${fieldError && fieldTouched ? "border-danger" : ""}`,
1119
+ type: "button",
1120
+ "data-testid": `${formatString(name)}-visible-btn`,
1121
+ onClick: () => showFieldHandler(name),
1122
+ children: !showField[name] ? /* @__PURE__ */ jsx(IconRenderer, { Icon: VisibilityOffIcon, size: 16 }) : /* @__PURE__ */ jsx(IconRenderer, { Icon: VisibilityIcon, size: 16 })
1123
+ }
1124
+ ),
1125
+ isCopyEnable && CopyIcon && /* @__PURE__ */ jsx(
1126
+ "button",
1127
+ {
1128
+ className: `z-0 btn btn-outline-secondary border border-start-0 border-end rounded-end ${fieldError && fieldTouched ? "border-danger" : ""}`,
1129
+ type: "button",
1130
+ "data-testid": `${formatString(name)}-copy-btn`,
1131
+ "aria-label": "copy",
1132
+ onClick: handleCopy,
1133
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: CopyIcon, size: 16 })
1134
+ }
1135
+ ),
1136
+ component && /* @__PURE__ */ jsx("div", { children: component })
1137
+ ]
1138
+ }
1139
+ ),
1140
+ blockComponent && /* @__PURE__ */ jsx("div", { children: blockComponent }),
1141
+ (showCustomError || fieldError && fieldTouched) && /* @__PURE__ */ jsx(
1142
+ FieldError,
1143
+ {
1144
+ name,
1145
+ error: fieldError,
1146
+ touched: fieldTouched,
1147
+ showCustomError,
1148
+ dataTestId
1149
+ }
1150
+ )
1151
+ ]
1152
+ }
1153
+ );
1154
+ };
1155
+ var TextareaField = ({
1156
+ name,
1157
+ type,
1158
+ label,
1159
+ placeholder,
1160
+ desc,
1161
+ required,
1162
+ customClass,
1163
+ customComponentClass,
1164
+ isChild,
1165
+ noIndent,
1166
+ hidden,
1167
+ readonly,
1168
+ rows = 4,
1169
+ dataTestId,
1170
+ customHandleChange,
1171
+ customFormChange,
1172
+ component,
1173
+ formik: formikProp
1174
+ }) => {
1175
+ const { uiLibrary, formik } = useFormContext();
1176
+ const { adapter } = uiLibrary;
1177
+ const Textarea = adapter.Textarea;
1178
+ const activeFormik = formikProp || formik;
1179
+ const fieldValue = getFieldValue(activeFormik, name);
1180
+ const fieldError = getFieldError(activeFormik, name);
1181
+ const fieldTouched = getFieldTouched(activeFormik, name);
1182
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1183
+ /* @__PURE__ */ jsxs(
1184
+ FieldWrapper,
1185
+ {
1186
+ customClass,
1187
+ isChild,
1188
+ noIndent,
1189
+ hidden,
1190
+ children: [
1191
+ label && /* @__PURE__ */ jsx(
1192
+ FieldLabel,
1193
+ {
1194
+ name,
1195
+ label,
1196
+ required
1197
+ }
1198
+ ),
1199
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
1200
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
1201
+ Textarea,
1202
+ {
1203
+ id: name,
1204
+ className: `form-control text-14 ${required && fieldError && fieldTouched ? "border-danger" : ""}`,
1205
+ name,
1206
+ "data-testid": dataTestId || `${formatString(name)}-text-box`,
1207
+ placeholder,
1208
+ rows,
1209
+ value: fieldValue || "",
1210
+ autoComplete: "off",
1211
+ onChange: (event) => {
1212
+ if (customHandleChange) {
1213
+ customHandleChange(event, type);
1214
+ } else if (customFormChange) {
1215
+ customFormChange(event, type);
1216
+ } else {
1217
+ activeFormik.handleChange(event);
1218
+ }
1219
+ },
1220
+ onBlur: activeFormik.handleBlur,
1221
+ readOnly: readonly || false,
1222
+ disabled: readonly || false,
1223
+ error: !!(required && fieldError && fieldTouched)
1224
+ }
1225
+ ) }),
1226
+ required && fieldError && fieldTouched && /* @__PURE__ */ jsx(
1227
+ FieldError,
1228
+ {
1229
+ name,
1230
+ error: fieldError,
1231
+ touched: fieldTouched,
1232
+ dataTestId
1233
+ }
1234
+ )
1235
+ ]
1236
+ }
1237
+ ),
1238
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
1239
+ ] });
1240
+ };
1241
+ var CheckboxField = ({
1242
+ name,
1243
+ type,
1244
+ label,
1245
+ desc,
1246
+ info,
1247
+ required,
1248
+ disabled,
1249
+ customClass,
1250
+ customComponentClass,
1251
+ isChild,
1252
+ noIndent,
1253
+ hidden,
1254
+ dataTestId,
1255
+ showCustomError,
1256
+ customHandleChange,
1257
+ customFormChange,
1258
+ component,
1259
+ child,
1260
+ formik: formikProp
1261
+ }) => {
1262
+ const { uiLibrary, formik } = useFormContext();
1263
+ const { adapter, icons } = uiLibrary;
1264
+ const Checkbox = adapter.Checkbox;
1265
+ const FormHelperText = adapter.FormHelperText;
1266
+ const IconButton = adapter.IconButton;
1267
+ const activeFormik = formikProp || formik;
1268
+ const fieldValue = getFieldValue(activeFormik, name);
1269
+ const fieldError = getFieldError(activeFormik, name);
1270
+ const fieldTouched = getFieldTouched(activeFormik, name);
1271
+ const InfoIcon = icons?.Info;
1272
+ const setFieldValuesRecursive = (childFields) => {
1273
+ if (childFields) {
1274
+ childFields.forEach((c) => {
1275
+ activeFormik.setFieldValue(c.name, "");
1276
+ activeFormik.setFieldTouched(c.name, false);
1277
+ });
1278
+ }
1279
+ };
1280
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1281
+ /* @__PURE__ */ jsxs(
1282
+ FieldWrapper,
1283
+ {
1284
+ customClass,
1285
+ isChild,
1286
+ noIndent,
1287
+ hidden,
1288
+ children: [
1289
+ /* @__PURE__ */ jsx(
1290
+ Checkbox,
1291
+ {
1292
+ id: name,
1293
+ name,
1294
+ "data-testid": dataTestId || `${formatString(name)}-check-box`,
1295
+ checked: !!fieldValue,
1296
+ disabled: disabled || false,
1297
+ onChange: (event) => {
1298
+ if (customHandleChange) {
1299
+ customHandleChange(event, type);
1300
+ } else if (customFormChange) {
1301
+ customFormChange(event, type);
1302
+ } else {
1303
+ activeFormik.handleChange(event);
1304
+ }
1305
+ if (!event.target.checked) {
1306
+ setFieldValuesRecursive(child);
1307
+ }
1308
+ },
1309
+ label: /* @__PURE__ */ jsx("div", { className: "d-flex flex-column align-items-start", children: /* @__PURE__ */ jsxs("p", { className: "text-14 text-dark fw-medium align-items-center", children: [
1310
+ label,
1311
+ required && /* @__PURE__ */ jsx("span", { className: "text-danger", children: " *" }),
1312
+ info && InfoIcon && /* @__PURE__ */ jsx(
1313
+ IconButton,
1314
+ {
1315
+ size: "small",
1316
+ className: "p-0",
1317
+ "aria-label": "show info",
1318
+ tabIndex: -1,
1319
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: InfoIcon, size: 16 })
1320
+ }
1321
+ )
1322
+ ] }) }),
1323
+ error: !!(fieldError && fieldTouched)
1324
+ }
1325
+ ),
1326
+ desc && /* @__PURE__ */ jsx(FormHelperText, { className: "text-black-50 mt-0 mb-1", children: desc }),
1327
+ (showCustomError || fieldError && fieldTouched) && /* @__PURE__ */ jsx(
1328
+ FieldError,
1329
+ {
1330
+ name,
1331
+ error: fieldError,
1332
+ touched: fieldTouched,
1333
+ showCustomError,
1334
+ dataTestId
1335
+ }
1336
+ ),
1337
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
1338
+ ]
1339
+ }
1340
+ ),
1341
+ child && child.map((c, childIndex) => {
1342
+ return fieldValue && // This would need to be handled by DynamicForm orchestrator
1343
+ // For now, we'll just render the child if value is truthy
1344
+ null;
1345
+ })
1346
+ ] });
1347
+ };
1348
+ var RadioField = ({
1349
+ name,
1350
+ type,
1351
+ label,
1352
+ desc,
1353
+ required,
1354
+ disabled,
1355
+ customClass,
1356
+ customComponentClass,
1357
+ isChild,
1358
+ noIndent,
1359
+ hidden,
1360
+ values = {},
1361
+ dataTestId,
1362
+ customHandleChange,
1363
+ customFormChange,
1364
+ component,
1365
+ child,
1366
+ formik: formikProp
1367
+ }) => {
1368
+ const { uiLibrary, formik } = useFormContext();
1369
+ const { adapter } = uiLibrary;
1370
+ const Radio = adapter.Radio;
1371
+ const FormHelperText = adapter.FormHelperText;
1372
+ const activeFormik = formikProp || formik;
1373
+ const fieldValue = getFieldValue(activeFormik, name);
1374
+ const fieldError = getFieldError(activeFormik, name);
1375
+ const fieldTouched = getFieldTouched(activeFormik, name);
1376
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1377
+ /* @__PURE__ */ jsxs(
1378
+ FieldWrapper,
1379
+ {
1380
+ customClass,
1381
+ isChild,
1382
+ noIndent,
1383
+ hidden,
1384
+ children: [
1385
+ label && /* @__PURE__ */ jsx(
1386
+ FieldLabel,
1387
+ {
1388
+ name,
1389
+ label,
1390
+ required
1391
+ }
1392
+ ),
1393
+ /* @__PURE__ */ jsx(
1394
+ "div",
1395
+ {
1396
+ id: name,
1397
+ "data-testid": dataTestId || `${formatString(name)}-btn`,
1398
+ role: "radiogroup",
1399
+ children: Object.entries(values).map(([key, value], index) => /* @__PURE__ */ jsx(
1400
+ Radio,
1401
+ {
1402
+ name,
1403
+ value: key,
1404
+ checked: fieldValue === key || fieldValue === value,
1405
+ disabled: disabled || false,
1406
+ onChange: (event) => {
1407
+ if (customHandleChange) {
1408
+ customHandleChange(event, type);
1409
+ } else if (customFormChange) {
1410
+ customFormChange(event, type);
1411
+ } else {
1412
+ activeFormik.handleChange(event);
1413
+ }
1414
+ if (!event.target.checked && child) {
1415
+ child.forEach((c) => {
1416
+ activeFormik.setFieldValue(c.name, "");
1417
+ });
1418
+ }
1419
+ },
1420
+ label: /* @__PURE__ */ jsx("p", { className: "font-14 text-secondary m-0", children: value })
1421
+ },
1422
+ key
1423
+ ))
1424
+ }
1425
+ ),
1426
+ desc && /* @__PURE__ */ jsx(FormHelperText, { className: "text-black-50 mb-1", children: desc }),
1427
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
1428
+ FieldError,
1429
+ {
1430
+ name,
1431
+ error: fieldError,
1432
+ touched: fieldTouched,
1433
+ dataTestId
1434
+ }
1435
+ ),
1436
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
1437
+ ]
1438
+ }
1439
+ ),
1440
+ child && child.map((c, i) => {
1441
+ return null;
1442
+ })
1443
+ ] });
1444
+ };
1445
+ var DropdownField = ({
1446
+ name,
1447
+ type,
1448
+ label,
1449
+ desc,
1450
+ info,
1451
+ required,
1452
+ disabled,
1453
+ customClass,
1454
+ isChild,
1455
+ noIndent,
1456
+ hidden,
1457
+ values = {},
1458
+ headerKey,
1459
+ dataTestId,
1460
+ isCopyEnable,
1461
+ resetChild = true,
1462
+ ignoreChar,
1463
+ customHandleChange,
1464
+ customFormChange,
1465
+ component,
1466
+ child,
1467
+ setFieldValuesRecursive,
1468
+ formik: formikProp,
1469
+ index
1470
+ }) => {
1471
+ const { uiLibrary, formik } = useFormContext();
1472
+ const { adapter } = uiLibrary;
1473
+ const Select = adapter.Select;
1474
+ const FormControl = adapter.FormControl;
1475
+ const activeFormik = formikProp || formik;
1476
+ const fieldValue = getFieldValue(activeFormik, name);
1477
+ const fieldError = getFieldError(activeFormik, name);
1478
+ const fieldTouched = getFieldTouched(activeFormik, name);
1479
+ const handleSetFieldValuesRecursive = (childFields, parentValue) => {
1480
+ if (childFields && setFieldValuesRecursive) {
1481
+ setFieldValuesRecursive(childFields, parentValue);
1482
+ }
1483
+ };
1484
+ const options = Array.isArray(values) ? values : Object.entries(values).map(([key, value]) => ({
1485
+ value: key,
1486
+ label: value || key
1487
+ }));
1488
+ const sortedOptions = [...options].sort((a, b) => {
1489
+ if (a.value === "") return -1;
1490
+ return 0;
1491
+ });
1492
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1493
+ /* @__PURE__ */ jsx(
1494
+ FieldWrapper,
1495
+ {
1496
+ customClass,
1497
+ isChild,
1498
+ noIndent,
1499
+ hidden,
1500
+ index,
1501
+ children: /* @__PURE__ */ jsxs(
1502
+ FormControl,
1503
+ {
1504
+ className: "w-100",
1505
+ required,
1506
+ error: !!(fieldTouched && fieldError),
1507
+ children: [
1508
+ label && /* @__PURE__ */ jsx(
1509
+ FieldLabel,
1510
+ {
1511
+ name,
1512
+ label,
1513
+ required,
1514
+ info
1515
+ }
1516
+ ),
1517
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
1518
+ /* @__PURE__ */ jsxs(
1519
+ Select,
1520
+ {
1521
+ className: `form-select text-14 ${isCopyEnable ? "border border-end-0" : ""} ${fieldError && fieldTouched ? "border-danger" : ""}`,
1522
+ id: name,
1523
+ name,
1524
+ "data-testid": dataTestId || `${formatString(name)}-dropdown`,
1525
+ disabled: disabled || false,
1526
+ value: fieldValue || "",
1527
+ onChange: (event) => {
1528
+ if (customHandleChange) {
1529
+ customHandleChange(event, type, typeof index === "number" ? index : void 0);
1530
+ } else if (customFormChange) {
1531
+ customFormChange(event, type);
1532
+ } else {
1533
+ activeFormik.handleChange(event);
1534
+ }
1535
+ if (resetChild) {
1536
+ handleSetFieldValuesRecursive(child, event.target.value);
1537
+ }
1538
+ },
1539
+ onBlur: activeFormik.handleBlur,
1540
+ error: !!(fieldError && fieldTouched),
1541
+ children: [
1542
+ headerKey && /* @__PURE__ */ jsx("option", { children: headerKey }),
1543
+ sortedOptions.map((option, i) => /* @__PURE__ */ jsx(
1544
+ "option",
1545
+ {
1546
+ "data-testid": `${formatString(String(option.value), ignoreChar)}-option`,
1547
+ value: option.value,
1548
+ children: option.label
1549
+ },
1550
+ i
1551
+ ))
1552
+ ]
1553
+ }
1554
+ ),
1555
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
1556
+ FieldError,
1557
+ {
1558
+ name,
1559
+ error: fieldError,
1560
+ touched: fieldTouched,
1561
+ dataTestId
1562
+ }
1563
+ )
1564
+ ]
1565
+ }
1566
+ )
1567
+ }
1568
+ ),
1569
+ child && child.map((childField, childIndex) => {
1570
+ return null;
1571
+ }),
1572
+ component && /* @__PURE__ */ jsx("div", { className: "mb-1 mx-1", children: component })
1573
+ ] });
1574
+ };
1575
+ var ToggleField = ({
1576
+ name,
1577
+ type,
1578
+ label,
1579
+ required,
1580
+ disabled,
1581
+ customClass,
1582
+ isChild,
1583
+ noIndent,
1584
+ dataTestId,
1585
+ customHandleChange,
1586
+ customFormChange,
1587
+ formik: formikProp
1588
+ }) => {
1589
+ const { uiLibrary, formik } = useFormContext();
1590
+ const { adapter } = uiLibrary;
1591
+ const Switch = adapter.Switch;
1592
+ const activeFormik = formikProp || formik;
1593
+ const fieldValue = getFieldValue(activeFormik, name);
1594
+ const fieldError = getFieldError(activeFormik, name);
1595
+ const fieldTouched = getFieldTouched(activeFormik, name);
1596
+ return /* @__PURE__ */ jsxs(
1597
+ "div",
1598
+ {
1599
+ className: `d-flex gap-2 align-items-center ${isChild && !noIndent ? "ps-5" : ""}`,
1600
+ children: [
1601
+ /* @__PURE__ */ jsx(
1602
+ Switch,
1603
+ {
1604
+ id: name,
1605
+ name,
1606
+ "data-testid": dataTestId || `${formatString(name)}-check-box`,
1607
+ disabled: disabled || false,
1608
+ checked: !!fieldValue,
1609
+ onChange: (event) => {
1610
+ const newValue = event.target.checked;
1611
+ if (customHandleChange) {
1612
+ customHandleChange(event, type);
1613
+ } else if (customFormChange) {
1614
+ customFormChange(event, type);
1615
+ } else {
1616
+ activeFormik.setFieldValue(name, newValue);
1617
+ }
1618
+ }
1619
+ }
1620
+ ),
1621
+ label && /* @__PURE__ */ jsx(
1622
+ FieldLabel,
1623
+ {
1624
+ name,
1625
+ label,
1626
+ required,
1627
+ htmlFor: name
1628
+ }
1629
+ ),
1630
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
1631
+ FieldError,
1632
+ {
1633
+ name,
1634
+ error: fieldError,
1635
+ touched: fieldTouched,
1636
+ dataTestId
1637
+ }
1638
+ )
1639
+ ]
1640
+ }
1641
+ );
1642
+ };
1643
+ var FileUploadField = ({
1644
+ name,
1645
+ type,
1646
+ label,
1647
+ info,
1648
+ required,
1649
+ customClass,
1650
+ customComponentClass,
1651
+ isChild,
1652
+ noIndent,
1653
+ dataTestId,
1654
+ customHandleChange,
1655
+ customFormChange,
1656
+ component,
1657
+ ref: inputRef,
1658
+ formik: formikProp,
1659
+ index
1660
+ }) => {
1661
+ const { uiLibrary, formik } = useFormContext();
1662
+ const { adapter, icons } = uiLibrary;
1663
+ adapter.Input;
1664
+ const Button = adapter.Button;
1665
+ adapter.IconButton;
1666
+ const activeFormik = formikProp || formik;
1667
+ const fieldValue = getFieldValue(activeFormik, name);
1668
+ const fieldError = getFieldError(activeFormik, name);
1669
+ const fieldTouched = getFieldTouched(activeFormik, name);
1670
+ icons?.Info;
1671
+ const DeleteIcon = icons?.Delete;
1672
+ const handleRemoveFile = () => {
1673
+ activeFormik.setFieldValue(name, null);
1674
+ };
1675
+ const fileValue = fieldValue;
1676
+ const fileName = fileValue instanceof File ? fileValue.name : typeof fileValue === "string" ? fileValue.split("/").pop() : null;
1677
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1678
+ /* @__PURE__ */ jsxs(
1679
+ FieldWrapper,
1680
+ {
1681
+ customClass,
1682
+ isChild,
1683
+ noIndent,
1684
+ index,
1685
+ children: [
1686
+ label && /* @__PURE__ */ jsx(
1687
+ FieldLabel,
1688
+ {
1689
+ name,
1690
+ label,
1691
+ required,
1692
+ info
1693
+ }
1694
+ ),
1695
+ !fileValue && /* @__PURE__ */ jsx(
1696
+ "input",
1697
+ {
1698
+ className: `form-control ${required && fieldError && fieldTouched ? "border-danger" : ""}`,
1699
+ type: "file",
1700
+ id: name,
1701
+ name,
1702
+ "data-testid": dataTestId || `${formatString(name)}-file`,
1703
+ ref: inputRef,
1704
+ onChange: (event) => {
1705
+ if (customHandleChange) {
1706
+ customHandleChange(event, type);
1707
+ } else if (customFormChange) {
1708
+ customFormChange(event, type);
1709
+ } else {
1710
+ activeFormik.handleChange(event);
1711
+ }
1712
+ if (event.currentTarget.files?.[0]) {
1713
+ activeFormik.setFieldValue(name, event.currentTarget.files[0]);
1714
+ }
1715
+ },
1716
+ onBlur: activeFormik.handleBlur
1717
+ }
1718
+ ),
1719
+ required && fieldError && fieldTouched && /* @__PURE__ */ jsx(
1720
+ FieldError,
1721
+ {
1722
+ name,
1723
+ error: fieldError,
1724
+ touched: fieldTouched,
1725
+ dataTestId
1726
+ }
1727
+ ),
1728
+ fileValue && /* @__PURE__ */ jsxs(Fragment, { children: [
1729
+ /* @__PURE__ */ jsxs("div", { className: "d-flex justify-content-between align-items-center", children: [
1730
+ /* @__PURE__ */ jsxs("div", { children: [
1731
+ "File: ",
1732
+ fileName
1733
+ ] }),
1734
+ /* @__PURE__ */ jsxs(
1735
+ Button,
1736
+ {
1737
+ variant: "text",
1738
+ "data-testid": `${formatString(name)}-remove-btn`,
1739
+ className: "text-14 text-capitalize p-1 text-danger gap-1 col-3",
1740
+ onClick: handleRemoveFile,
1741
+ children: [
1742
+ DeleteIcon && /* @__PURE__ */ jsx(IconRenderer, { Icon: DeleteIcon, size: 16 }),
1743
+ " Remove File"
1744
+ ]
1745
+ }
1746
+ )
1747
+ ] }),
1748
+ fieldError && /* @__PURE__ */ jsx(
1749
+ FieldError,
1750
+ {
1751
+ name,
1752
+ error: fieldError,
1753
+ touched: fieldTouched,
1754
+ dataTestId
1755
+ }
1756
+ )
1757
+ ] })
1758
+ ]
1759
+ }
1760
+ ),
1761
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
1762
+ ] });
1763
+ };
1764
+ var SingleSelectField = ({
1765
+ name,
1766
+ type,
1767
+ label,
1768
+ desc,
1769
+ info,
1770
+ required,
1771
+ disabled,
1772
+ customClass,
1773
+ customComponentClass,
1774
+ isChild,
1775
+ noIndent,
1776
+ hidden,
1777
+ values = [],
1778
+ isSearchable,
1779
+ isMulti = false,
1780
+ optionsLabel,
1781
+ dataTestId,
1782
+ customHandleChange,
1783
+ customFormChange,
1784
+ component,
1785
+ child,
1786
+ setFieldValuesRecursive,
1787
+ formik: formikProp,
1788
+ index
1789
+ }) => {
1790
+ const { uiLibrary, formik } = useFormContext();
1791
+ const { adapter } = uiLibrary;
1792
+ const FormControl = adapter.FormControl;
1793
+ const activeFormik = formikProp || formik;
1794
+ const fieldValue = getFieldValue(activeFormik, name);
1795
+ const fieldError = getFieldError(activeFormik, name);
1796
+ const fieldTouched = getFieldTouched(activeFormik, name);
1797
+ const options = Array.isArray(values) ? values : Object.entries(values).map(([value, label2]) => ({
1798
+ value,
1799
+ label: String(label2)
1800
+ }));
1801
+ const selectedOption = fieldValue ? options.find((opt) => opt.value === fieldValue) : null;
1802
+ const handleSelectChange = (selected) => {
1803
+ const event = {
1804
+ target: {
1805
+ name,
1806
+ value: selected ? selected.value : ""
1807
+ }
1808
+ };
1809
+ if (customHandleChange) {
1810
+ customHandleChange(event, type);
1811
+ } else if (customFormChange) {
1812
+ customFormChange(event, type);
1813
+ } else {
1814
+ activeFormik.handleChange(event);
1815
+ }
1816
+ if (child && setFieldValuesRecursive) {
1817
+ setFieldValuesRecursive(child);
1818
+ }
1819
+ };
1820
+ const Select = adapter.Select;
1821
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1822
+ /* @__PURE__ */ jsx(
1823
+ FieldWrapper,
1824
+ {
1825
+ customClass,
1826
+ isChild,
1827
+ noIndent,
1828
+ hidden,
1829
+ index,
1830
+ children: /* @__PURE__ */ jsxs(
1831
+ FormControl,
1832
+ {
1833
+ className: "w-100",
1834
+ required,
1835
+ error: !!(fieldTouched && fieldError),
1836
+ children: [
1837
+ label && /* @__PURE__ */ jsx(
1838
+ FieldLabel,
1839
+ {
1840
+ name,
1841
+ label,
1842
+ required,
1843
+ info
1844
+ }
1845
+ ),
1846
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
1847
+ /* @__PURE__ */ jsx("div", { "data-testid": dataTestId || `${formatString(name)}-single-select`, children: /* @__PURE__ */ jsx(
1848
+ Select,
1849
+ {
1850
+ className: `text-14 ${isMulti ? "" : ""} ${fieldError && fieldTouched ? "border-danger" : ""}`,
1851
+ name,
1852
+ disabled: disabled || false,
1853
+ value: selectedOption ? String(selectedOption.value) : "",
1854
+ onChange: (event) => {
1855
+ const selected = options.find(
1856
+ (opt) => String(opt.value) === event.target.value
1857
+ );
1858
+ handleSelectChange(selected || null);
1859
+ },
1860
+ onBlur: activeFormik.handleBlur,
1861
+ error: !!(fieldError && fieldTouched),
1862
+ children: options.map((option) => /* @__PURE__ */ jsx("option", { value: String(option.value), children: option.label }, option.value))
1863
+ }
1864
+ ) }),
1865
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
1866
+ FieldError,
1867
+ {
1868
+ name,
1869
+ error: fieldError,
1870
+ touched: fieldTouched,
1871
+ dataTestId
1872
+ }
1873
+ )
1874
+ ]
1875
+ }
1876
+ )
1877
+ }
1878
+ ),
1879
+ child && child.map((childField, childIndex) => {
1880
+ return null;
1881
+ }),
1882
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
1883
+ ] });
1884
+ };
1885
+ var MultiSelectField = ({
1886
+ name,
1887
+ type,
1888
+ label,
1889
+ desc,
1890
+ info,
1891
+ required,
1892
+ customClass,
1893
+ customDescClass,
1894
+ customComponentClass,
1895
+ isChild,
1896
+ noIndent,
1897
+ hidden,
1898
+ values = [],
1899
+ dataTestId,
1900
+ customHandleChange,
1901
+ component,
1902
+ blockComponent,
1903
+ formik: formikProp,
1904
+ index
1905
+ }) => {
1906
+ const { uiLibrary, formik } = useFormContext();
1907
+ const { adapter } = uiLibrary;
1908
+ const FormControl = adapter.FormControl;
1909
+ const activeFormik = formikProp || formik;
1910
+ const fieldValue = getFieldValue(activeFormik, name);
1911
+ const fieldError = getFieldError(activeFormik, name);
1912
+ const fieldTouched = getFieldTouched(activeFormik, name);
1913
+ const options = Array.isArray(values) ? values : Object.entries(values).map(([value, label2]) => ({
1914
+ value,
1915
+ label: String(label2)
1916
+ }));
1917
+ const selectedValues = Array.isArray(fieldValue) ? fieldValue : [];
1918
+ const handleChange = (event) => {
1919
+ const selectedOptions = Array.from(
1920
+ event.target.selectedOptions,
1921
+ (option) => option.value
1922
+ );
1923
+ const syntheticEvent = {
1924
+ target: {
1925
+ name,
1926
+ value: selectedOptions
1927
+ }
1928
+ };
1929
+ if (customHandleChange) {
1930
+ customHandleChange(syntheticEvent, "multiSelect");
1931
+ } else {
1932
+ activeFormik.setFieldValue(name, selectedOptions);
1933
+ }
1934
+ };
1935
+ adapter.Select;
1936
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1937
+ /* @__PURE__ */ jsxs(
1938
+ FieldWrapper,
1939
+ {
1940
+ customClass,
1941
+ isChild,
1942
+ noIndent,
1943
+ hidden,
1944
+ index,
1945
+ "data-testid": dataTestId || `${formatString(name)}-multi-select`,
1946
+ children: [
1947
+ blockComponent && /* @__PURE__ */ jsx("div", { children: blockComponent }),
1948
+ /* @__PURE__ */ jsxs(FormControl, { className: "w-100", required, children: [
1949
+ label && /* @__PURE__ */ jsx(
1950
+ FieldLabel,
1951
+ {
1952
+ name,
1953
+ label,
1954
+ required,
1955
+ info
1956
+ }
1957
+ ),
1958
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc, customDescClass }),
1959
+ /* @__PURE__ */ jsx("div", { "data-testid": dataTestId || `${formatString(name)}-select`, children: /* @__PURE__ */ jsx(
1960
+ "select",
1961
+ {
1962
+ name,
1963
+ multiple: true,
1964
+ value: selectedValues.map(String),
1965
+ onChange: handleChange,
1966
+ onBlur: activeFormik.handleBlur,
1967
+ className: `form-select text-14 ${fieldError && fieldTouched ? "border-danger" : ""}`,
1968
+ children: options.map((option) => /* @__PURE__ */ jsx("option", { value: String(option.value), children: option.label }, option.value))
1969
+ }
1970
+ ) }),
1971
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
1972
+ FieldError,
1973
+ {
1974
+ name,
1975
+ error: fieldError,
1976
+ touched: fieldTouched,
1977
+ dataTestId
1978
+ }
1979
+ )
1980
+ ] })
1981
+ ]
1982
+ }
1983
+ ),
1984
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
1985
+ ] });
1986
+ };
1987
+ var AsyncSelectField = ({
1988
+ name,
1989
+ type,
1990
+ label,
1991
+ desc,
1992
+ info,
1993
+ required,
1994
+ disabled,
1995
+ customClass,
1996
+ customComponentClass,
1997
+ isChild,
1998
+ noIndent,
1999
+ hidden,
2000
+ values = [],
2001
+ isMulti = false,
2002
+ loaderCall,
2003
+ dataTestId,
2004
+ customHandleChange,
2005
+ customFormChange,
2006
+ component,
2007
+ child,
2008
+ setFieldValuesRecursive,
2009
+ formik: formikProp,
2010
+ index
2011
+ }) => {
2012
+ const { uiLibrary, formik } = useFormContext();
2013
+ const { adapter } = uiLibrary;
2014
+ const FormControl = adapter.FormControl;
2015
+ const activeFormik = formikProp || formik;
2016
+ const [asyncLoading, setAsyncLoading] = useState(false);
2017
+ const fieldValue = getFieldValue(activeFormik, name);
2018
+ const fieldError = getFieldError(activeFormik, name);
2019
+ const fieldTouched = getFieldTouched(activeFormik, name);
2020
+ const handleChange = (event) => {
2021
+ if (customHandleChange) {
2022
+ customHandleChange(event, type);
2023
+ } else if (customFormChange) {
2024
+ customFormChange(event, type);
2025
+ } else {
2026
+ activeFormik.handleChange(event);
2027
+ }
2028
+ if (child && setFieldValuesRecursive) {
2029
+ setFieldValuesRecursive(child);
2030
+ }
2031
+ };
2032
+ const Select = adapter.Select;
2033
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2034
+ /* @__PURE__ */ jsx(
2035
+ FieldWrapper,
2036
+ {
2037
+ customClass,
2038
+ isChild,
2039
+ noIndent,
2040
+ hidden,
2041
+ index,
2042
+ "data-testid": dataTestId || `${formatString(name)}-async-select`,
2043
+ children: /* @__PURE__ */ jsxs(
2044
+ FormControl,
2045
+ {
2046
+ className: "w-100",
2047
+ required,
2048
+ error: !!(fieldTouched && fieldError),
2049
+ children: [
2050
+ label && /* @__PURE__ */ jsx(
2051
+ FieldLabel,
2052
+ {
2053
+ name,
2054
+ label,
2055
+ required,
2056
+ info
2057
+ }
2058
+ ),
2059
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
2060
+ /* @__PURE__ */ jsx(
2061
+ "div",
2062
+ {
2063
+ "data-testid": dataTestId || `${formatString(name)}-async-select`,
2064
+ children: /* @__PURE__ */ jsxs(
2065
+ Select,
2066
+ {
2067
+ name,
2068
+ disabled,
2069
+ value: fieldValue ? String(fieldValue) : "",
2070
+ onChange: handleChange,
2071
+ onBlur: activeFormik.handleBlur,
2072
+ error: !!(fieldError && fieldTouched),
2073
+ children: [
2074
+ asyncLoading && /* @__PURE__ */ jsx("option", { children: "Loading..." }),
2075
+ !asyncLoading && values && (Array.isArray(values) ? values : Object.entries(values).map(([value, label2]) => ({
2076
+ value,
2077
+ label: String(label2)
2078
+ }))).map((option) => /* @__PURE__ */ jsx("option", { value: String(option.value), children: option.label }, option.value))
2079
+ ]
2080
+ }
2081
+ )
2082
+ }
2083
+ ),
2084
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
2085
+ FieldError,
2086
+ {
2087
+ name,
2088
+ error: fieldError,
2089
+ touched: fieldTouched,
2090
+ dataTestId
2091
+ }
2092
+ )
2093
+ ]
2094
+ }
2095
+ )
2096
+ }
2097
+ ),
2098
+ child && child.map((childField, childIndex) => {
2099
+ return null;
2100
+ }),
2101
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
2102
+ ] });
2103
+ };
2104
+ var DatePickerField = ({
2105
+ name,
2106
+ type,
2107
+ label,
2108
+ info,
2109
+ required,
2110
+ disabled,
2111
+ customClass,
2112
+ isChild,
2113
+ noIndent,
2114
+ hidden,
2115
+ dateFormat = "DD/MM/YYYY",
2116
+ dataTestId,
2117
+ component,
2118
+ formik: formikProp,
2119
+ index
2120
+ }) => {
2121
+ const { uiLibrary, formik } = useFormContext();
2122
+ const { adapter } = uiLibrary;
2123
+ const activeFormik = formikProp || formik;
2124
+ const fieldValue = getFieldValue(activeFormik, name);
2125
+ const fieldError = getFieldError(activeFormik, name);
2126
+ const fieldTouched = getFieldTouched(activeFormik, name);
2127
+ const DatePicker = adapter.DatePicker;
2128
+ const Input = adapter.Input;
2129
+ const handleDateChange = (date) => {
2130
+ let formattedDate = "";
2131
+ if (date) {
2132
+ if (typeof date === "string") {
2133
+ formattedDate = date;
2134
+ } else if (date instanceof Date) {
2135
+ const day = String(date.getDate()).padStart(2, "0");
2136
+ const month = String(date.getMonth() + 1).padStart(2, "0");
2137
+ const year = date.getFullYear();
2138
+ formattedDate = `${day}/${month}/${year}`;
2139
+ }
2140
+ }
2141
+ activeFormik.setFieldValue(name, formattedDate);
2142
+ };
2143
+ if (!DatePicker) {
2144
+ return /* @__PURE__ */ jsxs(
2145
+ FieldWrapper,
2146
+ {
2147
+ customClass,
2148
+ isChild,
2149
+ noIndent,
2150
+ hidden,
2151
+ index,
2152
+ children: [
2153
+ label && /* @__PURE__ */ jsx(
2154
+ FieldLabel,
2155
+ {
2156
+ name,
2157
+ label,
2158
+ required,
2159
+ info
2160
+ }
2161
+ ),
2162
+ /* @__PURE__ */ jsx("div", { className: "col-xs-12 col-md-5 col-sm-9 px-0", children: /* @__PURE__ */ jsx(
2163
+ Input,
2164
+ {
2165
+ type: "date",
2166
+ name,
2167
+ "data-testid": dataTestId || `${formatString(name)}-date-picker`,
2168
+ value: fieldValue || "",
2169
+ onChange: (event) => activeFormik.handleChange(event),
2170
+ onBlur: activeFormik.handleBlur,
2171
+ disabled: disabled || false,
2172
+ error: !!(fieldError && fieldTouched)
2173
+ }
2174
+ ) }),
2175
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
2176
+ FieldError,
2177
+ {
2178
+ name,
2179
+ error: fieldError,
2180
+ touched: fieldTouched,
2181
+ dataTestId
2182
+ }
2183
+ ),
2184
+ component && /* @__PURE__ */ jsx("div", { className: "mt-3", children: component })
2185
+ ]
2186
+ }
2187
+ );
2188
+ }
2189
+ return /* @__PURE__ */ jsxs(
2190
+ FieldWrapper,
2191
+ {
2192
+ customClass,
2193
+ isChild,
2194
+ noIndent,
2195
+ hidden,
2196
+ index,
2197
+ children: [
2198
+ label && /* @__PURE__ */ jsx(
2199
+ FieldLabel,
2200
+ {
2201
+ name,
2202
+ label,
2203
+ required,
2204
+ info
2205
+ }
2206
+ ),
2207
+ /* @__PURE__ */ jsx("div", { className: "col-xs-12 col-md-5 col-sm-9 px-0", children: /* @__PURE__ */ jsx(
2208
+ DatePicker,
2209
+ {
2210
+ value: fieldValue || null,
2211
+ onChange: handleDateChange,
2212
+ format: dateFormat,
2213
+ disabled,
2214
+ "data-testid": dataTestId || `${formatString(name)}-date-picker`
2215
+ }
2216
+ ) }),
2217
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
2218
+ FieldError,
2219
+ {
2220
+ name,
2221
+ error: fieldError,
2222
+ touched: fieldTouched,
2223
+ dataTestId
2224
+ }
2225
+ ),
2226
+ component && /* @__PURE__ */ jsx("div", { className: "mt-3", children: component })
2227
+ ]
2228
+ }
2229
+ );
2230
+ };
2231
+ var DateTimePickerField = ({
2232
+ name,
2233
+ type,
2234
+ label,
2235
+ desc,
2236
+ info,
2237
+ required,
2238
+ disabled,
2239
+ customClass,
2240
+ customComponentClass,
2241
+ isChild,
2242
+ noIndent,
2243
+ hidden,
2244
+ views,
2245
+ disablePast,
2246
+ dataTestId,
2247
+ customHandleChange,
2248
+ customFormChange,
2249
+ component,
2250
+ child,
2251
+ formik: formikProp,
2252
+ index
2253
+ }) => {
2254
+ const { uiLibrary, formik } = useFormContext();
2255
+ const { adapter } = uiLibrary;
2256
+ const FormControl = adapter.FormControl;
2257
+ const activeFormik = formikProp || formik;
2258
+ const fieldValue = getFieldValue(activeFormik, name);
2259
+ const fieldError = getFieldError(activeFormik, name);
2260
+ const fieldTouched = getFieldTouched(activeFormik, name);
2261
+ const DateTimePicker = adapter.DateTimePicker;
2262
+ const Input = adapter.Input;
2263
+ const handleDateTimeChange = (date) => {
2264
+ const event = {
2265
+ name,
2266
+ value: date
2267
+ };
2268
+ if (customHandleChange) {
2269
+ customHandleChange(event, type);
2270
+ } else if (customFormChange) {
2271
+ customFormChange(event, type);
2272
+ } else {
2273
+ activeFormik.handleChange(event);
2274
+ }
2275
+ };
2276
+ const format = Array.isArray(views) && views.length === 2 && views[0] === "day" && views[1] === "hours" ? "DD/MM/YYYY HH:mm:ss" : "DD/MM/YYYY HH:mm";
2277
+ if (!DateTimePicker) {
2278
+ return /* @__PURE__ */ jsx(
2279
+ FieldWrapper,
2280
+ {
2281
+ customClass,
2282
+ isChild,
2283
+ noIndent,
2284
+ hidden,
2285
+ index,
2286
+ children: /* @__PURE__ */ jsxs(
2287
+ FormControl,
2288
+ {
2289
+ className: "w-100",
2290
+ required,
2291
+ error: !!(fieldTouched && fieldError),
2292
+ children: [
2293
+ label && /* @__PURE__ */ jsx(
2294
+ FieldLabel,
2295
+ {
2296
+ name,
2297
+ label,
2298
+ required,
2299
+ info
2300
+ }
2301
+ ),
2302
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
2303
+ /* @__PURE__ */ jsx(
2304
+ Input,
2305
+ {
2306
+ type: "datetime-local",
2307
+ name,
2308
+ "data-testid": dataTestId || `${formatString(name)}-date-time-picker`,
2309
+ value: fieldValue || "",
2310
+ onChange: (event) => activeFormik.handleChange(event),
2311
+ onBlur: activeFormik.handleBlur,
2312
+ disabled: disabled || false,
2313
+ error: !!(fieldError && fieldTouched)
2314
+ }
2315
+ ),
2316
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
2317
+ FieldError,
2318
+ {
2319
+ name,
2320
+ error: fieldError,
2321
+ touched: fieldTouched,
2322
+ dataTestId
2323
+ }
2324
+ )
2325
+ ]
2326
+ }
2327
+ )
2328
+ }
2329
+ );
2330
+ }
2331
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2332
+ /* @__PURE__ */ jsx(
2333
+ FieldWrapper,
2334
+ {
2335
+ customClass,
2336
+ isChild,
2337
+ noIndent,
2338
+ hidden,
2339
+ index,
2340
+ children: /* @__PURE__ */ jsxs(
2341
+ FormControl,
2342
+ {
2343
+ className: "w-100",
2344
+ required,
2345
+ error: !!(fieldTouched && fieldError),
2346
+ children: [
2347
+ label && /* @__PURE__ */ jsx(
2348
+ FieldLabel,
2349
+ {
2350
+ name,
2351
+ label,
2352
+ required,
2353
+ info
2354
+ }
2355
+ ),
2356
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
2357
+ /* @__PURE__ */ jsx(
2358
+ DateTimePicker,
2359
+ {
2360
+ value: fieldValue || null,
2361
+ onChange: handleDateTimeChange,
2362
+ format,
2363
+ disabled,
2364
+ views,
2365
+ disablePast,
2366
+ "data-testid": dataTestId || `${formatString(name)}-date-time-picker`
2367
+ }
2368
+ ),
2369
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
2370
+ FieldError,
2371
+ {
2372
+ name,
2373
+ error: fieldError,
2374
+ touched: fieldTouched,
2375
+ dataTestId
2376
+ }
2377
+ )
2378
+ ]
2379
+ }
2380
+ )
2381
+ }
2382
+ ),
2383
+ child && child.map((childField, childIndex) => {
2384
+ return null;
2385
+ }),
2386
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
2387
+ ] });
2388
+ };
2389
+ var DeleteField = ({
2390
+ name,
2391
+ type,
2392
+ handleDeleteAttribute,
2393
+ index
2394
+ }) => {
2395
+ const { uiLibrary } = useFormContext();
2396
+ const { adapter, icons } = uiLibrary;
2397
+ const IconButton = adapter.IconButton;
2398
+ const DeleteIcon = icons?.Delete;
2399
+ const handleClick = () => {
2400
+ if (handleDeleteAttribute) {
2401
+ handleDeleteAttribute(name);
2402
+ }
2403
+ };
2404
+ return /* @__PURE__ */ jsx("div", { className: "col-1", children: DeleteIcon && IconButton ? /* @__PURE__ */ jsx(
2405
+ IconButton,
2406
+ {
2407
+ role: "button",
2408
+ "data-testid": `${formatString(name)}-delete-btn`,
2409
+ onClick: handleClick,
2410
+ className: "text-danger fs-4 mt-3",
2411
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: DeleteIcon, size: 20 })
2412
+ }
2413
+ ) : /* @__PURE__ */ jsx(
2414
+ "button",
2415
+ {
2416
+ type: "button",
2417
+ "data-testid": `${formatString(name)}-delete-btn`,
2418
+ onClick: handleClick,
2419
+ className: "text-danger fs-4 mt-3",
2420
+ children: "\xD7"
2421
+ }
2422
+ ) }, index);
2423
+ };
2424
+ var CounterField = ({
2425
+ name,
2426
+ type,
2427
+ label,
2428
+ desc,
2429
+ info,
2430
+ required,
2431
+ customClass,
2432
+ customComponentClass,
2433
+ isChild,
2434
+ noIndent,
2435
+ hidden,
2436
+ min,
2437
+ max,
2438
+ suffix,
2439
+ dataTestId,
2440
+ customHandleChange,
2441
+ customFormChange,
2442
+ component,
2443
+ child,
2444
+ formik: formikProp,
2445
+ index
2446
+ }) => {
2447
+ const { uiLibrary, formik } = useFormContext();
2448
+ const { adapter } = uiLibrary;
2449
+ const FormControl = adapter.FormControl;
2450
+ const Button = adapter.Button;
2451
+ const Input = adapter.Input;
2452
+ const activeFormik = formikProp || formik;
2453
+ const fieldValue = getFieldValue(activeFormik, name);
2454
+ const numericValue = Number(fieldValue) || 0;
2455
+ const fieldError = getFieldError(activeFormik, name);
2456
+ const fieldTouched = getFieldTouched(activeFormik, name);
2457
+ const handleIncrement = () => {
2458
+ const newValue = max !== void 0 ? Math.min(numericValue + 1, max) : numericValue + 1;
2459
+ const event = {
2460
+ name,
2461
+ value: newValue
2462
+ };
2463
+ if (customHandleChange) {
2464
+ customHandleChange(event, type);
2465
+ } else if (customFormChange) {
2466
+ customFormChange(event, type);
2467
+ } else {
2468
+ activeFormik.handleChange(event);
2469
+ }
2470
+ };
2471
+ const handleDecrement = () => {
2472
+ const newValue = min !== void 0 ? Math.max(numericValue - 1, min) : numericValue - 1;
2473
+ const event = {
2474
+ name,
2475
+ value: newValue
2476
+ };
2477
+ if (customHandleChange) {
2478
+ customHandleChange(event, type);
2479
+ } else if (customFormChange) {
2480
+ customFormChange(event, type);
2481
+ } else {
2482
+ activeFormik.handleChange(event);
2483
+ }
2484
+ };
2485
+ const handleInputChange = (event) => {
2486
+ const value = Number(event.target.value);
2487
+ if (isNaN(value)) return;
2488
+ let newValue = value;
2489
+ if (min !== void 0 && value < min) newValue = min;
2490
+ if (max !== void 0 && value > max) newValue = max;
2491
+ const syntheticEvent = {
2492
+ target: {
2493
+ name,
2494
+ value: newValue
2495
+ }
2496
+ };
2497
+ if (customHandleChange) {
2498
+ customHandleChange(syntheticEvent, type);
2499
+ } else if (customFormChange) {
2500
+ customFormChange(syntheticEvent, type);
2501
+ } else {
2502
+ activeFormik.handleChange(syntheticEvent);
2503
+ }
2504
+ };
2505
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2506
+ /* @__PURE__ */ jsx(
2507
+ FieldWrapper,
2508
+ {
2509
+ customClass,
2510
+ isChild,
2511
+ noIndent,
2512
+ hidden,
2513
+ index,
2514
+ children: /* @__PURE__ */ jsxs(
2515
+ FormControl,
2516
+ {
2517
+ className: "w-100",
2518
+ required,
2519
+ error: !!(fieldTouched && fieldError),
2520
+ children: [
2521
+ label && /* @__PURE__ */ jsx(
2522
+ FieldLabel,
2523
+ {
2524
+ name,
2525
+ label,
2526
+ required,
2527
+ info
2528
+ }
2529
+ ),
2530
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
2531
+ /* @__PURE__ */ jsxs("div", { className: "d-flex align-items-center gap-2", children: [
2532
+ /* @__PURE__ */ jsx(
2533
+ Button,
2534
+ {
2535
+ type: "button",
2536
+ onClick: handleDecrement,
2537
+ disabled: min !== void 0 && numericValue <= min,
2538
+ children: "\u2212"
2539
+ }
2540
+ ),
2541
+ /* @__PURE__ */ jsx(
2542
+ Input,
2543
+ {
2544
+ type: "number",
2545
+ name,
2546
+ "data-testid": dataTestId || `${formatString(name)}-counter`,
2547
+ value: numericValue,
2548
+ onChange: handleInputChange,
2549
+ onBlur: activeFormik.handleBlur,
2550
+ min,
2551
+ max,
2552
+ className: "text-center",
2553
+ style: { width: "80px" },
2554
+ error: !!(fieldError && fieldTouched)
2555
+ }
2556
+ ),
2557
+ suffix && /* @__PURE__ */ jsx("span", { children: suffix }),
2558
+ /* @__PURE__ */ jsx(
2559
+ Button,
2560
+ {
2561
+ type: "button",
2562
+ onClick: handleIncrement,
2563
+ disabled: max !== void 0 && numericValue >= max,
2564
+ children: "+"
2565
+ }
2566
+ )
2567
+ ] }),
2568
+ fieldError && fieldTouched && /* @__PURE__ */ jsx(
2569
+ FieldError,
2570
+ {
2571
+ name,
2572
+ error: fieldError,
2573
+ touched: fieldTouched,
2574
+ dataTestId
2575
+ }
2576
+ )
2577
+ ]
2578
+ }
2579
+ )
2580
+ }
2581
+ ),
2582
+ child && child.map((childField, childIndex) => {
2583
+ return null;
2584
+ }),
2585
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-1 mx-1", children: component })
2586
+ ] });
2587
+ };
2588
+
2589
+ // src/hooks/useTranslation.ts
2590
+ var useTranslation = () => {
2591
+ return {
2592
+ t: (key) => {
2593
+ const translations = {
2594
+ "COMMON:add": "Add",
2595
+ "COMMON:choose_attribute": "Choose Attribute",
2596
+ "COMMON:attribute_mapping.no_attributes_added": "No attributes added"
2597
+ };
2598
+ return translations[key] || key;
2599
+ }
2600
+ };
2601
+ };
2602
+ var FieldArrayField = ({
2603
+ name,
2604
+ type,
2605
+ label,
2606
+ desc,
2607
+ info,
2608
+ required,
2609
+ showOptional,
2610
+ customClass,
2611
+ customComponentClass,
2612
+ isButtonVisible = true,
2613
+ buttonLabel,
2614
+ properties,
2615
+ component,
2616
+ formik: formikProp,
2617
+ index
2618
+ }) => {
2619
+ const { uiLibrary, formik } = useFormContext();
2620
+ const { adapter, icons } = uiLibrary;
2621
+ const Input = adapter.Input;
2622
+ const Button = adapter.Button;
2623
+ const IconButton = adapter.IconButton;
2624
+ const activeFormik = formikProp || formik;
2625
+ const { t } = useTranslation();
2626
+ const fieldValue = getFieldValue(activeFormik, name);
2627
+ const arrayValue = Array.isArray(fieldValue) ? fieldValue : [];
2628
+ const AddIcon = icons?.Add;
2629
+ const DeleteIcon = icons?.Delete;
2630
+ const deleteRow = (indexToDelete) => {
2631
+ const updatedArray = arrayValue.filter((_, i) => i !== indexToDelete);
2632
+ activeFormik.setFieldValue(name, updatedArray);
2633
+ };
2634
+ const addRow = () => {
2635
+ if (properties?.isKeyValue) {
2636
+ activeFormik.setFieldValue(name, [...arrayValue, { key: "", value: "" }]);
2637
+ } else {
2638
+ activeFormik.setFieldValue(name, [...arrayValue, ""]);
2639
+ }
2640
+ };
2641
+ const isKeyValue = properties?.isKeyValue || false;
2642
+ return /* @__PURE__ */ jsxs(FieldWrapper, { customClass, index, children: [
2643
+ label && /* @__PURE__ */ jsx(
2644
+ FieldLabel,
2645
+ {
2646
+ name,
2647
+ label,
2648
+ required,
2649
+ showOptional,
2650
+ info
2651
+ }
2652
+ ),
2653
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
2654
+ component && /* @__PURE__ */ jsx("div", { className: customComponentClass || "mb-2", children: component }),
2655
+ isKeyValue ? /* @__PURE__ */ jsxs(Fragment, { children: [
2656
+ arrayValue.map((item, itemIndex) => /* @__PURE__ */ jsxs("div", { className: "d-flex mb-2 gap-2", children: [
2657
+ /* @__PURE__ */ jsxs("div", { className: "col", children: [
2658
+ /* @__PURE__ */ jsx(
2659
+ Input,
2660
+ {
2661
+ name: `${name}[${itemIndex}].key`,
2662
+ "data-testid": formatString(name) + "-key-field",
2663
+ className: `form-control font-14 ${activeFormik.touched[name]?.[itemIndex] && activeFormik.errors[name]?.[itemIndex]?.key ? "border-danger" : ""}`,
2664
+ value: item.key || "",
2665
+ onChange: (event) => {
2666
+ const newValue = [...arrayValue];
2667
+ newValue[itemIndex] = {
2668
+ ...newValue[itemIndex],
2669
+ key: event.target.value
2670
+ };
2671
+ activeFormik.setFieldValue(name, newValue);
2672
+ },
2673
+ onBlur: activeFormik.handleBlur,
2674
+ placeholder: properties?.keyPlaceholder || "Enter key",
2675
+ autoComplete: "off"
2676
+ }
2677
+ ),
2678
+ (() => {
2679
+ const errorKey = activeFormik.errors[name]?.[itemIndex]?.key;
2680
+ const isTouched = activeFormik.touched[name]?.[itemIndex];
2681
+ return isTouched && errorKey ? /* @__PURE__ */ jsx(
2682
+ "small",
2683
+ {
2684
+ "data-testid": `${formatString(name)}-key-error`,
2685
+ className: "d-flex text-danger mt-1 text-12",
2686
+ children: String(errorKey)
2687
+ }
2688
+ ) : null;
2689
+ })()
2690
+ ] }),
2691
+ /* @__PURE__ */ jsxs("div", { className: "col", children: [
2692
+ /* @__PURE__ */ jsx(
2693
+ Input,
2694
+ {
2695
+ name: `${name}[${itemIndex}].value`,
2696
+ "data-testid": formatString(name) + "-value-field",
2697
+ className: `form-control font-14 ${activeFormik.touched[name]?.[itemIndex] && activeFormik.errors[name]?.[itemIndex]?.value ? "border-danger" : ""}`,
2698
+ value: item.value || "",
2699
+ onChange: (event) => {
2700
+ const newValue = [...arrayValue];
2701
+ newValue[itemIndex] = {
2702
+ ...newValue[itemIndex],
2703
+ value: event.target.value
2704
+ };
2705
+ activeFormik.setFieldValue(name, newValue);
2706
+ },
2707
+ onBlur: activeFormik.handleBlur,
2708
+ placeholder: properties?.valuePlaceholder || "Enter value",
2709
+ autoComplete: "off"
2710
+ }
2711
+ ),
2712
+ (() => {
2713
+ const errorValue = activeFormik.errors[name]?.[itemIndex]?.value;
2714
+ const isTouched = activeFormik.touched[name]?.[itemIndex];
2715
+ return isTouched && errorValue ? /* @__PURE__ */ jsx(
2716
+ "small",
2717
+ {
2718
+ "data-testid": `${formatString(name)}-value-error`,
2719
+ className: "d-flex text-danger mt-1 text-12",
2720
+ children: String(errorValue)
2721
+ }
2722
+ ) : null;
2723
+ })()
2724
+ ] }),
2725
+ arrayValue.length !== 1 && /* @__PURE__ */ jsx("div", { children: IconButton && DeleteIcon ? /* @__PURE__ */ jsx(
2726
+ IconButton,
2727
+ {
2728
+ size: "small",
2729
+ "data-testid": `${formatString(name)}-del-btn`,
2730
+ onClick: () => deleteRow(itemIndex),
2731
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: DeleteIcon, size: 20, className: "text-danger" })
2732
+ }
2733
+ ) : /* @__PURE__ */ jsx(
2734
+ "button",
2735
+ {
2736
+ type: "button",
2737
+ "data-testid": `${formatString(name)}-del-btn`,
2738
+ onClick: () => deleteRow(itemIndex),
2739
+ children: "\xD7"
2740
+ }
2741
+ ) })
2742
+ ] }, itemIndex)),
2743
+ isButtonVisible && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2744
+ Button,
2745
+ {
2746
+ variant: "text",
2747
+ className: "text-primary text-capitalize text-start",
2748
+ startIcon: AddIcon ? /* @__PURE__ */ jsx(IconRenderer, { Icon: AddIcon, size: 16 }) : "+",
2749
+ "data-testid": `${formatString(name)}-add-btn`,
2750
+ onClick: addRow,
2751
+ children: buttonLabel || t("COMMON:add")
2752
+ }
2753
+ ) })
2754
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2755
+ arrayValue.map((item, itemIndex) => /* @__PURE__ */ jsxs("div", { className: "d-flex mb-2", children: [
2756
+ /* @__PURE__ */ jsxs("div", { className: "col", children: [
2757
+ /* @__PURE__ */ jsx(
2758
+ Input,
2759
+ {
2760
+ name: `${name}[${itemIndex}]`,
2761
+ "data-testid": formatString(name) + "-field",
2762
+ className: `form-control font-14 ${activeFormik.touched[name]?.[itemIndex] && activeFormik.errors[name]?.[itemIndex] ? "border-danger" : ""}`,
2763
+ value: item,
2764
+ onChange: (event) => {
2765
+ const newValue = [...arrayValue];
2766
+ newValue[itemIndex] = event.target.value;
2767
+ activeFormik.setFieldValue(name, newValue);
2768
+ },
2769
+ onBlur: activeFormik.handleBlur,
2770
+ autoComplete: "off"
2771
+ }
2772
+ ),
2773
+ (() => {
2774
+ const error = activeFormik.errors[name]?.[itemIndex];
2775
+ const isTouched = activeFormik.touched[name]?.[itemIndex];
2776
+ return isTouched && error ? /* @__PURE__ */ jsx(
2777
+ "small",
2778
+ {
2779
+ "data-testid": `${formatString(name)}-error`,
2780
+ className: "d-flex text-danger mt-1 text-12",
2781
+ children: String(error)
2782
+ }
2783
+ ) : null;
2784
+ })()
2785
+ ] }),
2786
+ arrayValue.length !== 1 && /* @__PURE__ */ jsx("div", { children: IconButton && DeleteIcon ? /* @__PURE__ */ jsx(
2787
+ IconButton,
2788
+ {
2789
+ size: "small",
2790
+ "data-testid": `${formatString(name)}-del-btn`,
2791
+ onClick: () => deleteRow(itemIndex),
2792
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: DeleteIcon, size: 20, className: "text-danger" })
2793
+ }
2794
+ ) : /* @__PURE__ */ jsx(
2795
+ "button",
2796
+ {
2797
+ type: "button",
2798
+ "data-testid": `${formatString(name)}-del-btn`,
2799
+ onClick: () => deleteRow(itemIndex),
2800
+ children: "\xD7"
2801
+ }
2802
+ ) })
2803
+ ] }, itemIndex)),
2804
+ isButtonVisible && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2805
+ Button,
2806
+ {
2807
+ variant: "text",
2808
+ className: "text-primary text-capitalize text-start",
2809
+ startIcon: AddIcon ? /* @__PURE__ */ jsx(IconRenderer, { Icon: AddIcon, size: 16 }) : "+",
2810
+ "data-testid": `${formatString(name)}-add-btn`,
2811
+ onClick: addRow,
2812
+ children: buttonLabel || t("COMMON:add")
2813
+ }
2814
+ ) })
2815
+ ] })
2816
+ ] });
2817
+ };
2818
+ var PROPERTY_FIELD_MAP = {
2819
+ inputfield: InputField,
2820
+ dropdown: DropdownField,
2821
+ checkbox: CheckboxField,
2822
+ radiobtn: RadioField,
2823
+ textarea: TextareaField,
2824
+ fileupload: FileUploadField,
2825
+ multiSelect: MultiSelectField,
2826
+ singleSelect: SingleSelectField,
2827
+ component: ComponentField,
2828
+ link: LinkField
2829
+ };
2830
+ var AttributeField = ({
2831
+ name,
2832
+ type,
2833
+ label,
2834
+ desc,
2835
+ required,
2836
+ customClass,
2837
+ customAttrClass,
2838
+ showIllustration = true,
2839
+ showAddNewFieldBtn = true,
2840
+ addNewFieldBtnLabel,
2841
+ properties = [],
2842
+ addNewField = {},
2843
+ component,
2844
+ formik: formikProp,
2845
+ minimumValuePresent = false,
2846
+ index,
2847
+ setFieldValuesRecursive,
2848
+ customFormChange
2849
+ }) => {
2850
+ const { uiLibrary, formik } = useFormContext();
2851
+ const { adapter, icons } = uiLibrary;
2852
+ const Button = adapter.Button;
2853
+ const IconButton = adapter.IconButton;
2854
+ const activeFormik = formikProp || formik;
2855
+ const { t } = useTranslation();
2856
+ const AddIcon = icons?.Add;
2857
+ const DeleteIcon = icons?.Delete;
2858
+ const attributeValues = getNestedValueNew(activeFormik.values, name);
2859
+ const attributeValuesAlt = getNestedProperty(activeFormik.values, name);
2860
+ const valuesArray = Array.isArray(attributeValues) ? attributeValues : Array.isArray(attributeValuesAlt) ? attributeValuesAlt : [];
2861
+ const deleteRow = (indexToDelete) => {
2862
+ const currentValues = getNestedProperty(activeFormik.values, name);
2863
+ const valuesArray2 = Array.isArray(currentValues) ? currentValues : [];
2864
+ const updatedArray = valuesArray2.filter((_, i) => i !== indexToDelete);
2865
+ activeFormik.setFieldValue(name, updatedArray);
2866
+ };
2867
+ const addNewAttribute = () => {
2868
+ const currentValues = getNestedProperty(activeFormik.values, name);
2869
+ const valuesArray2 = Array.isArray(currentValues) ? currentValues : [];
2870
+ activeFormik.setFieldValue(name, [...valuesArray2, addNewField]);
2871
+ };
2872
+ const hasNoAttributes = valuesArray.length === 0 || typeof valuesArray === "object" && Object.keys(valuesArray).length === 0;
2873
+ const renderPropertyField = (property, propIndex) => {
2874
+ const PropertyComponent = PROPERTY_FIELD_MAP[property.type];
2875
+ if (!PropertyComponent) {
2876
+ console.warn(`Unknown property type in AttributeField: ${property.type}`);
2877
+ return null;
2878
+ }
2879
+ const propertyProps = {
2880
+ ...property,
2881
+ formik: activeFormik,
2882
+ index: propIndex,
2883
+ setFieldValuesRecursive,
2884
+ customFormChange
2885
+ };
2886
+ return /* @__PURE__ */ jsx(PropertyComponent, { ...propertyProps }, propIndex);
2887
+ };
2888
+ return /* @__PURE__ */ jsxs(FieldWrapper, { customClass, index, children: [
2889
+ label && /* @__PURE__ */ jsx(
2890
+ FieldLabel,
2891
+ {
2892
+ name,
2893
+ label,
2894
+ required
2895
+ }
2896
+ ),
2897
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
2898
+ component && /* @__PURE__ */ jsx("div", { className: "mt-3", children: component }),
2899
+ showIllustration && hasNoAttributes ? /* @__PURE__ */ jsxs("div", { className: "d-flex flex-column justify-content-center align-items-center gap-4 pt-4", children: [
2900
+ /* @__PURE__ */ jsx(
2901
+ "div",
2902
+ {
2903
+ "data-testid": "no-attr-img",
2904
+ style: {
2905
+ width: "200px",
2906
+ height: "200px",
2907
+ backgroundColor: "#f0f0f0",
2908
+ display: "flex",
2909
+ alignItems: "center",
2910
+ justifyContent: "center"
2911
+ },
2912
+ children: "No Image"
2913
+ }
2914
+ ),
2915
+ /* @__PURE__ */ jsx("h6", { "data-testid": "no-attr-text", className: "mb-4", children: t("COMMON:attribute_mapping.no_attributes_added") })
2916
+ ] }) : valuesArray.map((item, itemIndex) => {
2917
+ const transformedProperties = properties.map((property) => ({
2918
+ ...property,
2919
+ name: `${name}[${itemIndex}].${property.name}`,
2920
+ child: property.child?.map((childItem) => ({
2921
+ ...childItem,
2922
+ name: `${name}[${itemIndex}].${childItem.name}`
2923
+ }))
2924
+ }));
2925
+ return /* @__PURE__ */ jsxs(
2926
+ "div",
2927
+ {
2928
+ className: customAttrClass || "d-flex flex-row gap-3 mb-3",
2929
+ children: [
2930
+ transformedProperties.map((property, propIndex) => {
2931
+ return /* @__PURE__ */ jsx(React7.Fragment, { children: renderPropertyField(property, propIndex) }, propIndex);
2932
+ }),
2933
+ (minimumValuePresent ? valuesArray.length > 1 : true) && /* @__PURE__ */ jsx("div", { className: "col-1 mt-4 pt-1", children: /* @__PURE__ */ jsx("div", { className: minimumValuePresent ? "mt-0" : "", children: IconButton && DeleteIcon ? /* @__PURE__ */ jsx(
2934
+ IconButton,
2935
+ {
2936
+ size: "small",
2937
+ onClick: () => deleteRow(itemIndex),
2938
+ "data-testid": `${formatString(name)}-delete-icon`,
2939
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: DeleteIcon, size: 20, className: "text-danger" })
2940
+ }
2941
+ ) : /* @__PURE__ */ jsx(
2942
+ "button",
2943
+ {
2944
+ type: "button",
2945
+ onClick: () => deleteRow(itemIndex),
2946
+ "data-testid": `${formatString(name)}-delete-icon`,
2947
+ children: "\xD7"
2948
+ }
2949
+ ) }) })
2950
+ ]
2951
+ },
2952
+ itemIndex
2953
+ );
2954
+ }),
2955
+ showAddNewFieldBtn && /* @__PURE__ */ jsx(
2956
+ "div",
2957
+ {
2958
+ className: valuesArray.length ? "" : `d-flex ${showIllustration ? "justify-content-center" : "justify-content-start"} align-items-center`,
2959
+ children: /* @__PURE__ */ jsx(
2960
+ Button,
2961
+ {
2962
+ variant: "text",
2963
+ className: "text-primary text-capitalize text-start",
2964
+ startIcon: AddIcon ? /* @__PURE__ */ jsx(IconRenderer, { Icon: AddIcon, size: 16 }) : "+",
2965
+ "data-testid": "add-attr-btn",
2966
+ onClick: addNewAttribute,
2967
+ children: addNewFieldBtnLabel ?? "Add"
2968
+ }
2969
+ )
2970
+ }
2971
+ )
2972
+ ] });
2973
+ };
2974
+ var EditableDivField = ({
2975
+ name,
2976
+ type,
2977
+ label,
2978
+ placeholder,
2979
+ desc,
2980
+ info,
2981
+ required,
2982
+ readonly,
2983
+ customClass,
2984
+ isCopyEnable,
2985
+ isVisibleEnable,
2986
+ dataTestId,
2987
+ availableFields = [],
2988
+ customHandleChange,
2989
+ customFormChange,
2990
+ component,
2991
+ showCustomError,
2992
+ formik: formikProp,
2993
+ index
2994
+ }) => {
2995
+ const { uiLibrary, formik } = useFormContext();
2996
+ const { adapter, icons } = uiLibrary;
2997
+ const Box = adapter.Box;
2998
+ const Popover = adapter.Popover;
2999
+ const Paper = adapter.Paper;
3000
+ const MenuItem = adapter.MenuItem;
3001
+ const Typography = adapter.Typography;
3002
+ adapter.IconButton;
3003
+ const activeFormik = formikProp || formik;
3004
+ const { t } = useTranslation();
3005
+ const [showPlaceholder, setShowPlaceholder] = useState({});
3006
+ const [anchorElEditableDiv, setAnchorElEditableDiv] = useState(null);
3007
+ const [activeSpan, setActiveSpan] = useState(null);
3008
+ const [prevKey, setPrevKey] = useState("");
3009
+ const [isTyping, setIsTyping] = useState(false);
3010
+ const editorRefEditableDiv = useRef(null);
3011
+ const fieldTimeoutRef = useRef(null);
3012
+ const isFieldFocusedRef = useRef(false);
3013
+ getFieldValue(activeFormik, name);
3014
+ const fieldError = getFieldError(activeFormik, name);
3015
+ const fieldTouched = getFieldTouched(activeFormik, name);
3016
+ const CopyIcon = icons?.Copy;
3017
+ const VisibilityIcon = icons?.Visibility;
3018
+ const VisibilityOffIcon = icons?.VisibilityOff;
3019
+ const checkPlaceholderVisibility = useCallback((content, fieldName) => {
3020
+ const isEmpty = !content || content.trim() === "" || content === "\u200B";
3021
+ setShowPlaceholder((prev) => ({
3022
+ ...prev,
3023
+ [fieldName]: isEmpty
3024
+ }));
3025
+ }, []);
3026
+ const setCursorToEnd = useCallback(() => {
3027
+ if (editorRefEditableDiv.current) {
3028
+ const editor = editorRefEditableDiv.current;
3029
+ if (editor.childNodes.length > 0) {
3030
+ const range = document.createRange();
3031
+ const selection = window.getSelection();
3032
+ if (selection) {
3033
+ range.selectNodeContents(editor);
3034
+ range.collapse(false);
3035
+ selection.removeAllRanges();
3036
+ selection.addRange(range);
3037
+ }
3038
+ editor.focus();
3039
+ } else {
3040
+ editor.focus();
3041
+ }
3042
+ }
3043
+ }, []);
3044
+ const setEditorContentWithSpans = useCallback((expression, fields) => {
3045
+ if (!editorRefEditableDiv.current) return;
3046
+ const editor = editorRefEditableDiv.current;
3047
+ editor.innerHTML = "";
3048
+ const parts = expression.split(/(\{\{[^}]+\}\}|\$\{[^}]+\})/);
3049
+ parts.forEach((part) => {
3050
+ let key = null;
3051
+ if (part.startsWith("{{") && part.endsWith("}}")) {
3052
+ key = part.slice(2, -2);
3053
+ }
3054
+ if (key) {
3055
+ const field = fields.find((f) => f.key === key);
3056
+ if (field) {
3057
+ const span = document.createElement("span");
3058
+ span.className = "field-span";
3059
+ span.contentEditable = "false";
3060
+ span.style.cursor = "pointer";
3061
+ span.innerText = `{{${field.key}}}`;
3062
+ editor.appendChild(span);
3063
+ } else {
3064
+ editor.appendChild(document.createTextNode(part));
3065
+ }
3066
+ } else if (part) {
3067
+ editor.appendChild(document.createTextNode(part));
3068
+ }
3069
+ });
3070
+ }, [availableFields]);
3071
+ const handleKeyDown = useCallback((e) => {
3072
+ if (e.key === "{" && prevKey === "{") {
3073
+ e.preventDefault();
3074
+ return;
3075
+ }
3076
+ if (e.key === "Backspace") {
3077
+ const sel = window.getSelection();
3078
+ if (sel && sel.rangeCount > 0) {
3079
+ const range = sel.getRangeAt(0);
3080
+ const { startContainer, startOffset } = range;
3081
+ if (startContainer.nodeType === Node.TEXT_NODE && startOffset === 0 && startContainer.previousSibling && startContainer.previousSibling.classList?.contains("field-span")) {
3082
+ e.preventDefault();
3083
+ const prevSibling = startContainer.previousSibling;
3084
+ if (prevSibling.parentNode) {
3085
+ prevSibling.parentNode.removeChild(prevSibling);
3086
+ }
3087
+ return;
3088
+ }
3089
+ if (startContainer.nodeType === Node.ELEMENT_NODE && startContainer.classList?.contains("field-span")) {
3090
+ e.preventDefault();
3091
+ if (startContainer.parentNode) {
3092
+ startContainer.parentNode.removeChild(startContainer);
3093
+ }
3094
+ }
3095
+ }
3096
+ }
3097
+ }, [prevKey]);
3098
+ const handleKeyUp = useCallback((e) => {
3099
+ const currentKey = e.key;
3100
+ if (currentKey === "{" && prevKey === "{" && !e.defaultPrevented) {
3101
+ const selection = window.getSelection();
3102
+ if (selection && selection.rangeCount > 0) {
3103
+ const range = selection.getRangeAt(0);
3104
+ const { startContainer, startOffset } = range;
3105
+ if (startContainer.nodeType === Node.TEXT_NODE) {
3106
+ const textContent = startContainer.textContent || "";
3107
+ const beforeCursor = textContent.substring(0, startOffset);
3108
+ if (beforeCursor.endsWith("{")) {
3109
+ if (editorRefEditableDiv.current) {
3110
+ setAnchorElEditableDiv(editorRefEditableDiv.current);
3111
+ }
3112
+ }
3113
+ }
3114
+ }
3115
+ }
3116
+ setPrevKey(currentKey);
3117
+ }, [prevKey]);
3118
+ const handleFieldSelect = useCallback((item) => {
3119
+ if (!editorRefEditableDiv.current) return;
3120
+ const newSpan = document.createElement("span");
3121
+ newSpan.className = "field-span";
3122
+ newSpan.contentEditable = "false";
3123
+ newSpan.style.cursor = "pointer";
3124
+ newSpan.innerText = `{{${item.key}}}`;
3125
+ if (activeSpan) {
3126
+ activeSpan.replaceWith(newSpan);
3127
+ const spaceNode = document.createTextNode("\u200B");
3128
+ newSpan.after(spaceNode);
3129
+ if (spaceNode.parentNode) {
3130
+ const range = document.createRange();
3131
+ range.setStartAfter(spaceNode);
3132
+ range.setEndAfter(spaceNode);
3133
+ const sel = window.getSelection();
3134
+ if (sel) {
3135
+ sel.removeAllRanges();
3136
+ sel.addRange(range);
3137
+ }
3138
+ }
3139
+ setActiveSpan(null);
3140
+ } else {
3141
+ const selection = window.getSelection();
3142
+ if (selection && selection.rangeCount > 0) {
3143
+ const range = selection.getRangeAt(0);
3144
+ range.deleteContents();
3145
+ range.insertNode(newSpan);
3146
+ const spaceNode = document.createTextNode("\u200B");
3147
+ newSpan.after(spaceNode);
3148
+ const newRange = document.createRange();
3149
+ newRange.setStartAfter(spaceNode);
3150
+ newRange.setEndAfter(spaceNode);
3151
+ const sel = window.getSelection();
3152
+ if (sel) {
3153
+ sel.removeAllRanges();
3154
+ sel.addRange(newRange);
3155
+ }
3156
+ }
3157
+ }
3158
+ const content = editorRefEditableDiv.current.innerText;
3159
+ if (customHandleChange) {
3160
+ customHandleChange(
3161
+ { target: { name, value: content } },
3162
+ "editablediv"
3163
+ );
3164
+ } else if (customFormChange) {
3165
+ customFormChange(
3166
+ { target: { name, value: content } },
3167
+ "editablediv"
3168
+ );
3169
+ } else {
3170
+ activeFormik.setFieldValue(name, content);
3171
+ }
3172
+ setAnchorElEditableDiv(null);
3173
+ setTimeout(() => {
3174
+ setCursorToEnd();
3175
+ }, 0);
3176
+ }, [activeSpan, name, customHandleChange, customFormChange, activeFormik, setCursorToEnd]);
3177
+ useEffect(() => {
3178
+ if (editorRefEditableDiv.current && activeFormik.values && !isTyping && availableFields.length > 0) {
3179
+ const fieldValue2 = getNestedProperty(activeFormik.values, name);
3180
+ checkPlaceholderVisibility(String(fieldValue2 || ""), name);
3181
+ setTimeout(() => {
3182
+ setEditorContentWithSpans(String(fieldValue2 || ""), availableFields);
3183
+ }, 0);
3184
+ }
3185
+ }, [activeFormik.values, name, isTyping, availableFields, checkPlaceholderVisibility, setEditorContentWithSpans]);
3186
+ useEffect(() => {
3187
+ return () => {
3188
+ if (fieldTimeoutRef.current) {
3189
+ clearTimeout(fieldTimeoutRef.current);
3190
+ }
3191
+ };
3192
+ }, []);
3193
+ return /* @__PURE__ */ jsxs(FieldWrapper, { customClass, index, children: [
3194
+ label && /* @__PURE__ */ jsx(
3195
+ FieldLabel,
3196
+ {
3197
+ name,
3198
+ label,
3199
+ required,
3200
+ info
3201
+ }
3202
+ ),
3203
+ desc && /* @__PURE__ */ jsx(FieldDescription, { desc }),
3204
+ /* @__PURE__ */ jsxs("div", { className: `input-group ${isCopyEnable || isVisibleEnable ? "" : "rounded"}`, children: [
3205
+ /* @__PURE__ */ jsxs("div", { className: "d-flex w-100 flex-wrap", children: [
3206
+ /* @__PURE__ */ jsxs(Box, { className: "w-100 d-flex flex-column align-items-start position-relative", children: [
3207
+ /* @__PURE__ */ jsx(
3208
+ Box,
3209
+ {
3210
+ contentEditable: !readonly,
3211
+ ref: editorRefEditableDiv,
3212
+ id: name,
3213
+ onKeyDown: handleKeyDown,
3214
+ onKeyUp: handleKeyUp,
3215
+ onInput: (event) => {
3216
+ const content = event.target.innerText;
3217
+ setIsTyping(true);
3218
+ checkPlaceholderVisibility(content, name);
3219
+ if (fieldTimeoutRef.current) {
3220
+ clearTimeout(fieldTimeoutRef.current);
3221
+ }
3222
+ if (isFieldFocusedRef.current) {
3223
+ fieldTimeoutRef.current = setTimeout(() => {
3224
+ setIsTyping(false);
3225
+ }, 9e3);
3226
+ }
3227
+ if (customHandleChange) {
3228
+ customHandleChange(
3229
+ { target: { name, value: content } },
3230
+ type
3231
+ );
3232
+ } else if (customFormChange) {
3233
+ customFormChange(
3234
+ { target: { name, value: content } },
3235
+ type
3236
+ );
3237
+ } else {
3238
+ activeFormik.setFieldValue(name, content);
3239
+ }
3240
+ },
3241
+ onPaste: (e) => {
3242
+ e.preventDefault();
3243
+ const text = (e.clipboardData || window.clipboardData)?.getData("text/plain") || "";
3244
+ const selection = window.getSelection();
3245
+ if (selection && selection.rangeCount > 0) {
3246
+ const range = selection.getRangeAt(0);
3247
+ range.deleteContents();
3248
+ range.insertNode(document.createTextNode(text));
3249
+ range.collapse(false);
3250
+ selection.removeAllRanges();
3251
+ selection.addRange(range);
3252
+ }
3253
+ const editor = e.target;
3254
+ const content = editor.innerText;
3255
+ checkPlaceholderVisibility(content, name);
3256
+ if (availableFields.length > 0) {
3257
+ setTimeout(() => {
3258
+ setEditorContentWithSpans(content, availableFields);
3259
+ setCursorToEnd();
3260
+ }, 0);
3261
+ }
3262
+ if (customHandleChange) {
3263
+ customHandleChange(
3264
+ { target: { name, value: content } },
3265
+ type
3266
+ );
3267
+ } else if (customFormChange) {
3268
+ customFormChange(
3269
+ { target: { name, value: content } },
3270
+ type
3271
+ );
3272
+ } else {
3273
+ activeFormik.setFieldValue(name, content);
3274
+ }
3275
+ },
3276
+ onClick: (e) => {
3277
+ const target = e.target;
3278
+ if (target.classList?.contains("field-span")) {
3279
+ setActiveSpan(target);
3280
+ setAnchorElEditableDiv(target);
3281
+ setIsTyping(true);
3282
+ }
3283
+ },
3284
+ suppressContentEditableWarning: true,
3285
+ "data-testid": dataTestId || `${formatString(name)}-editable-div`,
3286
+ className: `form-control ${isCopyEnable || isVisibleEnable ? "border border-end-0" : "rounded"} ${fieldError && fieldTouched ? "border-danger" : ""}`,
3287
+ style: {
3288
+ borderRadius: "8px",
3289
+ border: "1px solid #dee2e6",
3290
+ padding: "6px 12px",
3291
+ display: "inline-block",
3292
+ flexGrow: 1,
3293
+ minHeight: "37px"
3294
+ },
3295
+ onFocus: () => {
3296
+ isFieldFocusedRef.current = true;
3297
+ setIsTyping(true);
3298
+ const content = editorRefEditableDiv.current?.innerText || "";
3299
+ checkPlaceholderVisibility(content, name);
3300
+ },
3301
+ onBlur: (event) => {
3302
+ isFieldFocusedRef.current = false;
3303
+ if (fieldTimeoutRef.current) {
3304
+ clearTimeout(fieldTimeoutRef.current);
3305
+ fieldTimeoutRef.current = null;
3306
+ }
3307
+ const content = event.target.innerText;
3308
+ checkPlaceholderVisibility(content, name);
3309
+ activeFormik.setFieldValue(name, content);
3310
+ const syntheticEvent = {
3311
+ ...event,
3312
+ target: { name, value: content }
3313
+ };
3314
+ activeFormik.handleBlur(syntheticEvent);
3315
+ },
3316
+ readOnly: readonly || false
3317
+ }
3318
+ ),
3319
+ showPlaceholder[name] && placeholder && /* @__PURE__ */ jsx(
3320
+ Box,
3321
+ {
3322
+ sx: {
3323
+ position: "absolute",
3324
+ top: "8px",
3325
+ left: "12px",
3326
+ color: "#acadaf",
3327
+ pointerEvents: "none",
3328
+ fontSize: "14px",
3329
+ zIndex: 1
3330
+ },
3331
+ children: placeholder
3332
+ }
3333
+ )
3334
+ ] }),
3335
+ /* @__PURE__ */ jsx(
3336
+ Popover,
3337
+ {
3338
+ open: Boolean(anchorElEditableDiv),
3339
+ anchorEl: anchorElEditableDiv,
3340
+ onClose: () => setAnchorElEditableDiv(null),
3341
+ anchorOrigin: { vertical: "bottom", horizontal: "left" },
3342
+ "data-testid": `${formatString(name)}-attribute-popover`,
3343
+ children: /* @__PURE__ */ jsxs(
3344
+ Paper,
3345
+ {
3346
+ elevation: 3,
3347
+ className: "attribute-popover",
3348
+ children: [
3349
+ /* @__PURE__ */ jsx(
3350
+ Box,
3351
+ {
3352
+ style: {
3353
+ padding: "12px 16px",
3354
+ backgroundColor: "#f8f9fa",
3355
+ borderBottom: "1px solid #e0e0e0"
3356
+ },
3357
+ children: /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", color: "text.secondary", children: t("COMMON:choose_attribute") })
3358
+ }
3359
+ ),
3360
+ availableFields.map((item) => /* @__PURE__ */ jsxs(
3361
+ MenuItem,
3362
+ {
3363
+ "data-testid": `${formatString(name)}-attribute-${item.key}`,
3364
+ onClick: () => handleFieldSelect(item),
3365
+ className: "d-flex justify-content-between align-items-center",
3366
+ children: [
3367
+ /* @__PURE__ */ jsx(Typography, { children: item.label }),
3368
+ /* @__PURE__ */ jsx(Typography, { color: "text.secondary", className: "text-12", children: item.key })
3369
+ ]
3370
+ },
3371
+ item.key
3372
+ ))
3373
+ ]
3374
+ }
3375
+ )
3376
+ }
3377
+ )
3378
+ ] }),
3379
+ isVisibleEnable && VisibilityIcon && VisibilityOffIcon && /* @__PURE__ */ jsx(
3380
+ "button",
3381
+ {
3382
+ className: `z-0 btn btn-outline-secondary border-0 rounded-0 border-top border-bottom ${!isCopyEnable ? "border-end rounded-end" : ""} ${fieldError && fieldTouched ? "border-danger" : ""}`,
3383
+ type: "button",
3384
+ "data-testid": `${formatString(name)}-visible-btn`,
3385
+ onClick: () => {
3386
+ },
3387
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: VisibilityIcon, size: 16 })
3388
+ }
3389
+ ),
3390
+ isCopyEnable && CopyIcon && /* @__PURE__ */ jsx(
3391
+ "button",
3392
+ {
3393
+ className: `z-0 btn btn-outline-secondary border border-start-0 border-end rounded-end ${fieldError && fieldTouched ? "border-danger" : ""}`,
3394
+ type: "button",
3395
+ "data-testid": `${formatString(name)}-copy-btn`,
3396
+ "aria-label": "copy",
3397
+ onClick: () => {
3398
+ if (editorRefEditableDiv.current) {
3399
+ const text = editorRefEditableDiv.current.innerText;
3400
+ navigator.clipboard.writeText(text);
3401
+ }
3402
+ },
3403
+ children: /* @__PURE__ */ jsx(IconRenderer, { Icon: CopyIcon, size: 16 })
3404
+ }
3405
+ ),
3406
+ component && /* @__PURE__ */ jsx("div", { children: component })
3407
+ ] }),
3408
+ (showCustomError || fieldError && fieldTouched) && /* @__PURE__ */ jsx(
3409
+ FieldError,
3410
+ {
3411
+ name,
3412
+ error: fieldError,
3413
+ touched: fieldTouched,
3414
+ showCustomError,
3415
+ dataTestId
3416
+ }
3417
+ )
3418
+ ] });
3419
+ };
3420
+ var FIELD_COMPONENT_MAP = {
3421
+ emptyField: EmptyField,
3422
+ text: TextField,
3423
+ link: LinkField,
3424
+ component: ComponentField,
3425
+ custom: CustomField,
3426
+ inputfield: InputField,
3427
+ textarea: TextareaField,
3428
+ checkbox: CheckboxField,
3429
+ radiobtn: RadioField,
3430
+ dropdown: DropdownField,
3431
+ toggle: ToggleField,
3432
+ fileupload: FileUploadField,
3433
+ singleSelect: SingleSelectField,
3434
+ multiSelect: MultiSelectField,
3435
+ asyncSelect: AsyncSelectField,
3436
+ datePicker: DatePickerField,
3437
+ dateTimePicker: DateTimePickerField,
3438
+ delete: DeleteField,
3439
+ counter: CounterField,
3440
+ fieldArray: FieldArrayField,
3441
+ attribute: AttributeField,
3442
+ editablediv: EditableDivField
3443
+ };
3444
+ var DynamicForm = ({
3445
+ fields,
3446
+ formik,
3447
+ firstInitialValues,
3448
+ fieldCount,
3449
+ attributeFields,
3450
+ customFormChange,
3451
+ RadiusTab = false,
3452
+ uiLibrary
3453
+ }) => {
3454
+ const [formFields, setFormFields] = useState([]);
3455
+ const activeUILibrary = uiLibrary || {
3456
+ adapter: defaultAdapter,
3457
+ icons: defaultIcons,
3458
+ name: "default"
3459
+ };
3460
+ useEffect(() => {
3461
+ const newFormFields = fields?.filter((item) => item !== false);
3462
+ setFormFields(newFormFields);
3463
+ }, [fields]);
3464
+ const setFieldValuesRecursive = useCallback(
3465
+ (child, parentValue = null) => {
3466
+ if (!child) return;
3467
+ child.forEach((c) => {
3468
+ if (RadiusTab) {
3469
+ if (!c.hidden || parentValue === c.hiddenlabel) {
3470
+ const hasValues = "values" in c && c.values;
3471
+ const fieldValue = hasValues && typeof c.values === "object" && !Array.isArray(c.values) && Object.keys(c.values).length > 0 ? Object.keys(c.values)[0] : firstInitialValues ? getNestedProperty(firstInitialValues, c.name) : "";
3472
+ formik.setFieldValue(c.name, fieldValue);
3473
+ }
3474
+ } else {
3475
+ const value = firstInitialValues ? getNestedProperty(firstInitialValues, c.name) : void 0;
3476
+ formik.setFieldValue(c.name, value === void 0 ? "" : value);
3477
+ formik.setFieldTouched(c.name, false);
3478
+ }
3479
+ if (c.child) {
3480
+ setFieldValuesRecursive(c.child, parentValue);
3481
+ }
3482
+ });
3483
+ },
3484
+ [formik, firstInitialValues, RadiusTab]
3485
+ );
3486
+ const renderField = (field, index, isChild = false) => {
3487
+ if (!field) return null;
3488
+ if (field.shouldHide && field.shouldHide({
3489
+ formik,
3490
+ name: field.name,
3491
+ index: typeof index === "number" ? index : void 0
3492
+ })) {
3493
+ return null;
3494
+ }
3495
+ const FieldComponent = FIELD_COMPONENT_MAP[field.type];
3496
+ if (!FieldComponent) {
3497
+ console.warn(`Unknown field type: ${field.type}`);
3498
+ return null;
3499
+ }
3500
+ const fieldProps = {
3501
+ ...field,
3502
+ formik,
3503
+ index,
3504
+ isChild,
3505
+ setFieldValuesRecursive,
3506
+ customFormChange
3507
+ };
3508
+ const fieldElement = /* @__PURE__ */ jsx(FieldComponent, { ...fieldProps }, `${field.name}-${index}`);
3509
+ if (field.child && field.child.length > 0) {
3510
+ const fieldValue = getFieldValue(formik, field.name);
3511
+ const valuePath = getNestedProperty(formik.values, field.name);
3512
+ return /* @__PURE__ */ jsxs(React7.Fragment, { children: [
3513
+ fieldElement,
3514
+ field.child.map((childField, childIndex) => {
3515
+ const shouldShowChild = fieldValue === childField.hiddenlabel || valuePath === childField.hiddenlabel || field.type === "checkbox" && fieldValue || field.type === "radiobtn" && (fieldValue === childField.targetType || String(fieldValue) === String(childField.targetType)) || field.type === "attribute" && true;
3516
+ if (shouldShowChild) {
3517
+ return renderField(
3518
+ childField,
3519
+ `child-${childField.name}-${childIndex}`,
3520
+ true
3521
+ );
3522
+ }
3523
+ return null;
3524
+ })
3525
+ ] }, `${field.name}-${index}`);
3526
+ }
3527
+ return fieldElement;
3528
+ };
3529
+ const groupFormFieldsIntoRows = () => {
3530
+ if (!fieldCount) return [];
3531
+ const rows = [];
3532
+ for (let i = 0; i < fieldCount; i += 1) {
3533
+ const startIdx = i * 3;
3534
+ const endIdx = startIdx + 3;
3535
+ const rowFields = formFields.slice(startIdx, endIdx);
3536
+ rows.push(rowFields);
3537
+ }
3538
+ return rows;
3539
+ };
3540
+ if (attributeFields !== void 0) {
3541
+ return /* @__PURE__ */ jsx(FormProvider, { uiLibrary: activeUILibrary, formik, children: /* @__PURE__ */ jsx("div", { className: "row", children: groupFormFieldsIntoRows().map((rowFields, rowIndex) => /* @__PURE__ */ jsx("div", { className: "row", children: rowFields.map((fieldValue, index) => {
3542
+ const uniqueKey = `${fieldValue?.label || fieldValue?.name}-${index}`;
3543
+ return /* @__PURE__ */ jsx(React7.Fragment, { children: renderField(fieldValue, uniqueKey) }, uniqueKey);
3544
+ }) }, rowIndex)) }) });
3545
+ }
3546
+ return /* @__PURE__ */ jsx(FormProvider, { uiLibrary: activeUILibrary, formik, children: /* @__PURE__ */ jsx("div", { className: "row mx-0", children: formFields.map((fieldValue, index) => {
3547
+ const uniqueKey = `${fieldValue?.label || fieldValue?.name}-${index}`;
3548
+ return renderField(fieldValue, uniqueKey);
3549
+ }) }) });
3550
+ };
3551
+
3552
+ // src/icons/mui.icons.tsx
3553
+ var createMUIIcons = (Info, Visibility, VisibilityOff, Copy, Add, Delete) => {
3554
+ return {
3555
+ Info,
3556
+ Visibility,
3557
+ VisibilityOff,
3558
+ Copy,
3559
+ Add,
3560
+ Delete
3561
+ };
3562
+ };
3563
+
3564
+ // src/icons/bootstrap.icons.tsx
3565
+ var createBootstrapIcons = (Info, Visibility, VisibilityOff, Copy, Add, Delete) => {
3566
+ return {
3567
+ Info,
3568
+ Visibility,
3569
+ VisibilityOff,
3570
+ Copy,
3571
+ Add,
3572
+ Delete
3573
+ };
3574
+ };
3575
+
3576
+ // src/icons/antd.icons.tsx
3577
+ var createAntDesignIcons = (Info, Visibility, VisibilityOff, Copy, Add, Delete) => {
3578
+ return {
3579
+ Info,
3580
+ Visibility,
3581
+ VisibilityOff,
3582
+ Copy,
3583
+ Add,
3584
+ Delete
3585
+ };
3586
+ };
3587
+
3588
+ // src/utils/validation.utils.ts
3589
+ var validateEmail = (email) => {
3590
+ if (!email) return false;
3591
+ const value = email.trim().toLowerCase();
3592
+ const strictRegex = /^[a-z0-9]+([._-]?[a-z0-9]+)*@[a-z0-9]+([.-]?[a-z0-9]+)*\.[a-z]{2,}$/;
3593
+ return strictRegex.test(value);
3594
+ };
3595
+ var isValidUrl = (url) => {
3596
+ if (!url) return false;
3597
+ try {
3598
+ const urlObj = new URL(url);
3599
+ return urlObj.protocol === "http:" || urlObj.protocol === "https:";
3600
+ } catch {
3601
+ return false;
3602
+ }
3603
+ };
3604
+ var checkValidUsername = (username, minLength, maxLength) => {
3605
+ const regex = new RegExp(`^[a-zA-Z0-9-_\\.]{${minLength},${maxLength}}$`);
3606
+ return regex.test(String(username));
3607
+ };
3608
+
3609
+ export { AsyncSelectField, AttributeField, CheckboxField, ComponentField, CounterField, CustomField, DatePickerField, DateTimePickerField, DeleteField, DropdownField, DynamicForm, EditableDivField, EmptyField, FieldArrayField, FieldDescription, FieldError, FieldLabel, FieldWrapper, FileUploadField, FormProvider, InputField, LinkField, MultiSelectField, RadioField, SingleSelectField, TextField, TextareaField, ToggleField, camelToKebabCase, checkValidUsername, createAntDesignAdapter, createAntDesignIcons, createBootstrapAdapter, createBootstrapIcons, createMUIAdapter, createMUIIcons, defaultAdapter, defaultIcons, formatString, getFieldError, getFieldTouched, getFieldValue, getNestedProperty, getNestedValueNew, isBlank, isNotBlank, isValidUrl, sanitizeLabelForCSS, useFormContext, validateEmail };
3610
+ //# sourceMappingURL=index.mjs.map
3611
+ //# sourceMappingURL=index.mjs.map