@gnwebsoft/ui 2.17.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.
@@ -0,0 +1,1288 @@
1
+ import {
2
+ useTransform
3
+ } from "./chunk-GFSTK7KN.mjs";
4
+ import {
5
+ readValueAsDate
6
+ } from "./chunk-D3X5GWIG.mjs";
7
+
8
+ // src/wrappers/DatePickerElement/DatePickerElement.tsx
9
+ import {
10
+ useController
11
+ } from "react-hook-form";
12
+ import { Grid2, useForkRef } from "@mui/material";
13
+ import {
14
+ DatePicker
15
+ } from "@mui/x-date-pickers";
16
+ import { useLocalizationContext } from "@mui/x-date-pickers/internals";
17
+ import { jsx } from "react/jsx-runtime";
18
+ var Component = function DatePickerElement(props) {
19
+ const {
20
+ parseError,
21
+ name,
22
+ required,
23
+ rules = {},
24
+ inputProps,
25
+ control,
26
+ textReadOnly,
27
+ gridProps,
28
+ slotProps,
29
+ transform,
30
+ datePickerProps = {},
31
+ ...rest
32
+ } = props;
33
+ const adapter = useLocalizationContext();
34
+ const { disabled, inputRef, onClose } = datePickerProps;
35
+ const {
36
+ field,
37
+ fieldState: { error }
38
+ } = useController({
39
+ name,
40
+ control,
41
+ disabled,
42
+ defaultValue: null
43
+ });
44
+ const { value, onChange } = useTransform({
45
+ value: field.value,
46
+ onChange: field.onChange,
47
+ transform: {
48
+ input: typeof transform?.input === "function" ? transform.input : (newValue) => readValueAsDate(adapter, newValue),
49
+ output: typeof transform?.output === "function" ? transform.output : (newValue) => newValue
50
+ }
51
+ });
52
+ const handleInputRef = useForkRef(field.ref, inputRef);
53
+ return /* @__PURE__ */ jsx(
54
+ DatePicker,
55
+ {
56
+ ...rest,
57
+ ...field,
58
+ value,
59
+ inputRef: handleInputRef,
60
+ onClose: (...args) => {
61
+ field.onBlur();
62
+ if (onClose) {
63
+ onClose(...args);
64
+ }
65
+ },
66
+ onChange: (newValue, context) => {
67
+ onChange(newValue, context);
68
+ if (typeof datePickerProps.onChange === "function") {
69
+ datePickerProps.onChange(newValue, context);
70
+ }
71
+ },
72
+ slotProps: {
73
+ ...slotProps,
74
+ textField: {
75
+ ...inputProps,
76
+ required,
77
+ fullWidth: true,
78
+ onBlur: (event) => {
79
+ field.onBlur();
80
+ if (typeof inputProps?.onBlur === "function") {
81
+ inputProps.onBlur(event);
82
+ }
83
+ },
84
+ error: !!error,
85
+ helperText: error ? error.message : inputProps?.helperText || rest.helperText,
86
+ inputProps: {
87
+ readOnly: !!textReadOnly,
88
+ ...inputProps?.inputProps
89
+ }
90
+ }
91
+ }
92
+ }
93
+ );
94
+ };
95
+ var DatePickerElement2 = ({
96
+ gridProps,
97
+ ...props
98
+ }) => {
99
+ if (gridProps) {
100
+ return /* @__PURE__ */ jsx(Grid2, { ...gridProps, children: /* @__PURE__ */ jsx(Component, { ...props }) });
101
+ }
102
+ return /* @__PURE__ */ jsx(Component, { ...props });
103
+ };
104
+ DatePickerElement2.displayName = "DatePickerElement";
105
+ var DatePickerElement_default = DatePickerElement2;
106
+
107
+ // src/wrappers/PasswordElement/PasswordElement.tsx
108
+ import { useState } from "react";
109
+ import {
110
+ IconButton,
111
+ InputAdornment,
112
+ TextField,
113
+ useForkRef as useForkRef2,
114
+ Grid2 as Grid22
115
+ } from "@mui/material";
116
+ import Visibility from "@mui/icons-material/Visibility";
117
+ import VisibilityOff from "@mui/icons-material/VisibilityOff";
118
+ import {
119
+ useController as useController2
120
+ } from "react-hook-form";
121
+ import { jsx as jsx2 } from "react/jsx-runtime";
122
+ var Component2 = function PasswordEl(props) {
123
+ const {
124
+ type,
125
+ required,
126
+ iconColor,
127
+ renderIcon = (password2) => password2 ? /* @__PURE__ */ jsx2(Visibility, {}) : /* @__PURE__ */ jsx2(VisibilityOff, {}),
128
+ slotProps,
129
+ name,
130
+ control,
131
+ component: TextFieldComponent = TextField,
132
+ inputRef,
133
+ onBlur,
134
+ ...rest
135
+ } = props;
136
+ const [password, setPassword] = useState(true);
137
+ const endAdornment = /* @__PURE__ */ jsx2(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx2(
138
+ IconButton,
139
+ {
140
+ onMouseDown: (e) => e.preventDefault(),
141
+ onClick: () => setPassword(!password),
142
+ tabIndex: -1,
143
+ color: iconColor ?? "default",
144
+ children: renderIcon(password)
145
+ }
146
+ ) });
147
+ const {
148
+ field,
149
+ fieldState: { error }
150
+ } = useController2({
151
+ name,
152
+ control
153
+ });
154
+ const handleInputRef = useForkRef2(field.ref, inputRef);
155
+ return /* @__PURE__ */ jsx2(
156
+ TextField,
157
+ {
158
+ ...rest,
159
+ inputRef: handleInputRef,
160
+ type: password ? "password" : "text",
161
+ value: field.value,
162
+ fullWidth: true,
163
+ onChange: (event) => {
164
+ field.onChange(event);
165
+ if (typeof rest.onChange === "function") {
166
+ rest.onChange(event);
167
+ }
168
+ },
169
+ onBlur: (event) => {
170
+ field.onBlur();
171
+ if (typeof onBlur === "function") {
172
+ onBlur(event);
173
+ }
174
+ },
175
+ ...typeof slotProps === "undefined" ? {
176
+ InputProps: {
177
+ endAdornment
178
+ }
179
+ } : {
180
+ slotProps: {
181
+ ...slotProps,
182
+ input: {
183
+ endAdornment,
184
+ ...slotProps?.input
185
+ }
186
+ }
187
+ },
188
+ error: !!error,
189
+ helperText: error ? error.message : ""
190
+ }
191
+ );
192
+ };
193
+ var PasswordElement = ({
194
+ gridProps,
195
+ ...props
196
+ }) => {
197
+ if (gridProps) {
198
+ return /* @__PURE__ */ jsx2(Grid22, { ...gridProps, children: /* @__PURE__ */ jsx2(Component2, { ...props }) });
199
+ }
200
+ return /* @__PURE__ */ jsx2(Component2, { ...props });
201
+ };
202
+ PasswordElement.displayName = "PasswordElement";
203
+ var PasswordElement_default = PasswordElement;
204
+
205
+ // src/wrappers/RadioButtonGroup/RadioButtonGroup.tsx
206
+ import {
207
+ useController as useController3
208
+ } from "react-hook-form";
209
+ import {
210
+ FormControl,
211
+ FormControlLabel,
212
+ FormHelperText,
213
+ FormLabel,
214
+ Radio,
215
+ RadioGroup,
216
+ useTheme,
217
+ Grid2 as Grid23
218
+ } from "@mui/material";
219
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
220
+ import { createElement } from "react";
221
+ var Component3 = function RadioButtonGroup(props) {
222
+ const {
223
+ helperText,
224
+ options,
225
+ label,
226
+ name,
227
+ parseError,
228
+ labelKey = "label",
229
+ valueKey = "id",
230
+ disabledKey = "disabled",
231
+ required,
232
+ emptyOptionLabel,
233
+ returnObject,
234
+ row,
235
+ control,
236
+ type,
237
+ labelProps,
238
+ disabled,
239
+ formLabelProps,
240
+ radioProps,
241
+ transform,
242
+ rules = {},
243
+ ...rest
244
+ } = props;
245
+ const theme = useTheme();
246
+ const {
247
+ field,
248
+ fieldState: { error }
249
+ } = useController3({
250
+ name,
251
+ disabled,
252
+ control
253
+ });
254
+ const { value, onChange } = useTransform({
255
+ value: field.value,
256
+ onChange: field.onChange,
257
+ transform: {
258
+ input: typeof transform?.input === "function" ? transform.input : (value2) => {
259
+ return value2 || "";
260
+ },
261
+ output: typeof transform?.output === "function" ? transform?.output : (_event, value2) => {
262
+ if (value2 && type === "number") {
263
+ return Number(value2);
264
+ }
265
+ return value2;
266
+ }
267
+ }
268
+ });
269
+ const onRadioChange = (event, radioValue) => {
270
+ const returnValue = returnObject ? options.find((items) => items[valueKey] === radioValue) : radioValue;
271
+ onChange(event, returnValue);
272
+ if (typeof rest.onChange === "function") {
273
+ rest.onChange(returnValue);
274
+ }
275
+ };
276
+ return /* @__PURE__ */ jsxs(FormControl, { error: !!error, children: [
277
+ label && /* @__PURE__ */ jsx3(FormLabel, { ...formLabelProps, required, error: !!error, children: label }),
278
+ /* @__PURE__ */ jsxs(RadioGroup, { onChange: onRadioChange, name, row, value, children: [
279
+ emptyOptionLabel && /* @__PURE__ */ jsx3(
280
+ FormControlLabel,
281
+ {
282
+ ...labelProps,
283
+ control: /* @__PURE__ */ jsx3(
284
+ Radio,
285
+ {
286
+ ...radioProps,
287
+ sx: {
288
+ color: error ? theme.palette.error.main : void 0
289
+ },
290
+ checked: !value
291
+ }
292
+ ),
293
+ label: emptyOptionLabel,
294
+ value: ""
295
+ }
296
+ ),
297
+ options.map((option) => {
298
+ const optionKey = option[valueKey];
299
+ const optionDisabled = option[disabledKey] || false;
300
+ if (optionKey === void 0) {
301
+ console.error(
302
+ `RadioButtonGroup: valueKey ${valueKey} does not exist on option`,
303
+ option
304
+ );
305
+ }
306
+ let val = returnObject ? value?.[valueKey] : value;
307
+ if (type === "number") {
308
+ val = Number(val);
309
+ }
310
+ const isChecked = val === optionKey;
311
+ return /* @__PURE__ */ createElement(
312
+ FormControlLabel,
313
+ {
314
+ ...labelProps,
315
+ control: /* @__PURE__ */ jsx3(
316
+ Radio,
317
+ {
318
+ ...radioProps,
319
+ sx: {
320
+ color: error ? theme.palette.error.main : void 0
321
+ },
322
+ disabled: disabled || optionDisabled,
323
+ checked: isChecked
324
+ }
325
+ ),
326
+ value: optionKey,
327
+ label: option[labelKey],
328
+ key: optionKey
329
+ }
330
+ );
331
+ })
332
+ ] }),
333
+ error && /* @__PURE__ */ jsx3(FormHelperText, { children: error.message })
334
+ ] });
335
+ };
336
+ var RadioButtonGroup2 = ({
337
+ gridProps,
338
+ ...props
339
+ }) => {
340
+ if (gridProps) {
341
+ return /* @__PURE__ */ jsx3(Grid23, { ...gridProps, children: /* @__PURE__ */ jsx3(Component3, { ...props }) });
342
+ }
343
+ return /* @__PURE__ */ jsx3(Component3, { ...props });
344
+ };
345
+ RadioButtonGroup2.displayName = "RadioButtonGroup";
346
+ var RadioButtonGroup_default = RadioButtonGroup2;
347
+
348
+ // src/wrappers/TextFieldElement/TextFieldElement.tsx
349
+ import {
350
+ Grid2 as Grid24,
351
+ TextField as TextField2,
352
+ useForkRef as useForkRef3
353
+ } from "@mui/material";
354
+ import {
355
+ useController as useController4
356
+ } from "react-hook-form";
357
+ import { jsx as jsx4 } from "react/jsx-runtime";
358
+ var Component4 = function TextFieldElement(props) {
359
+ const {
360
+ rules = {},
361
+ parseError,
362
+ name,
363
+ control,
364
+ component: TextFieldComponent = TextField2,
365
+ gridProps,
366
+ transform,
367
+ textFieldProps = {},
368
+ ...rest
369
+ } = props;
370
+ const { type, required, helperText, inputRef, onBlur, disabled } = textFieldProps;
371
+ const {
372
+ field,
373
+ fieldState: { error }
374
+ } = useController4({
375
+ name,
376
+ control,
377
+ disabled
378
+ });
379
+ const { value, onChange } = useTransform({
380
+ value: field.value,
381
+ onChange: field.onChange,
382
+ transform: {
383
+ input: typeof transform?.input === "function" ? transform.input : (value2) => {
384
+ return value2 ?? "";
385
+ },
386
+ output: typeof transform?.output === "function" ? transform.output : (event) => {
387
+ const value2 = event.target.value;
388
+ if (type !== "number") {
389
+ return value2;
390
+ }
391
+ if (value2 === "") {
392
+ return null;
393
+ }
394
+ if (value2 == null) {
395
+ return value2;
396
+ }
397
+ return Number(value2);
398
+ }
399
+ }
400
+ });
401
+ const handleInputRef = useForkRef3(field.ref, inputRef);
402
+ return /* @__PURE__ */ jsx4(
403
+ TextFieldComponent,
404
+ {
405
+ ...rest,
406
+ name: field.name,
407
+ value,
408
+ onChange: (event) => {
409
+ field.onChange(event);
410
+ if (typeof onChange === "function") {
411
+ onChange(event);
412
+ }
413
+ },
414
+ onBlur: (event) => {
415
+ field.onBlur();
416
+ if (typeof onBlur === "function") {
417
+ onBlur(event);
418
+ }
419
+ },
420
+ fullWidth: true,
421
+ required,
422
+ type,
423
+ error: !!error,
424
+ helperText: error ? error.message : helperText,
425
+ inputRef: handleInputRef
426
+ }
427
+ );
428
+ };
429
+ var TextFieldElement2 = ({
430
+ gridProps,
431
+ ...props
432
+ }) => {
433
+ if (gridProps) {
434
+ return /* @__PURE__ */ jsx4(Grid24, { ...gridProps, children: /* @__PURE__ */ jsx4(Component4, { ...props }) });
435
+ }
436
+ return /* @__PURE__ */ jsx4(Component4, { ...props });
437
+ };
438
+ TextFieldElement2.displayName = "TextFieldElement";
439
+ var TextFieldElement_default = TextFieldElement2;
440
+
441
+ // src/wrappers/TimePickerElement/TimePickerElement.tsx
442
+ import {
443
+ TimePicker
444
+ } from "@mui/x-date-pickers";
445
+ import {
446
+ useController as useController5
447
+ } from "react-hook-form";
448
+ import { useForkRef as useForkRef4, Grid2 as Grid25 } from "@mui/material";
449
+ import { useLocalizationContext as useLocalizationContext2 } from "@mui/x-date-pickers/internals";
450
+ import { jsx as jsx5 } from "react/jsx-runtime";
451
+ var Component5 = function TimePickerElement(props) {
452
+ const {
453
+ parseError,
454
+ name,
455
+ required,
456
+ rules = {},
457
+ inputProps,
458
+ control,
459
+ textReadOnly,
460
+ slotProps,
461
+ inputRef,
462
+ transform,
463
+ ...rest
464
+ } = props;
465
+ const adapter = useLocalizationContext2();
466
+ const {
467
+ field,
468
+ fieldState: { error }
469
+ } = useController5({
470
+ name,
471
+ control,
472
+ disabled: rest.disabled,
473
+ defaultValue: null
474
+ });
475
+ const { value, onChange } = useTransform({
476
+ value: field.value,
477
+ onChange: field.onChange,
478
+ transform: {
479
+ input: typeof transform?.input === "function" ? transform.input : (newValue) => readValueAsDate(adapter, newValue),
480
+ output: typeof transform?.output === "function" ? transform.output : (newValue) => newValue
481
+ }
482
+ });
483
+ const handleInputRef = useForkRef4(field.ref, inputRef);
484
+ return /* @__PURE__ */ jsx5(
485
+ TimePicker,
486
+ {
487
+ ...rest,
488
+ ...field,
489
+ value,
490
+ inputRef: handleInputRef,
491
+ onClose: (...args) => {
492
+ field.onBlur();
493
+ if (rest.onClose) {
494
+ rest.onClose(...args);
495
+ }
496
+ },
497
+ onChange: (value2, context) => {
498
+ onChange(value2, context);
499
+ if (typeof rest.onChange === "function") {
500
+ rest.onChange(value2, context);
501
+ }
502
+ },
503
+ slotProps: {
504
+ ...slotProps,
505
+ textField: {
506
+ ...inputProps,
507
+ required,
508
+ fullWidth: true,
509
+ error: !!error,
510
+ helperText: error ? error.message : inputProps?.helperText || rest.helperText,
511
+ inputProps: {
512
+ readOnly: textReadOnly,
513
+ ...inputProps?.inputProps
514
+ }
515
+ }
516
+ }
517
+ }
518
+ );
519
+ };
520
+ var TimePickerElement2 = ({
521
+ gridProps,
522
+ ...props
523
+ }) => {
524
+ if (gridProps) {
525
+ return /* @__PURE__ */ jsx5(Grid25, { ...gridProps, children: /* @__PURE__ */ jsx5(Component5, { ...props }) });
526
+ }
527
+ return /* @__PURE__ */ jsx5(Component5, { ...props });
528
+ };
529
+ TimePickerElement2.displayName = "TimePickerElement";
530
+ var TimePickerElement_default = TimePickerElement2;
531
+
532
+ // src/wrappers/AsyncSelect/AsyncSelect.tsx
533
+ import * as React from "react";
534
+ import TextField3 from "@mui/material/TextField";
535
+ import Autocomplete from "@mui/material/Autocomplete";
536
+ import { debounce } from "@mui/material/utils";
537
+ import {
538
+ Fragment,
539
+ useCallback,
540
+ useEffect as useEffect2,
541
+ useMemo,
542
+ useRef,
543
+ useState as useState2
544
+ } from "react";
545
+ import { useController as useController6 } from "react-hook-form";
546
+ import { CircularProgress, Grid2 as Grid26 } from "@mui/material";
547
+ import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
548
+ var Component6 = function AsyncSelectElement(props) {
549
+ const {
550
+ name,
551
+ onBlur,
552
+ disabled,
553
+ control,
554
+ gridProps,
555
+ placeholder,
556
+ initialValue,
557
+ label,
558
+ queryFn,
559
+ ...rest
560
+ } = props;
561
+ const {
562
+ field,
563
+ fieldState: { error }
564
+ } = useController6({
565
+ name,
566
+ control,
567
+ disabled
568
+ });
569
+ const [loading, setLoading] = useState2(false);
570
+ const [selectedOption, setSelectedOption] = useState2(null);
571
+ const [inputValue, setInputValue] = useState2("");
572
+ const inputValue2 = useMemo(() => inputValue, [inputValue]);
573
+ const setInputValue2 = useCallback(
574
+ (inputValue3) => setInputValue(inputValue3),
575
+ []
576
+ );
577
+ const [options, setOptions] = useState2([]);
578
+ const initialValueLoaded = useRef(
579
+ !initialValue ? true : !(initialValue != null && initialValue > 0)
580
+ );
581
+ const fieldValue = useRef(field.value);
582
+ console.log(initialValue, field.value);
583
+ const fetchData = useMemo(
584
+ () => debounce(
585
+ (payload, callback) => {
586
+ queryFn(payload).then((c) => callback(c));
587
+ },
588
+ 400
589
+ ),
590
+ []
591
+ );
592
+ const fillOptions = (results) => {
593
+ let newOptions = [];
594
+ if (selectedOption) {
595
+ newOptions = [selectedOption];
596
+ }
597
+ if (results) {
598
+ newOptions = [...newOptions, ...results];
599
+ }
600
+ setOptions(newOptions);
601
+ setLoading(false);
602
+ };
603
+ useEffect2(() => {
604
+ if (initialValueLoaded.current) return void 0;
605
+ let active = true;
606
+ const payload = {
607
+ query: null,
608
+ initialValue
609
+ };
610
+ setLoading(true);
611
+ fetchData(payload, (results) => {
612
+ if (active) {
613
+ if (!!results && results.length > 0) {
614
+ fillOptions(results?.filter((c) => c.value == initialValue));
615
+ setSelectedOption(results[0]);
616
+ field.onChange(results[0].value);
617
+ fieldValue.current = results[0].value;
618
+ }
619
+ initialValueLoaded.current = true;
620
+ setLoading(false);
621
+ }
622
+ });
623
+ return () => {
624
+ active = false;
625
+ };
626
+ }, [initialValue]);
627
+ React.useEffect(() => {
628
+ let active = true;
629
+ if (inputValue2 === "" || initialValueLoaded.current === false) {
630
+ setOptions(selectedOption ? [selectedOption] : []);
631
+ return void 0;
632
+ }
633
+ if (!!fieldValue.current) {
634
+ if (field.value === fieldValue.current) {
635
+ return void 0;
636
+ }
637
+ }
638
+ setLoading(true);
639
+ const payload = {
640
+ query: inputValue2,
641
+ initialValue: null
642
+ };
643
+ fetchData(payload, (results) => {
644
+ if (active) {
645
+ fillOptions(results);
646
+ }
647
+ });
648
+ return () => {
649
+ active = false;
650
+ };
651
+ }, [initialValue, inputValue2, fetchData]);
652
+ const selectRef = useRef(null);
653
+ const handleChange = (_2, selectedOption2, reason) => {
654
+ if (reason === "clear") {
655
+ setSelectedOption(null);
656
+ field.onChange(null);
657
+ } else if (reason === "selectOption" || reason === "removeOption") {
658
+ if (selectedOption2) {
659
+ setSelectedOption(selectedOption2);
660
+ field.onChange(selectedOption2.value);
661
+ fieldValue.current = selectedOption2.value;
662
+ }
663
+ }
664
+ setOptions([]);
665
+ };
666
+ return /* @__PURE__ */ jsx6(
667
+ Autocomplete,
668
+ {
669
+ ...rest,
670
+ ref: selectRef,
671
+ fullWidth: true,
672
+ loading,
673
+ getOptionLabel: (option) => option.label,
674
+ getOptionKey: (option) => option.value,
675
+ isOptionEqualToValue: (option, val) => option.value === val.value,
676
+ autoComplete: true,
677
+ includeInputInList: true,
678
+ options,
679
+ value: selectedOption,
680
+ filterSelectedOptions: true,
681
+ onChange: handleChange,
682
+ onInputChange: (_2, newInputValue) => {
683
+ setInputValue2(newInputValue);
684
+ },
685
+ renderInput: (params) => /* @__PURE__ */ jsx6(
686
+ TextField3,
687
+ {
688
+ ...params,
689
+ label,
690
+ error: !!error,
691
+ helperText: error ? error.message : "",
692
+ placeholder,
693
+ slotProps: {
694
+ input: {
695
+ ...params.InputProps,
696
+ endAdornment: /* @__PURE__ */ jsxs2(Fragment, { children: [
697
+ loading ? /* @__PURE__ */ jsx6(CircularProgress, { color: "inherit", size: 20 }) : null,
698
+ params.InputProps.endAdornment
699
+ ] })
700
+ }
701
+ }
702
+ }
703
+ ),
704
+ renderOption: (props2, option) => {
705
+ const { key, ...optionProps } = props2;
706
+ return /* @__PURE__ */ jsx6("li", { ...optionProps, children: option.label }, key);
707
+ }
708
+ }
709
+ );
710
+ };
711
+ var AsyncSelectElement2 = ({
712
+ gridProps,
713
+ ...props
714
+ }) => {
715
+ if (gridProps) {
716
+ return /* @__PURE__ */ jsx6(Grid26, { ...gridProps, children: /* @__PURE__ */ jsx6(Component6, { ...props }) });
717
+ }
718
+ return /* @__PURE__ */ jsx6(Component6, { ...props });
719
+ };
720
+ AsyncSelectElement2.displayName = "AsyncSelectElement";
721
+ var AsyncSelect_default = AsyncSelectElement2;
722
+
723
+ // src/wrappers/AsyncMultiSelect/AsyncMultiSelect.tsx
724
+ import _ from "lodash";
725
+ import {
726
+ useState as useState3,
727
+ useRef as useRef2,
728
+ useMemo as useMemo2,
729
+ useEffect as useEffect3,
730
+ useCallback as useCallback2,
731
+ Fragment as Fragment2
732
+ } from "react";
733
+ import { debounce as debounce2 } from "lodash";
734
+ import {
735
+ Autocomplete as Autocomplete2,
736
+ CircularProgress as CircularProgress2,
737
+ Grid2 as Grid27,
738
+ TextField as TextField4
739
+ } from "@mui/material";
740
+ import {
741
+ useController as useController7
742
+ } from "react-hook-form";
743
+ import match from "autosuggest-highlight/match";
744
+ import parse from "autosuggest-highlight/parse";
745
+ import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
746
+ var Component7 = function AsyncSelectMultiElement(props) {
747
+ const {
748
+ name,
749
+ onBlur,
750
+ disabled,
751
+ control,
752
+ gridProps,
753
+ placeholder,
754
+ initialValues,
755
+ label,
756
+ queryFn,
757
+ ...rest
758
+ } = props;
759
+ const {
760
+ field,
761
+ fieldState: { error }
762
+ } = useController7({
763
+ name,
764
+ control,
765
+ disabled
766
+ });
767
+ const multiSelectRef = useRef2(null);
768
+ const [selectedOptions, setSelectedOptions] = useState3([]);
769
+ const [inputValue, setInputValue] = useState3("");
770
+ const [options, setOptions] = useState3([]);
771
+ const [loading, setLoading] = useState3(false);
772
+ const initialValuesLoaded = useRef2(
773
+ !(initialValues && initialValues.length > 0)
774
+ );
775
+ const inputValue2 = useMemo2(() => inputValue, [inputValue]);
776
+ const setInputValue2 = useCallback2(
777
+ (inputValue3) => setInputValue(inputValue3),
778
+ []
779
+ );
780
+ const fetchData = useMemo2(
781
+ () => debounce2(
782
+ (payload, callback) => {
783
+ queryFn(payload).then((c) => callback(c));
784
+ },
785
+ 400
786
+ ),
787
+ []
788
+ );
789
+ const fillOptions = (results) => {
790
+ let newOptions = [];
791
+ if (selectedOptions) {
792
+ newOptions = [...selectedOptions];
793
+ }
794
+ if (results) {
795
+ const newlyAdded = _.differenceBy(
796
+ results,
797
+ selectedOptions,
798
+ (c) => c.value
799
+ );
800
+ newOptions = [...newOptions, ...newlyAdded];
801
+ }
802
+ setOptions(newOptions);
803
+ setLoading(false);
804
+ };
805
+ useEffect3(() => {
806
+ if (initialValuesLoaded.current) return void 0;
807
+ let active = true;
808
+ const payload = {
809
+ query: null,
810
+ initialValues
811
+ };
812
+ setLoading(true);
813
+ fetchData(payload, (results) => {
814
+ if (active) {
815
+ setSelectedOptions([...results]);
816
+ field.onChange([...results.map((c) => c.value)]);
817
+ initialValuesLoaded.current = true;
818
+ setLoading(false);
819
+ }
820
+ });
821
+ return () => {
822
+ active = false;
823
+ };
824
+ }, [initialValues]);
825
+ useEffect3(() => {
826
+ let active = true;
827
+ if (inputValue2 === "" || initialValuesLoaded.current === false) {
828
+ setOptions(selectedOptions ? [...selectedOptions] : []);
829
+ return void 0;
830
+ }
831
+ setLoading(true);
832
+ const payload = {
833
+ query: inputValue2,
834
+ initialValues: null
835
+ };
836
+ fetchData(payload, (results) => {
837
+ if (active) {
838
+ fillOptions(results);
839
+ }
840
+ });
841
+ return () => {
842
+ active = false;
843
+ };
844
+ }, [initialValues, inputValue2, fetchData]);
845
+ const handleChange = (_2, selectedOptions2, reason) => {
846
+ if (reason === "clear") {
847
+ setSelectedOptions([]);
848
+ field.onChange([]);
849
+ } else if (reason === "selectOption" || reason === "removeOption") {
850
+ setSelectedOptions(selectedOptions2);
851
+ field.onChange(selectedOptions2.map((c) => c.value));
852
+ }
853
+ setOptions([]);
854
+ };
855
+ return /* @__PURE__ */ jsx7(
856
+ Autocomplete2,
857
+ {
858
+ ref: multiSelectRef,
859
+ multiple: true,
860
+ loading,
861
+ getOptionLabel: (option) => option.label,
862
+ getOptionKey: (option) => option.value,
863
+ isOptionEqualToValue: (option, val) => option.value === val.value,
864
+ options,
865
+ value: selectedOptions,
866
+ filterSelectedOptions: true,
867
+ onChange: handleChange,
868
+ onInputChange: (_2, newInputValue) => {
869
+ setInputValue2(newInputValue);
870
+ },
871
+ renderInput: (params) => /* @__PURE__ */ jsx7(
872
+ TextField4,
873
+ {
874
+ ...params,
875
+ label,
876
+ error: !!error,
877
+ helperText: error ? error.message : "",
878
+ placeholder,
879
+ slotProps: {
880
+ input: {
881
+ ...params.InputProps,
882
+ endAdornment: /* @__PURE__ */ jsxs3(Fragment2, { children: [
883
+ loading ? /* @__PURE__ */ jsx7(CircularProgress2, { color: "inherit", size: 20 }) : null,
884
+ params.InputProps.endAdornment
885
+ ] })
886
+ }
887
+ }
888
+ }
889
+ ),
890
+ renderOption: (props2, option, { inputValue: inputValue3 }) => {
891
+ const { key, ...optionProps } = props2;
892
+ const matches = match(option.label, inputValue3, { insideWords: true });
893
+ const parts = parse(option.label, matches);
894
+ return /* @__PURE__ */ jsx7("li", { ...optionProps, children: /* @__PURE__ */ jsx7("div", { children: parts.map((part, index) => /* @__PURE__ */ jsx7(
895
+ "span",
896
+ {
897
+ style: {
898
+ fontWeight: part.highlight ? 700 : 400
899
+ },
900
+ children: part.text
901
+ },
902
+ index
903
+ )) }) }, key);
904
+ },
905
+ ...rest
906
+ }
907
+ );
908
+ };
909
+ var AsyncSelectMultiElement2 = ({
910
+ gridProps,
911
+ ...props
912
+ }) => {
913
+ if (gridProps) {
914
+ return /* @__PURE__ */ jsx7(Grid27, { ...gridProps, children: /* @__PURE__ */ jsx7(Component7, { ...props }) });
915
+ }
916
+ return /* @__PURE__ */ jsx7(Component7, { ...props });
917
+ };
918
+ AsyncSelectMultiElement2.displayName = "AsyncSelectMulti";
919
+ var AsyncMultiSelect_default = AsyncSelectMultiElement2;
920
+
921
+ // src/wrappers/SelectElement/SelectElement.tsx
922
+ import {
923
+ Autocomplete as Autocomplete3,
924
+ Grid2 as Grid28,
925
+ TextField as TextField5
926
+ } from "@mui/material";
927
+ import {
928
+ useController as useController8
929
+ } from "react-hook-form";
930
+ import { jsx as jsx8 } from "react/jsx-runtime";
931
+ var Component8 = function SelectElement(props) {
932
+ const {
933
+ name,
934
+ onBlur,
935
+ onChange,
936
+ disabled,
937
+ options,
938
+ control,
939
+ gridProps,
940
+ loading = false,
941
+ placeholder,
942
+ label,
943
+ ...rest
944
+ } = props;
945
+ const {
946
+ field,
947
+ fieldState: { error }
948
+ } = useController8({
949
+ name,
950
+ control,
951
+ disabled
952
+ });
953
+ return /* @__PURE__ */ jsx8(
954
+ Autocomplete3,
955
+ {
956
+ ...rest,
957
+ value: field.value ? options.find((option) => {
958
+ return field.value === option.value;
959
+ }) ?? null : null,
960
+ loading,
961
+ options,
962
+ getOptionLabel: (c) => c.label,
963
+ isOptionEqualToValue: (option, value) => option.value === value.value,
964
+ ref: field.ref,
965
+ disabled: field.disabled,
966
+ onChange: (event, newValue, reason) => {
967
+ field.onChange(newValue ? newValue.value : null);
968
+ if (onChange && typeof onChange === "function") {
969
+ onChange(event, newValue, reason);
970
+ }
971
+ },
972
+ onBlur: (event) => {
973
+ field.onBlur();
974
+ if (typeof onBlur === "function") {
975
+ onBlur(event);
976
+ }
977
+ },
978
+ fullWidth: true,
979
+ renderInput: (params) => /* @__PURE__ */ jsx8(
980
+ TextField5,
981
+ {
982
+ ...params,
983
+ fullWidth: true,
984
+ error: !!error,
985
+ helperText: error ? error.message : "",
986
+ placeholder,
987
+ label,
988
+ variant: "outlined"
989
+ }
990
+ )
991
+ }
992
+ );
993
+ };
994
+ var SelectElement2 = ({
995
+ gridProps,
996
+ ...props
997
+ }) => {
998
+ if (gridProps) {
999
+ return /* @__PURE__ */ jsx8(Grid28, { ...gridProps, children: /* @__PURE__ */ jsx8(Component8, { ...props }) });
1000
+ }
1001
+ return /* @__PURE__ */ jsx8(Component8, { ...props });
1002
+ };
1003
+ SelectElement2.displayName = "SelectElement";
1004
+ var SelectElement_default = SelectElement2;
1005
+
1006
+ // src/wrappers/SelectMultiElement/SelectMultiElement.tsx
1007
+ import {
1008
+ Autocomplete as Autocomplete4,
1009
+ CircularProgress as CircularProgress3,
1010
+ Grid2 as Grid29,
1011
+ TextField as TextField6
1012
+ } from "@mui/material";
1013
+ import {
1014
+ useController as useController9
1015
+ } from "react-hook-form";
1016
+ import { Fragment as Fragment3, useState as useState4 } from "react";
1017
+ import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
1018
+ var Component9 = function SelectMultiElement(props) {
1019
+ const {
1020
+ name,
1021
+ onBlur,
1022
+ disabled,
1023
+ options,
1024
+ control,
1025
+ loading = false,
1026
+ placeholder,
1027
+ label,
1028
+ ...rest
1029
+ } = props;
1030
+ const {
1031
+ field,
1032
+ fieldState: { error }
1033
+ } = useController9({
1034
+ name,
1035
+ control,
1036
+ disabled
1037
+ });
1038
+ const [selectedOptions, setSelectedOptions] = useState4([]);
1039
+ const handleChange = (_2, selectedOptions2, reason) => {
1040
+ if (reason === "clear") {
1041
+ setSelectedOptions([]);
1042
+ field.onChange([]);
1043
+ } else if (reason === "selectOption" || reason === "removeOption") {
1044
+ setSelectedOptions(selectedOptions2);
1045
+ field.onChange(selectedOptions2.map((c) => c.value));
1046
+ }
1047
+ };
1048
+ return /* @__PURE__ */ jsx9(
1049
+ Autocomplete4,
1050
+ {
1051
+ multiple: true,
1052
+ value: selectedOptions,
1053
+ loading,
1054
+ options,
1055
+ getOptionLabel: (c) => c.label,
1056
+ isOptionEqualToValue: (option, value) => option.value === value.value,
1057
+ filterSelectedOptions: true,
1058
+ ref: field.ref,
1059
+ disabled: field.disabled,
1060
+ onChange: handleChange,
1061
+ onBlur: (event) => {
1062
+ field.onBlur();
1063
+ if (typeof onBlur === "function") {
1064
+ onBlur(event);
1065
+ }
1066
+ },
1067
+ fullWidth: true,
1068
+ renderInput: (params) => /* @__PURE__ */ jsx9(
1069
+ TextField6,
1070
+ {
1071
+ ...params,
1072
+ label,
1073
+ error: !!error,
1074
+ helperText: error ? error.message : "",
1075
+ placeholder,
1076
+ slotProps: {
1077
+ input: {
1078
+ ...params.InputProps,
1079
+ endAdornment: /* @__PURE__ */ jsxs4(Fragment3, { children: [
1080
+ loading ? /* @__PURE__ */ jsx9(CircularProgress3, { color: "inherit", size: 20 }) : null,
1081
+ params.InputProps.endAdornment
1082
+ ] })
1083
+ }
1084
+ }
1085
+ }
1086
+ ),
1087
+ ...rest
1088
+ }
1089
+ );
1090
+ };
1091
+ var SelectMultiElement2 = ({
1092
+ gridProps,
1093
+ ...props
1094
+ }) => {
1095
+ if (gridProps) {
1096
+ return /* @__PURE__ */ jsx9(Grid29, { ...gridProps, children: /* @__PURE__ */ jsx9(Component9, { ...props }) });
1097
+ }
1098
+ return /* @__PURE__ */ jsx9(Component9, { ...props });
1099
+ };
1100
+ SelectMultiElement2.displayName = "SelectMultiElement";
1101
+ var SelectMultiElement_default = SelectMultiElement2;
1102
+
1103
+ // src/wrappers/SelectCascadeElement/SelectCascadeElement.tsx
1104
+ import {
1105
+ Autocomplete as Autocomplete5,
1106
+ Grid2 as Grid210,
1107
+ TextField as TextField7
1108
+ } from "@mui/material";
1109
+ import { useEffect as useEffect4, useRef as useRef3 } from "react";
1110
+ import {
1111
+ useController as useController10
1112
+ } from "react-hook-form";
1113
+ import { jsx as jsx10 } from "react/jsx-runtime";
1114
+ var Component10 = function SelectCascadeElement(props) {
1115
+ const {
1116
+ name,
1117
+ onBlur,
1118
+ onChange,
1119
+ disabled,
1120
+ options,
1121
+ control,
1122
+ gridProps,
1123
+ loading = false,
1124
+ placeholder,
1125
+ label,
1126
+ dependsOn,
1127
+ ...rest
1128
+ } = props;
1129
+ const {
1130
+ field,
1131
+ fieldState: { error }
1132
+ } = useController10({
1133
+ name,
1134
+ control,
1135
+ disabled
1136
+ });
1137
+ const { field: dependentField } = useController10({
1138
+ name: dependsOn,
1139
+ control,
1140
+ disabled
1141
+ });
1142
+ const parentValueRef = useRef3(dependentField.value ?? null);
1143
+ useEffect4(() => {
1144
+ if (!!dependentField.value && parentValueRef?.current?.value !== dependentField.value || dependentField.value === null) {
1145
+ field.onChange(null);
1146
+ }
1147
+ }, [dependentField.value]);
1148
+ return /* @__PURE__ */ jsx10(
1149
+ Autocomplete5,
1150
+ {
1151
+ ...rest,
1152
+ value: field.value !== null ? options.find((option) => {
1153
+ return field.value === option.value;
1154
+ }) ?? null : null,
1155
+ size: "small",
1156
+ loading,
1157
+ options,
1158
+ getOptionLabel: (c) => c.label,
1159
+ isOptionEqualToValue: (option, value) => option.value === value.value,
1160
+ ref: field.ref,
1161
+ disabled: field.disabled,
1162
+ onChange: (event, newValue, reason) => {
1163
+ field.onChange(newValue ? newValue.value : null);
1164
+ if (onChange && typeof onChange === "function") {
1165
+ onChange(event, newValue, reason);
1166
+ }
1167
+ },
1168
+ onBlur: (event) => {
1169
+ field.onBlur();
1170
+ if (typeof onBlur === "function") {
1171
+ onBlur(event);
1172
+ }
1173
+ },
1174
+ fullWidth: true,
1175
+ renderInput: (params) => /* @__PURE__ */ jsx10(
1176
+ TextField7,
1177
+ {
1178
+ ...params,
1179
+ fullWidth: true,
1180
+ error: !!error,
1181
+ helperText: error ? error.message : "",
1182
+ placeholder,
1183
+ label,
1184
+ variant: "outlined",
1185
+ sx: { "& .MuiInputBase-input": { color: "#3598dc" } }
1186
+ }
1187
+ )
1188
+ }
1189
+ );
1190
+ };
1191
+ var SelectCascadeElement2 = ({
1192
+ gridProps,
1193
+ ...props
1194
+ }) => {
1195
+ if (gridProps) {
1196
+ return /* @__PURE__ */ jsx10(Grid210, { ...gridProps, children: /* @__PURE__ */ jsx10(Component10, { ...props }) });
1197
+ }
1198
+ return /* @__PURE__ */ jsx10(Component10, { ...props });
1199
+ };
1200
+ SelectCascadeElement2.displayName = "SelectCascadeElement";
1201
+ var SelectCascadeElement_default = SelectCascadeElement2;
1202
+
1203
+ // src/wrappers/CheckboxElement/CheckboxElement.tsx
1204
+ import {
1205
+ Checkbox,
1206
+ FormControl as FormControl2,
1207
+ FormControlLabel as FormControlLabel2,
1208
+ FormGroup,
1209
+ FormHelperText as FormHelperText2,
1210
+ Grid2 as Grid211
1211
+ } from "@mui/material";
1212
+ import {
1213
+ useController as useController11
1214
+ } from "react-hook-form";
1215
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
1216
+ var Component11 = function CheckboxElement(props) {
1217
+ const { name, control, label, labelProps, inputRef, ...rest } = props;
1218
+ const {
1219
+ field,
1220
+ fieldState: { error }
1221
+ } = useController11({
1222
+ name,
1223
+ control,
1224
+ disabled: rest.disabled
1225
+ });
1226
+ return /* @__PURE__ */ jsxs5(FormControl2, { error: !!error, children: [
1227
+ /* @__PURE__ */ jsx11(FormGroup, { row: true, children: /* @__PURE__ */ jsx11(
1228
+ FormControlLabel2,
1229
+ {
1230
+ label: label || "",
1231
+ ...labelProps,
1232
+ control: /* @__PURE__ */ jsx11(
1233
+ Checkbox,
1234
+ {
1235
+ ...rest,
1236
+ color: rest.color || "primary",
1237
+ sx: [
1238
+ ...Array.isArray(rest.sx) ? rest.sx : [rest.sx],
1239
+ {
1240
+ color: error ? "error.main" : void 0
1241
+ }
1242
+ ],
1243
+ value: field.value,
1244
+ checked: !!field.value,
1245
+ onChange: (event, newValue) => {
1246
+ field.onChange(event, newValue);
1247
+ if (typeof rest.onChange === "function") {
1248
+ rest.onChange(event, newValue);
1249
+ }
1250
+ }
1251
+ }
1252
+ )
1253
+ }
1254
+ ) }),
1255
+ error && /* @__PURE__ */ jsx11(FormHelperText2, { error: !!error, children: error.message })
1256
+ ] });
1257
+ };
1258
+ var CheckboxElement2 = ({
1259
+ gridProps,
1260
+ ...props
1261
+ }) => {
1262
+ if (gridProps) {
1263
+ return /* @__PURE__ */ jsx11(Grid211, { ...gridProps, children: /* @__PURE__ */ jsx11(Component11, { ...props }) });
1264
+ }
1265
+ return /* @__PURE__ */ jsx11(Component11, { ...props });
1266
+ };
1267
+ CheckboxElement2.displayName = "CheckboxElement";
1268
+ var CheckboxElement_default = CheckboxElement2;
1269
+
1270
+ // src/wrappers/Field/index.ts
1271
+ var Field = {
1272
+ Text: TextFieldElement_default,
1273
+ Checkbox: CheckboxElement_default,
1274
+ Date: DatePickerElement_default,
1275
+ RadioGroup: RadioButtonGroup_default,
1276
+ Password: PasswordElement_default,
1277
+ Time: TimePickerElement_default,
1278
+ Select: SelectElement_default,
1279
+ SelectMulti: SelectMultiElement_default,
1280
+ SelectCascade: SelectCascadeElement_default,
1281
+ AsyncSelect: AsyncSelect_default,
1282
+ AsyncMultiSelect: AsyncMultiSelect_default
1283
+ };
1284
+ var Field_default = Field;
1285
+
1286
+ export {
1287
+ Field_default
1288
+ };