@m4l/components 9.3.36 → 9.3.37-JT20251128-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/@types/export.d.ts +3 -0
- package/@types/types.d.ts +33 -6
- package/components/DataGrid/DataGrid.js +2 -0
- package/components/DataGrid/Datagrid.styles.js +11 -2
- package/components/DataGrid/contexts/DataGridContext/index.js +43 -268
- package/components/DataGrid/contexts/DataGridContext/types.d.ts +5 -22
- 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/subcomponents/CardHeader/index.js +15 -7
- package/components/DataGrid/subcomponents/CheckboxCellAdapter/index.js +4 -1
- package/components/DataGrid/subcomponents/Table/hooks/useSortColumnsRows.js +6 -2
- package/components/DataGrid/subcomponents/Table/subcomponents/RadioButtonFormatter.d.ts +6 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/RadioButtonFormatter.js +12 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/RadioSelectColumn.d.ts +64 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/RadioSelectColumn.js +46 -0
- package/components/DataGrid/tests/table/subcomponents/RadioButtonFormatter.test.d.ts +1 -0
- package/components/DataGrid/tests/table/subcomponents/RadioSelectColumn.test.d.ts +1 -0
- package/components/DataGrid/types.d.ts +7 -0
- 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/mui_extended/RadioButton/RadioButton.d.ts +24 -0
- package/components/mui_extended/RadioButton/RadioButton.js +110 -0
- package/components/mui_extended/RadioButton/RadioButton.styles.d.ts +2 -0
- package/components/mui_extended/RadioButton/RadioButton.styles.js +126 -0
- package/components/mui_extended/RadioButton/constants.d.ts +1 -0
- package/components/mui_extended/RadioButton/constants.js +4 -0
- package/components/mui_extended/RadioButton/icons.d.ts +4 -0
- package/components/mui_extended/RadioButton/icons.js +7 -0
- package/components/mui_extended/RadioButton/index.d.ts +1 -0
- package/components/mui_extended/RadioButton/index.js +1 -0
- package/components/mui_extended/RadioButton/slots/RadioButtonEnum.d.ts +8 -0
- package/components/mui_extended/RadioButton/slots/RadioButtonEnum.js +12 -0
- package/components/mui_extended/RadioButton/slots/RadioButtonSlots.d.ts +20 -0
- package/components/mui_extended/RadioButton/slots/RadioButtonSlots.js +39 -0
- package/components/mui_extended/RadioButton/tests/RadioButton.test.d.ts +1 -0
- package/components/mui_extended/RadioButton/types.d.ts +50 -0
- package/components/mui_extended/index.d.ts +1 -0
- package/hooks/useDataGridPersistence/constants.d.ts +1 -0
- package/hooks/useDataGridPersistence/constants.js +4 -2
- package/hooks/useDataGridPersistence/useDataGridPersistence.js +5 -2
- package/index.js +44 -42
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function getColumnsWidth(id, columns, defaultUserColumns) {
|
|
2
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
3
|
+
let storeColumnsWidth;
|
|
4
|
+
try {
|
|
5
|
+
const item = window.localStorage.getItem(`${id}_columns_width`);
|
|
6
|
+
storeColumnsWidth = item !== null ? new Map(JSON.parse(item)) : /* @__PURE__ */ new Map();
|
|
7
|
+
} catch (_e) {
|
|
8
|
+
storeColumnsWidth = /* @__PURE__ */ new Map();
|
|
9
|
+
}
|
|
10
|
+
for (let i = 0; i < columns.length; i++) {
|
|
11
|
+
let width;
|
|
12
|
+
if (defaultUserColumns) {
|
|
13
|
+
try {
|
|
14
|
+
width = defaultUserColumns.columnsWidths[columns[i].key];
|
|
15
|
+
} catch (_e) {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (width === void 0) {
|
|
19
|
+
const storeWidth = storeColumnsWidth.get(columns[i].key);
|
|
20
|
+
if (typeof storeWidth === "number") {
|
|
21
|
+
width = storeWidth;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (width !== void 0) {
|
|
25
|
+
newMap.set(columns[i].key, width);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return newMap;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
getColumnsWidth as g
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getColumnsWidth } from './getColumnsWidth';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RowHeightVariants } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Obtiene el índice correspondiente a un variant de altura de fila.
|
|
4
|
+
*
|
|
5
|
+
* ## Propósito
|
|
6
|
+
*
|
|
7
|
+
* Mapea el nombre del variant ('compact', 'standard', 'confortable') a su
|
|
8
|
+
* índice en los arrays de alturas (rowHeights y rowHeaderHeights).
|
|
9
|
+
*
|
|
10
|
+
* ## Mapeo de variants a índices
|
|
11
|
+
*
|
|
12
|
+
* | Variant | Índice |
|
|
13
|
+
* |-------------|--------|
|
|
14
|
+
* | compact | 0 |
|
|
15
|
+
* | standard | 1 |
|
|
16
|
+
* | confortable | 2 |
|
|
17
|
+
* @param variant - Variant de altura de fila
|
|
18
|
+
* @returns Índice correspondiente en los arrays de alturas (0, 1 o 2)
|
|
19
|
+
* @example
|
|
20
|
+
* getIndexRowHeightVariant('compact'); // 0
|
|
21
|
+
* getIndexRowHeightVariant('standard'); // 1
|
|
22
|
+
* getIndexRowHeightVariant('confortable'); // 2
|
|
23
|
+
*/
|
|
24
|
+
export declare const getIndexRowHeightVariant: (variant: RowHeightVariants) => number;
|
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 del usuario (defaultUserConfig) si existe
|
|
12
|
+
* 2. Configuración guardada en localStorage si no hay defaultUserConfig
|
|
13
|
+
* 3. Valores por defecto de las columnas
|
|
14
|
+
*
|
|
15
|
+
* ## Prioridad de configuración
|
|
16
|
+
*
|
|
17
|
+
* 1. defaultUserConfig (del backend/API)
|
|
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 defaultUserConfig - Configuración por defecto del usuario (opcional)
|
|
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, defaultUserConfig?: 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, defaultUserConfig, viewSpecificDefaults, originalViewSpecificDefaults) => {
|
|
4
|
+
let columnsConfig;
|
|
5
|
+
if (defaultUserConfig) {
|
|
6
|
+
columnsConfig = defaultUserConfig;
|
|
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 : 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. **defaultUserColumns.viewMode** (Backend/API) - Prioridad máxima
|
|
12
|
+
* Configuración que viene del backend 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 del backend.
|
|
17
|
+
* Útil para desarrollo o cuando no hay integración con backend.
|
|
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 al backend
|
|
25
|
+
* mediante el callback `onChangeUserColumns`
|
|
26
|
+
* - En la siguiente carga, esos datos vuelven como `defaultUserColumns.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 defaultUserColumns - Configuración del usuario obtenida del backend/API.
|
|
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 del backend (usa localStorage como fallback)
|
|
35
|
+
* const viewMode = getViewMode('my-grid', null, 'table');
|
|
36
|
+
* @example
|
|
37
|
+
* // Con configuración del backend (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, defaultUserColumns: Maybe<IGridConfigExtended>, defaultViewMode?: ViewMode): ViewMode | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function getViewMode(id, defaultUserColumns, defaultViewMode) {
|
|
2
|
+
if (defaultUserColumns?.viewMode) {
|
|
3
|
+
return defaultUserColumns.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, OnChangeUserColumns } 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. **onChangeUserColumns** (Backend/API) - 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 el backend. En la siguiente carga, estos datos volverán
|
|
13
|
+
* como `defaultUserColumns` 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 backend.
|
|
18
|
+
*
|
|
19
|
+
* ## Ciclo completo de persistencia
|
|
20
|
+
*
|
|
21
|
+
* ```
|
|
22
|
+
* Usuario redimensiona columna
|
|
23
|
+
* ↓
|
|
24
|
+
* saveColumnsWidth() envía al backend via onChangeUserColumns
|
|
25
|
+
* ↓
|
|
26
|
+
* Backend persiste en BD/cookies
|
|
27
|
+
* ↓
|
|
28
|
+
* Próxima carga: datos vienen en defaultUserColumns
|
|
29
|
+
* ↓
|
|
30
|
+
* getColumnsWidth() lee de defaultUserColumns
|
|
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 onChangeUserColumns - Callback para enviar la configuración al backend.
|
|
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 al backend
|
|
42
|
+
* saveColumnsWidth('my-grid', columnsWidthsMap, ({ reason, userConfig }) => {
|
|
43
|
+
* // El backend persiste en BD o cookies
|
|
44
|
+
* api.saveUserPreferences(userConfig);
|
|
45
|
+
* });
|
|
46
|
+
* @example
|
|
47
|
+
* // Desarrollo: Guardar en localStorage (sin backend)
|
|
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>>, onChangeUserColumns?: OnChangeUserColumns): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { c as castMapColumnsWidthToRecord } from "../castMapColumnsWidthToRecord.js";
|
|
2
|
+
function saveColumnsWidth(id, storeColumnsWidth, onChangeUserColumns) {
|
|
3
|
+
if (onChangeUserColumns) {
|
|
4
|
+
const columnsWidthObject = castMapColumnsWidthToRecord(storeColumnsWidth);
|
|
5
|
+
onChangeUserColumns({
|
|
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 (API/backend).
|
|
9
|
+
*
|
|
10
|
+
* ## Prioridad de persistencia
|
|
11
|
+
*
|
|
12
|
+
* 1. Si hay `onChangeCallback`, notifica al callback (para guardar en backend)
|
|
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 onChangeCallback - 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, handleChange);
|
|
31
|
+
*/
|
|
32
|
+
export declare const saveViewConfig: <T>(id: RowKey, viewSuffix: string, config: T[], onChangeCallback?: (data: {
|
|
33
|
+
reason: string;
|
|
34
|
+
userConfig: T[];
|
|
35
|
+
}) => void) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const saveViewConfig = (id, viewSuffix, config, onChangeCallback) => {
|
|
2
|
+
if (onChangeCallback) {
|
|
3
|
+
const reason = viewSuffix === "" ? "columnsConfig" : `columnsConfig${viewSuffix.replace("_", "")}`;
|
|
4
|
+
onChangeCallback({
|
|
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 { OnChangeUserColumns, 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 `onChangeUserColumns` → Guarda en backend (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 onChangeUserColumns - Callback opcional para guardar en backend
|
|
24
|
+
* @example
|
|
25
|
+
* // Con backend
|
|
26
|
+
* saveViewMode('my-grid', 'cards', onChangeUserColumns);
|
|
27
|
+
* // Llama: onChangeUserColumns({ reason: 'viewMode', userConfig: 'cards' })
|
|
28
|
+
*
|
|
29
|
+
* // Sin backend (fallback)
|
|
30
|
+
* saveViewMode('my-grid', 'cards');
|
|
31
|
+
* // localStorage: 'my-grid_view_mode' = 'cards'
|
|
32
|
+
*/
|
|
33
|
+
export declare const saveViewMode: (id: RowKey, viewMode: ViewMode, onChangeUserColumns?: OnChangeUserColumns) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const saveViewMode = (id, viewMode, onChangeUserColumns) => {
|
|
2
|
+
if (onChangeUserColumns) {
|
|
3
|
+
onChangeUserColumns({
|
|
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
|
+
|