@m4l/components 9.4.1 → 9.4.2-JT11122025.beta.2
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/components/DataGrid/DataGrid.js +7 -1
- package/components/DataGrid/constants.d.ts +13 -0
- package/components/DataGrid/constants.js +11 -0
- package/components/DataGrid/contexts/DataGridContext/index.js +60 -275
- package/components/DataGrid/contexts/DataGridContext/types.d.ts +24 -23
- package/components/DataGrid/helpers/getAllViewModes/getAllViewModes.d.ts +19 -0
- package/components/DataGrid/helpers/getAllViewModes/getAllViewModes.js +6 -0
- package/components/DataGrid/helpers/getAllViewModes/getAllViewModes.test.d.ts +1 -0
- package/components/DataGrid/helpers/getAllViewModes/index.d.ts +1 -0
- package/components/DataGrid/helpers/getAllViewModes/index.js +1 -0
- package/components/DataGrid/helpers/getColumnsWidth/getColumnsWidth.d.ts +47 -0
- package/components/DataGrid/helpers/getColumnsWidth/getColumnsWidth.js +32 -0
- package/components/DataGrid/helpers/getColumnsWidth/getColumnsWidth.test.d.ts +1 -0
- package/components/DataGrid/helpers/getColumnsWidth/index.d.ts +1 -0
- package/components/DataGrid/helpers/getColumnsWidth/index.js +1 -0
- package/components/DataGrid/helpers/getIndexRowHeightVariant/getIndexRowHeightVariant.d.ts +24 -0
- package/components/DataGrid/helpers/getIndexRowHeightVariant/getIndexRowHeightVariant.js +12 -0
- package/components/DataGrid/helpers/getIndexRowHeightVariant/getIndexRowHeightVariant.test.d.ts +1 -0
- package/components/DataGrid/helpers/getIndexRowHeightVariant/index.d.ts +1 -0
- package/components/DataGrid/helpers/getIndexRowHeightVariant/index.js +1 -0
- package/components/DataGrid/helpers/getInitialColumnsConfig/getInitialColumnsConfig.d.ts +48 -0
- package/components/DataGrid/helpers/getInitialColumnsConfig/getInitialColumnsConfig.js +35 -0
- package/components/DataGrid/helpers/getInitialColumnsConfig/getInitialColumnsConfig.test.d.ts +1 -0
- package/components/DataGrid/helpers/getInitialColumnsConfig/index.d.ts +1 -0
- package/components/DataGrid/helpers/getInitialColumnsConfig/index.js +1 -0
- package/components/DataGrid/helpers/getViewMode/getViewMode.d.ts +41 -0
- package/components/DataGrid/helpers/getViewMode/getViewMode.js +19 -0
- package/components/DataGrid/helpers/getViewMode/getViewMode.test.d.ts +1 -0
- package/components/DataGrid/helpers/getViewMode/index.d.ts +1 -0
- package/components/DataGrid/helpers/getViewMode/index.js +1 -0
- package/components/DataGrid/helpers/getViewSpecificConfig/getViewSpecificConfig.d.ts +28 -0
- package/components/DataGrid/helpers/getViewSpecificConfig/getViewSpecificConfig.js +22 -0
- package/components/DataGrid/helpers/getViewSpecificConfig/getViewSpecificConfig.test.d.ts +1 -0
- package/components/DataGrid/helpers/getViewSpecificConfig/index.d.ts +1 -0
- package/components/DataGrid/helpers/getViewSpecificConfig/index.js +1 -0
- package/components/DataGrid/helpers/getViewSuffix/getViewSuffix.d.ts +24 -0
- package/components/DataGrid/helpers/getViewSuffix/getViewSuffix.js +9 -0
- package/components/DataGrid/helpers/getViewSuffix/getViewSuffix.test.d.ts +1 -0
- package/components/DataGrid/helpers/getViewSuffix/index.d.ts +1 -0
- package/components/DataGrid/helpers/getViewSuffix/index.js +1 -0
- package/components/DataGrid/helpers/index.d.ts +13 -0
- package/components/DataGrid/helpers/index.js +1 -0
- package/components/DataGrid/helpers/loadViewConfig/index.d.ts +1 -0
- package/components/DataGrid/helpers/loadViewConfig/index.js +1 -0
- package/components/DataGrid/helpers/loadViewConfig/loadViewConfig.d.ts +23 -0
- package/components/DataGrid/helpers/loadViewConfig/loadViewConfig.js +12 -0
- package/components/DataGrid/helpers/loadViewConfig/loadViewConfig.test.d.ts +1 -0
- package/components/DataGrid/helpers/saveColumnsWidth/index.d.ts +1 -0
- package/components/DataGrid/helpers/saveColumnsWidth/index.js +1 -0
- package/components/DataGrid/helpers/saveColumnsWidth/saveColumnsWidth.d.ts +52 -0
- package/components/DataGrid/helpers/saveColumnsWidth/saveColumnsWidth.js +18 -0
- package/components/DataGrid/helpers/saveColumnsWidth/saveColumnsWidth.test.d.ts +1 -0
- package/components/DataGrid/helpers/saveViewConfig/index.d.ts +1 -0
- package/components/DataGrid/helpers/saveViewConfig/index.js +1 -0
- package/components/DataGrid/helpers/saveViewConfig/saveViewConfig.d.ts +35 -0
- package/components/DataGrid/helpers/saveViewConfig/saveViewConfig.js +15 -0
- package/components/DataGrid/helpers/saveViewConfig/saveViewConfig.test.d.ts +1 -0
- package/components/DataGrid/helpers/saveViewMode/index.d.ts +1 -0
- package/components/DataGrid/helpers/saveViewMode/index.js +1 -0
- package/components/DataGrid/helpers/saveViewMode/saveViewMode.d.ts +33 -0
- package/components/DataGrid/helpers/saveViewMode/saveViewMode.js +13 -0
- package/components/DataGrid/helpers/saveViewMode/saveViewMode.test.d.ts +1 -0
- package/components/DataGrid/hooks/index.d.ts +6 -0
- package/components/DataGrid/hooks/index.js +1 -0
- package/components/DataGrid/hooks/useChangeColumnsConfig/index.d.ts +1 -0
- package/components/DataGrid/hooks/useChangeColumnsConfig/index.js +1 -0
- package/components/DataGrid/hooks/useChangeColumnsConfig/useChangeColumnsConfig.d.ts +9 -0
- package/components/DataGrid/hooks/useChangeColumnsConfig/useChangeColumnsConfig.js +27 -0
- package/components/DataGrid/hooks/useChangeColumnsConfig/useChangeColumnsConfig.test.d.ts +1 -0
- package/components/DataGrid/hooks/useChangeColumnsOrder/index.d.ts +1 -0
- package/components/DataGrid/hooks/useChangeColumnsOrder/index.js +1 -0
- package/components/DataGrid/hooks/useChangeColumnsOrder/useChangeColumnsOrder.d.ts +10 -0
- package/components/DataGrid/hooks/useChangeColumnsOrder/useChangeColumnsOrder.js +34 -0
- package/components/DataGrid/hooks/useChangeColumnsOrder/useChangeColumnsOrder.test.d.ts +1 -0
- package/components/DataGrid/hooks/useColumnsWidth/index.d.ts +1 -0
- package/components/DataGrid/hooks/useColumnsWidth/index.js +1 -0
- package/components/DataGrid/hooks/useColumnsWidth/useColumnsWidth.d.ts +11 -0
- package/components/DataGrid/hooks/useColumnsWidth/useColumnsWidth.js +29 -0
- package/components/DataGrid/hooks/useColumnsWidth/useColumnsWidth.test.d.ts +1 -0
- package/components/DataGrid/hooks/useRowHeight/index.d.ts +1 -0
- package/components/DataGrid/hooks/useRowHeight/index.js +1 -0
- package/components/DataGrid/hooks/useRowHeight/useRowHeight.d.ts +28 -0
- package/components/DataGrid/hooks/useRowHeight/useRowHeight.js +51 -0
- package/components/DataGrid/hooks/useRowHeight/useRowHeight.test.d.ts +1 -0
- package/components/DataGrid/hooks/useViewConfig/index.d.ts +1 -0
- package/components/DataGrid/hooks/useViewConfig/index.js +1 -0
- package/components/DataGrid/hooks/useViewConfig/useViewConfig.d.ts +9 -0
- package/components/DataGrid/hooks/useViewConfig/useViewConfig.js +30 -0
- package/components/DataGrid/hooks/useViewConfig/useViewConfig.test.d.ts +1 -0
- package/components/DataGrid/hooks/useViewMode/index.d.ts +1 -0
- package/components/DataGrid/hooks/useViewMode/index.js +1 -0
- package/components/DataGrid/hooks/useViewMode/useViewMode.d.ts +31 -0
- package/components/DataGrid/hooks/useViewMode/useViewMode.js +44 -0
- package/components/DataGrid/hooks/useViewMode/useViewMode.test.d.ts +1 -0
- package/components/DataGrid/index.d.ts +5 -4
- package/components/DataGrid/subcomponents/Cards/helpers/calculateCardHeight.d.ts +5 -4
- package/components/DataGrid/subcomponents/Cards/helpers/calculateCardHeight.js +4 -1
- package/components/DataGrid/types.d.ts +30 -6
- package/components/DataGrid/types.helpers.d.ts +55 -0
- package/components/DataGrid/types.helpers.js +1 -0
- package/components/DataGrid/types.hooks.d.ts +81 -0
- package/hooks/useDataGridPersistence/constants.d.ts +2 -0
- package/hooks/useDataGridPersistence/constants.js +6 -2
- package/hooks/useDataGridPersistence/helpers.d.ts +5 -1
- package/hooks/useDataGridPersistence/helpers.js +8 -1
- package/hooks/useDataGridPersistence/useDataGridPersistence.d.ts +11 -3
- package/hooks/useDataGridPersistence/useDataGridPersistence.js +43 -20
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { s as saveViewConfig } from "../../helpers/saveViewConfig/saveViewConfig.js";
|
|
3
|
+
import { g as getViewSuffix } from "../../helpers/getViewSuffix/getViewSuffix.js";
|
|
4
|
+
const useChangeColumnsConfig = ({
|
|
5
|
+
id,
|
|
6
|
+
onChangeConfig,
|
|
7
|
+
updateConfigColumns
|
|
8
|
+
}) => {
|
|
9
|
+
const onChangeColumnsConfig = useCallback(
|
|
10
|
+
(viewModeParam, newConfig) => {
|
|
11
|
+
saveViewConfig(
|
|
12
|
+
id,
|
|
13
|
+
getViewSuffix(viewModeParam),
|
|
14
|
+
newConfig,
|
|
15
|
+
onChangeConfig
|
|
16
|
+
);
|
|
17
|
+
updateConfigColumns(viewModeParam, newConfig);
|
|
18
|
+
},
|
|
19
|
+
[id, onChangeConfig, updateConfigColumns]
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
onChangeColumnsConfig
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
useChangeColumnsConfig as u
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useChangeColumnsOrder } from './useChangeColumnsOrder';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UseChangeColumnsOrderParams, UseChangeColumnsOrderReturn } from '../../types.hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Hook para manejar el cambio de orden de columnas.
|
|
4
|
+
*
|
|
5
|
+
* Reordena las columnas y llama a onChangeColumnsConfig para persistir.
|
|
6
|
+
* @param getConfigColumns Función para obtener la configuración de columnas
|
|
7
|
+
* @param onChangeColumnsConfig Función para cambiar la configuración de columnas
|
|
8
|
+
* @returns Función para cambiar el orden de columnas
|
|
9
|
+
*/
|
|
10
|
+
export declare const useChangeColumnsOrder: ({ getConfigColumns, onChangeColumnsConfig, }: UseChangeColumnsOrderParams) => UseChangeColumnsOrderReturn;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
const useChangeColumnsOrder = ({
|
|
3
|
+
getConfigColumns,
|
|
4
|
+
onChangeColumnsConfig
|
|
5
|
+
}) => {
|
|
6
|
+
const onChangeColumnsOrder = useCallback(
|
|
7
|
+
(viewModeParam, sourceKey, targetKey) => {
|
|
8
|
+
if (sourceKey === targetKey) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const currentConfig = getConfigColumns(viewModeParam);
|
|
12
|
+
const sourceColumnIndex = currentConfig.findIndex(
|
|
13
|
+
(c) => c.key === sourceKey
|
|
14
|
+
);
|
|
15
|
+
const targetColumnIndex = currentConfig.findIndex(
|
|
16
|
+
(c) => c.key === targetKey
|
|
17
|
+
);
|
|
18
|
+
const reorderedConfig = [...currentConfig];
|
|
19
|
+
reorderedConfig.splice(
|
|
20
|
+
targetColumnIndex,
|
|
21
|
+
0,
|
|
22
|
+
reorderedConfig.splice(sourceColumnIndex, 1)[0]
|
|
23
|
+
);
|
|
24
|
+
onChangeColumnsConfig(viewModeParam, reorderedConfig);
|
|
25
|
+
},
|
|
26
|
+
[getConfigColumns, onChangeColumnsConfig]
|
|
27
|
+
);
|
|
28
|
+
return {
|
|
29
|
+
onChangeColumnsOrder
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
useChangeColumnsOrder as u
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useColumnsWidth } from './useColumnsWidth';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UseColumnsWidthParams, UseColumnsWidthReturn } from '../../types.hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Hook para manejar el estado del ancho de las columnas del DataGrid.
|
|
4
|
+
*
|
|
5
|
+
* Maneja:
|
|
6
|
+
* - Estado del ancho de cada columna
|
|
7
|
+
* - Guardado con debounce de 500ms al cambiar el ancho
|
|
8
|
+
* @param params - Parámetros del hook
|
|
9
|
+
* @returns Estado y función para cambiar el ancho de columnas
|
|
10
|
+
*/
|
|
11
|
+
export declare const useColumnsWidth: ({ id, onChangeConfig, }: UseColumnsWidthParams) => UseColumnsWidthReturn;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useState, useRef, useCallback } from "react";
|
|
2
|
+
import { s as saveColumnsWidth } from "../../helpers/saveColumnsWidth/saveColumnsWidth.js";
|
|
3
|
+
const useColumnsWidth = ({
|
|
4
|
+
id,
|
|
5
|
+
onChangeConfig
|
|
6
|
+
}) => {
|
|
7
|
+
const [columnsWidths, setColumnsWidths] = useState(/* @__PURE__ */ new Map());
|
|
8
|
+
const timerRef = useRef(null);
|
|
9
|
+
const onChangeColumnWidth = useCallback(
|
|
10
|
+
(columnKey, width) => {
|
|
11
|
+
columnsWidths.set(columnKey, Math.round(width));
|
|
12
|
+
if (timerRef.current) {
|
|
13
|
+
clearTimeout(timerRef.current);
|
|
14
|
+
}
|
|
15
|
+
timerRef.current = setTimeout(() => {
|
|
16
|
+
saveColumnsWidth(id, columnsWidths, onChangeConfig);
|
|
17
|
+
}, 500);
|
|
18
|
+
},
|
|
19
|
+
[id, columnsWidths, onChangeConfig]
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
columnsWidths,
|
|
23
|
+
setColumnsWidths,
|
|
24
|
+
onChangeColumnWidth
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
useColumnsWidth as u
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useRowHeight } from './useRowHeight';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UseRowHeightParams, UseRowHeightReturn } from '../../types.hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Hook para manejar el estado de la altura de las filas del DataGrid.
|
|
4
|
+
*
|
|
5
|
+
* Soporta dos modos:
|
|
6
|
+
* - **Modo fijo**: rowHeights y rowHeaderHeights son números fijos
|
|
7
|
+
* - **Modo variable**: rowHeights y rowHeaderHeights son arrays de 3 elementos [compact, standard, confortable]
|
|
8
|
+
* @param params - Parámetros del hook
|
|
9
|
+
* @returns Estado actual y función para cambiar el variant
|
|
10
|
+
* @throws Error si rowHeights y rowHeaderHeights no son del mismo tipo
|
|
11
|
+
* @throws Error si los arrays no tienen exactamente 3 elementos
|
|
12
|
+
* @throws Error si se intenta cambiar el variant en modo fijo
|
|
13
|
+
* @example
|
|
14
|
+
* // Modo variable (permite cambiar variant)
|
|
15
|
+
* const { currentRowHeightVariant, setRowHeightVariant } = useRowHeight({
|
|
16
|
+
* rowHeights: [32, 40, 48],
|
|
17
|
+
* rowHeaderHeights: [36, 44, 52],
|
|
18
|
+
* initialRowHeightVariant: 'standard',
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Modo fijo (altura constante)
|
|
22
|
+
* const { currentRowHeightVariant } = useRowHeight({
|
|
23
|
+
* rowHeights: 40,
|
|
24
|
+
* rowHeaderHeights: 44,
|
|
25
|
+
* initialRowHeightVariant: 'standard',
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
export declare const useRowHeight: ({ rowHeights, rowHeaderHeights, initialRowHeightVariant, }: UseRowHeightParams) => UseRowHeightReturn;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import { g as getIndexRowHeightVariant } from "../../helpers/getIndexRowHeightVariant/getIndexRowHeightVariant.js";
|
|
3
|
+
const useRowHeight = ({
|
|
4
|
+
rowHeights,
|
|
5
|
+
rowHeaderHeights,
|
|
6
|
+
initialRowHeightVariant
|
|
7
|
+
}) => {
|
|
8
|
+
const [currentRowHeightVariant, setCurrentRowHeightVariant] = useState(() => {
|
|
9
|
+
if (typeof rowHeights !== typeof rowHeaderHeights) {
|
|
10
|
+
throw new Error("Must be same type rowheights and rowHeaderTypes");
|
|
11
|
+
}
|
|
12
|
+
if (typeof rowHeights === "number" && typeof rowHeaderHeights === "number") {
|
|
13
|
+
return {
|
|
14
|
+
rowHVariant: "compact",
|
|
15
|
+
rowHeight: rowHeights,
|
|
16
|
+
rowHeaderHeight: rowHeaderHeights
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (typeof rowHeights !== "number" && rowHeights.length !== 3) {
|
|
20
|
+
throw new Error("Must be 3 heights");
|
|
21
|
+
}
|
|
22
|
+
if (typeof rowHeaderHeights !== "number" && rowHeaderHeights.length !== 3) {
|
|
23
|
+
throw new Error("Must be 3 HeaderHeights");
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
rowHVariant: initialRowHeightVariant,
|
|
27
|
+
rowHeight: typeof rowHeights !== "number" ? rowHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeights,
|
|
28
|
+
rowHeaderHeight: typeof rowHeaderHeights !== "number" ? rowHeaderHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeaderHeights
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
const setRowHeightVariant = useCallback(
|
|
32
|
+
(newVariant) => {
|
|
33
|
+
if (typeof rowHeights === "number" || typeof rowHeaderHeights === "number") {
|
|
34
|
+
throw new Error("Only use setCurrentRowHeight with vector rowHeights");
|
|
35
|
+
}
|
|
36
|
+
setCurrentRowHeightVariant({
|
|
37
|
+
rowHVariant: newVariant,
|
|
38
|
+
rowHeight: rowHeights[getIndexRowHeightVariant(newVariant)],
|
|
39
|
+
rowHeaderHeight: rowHeaderHeights[getIndexRowHeightVariant(newVariant)]
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
[rowHeights, rowHeaderHeights]
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
currentRowHeightVariant,
|
|
46
|
+
setRowHeightVariant
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
useRowHeight as u
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useViewConfig } from './useViewConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UseViewConfigReturn } from '../../types.hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Hook para manejar el estado de la configuración de columnas por vista.
|
|
4
|
+
*
|
|
5
|
+
* Maneja un estado genérico unificado para las configuraciones de TODAS las vistas
|
|
6
|
+
* (table, cards, etc).
|
|
7
|
+
* @returns Estado y funciones para manejar la configuración de vistas
|
|
8
|
+
*/
|
|
9
|
+
export declare const useViewConfig: () => UseViewConfigReturn;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
const useViewConfig = () => {
|
|
3
|
+
const [viewConfig, setViewConfig] = useState(() => ({
|
|
4
|
+
table: [],
|
|
5
|
+
cards: []
|
|
6
|
+
}));
|
|
7
|
+
const getConfigColumns = useCallback(
|
|
8
|
+
(viewModeParam) => {
|
|
9
|
+
return viewConfig[viewModeParam];
|
|
10
|
+
},
|
|
11
|
+
[viewConfig]
|
|
12
|
+
);
|
|
13
|
+
const updateConfigColumns = useCallback(
|
|
14
|
+
(viewModeParam, config) => {
|
|
15
|
+
setViewConfig((prev) => ({
|
|
16
|
+
...prev,
|
|
17
|
+
[viewModeParam]: config
|
|
18
|
+
}));
|
|
19
|
+
},
|
|
20
|
+
[]
|
|
21
|
+
);
|
|
22
|
+
return {
|
|
23
|
+
viewConfig,
|
|
24
|
+
getConfigColumns,
|
|
25
|
+
updateConfigColumns
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
useViewConfig as u
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useViewMode } from './useViewMode';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UseViewModeParams, UseViewModeReturn } from '../../types.hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Hook para manejar el estado del modo de visualización (table/cards).
|
|
4
|
+
*
|
|
5
|
+
* ## Inicialización del viewMode
|
|
6
|
+
*
|
|
7
|
+
* El viewMode se inicializa siguiendo esta jerarquía de precedencia:
|
|
8
|
+
* 1. viewMode prop (modo controlado)
|
|
9
|
+
* 2. localStorage (configuración guardada localmente)
|
|
10
|
+
* 3. defaultViewMode (valor por defecto del desarrollador)
|
|
11
|
+
* 4. Fallback según dispositivo (mobile: 'cards', desktop: 'table')
|
|
12
|
+
*
|
|
13
|
+
* ## Persistencia del viewMode
|
|
14
|
+
*
|
|
15
|
+
* - Si `onChangeConfig` está definido → Guarda en cookies de red
|
|
16
|
+
* - Si no está definido → Fallback a localStorage
|
|
17
|
+
*
|
|
18
|
+
* ## Modo controlado vs no controlado
|
|
19
|
+
*
|
|
20
|
+
* - **Controlado**: Cuando se pasa `viewMode` prop, el padre controla el estado
|
|
21
|
+
* - **No controlado**: El hook maneja internamente el estado y persiste
|
|
22
|
+
* @param id - Identificador único del DataGrid
|
|
23
|
+
* @param viewMode - ViewMode controlado por el padre (opcional)
|
|
24
|
+
* @param defaultViewMode - ViewMode por defecto cuando no hay valor guardado
|
|
25
|
+
* @param onViewModeChange - Callback cuando cambia el viewMode (opcional)
|
|
26
|
+
* @param onChangeConfig - Callback para guardar en cookies de red (opcional)
|
|
27
|
+
* @returns viewModeState - Estado actual del viewMode
|
|
28
|
+
* @returns setViewModeState - Función para establecer el viewMode
|
|
29
|
+
* @returns handleViewModeChange - Función para cambiar el viewMode y persistirlo
|
|
30
|
+
*/
|
|
31
|
+
export declare const useViewMode: ({ id, viewMode, defaultViewMode, onViewModeChange, onChangeConfig, }: UseViewModeParams) => UseViewModeReturn;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from "react";
|
|
2
|
+
import { useIsMobile } from "@m4l/graphics";
|
|
3
|
+
import { g as getViewMode } from "../../helpers/getViewMode/getViewMode.js";
|
|
4
|
+
import { s as saveViewMode } from "../../helpers/saveViewMode/saveViewMode.js";
|
|
5
|
+
const useViewMode = ({
|
|
6
|
+
id,
|
|
7
|
+
viewMode,
|
|
8
|
+
defaultViewMode,
|
|
9
|
+
onViewModeChange,
|
|
10
|
+
onChangeConfig
|
|
11
|
+
}) => {
|
|
12
|
+
const isMobile = useIsMobile();
|
|
13
|
+
const [viewModeState, setViewModeState] = useState(() => {
|
|
14
|
+
if (viewMode) {
|
|
15
|
+
return viewMode;
|
|
16
|
+
}
|
|
17
|
+
const savedViewMode = getViewMode(id, null, defaultViewMode);
|
|
18
|
+
if (savedViewMode) {
|
|
19
|
+
return savedViewMode;
|
|
20
|
+
}
|
|
21
|
+
return isMobile ? "cards" : "table";
|
|
22
|
+
});
|
|
23
|
+
const handleViewModeChange = useCallback(
|
|
24
|
+
(newViewMode) => {
|
|
25
|
+
setViewModeState(newViewMode);
|
|
26
|
+
saveViewMode(id, newViewMode, onChangeConfig);
|
|
27
|
+
onViewModeChange?.(newViewMode);
|
|
28
|
+
},
|
|
29
|
+
[id, onViewModeChange, onChangeConfig]
|
|
30
|
+
);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (viewMode !== void 0) {
|
|
33
|
+
setViewModeState(viewMode);
|
|
34
|
+
}
|
|
35
|
+
}, [viewMode]);
|
|
36
|
+
return {
|
|
37
|
+
viewModeState,
|
|
38
|
+
setViewModeState,
|
|
39
|
+
handleViewModeChange
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
useViewMode as u
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { DataGrid } from './DataGrid';
|
|
2
2
|
export * from './formatters';
|
|
3
|
-
export type { Column, RenderEditCellProps, RenderCellProps } from 'react-data-grid';
|
|
4
|
-
export type { RowKey, ChangeUserColumn, RowActionsGetter, RowKeyGetter } from './types';
|
|
3
|
+
export type { Column, RenderEditCellProps, RenderCellProps, } from 'react-data-grid';
|
|
4
|
+
export type { RowKey, ChangeConfig, ChangeUserColumn, RowActionsGetter, RowKeyGetter, } from './types';
|
|
5
5
|
export { getDataGridComponentsDictionary } from './dictionary';
|
|
6
6
|
export { TextEditor, NumberEditor } from './subcomponents/editors/TextEditor';
|
|
7
7
|
export { getDataGridRowsFromSet } from './utils/getDataGridRowsFromSet';
|
|
8
|
-
export type {
|
|
9
|
-
export { DATAGRID_SEMANTIC_WIDTHS, DATAGRID_ROW_HEADER_HEIGHTS, DATAGRID_ROW_HEIGHTS } from './constants';
|
|
8
|
+
export type { IGridConfigExtended, BaseConfigColumn, } from './contexts/DataGridContext/types';
|
|
9
|
+
export { DATAGRID_SEMANTIC_WIDTHS, DATAGRID_ROW_HEADER_HEIGHTS, DATAGRID_ROW_HEIGHTS, } from './constants';
|
|
10
|
+
export * from './types.helpers';
|
|
@@ -6,13 +6,14 @@ import { CalculateCardHeightProps } from '../types';
|
|
|
6
6
|
* @returns Altura calculada en píxeles
|
|
7
7
|
*
|
|
8
8
|
* Fórmula:
|
|
9
|
+
* - 42px de header (checkbox + acciones)
|
|
9
10
|
* - 32px por cada columna visible (altura de label + value)
|
|
10
|
-
* - 40px de padding
|
|
11
|
+
* - 40px de padding vertical
|
|
11
12
|
* - Mínimo de 120px para garantizar una altura base
|
|
12
13
|
*
|
|
13
14
|
* Ejemplos:
|
|
14
|
-
* - 3 columnas: Math.max(120, 3 * 32 + 40) =
|
|
15
|
-
* - 5 columnas: Math.max(120, 5 * 32 + 40) =
|
|
16
|
-
* - 10 columnas: Math.max(120, 10 * 32 + 40) =
|
|
15
|
+
* - 3 columnas: Math.max(120, 42 + 3 * 32 + 40) = 178px
|
|
16
|
+
* - 5 columnas: Math.max(120, 42 + 5 * 32 + 40) = 242px
|
|
17
|
+
* - 10 columnas: Math.max(120, 42 + 10 * 32 + 40) = 402px
|
|
17
18
|
*/
|
|
18
19
|
export declare function calculateCardHeight(props: CalculateCardHeightProps): number;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { C as CARD_HEIGHT } from "../../../constants.js";
|
|
1
2
|
function calculateCardHeight(props) {
|
|
2
3
|
const { visibleColumnsCount, customMinHeight } = props;
|
|
3
4
|
if (customMinHeight !== void 0) {
|
|
4
5
|
return customMinHeight;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
const contentHeight = visibleColumnsCount * CARD_HEIGHT.COLUMN;
|
|
8
|
+
const totalHeight = CARD_HEIGHT.HEADER + contentHeight + CARD_HEIGHT.PADDING_VERTICAL;
|
|
9
|
+
return Math.max(CARD_HEIGHT.BASE_MIN, totalHeight);
|
|
7
10
|
}
|
|
8
11
|
export {
|
|
9
12
|
calculateCardHeight as c
|
|
@@ -61,12 +61,27 @@ export interface ColumnConfig {
|
|
|
61
61
|
position?: number;
|
|
62
62
|
frozen?: Maybe<boolean>;
|
|
63
63
|
}
|
|
64
|
-
type
|
|
65
|
-
|
|
64
|
+
type KeyConfig = keyof IGridConfigExtended;
|
|
65
|
+
/**
|
|
66
|
+
* Tipo que representa un cambio de configuración del DataGrid.
|
|
67
|
+
*/
|
|
68
|
+
export interface ChangeConfig<T extends KeyConfig = KeyConfig> {
|
|
66
69
|
reason: T;
|
|
67
70
|
userConfig: IGridConfigExtended[T];
|
|
68
71
|
}
|
|
69
|
-
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Usar `ChangeConfig` en su lugar. Este tipo será eliminado en futuras versiones.
|
|
74
|
+
*/
|
|
75
|
+
export type ChangeUserColumn = ChangeConfig;
|
|
76
|
+
/**
|
|
77
|
+
* Callback que se ejecuta cuando cambia cualquier configuración del DataGrid.
|
|
78
|
+
* Maneja todas las vistas genéricamente a través de IGridConfigExtended.
|
|
79
|
+
*/
|
|
80
|
+
export type OnChangeConfig = (props: ChangeConfig) => void;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Usar `OnChangeConfig` en su lugar. Este tipo será eliminado en futuras versiones.
|
|
83
|
+
*/
|
|
84
|
+
export type OnChangeUserColumns = OnChangeConfig;
|
|
70
85
|
export type SortApplied = {
|
|
71
86
|
columnKey: string;
|
|
72
87
|
removable: boolean;
|
|
@@ -146,12 +161,21 @@ export interface GridProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> exte
|
|
|
146
161
|
checkedRowsMultiple?: boolean;
|
|
147
162
|
onRowsChange?: Maybe<(rows: TRow[], data: RowsChangeData<TRow, TSummaryRow>) => void>;
|
|
148
163
|
/**
|
|
149
|
-
*
|
|
164
|
+
* Configuración inicial del DataGrid (anchos, orden, visibilidad, viewMode).
|
|
165
|
+
* Tiene prioridad sobre localStorage.
|
|
166
|
+
*/
|
|
167
|
+
defaultConfig?: IGridConfigExtended;
|
|
168
|
+
/**
|
|
169
|
+
* Callback que se ejecuta cuando cambia cualquier configuración del DataGrid.
|
|
170
|
+
* @param props - Objeto con `reason` (tipo de cambio) y `userConfig` (nueva configuración)
|
|
171
|
+
*/
|
|
172
|
+
onChangeConfig?: OnChangeConfig;
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated Usar `defaultConfig` en su lugar. Esta prop será eliminada en futuras versiones.
|
|
150
175
|
*/
|
|
151
176
|
defaultUserColumns?: IGridConfigExtended;
|
|
152
177
|
/**
|
|
153
|
-
*
|
|
154
|
-
* las configuraciones de las columnas.
|
|
178
|
+
* @deprecated Usar `onChangeConfig` en su lugar. Esta prop será eliminada en futuras versiones.
|
|
155
179
|
*/
|
|
156
180
|
onChangeUserColumns?: OnChangeUserColumns;
|
|
157
181
|
/**
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RowKey } from './types';
|
|
2
|
+
import { BaseConfigColumn } from './contexts/DataGridContext/types';
|
|
3
|
+
/**
|
|
4
|
+
* Configuración base genérica que puede extenderse con propiedades específicas de cualquier vista.
|
|
5
|
+
*
|
|
6
|
+
* USO INTERNO: El sistema usa esto para manejar genéricamente las configuraciones
|
|
7
|
+
* de columnas sin importar el tipo de vista (table, cards, etc).
|
|
8
|
+
* @example
|
|
9
|
+
* // Para vista table
|
|
10
|
+
* BaseViewConfig<{ frozen: boolean }>
|
|
11
|
+
*
|
|
12
|
+
* // Para vista cards
|
|
13
|
+
* BaseViewConfig<{ showTitle: boolean }>
|
|
14
|
+
*/
|
|
15
|
+
export type BaseViewConfig<TViewSpecific = object> = TViewSpecific & {
|
|
16
|
+
key: string;
|
|
17
|
+
visible: boolean;
|
|
18
|
+
index: number;
|
|
19
|
+
name?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
*Este tipo define la estructura de configuración que el usuario puede
|
|
24
|
+
*pasar al DataGrid para personalizar columnas y sus anchos.
|
|
25
|
+
*
|
|
26
|
+
*- `columnsConfig`: Configuración de visibilidad y orden de columnas para vista table
|
|
27
|
+
*- `columnsWidths`: Anchos personalizados de columnas
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const userConfig: IGridConfig = {
|
|
31
|
+
* columnsConfig: [
|
|
32
|
+
* { key: 'name', visible: true, index: 0, frozen: false },
|
|
33
|
+
* { key: 'email', visible: true, index: 1, frozen: false },
|
|
34
|
+
* ],
|
|
35
|
+
* columnsWidths: { name: 200, email: 300 }
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface IGridConfig {
|
|
40
|
+
/** Configuración de columnas para vista table (visibilidad, orden, frozen) */
|
|
41
|
+
columnsConfig: BaseConfigColumn[];
|
|
42
|
+
/** Anchos de columnas en píxeles */
|
|
43
|
+
columnsWidths: Record<RowKey, number>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Configuración específica retornada por getViewSpecificConfig
|
|
47
|
+
*/
|
|
48
|
+
export interface ViewSpecificConfig {
|
|
49
|
+
/** Valores por defecto para propiedades específicas de la vista */
|
|
50
|
+
defaults: Record<string, unknown>;
|
|
51
|
+
/** Valores originales por defecto para tracking de cambios */
|
|
52
|
+
originalDefaults: Record<string, unknown>;
|
|
53
|
+
/** Función para obtener propiedades originales dinámicas de un item */
|
|
54
|
+
dynamicOriginalProperty: (item: unknown) => Record<string, unknown>;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { RowKey, RowHeightVariants, RowHeights, OnChangeConfig } from './types';
|
|
2
|
+
import { Maybe } from '@m4l/core';
|
|
3
|
+
import { IViewConfig, RowHeightState, ViewMode } from './contexts/DataGridContext/types';
|
|
4
|
+
export interface UseViewModeParams {
|
|
5
|
+
/** Identificador único del DataGrid */
|
|
6
|
+
id: RowKey;
|
|
7
|
+
/** ViewMode controlado por el padre */
|
|
8
|
+
viewMode?: ViewMode;
|
|
9
|
+
/** ViewMode por defecto cuando no hay valor guardado */
|
|
10
|
+
defaultViewMode?: ViewMode;
|
|
11
|
+
/** Callback cuando cambia el viewMode */
|
|
12
|
+
onViewModeChange?: (viewMode: ViewMode) => void;
|
|
13
|
+
/** Callback para persistir cambios */
|
|
14
|
+
onChangeConfig?: OnChangeConfig;
|
|
15
|
+
}
|
|
16
|
+
export interface UseViewModeReturn {
|
|
17
|
+
/** Estado actual del viewMode */
|
|
18
|
+
viewModeState: ViewMode;
|
|
19
|
+
/** Función para establecer el viewMode */
|
|
20
|
+
setViewModeState: React.Dispatch<React.SetStateAction<ViewMode>>;
|
|
21
|
+
/** Función para cambiar el viewMode y persistirlo */
|
|
22
|
+
handleViewModeChange: (newViewMode: ViewMode) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface UseRowHeightParams {
|
|
25
|
+
/** Alturas de las filas (número fijo o array de 3 elementos) */
|
|
26
|
+
rowHeights: RowHeights;
|
|
27
|
+
/** Alturas de los headers (número fijo o array de 3 elementos) */
|
|
28
|
+
rowHeaderHeights: RowHeights;
|
|
29
|
+
/** Variant inicial de altura */
|
|
30
|
+
initialRowHeightVariant: RowHeightVariants;
|
|
31
|
+
}
|
|
32
|
+
export interface UseRowHeightReturn {
|
|
33
|
+
/** Estado actual de la altura de filas */
|
|
34
|
+
currentRowHeightVariant: RowHeightState;
|
|
35
|
+
/** Función para cambiar el variant de altura */
|
|
36
|
+
setRowHeightVariant: (newVariant: RowHeightVariants) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface UseColumnsWidthParams {
|
|
39
|
+
/** Identificador único del DataGrid */
|
|
40
|
+
id: RowKey;
|
|
41
|
+
/** Callback para persistir cambios */
|
|
42
|
+
onChangeConfig?: OnChangeConfig;
|
|
43
|
+
}
|
|
44
|
+
export interface UseColumnsWidthReturn {
|
|
45
|
+
/** Mapa con el ancho de cada columna */
|
|
46
|
+
columnsWidths: Map<string, Maybe<string | number>>;
|
|
47
|
+
/** Función para establecer el mapa de anchos */
|
|
48
|
+
setColumnsWidths: React.Dispatch<React.SetStateAction<Map<string, Maybe<string | number>>>>;
|
|
49
|
+
/** Función para cambiar el ancho de una columna */
|
|
50
|
+
onChangeColumnWidth: (columnKey: string, width: number) => void;
|
|
51
|
+
}
|
|
52
|
+
export interface UseViewConfigReturn {
|
|
53
|
+
/** Estado de configuración por vista */
|
|
54
|
+
viewConfig: Record<ViewMode, IViewConfig<any, any>[]>;
|
|
55
|
+
/** Obtiene la configuración de columnas para una vista */
|
|
56
|
+
getConfigColumns: (viewMode: ViewMode) => IViewConfig<any, any>[];
|
|
57
|
+
/** Actualiza la configuración de columnas para una vista */
|
|
58
|
+
updateConfigColumns: (viewMode: ViewMode, config: IViewConfig<any, any>[]) => void;
|
|
59
|
+
}
|
|
60
|
+
export interface UseChangeColumnsConfigParams {
|
|
61
|
+
/** Identificador único del DataGrid */
|
|
62
|
+
id: RowKey;
|
|
63
|
+
/** Callback para persistir cambios */
|
|
64
|
+
onChangeConfig?: OnChangeConfig;
|
|
65
|
+
/** Función para actualizar la configuración de columnas */
|
|
66
|
+
updateConfigColumns: (viewMode: ViewMode, config: IViewConfig<any, any>[]) => void;
|
|
67
|
+
}
|
|
68
|
+
export interface UseChangeColumnsConfigReturn {
|
|
69
|
+
/** Función para cambiar la configuración de columnas de una vista */
|
|
70
|
+
onChangeColumnsConfig: (viewMode: ViewMode, newConfig: IViewConfig<any, any>[]) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface UseChangeColumnsOrderParams {
|
|
73
|
+
/** Función para obtener la configuración de columnas de una vista */
|
|
74
|
+
getConfigColumns: (viewMode: ViewMode) => IViewConfig<any, any>[];
|
|
75
|
+
/** Función para cambiar la configuración de columnas */
|
|
76
|
+
onChangeColumnsConfig: (viewMode: ViewMode, newConfig: IViewConfig<any, any>[]) => void;
|
|
77
|
+
}
|
|
78
|
+
export interface UseChangeColumnsOrderReturn {
|
|
79
|
+
/** Función para cambiar el orden de columnas de una vista */
|
|
80
|
+
onChangeColumnsOrder: (viewMode: ViewMode, sourceKey: string, targetKey: string) => void;
|
|
81
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const M4LDYNAMIC_KEY_FILTER_AND_SORT = "M4LDynamicFilterAndSort";
|
|
2
2
|
export declare const COOKIE_COLUMNS_WIDTHS = "columns_widths";
|
|
3
3
|
export declare const COOKIE_COLUMNS_CONFIG = "columns_config";
|
|
4
|
+
export declare const COOKIE_COLUMNS_CONFIG_CARDS = "columns_config_cards";
|
|
5
|
+
export declare const COOKIE_VIEW_MODE = "view_mode";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const COOKIE_COLUMNS_WIDTHS = "columns_widths";
|
|
2
2
|
const COOKIE_COLUMNS_CONFIG = "columns_config";
|
|
3
|
+
const COOKIE_COLUMNS_CONFIG_CARDS = "columns_config_cards";
|
|
4
|
+
const COOKIE_VIEW_MODE = "view_mode";
|
|
3
5
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
COOKIE_VIEW_MODE as C,
|
|
7
|
+
COOKIE_COLUMNS_CONFIG_CARDS as a,
|
|
8
|
+
COOKIE_COLUMNS_CONFIG as b,
|
|
9
|
+
COOKIE_COLUMNS_WIDTHS as c
|
|
6
10
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { IGridConfigExtended } from '../../components/DataGrid';
|
|
2
2
|
/**
|
|
3
|
-
* Obtiene
|
|
3
|
+
* Obtiene la configuración de columnas de tabla desde la cookie
|
|
4
4
|
*/
|
|
5
5
|
export declare const getColumnsConfigCookie: (cookie: Record<string, any> | undefined | Array<any>) => IGridConfigExtended["columnsConfig"];
|
|
6
|
+
/**
|
|
7
|
+
* Obtiene la configuración de columnas de cards desde la cookie
|
|
8
|
+
*/
|
|
9
|
+
export declare const getColumnsConfigCardsCookie: (cookie: Record<string, any> | undefined | Array<any>) => IGridConfigExtended["columnsConfigCards"];
|