@m4l/components 9.3.24 → 9.3.25

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.
Files changed (105) hide show
  1. package/@types/export.d.ts +6 -0
  2. package/@types/types.d.ts +26 -1
  3. package/components/DataGrid/DataGrid.js +6 -2
  4. package/components/DataGrid/Datagrid.styles.js +67 -18
  5. package/components/DataGrid/constants.d.ts +19 -0
  6. package/components/DataGrid/formatters/ColumnIconFormatter/formatter.d.ts +1 -2
  7. package/components/DataGrid/formatters/ColumnIconFormatter/formatter.js +3 -6
  8. package/components/DataGrid/formatters/ColumnIconFormatter/types.d.ts +2 -4
  9. package/components/DataGrid/formatters/ColumnSetCheckFormatter/formatter.js +7 -1
  10. package/components/DataGrid/formatters/ColumnSetCheckFormatter/types.d.ts +1 -0
  11. package/components/DataGrid/formatters/ColumnTagsFormatter/formatter.d.ts +8 -0
  12. package/components/DataGrid/formatters/ColumnTagsFormatter/formatter.js +16 -0
  13. package/components/DataGrid/formatters/ColumnTagsFormatter/index.d.ts +3 -0
  14. package/components/DataGrid/formatters/ColumnTagsFormatter/index.js +1 -0
  15. package/components/DataGrid/formatters/ColumnTagsFormatter/types.d.ts +4 -0
  16. package/components/DataGrid/formatters/ColumnTagsFormatter/useColumnTags.d.ts +9 -0
  17. package/components/DataGrid/formatters/ColumnTagsFormatter/useColumnTags.js +60 -0
  18. package/components/DataGrid/formatters/index.d.ts +1 -0
  19. package/components/DataGrid/hooks/useModalCardDetail.d.ts +2 -2
  20. package/components/DataGrid/hooks/useModalCardDetail.js +49 -48
  21. package/components/DataGrid/slots/DataGridEnum.d.ts +2 -0
  22. package/components/DataGrid/slots/DataGridEnum.js +2 -0
  23. package/components/DataGrid/slots/DataGridSlot.d.ts +3 -1
  24. package/components/DataGrid/slots/DataGridSlot.js +45 -37
  25. package/components/DataGrid/subcomponents/Cards/helpers/calculateCardHeight.d.ts +18 -0
  26. package/components/DataGrid/subcomponents/Cards/helpers/calculateCardHeight.js +10 -0
  27. package/components/DataGrid/subcomponents/Cards/helpers/scrollToCardElement.d.ts +9 -0
  28. package/components/DataGrid/subcomponents/Cards/helpers/scrollToCardElement.js +25 -0
  29. package/components/DataGrid/subcomponents/Cards/hooks/useCardContent.d.ts +1 -2
  30. package/components/DataGrid/subcomponents/Cards/hooks/useCardContent.js +62 -73
  31. package/components/DataGrid/subcomponents/Cards/index.js +71 -16
  32. package/components/DataGrid/subcomponents/Cards/subcomponents/CardDetails/index.js +36 -18
  33. package/components/DataGrid/subcomponents/Cards/subcomponents/CardHeader/index.d.ts +1 -1
  34. package/components/DataGrid/subcomponents/Cards/subcomponents/CardHeader/index.js +13 -20
  35. package/components/DataGrid/subcomponents/Cards/subcomponents/CardRow/index.d.ts +6 -1
  36. package/components/DataGrid/subcomponents/Cards/subcomponents/CardRow/index.js +67 -36
  37. package/components/DataGrid/subcomponents/Cards/subcomponents/IntersectCard/index.js +9 -2
  38. package/components/DataGrid/subcomponents/Cards/subcomponents/LazyLoadCard/index.js +4 -2
  39. package/components/DataGrid/subcomponents/Cards/types.d.ts +50 -1
  40. package/components/DataGrid/subcomponents/CheckboxCellAdapter/index.js +5 -2
  41. package/components/DataGrid/subcomponents/ControlNavigate/ControlNavigate.js +1 -1
  42. package/components/DataGrid/subcomponents/HeaderActions/index.js +1 -1
  43. package/components/DataGrid/subcomponents/HeaderActions/subcomponents/RowsCount/index.js +1 -1
  44. package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfig/index.js +1 -1
  45. package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfigCards/index.js +1 -1
  46. package/components/DataGrid/subcomponents/HeaderActions/subcomponents/ViewMode/index.js +1 -1
  47. package/components/DataGrid/subcomponents/HeaderActions/subcomponents/hooks/useModalSettings/index.js +1 -1
  48. package/components/DataGrid/subcomponents/HeaderActions/subcomponents/hooks/useModalSettingsCards/index.js +1 -1
  49. package/components/DataGrid/subcomponents/Table/index.js +60 -41
  50. package/components/DataGrid/subcomponents/Table/subcomponents/CheckboxFormatter.js +16 -18
  51. package/components/DataGrid/subcomponents/Table/subcomponents/DraggableHeaderRenderer.js +3 -3
  52. package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.js +1 -1
  53. package/components/DataGrid/subcomponents/editors/TextEditor/index.js +1 -1
  54. package/components/DataGrid/tests/helpers/types.d.ts +3 -0
  55. package/components/DataGrid/types.d.ts +17 -2
  56. package/components/ObjectLogs/slots/ObjectLogsSlots.js +3 -5
  57. package/components/formatters/IconsFormatter/IconsFormatter.d.ts +6 -0
  58. package/components/formatters/IconsFormatter/IconsFormatter.js +22 -0
  59. package/components/formatters/IconsFormatter/IconsFormatter.styles.d.ts +2 -0
  60. package/components/formatters/IconsFormatter/IconsFormatter.styles.js +29 -0
  61. package/components/formatters/IconsFormatter/constants.d.ts +1 -0
  62. package/components/formatters/IconsFormatter/constants.js +4 -0
  63. package/components/{DataGrid/formatters/ColumnIconFormatter → formatters/IconsFormatter}/helpers/renderIcon.d.ts +2 -2
  64. package/components/formatters/IconsFormatter/helpers/renderIcon.js +24 -0
  65. package/components/formatters/IconsFormatter/helpers/renderMultipleIcons.d.ts +7 -0
  66. package/components/formatters/IconsFormatter/helpers/renderMultipleIcons.js +16 -0
  67. package/components/formatters/IconsFormatter/index.d.ts +3 -0
  68. package/components/formatters/IconsFormatter/index.js +1 -0
  69. package/components/formatters/IconsFormatter/slots/IconsFormatterEnum.d.ts +5 -0
  70. package/components/formatters/IconsFormatter/slots/IconsFormatterEnum.js +9 -0
  71. package/components/formatters/IconsFormatter/slots/IconsFormatterSlots.d.ts +9 -0
  72. package/components/formatters/IconsFormatter/slots/IconsFormatterSlots.js +22 -0
  73. package/components/formatters/IconsFormatter/types.d.ts +57 -0
  74. package/components/formatters/IconsFormatter/types.js +1 -0
  75. package/components/formatters/TagsFormatter/TagsFormatter.d.ts +5 -0
  76. package/components/formatters/TagsFormatter/TagsFormatter.js +28 -0
  77. package/components/formatters/TagsFormatter/TagsFormatter.styles.d.ts +2 -0
  78. package/components/formatters/TagsFormatter/TagsFormatter.styles.js +41 -0
  79. package/components/formatters/TagsFormatter/constants.d.ts +5 -0
  80. package/components/formatters/TagsFormatter/constants.js +11 -0
  81. package/components/formatters/TagsFormatter/helpers/renderMultipleTag.d.ts +8 -0
  82. package/components/formatters/TagsFormatter/helpers/renderMultipleTag.js +19 -0
  83. package/components/formatters/TagsFormatter/helpers/renderTag.d.ts +7 -0
  84. package/components/formatters/TagsFormatter/helpers/renderTag.js +9 -0
  85. package/components/formatters/TagsFormatter/helpers/validateHexColor.d.ts +8 -0
  86. package/components/formatters/TagsFormatter/helpers/validateHexColor.js +9 -0
  87. package/components/formatters/TagsFormatter/index.d.ts +2 -0
  88. package/components/formatters/TagsFormatter/index.js +1 -0
  89. package/components/formatters/TagsFormatter/slots/TagsFormatterEnum.d.ts +5 -0
  90. package/components/formatters/TagsFormatter/slots/TagsFormatterEnum.js +9 -0
  91. package/components/formatters/TagsFormatter/slots/TagsFormatterSlots.d.ts +6 -0
  92. package/components/formatters/TagsFormatter/slots/TagsFormatterSlots.js +16 -0
  93. package/components/formatters/TagsFormatter/subcomponents/Tag/Tag.d.ts +5 -0
  94. package/components/formatters/TagsFormatter/subcomponents/Tag/Tag.js +35 -0
  95. package/components/formatters/TagsFormatter/subcomponents/Tag/index.d.ts +1 -0
  96. package/components/formatters/TagsFormatter/subcomponents/Tag/index.js +1 -0
  97. package/components/formatters/TagsFormatter/types.d.ts +47 -0
  98. package/components/formatters/index.d.ts +6 -5
  99. package/contexts/ModalContext/index.js +5 -5
  100. package/index.js +62 -56
  101. package/package.json +1 -1
  102. package/components/DataGrid/formatters/ColumnIconFormatter/constants.js +0 -4
  103. package/components/DataGrid/formatters/ColumnIconFormatter/helpers/renderIcon.js +0 -58
  104. package/components/DataGrid/formatters/ColumnIconFormatter/helpers/renderMultipleIcons.d.ts +0 -7
  105. package/components/DataGrid/formatters/ColumnIconFormatter/helpers/renderMultipleIcons.js +0 -19
