next-recomponents 2.0.30 → 2.0.32
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 +0 -27
- package/dist/index.d.ts +0 -27
- package/dist/index.js +168 -245
- package/dist/index.mjs +175 -252
- package/package.json +1 -1
- package/src/table/index.tsx +218 -312
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,35 +89,9 @@ 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;
|
|
115
|
-
/**
|
|
116
|
-
* Cuando es true, el alto del contenedor se ajusta automáticamente
|
|
117
|
-
* al contenido de la tabla, eliminando el scroll vertical.
|
|
118
|
-
* Compatible con `wrapText` (filas de alto variable) y con
|
|
119
|
-
* cualquier valor de `density`. Cuando está activo, las props
|
|
120
|
-
* `height` y `HEIGHT_MAP` se ignoran.
|
|
121
|
-
*/
|
|
122
95
|
autoHeight?: boolean;
|
|
123
96
|
[key: string]: any;
|
|
124
97
|
}
|
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,35 +89,9 @@ 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;
|
|
115
|
-
/**
|
|
116
|
-
* Cuando es true, el alto del contenedor se ajusta automáticamente
|
|
117
|
-
* al contenido de la tabla, eliminando el scroll vertical.
|
|
118
|
-
* Compatible con `wrapText` (filas de alto variable) y con
|
|
119
|
-
* cualquier valor de `density`. Cuando está activo, las props
|
|
120
|
-
* `height` y `HEIGHT_MAP` se ignoran.
|
|
121
|
-
*/
|
|
122
95
|
autoHeight?: boolean;
|
|
123
96
|
[key: string]: any;
|
|
124
97
|
}
|
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,69 @@ 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
|
+
key: selectedRow.id,
|
|
35886
|
+
row: selectedRow,
|
|
35887
|
+
hide: onClose
|
|
35888
|
+
}
|
|
35858
35889
|
) })
|
|
35859
35890
|
] });
|
|
35860
35891
|
}
|
|
35861
|
-
function Toolbar({
|
|
35862
|
-
exportName,
|
|
35863
|
-
onSave,
|
|
35864
|
-
onSelect,
|
|
35865
|
-
rows,
|
|
35866
|
-
filteredRows
|
|
35867
|
-
}) {
|
|
35892
|
+
function Toolbar({ exportName, onSave, onSelect, rows, filteredRows }) {
|
|
35868
35893
|
const excel = useExcel();
|
|
35869
35894
|
const stripMeta = (r) => {
|
|
35870
35895
|
const { _edited, ...rest } = r;
|
|
35871
35896
|
return rest;
|
|
35872
35897
|
};
|
|
35873
35898
|
if (!exportName && !onSave && !onSelect) return null;
|
|
35874
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex gap-2
|
|
35899
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex gap-2 p-2 text-xs", children: [
|
|
35875
35900
|
exportName && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
35876
35901
|
Button,
|
|
35877
35902
|
{
|
|
@@ -35891,170 +35916,20 @@ function Toolbar({
|
|
|
35891
35916
|
) : onSave && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { onClick: () => onSave(rows.map(stripMeta)), children: "Guardar" })
|
|
35892
35917
|
] });
|
|
35893
35918
|
}
|
|
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
35919
|
function SearchBar({
|
|
36016
35920
|
value,
|
|
36017
35921
|
onChange
|
|
36018
35922
|
}) {
|
|
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
|
-
] });
|
|
35923
|
+
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)(
|
|
35924
|
+
"input",
|
|
35925
|
+
{
|
|
35926
|
+
type: "text",
|
|
35927
|
+
value,
|
|
35928
|
+
onChange: (e) => onChange(e.target.value),
|
|
35929
|
+
placeholder: "Buscar\u2026",
|
|
35930
|
+
className: "w-full max-w-xs text-xs border border-gray-300 rounded px-2 py-1"
|
|
35931
|
+
}
|
|
35932
|
+
) });
|
|
36058
35933
|
}
|
|
36059
35934
|
function rowMatchesSearch(row, query) {
|
|
36060
35935
|
if (!query.trim()) return true;
|
|
@@ -36088,29 +35963,54 @@ function IHTable({
|
|
|
36088
35963
|
autoHeight = false
|
|
36089
35964
|
}) {
|
|
36090
35965
|
var _a;
|
|
36091
|
-
if (modal && onSelect)
|
|
36092
|
-
throw new Error("Solo se puede usar modal o onSelect por separado");
|
|
36093
35966
|
const [open, setOpen] = (0, import_react5.useState)(false);
|
|
36094
35967
|
const [rows, setRows] = (0, import_react5.useState)(data);
|
|
35968
|
+
const [modalIndex, setModalIndex] = (0, import_react5.useState)(null);
|
|
36095
35969
|
const [selectedRows, setSelectedRows] = (0, import_react5.useState)({
|
|
36096
35970
|
type: "include",
|
|
36097
35971
|
ids: /* @__PURE__ */ new Set()
|
|
36098
35972
|
});
|
|
36099
|
-
const [modalRow, setModalRow] = (0, import_react5.useState)();
|
|
36100
35973
|
const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
|
|
36101
|
-
const resolvedButtons = modal ? { ...buttons, Modal: "" } : buttons;
|
|
36102
35974
|
(0, import_react5.useEffect)(() => {
|
|
36103
35975
|
setRows(data);
|
|
36104
35976
|
}, [data]);
|
|
35977
|
+
const filteredRows = (0, import_react5.useMemo)(() => {
|
|
35978
|
+
if ((selectedRows == null ? void 0 : selectedRows.type) === "exclude") {
|
|
35979
|
+
return rows.filter((r) => !Array.from(selectedRows.ids).includes(r.id));
|
|
35980
|
+
}
|
|
35981
|
+
if ((selectedRows == null ? void 0 : selectedRows.type) === "include") {
|
|
35982
|
+
return rows.filter((r) => Array.from(selectedRows.ids).includes(r.id));
|
|
35983
|
+
}
|
|
35984
|
+
return [];
|
|
35985
|
+
}, [selectedRows, rows]);
|
|
35986
|
+
const displayRows = (0, import_react5.useMemo)(
|
|
35987
|
+
() => searchable ? rows.filter((r) => rowMatchesSearch(r, searchQuery)) : rows,
|
|
35988
|
+
[rows, searchQuery, searchable]
|
|
35989
|
+
);
|
|
35990
|
+
const modalRow = modalIndex != null ? displayRows[modalIndex] : void 0;
|
|
36105
35991
|
const handleModalOpen = (row) => {
|
|
36106
|
-
|
|
35992
|
+
const index = displayRows.findIndex((r) => r.id === row.id);
|
|
35993
|
+
if (index === -1) return;
|
|
35994
|
+
setModalIndex(index);
|
|
36107
35995
|
setOpen(true);
|
|
36108
35996
|
};
|
|
36109
35997
|
const handleClose = async () => {
|
|
36110
|
-
const pass = onCloseModal ? await
|
|
35998
|
+
const pass = onCloseModal ? await onCloseModal(modalRow) : true;
|
|
36111
35999
|
if (!pass) return;
|
|
36112
36000
|
setOpen(false);
|
|
36113
|
-
|
|
36001
|
+
setModalIndex(null);
|
|
36002
|
+
};
|
|
36003
|
+
const handlePrevRow = () => {
|
|
36004
|
+
setModalIndex((prev) => {
|
|
36005
|
+
if (prev == null) return prev;
|
|
36006
|
+
return Math.max(prev - 1, 0);
|
|
36007
|
+
});
|
|
36008
|
+
};
|
|
36009
|
+
const handleNextRow = () => {
|
|
36010
|
+
setModalIndex((prev) => {
|
|
36011
|
+
if (prev == null) return prev;
|
|
36012
|
+
return Math.min(prev + 1, displayRows.length - 1);
|
|
36013
|
+
});
|
|
36114
36014
|
};
|
|
36115
36015
|
const handleRowUpdate = (newRow) => {
|
|
36116
36016
|
if (!newRow.id) throw new Error("Fila sin id");
|
|
@@ -36120,40 +36020,82 @@ function IHTable({
|
|
|
36120
36020
|
);
|
|
36121
36021
|
return updated;
|
|
36122
36022
|
};
|
|
36123
|
-
const
|
|
36124
|
-
|
|
36125
|
-
|
|
36126
|
-
|
|
36127
|
-
|
|
36128
|
-
return
|
|
36023
|
+
const resolvedButtons = modal ? { ...buttons, Modal: "" } : buttons;
|
|
36024
|
+
const columns = (0, import_react5.useMemo)(() => {
|
|
36025
|
+
if (!displayRows.length) return [];
|
|
36026
|
+
const cols = Object.keys(displayRows[0]).filter((key) => !key.startsWith("_") && !hideColumns.includes(key)).map((key) => {
|
|
36027
|
+
var _a2, _b;
|
|
36028
|
+
return {
|
|
36029
|
+
field: key,
|
|
36030
|
+
headerName: key,
|
|
36031
|
+
flex: key == "id" ? false : !(colSize == null ? void 0 : colSize[key]),
|
|
36032
|
+
width: key == "id" ? 80 : (_a2 = colSize == null ? void 0 : colSize[key]) != null ? _a2 : void 0,
|
|
36033
|
+
editable: (_b = editableFields == null ? void 0 : editableFields.includes(key)) != null ? _b : false,
|
|
36034
|
+
type: typeof displayRows[0][key] === "number" ? "number" : "string",
|
|
36035
|
+
valueFormatter: (value) => {
|
|
36036
|
+
if (value == null || value === "") return "";
|
|
36037
|
+
const isDate = /(\d{4}-\d{2}-\d{2})(T[\d:,.+-]*(Z)?)?/;
|
|
36038
|
+
if (`${value}`.match(isDate)) {
|
|
36039
|
+
return value.toString().split("T")[0].split("-").reverse().join("/");
|
|
36040
|
+
}
|
|
36041
|
+
const splited = `${value}`.split(".");
|
|
36042
|
+
const hasDecimals = splited.length == 2 && splited.every((v) => `${v}`.match(regular_expresions_default.number));
|
|
36043
|
+
if (hasDecimals) {
|
|
36044
|
+
return [
|
|
36045
|
+
currentCoin,
|
|
36046
|
+
(+`${value}`).toLocaleString("en-US", {
|
|
36047
|
+
minimumFractionDigits: 2,
|
|
36048
|
+
maximumFractionDigits: 2
|
|
36049
|
+
})
|
|
36050
|
+
].join(" ");
|
|
36051
|
+
}
|
|
36052
|
+
return value;
|
|
36053
|
+
},
|
|
36054
|
+
renderCell: (resolvedButtons == null ? void 0 : resolvedButtons[key]) ? (params) => {
|
|
36055
|
+
var _a3, _b2, _c;
|
|
36056
|
+
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];
|
|
36057
|
+
return import_react5.default.cloneElement(resolvedButtons[key], {
|
|
36058
|
+
className: `${(_c = params == null ? void 0 : params.className) != null ? _c : ""} m-auto text-xs`,
|
|
36059
|
+
children,
|
|
36060
|
+
row: params == null ? void 0 : params.row,
|
|
36061
|
+
onClick: async (e) => {
|
|
36062
|
+
var _a4, _b3;
|
|
36063
|
+
e.row = params == null ? void 0 : params.row;
|
|
36064
|
+
if ((_b3 = (_a4 = resolvedButtons[key]) == null ? void 0 : _a4.props) == null ? void 0 : _b3.onClick) {
|
|
36065
|
+
const newVal = await resolvedButtons[key].props.onClick(e);
|
|
36066
|
+
if (newVal) {
|
|
36067
|
+
handleRowUpdate({ ...e.row, newVal });
|
|
36068
|
+
}
|
|
36069
|
+
}
|
|
36070
|
+
}
|
|
36071
|
+
});
|
|
36072
|
+
} : null
|
|
36073
|
+
};
|
|
36074
|
+
});
|
|
36075
|
+
if (modal) {
|
|
36076
|
+
cols.unshift({
|
|
36077
|
+
field: "Modal",
|
|
36078
|
+
headerName: "Modal",
|
|
36079
|
+
width: 100,
|
|
36080
|
+
renderCell: (params) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36081
|
+
Button,
|
|
36082
|
+
{
|
|
36083
|
+
className: "text-xs",
|
|
36084
|
+
onClick: () => handleModalOpen(params.row),
|
|
36085
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(EditIcon, {}),
|
|
36086
|
+
children: "Abrir"
|
|
36087
|
+
}
|
|
36088
|
+
)
|
|
36089
|
+
});
|
|
36129
36090
|
}
|
|
36130
|
-
return
|
|
36131
|
-
}, [
|
|
36132
|
-
const displayRows = (0, import_react5.useMemo)(
|
|
36133
|
-
() => searchable ? rows.filter((r) => rowMatchesSearch(r, searchQuery)) : rows,
|
|
36134
|
-
[rows, searchQuery, searchable]
|
|
36135
|
-
);
|
|
36136
|
-
const columns = useColumns(
|
|
36137
|
-
displayRows,
|
|
36138
|
-
currentCoin,
|
|
36139
|
-
{
|
|
36140
|
-
flex,
|
|
36141
|
-
editableFields,
|
|
36142
|
-
buttons: resolvedButtons,
|
|
36143
|
-
hideColumns,
|
|
36144
|
-
modal,
|
|
36145
|
-
wrapText,
|
|
36146
|
-
handleRowUpdate,
|
|
36147
|
-
onModalOpen: handleModalOpen
|
|
36148
|
-
},
|
|
36149
|
-
colSize
|
|
36150
|
-
);
|
|
36091
|
+
return cols;
|
|
36092
|
+
}, [displayRows]);
|
|
36151
36093
|
if (!rows.length) return null;
|
|
36152
36094
|
const rowHeightProps = wrapText ? { getRowHeight: () => "auto" } : rowHeight != null ? { rowHeight } : {};
|
|
36153
36095
|
const containerHeight = autoHeight ? void 0 : (_a = HEIGHT_MAP[displayRows.length]) != null ? _a : height;
|
|
36154
36096
|
const hideFooter = autoHeight || displayRows.length <= Object.keys(HEIGHT_MAP).length;
|
|
36155
36097
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "m-2", children: [
|
|
36156
|
-
header && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "font-bold
|
|
36098
|
+
header && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "font-bold p-2", children: header }),
|
|
36157
36099
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex justify-between", children: [
|
|
36158
36100
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
36159
36101
|
Toolbar,
|
|
@@ -36173,10 +36115,8 @@ function IHTable({
|
|
|
36173
36115
|
sx: {
|
|
36174
36116
|
display: "flex",
|
|
36175
36117
|
flexDirection: "column",
|
|
36176
|
-
// undefined height lets the child DataGrid size itself freely
|
|
36177
36118
|
height: containerHeight,
|
|
36178
|
-
width
|
|
36179
|
-
zIndex: 999999999
|
|
36119
|
+
width
|
|
36180
36120
|
},
|
|
36181
36121
|
children: [
|
|
36182
36122
|
modal && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -36185,7 +36125,11 @@ function IHTable({
|
|
|
36185
36125
|
open,
|
|
36186
36126
|
onClose: handleClose,
|
|
36187
36127
|
modal,
|
|
36188
|
-
selectedRow: modalRow
|
|
36128
|
+
selectedRow: modalRow,
|
|
36129
|
+
onPrev: handlePrevRow,
|
|
36130
|
+
onNext: handleNextRow,
|
|
36131
|
+
hasPrev: (modalIndex != null ? modalIndex : 0) > 0,
|
|
36132
|
+
hasNext: (modalIndex != null ? modalIndex : -1) < displayRows.length - 1
|
|
36189
36133
|
}
|
|
36190
36134
|
),
|
|
36191
36135
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -36203,35 +36147,14 @@ function IHTable({
|
|
|
36203
36147
|
sx: {
|
|
36204
36148
|
fontSize,
|
|
36205
36149
|
"& .MuiDataGrid-cell": {
|
|
36206
|
-
fontSize
|
|
36207
|
-
// Allow cells to wrap text when wrapText is enabled
|
|
36208
|
-
...wrapText && {
|
|
36209
|
-
alignItems: "flex-start",
|
|
36210
|
-
paddingTop: "8px",
|
|
36211
|
-
paddingBottom: "8px",
|
|
36212
|
-
whiteSpace: "normal",
|
|
36213
|
-
wordBreak: "break-word"
|
|
36214
|
-
}
|
|
36150
|
+
fontSize
|
|
36215
36151
|
},
|
|
36216
36152
|
"& .MuiDataGrid-columnHeader": {
|
|
36217
|
-
fontSize
|
|
36218
|
-
...wrapText && {
|
|
36219
|
-
whiteSpace: "normal",
|
|
36220
|
-
"& .MuiDataGrid-columnHeaderTitle": {
|
|
36221
|
-
whiteSpace: "normal",
|
|
36222
|
-
lineHeight: 1.3,
|
|
36223
|
-
wordBreak: "break-word"
|
|
36224
|
-
}
|
|
36225
|
-
}
|
|
36153
|
+
fontSize
|
|
36226
36154
|
},
|
|
36227
36155
|
"& .MuiDataGrid-cell--editable": {
|
|
36228
36156
|
backgroundColor: "#c6d8f0",
|
|
36229
36157
|
fontWeight: 500
|
|
36230
|
-
},
|
|
36231
|
-
...displayRows.length <= Object.keys(HEIGHT_MAP).length && {
|
|
36232
|
-
"& .MuiDataGrid-filler": {
|
|
36233
|
-
display: "none"
|
|
36234
|
-
}
|
|
36235
36158
|
}
|
|
36236
36159
|
},
|
|
36237
36160
|
editMode: "row",
|