@gnwebsoft/ui 2.18.48 → 2.18.50

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.
@@ -0,0 +1,1890 @@
1
+ import {
2
+ useTransform
3
+ } from "./chunk-GFSTK7KN.mjs";
4
+ import {
5
+ readValueAsDate
6
+ } from "./chunk-RQS44YC7.mjs";
7
+
8
+ // src/wrappers3/DatePickerElement/DatePickerElement.tsx
9
+ import { useCallback } from "react";
10
+ import { useController } from "react-hook-form";
11
+ import { DatePicker } from "@mui/x-date-pickers";
12
+ import { Grid2, useForkRef, useTheme } from "@mui/material";
13
+ import { useLocalizationContext } from "@mui/x-date-pickers/internals";
14
+ import { jsx } from "react/jsx-runtime";
15
+ function readValueAsDate2(adapter, value) {
16
+ if (typeof value === "string") {
17
+ if (value === "") {
18
+ return null;
19
+ }
20
+ return adapter.utils.date(value);
21
+ }
22
+ return value;
23
+ }
24
+ function useTransform2(options) {
25
+ const value = typeof options.transform?.input === "function" ? options.transform.input(options.value) : options.value;
26
+ const onChange = useCallback(
27
+ (...event) => {
28
+ if (typeof options.transform?.output === "function") {
29
+ options.onChange(options.transform.output(...event));
30
+ } else {
31
+ options.onChange(...event);
32
+ }
33
+ },
34
+ [options]
35
+ );
36
+ return {
37
+ value,
38
+ onChange
39
+ };
40
+ }
41
+ var Component = function DatePickerElement(props) {
42
+ const {
43
+ name,
44
+ required,
45
+ inputProps,
46
+ control,
47
+ textReadOnly,
48
+ label,
49
+ placeholder,
50
+ slotProps,
51
+ datePickerProps = {},
52
+ transform,
53
+ sx,
54
+ ...rest
55
+ } = props;
56
+ const adapter = useLocalizationContext();
57
+ const theme = useTheme();
58
+ const { disabled, inputRef, onClose, ...restDatePickerProps } = datePickerProps;
59
+ const {
60
+ field,
61
+ fieldState: { error }
62
+ } = useController({
63
+ name,
64
+ control,
65
+ defaultValue: null
66
+ });
67
+ const { value, onChange } = useTransform2({
68
+ value: field.value,
69
+ onChange: field.onChange,
70
+ transform: {
71
+ input: typeof transform?.input === "function" ? transform.input : (newValue) => readValueAsDate2(adapter, newValue),
72
+ output: (outputValue, context) => {
73
+ if (outputValue === null) return null;
74
+ return outputValue;
75
+ }
76
+ }
77
+ });
78
+ const handleInputRef = useForkRef(field.ref, inputRef);
79
+ return /* @__PURE__ */ jsx(
80
+ DatePicker,
81
+ {
82
+ ...rest,
83
+ ...restDatePickerProps,
84
+ ...field,
85
+ value,
86
+ label,
87
+ disabled,
88
+ ...datePickerProps,
89
+ inputRef: handleInputRef,
90
+ onClose: (...args) => {
91
+ field.onBlur();
92
+ if (onClose) {
93
+ onClose(...args);
94
+ }
95
+ },
96
+ onChange: (newValue, context) => {
97
+ onChange(newValue, context);
98
+ if (typeof datePickerProps.onChange === "function") {
99
+ datePickerProps.onChange(newValue, context);
100
+ }
101
+ },
102
+ sx: {
103
+ "& .MuiOutlinedInput-root": {
104
+ bgcolor: disabled ? theme.palette.action.disabledBackground : "transparent"
105
+ },
106
+ "& .MuiInputLabel-asterisk": { color: "red" },
107
+ "& .MuiInputBase-input": {
108
+ cursor: disabled ? "not-allowed" : "default"
109
+ },
110
+ ...sx
111
+ },
112
+ slotProps: {
113
+ ...slotProps,
114
+ actionBar: {
115
+ actions: ["clear", "today", "cancel", "accept"]
116
+ },
117
+ textField: {
118
+ ...inputProps,
119
+ required,
120
+ placeholder,
121
+ fullWidth: true,
122
+ onBlur: (event) => {
123
+ field.onBlur();
124
+ if (typeof inputProps?.onBlur === "function") {
125
+ inputProps.onBlur(event);
126
+ }
127
+ },
128
+ error: !!error,
129
+ helperText: error ? error.message : inputProps?.helperText || rest.helperText,
130
+ inputProps: {
131
+ readOnly: !!textReadOnly,
132
+ ...inputProps?.inputProps
133
+ }
134
+ }
135
+ }
136
+ }
137
+ );
138
+ };
139
+ var DatePickerElement2 = ({
140
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
141
+ ...props
142
+ }) => {
143
+ if (gridProps) {
144
+ return /* @__PURE__ */ jsx(
145
+ Grid2,
146
+ {
147
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
148
+ children: /* @__PURE__ */ jsx(Component, { ...props })
149
+ }
150
+ );
151
+ }
152
+ return /* @__PURE__ */ jsx(Component, { ...props });
153
+ };
154
+ DatePickerElement2.displayName = "DatePickerElement";
155
+ var DatePickerElement_default = DatePickerElement2;
156
+
157
+ // src/wrappers3/PasswordElement/PasswordElement.tsx
158
+ import { useState } from "react";
159
+ import {
160
+ IconButton,
161
+ InputAdornment,
162
+ TextField,
163
+ useForkRef as useForkRef2,
164
+ Grid2 as Grid22
165
+ } from "@mui/material";
166
+ import Visibility from "@mui/icons-material/Visibility";
167
+ import VisibilityOff from "@mui/icons-material/VisibilityOff";
168
+ import {
169
+ useController as useController2
170
+ } from "react-hook-form";
171
+ import { jsx as jsx2 } from "react/jsx-runtime";
172
+ var Component2 = function PasswordEl(props) {
173
+ const {
174
+ type,
175
+ required,
176
+ iconColor,
177
+ renderIcon = (password2) => password2 ? /* @__PURE__ */ jsx2(Visibility, {}) : /* @__PURE__ */ jsx2(VisibilityOff, {}),
178
+ slotProps,
179
+ name,
180
+ control,
181
+ component: TextFieldComponent = TextField,
182
+ inputRef,
183
+ onBlur,
184
+ ...rest
185
+ } = props;
186
+ const [password, setPassword] = useState(true);
187
+ const endAdornment = /* @__PURE__ */ jsx2(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx2(
188
+ IconButton,
189
+ {
190
+ onMouseDown: (e) => e.preventDefault(),
191
+ onClick: () => setPassword(!password),
192
+ tabIndex: -1,
193
+ color: iconColor ?? "default",
194
+ children: renderIcon(password)
195
+ }
196
+ ) });
197
+ const {
198
+ field,
199
+ fieldState: { error }
200
+ } = useController2({
201
+ name,
202
+ control
203
+ });
204
+ const handleInputRef = useForkRef2(field.ref, inputRef);
205
+ return /* @__PURE__ */ jsx2(
206
+ TextField,
207
+ {
208
+ ...rest,
209
+ inputRef: handleInputRef,
210
+ type: password ? "password" : "text",
211
+ value: field.value,
212
+ fullWidth: true,
213
+ onChange: (event) => {
214
+ field.onChange(event);
215
+ if (typeof rest.onChange === "function") {
216
+ rest.onChange(event);
217
+ }
218
+ },
219
+ onBlur: (event) => {
220
+ field.onBlur();
221
+ if (typeof onBlur === "function") {
222
+ onBlur(event);
223
+ }
224
+ },
225
+ ...typeof slotProps === "undefined" ? {
226
+ InputProps: {
227
+ endAdornment
228
+ }
229
+ } : {
230
+ slotProps: {
231
+ ...slotProps,
232
+ input: {
233
+ endAdornment,
234
+ ...slotProps?.input
235
+ }
236
+ }
237
+ },
238
+ error: !!error,
239
+ helperText: error ? error.message : ""
240
+ }
241
+ );
242
+ };
243
+ var PasswordElement = ({
244
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
245
+ ...props
246
+ }) => {
247
+ if (gridProps) {
248
+ return /* @__PURE__ */ jsx2(
249
+ Grid22,
250
+ {
251
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
252
+ children: /* @__PURE__ */ jsx2(Component2, { ...props })
253
+ }
254
+ );
255
+ }
256
+ return /* @__PURE__ */ jsx2(Component2, { ...props });
257
+ };
258
+ PasswordElement.displayName = "PasswordElement";
259
+ var PasswordElement_default = PasswordElement;
260
+
261
+ // src/wrappers3/RadioButtonGroup/RadioButtonGroup.tsx
262
+ import {
263
+ useController as useController3
264
+ } from "react-hook-form";
265
+ import {
266
+ FormControl,
267
+ FormControlLabel,
268
+ FormHelperText,
269
+ FormLabel,
270
+ Radio,
271
+ RadioGroup,
272
+ useTheme as useTheme2,
273
+ Grid2 as Grid23
274
+ } from "@mui/material";
275
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
276
+ import { createElement } from "react";
277
+ var Component3 = function RadioButtonGroup(props) {
278
+ const {
279
+ helperText,
280
+ options,
281
+ label,
282
+ name,
283
+ parseError,
284
+ labelKey = "label",
285
+ valueKey = "id",
286
+ disabledKey = "disabled",
287
+ required,
288
+ emptyOptionLabel,
289
+ returnObject,
290
+ row,
291
+ control,
292
+ type,
293
+ labelProps,
294
+ disabled,
295
+ formLabelProps,
296
+ radioProps,
297
+ transform,
298
+ rules = {},
299
+ ...rest
300
+ } = props;
301
+ const theme = useTheme2();
302
+ const {
303
+ field,
304
+ fieldState: { error }
305
+ } = useController3({
306
+ name,
307
+ disabled,
308
+ control
309
+ });
310
+ const { value, onChange } = useTransform({
311
+ value: field.value,
312
+ onChange: field.onChange,
313
+ transform: {
314
+ input: typeof transform?.input === "function" ? transform.input : (value2) => {
315
+ return value2 || "";
316
+ },
317
+ output: typeof transform?.output === "function" ? transform?.output : (_event, value2) => {
318
+ if (value2 && type === "number") {
319
+ return Number(value2);
320
+ }
321
+ return value2;
322
+ }
323
+ }
324
+ });
325
+ const onRadioChange = (event, radioValue) => {
326
+ const returnValue = returnObject ? options.find((items) => items[valueKey] === radioValue) : radioValue;
327
+ onChange(event, returnValue);
328
+ if (typeof rest.onChange === "function") {
329
+ rest.onChange(returnValue);
330
+ }
331
+ };
332
+ return /* @__PURE__ */ jsxs(FormControl, { error: !!error, children: [
333
+ label && /* @__PURE__ */ jsx3(FormLabel, { ...formLabelProps, required, error: !!error, children: label }),
334
+ /* @__PURE__ */ jsxs(RadioGroup, { onChange: onRadioChange, name, row, value, children: [
335
+ emptyOptionLabel && /* @__PURE__ */ jsx3(
336
+ FormControlLabel,
337
+ {
338
+ ...labelProps,
339
+ control: /* @__PURE__ */ jsx3(
340
+ Radio,
341
+ {
342
+ ...radioProps,
343
+ sx: {
344
+ color: error ? theme.palette.error.main : void 0
345
+ },
346
+ checked: !value
347
+ }
348
+ ),
349
+ label: emptyOptionLabel,
350
+ value: ""
351
+ }
352
+ ),
353
+ options.map((option) => {
354
+ const optionKey = option[valueKey];
355
+ const optionDisabled = option[disabledKey] || false;
356
+ if (optionKey === void 0) {
357
+ console.error(
358
+ `RadioButtonGroup: valueKey ${valueKey} does not exist on option`,
359
+ option
360
+ );
361
+ }
362
+ let val = returnObject ? value?.[valueKey] : value;
363
+ if (type === "number") {
364
+ val = Number(val);
365
+ }
366
+ const isChecked = val === optionKey;
367
+ return /* @__PURE__ */ createElement(
368
+ FormControlLabel,
369
+ {
370
+ ...labelProps,
371
+ control: /* @__PURE__ */ jsx3(
372
+ Radio,
373
+ {
374
+ ...radioProps,
375
+ sx: {
376
+ color: error ? theme.palette.error.main : void 0
377
+ },
378
+ disabled: disabled || optionDisabled,
379
+ checked: isChecked
380
+ }
381
+ ),
382
+ value: optionKey,
383
+ label: option[labelKey],
384
+ key: optionKey
385
+ }
386
+ );
387
+ })
388
+ ] }),
389
+ error && /* @__PURE__ */ jsx3(FormHelperText, { children: error.message })
390
+ ] });
391
+ };
392
+ var RadioButtonGroup2 = ({
393
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
394
+ ...props
395
+ }) => {
396
+ if (gridProps) {
397
+ return /* @__PURE__ */ jsx3(
398
+ Grid23,
399
+ {
400
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
401
+ children: /* @__PURE__ */ jsx3(Component3, { ...props })
402
+ }
403
+ );
404
+ }
405
+ return /* @__PURE__ */ jsx3(Component3, { ...props });
406
+ };
407
+ RadioButtonGroup2.displayName = "RadioButtonGroup";
408
+ var RadioButtonGroup_default = RadioButtonGroup2;
409
+
410
+ // src/wrappers3/TextFieldElement/TextFieldElement.tsx
411
+ import {
412
+ Grid2 as Grid24,
413
+ TextField as TextField2,
414
+ useForkRef as useForkRef3,
415
+ useTheme as useTheme3
416
+ } from "@mui/material";
417
+ import {
418
+ useController as useController4
419
+ } from "react-hook-form";
420
+ import { jsx as jsx4 } from "react/jsx-runtime";
421
+ var Component4 = function TextFieldElement(props) {
422
+ const {
423
+ rules = {},
424
+ parseError,
425
+ name,
426
+ control,
427
+ component: TextFieldComponent = TextField2,
428
+ gridProps,
429
+ transform,
430
+ label,
431
+ placeholder,
432
+ textFieldProps = {},
433
+ variant,
434
+ sx,
435
+ ...rest
436
+ } = props;
437
+ const {
438
+ type,
439
+ required,
440
+ helperText,
441
+ inputRef,
442
+ onBlur,
443
+ disabled,
444
+ ...restTextProps
445
+ } = textFieldProps;
446
+ const {
447
+ field,
448
+ fieldState: { error }
449
+ } = useController4({
450
+ name,
451
+ control
452
+ });
453
+ const theme = useTheme3();
454
+ const { value, onChange } = useTransform({
455
+ value: field.value,
456
+ onChange: field.onChange,
457
+ transform: {
458
+ input: typeof transform?.input === "function" ? transform.input : (value2) => {
459
+ return value2 ?? "";
460
+ },
461
+ output: typeof transform?.output === "function" ? transform.output : (event) => {
462
+ const value2 = event.target.value;
463
+ if (type !== "number") {
464
+ return value2;
465
+ }
466
+ if (value2 === "") {
467
+ return null;
468
+ }
469
+ if (value2 == null) {
470
+ return value2;
471
+ }
472
+ return Number(value2);
473
+ }
474
+ }
475
+ });
476
+ const handleInputRef = useForkRef3(field.ref, inputRef);
477
+ return /* @__PURE__ */ jsx4(
478
+ TextFieldComponent,
479
+ {
480
+ ...rest,
481
+ ...restTextProps,
482
+ name: field.name,
483
+ value,
484
+ onChange: (event) => {
485
+ field.onChange(event);
486
+ if (typeof onChange === "function") {
487
+ onChange(event);
488
+ }
489
+ },
490
+ onBlur: (event) => {
491
+ field.onBlur();
492
+ if (typeof onBlur === "function") {
493
+ onBlur(event);
494
+ }
495
+ },
496
+ disabled,
497
+ label,
498
+ placeholder,
499
+ fullWidth: true,
500
+ required,
501
+ type,
502
+ error: !!error,
503
+ helperText: error ? error.message : helperText,
504
+ inputRef: handleInputRef,
505
+ variant: variant ? variant : "outlined",
506
+ size: "small",
507
+ sx: {
508
+ "& .MuiInputLabel-asterisk": { color: "red" },
509
+ "& .MuiInputBase-input": {
510
+ cursor: disabled ? "not-allowed" : "default"
511
+ },
512
+ bgcolor: disabled ? theme.palette.action.disabledBackground : "transparent",
513
+ ...sx
514
+ }
515
+ }
516
+ );
517
+ };
518
+ var TextFieldElement2 = ({
519
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
520
+ ...props
521
+ }) => {
522
+ if (gridProps) {
523
+ return /* @__PURE__ */ jsx4(
524
+ Grid24,
525
+ {
526
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
527
+ children: /* @__PURE__ */ jsx4(Component4, { ...props })
528
+ }
529
+ );
530
+ }
531
+ return /* @__PURE__ */ jsx4(Component4, { ...props });
532
+ };
533
+ TextFieldElement2.displayName = "TextFieldElement";
534
+ var TextFieldElement_default = TextFieldElement2;
535
+
536
+ // src/wrappers3/TimePickerElement/TimePickerElement.tsx
537
+ import {
538
+ TimePicker
539
+ } from "@mui/x-date-pickers";
540
+ import {
541
+ useController as useController5
542
+ } from "react-hook-form";
543
+ import { useForkRef as useForkRef4, Grid2 as Grid25 } from "@mui/material";
544
+ import { useLocalizationContext as useLocalizationContext2 } from "@mui/x-date-pickers/internals";
545
+ import { jsx as jsx5 } from "react/jsx-runtime";
546
+ var Component5 = function TimePickerElement(props) {
547
+ const {
548
+ parseError,
549
+ name,
550
+ required,
551
+ rules = {},
552
+ inputProps,
553
+ control,
554
+ textReadOnly,
555
+ slotProps,
556
+ inputRef,
557
+ transform,
558
+ ...rest
559
+ } = props;
560
+ const adapter = useLocalizationContext2();
561
+ const {
562
+ field,
563
+ fieldState: { error }
564
+ } = useController5({
565
+ name,
566
+ control,
567
+ disabled: rest.disabled,
568
+ defaultValue: null
569
+ });
570
+ const { value, onChange } = useTransform({
571
+ value: field.value,
572
+ onChange: field.onChange,
573
+ transform: {
574
+ input: typeof transform?.input === "function" ? transform.input : (newValue) => readValueAsDate(adapter, newValue),
575
+ output: typeof transform?.output === "function" ? transform.output : (newValue) => newValue
576
+ }
577
+ });
578
+ const handleInputRef = useForkRef4(field.ref, inputRef);
579
+ return /* @__PURE__ */ jsx5(
580
+ TimePicker,
581
+ {
582
+ ...rest,
583
+ ...field,
584
+ value,
585
+ inputRef: handleInputRef,
586
+ onClose: (...args) => {
587
+ field.onBlur();
588
+ if (rest.onClose) {
589
+ rest.onClose(...args);
590
+ }
591
+ },
592
+ onChange: (value2, context) => {
593
+ onChange(value2, context);
594
+ if (typeof rest.onChange === "function") {
595
+ rest.onChange(value2, context);
596
+ }
597
+ },
598
+ slotProps: {
599
+ ...slotProps,
600
+ textField: {
601
+ ...inputProps,
602
+ required,
603
+ fullWidth: true,
604
+ error: !!error,
605
+ helperText: error ? error.message : inputProps?.helperText || rest.helperText,
606
+ inputProps: {
607
+ readOnly: textReadOnly,
608
+ ...inputProps?.inputProps
609
+ }
610
+ }
611
+ }
612
+ }
613
+ );
614
+ };
615
+ var TimePickerElement2 = ({
616
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
617
+ ...props
618
+ }) => {
619
+ if (gridProps) {
620
+ return /* @__PURE__ */ jsx5(
621
+ Grid25,
622
+ {
623
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
624
+ children: /* @__PURE__ */ jsx5(Component5, { ...props })
625
+ }
626
+ );
627
+ }
628
+ return /* @__PURE__ */ jsx5(Component5, { ...props });
629
+ };
630
+ TimePickerElement2.displayName = "TimePickerElement";
631
+ var TimePickerElement_default = TimePickerElement2;
632
+
633
+ // src/wrappers3/AsyncSelect/AsyncSelectElement.tsx
634
+ import * as React from "react";
635
+ import { useController as useController6 } from "react-hook-form";
636
+ import {
637
+ useRef,
638
+ useMemo,
639
+ Fragment,
640
+ useState as useState2,
641
+ useEffect as useEffect2,
642
+ useCallback as useCallback2
643
+ } from "react";
644
+ import { debounce } from "@mui/material/utils";
645
+ import TextField3 from "@mui/material/TextField";
646
+ import Autocomplete from "@mui/material/Autocomplete";
647
+ import { Grid2 as Grid26, useTheme as useTheme4, CircularProgress } from "@mui/material";
648
+ import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
649
+ var Component6 = function AsyncSelectElement(props) {
650
+ const {
651
+ name,
652
+ onBlur,
653
+ disabled,
654
+ control,
655
+ gridProps,
656
+ placeholder,
657
+ initialValue,
658
+ label,
659
+ queryFn,
660
+ variant,
661
+ labelKey = "Label",
662
+ valueKey = "Value",
663
+ sx,
664
+ ...rest
665
+ } = props;
666
+ const {
667
+ field,
668
+ fieldState: { error }
669
+ } = useController6({
670
+ name,
671
+ control
672
+ });
673
+ const theme = useTheme4();
674
+ const [loading, setLoading] = useState2(false);
675
+ const [selectedOption, setSelectedOption] = useState2(null);
676
+ const [inputValue, setInputValue] = useState2("");
677
+ const inputValue2 = useMemo(() => inputValue, [inputValue]);
678
+ const setInputValue2 = useCallback2(
679
+ (newValue) => setInputValue(newValue),
680
+ []
681
+ );
682
+ const [options, setOptions] = useState2([]);
683
+ const initialValueLoaded = useRef(
684
+ !initialValue ? true : !(initialValue != null)
685
+ );
686
+ const fieldValue = useRef(field.value);
687
+ const fetchData = useMemo(
688
+ () => debounce(
689
+ (payload, callback) => {
690
+ queryFn(payload).then((c) => callback(c));
691
+ },
692
+ 400
693
+ ),
694
+ []
695
+ );
696
+ const fillOptions = (results) => {
697
+ let newOptions = [];
698
+ if (selectedOption) {
699
+ newOptions = [selectedOption];
700
+ }
701
+ if (results) {
702
+ newOptions = [...newOptions, ...results];
703
+ }
704
+ setOptions(newOptions);
705
+ setLoading(false);
706
+ };
707
+ useEffect2(() => {
708
+ if (initialValueLoaded.current) return void 0;
709
+ let active = true;
710
+ const payload = {
711
+ query: null,
712
+ initialValue
713
+ };
714
+ setLoading(true);
715
+ fetchData(payload, (results) => {
716
+ if (active) {
717
+ if (!!results && results.length > 0) {
718
+ fillOptions(results?.filter((c) => c.Value == initialValue));
719
+ setSelectedOption(results[0]);
720
+ field.onChange(results[0].Value);
721
+ fieldValue.current = results[0].Value;
722
+ }
723
+ initialValueLoaded.current = true;
724
+ setLoading(false);
725
+ }
726
+ });
727
+ return () => {
728
+ active = false;
729
+ };
730
+ }, [initialValue]);
731
+ React.useEffect(() => {
732
+ let active = true;
733
+ if (inputValue2 === "" || initialValueLoaded.current === false) {
734
+ setOptions(selectedOption ? [selectedOption] : []);
735
+ setLoading(false);
736
+ return void 0;
737
+ }
738
+ if (fieldValue.current) {
739
+ if (field.value === fieldValue.current) {
740
+ return void 0;
741
+ }
742
+ }
743
+ setLoading(true);
744
+ const payload = {
745
+ query: inputValue2,
746
+ initialValue: null
747
+ };
748
+ fetchData(payload, (results) => {
749
+ if (active) {
750
+ fillOptions(results);
751
+ }
752
+ });
753
+ return () => {
754
+ active = false;
755
+ };
756
+ }, [initialValue, inputValue2, fetchData]);
757
+ const selectRef = useRef(null);
758
+ const handleChange = (_2, newSelectedOption, reason) => {
759
+ if (reason === "clear") {
760
+ setSelectedOption(null);
761
+ field.onChange(null);
762
+ setLoading(false);
763
+ } else if (reason === "selectOption" || reason === "removeOption") {
764
+ if (newSelectedOption) {
765
+ setSelectedOption(newSelectedOption);
766
+ field.onChange(newSelectedOption.Value);
767
+ fieldValue.current = newSelectedOption.Value;
768
+ setLoading(false);
769
+ }
770
+ }
771
+ setOptions([]);
772
+ setLoading(false);
773
+ };
774
+ useEffect2(() => {
775
+ if (!field.value) {
776
+ setInputValue("");
777
+ setSelectedOption(null);
778
+ setLoading(false);
779
+ }
780
+ }, [field.value]);
781
+ const getOptionValue = (option) => {
782
+ if (typeof option === "string") return option;
783
+ return option ? option[valueKey] : null;
784
+ };
785
+ const getOptionLabel = (option) => {
786
+ if (typeof option === "string") return option;
787
+ return option ? option[labelKey] : "";
788
+ };
789
+ return /* @__PURE__ */ jsx6(
790
+ Autocomplete,
791
+ {
792
+ ...rest,
793
+ ref: selectRef,
794
+ fullWidth: true,
795
+ loading,
796
+ getOptionLabel,
797
+ getOptionKey: getOptionValue,
798
+ isOptionEqualToValue: (option, value) => getOptionValue(option) === getOptionValue(value),
799
+ autoComplete: true,
800
+ disabled,
801
+ includeInputInList: true,
802
+ options,
803
+ filterOptions: (x) => x,
804
+ value: selectedOption,
805
+ filterSelectedOptions: true,
806
+ onChange: handleChange,
807
+ onInputChange: (_2, newInputValue) => {
808
+ setInputValue2(newInputValue);
809
+ },
810
+ noOptionsText: "Type Something...",
811
+ renderInput: (params) => /* @__PURE__ */ jsx6(
812
+ TextField3,
813
+ {
814
+ ...params,
815
+ label,
816
+ error: !!error,
817
+ helperText: error ? error.message : "",
818
+ placeholder,
819
+ slotProps: {
820
+ input: {
821
+ ...params.InputProps,
822
+ endAdornment: /* @__PURE__ */ jsxs2(Fragment, { children: [
823
+ loading ? /* @__PURE__ */ jsx6(CircularProgress, { color: "inherit", size: 20 }) : null,
824
+ params.InputProps.endAdornment
825
+ ] })
826
+ }
827
+ },
828
+ variant: variant ? variant : "outlined",
829
+ sx: {
830
+ "& .MuiInputBase-input": {
831
+ cursor: disabled ? "not-allowed" : "default"
832
+ },
833
+ bgcolor: disabled ? theme.palette.action.disabledBackground : "transparent",
834
+ ...sx
835
+ }
836
+ }
837
+ ),
838
+ renderOption: (renderProps, option) => {
839
+ const { key, ...optionProps } = renderProps;
840
+ return /* @__PURE__ */ jsx6("li", { ...optionProps, children: option.Label }, key);
841
+ }
842
+ }
843
+ );
844
+ };
845
+ var AsyncSelectElement2 = ({
846
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
847
+ ...props
848
+ }) => {
849
+ if (gridProps) {
850
+ return /* @__PURE__ */ jsx6(
851
+ Grid26,
852
+ {
853
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
854
+ children: /* @__PURE__ */ jsx6(Component6, { ...props })
855
+ }
856
+ );
857
+ }
858
+ return /* @__PURE__ */ jsx6(Component6, { ...props });
859
+ };
860
+ AsyncSelectElement2.displayName = "AsyncSelectElement";
861
+ var AsyncSelectElement_default = AsyncSelectElement2;
862
+
863
+ // src/wrappers3/AsyncMultiSelect/AsyncMultiSelect.tsx
864
+ import _ from "lodash";
865
+ import {
866
+ useState as useState3,
867
+ useRef as useRef2,
868
+ useMemo as useMemo2,
869
+ useEffect as useEffect3,
870
+ useCallback as useCallback3,
871
+ Fragment as Fragment2
872
+ } from "react";
873
+ import { debounce as debounce2 } from "lodash";
874
+ import {
875
+ Autocomplete as Autocomplete2,
876
+ CircularProgress as CircularProgress2,
877
+ Grid2 as Grid27,
878
+ TextField as TextField4,
879
+ useTheme as useTheme5
880
+ } from "@mui/material";
881
+ import { useController as useController7 } from "react-hook-form";
882
+ import match from "autosuggest-highlight/match";
883
+ import parse from "autosuggest-highlight/parse";
884
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
885
+ var Component7 = function AsyncSelectMultiElement(props) {
886
+ const {
887
+ name,
888
+ onBlur,
889
+ disabled,
890
+ control,
891
+ gridProps,
892
+ placeholder,
893
+ initialValues,
894
+ label,
895
+ queryFn,
896
+ variant,
897
+ sx,
898
+ ...rest
899
+ } = props;
900
+ const {
901
+ field,
902
+ fieldState: { error }
903
+ } = useController7({
904
+ name,
905
+ control
906
+ });
907
+ const theme = useTheme5();
908
+ const multiSelectRef = useRef2(null);
909
+ const [selectedOptions, setSelectedOptions] = useState3([]);
910
+ const [inputValue, setInputValue] = useState3("");
911
+ const [options, setOptions] = useState3([]);
912
+ const [loading, setLoading] = useState3(false);
913
+ const initialValuesLoaded = useRef2(
914
+ !(initialValues && initialValues.length > 0)
915
+ );
916
+ const inputValue2 = useMemo2(() => inputValue, [inputValue]);
917
+ const setInputValue2 = useCallback3(
918
+ (inputValue3) => setInputValue(inputValue3),
919
+ []
920
+ );
921
+ const fetchData = useMemo2(
922
+ () => debounce2(
923
+ (payload, callback) => {
924
+ queryFn(payload).then((c) => callback(c));
925
+ },
926
+ 400
927
+ ),
928
+ []
929
+ );
930
+ const fillOptions = (results) => {
931
+ let newOptions = [];
932
+ if (selectedOptions) {
933
+ newOptions = [...selectedOptions];
934
+ }
935
+ if (results) {
936
+ const newlyAdded = _.differenceBy(
937
+ results,
938
+ selectedOptions,
939
+ (c) => c.Value
940
+ );
941
+ newOptions = [...newOptions, ...newlyAdded];
942
+ }
943
+ setOptions(newOptions);
944
+ setLoading(false);
945
+ };
946
+ useEffect3(() => {
947
+ if (initialValuesLoaded.current) return void 0;
948
+ let active = true;
949
+ const payload = {
950
+ query: null,
951
+ initialValues
952
+ };
953
+ setLoading(true);
954
+ fetchData(payload, (results) => {
955
+ if (active) {
956
+ setSelectedOptions([...results]);
957
+ field.onChange([...results.map((c) => c.Value)]);
958
+ initialValuesLoaded.current = true;
959
+ setLoading(false);
960
+ }
961
+ });
962
+ return () => {
963
+ active = false;
964
+ };
965
+ }, [initialValues]);
966
+ useEffect3(() => {
967
+ let active = true;
968
+ if (inputValue2 === "" || initialValuesLoaded.current === false) {
969
+ setOptions(selectedOptions ? [...selectedOptions] : []);
970
+ return void 0;
971
+ }
972
+ setLoading(true);
973
+ const payload = {
974
+ query: inputValue2,
975
+ initialValues: null
976
+ };
977
+ fetchData(payload, (results) => {
978
+ if (active) {
979
+ fillOptions(results);
980
+ }
981
+ });
982
+ return () => {
983
+ active = false;
984
+ };
985
+ }, [initialValues, inputValue2, fetchData]);
986
+ const handleChange = (_2, selectedOptions2, reason) => {
987
+ if (reason === "clear") {
988
+ setSelectedOptions([]);
989
+ field.onChange([]);
990
+ } else if (reason === "selectOption" || reason === "removeOption") {
991
+ setSelectedOptions(selectedOptions2);
992
+ field.onChange(selectedOptions2.map((c) => c.Value));
993
+ }
994
+ setOptions([]);
995
+ };
996
+ return /* @__PURE__ */ jsx7(
997
+ Autocomplete2,
998
+ {
999
+ ref: multiSelectRef,
1000
+ multiple: true,
1001
+ loading,
1002
+ getOptionLabel: (option) => option.Label,
1003
+ getOptionKey: (option) => option.Value,
1004
+ isOptionEqualToValue: (option, val) => option.Value === val.Value,
1005
+ options,
1006
+ value: selectedOptions,
1007
+ disabled,
1008
+ filterSelectedOptions: true,
1009
+ onChange: handleChange,
1010
+ onInputChange: (_2, newInputValue) => {
1011
+ setInputValue2(newInputValue);
1012
+ },
1013
+ renderInput: (params) => /* @__PURE__ */ jsx7(
1014
+ TextField4,
1015
+ {
1016
+ ...params,
1017
+ label,
1018
+ error: !!error,
1019
+ helperText: error ? error.message : "",
1020
+ placeholder,
1021
+ slotProps: {
1022
+ input: {
1023
+ ...params.InputProps,
1024
+ endAdornment: /* @__PURE__ */ jsxs3(Fragment2, { children: [
1025
+ loading ? /* @__PURE__ */ jsx7(CircularProgress2, { color: "inherit", size: 20 }) : null,
1026
+ params.InputProps.endAdornment
1027
+ ] })
1028
+ }
1029
+ },
1030
+ variant: variant ? variant : "outlined",
1031
+ sx: {
1032
+ "& .MuiInputBase-input": {
1033
+ cursor: disabled ? "not-allowed" : "default"
1034
+ },
1035
+ bgcolor: disabled ? theme.palette.action.disabledBackground : "transparent",
1036
+ ...sx
1037
+ }
1038
+ }
1039
+ ),
1040
+ renderOption: (props2, option, { inputValue: inputValue3 }) => {
1041
+ const { key, ...optionProps } = props2;
1042
+ const matches = match(option.Label, inputValue3, { insideWords: true });
1043
+ const parts = parse(option.Label, matches);
1044
+ return /* @__PURE__ */ jsx7("li", { ...optionProps, children: /* @__PURE__ */ jsx7("div", { children: parts.map((part, index) => /* @__PURE__ */ jsx7(
1045
+ "span",
1046
+ {
1047
+ style: {
1048
+ fontWeight: part.highlight ? 700 : 400
1049
+ },
1050
+ children: part.text
1051
+ },
1052
+ index
1053
+ )) }) }, key);
1054
+ },
1055
+ ...rest
1056
+ }
1057
+ );
1058
+ };
1059
+ var AsyncSelectMultiElement2 = ({
1060
+ gridProps,
1061
+ ...props
1062
+ }) => {
1063
+ if (gridProps) {
1064
+ return /* @__PURE__ */ jsx7(
1065
+ Grid27,
1066
+ {
1067
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
1068
+ children: /* @__PURE__ */ jsx7(Component7, { ...props })
1069
+ }
1070
+ );
1071
+ }
1072
+ return /* @__PURE__ */ jsx7(Component7, { ...props });
1073
+ };
1074
+ AsyncSelectMultiElement2.displayName = "AsyncSelectMulti";
1075
+ var AsyncMultiSelect_default = AsyncSelectMultiElement2;
1076
+
1077
+ // src/wrappers3/SelectElement/SelectElement.tsx
1078
+ import {
1079
+ useMemo as useMemo3,
1080
+ useEffect as useEffect4,
1081
+ useCallback as useCallback4
1082
+ } from "react";
1083
+ import {
1084
+ useController as useController8
1085
+ } from "react-hook-form";
1086
+ import { Grid2 as Grid28, useTheme as useTheme6, TextField as TextField5, Autocomplete as Autocomplete3 } from "@mui/material";
1087
+ import { jsx as jsx8 } from "react/jsx-runtime";
1088
+ var Component8 = function SelectElement(props) {
1089
+ const {
1090
+ name,
1091
+ control,
1092
+ onChange,
1093
+ isEdit,
1094
+ options,
1095
+ label,
1096
+ sx,
1097
+ variant,
1098
+ disabled,
1099
+ initialValue,
1100
+ labelKey = "Label",
1101
+ valueKey = "Value",
1102
+ placeholder,
1103
+ textFieldProps = {},
1104
+ ...rest
1105
+ } = props;
1106
+ const { required } = textFieldProps;
1107
+ const {
1108
+ field,
1109
+ fieldState: { error }
1110
+ } = useController8({
1111
+ name,
1112
+ control,
1113
+ defaultValue: initialValue
1114
+ });
1115
+ const theme = useTheme6();
1116
+ const getOptionValue = useCallback4(
1117
+ (option) => {
1118
+ if (typeof option === "string") return option;
1119
+ return option ? option[valueKey] : null;
1120
+ },
1121
+ [valueKey]
1122
+ );
1123
+ const getOptionLabel = useCallback4(
1124
+ (option) => {
1125
+ if (typeof option === "string") return option;
1126
+ return option ? String(option[labelKey]) : "";
1127
+ },
1128
+ [labelKey]
1129
+ );
1130
+ const handleChange = (event, newValue, reason) => {
1131
+ const option = newValue;
1132
+ field.onChange(option ? getOptionValue(option) : null);
1133
+ onChange?.(event, newValue, reason);
1134
+ };
1135
+ useEffect4(() => {
1136
+ if (!isEdit && options.length === 1 && (field.value == null || field.value === "")) {
1137
+ const defaultOption = options[0];
1138
+ field.onChange(getOptionValue(defaultOption));
1139
+ }
1140
+ if (isEdit) {
1141
+ if (field.value == null || field.value === "") {
1142
+ return;
1143
+ }
1144
+ }
1145
+ }, [isEdit, options, field.value, getOptionValue, field.onChange]);
1146
+ const autocompleteValue = useMemo3(() => {
1147
+ if (!field.value) return null;
1148
+ return options.find((option) => getOptionValue(option) === field.value) ?? null;
1149
+ }, [field.value, options, getOptionValue]);
1150
+ return /* @__PURE__ */ jsx8(
1151
+ Autocomplete3,
1152
+ {
1153
+ ...rest,
1154
+ filterSelectedOptions: false,
1155
+ options,
1156
+ value: autocompleteValue,
1157
+ onChange: handleChange,
1158
+ disabled,
1159
+ getOptionLabel: (option) => getOptionLabel(option),
1160
+ ref: field.ref,
1161
+ isOptionEqualToValue: (option, value) => getOptionValue(option) === getOptionValue(value),
1162
+ renderInput: (params) => /* @__PURE__ */ jsx8(
1163
+ TextField5,
1164
+ {
1165
+ ...params,
1166
+ fullWidth: true,
1167
+ required,
1168
+ error: !!error,
1169
+ helperText: error ? error.message : "",
1170
+ label,
1171
+ placeholder,
1172
+ variant: variant ? variant : "outlined",
1173
+ sx: {
1174
+ "& .MuiOutlinedInput-root": {
1175
+ bgcolor: disabled ? theme.palette.action.disabledBackground : "transparent"
1176
+ },
1177
+ "& .MuiInputLabel-asterisk": { color: "red" },
1178
+ "& .MuiInputBase-input": {
1179
+ cursor: disabled ? "not-allowed" : "default"
1180
+ },
1181
+ ...sx
1182
+ }
1183
+ }
1184
+ )
1185
+ }
1186
+ );
1187
+ };
1188
+ var SelectElement2 = ({
1189
+ gridProps,
1190
+ ...props
1191
+ }) => {
1192
+ if (gridProps) {
1193
+ return /* @__PURE__ */ jsx8(
1194
+ Grid28,
1195
+ {
1196
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
1197
+ children: /* @__PURE__ */ jsx8(Component8, { ...props })
1198
+ }
1199
+ );
1200
+ }
1201
+ return /* @__PURE__ */ jsx8(Component8, { ...props });
1202
+ };
1203
+ SelectElement2.displayName = "SelectElement";
1204
+ var SelectElement_default = SelectElement2;
1205
+
1206
+ // src/wrappers3/SelectMultiElement/SelectMultiElement.tsx
1207
+ import { Fragment as Fragment3 } from "react";
1208
+ import { useController as useController9 } from "react-hook-form";
1209
+ import Chip from "@mui/material/Chip";
1210
+ import CheckBoxIcon from "@mui/icons-material/CheckBox";
1211
+ import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
1212
+ import {
1213
+ Grid2 as Grid29,
1214
+ Checkbox,
1215
+ TextField as TextField6,
1216
+ Autocomplete as Autocomplete4,
1217
+ CircularProgress as CircularProgress3
1218
+ } from "@mui/material";
1219
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
1220
+ var Component9 = function SelectMultiElement(props) {
1221
+ const {
1222
+ name,
1223
+ control,
1224
+ onBlur,
1225
+ disabled,
1226
+ options,
1227
+ loading = false,
1228
+ placeholder,
1229
+ label,
1230
+ variant,
1231
+ sx,
1232
+ labelKey = "Label",
1233
+ valueKey = "Value",
1234
+ multiple = true,
1235
+ ...rest
1236
+ } = props;
1237
+ const {
1238
+ field,
1239
+ fieldState: { error }
1240
+ } = useController9({
1241
+ name,
1242
+ control
1243
+ });
1244
+ const getOptionValue = (option) => {
1245
+ if (typeof option === "string") return option;
1246
+ return option ? option[valueKey] : null;
1247
+ };
1248
+ const getOptionLabel = (option) => {
1249
+ if (typeof option === "string") return option;
1250
+ return option ? option[labelKey] : "";
1251
+ };
1252
+ const selectedValue = multiple ? Array.isArray(field.value) ? options.filter((option) => field.value.includes(getOptionValue(option))) : [] : options.find((option) => getOptionValue(option) === field.value) ?? null;
1253
+ const handleChange = (_2, selected, reason) => {
1254
+ if (multiple) {
1255
+ if (reason === "clear") {
1256
+ field.onChange([]);
1257
+ } else {
1258
+ const newValues = selected.map(
1259
+ (option) => getOptionValue(option)
1260
+ );
1261
+ field.onChange(newValues);
1262
+ }
1263
+ } else {
1264
+ field.onChange(selected ? getOptionValue(selected) : null);
1265
+ }
1266
+ };
1267
+ const icon = /* @__PURE__ */ jsx9(CheckBoxOutlineBlankIcon, { fontSize: "small" });
1268
+ const checkedIcon = /* @__PURE__ */ jsx9(CheckBoxIcon, { fontSize: "small" });
1269
+ return /* @__PURE__ */ jsx9(
1270
+ Autocomplete4,
1271
+ {
1272
+ multiple,
1273
+ value: selectedValue,
1274
+ loading,
1275
+ options,
1276
+ getOptionLabel: (option) => getOptionLabel(option),
1277
+ isOptionEqualToValue: (option, value) => getOptionValue(option) === getOptionValue(value),
1278
+ filterSelectedOptions: multiple,
1279
+ disableCloseOnSelect: multiple,
1280
+ ref: field.ref,
1281
+ disabled: disabled ?? field.disabled,
1282
+ onChange: handleChange,
1283
+ onBlur: (event) => {
1284
+ field.onBlur();
1285
+ if (typeof onBlur === "function") {
1286
+ onBlur(event);
1287
+ }
1288
+ },
1289
+ fullWidth: true,
1290
+ renderOption: (props1, option, { selected }) => multiple ? /* @__PURE__ */ jsxs4("li", { ...props1, children: [
1291
+ /* @__PURE__ */ jsx9(
1292
+ Checkbox,
1293
+ {
1294
+ icon,
1295
+ checkedIcon,
1296
+ checked: selected
1297
+ }
1298
+ ),
1299
+ getOptionLabel(option)
1300
+ ] }) : /* @__PURE__ */ jsx9("li", { ...props1, children: getOptionLabel(option) }),
1301
+ renderTags: (tagValue, getTagProps) => tagValue.map((option, index) => /* @__PURE__ */ jsx9(
1302
+ Chip,
1303
+ {
1304
+ ...getTagProps({ index }),
1305
+ label: getOptionLabel(option),
1306
+ size: "small",
1307
+ variant: "filled"
1308
+ }
1309
+ )),
1310
+ renderInput: (params) => /* @__PURE__ */ jsx9(
1311
+ TextField6,
1312
+ {
1313
+ ...params,
1314
+ label,
1315
+ error: !!error,
1316
+ helperText: error ? error.message : "",
1317
+ placeholder,
1318
+ slotProps: {
1319
+ input: {
1320
+ ...params.InputProps,
1321
+ endAdornment: /* @__PURE__ */ jsxs4(Fragment3, { children: [
1322
+ loading ? /* @__PURE__ */ jsx9(CircularProgress3, { color: "inherit", size: 20 }) : null,
1323
+ params.InputProps.endAdornment
1324
+ ] })
1325
+ }
1326
+ },
1327
+ variant: variant ? variant : "outlined",
1328
+ sx: {
1329
+ ...sx
1330
+ }
1331
+ }
1332
+ ),
1333
+ ...rest
1334
+ }
1335
+ );
1336
+ };
1337
+ var SelectMultiElement2 = ({
1338
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
1339
+ ...props
1340
+ }) => {
1341
+ if (gridProps) {
1342
+ return /* @__PURE__ */ jsx9(
1343
+ Grid29,
1344
+ {
1345
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
1346
+ children: /* @__PURE__ */ jsx9(Component9, { ...props })
1347
+ }
1348
+ );
1349
+ }
1350
+ return /* @__PURE__ */ jsx9(Component9, { ...props });
1351
+ };
1352
+ SelectMultiElement2.displayName = "SelectMultiElement";
1353
+ var SelectMultiElement_default = SelectMultiElement2;
1354
+
1355
+ // src/wrappers3/SelectCascadeElement/SelectCascadeElement.tsx
1356
+ import { useRef as useRef3, useState as useState4, useEffect as useEffect5, useCallback as useCallback5 } from "react";
1357
+ import {
1358
+ useController as useController10
1359
+ } from "react-hook-form";
1360
+ import {
1361
+ Grid2 as Grid210,
1362
+ useTheme as useTheme7,
1363
+ TextField as TextField7,
1364
+ Autocomplete as Autocomplete5
1365
+ } from "@mui/material";
1366
+ import { jsx as jsx10 } from "react/jsx-runtime";
1367
+ var Component10 = function SelectCascadeElement(props) {
1368
+ const {
1369
+ labelKey = "Label",
1370
+ valueKey = "Value",
1371
+ name,
1372
+ onBlur,
1373
+ onChange,
1374
+ disabled,
1375
+ options,
1376
+ control,
1377
+ loading = false,
1378
+ placeholder,
1379
+ label,
1380
+ dependsOn,
1381
+ initialValue,
1382
+ textFieldProps = {},
1383
+ variant,
1384
+ sx,
1385
+ isEdit = false,
1386
+ ...rest
1387
+ } = props;
1388
+ const { required } = textFieldProps;
1389
+ const getOptionKey = useCallback5(
1390
+ (option) => {
1391
+ if (typeof option === "string" || typeof option === "number")
1392
+ return option;
1393
+ const key = option ? option[valueKey] : void 0;
1394
+ if (key === void 0 || key === null) {
1395
+ return "";
1396
+ }
1397
+ if (typeof key === "string" || typeof key === "number") {
1398
+ return key;
1399
+ }
1400
+ return String(key);
1401
+ },
1402
+ [valueKey]
1403
+ );
1404
+ const getOptionLabel = useCallback5(
1405
+ (option) => {
1406
+ if (typeof option === "string") return option;
1407
+ return option ? String(option[labelKey]) : "";
1408
+ },
1409
+ [labelKey]
1410
+ );
1411
+ const isOptionEqualToValue = (option, value) => getOptionKey(option) === getOptionKey(value);
1412
+ const {
1413
+ field,
1414
+ fieldState: { error }
1415
+ } = useController10({
1416
+ name,
1417
+ control,
1418
+ defaultValue: initialValue
1419
+ });
1420
+ const theme = useTheme7();
1421
+ const { field: dependentField } = useController10({
1422
+ name: dependsOn,
1423
+ control
1424
+ });
1425
+ const parentValueRef = useRef3(dependentField.value ?? null);
1426
+ const [hasAutoSelected, setHasAutoSelected] = useState4(false);
1427
+ useEffect5(() => {
1428
+ if (parentValueRef.current !== dependentField.value) {
1429
+ parentValueRef.current = dependentField.value;
1430
+ field.onChange(null);
1431
+ setHasAutoSelected(false);
1432
+ }
1433
+ }, [dependentField.value, field]);
1434
+ useEffect5(() => {
1435
+ if (!dependentField.value) return;
1436
+ if (isEdit) {
1437
+ if (field.value) return;
1438
+ if (options.length === 1 && !hasAutoSelected) {
1439
+ field.onChange(getOptionKey(options[0]));
1440
+ setHasAutoSelected(true);
1441
+ }
1442
+ } else {
1443
+ if (options.length === 1 && !field.value && !hasAutoSelected) {
1444
+ field.onChange(getOptionKey(options[0]));
1445
+ setHasAutoSelected(true);
1446
+ }
1447
+ }
1448
+ }, [
1449
+ isEdit,
1450
+ options,
1451
+ field.value,
1452
+ dependentField.value,
1453
+ getOptionKey,
1454
+ hasAutoSelected,
1455
+ field
1456
+ ]);
1457
+ const autocompleteValue = options.find((opt) => getOptionKey(opt) === field.value) ?? null;
1458
+ return /* @__PURE__ */ jsx10(
1459
+ Autocomplete5,
1460
+ {
1461
+ ...rest,
1462
+ value: autocompleteValue,
1463
+ size: "small",
1464
+ loading,
1465
+ options,
1466
+ getOptionLabel,
1467
+ isOptionEqualToValue,
1468
+ ref: field.ref,
1469
+ disabled: !dependentField.value || disabled,
1470
+ onChange: (event, newValue, reason) => {
1471
+ field.onChange(newValue ? getOptionKey(newValue) : null);
1472
+ if (onChange && typeof onChange === "function") {
1473
+ onChange(event, newValue, reason);
1474
+ }
1475
+ },
1476
+ onBlur: (event) => {
1477
+ field.onBlur();
1478
+ if (typeof onBlur === "function") {
1479
+ onBlur(event);
1480
+ }
1481
+ },
1482
+ renderInput: (params) => /* @__PURE__ */ jsx10(
1483
+ TextField7,
1484
+ {
1485
+ ...params,
1486
+ fullWidth: true,
1487
+ error: !!error,
1488
+ required,
1489
+ helperText: error ? error.message : "",
1490
+ placeholder,
1491
+ label,
1492
+ variant: variant ?? "outlined",
1493
+ sx: {
1494
+ "& .MuiOutlinedInput-root": {
1495
+ bgcolor: disabled || !dependentField.value ? theme.palette.action.disabledBackground : "transparent"
1496
+ },
1497
+ "& .MuiInputLabel-asterisk": { color: "red" },
1498
+ "& .MuiInputBase-input": {
1499
+ cursor: disabled || !dependentField.value ? "not-allowed" : "default"
1500
+ },
1501
+ ...sx
1502
+ }
1503
+ }
1504
+ )
1505
+ }
1506
+ );
1507
+ };
1508
+ var SelectCascadeElement2 = ({
1509
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
1510
+ ...props
1511
+ }) => {
1512
+ if (gridProps) {
1513
+ return /* @__PURE__ */ jsx10(
1514
+ Grid210,
1515
+ {
1516
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
1517
+ children: /* @__PURE__ */ jsx10(Component10, { ...props })
1518
+ }
1519
+ );
1520
+ }
1521
+ return /* @__PURE__ */ jsx10(Component10, { ...props });
1522
+ };
1523
+ SelectCascadeElement2.displayName = "SelectCascadeElement";
1524
+ var SelectCascadeElement_default = SelectCascadeElement2;
1525
+
1526
+ // src/wrappers3/CheckboxElement/CheckboxElement.tsx
1527
+ import {
1528
+ Checkbox as Checkbox2,
1529
+ FormControl as FormControl2,
1530
+ FormControlLabel as FormControlLabel2,
1531
+ FormGroup,
1532
+ FormHelperText as FormHelperText2,
1533
+ Grid2 as Grid211
1534
+ } from "@mui/material";
1535
+ import {
1536
+ useController as useController11
1537
+ } from "react-hook-form";
1538
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
1539
+ var Component11 = function CheckboxElement(props) {
1540
+ const { name, control, label, labelProps, inputRef, ...rest } = props;
1541
+ const {
1542
+ field,
1543
+ fieldState: { error }
1544
+ } = useController11({
1545
+ name,
1546
+ control,
1547
+ disabled: rest.disabled
1548
+ });
1549
+ return /* @__PURE__ */ jsxs5(FormControl2, { error: !!error, children: [
1550
+ /* @__PURE__ */ jsx11(FormGroup, { row: true, children: /* @__PURE__ */ jsx11(
1551
+ FormControlLabel2,
1552
+ {
1553
+ label: label || "",
1554
+ ...labelProps,
1555
+ control: /* @__PURE__ */ jsx11(
1556
+ Checkbox2,
1557
+ {
1558
+ ...rest,
1559
+ color: rest.color || "primary",
1560
+ sx: [
1561
+ ...Array.isArray(rest.sx) ? rest.sx : [rest.sx],
1562
+ {
1563
+ color: error ? "error.main" : void 0
1564
+ }
1565
+ ],
1566
+ value: field.value,
1567
+ checked: !!field.value,
1568
+ onChange: (event, newValue) => {
1569
+ field.onChange(event, newValue);
1570
+ if (typeof rest.onChange === "function") {
1571
+ rest.onChange(event, newValue);
1572
+ }
1573
+ }
1574
+ }
1575
+ )
1576
+ }
1577
+ ) }),
1578
+ error && /* @__PURE__ */ jsx11(FormHelperText2, { error: !!error, children: error.message })
1579
+ ] });
1580
+ };
1581
+ var CheckboxElement2 = ({
1582
+ gridProps,
1583
+ ...props
1584
+ }) => {
1585
+ if (gridProps) {
1586
+ return /* @__PURE__ */ jsx11(Grid211, { ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps }, children: /* @__PURE__ */ jsx11(Component11, { ...props }) });
1587
+ }
1588
+ return /* @__PURE__ */ jsx11(Component11, { ...props });
1589
+ };
1590
+ CheckboxElement2.displayName = "CheckboxElement";
1591
+ var CheckboxElement_default = CheckboxElement2;
1592
+
1593
+ // src/wrappers3/CheckboxGroup/CheckboxGroup.tsx
1594
+ import {
1595
+ Checkbox as Checkbox3,
1596
+ FormControl as FormControl3,
1597
+ FormControlLabel as FormControlLabel3,
1598
+ FormGroup as FormGroup2,
1599
+ FormHelperText as FormHelperText3,
1600
+ Grid2 as Grid212
1601
+ } from "@mui/material";
1602
+ import { useEffect as useEffect6, useState as useState5 } from "react";
1603
+ import {
1604
+ useController as useController12
1605
+ } from "react-hook-form";
1606
+ import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
1607
+ var Component12 = function CheckboxGroup(props) {
1608
+ const { name, control, label, labelProps, inputRef, options, ...rest } = props;
1609
+ const {
1610
+ field,
1611
+ fieldState: { error }
1612
+ } = useController12({
1613
+ name,
1614
+ control,
1615
+ disabled: rest.disabled
1616
+ });
1617
+ const [selectedValues, setSelectedValues] = useState5(
1618
+ options.filter((c) => field.value?.includes(c.Value)).map((c) => c.Value) || []
1619
+ );
1620
+ useEffect6(() => {
1621
+ field.onChange(selectedValues ? [...selectedValues] : []);
1622
+ }, [selectedValues]);
1623
+ const handleChange = (event) => {
1624
+ const value = parseInt(event.target.value, 10);
1625
+ if (event.target.checked) {
1626
+ setSelectedValues([...selectedValues, value]);
1627
+ } else {
1628
+ setSelectedValues(selectedValues.filter((item) => item !== value));
1629
+ }
1630
+ };
1631
+ return /* @__PURE__ */ jsxs6(FormControl3, { error: !!error, children: [
1632
+ /* @__PURE__ */ jsx12(FormGroup2, { row: true, children: options.map((option) => /* @__PURE__ */ jsx12(
1633
+ FormControlLabel3,
1634
+ {
1635
+ label: option.Label,
1636
+ ...labelProps,
1637
+ control: /* @__PURE__ */ jsx12(
1638
+ Checkbox3,
1639
+ {
1640
+ ...rest,
1641
+ color: rest.color || "primary",
1642
+ sx: [
1643
+ ...Array.isArray(rest.sx) ? rest.sx : [rest.sx],
1644
+ {
1645
+ color: error ? "error.main" : void 0
1646
+ }
1647
+ ],
1648
+ value: option.Value,
1649
+ checked: selectedValues.includes(option.Value),
1650
+ onChange: handleChange
1651
+ }
1652
+ )
1653
+ },
1654
+ `${option.Value}`
1655
+ )) }),
1656
+ error && /* @__PURE__ */ jsx12(FormHelperText3, { error: !!error, children: error.message })
1657
+ ] });
1658
+ };
1659
+ var CheckboxGroup2 = ({
1660
+ gridProps,
1661
+ ...props
1662
+ }) => {
1663
+ if (gridProps) {
1664
+ return /* @__PURE__ */ jsx12(Grid212, { ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps }, children: /* @__PURE__ */ jsx12(Component12, { ...props }) });
1665
+ }
1666
+ return /* @__PURE__ */ jsx12(Component12, { ...props });
1667
+ };
1668
+ CheckboxGroup2.displayName = "CheckboxGroup";
1669
+ var CheckboxGroup_default = CheckboxGroup2;
1670
+
1671
+ // src/wrappers3/SelectMultiCascadeElement/SelectMultiCascadeElement.tsx
1672
+ import { useController as useController13 } from "react-hook-form";
1673
+ import { useRef as useRef4, Fragment as Fragment4, useState as useState6, useEffect as useEffect7, useCallback as useCallback6 } from "react";
1674
+ import CheckBoxIcon2 from "@mui/icons-material/CheckBox";
1675
+ import CheckBoxOutlineBlankIcon2 from "@mui/icons-material/CheckBoxOutlineBlank";
1676
+ import {
1677
+ Chip as Chip2,
1678
+ Grid2 as Grid213,
1679
+ Checkbox as Checkbox4,
1680
+ TextField as TextField8,
1681
+ Autocomplete as Autocomplete6,
1682
+ CircularProgress as CircularProgress4
1683
+ } from "@mui/material";
1684
+ import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
1685
+ var Component13 = function SelectMultiCascadeElement(props) {
1686
+ const {
1687
+ name,
1688
+ control,
1689
+ dependsOn,
1690
+ onBlur,
1691
+ disabled,
1692
+ options,
1693
+ loading = false,
1694
+ placeholder,
1695
+ label,
1696
+ variant,
1697
+ sx,
1698
+ labelKey = "Label",
1699
+ valueKey = "Value",
1700
+ multiple = true,
1701
+ isEdit = false,
1702
+ initialValue,
1703
+ ...rest
1704
+ } = props;
1705
+ const {
1706
+ field,
1707
+ fieldState: { error }
1708
+ } = useController13({
1709
+ name,
1710
+ control,
1711
+ defaultValue: initialValue
1712
+ });
1713
+ const { field: dependentField } = useController13({
1714
+ name: dependsOn,
1715
+ control
1716
+ });
1717
+ const parentValueRef = useRef4(dependentField.value ?? null);
1718
+ const [hasAutoSelected, setHasAutoSelected] = useState6(false);
1719
+ const getOptionValue = useCallback6(
1720
+ (option) => {
1721
+ if (typeof option === "string") return option;
1722
+ return option ? option[valueKey] : null;
1723
+ },
1724
+ [valueKey]
1725
+ );
1726
+ const getOptionLabel = useCallback6(
1727
+ (option) => {
1728
+ if (typeof option === "string") return option;
1729
+ return option ? option[labelKey] : "";
1730
+ },
1731
+ [labelKey]
1732
+ );
1733
+ useEffect7(() => {
1734
+ if (parentValueRef.current !== dependentField.value) {
1735
+ parentValueRef.current = dependentField.value;
1736
+ field.onChange(multiple ? [] : null);
1737
+ setHasAutoSelected(false);
1738
+ }
1739
+ }, [dependentField.value, field, multiple]);
1740
+ useEffect7(() => {
1741
+ if (!dependentField.value) return;
1742
+ if (isEdit) {
1743
+ if (field.value && (multiple ? field.value.length > 0 : field.value))
1744
+ return;
1745
+ if (options.length === 1 && !hasAutoSelected) {
1746
+ field.onChange(
1747
+ multiple ? [getOptionValue(options[0])] : getOptionValue(options[0])
1748
+ );
1749
+ setHasAutoSelected(true);
1750
+ }
1751
+ } else {
1752
+ if (options.length === 1 && (!field.value || field.value.length === 0) && !hasAutoSelected) {
1753
+ field.onChange(
1754
+ multiple ? [getOptionValue(options[0])] : getOptionValue(options[0])
1755
+ );
1756
+ setHasAutoSelected(true);
1757
+ }
1758
+ }
1759
+ }, [
1760
+ isEdit,
1761
+ options,
1762
+ field.value,
1763
+ dependentField.value,
1764
+ multiple,
1765
+ getOptionValue,
1766
+ hasAutoSelected,
1767
+ field
1768
+ ]);
1769
+ const selectedValue = multiple ? Array.isArray(field.value) ? options.filter((opt) => field.value.includes(getOptionValue(opt))) : [] : options.find((opt) => getOptionValue(opt) === field.value) ?? null;
1770
+ const handleChange = (_2, selected, reason) => {
1771
+ if (multiple) {
1772
+ if (reason === "clear") {
1773
+ field.onChange([]);
1774
+ } else {
1775
+ const newValues = selected.map((opt) => getOptionValue(opt));
1776
+ field.onChange(newValues);
1777
+ }
1778
+ } else {
1779
+ field.onChange(selected ? getOptionValue(selected) : null);
1780
+ }
1781
+ };
1782
+ const icon = /* @__PURE__ */ jsx13(CheckBoxOutlineBlankIcon2, { fontSize: "small" });
1783
+ const checkedIcon = /* @__PURE__ */ jsx13(CheckBoxIcon2, { fontSize: "small" });
1784
+ return /* @__PURE__ */ jsx13(
1785
+ Autocomplete6,
1786
+ {
1787
+ multiple,
1788
+ value: selectedValue,
1789
+ loading,
1790
+ options,
1791
+ getOptionLabel,
1792
+ isOptionEqualToValue: (option, value) => getOptionValue(option) === getOptionValue(value),
1793
+ filterSelectedOptions: multiple,
1794
+ disableCloseOnSelect: multiple,
1795
+ ref: field.ref,
1796
+ disabled: !dependentField.value || disabled,
1797
+ onChange: handleChange,
1798
+ onBlur: (event) => {
1799
+ field.onBlur();
1800
+ if (typeof onBlur === "function") {
1801
+ onBlur(event);
1802
+ }
1803
+ },
1804
+ fullWidth: true,
1805
+ renderOption: (props1, option, { selected }) => multiple ? /* @__PURE__ */ jsxs7("li", { ...props1, children: [
1806
+ /* @__PURE__ */ jsx13(
1807
+ Checkbox4,
1808
+ {
1809
+ icon,
1810
+ checkedIcon,
1811
+ checked: selected
1812
+ }
1813
+ ),
1814
+ getOptionLabel(option)
1815
+ ] }) : /* @__PURE__ */ jsx13("li", { ...props1, children: getOptionLabel(option) }),
1816
+ renderTags: (tagValue, getTagProps) => tagValue.map((option, index) => /* @__PURE__ */ jsx13(
1817
+ Chip2,
1818
+ {
1819
+ ...getTagProps({ index }),
1820
+ label: getOptionLabel(option),
1821
+ size: "small",
1822
+ variant: "filled"
1823
+ }
1824
+ )),
1825
+ renderInput: (params) => /* @__PURE__ */ jsx13(
1826
+ TextField8,
1827
+ {
1828
+ ...params,
1829
+ label,
1830
+ error: !!error,
1831
+ helperText: error ? error.message : "",
1832
+ placeholder,
1833
+ slotProps: {
1834
+ input: {
1835
+ ...params.InputProps,
1836
+ endAdornment: /* @__PURE__ */ jsxs7(Fragment4, { children: [
1837
+ loading ? /* @__PURE__ */ jsx13(CircularProgress4, { color: "inherit", size: 20 }) : null,
1838
+ params.InputProps.endAdornment
1839
+ ] })
1840
+ }
1841
+ },
1842
+ variant: variant ? variant : "outlined",
1843
+ sx: {
1844
+ ...sx
1845
+ }
1846
+ }
1847
+ ),
1848
+ ...rest
1849
+ }
1850
+ );
1851
+ };
1852
+ var SelectMultiCascadeElement2 = ({
1853
+ gridProps = { size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 } },
1854
+ ...props
1855
+ }) => {
1856
+ if (gridProps) {
1857
+ return /* @__PURE__ */ jsx13(
1858
+ Grid213,
1859
+ {
1860
+ ...{ size: { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }, ...gridProps },
1861
+ children: /* @__PURE__ */ jsx13(Component13, { ...props })
1862
+ }
1863
+ );
1864
+ }
1865
+ return /* @__PURE__ */ jsx13(Component13, { ...props });
1866
+ };
1867
+ SelectMultiCascadeElement2.displayName = "SelectMultiCascadeElement";
1868
+ var SelectMultiCascadeElement_default = SelectMultiCascadeElement2;
1869
+
1870
+ // src/wrappers3/Field/index.ts
1871
+ var Field3 = {
1872
+ Text: TextFieldElement_default,
1873
+ Checkbox: CheckboxElement_default,
1874
+ Date: DatePickerElement_default,
1875
+ RadioGroup: RadioButtonGroup_default,
1876
+ Password: PasswordElement_default,
1877
+ Time: TimePickerElement_default,
1878
+ Select: SelectElement_default,
1879
+ SelectMulti: SelectMultiElement_default,
1880
+ SelectCascade: SelectCascadeElement_default,
1881
+ AsyncSelect: AsyncSelectElement_default,
1882
+ AsyncMultiSelect: AsyncMultiSelect_default,
1883
+ CheckboxGroup: CheckboxGroup_default,
1884
+ SelectMultiCascadeElement: SelectMultiCascadeElement_default
1885
+ };
1886
+ var Field_default = Field3;
1887
+
1888
+ export {
1889
+ Field_default
1890
+ };