@m4l/components 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/can-use-dom.js +3 -0
- package/dist/components/DataGrid/index.js +3 -6
- package/dist/components/DataGrid/types.d.ts +1 -1
- package/dist/components/ModalDialog/index.js +0 -5
- package/dist/components/PropertyValue/index.d.ts +3 -0
- package/dist/components/PropertyValue/index.js +108 -0
- package/dist/components/PropertyValue/skeleton.d.ts +2 -0
- package/dist/components/PropertyValue/styles.d.ts +6 -0
- package/dist/components/PropertyValue/types.d.ts +11 -0
- package/dist/components/ScrollBar/index.d.ts +3 -0
- package/dist/components/ScrollBar/index.js +60 -0
- package/dist/components/ScrollBar/styles.d.ts +6 -0
- package/dist/components/ScrollBar/types.d.ts +7 -0
- package/dist/components/hook-form/FormProvider/components/FormActions/index.d.ts +3 -0
- package/dist/components/hook-form/FormProvider/components/FormActions/skeleton.d.ts +2 -0
- package/dist/components/hook-form/FormProvider/components/FormActions/styles.d.ts +3 -0
- package/dist/components/hook-form/FormProvider/components/FormActions/types.d.ts +4 -0
- package/dist/components/hook-form/FormProvider/index.d.ts +3 -0
- package/dist/components/hook-form/FormProvider/index.js +162 -0
- package/dist/components/hook-form/FormProvider/styles.d.ts +2 -0
- package/dist/components/hook-form/FormProvider/types.d.ts +10 -0
- package/dist/components/hook-form/RHFAutocompleteAsync/index.d.ts +4 -0
- package/dist/components/hook-form/RHFAutocompleteAsync/index.js +184 -0
- package/dist/components/hook-form/RHFAutocompleteAsync/styles.d.ts +4 -0
- package/dist/components/hook-form/RHFAutocompleteAsync/types.d.ts +17 -0
- package/dist/components/hook-form/RHFCheckbox/index.d.ts +3 -0
- package/dist/components/hook-form/RHFCheckbox/index.js +41 -0
- package/dist/components/hook-form/RHFCheckbox/skeleton.d.ts +2 -0
- package/dist/components/hook-form/RHFCheckbox/styles.d.ts +2 -0
- package/dist/components/hook-form/RHFCheckbox/types.d.ts +10 -0
- package/dist/components/hook-form/RHFMultiCheckbox/index.d.ts +3 -0
- package/dist/components/hook-form/RHFMultiCheckbox/index.js +32 -0
- package/dist/components/hook-form/RHFMultiCheckbox/types.d.ts +10 -0
- package/dist/components/hook-form/RHFRadioGroup.d.ts +9 -0
- package/dist/components/hook-form/RHFRadioGroup.js +41 -0
- package/dist/components/hook-form/RHFSelect.d.ts +8 -0
- package/dist/components/hook-form/RHFSelect.js +34 -0
- package/dist/components/hook-form/RHFTextField/index.d.ts +4 -0
- package/dist/components/hook-form/RHFTextField/index.js +57 -0
- package/dist/components/hook-form/RHFTextField/styles.d.ts +2 -0
- package/dist/components/hook-form/RHFTextField/types.d.ts +9 -0
- package/dist/components/hook-form/index.d.ts +7 -0
- package/dist/components/index.d.ts +10 -5
- package/dist/components/mui_extended/Accordion/index.d.ts +3 -0
- package/dist/components/mui_extended/Accordion/index.js +45 -0
- package/dist/components/mui_extended/Accordion/types.d.ts +11 -0
- package/dist/components/mui_extended/BoxIcon/index.js +1 -1
- package/dist/components/mui_extended/Breadcrumbs/index.d.ts +2 -1
- package/dist/components/mui_extended/MenuPopover/index.d.ts +2 -1
- package/dist/components/mui_extended/Tab/index.d.ts +2 -0
- package/dist/components/mui_extended/Tab/index.js +29 -0
- package/dist/components/mui_extended/Tab/styles.d.ts +2 -0
- package/dist/components/mui_extended/index.d.ts +8 -6
- package/dist/contexts/ModalContext/index.js +1 -1
- package/dist/core-js.js +2645 -0
- package/dist/index.js +34 -17
- package/dist/juggle.js +511 -0
- package/dist/lodash.js +489 -0
- package/dist/node_modules.js +54 -0
- package/dist/react-draggable.js +3 -3
- package/dist/react-resizable.js +3 -3
- package/dist/react-splitter-layout.js +2 -2
- package/dist/simplebar.js +849 -0
- package/dist/vendor.js +26 -14
- package/package.json +7 -2
|
@@ -6,9 +6,6 @@ import { HTML5Backend } from "react-dnd-html5-backend";
|
|
|
6
6
|
import { SvgIcon, Checkbox, InputBase, Skeleton } from "@mui/material";
|
|
7
7
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
8
8
|
import { voidFunction, useModuleDictionary, useEnvironment } from "@m4l/core";
|
|
9
|
-
import "@mui/material/Box";
|
|
10
|
-
import "../mui_extended/MenuPopover/index.js";
|
|
11
|
-
import "react-router-dom";
|
|
12
9
|
import { M as MenuActions } from "../mui_extended/MenuActions/index.js";
|
|
13
10
|
import { P as Pager, g as getPagerComponentsDictionary, d as defaultPagerDictionary } from "../mui_extended/Pager/index.js";
|
|
14
11
|
import { I as IconButton } from "../mui_extended/IconButton/index.js";
|
|
@@ -1591,7 +1588,7 @@ function DataGrid(props) {
|
|
|
1591
1588
|
function getGridComponentsDictionary() {
|
|
1592
1589
|
return ["grid"].concat(getPagerComponentsDictionary()).concat(getModalDialogComponentsDictionary());
|
|
1593
1590
|
}
|
|
1594
|
-
|
|
1591
|
+
({
|
|
1595
1592
|
grid: {
|
|
1596
1593
|
actions: "Actions",
|
|
1597
1594
|
settings_tooltip: "Settings",
|
|
@@ -1619,7 +1616,7 @@ const defaultGridDictionary = {
|
|
|
1619
1616
|
},
|
|
1620
1617
|
...defaultPagerDictionary,
|
|
1621
1618
|
...defaultModalDialogDictionary
|
|
1622
|
-
};
|
|
1619
|
+
});
|
|
1623
1620
|
function DateFormatter(props) {
|
|
1624
1621
|
const {
|
|
1625
1622
|
presentationType,
|
|
@@ -1655,4 +1652,4 @@ const initialPagerState = {
|
|
|
1655
1652
|
rowsPerPage: 25,
|
|
1656
1653
|
totalRecords: 0
|
|
1657
1654
|
};
|
|
1658
|
-
export { DateFormatter as D, DataGrid as a,
|
|
1655
|
+
export { DateFormatter as D, DataGrid as a, getGridComponentsDictionary as g, initialPagerState as i };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Column } from 'react-data-grid';
|
|
3
|
-
import { MenuAction } from '../mui_extended';
|
|
3
|
+
import type { MenuAction } from '../mui_extended/MenuActions/types';
|
|
4
4
|
import { ActionsProps } from './components/Actions/types';
|
|
5
5
|
export declare type ColumnType = 'text' | 'date' | 'number' | 'boolean' | 'custom';
|
|
6
6
|
export declare type ColumnAlign = 'left' | 'center' | 'right';
|
|
@@ -6,12 +6,7 @@ import { R as Resizeable } from "../Resizeable/index.js";
|
|
|
6
6
|
import { u as useResponsiveDesktop } from "../../vendor.js";
|
|
7
7
|
import { useEnvironment } from "@m4l/core";
|
|
8
8
|
import { B as BoxIcon } from "../mui_extended/BoxIcon/index.js";
|
|
9
|
-
import "../mui_extended/MenuPopover/index.js";
|
|
10
|
-
import "react";
|
|
11
9
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
12
|
-
import "react-router-dom";
|
|
13
|
-
import "../mui_extended/MenuActions/index.js";
|
|
14
|
-
import "../mui_extended/Pager/index.js";
|
|
15
10
|
import { F as FormActions, g as getActionnsComponentsDictionary } from "../FormActions/index.js";
|
|
16
11
|
const WrapperDialog = styled(Dialog)(() => ({}));
|
|
17
12
|
const Container = styled("div")(({ theme }) => ({
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { styled } from "@mui/material/styles";
|
|
2
|
+
import { Skeleton } from "@mui/material";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
const WrapperPropertyValue = styled("div", {
|
|
5
|
+
shouldForwardProp: (prop) => prop !== "propertyWidth" && prop !== "propertyHeight" && prop !== "isForm"
|
|
6
|
+
})(({
|
|
7
|
+
propertyHeight,
|
|
8
|
+
isForm,
|
|
9
|
+
theme
|
|
10
|
+
}) => ({
|
|
11
|
+
display: "flex",
|
|
12
|
+
alignItems: "flex-start",
|
|
13
|
+
width: "100%",
|
|
14
|
+
padding: `${theme.spacing(1)} ${theme.spacing(2)}`,
|
|
15
|
+
height: propertyHeight || "auto",
|
|
16
|
+
":hover": {
|
|
17
|
+
backgroundColor: isForm ? "unset" : theme.palette.grid?.rowHover
|
|
18
|
+
},
|
|
19
|
+
borderBottom: isForm ? "none" : `1px solid ${theme.palette.divider}`,
|
|
20
|
+
flexDirection: "column",
|
|
21
|
+
[theme.breakpoints.up("sm")]: {
|
|
22
|
+
flexDirection: "row",
|
|
23
|
+
alignItems: "center"
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
const Property = styled("span", {
|
|
27
|
+
shouldForwardProp: (prop) => prop !== "propertyWidth" && prop !== "propertyHeight" && prop !== "isForm"
|
|
28
|
+
})(({
|
|
29
|
+
propertyWidth,
|
|
30
|
+
isForm,
|
|
31
|
+
theme
|
|
32
|
+
}) => ({
|
|
33
|
+
width: propertyWidth || "150px",
|
|
34
|
+
minWidth: propertyWidth || "150px",
|
|
35
|
+
...theme.typography.subtitle2,
|
|
36
|
+
color: theme.palette.text.primary,
|
|
37
|
+
position: "relative",
|
|
38
|
+
[theme.breakpoints.up("sm")]: {
|
|
39
|
+
borderRight: isForm ? "none" : `1px solid ${theme.palette.divider}`,
|
|
40
|
+
paddingRight: theme.spacing(2),
|
|
41
|
+
textAlign: "right"
|
|
42
|
+
},
|
|
43
|
+
overflow: "hidden",
|
|
44
|
+
overflowWrap: "break-word"
|
|
45
|
+
}));
|
|
46
|
+
const Value = styled("div", {
|
|
47
|
+
shouldForwardProp: (prop) => prop !== "propertyWidth" && prop !== "propertyHeight"
|
|
48
|
+
})(({
|
|
49
|
+
propertyHeight,
|
|
50
|
+
theme
|
|
51
|
+
}) => ({
|
|
52
|
+
flexGrow: "1",
|
|
53
|
+
...theme.typography.body2,
|
|
54
|
+
color: theme.palette.text.secondary,
|
|
55
|
+
position: "relative",
|
|
56
|
+
padding: "1px",
|
|
57
|
+
height: propertyHeight ? propertyHeight - 24 : "auto",
|
|
58
|
+
marginTop: theme.spacing(1),
|
|
59
|
+
width: "100%",
|
|
60
|
+
[theme.breakpoints.up("sm")]: {
|
|
61
|
+
marginLeft: theme.spacing(2),
|
|
62
|
+
marginTop: "0px"
|
|
63
|
+
},
|
|
64
|
+
overflow: "hidden",
|
|
65
|
+
overflowWrap: "break-word"
|
|
66
|
+
}));
|
|
67
|
+
const SKTWrapperProperty = styled("div")(() => ({
|
|
68
|
+
display: "flex",
|
|
69
|
+
justifyContent: "flex-end"
|
|
70
|
+
}));
|
|
71
|
+
function SKTProperty() {
|
|
72
|
+
return /* @__PURE__ */ jsx(SKTWrapperProperty, {
|
|
73
|
+
children: /* @__PURE__ */ jsx(Skeleton, {
|
|
74
|
+
variant: "text",
|
|
75
|
+
width: 68,
|
|
76
|
+
height: 14
|
|
77
|
+
})
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function PropertyValue(props) {
|
|
81
|
+
const {
|
|
82
|
+
property,
|
|
83
|
+
value,
|
|
84
|
+
propertyWidth,
|
|
85
|
+
propertyHeight,
|
|
86
|
+
isForm,
|
|
87
|
+
isSkeleton = false
|
|
88
|
+
} = props;
|
|
89
|
+
return /* @__PURE__ */ jsxs(WrapperPropertyValue, {
|
|
90
|
+
id: "ContainerPropertyValue",
|
|
91
|
+
isForm,
|
|
92
|
+
propertyWidth,
|
|
93
|
+
propertyHeight,
|
|
94
|
+
children: [/* @__PURE__ */ jsx(Property, {
|
|
95
|
+
id: "Property",
|
|
96
|
+
isForm,
|
|
97
|
+
propertyWidth,
|
|
98
|
+
propertyHeight,
|
|
99
|
+
children: isSkeleton ? /* @__PURE__ */ jsx(SKTProperty, {}) : property
|
|
100
|
+
}), /* @__PURE__ */ jsx(Value, {
|
|
101
|
+
id: "Value",
|
|
102
|
+
propertyWidth,
|
|
103
|
+
propertyHeight,
|
|
104
|
+
children: value
|
|
105
|
+
})]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export { PropertyValue as P };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PropertyProps } from './types';
|
|
3
|
+
export declare const WrapperPropertyValue: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & PropertyProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
4
|
+
export declare const Property: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & PropertyProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
|
5
|
+
export declare const Value: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & PropertyProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
6
|
+
export declare const SKTWrapperProperty: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface PropertyProps {
|
|
3
|
+
propertyWidth?: number;
|
|
4
|
+
propertyHeight?: number;
|
|
5
|
+
isForm?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PropertyValueProps extends PropertyProps {
|
|
8
|
+
isSkeleton?: boolean;
|
|
9
|
+
property: string;
|
|
10
|
+
value: number | string | ReactNode;
|
|
11
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { styled, alpha } from "@mui/material/styles";
|
|
3
|
+
import { S as SimpleBar } from "../../simplebar.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
const RootStyle = styled("div")(() => ({
|
|
6
|
+
flexGrow: 1,
|
|
7
|
+
height: "100%",
|
|
8
|
+
overflow: "hidden"
|
|
9
|
+
}));
|
|
10
|
+
const SimpleBarStyle = styled(SimpleBar)(({
|
|
11
|
+
theme
|
|
12
|
+
}) => ({
|
|
13
|
+
maxHeight: "100%",
|
|
14
|
+
"& .simplebar-scrollbar": {
|
|
15
|
+
"&:before": {
|
|
16
|
+
backgroundColor: alpha(theme.palette.grey[600], 0.48)
|
|
17
|
+
},
|
|
18
|
+
"&.simplebar-visible:before": {
|
|
19
|
+
opacity: 1
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"& .simplebar-track.simplebar-vertical": {
|
|
23
|
+
width: 10
|
|
24
|
+
},
|
|
25
|
+
"& .simplebar-track.simplebar-horizontal .simplebar-scrollbar": {
|
|
26
|
+
height: 6
|
|
27
|
+
},
|
|
28
|
+
"& .simplebar-mask": {
|
|
29
|
+
zIndex: "inherit"
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
function ScrollBar({
|
|
33
|
+
children,
|
|
34
|
+
sx,
|
|
35
|
+
...other
|
|
36
|
+
}) {
|
|
37
|
+
const userAgent = typeof navigator === "undefined" ? "SSR" : navigator.userAgent;
|
|
38
|
+
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
|
|
39
|
+
if (isMobile) {
|
|
40
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
41
|
+
sx: {
|
|
42
|
+
overflowX: "auto",
|
|
43
|
+
...sx
|
|
44
|
+
},
|
|
45
|
+
...other,
|
|
46
|
+
children
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return /* @__PURE__ */ jsx(RootStyle, {
|
|
50
|
+
id: "RootStyle",
|
|
51
|
+
children: /* @__PURE__ */ jsx(SimpleBarStyle, {
|
|
52
|
+
timeout: 500,
|
|
53
|
+
clickOnTrack: false,
|
|
54
|
+
sx,
|
|
55
|
+
...other,
|
|
56
|
+
children
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export { ScrollBar as S };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import SimpleBarReact from 'simplebar-react';
|
|
3
|
+
export declare const RootStyle: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
4
|
+
export declare const SimpleBarStyle: import("@emotion/styled").StyledComponent<SimpleBarReact.Props & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {
|
|
5
|
+
ref?: import("react").Ref<SimpleBarReact> | undefined;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const WrapperFormActions: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
3
|
+
export declare const WrapperSKTFormActions: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { useCallback, useEffect } from "react";
|
|
2
|
+
import { useFormContext, useFormState, useForm, FormProvider as FormProvider$1 } from "react-hook-form";
|
|
3
|
+
import { o } from "../../../node_modules.js";
|
|
4
|
+
import { styled } from "@mui/material/styles";
|
|
5
|
+
import { useNavigate } from "react-router-dom";
|
|
6
|
+
import { useModuleDictionary, useFlagsPresent } from "@m4l/core";
|
|
7
|
+
import { LoadingButton } from "@mui/lab";
|
|
8
|
+
import { Skeleton, Button } from "@mui/material";
|
|
9
|
+
import { u as useModal } from "../../../hooks/useModal/index.js";
|
|
10
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
11
|
+
const WrapperFormProvider = styled("form")(({
|
|
12
|
+
theme
|
|
13
|
+
}) => ({
|
|
14
|
+
display: "flex",
|
|
15
|
+
flexDirection: "column",
|
|
16
|
+
width: "100%",
|
|
17
|
+
overflow: "scroll",
|
|
18
|
+
marginBottom: theme.spacing(1)
|
|
19
|
+
}));
|
|
20
|
+
const WrapperFormActions = styled("div")(({
|
|
21
|
+
theme
|
|
22
|
+
}) => ({
|
|
23
|
+
paddingTop: theme.spacing(3),
|
|
24
|
+
marginRight: theme.spacing(1.5),
|
|
25
|
+
display: "flex",
|
|
26
|
+
flexDirection: "row",
|
|
27
|
+
justifyContent: "flex-end",
|
|
28
|
+
"& > button": {
|
|
29
|
+
marginLeft: "10px"
|
|
30
|
+
},
|
|
31
|
+
"& .MuiLoadingButton-root ": {
|
|
32
|
+
minWidth: "80px"
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
const WrapperSKTFormActions = styled("div")(({
|
|
36
|
+
theme
|
|
37
|
+
}) => ({
|
|
38
|
+
display: "grid",
|
|
39
|
+
gridTemplateColumns: "auto auto",
|
|
40
|
+
margin: "0px",
|
|
41
|
+
gridGap: `${theme.spacing(3)}`,
|
|
42
|
+
justifyContent: "flex-end",
|
|
43
|
+
paddingTop: `${theme.spacing(3)}`,
|
|
44
|
+
borderTop: `1px solid ${theme.palette.divider}`,
|
|
45
|
+
[theme.breakpoints.up("sm")]: {
|
|
46
|
+
margin: `0 ${theme.spacing(4.5)}`
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
function SKTFormActions() {
|
|
50
|
+
return /* @__PURE__ */ jsxs(WrapperSKTFormActions, {
|
|
51
|
+
children: [/* @__PURE__ */ jsx(Skeleton, {
|
|
52
|
+
variant: "text",
|
|
53
|
+
width: 57,
|
|
54
|
+
height: 30
|
|
55
|
+
}), /* @__PURE__ */ jsx(Skeleton, {
|
|
56
|
+
variant: "text",
|
|
57
|
+
width: 57,
|
|
58
|
+
height: 30
|
|
59
|
+
})]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function FormActions(props) {
|
|
63
|
+
const {
|
|
64
|
+
withIntro,
|
|
65
|
+
urlCancel
|
|
66
|
+
} = props;
|
|
67
|
+
const navigate = useNavigate();
|
|
68
|
+
const {
|
|
69
|
+
getLabel
|
|
70
|
+
} = useModuleDictionary();
|
|
71
|
+
const isSkeleton = !useFlagsPresent(["dictionary_loaded", "form_loaded"]);
|
|
72
|
+
const {
|
|
73
|
+
openModalConfirm
|
|
74
|
+
} = useModal();
|
|
75
|
+
const {
|
|
76
|
+
control
|
|
77
|
+
} = useFormContext();
|
|
78
|
+
const {
|
|
79
|
+
isDirty,
|
|
80
|
+
isSubmitting
|
|
81
|
+
} = useFormState({
|
|
82
|
+
control
|
|
83
|
+
});
|
|
84
|
+
const onConfirmCancel = useCallback(() => {
|
|
85
|
+
if (typeof urlCancel === "number") {
|
|
86
|
+
navigate(urlCancel);
|
|
87
|
+
}
|
|
88
|
+
if (urlCancel && typeof urlCancel === "undefined") {
|
|
89
|
+
navigate(urlCancel, {
|
|
90
|
+
replace: false
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}, [navigate, urlCancel]);
|
|
94
|
+
const onClickCancel = useCallback(() => {
|
|
95
|
+
if (isDirty) {
|
|
96
|
+
openModalConfirm({
|
|
97
|
+
variant: "warning",
|
|
98
|
+
title: getLabel("form_provider.confirm_quit_title"),
|
|
99
|
+
msg: getLabel("form_provider.confirm_quit_msg"),
|
|
100
|
+
onClickIntro: onConfirmCancel
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
onConfirmCancel();
|
|
104
|
+
}
|
|
105
|
+
}, [getLabel, isDirty, onConfirmCancel, openModalConfirm]);
|
|
106
|
+
if (isSkeleton) {
|
|
107
|
+
return /* @__PURE__ */ jsx(SKTFormActions, {});
|
|
108
|
+
}
|
|
109
|
+
return /* @__PURE__ */ jsxs(WrapperFormActions, {
|
|
110
|
+
children: [urlCancel && /* @__PURE__ */ jsx(Button, {
|
|
111
|
+
variant: "outlined",
|
|
112
|
+
color: "inherit",
|
|
113
|
+
onClick: onClickCancel,
|
|
114
|
+
children: getLabel("actions.action_cancel")
|
|
115
|
+
}), withIntro && /* @__PURE__ */ jsx(LoadingButton, {
|
|
116
|
+
variant: "contained",
|
|
117
|
+
type: "submit",
|
|
118
|
+
loading: isSubmitting,
|
|
119
|
+
children: getLabel("actions.action_accept")
|
|
120
|
+
})]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function FormProvider(props) {
|
|
124
|
+
const {
|
|
125
|
+
children,
|
|
126
|
+
onSubmit,
|
|
127
|
+
values,
|
|
128
|
+
validationSchema,
|
|
129
|
+
withIntro,
|
|
130
|
+
urlCancel = -1
|
|
131
|
+
} = props;
|
|
132
|
+
const methods = useForm({
|
|
133
|
+
resolver: o(validationSchema),
|
|
134
|
+
defaultValues: values
|
|
135
|
+
});
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (values.initial) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
console.log("****\xB7\xB7\xB7\xB7\xB7\xB7useEffect FormProvider", values);
|
|
141
|
+
const keys = Object.keys(values);
|
|
142
|
+
keys.forEach((key) => {
|
|
143
|
+
methods.setValue(key, values[key], {
|
|
144
|
+
shouldValidate: false,
|
|
145
|
+
shouldDirty: false,
|
|
146
|
+
shouldTouch: false
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}, [methods, values]);
|
|
150
|
+
return /* @__PURE__ */ jsx(FormProvider$1, {
|
|
151
|
+
...methods,
|
|
152
|
+
children: /* @__PURE__ */ jsxs(WrapperFormProvider, {
|
|
153
|
+
id: "formProvider",
|
|
154
|
+
onSubmit: methods.handleSubmit(onSubmit),
|
|
155
|
+
children: [children, withIntro && /* @__PURE__ */ jsx(FormActions, {
|
|
156
|
+
withIntro,
|
|
157
|
+
urlCancel
|
|
158
|
+
})]
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export { FormProvider as F };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const WrapperFormProvider: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, {}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
export interface FormProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onSubmit: (data: FieldValues) => void;
|
|
6
|
+
values: FieldValues;
|
|
7
|
+
validationSchema: any;
|
|
8
|
+
withIntro?: boolean;
|
|
9
|
+
urlCancel?: string | number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { useState, useEffect, Fragment } from "react";
|
|
2
|
+
import { useModuleDictionary, useNetwork, getPropertyByString } from "@m4l/core";
|
|
3
|
+
import { useFormContext, Controller } from "react-hook-form";
|
|
4
|
+
import { Skeleton, Autocomplete, TextField, CircularProgress } from "@mui/material";
|
|
5
|
+
import { styled } from "@mui/material/styles";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
const SKTRHFAutocompleteAsyncWrapper = styled("div")(() => ({
|
|
8
|
+
display: "flex",
|
|
9
|
+
width: "100%",
|
|
10
|
+
flexDirection: "column"
|
|
11
|
+
}));
|
|
12
|
+
styled("div")(({
|
|
13
|
+
theme
|
|
14
|
+
}) => ({
|
|
15
|
+
display: "flex",
|
|
16
|
+
justifyContent: "flex-end",
|
|
17
|
+
paddingRight: `${theme.spacing(2)}`,
|
|
18
|
+
[theme.breakpoints.down("md")]: {
|
|
19
|
+
justifyContent: "flex-start"
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
const SKTInputText = styled("div")(({
|
|
23
|
+
theme
|
|
24
|
+
}) => ({
|
|
25
|
+
width: "100%",
|
|
26
|
+
display: "grid",
|
|
27
|
+
gridTemplateColumns: "1fr auto",
|
|
28
|
+
gridGap: theme.spacing(2),
|
|
29
|
+
alignItems: "center",
|
|
30
|
+
height: `${theme.spacing(4.5)}`,
|
|
31
|
+
border: `1px solid ${theme.palette.divider}`,
|
|
32
|
+
borderRadius: `${theme.spacing(1)}`,
|
|
33
|
+
padding: `0 ${theme.spacing(2)}`,
|
|
34
|
+
[theme.breakpoints.down("md")]: {
|
|
35
|
+
width: "100%"
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
function RHFAutocompleteAsync(props) {
|
|
39
|
+
const {
|
|
40
|
+
name,
|
|
41
|
+
getOptionLabel,
|
|
42
|
+
isOptionEqualToValue,
|
|
43
|
+
label,
|
|
44
|
+
endPoint,
|
|
45
|
+
timeout = 5e3,
|
|
46
|
+
parms = {},
|
|
47
|
+
resultField = "data",
|
|
48
|
+
skeletonProps = {},
|
|
49
|
+
isRemote = true,
|
|
50
|
+
...other
|
|
51
|
+
} = props;
|
|
52
|
+
const {
|
|
53
|
+
isSkeleton = false,
|
|
54
|
+
width = 100,
|
|
55
|
+
height = "18px"
|
|
56
|
+
} = skeletonProps;
|
|
57
|
+
const {
|
|
58
|
+
getLabel
|
|
59
|
+
} = useModuleDictionary();
|
|
60
|
+
const {
|
|
61
|
+
control,
|
|
62
|
+
getValues
|
|
63
|
+
} = useFormContext();
|
|
64
|
+
const {
|
|
65
|
+
networkOperation
|
|
66
|
+
} = useNetwork();
|
|
67
|
+
const initialValue = getValues(name);
|
|
68
|
+
const [options, setOptions] = useState(initialValue === null ? [] : [initialValue]);
|
|
69
|
+
const [open, setOpen] = useState(false);
|
|
70
|
+
const [optionsLoaded, setOptionsLoaded] = useState(false);
|
|
71
|
+
const loading = open && !optionsLoaded;
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!optionsLoaded && initialValue) {
|
|
74
|
+
setOptions([initialValue]);
|
|
75
|
+
}
|
|
76
|
+
}, [initialValue, optionsLoaded]);
|
|
77
|
+
console.log("***2022Render RHFAutocompleteAsync", loading, options, initialValue);
|
|
78
|
+
const getOptionLabelLocal = (option) => {
|
|
79
|
+
if (option === void 0 || option === null) {
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
return getOptionLabel(option);
|
|
83
|
+
};
|
|
84
|
+
const isOptionEqualToValueLocal = (option, value) => {
|
|
85
|
+
if (value === void 0 || value === null || option === null) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return isOptionEqualToValue(option, value);
|
|
89
|
+
};
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
let mounted = true;
|
|
92
|
+
if (!loading) {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
console.debug("useEffect - RHFAutocompleteAsync - initial", endPoint, loading, parms, resultField, timeout);
|
|
96
|
+
networkOperation({
|
|
97
|
+
method: "GET",
|
|
98
|
+
endPoint,
|
|
99
|
+
timeout,
|
|
100
|
+
parms,
|
|
101
|
+
isRemote
|
|
102
|
+
}).then((response) => {
|
|
103
|
+
if (mounted) {
|
|
104
|
+
setOptions(getPropertyByString(response, resultField));
|
|
105
|
+
setOptionsLoaded(true);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return () => {
|
|
109
|
+
mounted = false;
|
|
110
|
+
};
|
|
111
|
+
}, [loading]);
|
|
112
|
+
if (isSkeleton) {
|
|
113
|
+
return /* @__PURE__ */ jsx(SKTRHFAutocompleteAsyncWrapper, {
|
|
114
|
+
children: /* @__PURE__ */ jsxs(SKTInputText, {
|
|
115
|
+
children: [/* @__PURE__ */ jsx(Skeleton, {
|
|
116
|
+
variant: "text",
|
|
117
|
+
width,
|
|
118
|
+
height
|
|
119
|
+
}, "sk1"), /* @__PURE__ */ jsx(Skeleton, {
|
|
120
|
+
variant: "circular",
|
|
121
|
+
width: 16,
|
|
122
|
+
height: 16
|
|
123
|
+
}, "sk2")]
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
128
|
+
name,
|
|
129
|
+
control,
|
|
130
|
+
render: ({
|
|
131
|
+
field: {
|
|
132
|
+
onChange,
|
|
133
|
+
value
|
|
134
|
+
},
|
|
135
|
+
fieldState: {
|
|
136
|
+
error
|
|
137
|
+
}
|
|
138
|
+
}) => /* @__PURE__ */ jsx(Autocomplete, {
|
|
139
|
+
options,
|
|
140
|
+
getOptionLabel: getOptionLabelLocal,
|
|
141
|
+
defaultValue: initialValue,
|
|
142
|
+
isOptionEqualToValue: isOptionEqualToValueLocal,
|
|
143
|
+
disableClearable: true,
|
|
144
|
+
value: value || null,
|
|
145
|
+
onOpen: () => {
|
|
146
|
+
setOpen(true);
|
|
147
|
+
},
|
|
148
|
+
onClose: () => {
|
|
149
|
+
setOpen(false);
|
|
150
|
+
},
|
|
151
|
+
onChange: (_e, val) => {
|
|
152
|
+
onChange(val);
|
|
153
|
+
},
|
|
154
|
+
loading,
|
|
155
|
+
loadingText: "",
|
|
156
|
+
noOptionsText: getLabel("component_no_options"),
|
|
157
|
+
renderInput: (params) => {
|
|
158
|
+
console.log("TextField", params);
|
|
159
|
+
return /* @__PURE__ */ jsx(TextField, {
|
|
160
|
+
...params,
|
|
161
|
+
label,
|
|
162
|
+
fullWidth: true,
|
|
163
|
+
SelectProps: {
|
|
164
|
+
native: true
|
|
165
|
+
},
|
|
166
|
+
InputProps: {
|
|
167
|
+
...params.InputProps,
|
|
168
|
+
endAdornment: /* @__PURE__ */ jsxs(Fragment, {
|
|
169
|
+
children: [loading ? /* @__PURE__ */ jsx(CircularProgress, {
|
|
170
|
+
color: "primary",
|
|
171
|
+
size: 20
|
|
172
|
+
}, `cp_async${params.id}`) : null, params.InputProps.endAdornment]
|
|
173
|
+
}, `fr_async_${params.id}`)
|
|
174
|
+
},
|
|
175
|
+
autoComplete: "off",
|
|
176
|
+
error: !!error,
|
|
177
|
+
helperText: error?.message,
|
|
178
|
+
...other
|
|
179
|
+
}, `tx_async_${params.id}`);
|
|
180
|
+
}
|
|
181
|
+
}, "at_async")
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
export { RHFAutocompleteAsync as R };
|