@m4l/components 9.3.40 → 9.3.41-JT04122025.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/contexts/DataGridContext/index.js +56 -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/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/components/hook-form/RHFActionsGroup/RHFActionsGroup.js +2 -2
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.js +2 -2
- package/components/hook-form/RHFCheckbox/RHFCheckbox.js +2 -2
- package/components/hook-form/RHFColorPicker/RFHColorPicker.js +2 -2
- package/components/hook-form/RHFDatePicker/RHFDatePicker.js +2 -2
- package/components/hook-form/RHFDateTime/RHFDateTime.js +2 -2
- package/components/hook-form/RHFNumberInput/RHFNumberInput.js +2 -2
- package/components/hook-form/RHFPeriod/RHFPeriod.js +2 -2
- package/components/hook-form/RHFPeriod/subcomponents/Period/Period.js +1 -0
- package/components/hook-form/RHFSelect/RHFSelect.js +2 -2
- package/components/hook-form/RHFTextField/RHFTextField.js +2 -2
- package/components/hook-form/RHFTextFieldPassword/RHFTextFieldPassword.js +2 -2
- package/components/hook-form/RHFUpload/RHFUploadImage/RHFUploadImage.js +3 -1
- package/components/hook-form/RHFUpload/RHFUploadImage/subcomponents/UploadImage/UploadImage.js +4 -3
- package/components/hook-form/RHFUpload/RHFUploadImage/types.d.ts +4 -0
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/RHFUploadSingleFile.js +6 -4
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/subcomponents/Preview/Preview.js +3 -2
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/subcomponents/Preview/types.d.ts +1 -1
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/subcomponents/UploadSingleFile/index.js +13 -4
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/types.d.ts +4 -0
- package/hooks/useDataGridPersistence/constants.d.ts +1 -0
- package/hooks/useDataGridPersistence/constants.js +4 -2
- package/hooks/useDataGridPersistence/useDataGridPersistence.d.ts +11 -3
- package/hooks/useDataGridPersistence/useDataGridPersistence.js +13 -6
- package/package.json +1 -1
package/components/DataGrid/helpers/getIndexRowHeightVariant/getIndexRowHeightVariant.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getIndexRowHeightVariant } from './getIndexRowHeightVariant';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Column } from 'react-data-grid';
|
|
2
|
+
import { RowKey } from '../../types';
|
|
3
|
+
import { BaseViewConfig } from '../../types.helpers';
|
|
4
|
+
import { IViewConfig, ViewMode } from '../../contexts/DataGridContext/types';
|
|
5
|
+
/**
|
|
6
|
+
* Obtiene la configuración inicial de columnas para cualquier vista.
|
|
7
|
+
*
|
|
8
|
+
* ## Propósito
|
|
9
|
+
*
|
|
10
|
+
* Genera la configuración inicial de columnas combinando:
|
|
11
|
+
* 1. Configuración inicial (defaultConfig) si existe
|
|
12
|
+
* 2. Configuración guardada en localStorage si no hay defaultConfig
|
|
13
|
+
* 3. Valores por defecto de las columnas
|
|
14
|
+
*
|
|
15
|
+
* ## Prioridad de configuración
|
|
16
|
+
*
|
|
17
|
+
* 1. defaultConfig (configuración inicial de columnas)
|
|
18
|
+
* 2. localStorage (preferencia guardada del usuario)
|
|
19
|
+
* 3. Valores por defecto de las columnas
|
|
20
|
+
* @param id - Identificador único del DataGrid
|
|
21
|
+
* @param columns - Columnas del DataGrid
|
|
22
|
+
* @param viewMode - Modo de visualización actual ('table' | 'cards')
|
|
23
|
+
* @param defaultConfig - Configuración inicial de columnas (opcional) para la vista de "table" es la que viene en cada columna su configuración (visible, frozen, etc.) y para la vista "cards" es la que viene en la configuración de cardsViewConfig.columnsConfig
|
|
24
|
+
* @param viewSpecificDefaults - Valores por defecto específicos de la vista
|
|
25
|
+
* @param originalViewSpecificDefaults - Valores originales específicos de la vista
|
|
26
|
+
* @returns Array de configuración de columnas ordenado por índice
|
|
27
|
+
* @example
|
|
28
|
+
* // Para vista table
|
|
29
|
+
* getInitialColumnsConfig(
|
|
30
|
+
* 'my-grid',
|
|
31
|
+
* columns,
|
|
32
|
+
* 'table',
|
|
33
|
+
* undefined,
|
|
34
|
+
* { frozen: false },
|
|
35
|
+
* { originalFrozen: false }
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* // Para vista cards
|
|
39
|
+
* getInitialColumnsConfig(
|
|
40
|
+
* 'my-grid',
|
|
41
|
+
* columns,
|
|
42
|
+
* 'cards',
|
|
43
|
+
* undefined,
|
|
44
|
+
* { showTitle: true },
|
|
45
|
+
* { originalShowTitle: true }
|
|
46
|
+
* );
|
|
47
|
+
*/
|
|
48
|
+
export declare const getInitialColumnsConfig: <TRow, TSummaryRow, TViewSpecific, TOriginalViewSpecific>(id: RowKey, columns: readonly Column<TRow, TSummaryRow>[], viewMode: ViewMode, defaultConfig?: BaseViewConfig<TViewSpecific>[], viewSpecificDefaults?: TViewSpecific, originalViewSpecificDefaults?: TOriginalViewSpecific) => IViewConfig<TViewSpecific, TOriginalViewSpecific>[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { l as loadViewConfig } from "../loadViewConfig/loadViewConfig.js";
|
|
2
|
+
import { g as getViewSuffix } from "../getViewSuffix/getViewSuffix.js";
|
|
3
|
+
const getInitialColumnsConfig = (id, columns, viewMode, defaultConfig, viewSpecificDefaults, originalViewSpecificDefaults) => {
|
|
4
|
+
let columnsConfig;
|
|
5
|
+
if (defaultConfig) {
|
|
6
|
+
columnsConfig = defaultConfig;
|
|
7
|
+
} else {
|
|
8
|
+
columnsConfig = loadViewConfig(
|
|
9
|
+
id,
|
|
10
|
+
getViewSuffix(viewMode)
|
|
11
|
+
) || [];
|
|
12
|
+
}
|
|
13
|
+
return columns.map((column, index) => {
|
|
14
|
+
const existingConfig = columnsConfig.find((c) => c.key === column.key);
|
|
15
|
+
const columnConfigIndex = existingConfig ? columnsConfig.indexOf(existingConfig) : -1;
|
|
16
|
+
const baseConfig = {
|
|
17
|
+
key: column.key,
|
|
18
|
+
name: typeof column.name === "string" ? column.name : String(column.name),
|
|
19
|
+
hidden: column.hidden === void 0 ? false : column.hidden,
|
|
20
|
+
index: columnConfigIndex > -1 ? columnConfigIndex : index,
|
|
21
|
+
visible: existingConfig?.visible !== void 0 ? existingConfig.visible : defaultConfig !== void 0 && defaultConfig.length > 0 ? false : column.visible === void 0 ? true : column.visible,
|
|
22
|
+
originalIndex: index,
|
|
23
|
+
originalVisible: column.visible === void 0 ? true : column.visible
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
...baseConfig,
|
|
27
|
+
...viewSpecificDefaults,
|
|
28
|
+
...originalViewSpecificDefaults,
|
|
29
|
+
...existingConfig || {}
|
|
30
|
+
};
|
|
31
|
+
}).sort((a, b) => a.index - b.index);
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
getInitialColumnsConfig as g
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getInitialColumnsConfig } from './getInitialColumnsConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Maybe } from '@m4l/core';
|
|
2
|
+
import { RowKey } from '../../types';
|
|
3
|
+
import { IGridConfigExtended, ViewMode } from '../../contexts/DataGridContext/types';
|
|
4
|
+
/**
|
|
5
|
+
* Obtiene el modo de visualización del DataGrid.
|
|
6
|
+
*
|
|
7
|
+
* ## Flujo de persistencia
|
|
8
|
+
*
|
|
9
|
+
* Esta función obtiene el viewMode siguiendo una jerarquía de precedencia:
|
|
10
|
+
*
|
|
11
|
+
* 1. **defaultConfig.viewMode** (Cookies de red) - Prioridad máxima
|
|
12
|
+
* Configuración que viene de las cookies de red cuando el componente se monta.
|
|
13
|
+
* En producción, esta es la fuente principal de datos persistidos.
|
|
14
|
+
*
|
|
15
|
+
* 2. **localStorage** - Fallback local
|
|
16
|
+
* Solo se usa cuando NO hay configuración de cookies de red.
|
|
17
|
+
* Útil para desarrollo o cuando no hay integración con cookies de red.
|
|
18
|
+
*
|
|
19
|
+
* 3. **defaultViewMode** - Valor por defecto del desarrollador
|
|
20
|
+
* Se usa si no hay configuración guardada en ningún lado.
|
|
21
|
+
*
|
|
22
|
+
* ## Relación con saveViewMode
|
|
23
|
+
*
|
|
24
|
+
* - Cuando el usuario cambia de vista, `saveViewMode` envía los cambios
|
|
25
|
+
* mediante el callback `onChangeConfig`
|
|
26
|
+
* - En la siguiente carga, esos datos vuelven como `defaultConfig.viewMode`
|
|
27
|
+
* - localStorage es solo un fallback cuando no hay callback configurado
|
|
28
|
+
* @param id - Identificador único del DataGrid. Se usa como prefijo para la key en localStorage (fallback)
|
|
29
|
+
* @param defaultConfig - Configuración del usuario obtenida de cookies de red.
|
|
30
|
+
* Esta es la fuente principal en producción.
|
|
31
|
+
* @param defaultViewMode - Valor por defecto del desarrollador cuando no hay configuración guardada
|
|
32
|
+
* @returns El viewMode a usar, o undefined si no se encontró configuración
|
|
33
|
+
* @example
|
|
34
|
+
* // Sin configuración de cookies de red (usa localStorage como fallback)
|
|
35
|
+
* const viewMode = getViewMode('my-grid', null, 'table');
|
|
36
|
+
* @example
|
|
37
|
+
* // Con configuración de cookies de red (caso típico en producción)
|
|
38
|
+
* const viewMode = getViewMode('my-grid', { viewMode: 'cards' }, 'table');
|
|
39
|
+
* @see saveViewMode - Función complementaria para persistir la configuración
|
|
40
|
+
*/
|
|
41
|
+
export declare function getViewMode(id: RowKey, defaultConfig: Maybe<IGridConfigExtended>, defaultViewMode?: ViewMode): ViewMode | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function getViewMode(id, defaultConfig, defaultViewMode) {
|
|
2
|
+
if (defaultConfig?.viewMode) {
|
|
3
|
+
return defaultConfig.viewMode;
|
|
4
|
+
}
|
|
5
|
+
try {
|
|
6
|
+
const savedViewMode = window.localStorage.getItem(`${id}_view_mode`);
|
|
7
|
+
if (savedViewMode === "cards" || savedViewMode === "table") {
|
|
8
|
+
return savedViewMode;
|
|
9
|
+
}
|
|
10
|
+
} catch (_e) {
|
|
11
|
+
}
|
|
12
|
+
if (defaultViewMode) {
|
|
13
|
+
return defaultViewMode;
|
|
14
|
+
}
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
getViewMode as g
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getViewMode } from './getViewMode';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ViewMode } from '../../contexts/DataGridContext/types';
|
|
2
|
+
import { ViewSpecificConfig } from '../../types.helpers';
|
|
3
|
+
/**
|
|
4
|
+
* Obtiene la configuración específica para cada modo de vista.
|
|
5
|
+
*
|
|
6
|
+
* ## Propósito
|
|
7
|
+
*
|
|
8
|
+
* Centraliza la lógica específica de cada ViewMode para evitar hardcoding
|
|
9
|
+
* disperso en el código. Cada vista tiene sus propias propiedades:
|
|
10
|
+
*
|
|
11
|
+
* - **table**: `frozen` (columnas fijas)
|
|
12
|
+
* - **cards**: `showTitle` (mostrar título en tarjetas)
|
|
13
|
+
*
|
|
14
|
+
* ## Estructura de retorno
|
|
15
|
+
*
|
|
16
|
+
* - `defaults`: Valores por defecto para nuevas columnas
|
|
17
|
+
* - `originalDefaults`: Valores originales para tracking
|
|
18
|
+
* - `dynamicOriginalProperty`: Función para extraer propiedades originales de items existentes
|
|
19
|
+
* @param viewMode - Modo de vista ('table' | 'cards')
|
|
20
|
+
* @returns Configuración específica del modo de vista
|
|
21
|
+
* @example
|
|
22
|
+
* const tableConfig = getViewSpecificConfig('table');
|
|
23
|
+
* // { defaults: { frozen: false }, originalDefaults: { originalFrozen: false }, ... }
|
|
24
|
+
* @example
|
|
25
|
+
* const cardsConfig = getViewSpecificConfig('cards');
|
|
26
|
+
* // { defaults: { showTitle: true }, originalDefaults: { originalShowTitle: true }, ... }
|
|
27
|
+
*/
|
|
28
|
+
export declare const getViewSpecificConfig: (viewMode: ViewMode) => ViewSpecificConfig;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const getViewSpecificConfig = (viewMode) => {
|
|
2
|
+
const configs = {
|
|
3
|
+
table: {
|
|
4
|
+
defaults: { frozen: false },
|
|
5
|
+
originalDefaults: { originalFrozen: false },
|
|
6
|
+
dynamicOriginalProperty: (item) => ({
|
|
7
|
+
originalFrozen: item?.frozen ?? false
|
|
8
|
+
})
|
|
9
|
+
},
|
|
10
|
+
cards: {
|
|
11
|
+
defaults: { showTitle: true },
|
|
12
|
+
originalDefaults: { originalShowTitle: true },
|
|
13
|
+
dynamicOriginalProperty: (item) => ({
|
|
14
|
+
originalShowTitle: item?.showTitle ?? true
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return configs[viewMode] || configs.table;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
getViewSpecificConfig as g
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getViewSpecificConfig } from './getViewSpecificConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ViewMode } from '../../contexts/DataGridContext/types';
|
|
2
|
+
/**
|
|
3
|
+
* Genera el sufijo de localStorage basado en el viewMode.
|
|
4
|
+
*
|
|
5
|
+
* ## Propósito
|
|
6
|
+
*
|
|
7
|
+
* Mantiene retrocompatibilidad con las keys de localStorage existentes:
|
|
8
|
+
* - Vista `table`: sin sufijo (retrocompatibilidad)
|
|
9
|
+
* - Vista `cards`: con sufijo `_cards`
|
|
10
|
+
* - Futuras vistas: con sufijo `_${viewMode}`
|
|
11
|
+
*
|
|
12
|
+
* ## Uso en localStorage
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* table: `${id}_columns_config`
|
|
16
|
+
* cards: `${id}_columns_config_cards`
|
|
17
|
+
* ```
|
|
18
|
+
* @param viewMode - Modo de vista ('table' | 'cards')
|
|
19
|
+
* @returns Sufijo para la key de localStorage ('' para table, '_cards' para cards)
|
|
20
|
+
* @example
|
|
21
|
+
* getViewSuffix('table'); // ''
|
|
22
|
+
* getViewSuffix('cards'); // '_cards'
|
|
23
|
+
*/
|
|
24
|
+
export declare const getViewSuffix: (viewMode: ViewMode) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getViewSuffix } from './getViewSuffix';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './saveColumnsWidth';
|
|
2
|
+
export * from './castMapColumnsWidthToRecord';
|
|
3
|
+
export * from './getColumnsWidth';
|
|
4
|
+
export * from './getColumnKey';
|
|
5
|
+
export * from './getAllViewModes';
|
|
6
|
+
export * from './getViewSpecificConfig';
|
|
7
|
+
export * from './getViewSuffix';
|
|
8
|
+
export * from './saveViewMode';
|
|
9
|
+
export * from './getViewMode';
|
|
10
|
+
export * from './loadViewConfig';
|
|
11
|
+
export * from './saveViewConfig';
|
|
12
|
+
export * from './getIndexRowHeightVariant';
|
|
13
|
+
export * from './getInitialColumnsConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { loadViewConfig } from './loadViewConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RowKey } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Carga configuraciones de vista desde localStorage.
|
|
4
|
+
*
|
|
5
|
+
* ## Propósito
|
|
6
|
+
*
|
|
7
|
+
* Recupera la configuración de columnas guardada previamente para una vista específica.
|
|
8
|
+
* Trabaja en conjunto con `saveViewConfig` y `getViewSuffix` para persistencia.
|
|
9
|
+
*
|
|
10
|
+
* ## Formato de key en localStorage
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* table: `${id}_columns_config`
|
|
14
|
+
* cards: `${id}_columns_config_cards`
|
|
15
|
+
* ```
|
|
16
|
+
* @param id - Identificador único del DataGrid
|
|
17
|
+
* @param viewSuffix - Sufijo para identificar la vista ('' para table, '_cards' para cards)
|
|
18
|
+
* @returns Array de configuración o null si no existe/error
|
|
19
|
+
* @example
|
|
20
|
+
* loadViewConfig('my-grid', ''); // Lee 'my-grid_columns_config'
|
|
21
|
+
* loadViewConfig('my-grid', '_cards'); // Lee 'my-grid_columns_config_cards'
|
|
22
|
+
*/
|
|
23
|
+
export declare const loadViewConfig: <T>(id: RowKey, viewSuffix: string) => T[] | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const loadViewConfig = (id, viewSuffix) => {
|
|
2
|
+
try {
|
|
3
|
+
const storageKey = viewSuffix === "" ? `${id}_columns_config` : `${id}_columns_config${viewSuffix}`;
|
|
4
|
+
const stored = localStorage.getItem(storageKey);
|
|
5
|
+
return stored ? JSON.parse(stored) : null;
|
|
6
|
+
} catch (_e) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
loadViewConfig as l
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { saveColumnsWidth } from './saveColumnsWidth';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Maybe } from '@m4l/core';
|
|
2
|
+
import { RowKey, OnChangeConfig } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Persiste la configuración de anchos de las columnas del DataGrid.
|
|
5
|
+
*
|
|
6
|
+
* ## Flujo de persistencia
|
|
7
|
+
*
|
|
8
|
+
* Esta función guarda los anchos de columnas siguiendo esta lógica:
|
|
9
|
+
*
|
|
10
|
+
* 1. **onChangeConfig** (Cookies de red) - Método principal en producción
|
|
11
|
+
* Si está disponible, envía la configuración al callback para que el consumidor
|
|
12
|
+
* la persista en cookies de red. En la siguiente carga, estos datos volverán
|
|
13
|
+
* como `defaultConfig` en `getColumnsWidth`.
|
|
14
|
+
*
|
|
15
|
+
* 2. **localStorage** - Fallback local
|
|
16
|
+
* Solo se usa cuando NO hay callback configurado.
|
|
17
|
+
* Útil para desarrollo o cuando no hay integración con cookies de red.
|
|
18
|
+
*
|
|
19
|
+
* ## Ciclo completo de persistencia
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* Usuario redimensiona columna
|
|
23
|
+
* ↓
|
|
24
|
+
* saveColumnsWidth() envía via onChangeConfig
|
|
25
|
+
* ↓
|
|
26
|
+
* Se persiste en cookies de red
|
|
27
|
+
* ↓
|
|
28
|
+
* Próxima carga: datos vienen en defaultConfig
|
|
29
|
+
* ↓
|
|
30
|
+
* getColumnsWidth() lee de defaultConfig
|
|
31
|
+
* ```
|
|
32
|
+
* @param id - Identificador único del DataGrid. Se usa como prefijo en localStorage (fallback)
|
|
33
|
+
* @param storeColumnsWidth - Map con la configuración de anchos donde:
|
|
34
|
+
* - key: identificador de la columna (column.key)
|
|
35
|
+
* - value: ancho en píxeles (number) o string con unidad CSS
|
|
36
|
+
* @param onChangeConfig - Callback para enviar la configuración a cookies de red.
|
|
37
|
+
* Recibe un objeto con:
|
|
38
|
+
* - reason: 'columnsWidths' (identificador del tipo de cambio)
|
|
39
|
+
* - userConfig: Record con los anchos de columnas
|
|
40
|
+
* @example
|
|
41
|
+
* // Producción: Guardar mediante callback a cookies de red
|
|
42
|
+
* saveColumnsWidth('my-grid', columnsWidthsMap, ({ reason, userConfig }) => {
|
|
43
|
+
* // Persistir en cookies de red
|
|
44
|
+
* setCookie(userConfig);
|
|
45
|
+
* });
|
|
46
|
+
* @example
|
|
47
|
+
* // Desarrollo: Guardar en localStorage (sin cookies de red)
|
|
48
|
+
* saveColumnsWidth('my-grid', columnsWidthsMap);
|
|
49
|
+
* @see getColumnsWidth - Función complementaria para obtener la configuración
|
|
50
|
+
* @see castMapColumnsWidthToRecord - Helper usado para convertir el Map a Record
|
|
51
|
+
*/
|
|
52
|
+
export declare function saveColumnsWidth(id: RowKey, storeColumnsWidth: Map<string, Maybe<string | number>>, onChangeConfig?: OnChangeConfig): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { c as castMapColumnsWidthToRecord } from "../castMapColumnsWidthToRecord.js";
|
|
2
|
+
function saveColumnsWidth(id, storeColumnsWidth, onChangeConfig) {
|
|
3
|
+
if (onChangeConfig) {
|
|
4
|
+
const columnsWidthObject = castMapColumnsWidthToRecord(storeColumnsWidth);
|
|
5
|
+
onChangeConfig({
|
|
6
|
+
reason: "columnsWidths",
|
|
7
|
+
userConfig: columnsWidthObject
|
|
8
|
+
});
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
localStorage.setItem(
|
|
12
|
+
`${id}_columns_width`,
|
|
13
|
+
JSON.stringify([...storeColumnsWidth])
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
saveColumnsWidth as s
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { saveViewConfig } from './saveViewConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RowKey } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Guarda configuraciones de vista en localStorage o notifica via callback.
|
|
4
|
+
*
|
|
5
|
+
* ## Propósito
|
|
6
|
+
*
|
|
7
|
+
* Persiste la configuración de columnas para una vista específica.
|
|
8
|
+
* Soporta dos modos: localStorage directo o callback externo (cookies de red).
|
|
9
|
+
*
|
|
10
|
+
* ## Prioridad de persistencia
|
|
11
|
+
*
|
|
12
|
+
* 1. Si hay `onChangeConfig`, notifica al callback (para guardar en cookies de red)
|
|
13
|
+
* 2. Si no hay callback, guarda directamente en localStorage
|
|
14
|
+
*
|
|
15
|
+
* ## Formato de key en localStorage
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* table: `${id}_columns_config`
|
|
19
|
+
* cards: `${id}_columns_config_cards`
|
|
20
|
+
* ```
|
|
21
|
+
* @param id - Identificador único del DataGrid
|
|
22
|
+
* @param viewSuffix - Sufijo para identificar la vista ('' para table, '_cards' para cards)
|
|
23
|
+
* @param config - Array de configuración a guardar
|
|
24
|
+
* @param onChangeConfig - Callback opcional para notificar cambios (prioridad sobre localStorage)
|
|
25
|
+
* @example
|
|
26
|
+
* // Guardar en localStorage
|
|
27
|
+
* saveViewConfig('my-grid', '', config);
|
|
28
|
+
*
|
|
29
|
+
* // Notificar via callback
|
|
30
|
+
* saveViewConfig('my-grid', '_cards', config, onChangeConfig);
|
|
31
|
+
*/
|
|
32
|
+
export declare const saveViewConfig: <T>(id: RowKey, viewSuffix: string, config: T[], onChangeConfig?: (data: {
|
|
33
|
+
reason: string;
|
|
34
|
+
userConfig: T[];
|
|
35
|
+
}) => void) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const saveViewConfig = (id, viewSuffix, config, onChangeConfig) => {
|
|
2
|
+
if (onChangeConfig) {
|
|
3
|
+
const reason = viewSuffix === "" ? "columnsConfig" : `columnsConfig${viewSuffix.replace("_", "")}`;
|
|
4
|
+
onChangeConfig({
|
|
5
|
+
reason,
|
|
6
|
+
userConfig: config
|
|
7
|
+
});
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const storageKey = viewSuffix === "" ? `${id}_columns_config` : `${id}_columns_config${viewSuffix}`;
|
|
11
|
+
localStorage.setItem(storageKey, JSON.stringify(config));
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
saveViewConfig as s
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { saveViewMode } from './saveViewMode';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ViewMode } from '../../contexts/DataGridContext/types';
|
|
2
|
+
import { OnChangeConfig, RowKey } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Guarda el modo de visualización (table o cards).
|
|
5
|
+
*
|
|
6
|
+
* ## Propósito
|
|
7
|
+
*
|
|
8
|
+
* Persiste la preferencia del usuario sobre el modo de vista seleccionado.
|
|
9
|
+
* Permite que al recargar la página se mantenga la última vista utilizada.
|
|
10
|
+
*
|
|
11
|
+
* ## Prioridad de guardado
|
|
12
|
+
*
|
|
13
|
+
* 1. Si existe `onChangeConfig` → Guarda en cookies de red
|
|
14
|
+
* 2. Si no existe → Fallback a localStorage
|
|
15
|
+
*
|
|
16
|
+
* ## Formato de key en localStorage (fallback)
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
* `${id}_view_mode` -> 'table' | 'cards'
|
|
20
|
+
* ```
|
|
21
|
+
* @param id - Identificador único del DataGrid
|
|
22
|
+
* @param viewMode - Modo de visualización ('table' | 'cards')
|
|
23
|
+
* @param onChangeConfig - Callback opcional para guardar en cookies de red
|
|
24
|
+
* @example
|
|
25
|
+
* // Con cookies de red
|
|
26
|
+
* saveViewMode('my-grid', 'cards', onChangeConfig);
|
|
27
|
+
* // Llama: onChangeConfig({ reason: 'viewMode', userConfig: 'cards' })
|
|
28
|
+
*
|
|
29
|
+
* // Sin cookies de red (fallback)
|
|
30
|
+
* saveViewMode('my-grid', 'cards');
|
|
31
|
+
* // localStorage: 'my-grid_view_mode' = 'cards'
|
|
32
|
+
*/
|
|
33
|
+
export declare const saveViewMode: (id: RowKey, viewMode: ViewMode, onChangeConfig?: OnChangeConfig) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const saveViewMode = (id, viewMode, onChangeConfig) => {
|
|
2
|
+
if (onChangeConfig) {
|
|
3
|
+
onChangeConfig({
|
|
4
|
+
reason: "viewMode",
|
|
5
|
+
userConfig: viewMode
|
|
6
|
+
});
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
localStorage.setItem(`${id}_view_mode`, viewMode);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
saveViewMode as s
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useChangeColumnsConfig } from './useChangeColumnsConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UseChangeColumnsConfigParams, UseChangeColumnsConfigReturn } from '../../types.hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Hook para manejar el cambio de configuración de columnas.
|
|
4
|
+
*
|
|
5
|
+
* Guarda la configuración en localStorage y actualiza el estado.
|
|
6
|
+
* @param params - Parámetros del hook
|
|
7
|
+
* @returns Función para cambiar la configuración de columnas
|
|
8
|
+
*/
|
|
9
|
+
export declare const useChangeColumnsConfig: ({ id, onChangeConfig, updateConfigColumns, }: UseChangeColumnsConfigParams) => UseChangeColumnsConfigReturn;
|
|
@@ -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
|
+
|