@@ -1,11 +1,10 @@
1
1
  import { styled } from "@mui/material/styles";
2
2
  import { MenuList, InputBase } from "@mui/material";
3
3
  import { D as DATAGRID_PREFIX_NAME } from "../constants.js";
4
- import { D as DataGridSlots, T as TextEditorSlots, A as ActionsSlots, C as ControlNavigateSlots, c as ColumnIconFormatterSlots, b as TableSlots, R as RowsCountSlots, a as ColumnsConfigSlots } from "./DataGridEnum.js";
4
+ import { D as DataGridSlots, T as TextEditorSlots, A as ActionsSlots, C as ControlNavigateSlots, b as TableSlots, R as RowsCountSlots, a as ColumnsConfigSlots, c as ColumnIconFormatterSlots } from "./DataGridEnum.js";
5
5
  import { d as dataGridStyles } from "../Datagrid.styles.js";
6
6
  import { I as Icon } from "../../Icon/Icon.js";
7
7
  import { C as Card } from "../../Card/Card.js";
8
- import { C as ContainerFlow } from "../../ContainerFlow/ContainerFlow.js";
9
8
  import { T as Typography } from "../../mui_extended/Typography/Typography.js";
10
9
  const DataGridRootStyled = styled("div", {
11
10
  name: DATAGRID_PREFIX_NAME,
@@ -91,7 +90,15 @@ const CardHeaderRightStyled = styled("div", {
91
90
  name: DATAGRID_PREFIX_NAME,
92
91
  slot: TableSlots.cardHeaderRight
93
92
  })(dataGridStyles.cardHeaderRight);
94
- const CardsContainerStyled = styled(ContainerFlow, {
93
+ const CardContentWrapperStyled = styled("div", {
94
+ name: DATAGRID_PREFIX_NAME,
95
+ slot: TableSlots.cardContentWrapper
96
+ })(dataGridStyles.cardContentWrapper);
97
+ const CardContentStyled = styled("div", {
98
+ name: DATAGRID_PREFIX_NAME,
99
+ slot: TableSlots.cardContent
100
+ })(dataGridStyles.cardContent);
101
+ const CardsContainerStyled = styled("div", {
95
102
  name: DATAGRID_PREFIX_NAME,
96
103
  slot: TableSlots.cardsContainer
97
104
  })(dataGridStyles.cardsContainer);
@@ -207,54 +214,55 @@ const ControlNavigateStyled = styled("div", {
207
214
  name: DATAGRID_PREFIX_NAME,
208
215
  slot: ControlNavigateSlots.controlNavigate
209
216
  })(dataGridStyles.controlNavigate);
210
- const ColumnIconFormatterStyled = styled("div", {
217
+ styled("div", {
211
218
  name: DATAGRID_PREFIX_NAME,
212
219
  slot: ColumnIconFormatterSlots.columnIconFormatter
213
220
  })(dataGridStyles.columnIconFormatter);
214
221
  export {
215
222
  ActionsRootStyled as A,
216
- DraggableHeaderRootStyled as B,
223
+ NameColumnStyled as B,
217
224
  CustomHeaderStyled as C,
218
225
  DataGridRootStyled as D,
219
226
  EditorCellWrapperStyled as E,
220
- ButtonHeaderActionsStyled as F,
221
- DraggableWrapperInputBaseStyled as G,
222
- IconSearchStyled as H,
227
+ DraggableHeaderRootStyled as F,
228
+ ButtonHeaderActionsStyled as G,
229
+ DraggableWrapperInputBaseStyled as H,
223
230
  IconColumnStyled as I,
224
- HeaderInputBaseStyled as J,
225
- HeaderRenderClickStyled as K,
231
+ IconSearchStyled as J,
232
+ HeaderInputBaseStyled as K,
226
233
  LabelHeaderColumnStyled as L,
227
234
  MenuListStyled as M,
228
235
  NameColumnIconStyled as N,
229
- InputTextEditorStyled as O,
236
+ HeaderRenderClickStyled as O,
237
+ InputTextEditorStyled as P,
230
238
  RowsCountRootStyled as R,
231
239
  TableWrapperDataGridStyled as T,
232
240
  ValueColumnStyled as V,
233
241
  WrapperSkeletonStyled as W,
234
- ColumnIconFormatterStyled as a,
235
- ContentModalSettingStyled as b,
236
- ContainerLabelValueColumnStyled as c,
237
- ContentWrapperColumnStyled as d,
238
- CardsContainerStyled as e,
239
- CardDetailContainerStyled as f,
240
- CardHeaderStyled as g,
241
- CardHeaderLeftStyled as h,
242
- CardHeaderRightStyled as i,
243
- CardStyled as j,
244
- CheckboxCellWrapperStyled as k,
245
- ControlNavigateStyled as l,
246
- ActionsConfigContainerStyled as m,
247
- ContainerLeftActionsStyled as n,
248
- ContainerRightActionsStyled as o,
249
- RowsCountLabelStyled as p,
250
- RowsCountValueStyled as q,
251
- ColumnsConfigWrapperStyled as r,
252
- ColumnsConfigDataGridStyled as s,
253
- ColumnsConfigSelColumnsStyled as t,
254
- ColumnsConfigActiosStyled as u,
255
- ContainerToggleCardsStyled as v,
256
- CardToggleButtonStyled as w,
257
- TextToggleCardButtonStyled as x,
258
- TableContainerStyled as y,
259
- NameColumnStyled as z
242
+ ContentModalSettingStyled as a,
243
+ ContainerLabelValueColumnStyled as b,
244
+ ContentWrapperColumnStyled as c,
245
+ CardsContainerStyled as d,
246
+ CardDetailContainerStyled as e,
247
+ CardHeaderStyled as f,
248
+ CardHeaderLeftStyled as g,
249
+ CardHeaderRightStyled as h,
250
+ CardContentWrapperStyled as i,
251
+ CardContentStyled as j,
252
+ CardStyled as k,
253
+ CheckboxCellWrapperStyled as l,
254
+ ControlNavigateStyled as m,
255
+ ActionsConfigContainerStyled as n,
256
+ ContainerLeftActionsStyled as o,
257
+ ContainerRightActionsStyled as p,
258
+ RowsCountLabelStyled as q,
259
+ RowsCountValueStyled as r,
260
+ ColumnsConfigWrapperStyled as s,
261
+ ColumnsConfigDataGridStyled as t,
262
+ ColumnsConfigSelColumnsStyled as u,
263
+ ColumnsConfigActiosStyled as v,
264
+ ContainerToggleCardsStyled as w,
265
+ CardToggleButtonStyled as x,
266
+ TextToggleCardButtonStyled as y,
267
+ TableContainerStyled as z
260
268
  };
@@ -0,0 +1,18 @@
1
+ import { CalculateCardHeightProps } from '../types';
2
+ /**
3
+ * Calcula la altura estimada de una card basándose en el número de columnas visibles.
4
+ * @param visibleColumnsCount - Número de columnas visibles en la card
5
+ * @param customMinHeight - Altura mínima personalizada (opcional, para customRender)
6
+ * @returns Altura calculada en píxeles
7
+ *
8
+ * Fórmula:
9
+ * - 32px por cada columna visible (altura de label + value)
10
+ * - 40px de padding, márgenes y header
11
+ * - Mínimo de 120px para garantizar una altura base
12
+ *
13
+ * Ejemplos:
14
+ * - 3 columnas: Math.max(120, 3 * 32 + 40) = 136px
15
+ * - 5 columnas: Math.max(120, 5 * 32 + 40) = 200px
16
+ * - 10 columnas: Math.max(120, 10 * 32 + 40) = 360px
17
+ */
18
+ export declare function calculateCardHeight(props: CalculateCardHeightProps): number;
@@ -0,0 +1,10 @@
1
+ function calculateCardHeight(props) {
2
+ const { visibleColumnsCount, customMinHeight } = props;
3
+ if (customMinHeight !== void 0) {
4
+ return customMinHeight;
5
+ }
6
+ return Math.max(120, visibleColumnsCount * 32 + 40);
7
+ }
8
+ export {
9
+ calculateCardHeight as c
10
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Helper para hacer scroll a una card por su key.
3
+ * Busca el elemento en el DOM usando querySelector y hace scrollIntoView.
4
+ * @param containerElement - Elemento contenedor que tiene scroll
5
+ * @param rowKey - Key de la fila/card a la que hacer scroll
6
+ * @param selectorType - Tipo de selector: 'class' o 'data-attribute'
7
+ * @param selectorName - Nombre de la clase o atributo base
8
+ */
9
+ export declare function scrollToCardElement(containerElement: HTMLElement | null, rowKey: string | number, selectorType?: 'class' | 'data-attribute', selectorName?: string): void;
@@ -0,0 +1,25 @@
1
+ function scrollToCardElement(containerElement, rowKey, selectorType = "data-attribute", selectorName = "data-row-key") {
2
+ if (!containerElement) {
3
+ console.warn("scrollToCardElement: containerElement is null");
4
+ return;
5
+ }
6
+ try {
7
+ const selector = selectorType === "class" ? `.${selectorName}-${rowKey}` : `[${selectorName}="${rowKey}"]`;
8
+ const foundElement = containerElement.querySelector(selector);
9
+ if (!foundElement) {
10
+ console.warn(
11
+ `scrollToCardElement: No se encontró card con selector "${selector}"`
12
+ );
13
+ return;
14
+ }
15
+ foundElement.scrollIntoView({
16
+ behavior: "auto",
17
+ block: "center"
18
+ });
19
+ } catch (error) {
20
+ console.error("scrollToCardElement: Error al hacer scroll", error);
21
+ }
22
+ }
23
+ export {
24
+ scrollToCardElement as s
25
+ };
@@ -2,8 +2,7 @@ import { CardContentProps } from '../../../types';
2
2
  /**
3
3
  * Hook que encapsula toda la lógica de renderizado del contenido de una Card
4
4
  */
5
- export declare function useCardContent<TRow>({ row, columns, originalColumns, onRowsChange, }: CardContentProps<TRow>): {
5
+ export declare function useCardContent<TRow>({ row, columns, onRowsChange, }: CardContentProps<TRow>): {
6
6
  cardContent: import("react/jsx-runtime").JSX.Element[];
7
7
  columnsCount: number;
8
- onOpenDetail: () => void;
9
8
  };
@@ -1,89 +1,78 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useState, useMemo } from "react";
3
- import { u as useModalDetail } from "../../../hooks/useModalCardDetail.js";
2
+ import { useState } from "react";
4
3
  import { u as useDataGrid } from "../../../hooks/useDataGrid.js";
5
- import { c as ContainerLabelValueColumnStyled, d as ContentWrapperColumnStyled, L as LabelHeaderColumnStyled, E as EditorCellWrapperStyled, V as ValueColumnStyled } from "../../../slots/DataGridSlot.js";
4
+ import { b as ContainerLabelValueColumnStyled, c as ContentWrapperColumnStyled, L as LabelHeaderColumnStyled, E as EditorCellWrapperStyled, V as ValueColumnStyled } from "../../../slots/DataGridSlot.js";
6
5
  function useCardContent({
7
6
  row,
8
7
  columns,
9
- originalColumns,
10
8
  onRowsChange
11
9
  }) {
12
10
  const { getConfigColumns, size } = useDataGrid();
13
11
  const [editingColumnKey, setEditingColumnKey] = useState(null);
14
12
  const columnsConfig = getConfigColumns("cards");
15
- const onOpenDetail = useModalDetail({
16
- row,
17
- columns: originalColumns,
18
- viewMode: "cards",
19
- onRowsChange
20
- });
21
- const cardContent = useMemo(() => {
22
- return columns.map((column, index) => {
23
- const configColumn = columnsConfig.find(
24
- (config) => config.key === column.key
25
- );
26
- const shouldShowTitle = configColumn?.showTitle !== false;
27
- return /* @__PURE__ */ jsx(ContainerLabelValueColumnStyled, { children: /* @__PURE__ */ jsxs(
28
- ContentWrapperColumnStyled,
29
- {
30
- onDoubleClick: column.renderEditCell && editingColumnKey !== column.key ? () => {
31
- setEditingColumnKey(column.key);
32
- } : void 0,
33
- children: [
34
- shouldShowTitle && /* @__PURE__ */ jsx(LabelHeaderColumnStyled, { variant: "body", color: "text.secondary", children: column.name }),
35
- (() => {
36
- if (column.renderEditCell && editingColumnKey === column.key) {
37
- return /* @__PURE__ */ jsx(EditorCellWrapperStyled, { ownerState: { size }, children: column.renderEditCell({
38
- column,
39
- row,
40
- rowIdx: index,
41
- /**
42
- * onRowChange es una función que se ejecuta cuando el usuario edita una celda.
43
- */
44
- onRowChange: (updatedRow) => {
45
- if (onRowsChange) {
46
- onRowsChange([updatedRow], {
47
- indexes: [index],
48
- column
49
- });
50
- }
51
- },
52
- onClose: () => setEditingColumnKey(null)
53
- }) });
54
- }
55
- if (column.renderCell) {
56
- const cellContent = column.renderCell({
57
- column,
58
- row,
59
- rowIdx: index,
60
- isCellSelected: false,
61
- tabIndex: -1,
62
- /**
63
- * onRowChange es una función que se ejecuta cuando el usuario edita una celda.
64
- */
65
- onRowChange: (updatedRow) => {
66
- if (onRowsChange) {
67
- onRowsChange([updatedRow], {
68
- indexes: [index],
69
- column
70
- });
71
- }
13
+ const cardContent = columns.map((column, index) => {
14
+ const configColumn = columnsConfig.find(
15
+ (config) => config.key === column.key
16
+ );
17
+ const shouldShowTitle = configColumn?.showTitle !== false;
18
+ return /* @__PURE__ */ jsx(ContainerLabelValueColumnStyled, { children: /* @__PURE__ */ jsxs(
19
+ ContentWrapperColumnStyled,
20
+ {
21
+ onDoubleClick: column.renderEditCell && editingColumnKey !== column.key ? () => {
22
+ setEditingColumnKey(column.key);
23
+ } : void 0,
24
+ children: [
25
+ shouldShowTitle && /* @__PURE__ */ jsx(LabelHeaderColumnStyled, { variant: "body", color: "text.secondary", children: column.name }),
26
+ (() => {
27
+ if (column.renderEditCell && editingColumnKey === column.key) {
28
+ return /* @__PURE__ */ jsx(EditorCellWrapperStyled, { ownerState: { size }, children: column.renderEditCell({
29
+ column,
30
+ row,
31
+ rowIdx: index,
32
+ /**
33
+ * onRowChange es una función que se ejecuta cuando el usuario edita una celda.
34
+ */
35
+ onRowChange: (updatedRow) => {
36
+ if (onRowsChange) {
37
+ onRowsChange([updatedRow], {
38
+ indexes: [index],
39
+ column
40
+ });
41
+ }
42
+ },
43
+ onClose: () => setEditingColumnKey(null)
44
+ }) });
45
+ }
46
+ if (column.renderCell) {
47
+ const cellContent = column.renderCell({
48
+ column,
49
+ row,
50
+ rowIdx: index,
51
+ isCellSelected: false,
52
+ tabIndex: -1,
53
+ /**
54
+ * onRowChange es una función que se ejecuta cuando el usuario edita una celda.
55
+ */
56
+ onRowChange: (updatedRow) => {
57
+ if (onRowsChange) {
58
+ onRowsChange([updatedRow], {
59
+ indexes: [index],
60
+ column
61
+ });
72
62
  }
73
- });
74
- return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: cellContent });
75
- }
76
- return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: row[column.key] ?? "-" });
77
- })()
78
- ]
79
- }
80
- ) }, column.key);
81
- });
82
- }, [columns, columnsConfig, row, onRowsChange, editingColumnKey, size]);
63
+ }
64
+ });
65
+ return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: cellContent });
66
+ }
67
+ return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: row[column.key] ?? "-" });
68
+ })()
69
+ ]
70
+ }
71
+ ) }, column.key);
72
+ });
83
73
  return {
84
74
  cardContent,
85
- columnsCount: columns.length,
86
- onOpenDetail
75
+ columnsCount: columns.length
87
76
  };
88
77
  }
