next-recomponents 2.0.29 → 2.0.31
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/index.d.mts +1 -20
- package/dist/index.d.ts +1 -20
- package/dist/index.js +174 -247
- package/dist/index.mjs +181 -254
- package/package.json +1 -1
- package/src/table/index.tsx +228 -293
package/dist/index.d.mts
CHANGED
|
@@ -70,7 +70,6 @@ interface FooterType {
|
|
|
70
70
|
type GridDensity = "compact" | "standard" | "comfortable";
|
|
71
71
|
interface TableProps {
|
|
72
72
|
data: any;
|
|
73
|
-
/** Muestra un input de búsqueda general que filtra filas por palabras clave */
|
|
74
73
|
searchable?: boolean;
|
|
75
74
|
flex?: number;
|
|
76
75
|
editableFields?: string[];
|
|
@@ -90,28 +89,10 @@ interface TableProps {
|
|
|
90
89
|
className?: string;
|
|
91
90
|
fontSize?: string;
|
|
92
91
|
colSize?: Record<string, number>;
|
|
93
|
-
/**
|
|
94
|
-
* Alto fijo de fila en px.
|
|
95
|
-
* Si se omite usa el default de MUI según `density`
|
|
96
|
-
* (compact ≈ 36, standard ≈ 52, comfortable ≈ 68).
|
|
97
|
-
* Se ignora automáticamente cuando `wrapText` es true.
|
|
98
|
-
*/
|
|
99
92
|
rowHeight?: number;
|
|
100
|
-
/**
|
|
101
|
-
* Cuando es true el texto largo hace wrap en lugar de truncarse,
|
|
102
|
-
* y el alto de cada fila crece para mostrar todo el contenido.
|
|
103
|
-
* Internamente activa `getRowHeight={() => "auto"}` en el DataGrid.
|
|
104
|
-
*/
|
|
105
93
|
wrapText?: boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Densidad visual de la tabla.
|
|
108
|
-
* Afecta el padding de celdas y encabezados independientemente
|
|
109
|
-
* del tamaño de fuente.
|
|
110
|
-
* - "compact" → padding mínimo, tabla muy densa
|
|
111
|
-
* - "standard" → (default) comportamiento por defecto de MUI
|
|
112
|
-
* - "comfortable" → padding generoso, fácil de leer
|
|
113
|
-
*/
|
|
114
94
|
density?: GridDensity;
|
|
95
|
+
autoHeight?: boolean;
|
|
115
96
|
[key: string]: any;
|
|
116
97
|
}
|
|
117
98
|
declare function Table(props: TableProps): react_jsx_runtime.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -70,7 +70,6 @@ interface FooterType {
|
|
|
70
70
|
type GridDensity = "compact" | "standard" | "comfortable";
|
|
71
71
|
interface TableProps {
|
|
72
72
|
data: any;
|
|
73
|
-
/** Muestra un input de búsqueda general que filtra filas por palabras clave */
|
|
74
73
|
searchable?: boolean;
|
|
75
74
|
flex?: number;
|
|
76
75
|
editableFields?: string[];
|
|
@@ -90,28 +89,10 @@ interface TableProps {
|
|
|
90
89
|
className?: string;
|
|
91
90
|
fontSize?: string;
|
|
92
91
|
colSize?: Record<string, number>;
|
|
93
|
-
/**
|
|
94
|
-
* Alto fijo de fila en px.
|
|
95
|
-
* Si se omite usa el default de MUI según `density`
|
|
96
|
-
* (compact ≈ 36, standard ≈ 52, comfortable ≈ 68).
|
|
97
|
-
* Se ignora automáticamente cuando `wrapText` es true.
|
|
98
|
-
*/
|
|
99
92
|
rowHeight?: number;
|
|
100
|
-
/**
|
|
101
|
-
* Cuando es true el texto largo hace wrap en lugar de truncarse,
|
|
102
|
-
* y el alto de cada fila crece para mostrar todo el contenido.
|
|
103
|
-
* Internamente activa `getRowHeight={() => "auto"}` en el DataGrid.
|
|
104
|
-
*/
|
|
105
93
|
wrapText?: boolean;
|
|
106
|
-
/**
|
|
107
|
-
* Densidad visual de la tabla.
|
|
108
|
-
* Afecta el padding de celdas y encabezados independientemente
|
|
109
|
-
* del tamaño de fuente.
|
|
110
|
-
* - "compact" → padding mínimo, tabla muy densa
|
|
111
|
-
* - "standard" → (default) comportamiento por defecto de MUI
|
|
112
|
-
* - "comfortable" → padding generoso, fácil de leer
|
|
113
|
-
*/
|
|
114
94
|
density?: GridDensity;
|
|
95
|
+
autoHeight?: boolean;
|
|
115
96
|
[key: string]: any;
|
|
116
97
|
}
|
|
117
98
|
declare function Table(props: TableProps): react_jsx_runtime.JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -35827,10 +35827,6 @@ function CustomFooter({
|
|
|
35827
35827
|
if (!entries.length) return null;
|
|
35828
35828
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex justify-end gap-6 px-4 py-2 bg-gray-100 border-t border-gray-300 text-sm font-semibold text-gray-700", children: entries.map(([key, type]) => {
|
|
35829
35829
|
const value = computeAggregation(rows, key, type);
|
|
35830
|
-
const formatted = value.toLocaleString("en-US", {
|
|
35831
|
-
minimumFractionDigits: value % 1 !== 0 ? 2 : 0,
|
|
35832
|
-
maximumFractionDigits: value % 1 !== 0 ? 2 : 0
|
|
35833
|
-
});
|
|
35834
35830
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
|
|
35835
35831
|
FOOTER_LABELS[type],
|
|
35836
35832
|
" de",
|
|
@@ -35838,40 +35834,68 @@ function CustomFooter({
|
|
|
35838
35834
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "text-gray-900", children: key }),
|
|
35839
35835
|
":",
|
|
35840
35836
|
" ",
|
|
35841
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "text-blue-700", children:
|
|
35837
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "text-blue-700", children: value.toLocaleString() })
|
|
35842
35838
|
] }, key);
|
|
35843
35839
|
}) });
|
|
35844
35840
|
}
|
|
35845
|
-
function ModalDialog({
|
|
35841
|
+
function ModalDialog({
|
|
35842
|
+
open,
|
|
35843
|
+
onClose,
|
|
35844
|
+
modal,
|
|
35845
|
+
selectedRow,
|
|
35846
|
+
onPrev,
|
|
35847
|
+
onNext,
|
|
35848
|
+
hasPrev,
|
|
35849
|
+
hasNext
|
|
35850
|
+
}) {
|
|
35846
35851
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material.Dialog, { open, maxWidth: "xl", fullWidth: true, children: [
|
|
35847
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.
|
|
35848
|
-
"
|
|
35849
|
-
|
|
35850
|
-
|
|
35851
|
-
|
|
35852
|
-
|
|
35853
|
-
|
|
35854
|
-
|
|
35852
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center justify-between p-4 border-b", children: [
|
|
35853
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex gap-2", children: [
|
|
35854
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35855
|
+
"button",
|
|
35856
|
+
{
|
|
35857
|
+
disabled: !hasPrev,
|
|
35858
|
+
onClick: onPrev,
|
|
35859
|
+
className: "px-4 py-2 rounded border bg-gray-100 hover:bg-gray-200 disabled:opacity-40",
|
|
35860
|
+
children: "\u2190 Anterior"
|
|
35861
|
+
}
|
|
35862
|
+
),
|
|
35863
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35864
|
+
"button",
|
|
35865
|
+
{
|
|
35866
|
+
disabled: !hasNext,
|
|
35867
|
+
onClick: onNext,
|
|
35868
|
+
className: "px-4 py-2 rounded border bg-gray-100 hover:bg-gray-200 disabled:opacity-40",
|
|
35869
|
+
children: "Siguiente \u2192"
|
|
35870
|
+
}
|
|
35871
|
+
)
|
|
35872
|
+
] }),
|
|
35873
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35874
|
+
"button",
|
|
35875
|
+
{
|
|
35876
|
+
onClick: onClose,
|
|
35877
|
+
className: "font-bold w-[35px] h-[35px] flex items-center justify-center hover:animate-pulse border shadow rounded bg-red-500 text-white",
|
|
35878
|
+
children: "\xD7"
|
|
35879
|
+
}
|
|
35880
|
+
)
|
|
35881
|
+
] }),
|
|
35855
35882
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "mt-4 m-auto p-5", children: selectedRow && import_react5.default.cloneElement(
|
|
35856
35883
|
modal,
|
|
35857
|
-
{
|
|
35884
|
+
{
|
|
35885
|
+
row: selectedRow,
|
|
35886
|
+
hide: onClose
|
|
35887
|
+
}
|
|
35858
35888
|
) })
|
|
35859
35889
|
] });
|
|
35860
35890
|
}
|
|
35861
|
-
function Toolbar({
|
|
35862
|
-
exportName,
|
|
35863
|
-
onSave,
|
|
35864
|
-
onSelect,
|
|
35865
|
-
rows,
|
|
35866
|
-
filteredRows
|
|
35867
|
-
}) {
|
|
35891
|
+
function Toolbar({ exportName, onSave, onSelect, rows, filteredRows }) {
|
|
35868
35892
|
const excel = useExcel();
|
|
35869
35893
|
const stripMeta = (r) => {
|
|
35870
35894
|
const { _edited, ...rest } = r;
|
|
35871
35895
|
return rest;
|
|
35872
35896
|
};
|
|
35873
35897
|
if (!exportName && !onSave && !onSelect) return null;
|
|
35874
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex gap-2
|
|
35898
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex gap-2 p-2 text-xs", children: [
|
|
35875
35899
|
exportName && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35876
35900
|
Button,
|
|
35877
35901
|
{
|
|
@@ -35891,170 +35915,20 @@ function Toolbar({
|
|
|
35891
35915
|
) : onSave && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { onClick: () => onSave(rows.map(stripMeta)), children: "Guardar" })
|
|
35892
35916
|
] });
|
|
35893
35917
|
}
|
|
35894
|
-
function useColumns(rows, currentCoin, options, colSize) {
|
|
35895
|
-
const {
|
|
35896
|
-
flex,
|
|
35897
|
-
editableFields,
|
|
35898
|
-
buttons,
|
|
35899
|
-
hideColumns,
|
|
35900
|
-
modal,
|
|
35901
|
-
wrapText,
|
|
35902
|
-
handleRowUpdate,
|
|
35903
|
-
onModalOpen
|
|
35904
|
-
} = options;
|
|
35905
|
-
return (0, import_react5.useMemo)(() => {
|
|
35906
|
-
if (!rows.length) return [];
|
|
35907
|
-
const cols = Object.keys(rows[0]).filter((key) => !key.startsWith("_") && !hideColumns.includes(key)).map((key) => {
|
|
35908
|
-
var _a, _b;
|
|
35909
|
-
return {
|
|
35910
|
-
field: key,
|
|
35911
|
-
headerName: key,
|
|
35912
|
-
valueFormatter: (value) => {
|
|
35913
|
-
if (value == null || value === "") return "";
|
|
35914
|
-
const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
|
|
35915
|
-
if (`${value}`.match(isDate)) {
|
|
35916
|
-
return value.toString().split("T")[0].split("-").reverse().join("/");
|
|
35917
|
-
}
|
|
35918
|
-
const splited = `${value}`.split(".");
|
|
35919
|
-
const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(regular_expresions_default.number));
|
|
35920
|
-
if (hasDecimals) {
|
|
35921
|
-
return [
|
|
35922
|
-
currentCoin,
|
|
35923
|
-
(+`${value}`).toLocaleString("en-US", {
|
|
35924
|
-
minimumFractionDigits: 2,
|
|
35925
|
-
maximumFractionDigits: 2
|
|
35926
|
-
})
|
|
35927
|
-
].join(" ");
|
|
35928
|
-
}
|
|
35929
|
-
const isNumber = typeof value === "number";
|
|
35930
|
-
if (isNumber) {
|
|
35931
|
-
if (isNaN(value)) return value;
|
|
35932
|
-
return value;
|
|
35933
|
-
}
|
|
35934
|
-
return value;
|
|
35935
|
-
},
|
|
35936
|
-
flex: key == "id" ? false : !(colSize == null ? void 0 : colSize[key]),
|
|
35937
|
-
width: key == "id" ? 80 : (_a = colSize == null ? void 0 : colSize[key]) != null ? _a : void 0,
|
|
35938
|
-
editable: (_b = editableFields == null ? void 0 : editableFields.includes(key)) != null ? _b : false,
|
|
35939
|
-
type: typeof rows[0][key] === "number" ? "number" : "string",
|
|
35940
|
-
// When wrapText is enabled, allow cells to grow vertically
|
|
35941
|
-
...wrapText && {
|
|
35942
|
-
renderHeader: (params) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35943
|
-
"span",
|
|
35944
|
-
{
|
|
35945
|
-
style: {
|
|
35946
|
-
whiteSpace: "normal",
|
|
35947
|
-
lineHeight: 1.3,
|
|
35948
|
-
wordBreak: "break-word"
|
|
35949
|
-
},
|
|
35950
|
-
children: params.colDef.headerName
|
|
35951
|
-
}
|
|
35952
|
-
)
|
|
35953
|
-
},
|
|
35954
|
-
renderCell: (buttons == null ? void 0 : buttons[key]) ? (params) => {
|
|
35955
|
-
var _a2, _b2, _c;
|
|
35956
|
-
const children = ((_a2 = buttons == null ? void 0 : buttons[key]) == null ? void 0 : _a2.type) == "input" ? null : (_b2 = params == null ? void 0 : params.row) == null ? void 0 : _b2[key];
|
|
35957
|
-
return import_react5.default.cloneElement(buttons[key], {
|
|
35958
|
-
className: `${(_c = params == null ? void 0 : params.className) != null ? _c : ""} m-auto text-xs`,
|
|
35959
|
-
children,
|
|
35960
|
-
row: params == null ? void 0 : params.row,
|
|
35961
|
-
onClick: async (e) => {
|
|
35962
|
-
var _a3, _b3;
|
|
35963
|
-
e.row = params == null ? void 0 : params.row;
|
|
35964
|
-
if ((_b3 = (_a3 = buttons[key]) == null ? void 0 : _a3.props) == null ? void 0 : _b3.onClick) {
|
|
35965
|
-
const newVal = await buttons[key].props.onClick(e);
|
|
35966
|
-
if (newVal) handleRowUpdate({ ...e.row, newVal });
|
|
35967
|
-
}
|
|
35968
|
-
}
|
|
35969
|
-
});
|
|
35970
|
-
} : wrapText ? (params) => {
|
|
35971
|
-
var _a2;
|
|
35972
|
-
return (
|
|
35973
|
-
// Plain cell with wrap — no custom button
|
|
35974
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35975
|
-
"span",
|
|
35976
|
-
{
|
|
35977
|
-
style: {
|
|
35978
|
-
whiteSpace: "normal",
|
|
35979
|
-
wordBreak: "break-word",
|
|
35980
|
-
lineHeight: 1.4,
|
|
35981
|
-
padding: "6px 0",
|
|
35982
|
-
display: "block"
|
|
35983
|
-
},
|
|
35984
|
-
children: (_a2 = params.formattedValue) != null ? _a2 : params.value
|
|
35985
|
-
}
|
|
35986
|
-
)
|
|
35987
|
-
);
|
|
35988
|
-
} : null
|
|
35989
|
-
};
|
|
35990
|
-
});
|
|
35991
|
-
if (modal) {
|
|
35992
|
-
cols.unshift({
|
|
35993
|
-
field: "Modal",
|
|
35994
|
-
headerName: "Modal",
|
|
35995
|
-
editable: false,
|
|
35996
|
-
type: "string",
|
|
35997
|
-
width: 10,
|
|
35998
|
-
renderCell: (params) => {
|
|
35999
|
-
var _a;
|
|
36000
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36001
|
-
Button,
|
|
36002
|
-
{
|
|
36003
|
-
className: "text-xs",
|
|
36004
|
-
onClick: () => onModalOpen(params.row),
|
|
36005
|
-
icon: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(EditIcon, {}),
|
|
36006
|
-
children: (_a = params == null ? void 0 : params.row) == null ? void 0 : _a["Modal"]
|
|
36007
|
-
}
|
|
36008
|
-
);
|
|
36009
|
-
}
|
|
36010
|
-
});
|
|
36011
|
-
}
|
|
36012
|
-
return cols;
|
|
36013
|
-
}, [rows, wrapText]);
|
|
36014
|
-
}
|
|
36015
35918
|
function SearchBar({
|
|
36016
35919
|
value,
|
|
36017
35920
|
onChange
|
|
36018
35921
|
}) {
|
|
36019
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.
|
|
36020
|
-
|
|
36021
|
-
|
|
36022
|
-
|
|
36023
|
-
|
|
36024
|
-
|
|
36025
|
-
|
|
36026
|
-
|
|
36027
|
-
|
|
36028
|
-
|
|
36029
|
-
"path",
|
|
36030
|
-
{
|
|
36031
|
-
fillRule: "evenodd",
|
|
36032
|
-
d: "M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z",
|
|
36033
|
-
clipRule: "evenodd"
|
|
36034
|
-
}
|
|
36035
|
-
)
|
|
36036
|
-
}
|
|
36037
|
-
),
|
|
36038
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36039
|
-
"input",
|
|
36040
|
-
{
|
|
36041
|
-
type: "text",
|
|
36042
|
-
value,
|
|
36043
|
-
onChange: (e) => onChange(e.target.value),
|
|
36044
|
-
placeholder: "Buscar\u2026",
|
|
36045
|
-
className: "w-full max-w-xs text-xs border border-gray-300 rounded px-2 py-1 outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-200 transition"
|
|
36046
|
-
}
|
|
36047
|
-
),
|
|
36048
|
-
value && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36049
|
-
"button",
|
|
36050
|
-
{
|
|
36051
|
-
onClick: () => onChange(""),
|
|
36052
|
-
className: "text-gray-400 hover:text-gray-600 text-sm leading-none",
|
|
36053
|
-
title: "Limpiar b\xFAsqueda",
|
|
36054
|
-
children: "\xD7"
|
|
36055
|
-
}
|
|
36056
|
-
)
|
|
36057
|
-
] });
|
|
35922
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex items-center gap-2 px-2 pb-1", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35923
|
+
"input",
|
|
35924
|
+
{
|
|
35925
|
+
type: "text",
|
|
35926
|
+
value,
|
|
35927
|
+
onChange: (e) => onChange(e.target.value),
|
|
35928
|
+
placeholder: "Buscar\u2026",
|
|
35929
|
+
className: "w-full max-w-xs text-xs border border-gray-300 rounded px-2 py-1"
|
|
35930
|
+
}
|
|
35931
|
+
) });
|
|
36058
35932
|
}
|
|
36059
35933
|
function rowMatchesSearch(row, query) {
|
|
36060
35934
|
if (!query.trim()) return true;
|
|
@@ -36084,32 +35958,58 @@ function IHTable({
|
|
|
36084
35958
|
rowHeight,
|
|
36085
35959
|
wrapText = false,
|
|
36086
35960
|
density = "standard",
|
|
36087
|
-
searchable = false
|
|
35961
|
+
searchable = false,
|
|
35962
|
+
autoHeight = false
|
|
36088
35963
|
}) {
|
|
36089
35964
|
var _a;
|
|
36090
|
-
if (modal && onSelect)
|
|
36091
|
-
throw new Error("Solo se puede usar modal o onSelect por separado");
|
|
36092
35965
|
const [open, setOpen] = (0, import_react5.useState)(false);
|
|
36093
35966
|
const [rows, setRows] = (0, import_react5.useState)(data);
|
|
35967
|
+
const [modalIndex, setModalIndex] = (0, import_react5.useState)(null);
|
|
36094
35968
|
const [selectedRows, setSelectedRows] = (0, import_react5.useState)({
|
|
36095
35969
|
type: "include",
|
|
36096
35970
|
ids: /* @__PURE__ */ new Set()
|
|
36097
35971
|
});
|
|
36098
|
-
const [modalRow, setModalRow] = (0, import_react5.useState)();
|
|
36099
35972
|
const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
|
|
36100
|
-
const resolvedButtons = modal ? { ...buttons, Modal: "" } : buttons;
|
|
36101
35973
|
(0, import_react5.useEffect)(() => {
|
|
36102
35974
|
setRows(data);
|
|
36103
35975
|
}, [data]);
|
|
35976
|
+
const filteredRows = (0, import_react5.useMemo)(() => {
|
|
35977
|
+
if ((selectedRows == null ? void 0 : selectedRows.type) === "exclude") {
|
|
35978
|
+
return rows.filter((r) => !Array.from(selectedRows.ids).includes(r.id));
|
|
35979
|
+
}
|
|
35980
|
+
if ((selectedRows == null ? void 0 : selectedRows.type) === "include") {
|
|
35981
|
+
return rows.filter((r) => Array.from(selectedRows.ids).includes(r.id));
|
|
35982
|
+
}
|
|
35983
|
+
return [];
|
|
35984
|
+
}, [selectedRows, rows]);
|
|
35985
|
+
const displayRows = (0, import_react5.useMemo)(
|
|
35986
|
+
() => searchable ? rows.filter((r) => rowMatchesSearch(r, searchQuery)) : rows,
|
|
35987
|
+
[rows, searchQuery, searchable]
|
|
35988
|
+
);
|
|
35989
|
+
const modalRow = modalIndex != null ? displayRows[modalIndex] : void 0;
|
|
36104
35990
|
const handleModalOpen = (row) => {
|
|
36105
|
-
|
|
35991
|
+
const index = displayRows.findIndex((r) => r.id === row.id);
|
|
35992
|
+
if (index === -1) return;
|
|
35993
|
+
setModalIndex(index);
|
|
36106
35994
|
setOpen(true);
|
|
36107
35995
|
};
|
|
36108
35996
|
const handleClose = async () => {
|
|
36109
|
-
const pass = onCloseModal ? await
|
|
35997
|
+
const pass = onCloseModal ? await onCloseModal(modalRow) : true;
|
|
36110
35998
|
if (!pass) return;
|
|
36111
35999
|
setOpen(false);
|
|
36112
|
-
|
|
36000
|
+
setModalIndex(null);
|
|
36001
|
+
};
|
|
36002
|
+
const handlePrevRow = () => {
|
|
36003
|
+
setModalIndex((prev) => {
|
|
36004
|
+
if (prev == null) return prev;
|
|
36005
|
+
return Math.max(prev - 1, 0);
|
|
36006
|
+
});
|
|
36007
|
+
};
|
|
36008
|
+
const handleNextRow = () => {
|
|
36009
|
+
setModalIndex((prev) => {
|
|
36010
|
+
if (prev == null) return prev;
|
|
36011
|
+
return Math.min(prev + 1, displayRows.length - 1);
|
|
36012
|
+
});
|
|
36113
36013
|
};
|
|
36114
36014
|
const handleRowUpdate = (newRow) => {
|
|
36115
36015
|
if (!newRow.id) throw new Error("Fila sin id");
|
|
@@ -36119,38 +36019,82 @@ function IHTable({
|
|
|
36119
36019
|
);
|
|
36120
36020
|
return updated;
|
|
36121
36021
|
};
|
|
36122
|
-
const
|
|
36123
|
-
|
|
36124
|
-
|
|
36125
|
-
|
|
36126
|
-
|
|
36127
|
-
return
|
|
36022
|
+
const resolvedButtons = modal ? { ...buttons, Modal: "" } : buttons;
|
|
36023
|
+
const columns = (0, import_react5.useMemo)(() => {
|
|
36024
|
+
if (!displayRows.length) return [];
|
|
36025
|
+
const cols = Object.keys(displayRows[0]).filter((key) => !key.startsWith("_") && !hideColumns.includes(key)).map((key) => {
|
|
36026
|
+
var _a2, _b;
|
|
36027
|
+
return {
|
|
36028
|
+
field: key,
|
|
36029
|
+
headerName: key,
|
|
36030
|
+
flex: key == "id" ? false : !(colSize == null ? void 0 : colSize[key]),
|
|
36031
|
+
width: key == "id" ? 80 : (_a2 = colSize == null ? void 0 : colSize[key]) != null ? _a2 : void 0,
|
|
36032
|
+
editable: (_b = editableFields == null ? void 0 : editableFields.includes(key)) != null ? _b : false,
|
|
36033
|
+
type: typeof displayRows[0][key] === "number" ? "number" : "string",
|
|
36034
|
+
valueFormatter: (value) => {
|
|
36035
|
+
if (value == null || value === "") return "";
|
|
36036
|
+
const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
|
|
36037
|
+
if (`${value}`.match(isDate)) {
|
|
36038
|
+
return value.toString().split("T")[0].split("-").reverse().join("/");
|
|
36039
|
+
}
|
|
36040
|
+
const splited = `${value}`.split(".");
|
|
36041
|
+
const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(regular_expresions_default.number));
|
|
36042
|
+
if (hasDecimals) {
|
|
36043
|
+
return [
|
|
36044
|
+
currentCoin,
|
|
36045
|
+
(+`${value}`).toLocaleString("en-US", {
|
|
36046
|
+
minimumFractionDigits: 2,
|
|
36047
|
+
maximumFractionDigits: 2
|
|
36048
|
+
})
|
|
36049
|
+
].join(" ");
|
|
36050
|
+
}
|
|
36051
|
+
return value;
|
|
36052
|
+
},
|
|
36053
|
+
renderCell: (resolvedButtons == null ? void 0 : resolvedButtons[key]) ? (params) => {
|
|
36054
|
+
var _a3, _b2, _c;
|
|
36055
|
+
const children = ((_a3 = resolvedButtons == null ? void 0 : resolvedButtons[key]) == null ? void 0 : _a3.type) == "input" ? null : (_b2 = params == null ? void 0 : params.row) == null ? void 0 : _b2[key];
|
|
36056
|
+
return import_react5.default.cloneElement(resolvedButtons[key], {
|
|
36057
|
+
className: `${(_c = params == null ? void 0 : params.className) != null ? _c : ""} m-auto text-xs`,
|
|
36058
|
+
children,
|
|
36059
|
+
row: params == null ? void 0 : params.row,
|
|
36060
|
+
onClick: async (e) => {
|
|
36061
|
+
var _a4, _b3;
|
|
36062
|
+
e.row = params == null ? void 0 : params.row;
|
|
36063
|
+
if ((_b3 = (_a4 = resolvedButtons[key]) == null ? void 0 : _a4.props) == null ? void 0 : _b3.onClick) {
|
|
36064
|
+
const newVal = await resolvedButtons[key].props.onClick(e);
|
|
36065
|
+
if (newVal) {
|
|
36066
|
+
handleRowUpdate({ ...e.row, newVal });
|
|
36067
|
+
}
|
|
36068
|
+
}
|
|
36069
|
+
}
|
|
36070
|
+
});
|
|
36071
|
+
} : null
|
|
36072
|
+
};
|
|
36073
|
+
});
|
|
36074
|
+
if (modal) {
|
|
36075
|
+
cols.unshift({
|
|
36076
|
+
field: "Modal",
|
|
36077
|
+
headerName: "Modal",
|
|
36078
|
+
width: 100,
|
|
36079
|
+
renderCell: (params) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36080
|
+
Button,
|
|
36081
|
+
{
|
|
36082
|
+
className: "text-xs",
|
|
36083
|
+
onClick: () => handleModalOpen(params.row),
|
|
36084
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(EditIcon, {}),
|
|
36085
|
+
children: "Abrir"
|
|
36086
|
+
}
|
|
36087
|
+
)
|
|
36088
|
+
});
|
|
36128
36089
|
}
|
|
36129
|
-
return
|
|
36130
|
-
}, [
|
|
36131
|
-
const displayRows = (0, import_react5.useMemo)(
|
|
36132
|
-
() => searchable ? rows.filter((r) => rowMatchesSearch(r, searchQuery)) : rows,
|
|
36133
|
-
[rows, searchQuery, searchable]
|
|
36134
|
-
);
|
|
36135
|
-
const columns = useColumns(
|
|
36136
|
-
displayRows,
|
|
36137
|
-
currentCoin,
|
|
36138
|
-
{
|
|
36139
|
-
flex,
|
|
36140
|
-
editableFields,
|
|
36141
|
-
buttons: resolvedButtons,
|
|
36142
|
-
hideColumns,
|
|
36143
|
-
modal,
|
|
36144
|
-
wrapText,
|
|
36145
|
-
handleRowUpdate,
|
|
36146
|
-
onModalOpen: handleModalOpen
|
|
36147
|
-
},
|
|
36148
|
-
colSize
|
|
36149
|
-
);
|
|
36090
|
+
return cols;
|
|
36091
|
+
}, [displayRows]);
|
|
36150
36092
|
if (!rows.length) return null;
|
|
36151
36093
|
const rowHeightProps = wrapText ? { getRowHeight: () => "auto" } : rowHeight != null ? { rowHeight } : {};
|
|
36094
|
+
const containerHeight = autoHeight ? void 0 : (_a = HEIGHT_MAP[displayRows.length]) != null ? _a : height;
|
|
36095
|
+
const hideFooter = autoHeight || displayRows.length <= Object.keys(HEIGHT_MAP).length;
|
|
36152
36096
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "m-2", children: [
|
|
36153
|
-
header && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "font-bold
|
|
36097
|
+
header && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "font-bold p-2", children: header }),
|
|
36154
36098
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-between", children: [
|
|
36155
36099
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36156
36100
|
Toolbar,
|
|
@@ -36170,9 +36114,8 @@ function IHTable({
|
|
|
36170
36114
|
sx: {
|
|
36171
36115
|
display: "flex",
|
|
36172
36116
|
flexDirection: "column",
|
|
36173
|
-
height:
|
|
36174
|
-
width
|
|
36175
|
-
zIndex: 999999999
|
|
36117
|
+
height: containerHeight,
|
|
36118
|
+
width
|
|
36176
36119
|
},
|
|
36177
36120
|
children: [
|
|
36178
36121
|
modal && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -36181,7 +36124,11 @@ function IHTable({
|
|
|
36181
36124
|
open,
|
|
36182
36125
|
onClose: handleClose,
|
|
36183
36126
|
modal,
|
|
36184
|
-
selectedRow: modalRow
|
|
36127
|
+
selectedRow: modalRow,
|
|
36128
|
+
onPrev: handlePrevRow,
|
|
36129
|
+
onNext: handleNextRow,
|
|
36130
|
+
hasPrev: (modalIndex != null ? modalIndex : 0) > 0,
|
|
36131
|
+
hasNext: (modalIndex != null ? modalIndex : -1) < displayRows.length - 1
|
|
36185
36132
|
}
|
|
36186
36133
|
),
|
|
36187
36134
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -36191,6 +36138,7 @@ function IHTable({
|
|
|
36191
36138
|
rows: displayRows,
|
|
36192
36139
|
columns,
|
|
36193
36140
|
density,
|
|
36141
|
+
autoHeight,
|
|
36194
36142
|
checkboxSelection: Boolean(onSelect),
|
|
36195
36143
|
rowSelectionModel: selectedRows,
|
|
36196
36144
|
onRowSelectionModelChange: !modal ? setSelectedRows : void 0,
|
|
@@ -36198,41 +36146,20 @@ function IHTable({
|
|
|
36198
36146
|
sx: {
|
|
36199
36147
|
fontSize,
|
|
36200
36148
|
"& .MuiDataGrid-cell": {
|
|
36201
|
-
fontSize
|
|
36202
|
-
// Allow cells to wrap text when wrapText is enabled
|
|
36203
|
-
...wrapText && {
|
|
36204
|
-
alignItems: "flex-start",
|
|
36205
|
-
paddingTop: "8px",
|
|
36206
|
-
paddingBottom: "8px",
|
|
36207
|
-
whiteSpace: "normal",
|
|
36208
|
-
wordBreak: "break-word"
|
|
36209
|
-
}
|
|
36149
|
+
fontSize
|
|
36210
36150
|
},
|
|
36211
36151
|
"& .MuiDataGrid-columnHeader": {
|
|
36212
|
-
fontSize
|
|
36213
|
-
...wrapText && {
|
|
36214
|
-
whiteSpace: "normal",
|
|
36215
|
-
"& .MuiDataGrid-columnHeaderTitle": {
|
|
36216
|
-
whiteSpace: "normal",
|
|
36217
|
-
lineHeight: 1.3,
|
|
36218
|
-
wordBreak: "break-word"
|
|
36219
|
-
}
|
|
36220
|
-
}
|
|
36152
|
+
fontSize
|
|
36221
36153
|
},
|
|
36222
36154
|
"& .MuiDataGrid-cell--editable": {
|
|
36223
36155
|
backgroundColor: "#c6d8f0",
|
|
36224
36156
|
fontWeight: 500
|
|
36225
|
-
},
|
|
36226
|
-
...displayRows.length <= Object.keys(HEIGHT_MAP).length && {
|
|
36227
|
-
"& .MuiDataGrid-filler": {
|
|
36228
|
-
display: "none"
|
|
36229
|
-
}
|
|
36230
36157
|
}
|
|
36231
36158
|
},
|
|
36232
36159
|
editMode: "row",
|
|
36233
36160
|
processRowUpdate: handleRowUpdate,
|
|
36234
36161
|
pageSizeOptions: [5, 10],
|
|
36235
|
-
hideFooter
|
|
36162
|
+
hideFooter
|
|
36236
36163
|
}
|
|
36237
36164
|
)
|
|
36238
36165
|
]
|