@m4l/components 0.1.27 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/Logo/index.228dcb5a.js +42 -35
- package/commonjs.565e6834.js +5 -5
- package/components/CommonActions/components/ActionCancel/index.e498eeb2.js +17 -0
- package/components/CommonActions/components/ActionFormCancel/index.4ff0ad73.js +64 -0
- package/components/CommonActions/components/ActionFormIntro/index.ca4d2674.js +28 -22
- package/components/CommonActions/components/ActionIntro/index.60ef7bd7.js +18 -0
- package/components/CommonActions/components/Actions/index.0645e30f.js +867 -0
- package/components/DataGrid/index.76d8fd25.js +1075 -0
- package/components/DynamicFilter/index.342ba5fe.js +1577 -0
- package/components/ErrorLabel/index.c8615f16.js +13 -12
- package/components/Icon/index.619c31c4.js +65 -53
- package/components/Image/index.93d5f37f.js +190 -0
- package/components/Loadable/index.f5518558.js +8 -8
- package/components/ModalDialog/index.9ea10764.js +184 -0
- package/components/NoItemSelected/{index.9609a7f7.js → index.46d2f632.js} +52 -41
- package/components/ObjectLogs/index.f941fb79.js +288 -0
- package/components/Page/index.4237c241.js +22 -20
- package/components/PaperForm/index.ec9cb8c9.js +66 -59
- package/components/Period/index.2941fbda.js +249 -0
- package/components/PropertyValue/index.dfcfe1ba.js +95 -65
- package/components/Resizeable/index.45995d2b.js +19 -19
- package/components/ScrollBar/index.39eeb2de.js +26 -21
- package/components/ScrollToTop/index.e06f98f6.js +8 -7
- package/components/SplitLayout/index.4032673d.js +35 -33
- package/components/animate/LoadingScreen/index.1d0c4307.js +33 -33
- package/components/animate/MotionContainer/index.8d9f9d80.js +25 -22
- package/components/animate/MotionLazyContainer/index.572dd012.js +10 -10
- package/components/animate/features.0fbf41e1.js +3 -3
- package/components/animate/variants/bounce.784aaaaa.js +16 -13
- package/components/animate/variants/container.11f82b76.js +8 -6
- package/components/animate/variants/fade.b561c0fc.js +32 -28
- package/components/animate/variants/transition.bd46b9ce.js +17 -12
- package/components/formatters/BooleanFormatter/index.8da35c9c.js +46 -33
- package/components/formatters/DateFormatter/index.1b9baacc.js +49 -37
- package/components/formatters/index.689a8086.js +119 -0
- package/components/hook-form/RHFAutocomplete/index.59a68f9f.js +224 -0
- package/components/hook-form/RHFAutocompleteAsync/index.c3083062.js +87 -0
- package/components/hook-form/RHFCheckbox/index.6dcec9e2.js +49 -39
- package/components/hook-form/RHFDateTime/index.9231a7c7.js +69 -56
- package/components/hook-form/RHFMultiCheckbox/index.2680b3b6.js +23 -23
- package/components/hook-form/RHFPeriod/index.64a228d5.js +55 -0
- package/components/hook-form/RHFRadioGroup/index.b3335e13.js +29 -29
- package/components/hook-form/RHFSelect/index.b6ca8bb2.js +24 -24
- package/components/hook-form/RHFTextField/index.f9aaaa90.js +110 -93
- package/components/hook-form/RHFUpload/{index.ec4d5326.js → index.d5cc7c13.js} +151 -130
- package/components/mui_extended/Accordion/index.a02ac6ae.js +73 -69
- package/components/mui_extended/Avatar/index.fe06afd7.js +44 -34
- package/components/mui_extended/BoxIcon/index.e638ecc8.js +10 -10
- package/components/mui_extended/Breadcrumbs/index.5e37d903.js +49 -44
- package/components/mui_extended/Button/index.53b56958.js +178 -0
- package/components/mui_extended/CircularProgress/index.ad569afd.js +8 -6
- package/components/mui_extended/IconButton/index.a321e5cb.js +82 -67
- package/components/mui_extended/LinkWithRoute/index.16436ab8.js +25 -21
- package/components/mui_extended/Pager/index.c0865b70.js +141 -0
- package/components/mui_extended/Popover/index.705275a4.js +278 -0
- package/components/mui_extended/Tab/index.e0653a0a.js +25 -21
- package/components/mui_extended/Typography/index.e5494696.js +25 -21
- package/contexts/ModalContext/index.b92fa565.js +153 -0
- package/contexts/ModalContext/{components → subcomponents}/ContentConfirm/index.d.ts +0 -0
- package/contexts/ModalContext/{components → subcomponents}/ContentConfirm/styles.d.ts +0 -0
- package/contexts/ModalContext/{components → subcomponents}/ContentConfirm/types.d.ts +0 -0
- package/contexts/RHFormContext/index.b142190a.js +63 -0
- package/hooks/useFormAddEdit/index.d4845f1a.js +40 -22
- package/hooks/useModal/index.5fee01a3.js +11 -0
- package/index.js +153 -153
- package/package.json +2 -1
- package/react-data-grid.d46d625e.js +2206 -1663
- package/react-draggable.20e95c61.js +800 -553
- package/react-json-view.f56a7f8e.js +2344 -2340
- package/react-resizable.5277deaf.js +470 -298
- package/react-splitter-layout.7810ac1b.js +130 -128
- package/utils/index.214d9542.js +500 -354
- package/components/CommonActions/components/ActionCancel/index.431160ba.js +0 -17
- package/components/CommonActions/components/ActionFormCancel/index.6a0f34aa.js +0 -49
- package/components/CommonActions/components/ActionIntro/index.85557b90.js +0 -18
- package/components/CommonActions/components/Actions/index.edeb05c2.js +0 -742
- package/components/DataGrid/index.2ce9da7d.js +0 -894
- package/components/DynamicFilter/index.e1d4a948.js +0 -1157
- package/components/Image/index.c9da2d5a.js +0 -152
- package/components/ModalDialog/index.ad61757f.js +0 -168
- package/components/ObjectLogs/index.6ebaec71.js +0 -266
- package/components/Period/index.81de7941.js +0 -175
- package/components/contexts/RHFormContext/index.33dba822.js +0 -56
- package/components/formatters/index.c2a9b55d.js +0 -106
- package/components/hook-form/RHFAutocomplete/index.5eee9d7c.js +0 -174
- package/components/hook-form/RHFAutocompleteAsync/index.757b5080.js +0 -65
- package/components/hook-form/RHFPeriod/index.e08fb1ab.js +0 -51
- package/components/mui_extended/Button/index.51dae0bb.js +0 -144
- package/components/mui_extended/Pager/index.1dc45f5e.js +0 -126
- package/components/mui_extended/Popover/index.cb2ccc66.js +0 -252
- package/contexts/ModalContext/index.9ebc793c.js +0 -136
- package/hooks/useModal/index.34f5978e.js +0 -11
- package/node_modules.168cb897.js +0 -55
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
import { useModuleDictionary
|
|
2
|
-
import
|
|
3
|
-
import { I as
|
|
4
|
-
import { jsx
|
|
5
|
-
function
|
|
1
|
+
import { useModuleDictionary, useEnvironment, getPropertyByString } from "@m4l/core";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { I as Icon } from "../../Icon/index.619c31c4.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
function BooleanFormatter(props) {
|
|
6
6
|
const {
|
|
7
|
-
presentationType
|
|
8
|
-
value
|
|
9
|
-
Component
|
|
10
|
-
} =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
presentationType,
|
|
8
|
+
value,
|
|
9
|
+
Component = React.Fragment
|
|
10
|
+
} = props;
|
|
11
|
+
const {
|
|
12
|
+
getLabel
|
|
13
|
+
} = useModuleDictionary();
|
|
14
|
+
const {
|
|
15
|
+
host_static_assets,
|
|
16
|
+
environment_assets
|
|
17
|
+
} = useEnvironment();
|
|
18
|
+
const final_value = value ?? false;
|
|
19
|
+
const srcCheckTrue = `${host_static_assets}/${environment_assets}/frontend/components/data_grid/components/boolean_formatter/assets/icons/check_true.svg`;
|
|
20
|
+
const srcCheckFalse = `${host_static_assets}/${environment_assets}/frontend/components/data_grid/components/boolean_formatter/assets/icons/check_false.svg`;
|
|
21
|
+
if (presentationType === "string_yes_no") {
|
|
22
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
23
|
+
children: final_value ? getLabel("formatters.boolean_yes") : getLabel("formatters.boolean_no")
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (presentationType === "string_true_false") {
|
|
27
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
28
|
+
children: final_value ? getLabel("formatters.boolean_true") : getLabel("formatters.boolean_false")
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
32
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
33
|
+
src: final_value ? srcCheckTrue : srcCheckFalse,
|
|
23
34
|
bgColor: "action.disabled"
|
|
24
35
|
})
|
|
25
36
|
});
|
|
26
37
|
}
|
|
27
|
-
function
|
|
38
|
+
function columnBooleanFormatter(props) {
|
|
28
39
|
const {
|
|
29
|
-
fieldValue
|
|
30
|
-
presentationType
|
|
31
|
-
Component
|
|
32
|
-
} =
|
|
33
|
-
return (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
fieldValue,
|
|
41
|
+
presentationType,
|
|
42
|
+
Component = React.Fragment
|
|
43
|
+
} = props;
|
|
44
|
+
return (obProps) => {
|
|
45
|
+
return /* @__PURE__ */ jsx(BooleanFormatter, {
|
|
46
|
+
presentationType,
|
|
47
|
+
value: getPropertyByString(obProps, fieldValue),
|
|
48
|
+
Component
|
|
49
|
+
});
|
|
50
|
+
};
|
|
38
51
|
}
|
|
39
52
|
export {
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
BooleanFormatter as B,
|
|
54
|
+
columnBooleanFormatter as c
|
|
42
55
|
};
|
|
@@ -1,57 +1,69 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useEnvironment
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useEnvironment, useHostTools, getPropertyByString } from "@m4l/core";
|
|
3
3
|
import "../../Icon/index.619c31c4.js";
|
|
4
4
|
import "@mui/material/styles";
|
|
5
|
-
import { jsx
|
|
6
|
-
function
|
|
5
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
6
|
+
function DateFormatter(props) {
|
|
7
7
|
const {
|
|
8
|
-
presentationType
|
|
9
|
-
value
|
|
10
|
-
format
|
|
11
|
-
Component
|
|
12
|
-
} =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
presentationType,
|
|
9
|
+
value,
|
|
10
|
+
format,
|
|
11
|
+
Component = React.Fragment
|
|
12
|
+
} = props;
|
|
13
|
+
const {
|
|
14
|
+
dfnsFormat
|
|
15
|
+
} = useEnvironment();
|
|
16
|
+
const {
|
|
17
|
+
formatDate
|
|
18
|
+
} = useHostTools();
|
|
19
|
+
let finalFormat = format || dfnsFormat.datetime_format;
|
|
20
|
+
let result;
|
|
21
|
+
let resultDate;
|
|
22
|
+
if (value === void 0 || value === null) {
|
|
23
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
20
24
|
children: "-"
|
|
21
25
|
});
|
|
22
|
-
|
|
26
|
+
}
|
|
27
|
+
switch (presentationType) {
|
|
23
28
|
case "datetime":
|
|
24
|
-
|
|
29
|
+
finalFormat = format || dfnsFormat.datetime_format;
|
|
25
30
|
break;
|
|
26
31
|
case "date":
|
|
27
|
-
|
|
32
|
+
finalFormat = format || dfnsFormat.date_format;
|
|
28
33
|
break;
|
|
29
34
|
case "time":
|
|
30
|
-
|
|
35
|
+
finalFormat = format || dfnsFormat.time_format;
|
|
31
36
|
break;
|
|
32
37
|
}
|
|
33
38
|
try {
|
|
34
|
-
typeof
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
40
|
+
resultDate = new Date(value);
|
|
41
|
+
} else {
|
|
42
|
+
resultDate = value;
|
|
43
|
+
}
|
|
44
|
+
result = formatDate(resultDate, finalFormat);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
result = "err_typing";
|
|
37
47
|
}
|
|
38
|
-
return /* @__PURE__ */
|
|
39
|
-
children:
|
|
48
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
49
|
+
children: result
|
|
40
50
|
});
|
|
41
51
|
}
|
|
42
|
-
function
|
|
52
|
+
function columnDateFormatter(props) {
|
|
43
53
|
const {
|
|
44
|
-
fieldValue
|
|
45
|
-
presentationType
|
|
46
|
-
Component
|
|
47
|
-
} =
|
|
48
|
-
return (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
fieldValue,
|
|
55
|
+
presentationType,
|
|
56
|
+
Component = React.Fragment
|
|
57
|
+
} = props;
|
|
58
|
+
return (obProps) => {
|
|
59
|
+
return /* @__PURE__ */ jsx(DateFormatter, {
|
|
60
|
+
presentationType,
|
|
61
|
+
value: getPropertyByString(obProps, fieldValue),
|
|
62
|
+
Component
|
|
63
|
+
});
|
|
64
|
+
};
|
|
53
65
|
}
|
|
54
66
|
export {
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
DateFormatter as D,
|
|
68
|
+
columnDateFormatter as c
|
|
57
69
|
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { getPropertyByString } from "@m4l/core";
|
|
4
|
+
import "../Icon/index.619c31c4.js";
|
|
5
|
+
import "@mui/material/styles";
|
|
6
|
+
function UncertaintyFormatter(props) {
|
|
7
|
+
const {
|
|
8
|
+
value,
|
|
9
|
+
unit,
|
|
10
|
+
symbol,
|
|
11
|
+
Component = React.Fragment
|
|
12
|
+
} = props;
|
|
13
|
+
if (value === void 0 || value === null || !Array.isArray(value)) {
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
15
|
+
children: ""
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
let result = "";
|
|
19
|
+
value.map((obj, idx) => {
|
|
20
|
+
const cmc_min_closed = obj.cmc_min_closed != true ? "<" : "\u2264";
|
|
21
|
+
const cmc_max_closed = obj.cmc_max_closed != true ? "<" : "\u2264";
|
|
22
|
+
result = result.concat(`${idx > 0 ? " " : ""}`, obj.cmc_min !== obj.cmc_max ? `[${obj.cmc_min}${unit} ${cmc_min_closed} ${symbol} ${cmc_max_closed} ${obj.cmc_max}${unit} \xB1 ${obj.cmc_uncertainty}]` : `[${obj.cmc_min}${unit} \xB1 ${obj.cmc_uncertainty}]`);
|
|
23
|
+
});
|
|
24
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
25
|
+
children: result
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function PointsFormatter(props) {
|
|
29
|
+
const {
|
|
30
|
+
value,
|
|
31
|
+
unit,
|
|
32
|
+
Component = React.Fragment
|
|
33
|
+
} = props;
|
|
34
|
+
if (value === void 0 || value === null || !Array.isArray(value)) {
|
|
35
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
36
|
+
children: "[]"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
let result = "";
|
|
40
|
+
value.map((point) => {
|
|
41
|
+
if (point) {
|
|
42
|
+
result = result.concat(`[${point}${unit}]`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
46
|
+
children: result
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function PriceFormatter(props) {
|
|
50
|
+
const {
|
|
51
|
+
value,
|
|
52
|
+
Component = React.Fragment
|
|
53
|
+
} = props;
|
|
54
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
55
|
+
children: `${value}$Cop`
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function getFormattersComponentsDictionary() {
|
|
59
|
+
return ["formatters"];
|
|
60
|
+
}
|
|
61
|
+
const defaultFormattersDictionary = {
|
|
62
|
+
pager: {
|
|
63
|
+
boolean_yes: "Yes",
|
|
64
|
+
boolean_no: "No",
|
|
65
|
+
boolean_true: "True",
|
|
66
|
+
boolean_false: "False"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function columnUncertaintyFormatter(props) {
|
|
70
|
+
const {
|
|
71
|
+
fieldUnit,
|
|
72
|
+
fieldValue,
|
|
73
|
+
fieldSymbol,
|
|
74
|
+
Component
|
|
75
|
+
} = props;
|
|
76
|
+
return (obProps) => {
|
|
77
|
+
return /* @__PURE__ */ jsx(UncertaintyFormatter, {
|
|
78
|
+
Component,
|
|
79
|
+
value: getPropertyByString(obProps, fieldValue),
|
|
80
|
+
unit: getPropertyByString(obProps, fieldUnit),
|
|
81
|
+
symbol: getPropertyByString(obProps, fieldSymbol)
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function columnPointsFormatter(props) {
|
|
86
|
+
const {
|
|
87
|
+
fieldUnit,
|
|
88
|
+
fieldValue,
|
|
89
|
+
Component
|
|
90
|
+
} = props;
|
|
91
|
+
return (obProps) => {
|
|
92
|
+
return /* @__PURE__ */ jsx(PointsFormatter, {
|
|
93
|
+
Component,
|
|
94
|
+
value: getPropertyByString(obProps, fieldValue),
|
|
95
|
+
unit: getPropertyByString(obProps, fieldUnit)
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function columnNestedValueFormatter(props) {
|
|
100
|
+
const {
|
|
101
|
+
fieldValue,
|
|
102
|
+
Component = React.Fragment
|
|
103
|
+
} = props;
|
|
104
|
+
return (obProps) => {
|
|
105
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
106
|
+
children: getPropertyByString(obProps, fieldValue) + ""
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
PointsFormatter as P,
|
|
112
|
+
UncertaintyFormatter as U,
|
|
113
|
+
PriceFormatter as a,
|
|
114
|
+
columnPointsFormatter as b,
|
|
115
|
+
columnUncertaintyFormatter as c,
|
|
116
|
+
defaultFormattersDictionary as d,
|
|
117
|
+
columnNestedValueFormatter as e,
|
|
118
|
+
getFormattersComponentsDictionary as g
|
|
119
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { useModuleDictionary, useModuleSkeleton } from "@m4l/core";
|
|
2
|
+
import { useFormContext, Controller } from "react-hook-form";
|
|
3
|
+
import { Skeleton, Autocomplete, TextField, CircularProgress } from "@mui/material";
|
|
4
|
+
import { styled } from "@mui/material/styles";
|
|
5
|
+
import { I as Image } from "../../Image/index.93d5f37f.js";
|
|
6
|
+
import { useMemo, useState, useEffect } from "react";
|
|
7
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
8
|
+
const SKTRHFAutocompleteWrapper = styled("div")(() => ({
|
|
9
|
+
display: "flex",
|
|
10
|
+
width: "100%",
|
|
11
|
+
flexDirection: "column"
|
|
12
|
+
}));
|
|
13
|
+
const SKTInputText = styled("div")(({
|
|
14
|
+
theme
|
|
15
|
+
}) => ({
|
|
16
|
+
width: "100%",
|
|
17
|
+
display: "grid",
|
|
18
|
+
gridTemplateColumns: "1fr auto",
|
|
19
|
+
gridGap: theme.spacing(2),
|
|
20
|
+
alignItems: "center",
|
|
21
|
+
height: `${theme.spacing(4.5)}`,
|
|
22
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
23
|
+
borderRadius: `${theme.spacing(1)}`,
|
|
24
|
+
padding: `0 ${theme.spacing(2)}`,
|
|
25
|
+
[theme.breakpoints.down("md")]: {
|
|
26
|
+
width: "100%"
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
const WrapperAutocomplete = styled("div")(({
|
|
30
|
+
theme
|
|
31
|
+
}) => ({
|
|
32
|
+
display: "flex",
|
|
33
|
+
width: "100%",
|
|
34
|
+
"& .MuiAutocomplete-root": {
|
|
35
|
+
width: "100%"
|
|
36
|
+
},
|
|
37
|
+
"& .m4l_image": {
|
|
38
|
+
marginLeft: theme.spacing(1.5)
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
const WrapperOption = styled("li")(({
|
|
42
|
+
theme
|
|
43
|
+
}) => ({
|
|
44
|
+
"& .m4l_image": {
|
|
45
|
+
marginRight: theme.spacing(1.5)
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
function withRenderOption(getUrlImage, imageWidth, imageHeight) {
|
|
49
|
+
return function RenderOption(optionProps, option) {
|
|
50
|
+
return /* @__PURE__ */ jsxs(WrapperOption, {
|
|
51
|
+
...optionProps,
|
|
52
|
+
children: [/* @__PURE__ */ jsx(Image, {
|
|
53
|
+
src: getUrlImage(option),
|
|
54
|
+
width: imageWidth,
|
|
55
|
+
height: imageHeight
|
|
56
|
+
}), optionProps.key]
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function RHFAutocomplete(props) {
|
|
61
|
+
const {
|
|
62
|
+
name,
|
|
63
|
+
getOptionLabel,
|
|
64
|
+
isOptionEqualToValue,
|
|
65
|
+
label,
|
|
66
|
+
skeletonWidth = 100,
|
|
67
|
+
skeletonHeight = "18px",
|
|
68
|
+
options,
|
|
69
|
+
disabled,
|
|
70
|
+
getOptionUrlImage,
|
|
71
|
+
imageWidth = "24px",
|
|
72
|
+
imageHeight = "24px",
|
|
73
|
+
onOpen,
|
|
74
|
+
onClose,
|
|
75
|
+
loading,
|
|
76
|
+
onChangeFilterParmsLocal,
|
|
77
|
+
...other
|
|
78
|
+
} = props;
|
|
79
|
+
const {
|
|
80
|
+
getLabel
|
|
81
|
+
} = useModuleDictionary();
|
|
82
|
+
const isSkeleton = useModuleSkeleton();
|
|
83
|
+
const {
|
|
84
|
+
control
|
|
85
|
+
} = useFormContext();
|
|
86
|
+
const withImage = useMemo(() => getOptionUrlImage !== void 0, [getOptionUrlImage]);
|
|
87
|
+
const [open, setOpen] = useState(false);
|
|
88
|
+
const onCloseLocal = (event, reason) => {
|
|
89
|
+
setOpen(false);
|
|
90
|
+
if (onClose)
|
|
91
|
+
onClose(event, reason);
|
|
92
|
+
};
|
|
93
|
+
const onOpenLocal = (event) => {
|
|
94
|
+
setOpen(true);
|
|
95
|
+
if (onOpen)
|
|
96
|
+
onOpen(event);
|
|
97
|
+
};
|
|
98
|
+
const getOptionLabelLocal = (option) => {
|
|
99
|
+
if (option === void 0 || option === null) {
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
return getOptionLabel(option);
|
|
103
|
+
};
|
|
104
|
+
const getOptionUrlImageLocal = (option) => {
|
|
105
|
+
if (option === void 0 || option === null || getOptionUrlImage === void 0) {
|
|
106
|
+
return "";
|
|
107
|
+
}
|
|
108
|
+
return getOptionUrlImage(option);
|
|
109
|
+
};
|
|
110
|
+
const isOptionEqualToValueLocal = (option, value) => {
|
|
111
|
+
if (value === void 0 || value === null || option === null) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return isOptionEqualToValue(option, value);
|
|
115
|
+
};
|
|
116
|
+
if (isSkeleton) {
|
|
117
|
+
return /* @__PURE__ */ jsx(SKTRHFAutocompleteWrapper, {
|
|
118
|
+
children: /* @__PURE__ */ jsxs(SKTInputText, {
|
|
119
|
+
children: [/* @__PURE__ */ jsx(Skeleton, {
|
|
120
|
+
variant: "text",
|
|
121
|
+
width: skeletonWidth,
|
|
122
|
+
height: skeletonHeight
|
|
123
|
+
}, "sk1"), /* @__PURE__ */ jsx(Skeleton, {
|
|
124
|
+
variant: "circular",
|
|
125
|
+
width: 16,
|
|
126
|
+
height: 16
|
|
127
|
+
}, "sk2")]
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
132
|
+
name,
|
|
133
|
+
control,
|
|
134
|
+
render: ({
|
|
135
|
+
field: {
|
|
136
|
+
onChange,
|
|
137
|
+
value
|
|
138
|
+
},
|
|
139
|
+
fieldState: {
|
|
140
|
+
error
|
|
141
|
+
}
|
|
142
|
+
}) => {
|
|
143
|
+
const [inputValue, setInputValue] = useState(getOptionLabelLocal(value));
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!open && value === null && inputValue !== "") {
|
|
146
|
+
setInputValue("");
|
|
147
|
+
}
|
|
148
|
+
if (!open && value !== null && options.length === 0 && onChangeFilterParmsLocal) {
|
|
149
|
+
onChangeFilterParmsLocal(getOptionLabelLocal(value), "reset");
|
|
150
|
+
}
|
|
151
|
+
}, [value]);
|
|
152
|
+
return /* @__PURE__ */ jsx(WrapperAutocomplete, {
|
|
153
|
+
className: "m4l_rhf_autocomplete",
|
|
154
|
+
children: /* @__PURE__ */ jsx(Autocomplete, {
|
|
155
|
+
autoComplete: true,
|
|
156
|
+
autoSelect: false,
|
|
157
|
+
options,
|
|
158
|
+
getOptionLabel: getOptionLabelLocal,
|
|
159
|
+
inputValue,
|
|
160
|
+
clearOnBlur: false,
|
|
161
|
+
onInputChange: (_event, newValue, reason) => {
|
|
162
|
+
if (reason === "input") {
|
|
163
|
+
setInputValue(newValue);
|
|
164
|
+
if (onChangeFilterParmsLocal) {
|
|
165
|
+
onChangeFilterParmsLocal(newValue, reason);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
onChange(null);
|
|
169
|
+
},
|
|
170
|
+
isOptionEqualToValue: isOptionEqualToValueLocal,
|
|
171
|
+
disableClearable: true,
|
|
172
|
+
value: value || null,
|
|
173
|
+
onOpen: onOpenLocal,
|
|
174
|
+
onClose: onCloseLocal,
|
|
175
|
+
onChange: (_e, val) => {
|
|
176
|
+
setInputValue(getOptionLabelLocal(val));
|
|
177
|
+
onChange(val);
|
|
178
|
+
},
|
|
179
|
+
filterOptions: onChangeFilterParmsLocal ? (x) => x : void 0,
|
|
180
|
+
loading,
|
|
181
|
+
loadingText: getLabel("rhf_autocomplete.loading_options"),
|
|
182
|
+
disabled,
|
|
183
|
+
noOptionsText: getLabel("rhf_autocomplete.no_options"),
|
|
184
|
+
renderOption: withImage ? withRenderOption(getOptionUrlImageLocal, imageWidth, imageHeight) : void 0,
|
|
185
|
+
renderInput: (params) => {
|
|
186
|
+
return /* @__PURE__ */ jsx(TextField, {
|
|
187
|
+
...params,
|
|
188
|
+
label,
|
|
189
|
+
fullWidth: true,
|
|
190
|
+
SelectProps: {
|
|
191
|
+
native: true
|
|
192
|
+
},
|
|
193
|
+
InputProps: {
|
|
194
|
+
...params.InputProps,
|
|
195
|
+
startAdornment: withImage && value ? /* @__PURE__ */ jsx(Image, {
|
|
196
|
+
src: getOptionUrlImageLocal(value),
|
|
197
|
+
width: imageWidth,
|
|
198
|
+
height: imageHeight
|
|
199
|
+
}, "ImageTextField") : null,
|
|
200
|
+
endAdornment: /* @__PURE__ */ jsxs(Fragment, {
|
|
201
|
+
children: [loading ? /* @__PURE__ */ jsx(CircularProgress, {
|
|
202
|
+
color: "inherit",
|
|
203
|
+
size: 20
|
|
204
|
+
}) : null, params.InputProps.endAdornment]
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
autoComplete: "off",
|
|
208
|
+
error: !!error,
|
|
209
|
+
helperText: error?.message,
|
|
210
|
+
...other
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function getRHFAutocompleteComponentsDictionary() {
|
|
219
|
+
return ["rhf_autocomplete"];
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
RHFAutocomplete as R,
|
|
223
|
+
getRHFAutocompleteComponentsDictionary as g
|
|
224
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from "react";
|
|
2
|
+
import { useNetwork, getPropertyByString } from "@m4l/core";
|
|
3
|
+
import debounce from "lodash/debounce";
|
|
4
|
+
import { R as RHFAutocomplete, g as getRHFAutocompleteComponentsDictionary } from "../RHFAutocomplete/index.59a68f9f.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
function RHFAutocompleteAsync(props) {
|
|
7
|
+
const {
|
|
8
|
+
name,
|
|
9
|
+
endPoint,
|
|
10
|
+
timeout = 5e3,
|
|
11
|
+
parms,
|
|
12
|
+
resultField = "data",
|
|
13
|
+
isRemote = true,
|
|
14
|
+
onChangeFilterParms,
|
|
15
|
+
...other
|
|
16
|
+
} = props;
|
|
17
|
+
const {
|
|
18
|
+
networkOperation
|
|
19
|
+
} = useNetwork();
|
|
20
|
+
const [options, setOptions] = useState([]);
|
|
21
|
+
const [open, setOpen] = useState(false);
|
|
22
|
+
const [loading, setIsloading] = useState(false);
|
|
23
|
+
const [canLoadOptions, setCanLoadOptions] = useState(true);
|
|
24
|
+
const [filterParms, setFilterParms] = useState({});
|
|
25
|
+
const debouncedFilter = useCallback(debounce((newFilterParms) => {
|
|
26
|
+
setCanLoadOptions(true);
|
|
27
|
+
setFilterParms(newFilterParms);
|
|
28
|
+
}, 300), []);
|
|
29
|
+
const onChangeFilterParmsLocal = (newValue) => {
|
|
30
|
+
if (onChangeFilterParms) {
|
|
31
|
+
debouncedFilter(onChangeFilterParms(newValue));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
setCanLoadOptions(true);
|
|
36
|
+
}, [parms, endPoint]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!open || loading) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!canLoadOptions) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setIsloading(true);
|
|
45
|
+
setOptions([]);
|
|
46
|
+
setCanLoadOptions(false);
|
|
47
|
+
networkOperation({
|
|
48
|
+
method: "GET",
|
|
49
|
+
endPoint,
|
|
50
|
+
timeout,
|
|
51
|
+
parms: {
|
|
52
|
+
...parms,
|
|
53
|
+
...filterParms
|
|
54
|
+
},
|
|
55
|
+
isRemote
|
|
56
|
+
}).then((response) => {
|
|
57
|
+
const newOptions = getPropertyByString(response, resultField);
|
|
58
|
+
setOptions(newOptions);
|
|
59
|
+
}).catch(() => {
|
|
60
|
+
setCanLoadOptions(true);
|
|
61
|
+
}).finally(() => {
|
|
62
|
+
setIsloading(false);
|
|
63
|
+
});
|
|
64
|
+
return () => {
|
|
65
|
+
};
|
|
66
|
+
}, [open, parms, filterParms, endPoint]);
|
|
67
|
+
return /* @__PURE__ */ jsx(RHFAutocomplete, {
|
|
68
|
+
name,
|
|
69
|
+
loading,
|
|
70
|
+
options,
|
|
71
|
+
onChangeFilterParmsLocal: onChangeFilterParms ? onChangeFilterParmsLocal : void 0,
|
|
72
|
+
onOpen: () => {
|
|
73
|
+
setOpen(true);
|
|
74
|
+
},
|
|
75
|
+
onClose: () => {
|
|
76
|
+
setOpen(false);
|
|
77
|
+
},
|
|
78
|
+
...other
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function getRHFAutocompleteAsyncComponentsDictionary() {
|
|
82
|
+
return getRHFAutocompleteComponentsDictionary();
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
RHFAutocompleteAsync as R,
|
|
86
|
+
getRHFAutocompleteAsyncComponentsDictionary as g
|
|
87
|
+
};
|