89
78
  export {
@@ -1,7 +1,11 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { e as CardsContainerStyled } from "../../slots/DataGridSlot.js";
2
+ import { useRef, useMemo, useEffect } from "react";
3
+ import { d as CardsContainerStyled } from "../../slots/DataGridSlot.js";
3
4
  import { C as CardRow } from "./subcomponents/CardRow/index.js";
4
5
  import { u as useProcessedColumns } from "../../hooks/useProcessedColumns.js";
6
+ import { c as calculateCardHeight } from "./helpers/calculateCardHeight.js";
7
+ import { u as useModalDetail } from "../../hooks/useModalCardDetail.js";
8
+ import { s as scrollToCardElement } from "./helpers/scrollToCardElement.js";
5
9
  import { C as ContainerFlow } from "../../../ContainerFlow/ContainerFlow.js";
6
10
  function Cards(props) {
7
11
  const {
@@ -11,29 +15,80 @@ function Cards(props) {
11
15
  selectedRows,
12
16
  onSelectedRowsChange,
13
17
  onRowsChange,
14
- cardsViewConfig
18
+ cardsViewConfig,
19
+ focusOnRowKey,
20
+ checkedRows,
21
+ onCheckedRowsChange
15
22
  } = props;
23
+ const containerRef = useRef(null);
16
24
  const processedColumns = useProcessedColumns(columns);
17
25
  const allProcessedColumns = useProcessedColumns(columns, {
18
26
  applyVisibilityFilter: false
19
27
  });
28
+ const handleOpenDetail = useModalDetail({
29
+ columns: allProcessedColumns,
30
+ viewMode: "cards",
31
+ onRowsChange
32
+ });
33
+ const cardHeight = useMemo(() => {
34
+ return calculateCardHeight({
35
+ visibleColumnsCount: processedColumns.length,
36
+ customMinHeight: cardsViewConfig?.customRender?.minHeight
37
+ });
38
+ }, [processedColumns.length, cardsViewConfig]);
39
+ useEffect(() => {
40
+ if (!focusOnRowKey) {
41
+ return;
42
+ }
43
+ const rowIndex = rows.findIndex(
44
+ (row) => rowKeyGetter(row) === focusOnRowKey
45
+ );
46
+ if (rowIndex === -1) {
47
+ return;
48
+ }
49
+ const timer = setTimeout(() => {
50
+ const container = containerRef.current;
51
+ if (!container) {
52
+ console.warn("container es null, abortando scroll");
53
+ return;
54
+ }
55
+ scrollToCardElement(
56
+ container,
57
+ focusOnRowKey,
58
+ "data-attribute",
59
+ "data-row-key"
60
+ );
61
+ }, 300);
62
+ return () => clearTimeout(timer);
63
+ }, [focusOnRowKey, rows, rowKeyGetter, cardHeight]);
20
64
  if (processedColumns.length === 0) {
21
65
  return null;
22
66
  }
23
- return /* @__PURE__ */ jsx(CardsContainerStyled, { "data-testid": "cards-container", children: /* @__PURE__ */ jsx(ContainerFlow, { variant: "grid-layout", minWidth: 280, children: rows.map((row) => /* @__PURE__ */ jsx(
24
- CardRow,
25
- {
26
- row,
27
- columns: processedColumns,
28
- originalColumns: allProcessedColumns,
29
- rowKeyGetter,
30
- selectedRows,
31
- onSelectedRowsChange,
32
- onRowsChange,
33
- customRender: cardsViewConfig?.customRender
34
- },
35
- rowKeyGetter(row)
36
- )) }) });
67
+ return /* @__PURE__ */ jsx(CardsContainerStyled, { "data-testid": "cards-container", ref: containerRef, children: /* @__PURE__ */ jsx(ContainerFlow, { variant: "grid-layout", minWidth: 280, children: rows.map((row) => {
68
+ const rowKey = rowKeyGetter(row);
69
+ const isChecked = checkedRows?.has(rowKey) || false;
70
+ const showCheckbox = checkedRows !== void 0 && onCheckedRowsChange !== void 0;
71
+ return /* @__PURE__ */ jsx(
72
+ CardRow,
73
+ {
74
+ row,
75
+ columns: processedColumns,
76
+ originalColumns: allProcessedColumns,
77
+ rowKeyGetter,
78
+ selectedRows,
79
+ onSelectedRowsChange,
80
+ onRowsChange,
81
+ customRender: cardsViewConfig?.customRender,
82
+ minHeight: cardHeight,
83
+ isChecked,
84
+ showCheckbox,
85
+ checkedRows,
86
+ onCheckedRowsChange,
87
+ onOpenDetail: handleOpenDetail
88
+ },
89
+ rowKeyGetter(row)
90
+ );
91
+ }) }) });
37
92
  }
38
93
  export {
39
94
  Cards as C
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useState } from "react";
3
- import { f as CardDetailContainerStyled, c as ContainerLabelValueColumnStyled, d as ContentWrapperColumnStyled, L as LabelHeaderColumnStyled, E as EditorCellWrapperStyled, V as ValueColumnStyled } from "../../../../slots/DataGridSlot.js";
2
+ import { useState, useCallback } from "react";
3
+ import { e as CardDetailContainerStyled, b as ContainerLabelValueColumnStyled, c as ContentWrapperColumnStyled, L as LabelHeaderColumnStyled, E as EditorCellWrapperStyled, V as ValueColumnStyled } from "../../../../slots/DataGridSlot.js";
4
4
  function CardDetails({
5
5
  row,
6
6
  columns,
@@ -9,27 +9,45 @@ function CardDetails({
9
9
  size = "medium"
10
10
  }) {
11
11
  const [editingColumnKey, setEditingColumnKey] = useState(null);
12
- return /* @__PURE__ */ jsx(CardDetailContainerStyled, { children: columns.map((column, index) => {
12
+ const [refreshCounter, setRefreshCounter] = useState(0);
13
+ const handleForceRefresh = useCallback(() => {
14
+ setRefreshCounter((prev) => prev + 1);
15
+ }, []);
16
+ const columnsWithRefresh = columns.map((column) => {
17
+ if (column.renderCell) {
18
+ return {
19
+ ...column,
20
+ // Agregar onAfterChange al objeto de la columna si no existe
21
+ ...!column.onAfterChange && {
22
+ onAfterChange: handleForceRefresh
23
+ }
24
+ };
25
+ }
26
+ return column;
27
+ });
28
+ return /* @__PURE__ */ jsx(CardDetailContainerStyled, { children: columnsWithRefresh.map((modifiedColumn, index) => {
13
29
  const configColumn = viewColumnsConfig.find(
14
- (config) => config.key === column.key
30
+ (config) => config.key === modifiedColumn.key
15
31
  );
32
+ const originalColumn = columns[index];
33
+ const columnKey = `${originalColumn.key}-${refreshCounter}`;
16
34
  const shouldShowTitle = configColumn?.showTitle !== false;
17
35
  return /* @__PURE__ */ jsx(ContainerLabelValueColumnStyled, { children: /* @__PURE__ */ jsxs(
18
36
  ContentWrapperColumnStyled,
19
37
  {
20
- "data-testid": `card-detail-column-${column.key}`,
21
- onDoubleClick: column.renderEditCell && editingColumnKey !== column.key ? () => {
22
- setEditingColumnKey(column.key);
38
+ "data-testid": `card-detail-column-${originalColumn.key}`,
39
+ onDoubleClick: modifiedColumn.renderEditCell && editingColumnKey !== modifiedColumn.key ? () => {
40
+ setEditingColumnKey(modifiedColumn.key);
23
41
  } : void 0,
24
42
  children: [
25
43
  shouldShowTitle && /* @__PURE__ */ jsxs(LabelHeaderColumnStyled, { variant: "body", color: "text.secondary", children: [
26
- column.name,
44
+ modifiedColumn.name,
27
45
  ":"
28
46
  ] }),
29
47
  (() => {
30
- if (column.renderEditCell && editingColumnKey === column.key) {
31
- return /* @__PURE__ */ jsx(EditorCellWrapperStyled, { ownerState: { size }, children: column.renderEditCell({
32
- column,
48
+ if (modifiedColumn.renderEditCell && editingColumnKey === modifiedColumn.key) {
49
+ return /* @__PURE__ */ jsx(EditorCellWrapperStyled, { ownerState: { size }, children: modifiedColumn.renderEditCell({
50
+ column: originalColumn,
33
51
  row,
34
52
  rowIdx: index,
35
53
  /**
@@ -39,16 +57,16 @@ function CardDetails({
39
57
  if (onRowsChange) {
40
58
  onRowsChange([updatedRow], {
41
59
  indexes: [index],
42
- column
60
+ column: originalColumn
43
61
  });
44
62
  }
45
63
  },
46
64
  onClose: () => setEditingColumnKey(null)
47
65
  }) });
48
66
  }
49
- if (column.renderCell) {
50
- const cellContent = column.renderCell({
51
- column,
67
+ if (modifiedColumn.renderCell) {
68
+ const cellContent = modifiedColumn.renderCell({
69
+ column: originalColumn,
52
70
  row,
53
71
  rowIdx: index,
54
72
  isCellSelected: false,
@@ -60,18 +78,18 @@ function CardDetails({
60
78
  if (onRowsChange) {
61
79
  onRowsChange([updatedRow], {
62
80
  indexes: [index],
63
- column
81
+ column: originalColumn
64
82
  });
65
83
  }
66
84
  }
67
85
  });
68
86
  return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: cellContent });
69
87
  }
70
- return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: row[column.key] ?? "-" });
88
+ return /* @__PURE__ */ jsx(ValueColumnStyled, { variant: "body", color: "text.primary", children: row[modifiedColumn.key] ?? "-" });
71
89
  })()
72
90
  ]
73
91
  }
74
- ) }, column.key);
92
+ ) }, columnKey);
75
93
  }) });
76
94
  }
77
95
  export {
@@ -4,4 +4,4 @@ import { CardHeaderProps } from '../../types';
4
4
  * - Checkbox en el lado izquierdo (solo si existen checkedRows/onCheckedRowsChange)
5
5
  * - Botones de acción en el lado derecho (IconButton + MenuActions)
6
6
  */
7
- export declare function CardHeader<TRow>({ row, onOpenDetail }: CardHeaderProps<TRow>): import("react/jsx-runtime").JSX.Element;
7
+ export declare function CardHeader<TRow>({ row, onOpenDetail, isChecked, showCheckbox, checkedRows, onCheckedRowsChange, }: CardHeaderProps<TRow>): import("react/jsx-runtime").JSX.Element;
@@ -2,32 +2,25 @@ import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import { useMemo, useCallback } from "react";
3
3
  import { useEnvironment } from "@m4l/core";
4
4
  import { u as useDataGrid } from "../../../../hooks/useDataGrid.js";
5
- import { g as CardHeaderStyled, h as CardHeaderLeftStyled, i as CardHeaderRightStyled } from "../../../../slots/DataGridSlot.js";
5
+ import { f as CardHeaderStyled, g as CardHeaderLeftStyled, h as CardHeaderRightStyled } from "../../../../slots/DataGridSlot.js";
6
6
  import { p as pathIcons } from "../../../../icons.js";
7
7
  import { C as CheckboxCellAdapter } from "../../../CheckboxCellAdapter/index.js";
8
8
  import { I as IconButton } from "../../../../../mui_extended/IconButton/IconButton.js";
9
9
  import { M as MenuActions } from "../../../../../MenuActions/MenuActions.js";
10
- function CardHeader({ row, onOpenDetail }) {
11
- const {
12
- rowKeyGetter,
13
- checkedRows,
14
- onCheckedRowsChange,
15
- rowActionsGetter,
16
- size
17
- } = useDataGrid();
10
+ function CardHeader({
11
+ row,
12
+ onOpenDetail,
13
+ isChecked,
14
+ showCheckbox,
15
+ checkedRows,
16
+ onCheckedRowsChange
17
+ }) {
18
+ const { rowKeyGetter, rowActionsGetter, size } = useDataGrid();
18
19
  const { host_static_assets, environment_assets } = useEnvironment();
19
20
  const rowKey = useMemo(() => rowKeyGetter(row), [rowKeyGetter, row]);
20
- const showCheckbox = useMemo(
21
- () => checkedRows !== void 0 && onCheckedRowsChange !== void 0,
22
- [checkedRows, onCheckedRowsChange]
23
- );
24
- const isChecked = useMemo(
25
- () => checkedRows?.has(rowKey) || false,
26
- [checkedRows, rowKey]
27
- );
28
21
  const onChange = useCallback(
29
22
  (checked, _isShiftClick) => {
30
- if (!onCheckedRowsChange) {
23
+ if (!onCheckedRowsChange || !checkedRows) {
31
24
  return;
32
25
  }
33
26
  const newCheckedRows = new Set(checkedRows);
@@ -58,7 +51,7 @@ function CardHeader({ row, onOpenDetail }) {
58
51
  showCheckbox && /* @__PURE__ */ jsx(CardHeaderLeftStyled, { children: /* @__PURE__ */ jsx(
59
52
  CheckboxCellAdapter,
60
53
  {
61
- value: isChecked,
54
+ value: isChecked ?? false,
62
55
  tabIndex: -1,
63
56
  onChange,
64
57
  "aria-label": "Select"
@@ -74,7 +67,7 @@ function CardHeader({ row, onOpenDetail }) {
74
67
  "data-testid": `card-details-button-${rowKey}`,
75
68
  onClick: (e) => {
76
69
  e.stopPropagation();
77
- onOpenDetail();
70
+ onOpenDetail(row);
78
71
  }
79
72
  }
80
73
  ),
@@ -3,4 +3,9 @@ import { CardRowProps } from '../../types';
3
3
  /**
4
4
  * Componente que muestra una fila de tarjetas.
5
5
  */
6
- export declare function CardRow<TRow, TKey extends RowKey = RowKey>({ row, columns, originalColumns, rowKeyGetter, selectedRows, onSelectedRowsChange, onRowsChange, customRender, }: CardRowProps<TRow, TKey>): import("react/jsx-runtime").JSX.Element;
6
+ declare function CardRowComponent<TRow, TKey extends RowKey = RowKey>({ row, columns, originalColumns, rowKeyGetter, selectedRows, onSelectedRowsChange, onRowsChange, customRender, minHeight, isChecked, checkedRows, showCheckbox, onCheckedRowsChange, onOpenDetail, }: CardRowProps<TRow, TKey>): import("react/jsx-runtime").JSX.Element;
7
+ /**
8
+ *
9
+ */
10
+ export declare const CardRow: typeof CardRowComponent;
11
+ export {};