@m4l/components 0.1.13 → 0.1.15
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.js +91 -0
- package/commonjs.js +9 -0
- package/components/CommonActions/components/ActionCancel/index.js +15 -0
- package/components/CommonActions/components/ActionFormCancel/index.js +62 -0
- package/components/CommonActions/components/ActionFormIntro/index.js +35 -0
- package/components/CommonActions/components/ActionIntro/index.js +16 -0
- package/components/CommonActions/components/Actions/index.js +859 -0
- package/components/CompanyLogo/{index.f81c179c.js → index.js} +48 -42
- package/components/DataGrid/index.js +1067 -0
- package/components/DynamicFilter/index.js +1573 -0
- package/components/ErrorLabel/index.js +18 -0
- package/components/Icon/index.js +80 -0
- package/components/Image/index.js +128 -0
- package/components/LanguagePopover/index.js +93 -0
- package/components/Loadable/index.js +13 -0
- package/components/ModalDialog/index.js +180 -0
- package/components/NoItemSelected/{index.12f0ca67.js → index.js} +50 -43
- package/components/ObjectLogs/index.js +284 -0
- package/components/Page/index.js +36 -0
- package/components/PaperForm/index.js +110 -0
- package/components/Period/index.js +230 -0
- package/components/PropertyValue/index.js +142 -0
- package/components/Resizeable/{index.45995d2b.js → index.js} +19 -21
- package/components/ScrollBar/index.js +52 -0
- package/components/ScrollToTop/index.js +10 -0
- package/components/SplitLayout/{index.4032673d.js → index.js} +35 -35
- package/components/animate/LoadingScreen/{index.f1cec7db.js → index.js} +27 -29
- package/components/animate/MotionContainer/index.js +31 -0
- package/components/animate/MotionLazyContainer/index.js +13 -0
- package/components/animate/features.js +2 -0
- package/components/animate/variants/{bounce.784aaaaa.js → bounce.js} +16 -15
- package/components/animate/variants/container.js +20 -0
- package/components/animate/variants/fade.js +61 -0
- package/components/animate/variants/{index.7a912140.js → index.js} +0 -0
- package/components/animate/variants/transition.js +16 -0
- package/components/formatters/BooleanFormatter/index.js +52 -0
- package/components/formatters/DateFormatter/index.js +66 -0
- package/components/formatters/index.js +112 -0
- package/components/hook-form/FormProvider/index.js +61 -0
- package/components/hook-form/RHFAutocomplete/index.js +144 -0
- package/components/hook-form/RHFAutocompleteAsync/index.js +191 -0
- package/components/hook-form/RHFCheckbox/index.js +65 -0
- package/components/hook-form/RHFDateTime/index.js +79 -0
- package/components/hook-form/RHFMultiCheckbox/index.js +32 -0
- package/components/hook-form/RHFPeriod/index.js +47 -0
- package/components/hook-form/RHFRadioGroup/index.js +41 -0
- package/components/hook-form/RHFSelect/index.js +34 -0
- package/components/hook-form/RHFTextField/index.js +87 -0
- package/components/hook-form/RHFUpload/index.js +255 -0
- package/components/mui_extended/Accordion/index.js +105 -0
- package/components/mui_extended/Avatar/index.js +33 -0
- package/components/mui_extended/BoxIcon/index.js +20 -0
- package/components/mui_extended/Breadcrumbs/index.js +92 -0
- package/components/mui_extended/Button/index.js +131 -0
- package/components/mui_extended/IconButton/index.js +108 -0
- package/components/mui_extended/LinkWithRoute/index.js +30 -0
- package/components/mui_extended/MenuPopover/index.js +135 -0
- package/components/mui_extended/Pager/index.js +137 -0
- package/components/mui_extended/Tab/index.js +30 -0
- package/components/mui_extended/Typography/index.js +21 -0
- package/contexts/ModalContext/index.js +165 -0
- package/hooks/useFormAddEdit/index.js +42 -0
- package/hooks/useModal/index.js +4 -0
- package/index.js +70 -162
- package/lodash.js +62 -0
- package/node_modules.js +54 -0
- package/package.json +2 -1
- package/react-data-grid.js +2652 -0
- package/react-draggable.js +960 -0
- package/react-json-view.js +2764 -0
- package/react-lazy-load-image-component.js +792 -0
- package/react-resizable.js +541 -0
- package/react-splitter-layout.js +165 -0
- package/utils/index.js +572 -0
- package/assets/Logo/index.228dcb5a.js +0 -86
- package/commonjs.565e6834.js +0 -12
- package/components/CommonActions/components/ActionCancel/index.cba1b460.js +0 -17
- package/components/CommonActions/components/ActionFormCancel/index.be2fe891.js +0 -49
- package/components/CommonActions/components/ActionFormIntro/index.ca4d2674.js +0 -31
- package/components/CommonActions/components/ActionIntro/index.cc4b1e0e.js +0 -18
- package/components/CommonActions/components/Actions/index.e8148d98.js +0 -743
- package/components/DataGrid/index.b688877d.js +0 -894
- package/components/DynamicFilter/index.82ce857e.js +0 -1158
- package/components/ErrorLabel/index.c8615f16.js +0 -19
- package/components/Icon/index.cbca79b0.js +0 -70
- package/components/Image/index.e790b50b.js +0 -122
- package/components/LanguagePopover/index.3d9611cb.js +0 -87
- package/components/Loadable/index.f5518558.js +0 -15
- package/components/ModalDialog/index.3850c053.js +0 -168
- package/components/ObjectLogs/index.27ef875d.js +0 -266
- package/components/Page/index.6d69977e.js +0 -35
- package/components/PaperForm/index.d7c74064.js +0 -105
- package/components/Period/index.5e68286a.js +0 -160
- package/components/PropertyValue/index.ab3dd7e9.js +0 -116
- package/components/ScrollBar/index.39eeb2de.js +0 -49
- package/components/ScrollToTop/index.e06f98f6.js +0 -11
- package/components/animate/MotionContainer/index.8d9f9d80.js +0 -30
- package/components/animate/MotionLazyContainer/index.572dd012.js +0 -15
- package/components/animate/features.0fbf41e1.js +0 -5
- package/components/animate/variants/container.11f82b76.js +0 -20
- package/components/animate/variants/fade.b561c0fc.js +0 -59
- package/components/animate/variants/transition.bd46b9ce.js +0 -15
- package/components/formatters/BooleanFormatter/index.cca53b7f.js +0 -42
- package/components/formatters/DateFormatter/index.ad8d9b8e.js +0 -57
- package/components/formatters/index.55856d65.js +0 -106
- package/components/hook-form/FormProvider/index.257acd9f.js +0 -55
- package/components/hook-form/RHFAutocomplete/index.6ed76d4c.js +0 -122
- package/components/hook-form/RHFAutocompleteAsync/index.8f2c97ea.js +0 -153
- package/components/hook-form/RHFCheckbox/index.f9ce6c39.js +0 -59
- package/components/hook-form/RHFDateTime/index.fc5cbafe.js +0 -68
- package/components/hook-form/RHFMultiCheckbox/index.2680b3b6.js +0 -34
- package/components/hook-form/RHFPeriod/index.23c254e9.js +0 -45
- package/components/hook-form/RHFRadioGroup/index.b3335e13.js +0 -43
- package/components/hook-form/RHFSelect/index.b6ca8bb2.js +0 -36
- package/components/hook-form/RHFTextField/index.4c455f75.js +0 -77
- package/components/hook-form/RHFUpload/index.ed3d739f.js +0 -244
- package/components/mui_extended/Accordion/index.2116e423.js +0 -103
- package/components/mui_extended/Avatar/index.0a2a4523.js +0 -32
- package/components/mui_extended/BoxIcon/index.e638ecc8.js +0 -22
- package/components/mui_extended/Breadcrumbs/index.5e37d903.js +0 -89
- package/components/mui_extended/Button/index.84d8898c.js +0 -110
- package/components/mui_extended/IconButton/index.88f3aadb.js +0 -98
- package/components/mui_extended/LinkWithRoute/index.d4b263de.js +0 -28
- package/components/mui_extended/MenuPopover/index.488fc536.js +0 -131
- package/components/mui_extended/Pager/index.0576814f.js +0 -126
- package/components/mui_extended/Tab/index.e0653a0a.js +0 -28
- package/components/mui_extended/Typography/index.0c4604b3.js +0 -22
- package/contexts/ModalContext/index.2188b69e.js +0 -150
- package/hooks/useFormAddEdit/index.d4845f1a.js +0 -26
- package/hooks/useModal/index.6571d2d9.js +0 -6
- package/lodash.e09401f0.js +0 -32
- package/node_modules.168cb897.js +0 -55
- package/react-data-grid.d46d625e.js +0 -2115
- package/react-draggable.20e95c61.js +0 -714
- package/react-json-view.f56a7f8e.js +0 -2762
- package/react-lazy-load-image-component.45b56650.js +0 -784
- package/react-resizable.5277deaf.js +0 -371
- package/react-splitter-layout.7810ac1b.js +0 -165
- package/utils/index.214d9542.js +0 -435
|
@@ -0,0 +1,1067 @@
|
|
|
1
|
+
import { styled, alpha } from "@mui/material/styles";
|
|
2
|
+
import { forwardRef, useRef, useLayoutEffect, createContext, useState, useContext, useEffect, useMemo, useCallback } from "react";
|
|
3
|
+
import { S as SELECT_COLUMN_KEY, a as SelectCellFormatter, u as useRowSelection, H as HeaderRenderer, D as DataGrid$1 } from "../../react-data-grid.js";
|
|
4
|
+
import { useDrag, useDrop, DndProvider } from "react-dnd";
|
|
5
|
+
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
6
|
+
import { SvgIcon, Checkbox, InputBase, Skeleton } from "@mui/material";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { voidFunction, useModuleDictionary, useModuleSkeleton } from "@m4l/core";
|
|
9
|
+
import { A as ActionsColumn, a as Actions } from "../CommonActions/components/Actions/index.js";
|
|
10
|
+
import { g as getModalDialogComponentsDictionary, d as defaultModalDialogDictionary } from "../ModalDialog/index.js";
|
|
11
|
+
import { g as getPagerComponentsDictionary, d as defaultPagerDictionary } from "../mui_extended/Pager/index.js";
|
|
12
|
+
const WrapperGrid = styled("div")(() => ({
|
|
13
|
+
display: "flex",
|
|
14
|
+
flexDirection: "column",
|
|
15
|
+
position: "absolute",
|
|
16
|
+
padding: "0px",
|
|
17
|
+
inset: "0px",
|
|
18
|
+
overflow: "hidden"
|
|
19
|
+
}));
|
|
20
|
+
const OriginalDataGridWrapperStyled = styled("div")(({
|
|
21
|
+
theme
|
|
22
|
+
}) => ({
|
|
23
|
+
position: "absolute",
|
|
24
|
+
bottom: "0px",
|
|
25
|
+
top: "0px",
|
|
26
|
+
left: "0px",
|
|
27
|
+
right: "0px",
|
|
28
|
+
"& .rdg ": {
|
|
29
|
+
userSelect: "initial",
|
|
30
|
+
height: "100%",
|
|
31
|
+
contentVisibility: "unset",
|
|
32
|
+
overflow: "scroll",
|
|
33
|
+
borderRadius: "5px",
|
|
34
|
+
"--rdg-grid-inline-size": "0px",
|
|
35
|
+
"--rdg-header-background-color": theme.palette.grid?.sectionHeader,
|
|
36
|
+
"--rdg-row-selected-background-color": theme.palette.mode === "light" ? theme.palette.primary.LightSelected : theme.palette.primary.DarkSelected,
|
|
37
|
+
"--rdg-row-hover-background-color": theme.palette.grid?.rowHover,
|
|
38
|
+
"--rdg-background-color": theme.palette.background.default,
|
|
39
|
+
"--rdg-selection-color": theme.palette.primary.main,
|
|
40
|
+
"--row-selected-hover-background-color": theme.palette.mode === "light" ? theme.palette.primary.LightSelectedHover : theme.palette.primary.DarkSelectedHover,
|
|
41
|
+
"--rdg-checkbox-color": theme.palette.primary.main,
|
|
42
|
+
"--rdg-checkbox-focus-color": alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
|
|
43
|
+
"--rdg-border-color": theme.palette.divider
|
|
44
|
+
},
|
|
45
|
+
"& .rdg::-webkit-scrollbar": {
|
|
46
|
+
width: "6px",
|
|
47
|
+
height: "6px",
|
|
48
|
+
borderRadius: "3px",
|
|
49
|
+
backgroundColor: "transparent"
|
|
50
|
+
},
|
|
51
|
+
"& .rdg::-webkit-scrollbar-track": {
|
|
52
|
+
backgroundColor: "transparent",
|
|
53
|
+
border: "0px solid transparent"
|
|
54
|
+
},
|
|
55
|
+
"& .rdg::-webkit-scrollbar-corner": {
|
|
56
|
+
backgroundColor: "transparent"
|
|
57
|
+
},
|
|
58
|
+
"& ::-webkit-scrollbar-thumb": {
|
|
59
|
+
borderRadius: "10px",
|
|
60
|
+
backgroundColor: theme.palette.divider,
|
|
61
|
+
border: "0px solid transparent"
|
|
62
|
+
},
|
|
63
|
+
'& [role="columnheader"]': {
|
|
64
|
+
justifyContent: "center",
|
|
65
|
+
alignItems: "center"
|
|
66
|
+
},
|
|
67
|
+
"& .rdg-cell": {
|
|
68
|
+
fontFamily: theme.typography.body2.fontFamily,
|
|
69
|
+
fontWeight: theme.typography.body2.fontWeight,
|
|
70
|
+
fontSize: theme.typography.body2.fontSize,
|
|
71
|
+
color: theme.palette.text.secondary,
|
|
72
|
+
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
73
|
+
borderRight: `0px solid transparent`,
|
|
74
|
+
position: "relative",
|
|
75
|
+
"&.rdg-cell-frozen": {
|
|
76
|
+
position: "sticky"
|
|
77
|
+
},
|
|
78
|
+
"&:after": {
|
|
79
|
+
content: `""`,
|
|
80
|
+
borderRight: `1px solid ${theme.palette.divider}`,
|
|
81
|
+
position: "absolute",
|
|
82
|
+
right: "0px",
|
|
83
|
+
top: "25%",
|
|
84
|
+
bottom: "25%"
|
|
85
|
+
},
|
|
86
|
+
"& .m4l_icon": {
|
|
87
|
+
height: "100%"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"& .rdg-cell.rdg-cell-align-left": {
|
|
91
|
+
textAlign: "left"
|
|
92
|
+
},
|
|
93
|
+
"& .rdg-cell.rdg-cell-align-center": {
|
|
94
|
+
textAlign: "center"
|
|
95
|
+
},
|
|
96
|
+
"& .rdg-cell.rdg-cell-align-right": {
|
|
97
|
+
textAlign: "right"
|
|
98
|
+
},
|
|
99
|
+
"& .rdg-row .rdg-cell-frozen-last:after": {
|
|
100
|
+
borderRight: `0px solid transparent`,
|
|
101
|
+
boxShadow: "none"
|
|
102
|
+
},
|
|
103
|
+
"& .rdg-row :last-child:after": {
|
|
104
|
+
borderRight: `0px solid transparent`
|
|
105
|
+
},
|
|
106
|
+
"& .rdg-header-row .rdg-cell": {
|
|
107
|
+
fontFamily: theme.typography.subtitle2.fontFamily,
|
|
108
|
+
fontWeight: theme.typography.subtitle2.fontWeight,
|
|
109
|
+
fontSize: theme.typography.subtitle2.fontSize,
|
|
110
|
+
color: theme.palette.text.primary,
|
|
111
|
+
borderRight: `0px solid transparent`,
|
|
112
|
+
boxShadow: "none",
|
|
113
|
+
"&.rdg-cell-frozen-last": {
|
|
114
|
+
"&:after": {
|
|
115
|
+
borderRight: `0px solid transparent`
|
|
116
|
+
},
|
|
117
|
+
boxShadow: "var(--rdg-frozen-cell-box-shadow)"
|
|
118
|
+
},
|
|
119
|
+
"& .rdg-sort-arrow": {
|
|
120
|
+
width: theme.spacing(1),
|
|
121
|
+
margin: `0 ${theme.spacing(0.5)}`
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"& .rdg-header-row :last-child.rdg-cell": {
|
|
125
|
+
borderTopRightRadius: "5px",
|
|
126
|
+
"&:after": {
|
|
127
|
+
borderRight: `0px solid transparent`
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"& .filter_cell_div": {
|
|
131
|
+
paddingLeft: theme.spacing(0.5),
|
|
132
|
+
paddingRight: theme.spacing(0.5)
|
|
133
|
+
},
|
|
134
|
+
"& .rdg-header-sort-cell": {
|
|
135
|
+
width: "100%",
|
|
136
|
+
flexGrow: "1",
|
|
137
|
+
alignItems: "center"
|
|
138
|
+
},
|
|
139
|
+
'& [aria-columnsort="ASC"]': {
|
|
140
|
+
borderTop: `2px solid ${theme.palette.primary.main}`
|
|
141
|
+
},
|
|
142
|
+
'& [aria-columnsort="DESC"]': {
|
|
143
|
+
borderBottom: `2px solid ${theme.palette.primary.main}`
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
const WrapperTable = styled("div", {
|
|
147
|
+
shouldForwardProp: (prop) => prop !== "withActions"
|
|
148
|
+
})(({
|
|
149
|
+
withActions,
|
|
150
|
+
theme
|
|
151
|
+
}) => ({
|
|
152
|
+
display: "flex",
|
|
153
|
+
flexDirection: "column",
|
|
154
|
+
position: "absolute",
|
|
155
|
+
top: withActions ? theme.spacing(5.5) : "0px",
|
|
156
|
+
bottom: "0px",
|
|
157
|
+
left: "0px",
|
|
158
|
+
right: "0px",
|
|
159
|
+
overflow: "hidden"
|
|
160
|
+
}));
|
|
161
|
+
function CheckboxIcon(props) {
|
|
162
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
163
|
+
...props,
|
|
164
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
165
|
+
d: "M17 3a4 4 0 014 4v10a4 4 0 01-4 4H7a4 4 0 01-4-4V7a4 4 0 014-4h10zm0 2H7a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2z"
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function CheckboxCheckedIcon(props) {
|
|
170
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
171
|
+
...props,
|
|
172
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
173
|
+
d: "M17 3a4 4 0 014 4v10a4 4 0 01-4 4H7a4 4 0 01-4-4V7a4 4 0 014-4h10zm-1.372 4.972a1.006 1.006 0 00-.928.388l-3.78 5-1.63-2.08a1.001 1.001 0 00-1.58 1.23l2.44 3.11a1 1 0 001.58-.01l4.57-6v-.03a1.006 1.006 0 00-.672-1.608z"
|
|
174
|
+
})
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function CheckboxIndeterminateIcon(props) {
|
|
178
|
+
return /* @__PURE__ */ jsx(SvgIcon, {
|
|
179
|
+
...props,
|
|
180
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
181
|
+
d: "M17 3a4 4 0 014 4v10a4 4 0 01-4 4H7a4 4 0 01-4-4V7a4 4 0 014-4h10zm-1.75 8h-6.5a.75.75 0 00-.75.75v.5c0 .414.336.75.75.75h6.5a.75.75 0 00.75-.75v-.5a.75.75 0 00-.75-.75z"
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const CheckboxFormatter = forwardRef(
|
|
186
|
+
function CheckboxFormatter2({
|
|
187
|
+
onChange,
|
|
188
|
+
checked,
|
|
189
|
+
...props
|
|
190
|
+
}, _ref) {
|
|
191
|
+
function handleChange(e) {
|
|
192
|
+
onChange(e.target.checked, e.nativeEvent.shiftKey);
|
|
193
|
+
}
|
|
194
|
+
return /* @__PURE__ */ jsx(Checkbox, {
|
|
195
|
+
checked,
|
|
196
|
+
size: "small",
|
|
197
|
+
icon: /* @__PURE__ */ jsx(CheckboxIcon, {}),
|
|
198
|
+
checkedIcon: /* @__PURE__ */ jsx(CheckboxCheckedIcon, {}),
|
|
199
|
+
indeterminateIcon: /* @__PURE__ */ jsx(CheckboxIndeterminateIcon, {}),
|
|
200
|
+
onChange: handleChange,
|
|
201
|
+
...props
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
const filterColumnClassName = "filter-cell";
|
|
206
|
+
const filterHeight = 35;
|
|
207
|
+
function SelectFormatter(props) {
|
|
208
|
+
const [isRowSelected, onRowSelectionChange] = useRowSelection();
|
|
209
|
+
const onChange = (checked, isShiftClick) => {
|
|
210
|
+
onRowSelectionChange({
|
|
211
|
+
row: props.row,
|
|
212
|
+
checked,
|
|
213
|
+
isShiftClick
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const cellFormater = SelectCellFormatter({
|
|
217
|
+
value: isRowSelected,
|
|
218
|
+
isCellSelected: props.isCellSelected,
|
|
219
|
+
onChange,
|
|
220
|
+
"aria-label": "Select"
|
|
221
|
+
});
|
|
222
|
+
return cellFormater;
|
|
223
|
+
}
|
|
224
|
+
function SelectGroupFormatter(props) {
|
|
225
|
+
const [isRowSelected, onRowSelectionChange] = useRowSelection();
|
|
226
|
+
const onChange = (checked) => {
|
|
227
|
+
onRowSelectionChange({
|
|
228
|
+
row: props.row,
|
|
229
|
+
checked,
|
|
230
|
+
isShiftClick: false
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
const cellFormater = SelectCellFormatter({
|
|
234
|
+
value: isRowSelected,
|
|
235
|
+
isCellSelected: props.isCellSelected,
|
|
236
|
+
onChange,
|
|
237
|
+
"aria-label": "Select Group"
|
|
238
|
+
});
|
|
239
|
+
return cellFormater;
|
|
240
|
+
}
|
|
241
|
+
const SelectColumn = {
|
|
242
|
+
key: SELECT_COLUMN_KEY,
|
|
243
|
+
name: "",
|
|
244
|
+
width: 60,
|
|
245
|
+
maxWidth: 60,
|
|
246
|
+
resizable: false,
|
|
247
|
+
sortable: false,
|
|
248
|
+
frozen: true,
|
|
249
|
+
type: "number",
|
|
250
|
+
headerRenderer: (props) => SelectCellFormatter({
|
|
251
|
+
"aria-label": "Select All",
|
|
252
|
+
isCellSelected: props.isCellSelected,
|
|
253
|
+
value: props.allRowsSelected,
|
|
254
|
+
onChange: props.onAllRowsSelectionChange
|
|
255
|
+
}),
|
|
256
|
+
formatter: SelectFormatter,
|
|
257
|
+
groupFormatter: SelectGroupFormatter
|
|
258
|
+
};
|
|
259
|
+
function useFocusRef(isSelected) {
|
|
260
|
+
const ref = useRef(null);
|
|
261
|
+
useLayoutEffect(() => {
|
|
262
|
+
if (!isSelected)
|
|
263
|
+
return;
|
|
264
|
+
ref.current?.focus({ preventScroll: true });
|
|
265
|
+
}, [isSelected]);
|
|
266
|
+
return {
|
|
267
|
+
ref,
|
|
268
|
+
tabIndex: isSelected ? 0 : -1
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const initialState$1 = {
|
|
272
|
+
activeFilters: false,
|
|
273
|
+
setActiveFilters: voidFunction
|
|
274
|
+
};
|
|
275
|
+
const FilterContext = createContext(initialState$1);
|
|
276
|
+
function FilterProvider({
|
|
277
|
+
children,
|
|
278
|
+
initialActiveFilters
|
|
279
|
+
}) {
|
|
280
|
+
const [filterOptions, setFilterOptions] = useState({
|
|
281
|
+
activeFilters: initialActiveFilters
|
|
282
|
+
});
|
|
283
|
+
const onChangeFilter = (columnkey, value) => {
|
|
284
|
+
const newMap = filterOptions.filters ? new Map(filterOptions.filters) : /* @__PURE__ */ new Map();
|
|
285
|
+
if (value !== "") {
|
|
286
|
+
newMap.set(columnkey, value);
|
|
287
|
+
} else {
|
|
288
|
+
newMap.delete(columnkey);
|
|
289
|
+
}
|
|
290
|
+
setFilterOptions({
|
|
291
|
+
...filterOptions,
|
|
292
|
+
filters: newMap
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
const setActiveFilters = (active) => {
|
|
296
|
+
if (active) {
|
|
297
|
+
setFilterOptions({
|
|
298
|
+
activeFilters: true,
|
|
299
|
+
filters: /* @__PURE__ */ new Map()
|
|
300
|
+
});
|
|
301
|
+
} else {
|
|
302
|
+
setFilterOptions({
|
|
303
|
+
activeFilters: false
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
return /* @__PURE__ */ jsx(FilterContext.Provider, {
|
|
308
|
+
value: {
|
|
309
|
+
...filterOptions,
|
|
310
|
+
onChangeFilter,
|
|
311
|
+
setActiveFilters
|
|
312
|
+
},
|
|
313
|
+
children
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
const useFilters = () => useContext(FilterContext);
|
|
317
|
+
function DraggableHeaderRenderer(props) {
|
|
318
|
+
const {
|
|
319
|
+
onColumnsReorder,
|
|
320
|
+
column,
|
|
321
|
+
isCellSelected,
|
|
322
|
+
...others
|
|
323
|
+
} = props;
|
|
324
|
+
const {
|
|
325
|
+
ref,
|
|
326
|
+
tabIndex
|
|
327
|
+
} = useFocusRef(isCellSelected);
|
|
328
|
+
const {
|
|
329
|
+
getLabel
|
|
330
|
+
} = useModuleDictionary();
|
|
331
|
+
const {
|
|
332
|
+
activeFilters,
|
|
333
|
+
filters,
|
|
334
|
+
onChangeFilter
|
|
335
|
+
} = useFilters();
|
|
336
|
+
const [filter, setFilter] = useState(filters?.get(column.key) || "");
|
|
337
|
+
const [{
|
|
338
|
+
isDragging
|
|
339
|
+
}, drag] = useDrag({
|
|
340
|
+
type: "COLUMN_DRAG",
|
|
341
|
+
item: {
|
|
342
|
+
key: column.key
|
|
343
|
+
},
|
|
344
|
+
collect: (monitor) => ({
|
|
345
|
+
isDragging: monitor.isDragging()
|
|
346
|
+
})
|
|
347
|
+
});
|
|
348
|
+
const [{
|
|
349
|
+
isOver
|
|
350
|
+
}, drop] = useDrop({
|
|
351
|
+
accept: "COLUMN_DRAG",
|
|
352
|
+
drop({
|
|
353
|
+
key
|
|
354
|
+
}) {
|
|
355
|
+
onColumnsReorder(key, column.key);
|
|
356
|
+
},
|
|
357
|
+
collect: (monitor) => ({
|
|
358
|
+
isOver: monitor.isOver(),
|
|
359
|
+
canDrop: monitor.canDrop()
|
|
360
|
+
})
|
|
361
|
+
});
|
|
362
|
+
const handleChange = (e) => {
|
|
363
|
+
if (activeFilters) {
|
|
364
|
+
if (onChangeFilter)
|
|
365
|
+
onChangeFilter(column.key, e.target.value);
|
|
366
|
+
}
|
|
367
|
+
setFilter(e.target.value);
|
|
368
|
+
};
|
|
369
|
+
useEffect(() => {
|
|
370
|
+
if (!activeFilters)
|
|
371
|
+
setFilter("");
|
|
372
|
+
}, [activeFilters]);
|
|
373
|
+
const newColumn = {
|
|
374
|
+
...column
|
|
375
|
+
};
|
|
376
|
+
if (newColumn.withinHeaderRenderer) {
|
|
377
|
+
newColumn.name = newColumn.withinHeaderRenderer(props);
|
|
378
|
+
}
|
|
379
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
380
|
+
ref: (newRef) => {
|
|
381
|
+
drag(newRef);
|
|
382
|
+
drop(newRef);
|
|
383
|
+
},
|
|
384
|
+
style: {
|
|
385
|
+
opacity: isDragging ? 0.5 : 1,
|
|
386
|
+
backgroundColor: isOver ? "#ececec" : void 0,
|
|
387
|
+
cursor: "move",
|
|
388
|
+
display: "flex",
|
|
389
|
+
flexDirection: "column",
|
|
390
|
+
lineHeight: "1",
|
|
391
|
+
height: "100%",
|
|
392
|
+
justifyContent: "center",
|
|
393
|
+
textAlign: "center"
|
|
394
|
+
},
|
|
395
|
+
children: [/* @__PURE__ */ jsx(HeaderRenderer, {
|
|
396
|
+
column: newColumn,
|
|
397
|
+
isCellSelected,
|
|
398
|
+
...others
|
|
399
|
+
}), activeFilters && (column?.withFilter === void 0 || column.withFilter === true) && /* @__PURE__ */ jsx("div", {
|
|
400
|
+
className: "filter_cell_div",
|
|
401
|
+
style: {
|
|
402
|
+
borderTop: "1px solid var(--rdg-border-color)",
|
|
403
|
+
width: "100%",
|
|
404
|
+
display: "flex",
|
|
405
|
+
alignItems: "center",
|
|
406
|
+
height: `${filterHeight}px`
|
|
407
|
+
},
|
|
408
|
+
children: /* @__PURE__ */ jsx(InputBase, {
|
|
409
|
+
inputRef: ref,
|
|
410
|
+
placeholder: getLabel("data_grid.filter_holder"),
|
|
411
|
+
style: {
|
|
412
|
+
width: "100%",
|
|
413
|
+
paddingBottom: "2px",
|
|
414
|
+
border: "1px solid var(--rdg-border-color)"
|
|
415
|
+
},
|
|
416
|
+
tabIndex,
|
|
417
|
+
type: "text",
|
|
418
|
+
onChange: handleChange,
|
|
419
|
+
value: filter
|
|
420
|
+
})
|
|
421
|
+
})]
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const getDragHeaderRenderer = (handleColumnsReorder) => {
|
|
425
|
+
function HeaderRenderer2(props) {
|
|
426
|
+
return /* @__PURE__ */ jsx(DraggableHeaderRenderer, {
|
|
427
|
+
...props,
|
|
428
|
+
onColumnsReorder: handleColumnsReorder
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return HeaderRenderer2;
|
|
432
|
+
};
|
|
433
|
+
const initialState = {
|
|
434
|
+
columnsWidths: /* @__PURE__ */ new Map(),
|
|
435
|
+
onChangeColumnsConfig: voidFunction,
|
|
436
|
+
onChangeColumnsOrder: voidFunction,
|
|
437
|
+
onChangeColumnWidth: voidFunction,
|
|
438
|
+
columnsConfig: [{
|
|
439
|
+
key: "string",
|
|
440
|
+
visible: true,
|
|
441
|
+
hidden: false,
|
|
442
|
+
index: 0,
|
|
443
|
+
frozen: true,
|
|
444
|
+
name: "string;",
|
|
445
|
+
orginalIndex: 0,
|
|
446
|
+
originalVisible: true,
|
|
447
|
+
originalFrozen: false
|
|
448
|
+
}],
|
|
449
|
+
isSkeleton: false,
|
|
450
|
+
rowsCount: 0,
|
|
451
|
+
setRowsCount: voidFunction,
|
|
452
|
+
rowHeights: 36,
|
|
453
|
+
currentRowHeight: 36,
|
|
454
|
+
currentRowHeaderHeight: 40,
|
|
455
|
+
currentRowHeightVariant: "compact",
|
|
456
|
+
setRowHeightVariant: voidFunction
|
|
457
|
+
};
|
|
458
|
+
const BaseContext = createContext(initialState);
|
|
459
|
+
const getColumnConfigByKey = (key, storeColumnsConfig) => {
|
|
460
|
+
let indexFind = -1;
|
|
461
|
+
return [storeColumnsConfig.find((column, index) => {
|
|
462
|
+
if (column.key === key) {
|
|
463
|
+
indexFind = index;
|
|
464
|
+
}
|
|
465
|
+
return column.key === key;
|
|
466
|
+
}), indexFind];
|
|
467
|
+
};
|
|
468
|
+
function getColumnsConfig(id, columns, remoteConfig = void 0) {
|
|
469
|
+
let columnsConfig;
|
|
470
|
+
if (remoteConfig) {
|
|
471
|
+
columnsConfig = remoteConfig.columnsConfig;
|
|
472
|
+
} else {
|
|
473
|
+
try {
|
|
474
|
+
const item = window.localStorage.getItem(`${id}_columns_config`);
|
|
475
|
+
columnsConfig = item !== null ? JSON.parse(item) : [];
|
|
476
|
+
} catch (e) {
|
|
477
|
+
columnsConfig = [];
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return columns.map((column, index) => {
|
|
481
|
+
const [columnConfig = {
|
|
482
|
+
...column
|
|
483
|
+
}, columnConfigIndex] = getColumnConfigByKey(column.key, columnsConfig);
|
|
484
|
+
return {
|
|
485
|
+
key: column.key,
|
|
486
|
+
name: column.name,
|
|
487
|
+
hidden: column.hidden === void 0 ? false : column.hidden,
|
|
488
|
+
index: columnConfigIndex > -1 ? columnConfigIndex : index,
|
|
489
|
+
visible: columnConfig.visible === void 0 ? true : columnConfig.visible,
|
|
490
|
+
frozen: columnConfig.frozen === void 0 ? false : columnConfig.frozen,
|
|
491
|
+
orginalIndex: index,
|
|
492
|
+
originalVisible: column.visible === void 0 ? true : column.visible,
|
|
493
|
+
originalFrozen: column.frozen === void 0 ? false : column.frozen
|
|
494
|
+
};
|
|
495
|
+
}).sort((a, b) => a.index - b.index);
|
|
496
|
+
}
|
|
497
|
+
function getColumnsWidth(id, columns, remoteConfig) {
|
|
498
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
499
|
+
let storeColumnsWidth;
|
|
500
|
+
try {
|
|
501
|
+
const item = window.localStorage.getItem(`${id}_columns_width`);
|
|
502
|
+
storeColumnsWidth = item !== null ? new Map(JSON.parse(item)) : /* @__PURE__ */ new Map();
|
|
503
|
+
} catch (e) {
|
|
504
|
+
storeColumnsWidth = /* @__PURE__ */ new Map();
|
|
505
|
+
}
|
|
506
|
+
for (let i = 0; i < columns.length; i++) {
|
|
507
|
+
let width;
|
|
508
|
+
if (remoteConfig) {
|
|
509
|
+
try {
|
|
510
|
+
width = remoteConfig.columnsWidths.get(columns[i].key);
|
|
511
|
+
} catch (error) {
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (width === void 0) {
|
|
515
|
+
const storeWidth = storeColumnsWidth.get(columns[i].key);
|
|
516
|
+
if (typeof storeWidth === "number") {
|
|
517
|
+
width = storeWidth;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (width !== void 0) {
|
|
521
|
+
newMap.set(columns[i].key, width);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return newMap;
|
|
525
|
+
}
|
|
526
|
+
function saveColumnsWidth(id, storeColumnsWidth) {
|
|
527
|
+
localStorage.setItem(`${id}_columns_width`, JSON.stringify([...storeColumnsWidth]));
|
|
528
|
+
}
|
|
529
|
+
function saveColumnsConfig(id, columnsConfig) {
|
|
530
|
+
localStorage.setItem(`${id}_columns_config`, JSON.stringify(columnsConfig));
|
|
531
|
+
}
|
|
532
|
+
function getIndexRowHeightVariant(variant) {
|
|
533
|
+
if (variant === "compact") {
|
|
534
|
+
return 0;
|
|
535
|
+
}
|
|
536
|
+
if (variant === "standard") {
|
|
537
|
+
return 1;
|
|
538
|
+
}
|
|
539
|
+
return 2;
|
|
540
|
+
}
|
|
541
|
+
function BaseProvider(props) {
|
|
542
|
+
const {
|
|
543
|
+
id,
|
|
544
|
+
children,
|
|
545
|
+
isSkeleton,
|
|
546
|
+
columns,
|
|
547
|
+
remoteConfig,
|
|
548
|
+
rowsCount,
|
|
549
|
+
rowActionsGetter,
|
|
550
|
+
rowHeights,
|
|
551
|
+
rowHeaderHeights,
|
|
552
|
+
initialRowHeightVariant
|
|
553
|
+
} = props;
|
|
554
|
+
const [columnsWidths, setColumnsWidths] = useState(/* @__PURE__ */ new Map());
|
|
555
|
+
const [columnsConfig, setColumnsConfigOptions] = useState(() => []);
|
|
556
|
+
const [rowsFilterCount, setRowFilterCount] = useState(rowsCount);
|
|
557
|
+
const [currentRowHeightVariant, setCurrentRowHeightVariant] = useState(() => {
|
|
558
|
+
if (typeof rowHeights !== typeof rowHeaderHeights) {
|
|
559
|
+
throw new Error("Must be same type rowheights and rowHeaderTypes");
|
|
560
|
+
}
|
|
561
|
+
if (typeof rowHeights === "number" && typeof rowHeaderHeights === "number") {
|
|
562
|
+
return {
|
|
563
|
+
rowHVariant: "compact",
|
|
564
|
+
rowHeight: rowHeights,
|
|
565
|
+
rowHeaderHeight: rowHeaderHeights
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
if (typeof rowHeights !== "number" && rowHeights.length !== 3) {
|
|
569
|
+
throw new Error("Must be 3 heights");
|
|
570
|
+
}
|
|
571
|
+
if (typeof rowHeaderHeights !== "number" && rowHeaderHeights.length !== 3) {
|
|
572
|
+
throw new Error("Must be 3 HeaderHeights");
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
rowHVariant: initialRowHeightVariant,
|
|
576
|
+
rowHeight: typeof rowHeights !== "number" ? rowHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeights,
|
|
577
|
+
rowHeaderHeight: typeof rowHeaderHeights !== "number" ? rowHeaderHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeaderHeights
|
|
578
|
+
};
|
|
579
|
+
});
|
|
580
|
+
const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
|
|
581
|
+
let timerSaveColumns;
|
|
582
|
+
useEffect(() => {
|
|
583
|
+
}, [columnsConfig]);
|
|
584
|
+
useEffect(() => {
|
|
585
|
+
setColumnsWidths(getColumnsWidth(id, columns, remoteConfig));
|
|
586
|
+
setColumnsConfigOptions(getColumnsConfig(id, columns, remoteConfig));
|
|
587
|
+
}, [columns, id, remoteConfig]);
|
|
588
|
+
const onChangeColumnsConfig = useCallback((newColumnsConfig) => {
|
|
589
|
+
saveColumnsConfig(id, newColumnsConfig);
|
|
590
|
+
setColumnsConfigOptions(newColumnsConfig);
|
|
591
|
+
}, [setColumnsConfigOptions, id]);
|
|
592
|
+
const onChangeColumnsOrder = useCallback((sourceKey, targetKey) => {
|
|
593
|
+
if (sourceKey === targetKey)
|
|
594
|
+
return;
|
|
595
|
+
const sourceColumnIndex = columnsConfig.findIndex((c) => c.key === sourceKey);
|
|
596
|
+
const targetColumnIndex = columnsConfig.findIndex((c) => c.key === targetKey);
|
|
597
|
+
const reorderedColumnsConfig = [...columnsConfig];
|
|
598
|
+
reorderedColumnsConfig.splice(targetColumnIndex, 0, reorderedColumnsConfig.splice(sourceColumnIndex, 1)[0]);
|
|
599
|
+
onChangeColumnsConfig(reorderedColumnsConfig);
|
|
600
|
+
}, [columnsConfig, onChangeColumnsConfig]);
|
|
601
|
+
const onChangeColumnWidth = (columnKey, width) => {
|
|
602
|
+
columnsWidths.set(columnKey, Math.round(width));
|
|
603
|
+
if (timerSaveColumns) {
|
|
604
|
+
clearTimeout(timerSaveColumns);
|
|
605
|
+
}
|
|
606
|
+
timerSaveColumns = setTimeout(() => {
|
|
607
|
+
saveColumnsWidth(id, columnsWidths);
|
|
608
|
+
}, 500);
|
|
609
|
+
};
|
|
610
|
+
useEffect(() => {
|
|
611
|
+
setColumnsConfigOptions(getColumnsConfig(id, columns));
|
|
612
|
+
}, [columns]);
|
|
613
|
+
const setRowFilterCountInternal = (newRowsCount) => {
|
|
614
|
+
setRowFilterCount(newRowsCount);
|
|
615
|
+
};
|
|
616
|
+
const setCurrentRowHeightInternal = useCallback((newVariant) => {
|
|
617
|
+
if (typeof rowHeights === "number" || typeof rowHeaderHeights === "number") {
|
|
618
|
+
throw new Error("Only use setCurrentRowHeight with vector rowHeights");
|
|
619
|
+
}
|
|
620
|
+
setCurrentRowHeightVariant({
|
|
621
|
+
rowHVariant: newVariant,
|
|
622
|
+
rowHeight: rowHeights[getIndexRowHeightVariant(newVariant)],
|
|
623
|
+
rowHeaderHeight: rowHeaderHeights[getIndexRowHeightVariant(newVariant)]
|
|
624
|
+
});
|
|
625
|
+
}, [setCurrentRowHeightVariant, rowHeights, rowHeaderHeights]);
|
|
626
|
+
return /* @__PURE__ */ jsx(BaseContext.Provider, {
|
|
627
|
+
value: {
|
|
628
|
+
isSkeleton,
|
|
629
|
+
columnsConfig,
|
|
630
|
+
columnsWidths,
|
|
631
|
+
onChangeColumnsConfig,
|
|
632
|
+
onChangeColumnsOrder,
|
|
633
|
+
onChangeColumnWidth,
|
|
634
|
+
rowsCount: rowsFilterCount,
|
|
635
|
+
setRowsCount: setRowFilterCountInternal,
|
|
636
|
+
rowActionsGetter,
|
|
637
|
+
currentRowHeightVariant: currentRowHeightVariant.rowHVariant,
|
|
638
|
+
currentRowHeight: currentRowHeightVariant.rowHeight,
|
|
639
|
+
currentRowHeaderHeight: currentRowHeightVariant.rowHeaderHeight,
|
|
640
|
+
rowHeights: finalRowHeights,
|
|
641
|
+
setRowHeightVariant: setCurrentRowHeightInternal
|
|
642
|
+
},
|
|
643
|
+
children
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
const useBase = () => useContext(BaseContext);
|
|
647
|
+
const WrapperSkeleton = styled("div")(() => ({
|
|
648
|
+
display: "flex",
|
|
649
|
+
width: "100%",
|
|
650
|
+
height: "100%",
|
|
651
|
+
alignItems: "center"
|
|
652
|
+
}));
|
|
653
|
+
function SkeletonFormatter() {
|
|
654
|
+
return /* @__PURE__ */ jsx(WrapperSkeleton, {
|
|
655
|
+
children: /* @__PURE__ */ jsx(Skeleton, {
|
|
656
|
+
variant: "text",
|
|
657
|
+
width: "100%",
|
|
658
|
+
height: "12px"
|
|
659
|
+
})
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
function getComparator(columns, sortColumn) {
|
|
663
|
+
const column = columns.find((d) => d.key === sortColumn);
|
|
664
|
+
let typeOrder = "string";
|
|
665
|
+
if (column) {
|
|
666
|
+
typeOrder = column.type || "string";
|
|
667
|
+
}
|
|
668
|
+
switch (typeOrder) {
|
|
669
|
+
case "number":
|
|
670
|
+
return (a, b) => {
|
|
671
|
+
try {
|
|
672
|
+
return Number(a[sortColumn]) - Number(b[sortColumn]);
|
|
673
|
+
} catch (error) {
|
|
674
|
+
return -1;
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
default:
|
|
678
|
+
return (a, b) => {
|
|
679
|
+
try {
|
|
680
|
+
return a[sortColumn].toString().localeCompare(b[sortColumn].toString());
|
|
681
|
+
} catch (error) {
|
|
682
|
+
return -1;
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const getColumIndex = (key, columnsConfig) => columnsConfig.findIndex((columnConfig) => columnConfig.key === key);
|
|
688
|
+
const getInOrderColumns = (columns, isMultipleRows, columnsConfig, columnsWidths, rowActionsGetter) => {
|
|
689
|
+
let filteredSortedColumns = columns.filter((column) => {
|
|
690
|
+
const columnConfigIndex = getColumIndex(column.key, columnsConfig);
|
|
691
|
+
const visible = columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].visible : true;
|
|
692
|
+
return !column.hidden && visible;
|
|
693
|
+
}).sort(
|
|
694
|
+
(a, b) => getColumIndex(a.key, columnsConfig) - getColumIndex(b.key, columnsConfig)
|
|
695
|
+
).map((columnSorted) => {
|
|
696
|
+
const columnConfigIndex = getColumIndex(columnSorted.key, columnsConfig);
|
|
697
|
+
return {
|
|
698
|
+
...columnSorted,
|
|
699
|
+
frozen: columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].frozen : true,
|
|
700
|
+
width: typeof columnsWidths.get(columnSorted.key) === "number" ? columnsWidths.get(columnSorted.key) : columnSorted.width
|
|
701
|
+
};
|
|
702
|
+
}).sort((a, b) => {
|
|
703
|
+
const order = (a.frozen === void 0 || a.frozen === false) === (b.frozen === void 0 || b.frozen === false) ? 0 : a.frozen ? -1 : 1;
|
|
704
|
+
return order;
|
|
705
|
+
});
|
|
706
|
+
if (rowActionsGetter) {
|
|
707
|
+
filteredSortedColumns = [ActionsColumn, ...filteredSortedColumns];
|
|
708
|
+
}
|
|
709
|
+
if (isMultipleRows) {
|
|
710
|
+
filteredSortedColumns = [SelectColumn, ...filteredSortedColumns];
|
|
711
|
+
}
|
|
712
|
+
return filteredSortedColumns;
|
|
713
|
+
};
|
|
714
|
+
const getAligByType = (columnType) => {
|
|
715
|
+
switch (columnType) {
|
|
716
|
+
case "string":
|
|
717
|
+
return "left";
|
|
718
|
+
case "date":
|
|
719
|
+
case "boolean":
|
|
720
|
+
case "custom":
|
|
721
|
+
return "center";
|
|
722
|
+
case "number":
|
|
723
|
+
return "right";
|
|
724
|
+
}
|
|
725
|
+
return "left";
|
|
726
|
+
};
|
|
727
|
+
const useSortColumnsRows = (sourceColumns, sourceRows, isMultipleRows) => {
|
|
728
|
+
const { columnsConfig, columnsWidths, onChangeColumnsOrder, rowActionsGetter, isSkeleton } = useBase();
|
|
729
|
+
const [columns, setColumns] = useState(
|
|
730
|
+
() => []
|
|
731
|
+
);
|
|
732
|
+
const [sortColumns, setSortColumns] = useState([]);
|
|
733
|
+
const { activeFilters, filters } = useFilters();
|
|
734
|
+
const findKeyInColumns = (key, cols) => {
|
|
735
|
+
const index = cols.findIndex((column) => key === column.key && column.hidden === false);
|
|
736
|
+
return index !== -1;
|
|
737
|
+
};
|
|
738
|
+
useEffect(() => {
|
|
739
|
+
setColumns(
|
|
740
|
+
getInOrderColumns(
|
|
741
|
+
sourceColumns,
|
|
742
|
+
isMultipleRows,
|
|
743
|
+
columnsConfig,
|
|
744
|
+
columnsWidths,
|
|
745
|
+
rowActionsGetter
|
|
746
|
+
)
|
|
747
|
+
);
|
|
748
|
+
const finalSortedColumns = sortColumns.filter(
|
|
749
|
+
(sortColumn) => findKeyInColumns(sortColumn.columnKey, sourceColumns)
|
|
750
|
+
);
|
|
751
|
+
if (JSON.stringify(finalSortedColumns) !== JSON.stringify(sortColumns)) {
|
|
752
|
+
setSortColumns(finalSortedColumns);
|
|
753
|
+
}
|
|
754
|
+
}, [sourceColumns, columnsConfig, rowActionsGetter]);
|
|
755
|
+
const finalColumns = useMemo(() => {
|
|
756
|
+
const DragAndDropHeaderRenderer = getDragHeaderRenderer(onChangeColumnsOrder);
|
|
757
|
+
return columns.map((c) => {
|
|
758
|
+
const newColumn = {
|
|
759
|
+
...c,
|
|
760
|
+
cellClass: c.align !== void 0 ? `rdg-cell-align-${c.align}` : `rdg-cell-align-${getAligByType(c.type)}`
|
|
761
|
+
};
|
|
762
|
+
if (newColumn.key === SELECT_COLUMN_KEY || newColumn.isDraggable !== void 0 && newColumn.isDraggable === false)
|
|
763
|
+
return newColumn;
|
|
764
|
+
if (isSkeleton) {
|
|
765
|
+
newColumn.headerRenderer = SkeletonFormatter;
|
|
766
|
+
newColumn.formatter = SkeletonFormatter;
|
|
767
|
+
}
|
|
768
|
+
if (newColumn.headerRenderer) {
|
|
769
|
+
newColumn.withinHeaderRenderer = newColumn.headerRenderer;
|
|
770
|
+
}
|
|
771
|
+
if ((newColumn?.withFilter === void 0 || newColumn.withFilter === true) && activeFilters) {
|
|
772
|
+
newColumn.headerCellClass = filterColumnClassName;
|
|
773
|
+
}
|
|
774
|
+
newColumn.headerRenderer = DragAndDropHeaderRenderer;
|
|
775
|
+
return newColumn;
|
|
776
|
+
});
|
|
777
|
+
}, [isSkeleton, columns, activeFilters, onChangeColumnsOrder]);
|
|
778
|
+
const finalRows = useMemo(() => {
|
|
779
|
+
const nextRows = sourceRows.filter((r) => {
|
|
780
|
+
if (!filters || filters.size === 0)
|
|
781
|
+
return true;
|
|
782
|
+
const iterator = filters.entries();
|
|
783
|
+
let valReturn = true;
|
|
784
|
+
for (let i = 0; i < filters.size; i++) {
|
|
785
|
+
const entry = iterator.next().value;
|
|
786
|
+
const key = entry[0];
|
|
787
|
+
const value = `${entry[1]}`;
|
|
788
|
+
let valRow;
|
|
789
|
+
try {
|
|
790
|
+
valRow = `${r[key]}`;
|
|
791
|
+
} catch (error) {
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
valReturn = valReturn && valRow.includes(value);
|
|
795
|
+
if (!valReturn)
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
return valReturn;
|
|
799
|
+
});
|
|
800
|
+
if (sortColumns.length === 0) {
|
|
801
|
+
return nextRows;
|
|
802
|
+
}
|
|
803
|
+
nextRows.sort((a, b) => {
|
|
804
|
+
for (const sort of sortColumns) {
|
|
805
|
+
const comparator = getComparator(columns, sort.columnKey);
|
|
806
|
+
const compResult = comparator(a, b);
|
|
807
|
+
if (compResult !== 0) {
|
|
808
|
+
return sort.direction === "ASC" ? compResult : -compResult;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return 0;
|
|
812
|
+
});
|
|
813
|
+
return nextRows;
|
|
814
|
+
}, [sourceRows, sortColumns, filters]);
|
|
815
|
+
return { finalColumns, sortColumns, setSortColumns, finalRows };
|
|
816
|
+
};
|
|
817
|
+
function Table(props) {
|
|
818
|
+
const {
|
|
819
|
+
isMultipleSelect = false,
|
|
820
|
+
columns,
|
|
821
|
+
rows,
|
|
822
|
+
withActions,
|
|
823
|
+
onRowsChange
|
|
824
|
+
} = props;
|
|
825
|
+
const {
|
|
826
|
+
finalColumns,
|
|
827
|
+
sortColumns,
|
|
828
|
+
setSortColumns,
|
|
829
|
+
finalRows
|
|
830
|
+
} = useSortColumnsRows(columns, rows, isMultipleSelect);
|
|
831
|
+
const {
|
|
832
|
+
activeFilters
|
|
833
|
+
} = useFilters();
|
|
834
|
+
const {
|
|
835
|
+
onChangeColumnWidth,
|
|
836
|
+
setRowsCount,
|
|
837
|
+
currentRowHeight,
|
|
838
|
+
currentRowHeaderHeight
|
|
839
|
+
} = useBase();
|
|
840
|
+
const [selectedRows, setSelectedRows] = useState(() => new Set(props.selectedRows));
|
|
841
|
+
useEffect(() => {
|
|
842
|
+
setSelectedRows(new Set(props.selectedRows));
|
|
843
|
+
}, [props.selectedRows]);
|
|
844
|
+
const ref_data_grid = useRef(null);
|
|
845
|
+
const updateExternal = (mapRowsSelected) => {
|
|
846
|
+
if (props.onRowsSelectedChange) {
|
|
847
|
+
const rawRowsSelected = [];
|
|
848
|
+
if (mapRowsSelected.size > 0) {
|
|
849
|
+
const iterator = mapRowsSelected.entries();
|
|
850
|
+
for (let i = 0; i < mapRowsSelected.size; i++) {
|
|
851
|
+
const entry = iterator.next().value;
|
|
852
|
+
const key = entry[1];
|
|
853
|
+
const row = finalRows.find((frow) => props.rowKeyGetter(frow) === key);
|
|
854
|
+
if (row) {
|
|
855
|
+
rawRowsSelected.push(row);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
props.onRowsSelectedChange(mapRowsSelected, rawRowsSelected);
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
const onInternalSelectedRowsChange = (mapRowsSelected) => {
|
|
863
|
+
setSelectedRows(mapRowsSelected);
|
|
864
|
+
updateExternal(mapRowsSelected);
|
|
865
|
+
};
|
|
866
|
+
const onRowClick = (row) => {
|
|
867
|
+
if (!isMultipleSelect) {
|
|
868
|
+
if (selectedRows.entries().next().value) {
|
|
869
|
+
if (selectedRows.entries().next().value[1] === props.rowKeyGetter(row)) {
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
const mySet = /* @__PURE__ */ new Set([props.rowKeyGetter(row)]);
|
|
874
|
+
setSelectedRows(mySet);
|
|
875
|
+
updateExternal(mySet);
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
useEffect(() => {
|
|
879
|
+
let columnIndice = 0;
|
|
880
|
+
for (const column of finalColumns) {
|
|
881
|
+
const index = sortColumns.findIndex((sortColumn) => column.key === sortColumn.columnKey);
|
|
882
|
+
if (index !== -1) {
|
|
883
|
+
ref_data_grid.current?.element?.querySelector(`[role="columnheader"][aria-colindex="${columnIndice + 1}"]`)?.setAttribute("aria-columnsort", `${sortColumns[index].direction}`);
|
|
884
|
+
} else {
|
|
885
|
+
ref_data_grid.current?.element?.querySelector(`[role="columnheader"][aria-colindex="${columnIndice + 1}"]`)?.removeAttribute("aria-columnsort");
|
|
886
|
+
}
|
|
887
|
+
columnIndice++;
|
|
888
|
+
}
|
|
889
|
+
}, [sortColumns, finalColumns]);
|
|
890
|
+
useEffect(() => {
|
|
891
|
+
setRowsCount(finalRows.length);
|
|
892
|
+
}, [finalRows]);
|
|
893
|
+
const onColumnResize = (idx, width) => {
|
|
894
|
+
onChangeColumnWidth(finalColumns[idx].key, width);
|
|
895
|
+
};
|
|
896
|
+
const onChangeSort = (newSortColumns) => {
|
|
897
|
+
setSortColumns(newSortColumns);
|
|
898
|
+
};
|
|
899
|
+
return /* @__PURE__ */ jsx(WrapperTable, {
|
|
900
|
+
id: "WrapperTable",
|
|
901
|
+
withActions,
|
|
902
|
+
children: /* @__PURE__ */ jsx(OriginalDataGridWrapperStyled, {
|
|
903
|
+
id: "OriginalGridWrapperStyled",
|
|
904
|
+
children: /* @__PURE__ */ jsx(DndProvider, {
|
|
905
|
+
backend: HTML5Backend,
|
|
906
|
+
children: /* @__PURE__ */ jsx(DataGrid$1, {
|
|
907
|
+
className: "fill-grid rdg-light",
|
|
908
|
+
ref: ref_data_grid,
|
|
909
|
+
headerRowHeight: activeFilters ? currentRowHeaderHeight + filterHeight : currentRowHeaderHeight,
|
|
910
|
+
columns: finalColumns,
|
|
911
|
+
sortColumns,
|
|
912
|
+
onSortColumnsChange: onChangeSort,
|
|
913
|
+
onColumnResize,
|
|
914
|
+
rows: finalRows,
|
|
915
|
+
onRowsChange,
|
|
916
|
+
selectedRows,
|
|
917
|
+
onSelectedRowsChange: onInternalSelectedRowsChange,
|
|
918
|
+
onRowClick,
|
|
919
|
+
rowHeight: currentRowHeight,
|
|
920
|
+
rowKeyGetter: props.rowKeyGetter,
|
|
921
|
+
cellNavigationMode: "LOOP_OVER_ROW",
|
|
922
|
+
components: {
|
|
923
|
+
checkboxFormatter: CheckboxFormatter
|
|
924
|
+
},
|
|
925
|
+
defaultColumnOptions: {
|
|
926
|
+
resizable: true,
|
|
927
|
+
sortable: true
|
|
928
|
+
}
|
|
929
|
+
})
|
|
930
|
+
})
|
|
931
|
+
})
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
function DataGrid(props) {
|
|
935
|
+
const {
|
|
936
|
+
withActions = true,
|
|
937
|
+
rows,
|
|
938
|
+
columns,
|
|
939
|
+
actionsProps,
|
|
940
|
+
rowActionsGetter,
|
|
941
|
+
onRowsChange,
|
|
942
|
+
rowHeaderHeights = [44, 63, 75],
|
|
943
|
+
rowHeights = [36, 52, 67],
|
|
944
|
+
initialRowHeightVariant = "compact"
|
|
945
|
+
} = props;
|
|
946
|
+
const isSkeleton = useModuleSkeleton();
|
|
947
|
+
return /* @__PURE__ */ jsx(WrapperGrid, {
|
|
948
|
+
id: `WrapperGrid_${props.id}`,
|
|
949
|
+
children: /* @__PURE__ */ jsx(BaseProvider, {
|
|
950
|
+
id: props.id,
|
|
951
|
+
isSkeleton,
|
|
952
|
+
columns: props.columns,
|
|
953
|
+
rowHeights,
|
|
954
|
+
rowHeaderHeights,
|
|
955
|
+
initialRowHeightVariant,
|
|
956
|
+
rowsCount: rows.length,
|
|
957
|
+
rowActionsGetter,
|
|
958
|
+
children: /* @__PURE__ */ jsxs(FilterProvider, {
|
|
959
|
+
initialActiveFilters: false,
|
|
960
|
+
children: [withActions && actionsProps && /* @__PURE__ */ jsx(Actions, {
|
|
961
|
+
...actionsProps
|
|
962
|
+
}), /* @__PURE__ */ jsx(Table, {
|
|
963
|
+
id: props.id,
|
|
964
|
+
withActions,
|
|
965
|
+
columns,
|
|
966
|
+
rows,
|
|
967
|
+
isMultipleSelect: props.isMultipleSelect,
|
|
968
|
+
selectedRows: props.selectedRows,
|
|
969
|
+
rowKeyGetter: props.rowKeyGetter,
|
|
970
|
+
onRowsChange,
|
|
971
|
+
onRowsSelectedChange: props.onRowsSelectedChange
|
|
972
|
+
})]
|
|
973
|
+
})
|
|
974
|
+
})
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
function getDataGridComponentsDictionary() {
|
|
978
|
+
return ["data_grid"].concat(getPagerComponentsDictionary()).concat(getModalDialogComponentsDictionary());
|
|
979
|
+
}
|
|
980
|
+
({
|
|
981
|
+
grid: {
|
|
982
|
+
actions: "Actions",
|
|
983
|
+
settings_tooltip: "Settings",
|
|
984
|
+
settings_sel_columns: "Select columns",
|
|
985
|
+
settings_column_name: "Name",
|
|
986
|
+
settings_column_position: "Position",
|
|
987
|
+
settings_column_visible: "Visible",
|
|
988
|
+
settings_column_frozen: "Frozen",
|
|
989
|
+
settings_move_first: "Move first",
|
|
990
|
+
settings_move_up: "Move up",
|
|
991
|
+
settings_move_last: "Move first",
|
|
992
|
+
settings_move_down: "Move down",
|
|
993
|
+
settings_visible_all: "Visible all",
|
|
994
|
+
settings_no_visible_all: "Invisible all",
|
|
995
|
+
settings_restore: "Restore",
|
|
996
|
+
density_tooltip: "Density",
|
|
997
|
+
density_compact: "Compact",
|
|
998
|
+
density_standard: "Standard",
|
|
999
|
+
density_confortable: "Confortable",
|
|
1000
|
+
filter_holder: "Filter",
|
|
1001
|
+
filter_show: "Show filters",
|
|
1002
|
+
filter_hide: "Hide filters",
|
|
1003
|
+
rows: "Rows",
|
|
1004
|
+
rows_per_page: "Rows per page"
|
|
1005
|
+
},
|
|
1006
|
+
...defaultPagerDictionary,
|
|
1007
|
+
...defaultModalDialogDictionary
|
|
1008
|
+
});
|
|
1009
|
+
const Input = styled("input")(() => ({
|
|
1010
|
+
appearance: "none",
|
|
1011
|
+
boxSizing: "border-box",
|
|
1012
|
+
inlineSize: "100%",
|
|
1013
|
+
blockSize: "100%",
|
|
1014
|
+
paddingBlock: "0",
|
|
1015
|
+
verticalAlign: "top",
|
|
1016
|
+
textAlign: "right",
|
|
1017
|
+
color: "var(--rdg-color)",
|
|
1018
|
+
backgroundColor: "var(--rdg-background-color)",
|
|
1019
|
+
fontFamily: "inherit",
|
|
1020
|
+
"&:focus": {
|
|
1021
|
+
outline: "none"
|
|
1022
|
+
},
|
|
1023
|
+
"&::placeholder": {
|
|
1024
|
+
color: "#999",
|
|
1025
|
+
opacity: "1"
|
|
1026
|
+
}
|
|
1027
|
+
}));
|
|
1028
|
+
function autoFocusAndSelect(input) {
|
|
1029
|
+
input?.focus();
|
|
1030
|
+
input?.select();
|
|
1031
|
+
}
|
|
1032
|
+
function TextEditor({
|
|
1033
|
+
row,
|
|
1034
|
+
column,
|
|
1035
|
+
onRowChange,
|
|
1036
|
+
onClose
|
|
1037
|
+
}) {
|
|
1038
|
+
return /* @__PURE__ */ jsx(Input, {
|
|
1039
|
+
className: "rdg-text-editor",
|
|
1040
|
+
ref: autoFocusAndSelect,
|
|
1041
|
+
value: row[column.key],
|
|
1042
|
+
onChange: (event) => onRowChange({
|
|
1043
|
+
...row,
|
|
1044
|
+
[column.key]: event.target.value
|
|
1045
|
+
}),
|
|
1046
|
+
onBlur: () => onClose(true)
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function NumberEditor({
|
|
1050
|
+
row,
|
|
1051
|
+
column,
|
|
1052
|
+
onRowChange,
|
|
1053
|
+
onClose
|
|
1054
|
+
}) {
|
|
1055
|
+
return /* @__PURE__ */ jsx(Input, {
|
|
1056
|
+
className: "rdg-text-editor",
|
|
1057
|
+
ref: autoFocusAndSelect,
|
|
1058
|
+
type: "number",
|
|
1059
|
+
value: row[column.key],
|
|
1060
|
+
onChange: (event) => onRowChange({
|
|
1061
|
+
...row,
|
|
1062
|
+
[column.key]: event.target.value !== "" ? Number(event.target.value) : ""
|
|
1063
|
+
}),
|
|
1064
|
+
onBlur: () => onClose(true)
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
export { DataGrid as D, NumberEditor as N, OriginalDataGridWrapperStyled as O, TextEditor as T, useFilters as a, getDataGridComponentsDictionary as g, useBase as u };
|