@m4l/components 9.3.29-JT19112025.beta.6 → 9.3.30-BE211125-beta.1
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/AppBar/styles.js +1 -1
- package/components/Card/Card.styles.js +1 -1
- package/components/DataGrid/Datagrid.styles.js +39 -111
- package/components/DataGrid/dictionary.d.ts +0 -1
- package/components/DataGrid/dictionary.js +1 -2
- package/components/DataGrid/formatters/ColumnIconFormatter/constants.d.ts +4 -0
- package/components/DataGrid/hooks/useModalCardDetail.d.ts +1 -1
- package/components/DataGrid/hooks/useModalCardDetail.js +2 -10
- package/components/DataGrid/icons.d.ts +0 -1
- package/components/DataGrid/icons.js +1 -2
- package/components/DataGrid/slots/DataGridEnum.d.ts +1 -4
- package/components/DataGrid/slots/DataGridEnum.js +0 -3
- package/components/DataGrid/slots/DataGridSlot.d.ts +0 -3
- package/components/DataGrid/slots/DataGridSlot.js +33 -48
- package/components/DataGrid/subcomponents/Cards/hooks/useCardContent.d.ts +1 -1
- package/components/DataGrid/subcomponents/Cards/hooks/useCardContent.js +5 -47
- package/components/DataGrid/subcomponents/Cards/index.js +3 -6
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardDetails/index.d.ts +1 -1
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardDetails/index.js +15 -59
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardHeader/index.js +1 -1
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardRow/index.d.ts +2 -2
- package/components/DataGrid/subcomponents/Cards/subcomponents/CardRow/index.js +1 -5
- package/components/DataGrid/subcomponents/Cards/types.d.ts +0 -16
- package/components/DataGrid/subcomponents/CheckboxCellAdapter/index.js +1 -1
- package/components/DataGrid/subcomponents/ControlNavigate/ControlNavigate.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/index.js +2 -2
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/RowsCount/index.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfig/index.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/Settings/subcomponents/ColumnsConfigCards/index.js +1 -1
- package/components/DataGrid/subcomponents/HeaderActions/subcomponents/ViewMode/index.js +1 -1
- package/components/DataGrid/subcomponents/Table/index.js +1 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/CheckboxFormatter.js +0 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/CustomIcons.js +14 -39
- package/components/DataGrid/subcomponents/Table/subcomponents/DraggableHeaderRenderer.js +1 -1
- package/components/DataGrid/subcomponents/Table/subcomponents/HeaderRenderClick/HeaderRenderClick.js +1 -1
- package/components/DataGrid/subcomponents/editors/TextEditor/index.js +1 -1
- package/components/DataGrid/types.d.ts +0 -12
- package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/helpers.d.ts +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/helpers.js +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/DateTimeFilter/helpers.d.ts +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/DateTimeFilter/helpers.js +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/FieldTypeInterface.d.ts +3 -4
- package/components/DynamicFilter/subcomponents/FieldTypes/NumberFilter/helpers.d.ts +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/NumberFilter/helpers.js +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/SelectAsyncFilter/helpers.d.ts +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/SelectAsyncFilter/helpers.js +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/SelectFilter/helpers.d.ts +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/SelectFilter/helpers.js +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/StringFilter/helpers.d.ts +3 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/StringFilter/helpers.js +3 -2
- package/components/DynamicFilter/subcomponents/PopoverFilter/PopoverFilter.js +1 -1
- package/components/DynamicFilter/subcomponents/PopoverFilter/usePopoverFilter.d.ts +1 -7
- package/components/DynamicSort/subcomponents/FieldTypes/FieldTypeInterface.d.ts +2 -3
- package/components/DynamicSort/subcomponents/FieldTypes/StringSort/helpers.d.ts +3 -2
- package/components/DynamicSort/subcomponents/FieldTypes/StringSort/helpers.js +3 -2
- package/components/DynamicSort/subcomponents/PopoverSort/PopoverSort.js +1 -1
- package/components/DynamicSort/subcomponents/PopoverSort/usePopoverSort.d.ts +1 -7
- package/components/areas/components/AreasAdmin/AreasAdmin.js +1 -1
- package/components/areas/components/AreasAdmin/subcomponents/AreaChip/AreaChip.js +4 -3
- package/components/areas/components/AreasAdmin/subcomponents/AreaChipMobile/subcomponents/ChipMobile/ChipMobile.js +4 -3
- package/components/hook-form/RHFormProvider/RHFormProvider.d.ts +14 -0
- package/components/hook-form/RHFormProvider/RHFormProvider.js +98 -0
- package/components/hook-form/RHFormProvider/index.d.ts +4 -0
- package/components/hook-form/RHFormProvider/index.js +1 -0
- package/components/hook-form/RHFormProvider/schema.d.ts +17 -0
- package/components/hook-form/RHFormProvider/schema.js +29 -0
- package/components/hook-form/RHFormProvider/types.d.ts +133 -0
- package/components/hook-form/RHFormProvider/types.js +8 -0
- package/components/hook-form/index.d.ts +1 -0
- package/contexts/index.d.ts +3 -3
- package/helpers/getStepsAndValidationSchema/getStepsAndValidationSchema.d.ts +3 -3
- package/helpers/getStepsAndValidationSchema/getStepsAndValidationSchema.js +3 -3
- package/helpers/getStepsAndValidationSchema/types.d.ts +5 -4
- package/hooks/index.d.ts +2 -1
- package/hooks/useFormAddEdit/{index.d.ts → useFormAddEdit.d.ts} +3 -2
- package/hooks/useWatchTyped/index.d.ts +1 -0
- package/hooks/useWatchTyped/index.js +1 -0
- package/hooks/useWatchTyped/types.d.ts +11 -0
- package/hooks/useWatchTyped/useTypedWatch.d.ts +9 -0
- package/hooks/useWatchTyped/useTypedWatch.js +30 -0
- package/index.js +47 -36
- package/package.json +1 -1
- package/components/DataGrid/formatters/ColumnColorFormatter/tests/ColumnColorFormatter.test.d.ts +0 -1
- package/components/DataGrid/formatters/ColumnColorFormatter/tests/useColumnColor.test.d.ts +0 -1
- package/components/DataGrid/formatters/ColumnTagsFormatter/tests/ColumnTagsFormatter.test.d.ts +0 -1
- package/components/DataGrid/formatters/ColumnTagsFormatter/tests/useColumnTags.test.d.ts +0 -1
- package/components/hook-form/RHFormContext/index.d.ts +0 -120
- package/components/hook-form/RHFormContext/index.js +0 -91
- package/components/hook-form/RHFormContext/types.d.ts +0 -83
- package/hooks/useFormReadyForUpdate/types.d.ts +0 -8
- /package/components/hook-form/{RHFormContext → RHFormProvider}/classes/constants.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/classes/constants.js +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/classes/index.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/classes/index.js +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/classes/types.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/dictionary.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/dictionary.js +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/styles.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/styles.js +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/subcomponents/FormActions/index.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/subcomponents/FormActions/skeleton.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/subcomponents/FormActions/styles.d.ts +0 -0
- /package/components/hook-form/{RHFormContext → RHFormProvider}/subcomponents/FormActions/types.d.ts +0 -0
- /package/hooks/useFormAddEdit/{index.js → useFormAddEdit.js} +0 -0
|
@@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|
|
2
2
|
import { S as SELECT_ASYNC_OPERATORS_MULTIPLE, c as SELECT_ASYNC_OPERATORS_SINGLE } from "../../../constants.js";
|
|
3
3
|
import { S as SelectAsyncFilter } from "./index.js";
|
|
4
4
|
import { D as DYNAMIC_FILTER_DICTIONARY_ID, a as DICCTIONARY } from "../../../dictionary.js";
|
|
5
|
+
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../hook-form/RHFormProvider/schema.js";
|
|
5
6
|
function filterValidOperandsArraySelectAsync(operandsArray, field) {
|
|
6
7
|
const operandsArrayFormatted = Array.isArray(operandsArray) ? operandsArray : [operandsArray];
|
|
7
8
|
const getOptionId = field?.selectAsyncOptions?.getOptionId;
|
|
@@ -147,7 +148,7 @@ class SelectAsyncFilterHelpers {
|
|
|
147
148
|
* getschema devuelve el esquema de validación de Yup para el filtro.
|
|
148
149
|
*/
|
|
149
150
|
getSchema(getLabel) {
|
|
150
|
-
return
|
|
151
|
+
return createValidationSchema(createValidationFullObject(createValidationPartialObject({
|
|
151
152
|
formValueOperator: Yup.object().nullable().required(getLabel(DICCTIONARY.error_operator_required)),
|
|
152
153
|
formValueOperandsArray: Yup.mixed().when(["multiple"], {
|
|
153
154
|
is: true,
|
|
@@ -157,7 +158,7 @@ class SelectAsyncFilterHelpers {
|
|
|
157
158
|
is: false,
|
|
158
159
|
then: Yup.object().nullable().required(getLabel(DICCTIONARY.error_operand_required))
|
|
159
160
|
})
|
|
160
|
-
});
|
|
161
|
+
})));
|
|
161
162
|
}
|
|
162
163
|
/**
|
|
163
164
|
* verifyFilter verifica si el filtro es válido.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GetLabelType } from '@m4l/core';
|
|
2
2
|
import { Formatters } from '@m4l/graphics';
|
|
3
3
|
import { DataTypeFilerLabels, FilterField, FilterFieldApplied, FilterValue, FilterValueSelect, FormFilterValueSelect, OperandSelect, InitialFilterApplied } from '../../../types';
|
|
4
|
-
import { IFieldType
|
|
4
|
+
import { IFieldType } from '../FieldTypeInterface';
|
|
5
5
|
import { SelectFilter } from './index';
|
|
6
|
+
import { ValidationSchema } from '../../../../hook-form/RHFormProvider';
|
|
6
7
|
/**
|
|
7
8
|
* Filtra los valores de operandArray para que solo tengan valores validos
|
|
8
9
|
* @param operandsArray valores del OperandsArray
|
|
@@ -35,7 +36,7 @@ export declare class SelectFilterHelpers implements IFieldType<FormFilterValueSe
|
|
|
35
36
|
/**
|
|
36
37
|
* getSchema devuelve el esquema de validación de Yup para un filtro de selección.
|
|
37
38
|
*/
|
|
38
|
-
getSchema(getLabel: GetLabelType):
|
|
39
|
+
getSchema(getLabel: GetLabelType): ValidationSchema<FormFilterValueSelect>;
|
|
39
40
|
/**
|
|
40
41
|
* TODO: Documentar
|
|
41
42
|
*/
|
|
@@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|
|
2
2
|
import { d as SELECT_OPERATORS_MULTIPLE, e as SELECT_OPERATORS_SINGLE } from "../../../constants.js";
|
|
3
3
|
import { S as SelectFilter } from "./index.js";
|
|
4
4
|
import { D as DYNAMIC_FILTER_DICTIONARY_ID, a as DICCTIONARY } from "../../../dictionary.js";
|
|
5
|
+
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../hook-form/RHFormProvider/schema.js";
|
|
5
6
|
function filterValidOperandsArraySelect(operandsArray, _field) {
|
|
6
7
|
const operandsArrayFormatted = Array.isArray(operandsArray) ? operandsArray : [operandsArray];
|
|
7
8
|
return operandsArrayFormatted?.filter((operand) => {
|
|
@@ -145,7 +146,7 @@ class SelectFilterHelpers {
|
|
|
145
146
|
* getSchema devuelve el esquema de validación de Yup para un filtro de selección.
|
|
146
147
|
*/
|
|
147
148
|
getSchema(getLabel) {
|
|
148
|
-
return
|
|
149
|
+
return createValidationSchema(createValidationFullObject(createValidationPartialObject({
|
|
149
150
|
formValueOperator: Yup.object().nullable().required(getLabel(DICCTIONARY.error_operator_required)),
|
|
150
151
|
formValueOperandsArray: Yup.mixed().when(["multiple"], {
|
|
151
152
|
is: true,
|
|
@@ -161,7 +162,7 @@ class SelectFilterHelpers {
|
|
|
161
162
|
}
|
|
162
163
|
).required(getLabel(DICCTIONARY.error_operand_required))
|
|
163
164
|
})
|
|
164
|
-
});
|
|
165
|
+
})));
|
|
165
166
|
}
|
|
166
167
|
/**
|
|
167
168
|
* TODO: Documentar
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GetLabelType } from '@m4l/core';
|
|
2
2
|
import { Formatters } from '@m4l/graphics';
|
|
3
3
|
import { DataTypeFilerLabels, FilterField, FilterFieldApplied, FilterValue, FormFilterValueString, InitialFilterApplied } from '../../../types';
|
|
4
|
-
import { IFieldType
|
|
4
|
+
import { IFieldType } from '../FieldTypeInterface';
|
|
5
5
|
import { StringFilter } from './index';
|
|
6
|
+
import { ValidationSchema } from '../../../../hook-form/RHFormProvider/types';
|
|
6
7
|
/**
|
|
7
8
|
* StringFilterHelpers es una clase que implementa la interfaz IFieldType
|
|
8
9
|
*/
|
|
@@ -27,7 +28,7 @@ export declare class StringFilterHelpers implements IFieldType<FormFilterValueSt
|
|
|
27
28
|
/**
|
|
28
29
|
* getSchema devuelve el esquema de validación para el filtro de cadena.
|
|
29
30
|
*/
|
|
30
|
-
getSchema(getLabel: GetLabelType):
|
|
31
|
+
getSchema(getLabel: GetLabelType): ValidationSchema<FormFilterValueString>;
|
|
31
32
|
/**
|
|
32
33
|
* getFilterValue devuelve el valor del filtro.
|
|
33
34
|
*/
|
|
@@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|
|
2
2
|
import { f as STRING_OPERATORS } from "../../../constants.js";
|
|
3
3
|
import { D as DYNAMIC_FILTER_DICTIONARY_ID, a as DICCTIONARY } from "../../../dictionary.js";
|
|
4
4
|
import { S as StringFilter } from "./index.js";
|
|
5
|
+
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../hook-form/RHFormProvider/schema.js";
|
|
5
6
|
class StringFilterHelpers {
|
|
6
7
|
getComponent() {
|
|
7
8
|
return StringFilter;
|
|
@@ -74,12 +75,12 @@ class StringFilterHelpers {
|
|
|
74
75
|
* getSchema devuelve el esquema de validación para el filtro de cadena.
|
|
75
76
|
*/
|
|
76
77
|
getSchema(getLabel) {
|
|
77
|
-
return
|
|
78
|
+
return createValidationSchema(createValidationFullObject(createValidationPartialObject({
|
|
78
79
|
formValueOperator: Yup.object().nullable().required(getLabel(DICCTIONARY.error_operator_required)),
|
|
79
80
|
formValueOperand1: Yup.string().required(
|
|
80
81
|
getLabel(DICCTIONARY.error_operand_required)
|
|
81
82
|
)
|
|
82
|
-
});
|
|
83
|
+
})));
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* getFilterValue devuelve el valor del filtro.
|
|
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { D as DataTypeComponent } from "../FieldTypes/DataTypeComponent.js";
|
|
3
3
|
import { u as usePopoverFilter } from "./usePopoverFilter.js";
|
|
4
4
|
import { P as PopoverStyled, h as PopoverContainerFieldsStyled, i as PopoverHeaderActionsStyled } from "../../slots/dynamicFilterSlots.js";
|
|
5
|
-
import { R as RHFormProvider } from "../../../hook-form/
|
|
5
|
+
import { R as RHFormProvider } from "../../../hook-form/RHFormProvider/RHFormProvider.js";
|
|
6
6
|
import { W as WindowBase } from "../../../WindowBase/WindowBase.js";
|
|
7
7
|
import { A as ActionCancel } from "../../../CommonActions/components/ActionCancel/ActionCancel.js";
|
|
8
8
|
import { A as ActionIntro } from "../../../CommonActions/components/ActionIntro/ActionIntro.js";
|
|
@@ -16,13 +16,7 @@ declare function usePopoverFilter(): {
|
|
|
16
16
|
onClose: () => void;
|
|
17
17
|
filterFormValue: FormFilterValue;
|
|
18
18
|
formFilter: FormFilterFieldApplied;
|
|
19
|
-
popupValidationSchema: import('
|
|
20
|
-
[x: string]: import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>> | import('yup').BaseSchema<any, import('yup/lib/object').AnyObject, any> | import('yup').ArraySchema<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown> | import('yup/lib/Lazy').default<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown>, import('yup/lib/object').AnyObject>, import('yup/lib/types').AnyObject, unknown[] | undefined, unknown[] | undefined> | import('yup/lib/Lazy').default<import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>>, any>;
|
|
21
|
-
}, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape<{
|
|
22
|
-
[x: string]: import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>> | import('yup').BaseSchema<any, import('yup/lib/object').AnyObject, any> | import('yup').ArraySchema<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown> | import('yup/lib/Lazy').default<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown>, import('yup/lib/object').AnyObject>, import('yup/lib/types').AnyObject, unknown[] | undefined, unknown[] | undefined> | import('yup/lib/Lazy').default<import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>>, any>;
|
|
23
|
-
}>, import('yup/lib/object').AssertsShape<{
|
|
24
|
-
[x: string]: import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>> | import('yup').BaseSchema<any, import('yup/lib/object').AnyObject, any> | import('yup').ArraySchema<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown> | import('yup/lib/Lazy').default<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown>, import('yup/lib/object').AnyObject>, import('yup/lib/types').AnyObject, unknown[] | undefined, unknown[] | undefined> | import('yup/lib/Lazy').default<import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>>, any>;
|
|
25
|
-
}>> | undefined;
|
|
19
|
+
popupValidationSchema: import('../../..').ValidationSchema<import('../../types').FormFilterValueBoolean> | undefined;
|
|
26
20
|
statusLoad: "initial" | "reload_values_provider" | "ready";
|
|
27
21
|
};
|
|
28
22
|
export default usePopoverFilter;
|
|
@@ -2,8 +2,7 @@ import { GetLabelType } from '@m4l/core';
|
|
|
2
2
|
import { Formatters } from '@m4l/graphics';
|
|
3
3
|
import { FC } from 'react';
|
|
4
4
|
import { DataTypeFilerLabels, FormSortValueBase, InitialSortApplied, SortField, SortFieldApplied, SortValue } from '../../types';
|
|
5
|
-
import
|
|
6
|
-
export type YupSchema = Yup.SchemaOf<any>;
|
|
5
|
+
import { ValidationSchema } from '../../../hook-form/RHFormProvider/types';
|
|
7
6
|
/**
|
|
8
7
|
* Interface para crear los helpers de cada tipo de campo
|
|
9
8
|
*/
|
|
@@ -13,7 +12,7 @@ export interface IFieldType {
|
|
|
13
12
|
}>;
|
|
14
13
|
getDefaultSort(field: SortField, fixed: boolean): SortFieldApplied;
|
|
15
14
|
getLabels(Sort: SortFieldApplied, getLabel: GetLabelType, formatters: Formatters, field: SortField): DataTypeFilerLabels;
|
|
16
|
-
getSchema(getLabel: GetLabelType):
|
|
15
|
+
getSchema(getLabel: GetLabelType): ValidationSchema<FormSortValueBase>;
|
|
17
16
|
getFormValue(field: SortField, getLabel: GetLabelType, sortValue?: SortValue): FormSortValueBase;
|
|
18
17
|
getSortFromFormValue(formSortValue: FormSortValueBase): SortValue;
|
|
19
18
|
verifySort(Sort: InitialSortApplied, field?: SortField): boolean;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { GetLabelType } from '@m4l/core';
|
|
2
2
|
import { Formatters } from '@m4l/graphics';
|
|
3
3
|
import { DataTypeFilerLabels, FormSortValueBase, InitialSortApplied, SortField, SortFieldApplied, SortValue } from '../../../types';
|
|
4
|
-
import { IFieldType
|
|
4
|
+
import { IFieldType } from '../FieldTypeInterface';
|
|
5
5
|
import { StringSort } from './index';
|
|
6
|
+
import { ValidationSchema } from '../../../../hook-form/RHFormProvider/types';
|
|
6
7
|
/**
|
|
7
8
|
* Clase que implementa los métodos necesarios para el tipo de campo string
|
|
8
9
|
*/
|
|
@@ -27,7 +28,7 @@ export declare class SortHelpers implements IFieldType {
|
|
|
27
28
|
/**
|
|
28
29
|
* getSchema obtiene el esquema de un campo de tipo string
|
|
29
30
|
*/
|
|
30
|
-
getSchema(getLabel: GetLabelType):
|
|
31
|
+
getSchema(getLabel: GetLabelType): ValidationSchema<FormSortValueBase>;
|
|
31
32
|
/**
|
|
32
33
|
* verifySort verifica si un campo de tipo string es válido
|
|
33
34
|
*/
|
|
@@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|
|
2
2
|
import { O as OPERATORS } from "../../../constants.js";
|
|
3
3
|
import { g as getDynamicSortDictionary } from "../../../dictionary.js";
|
|
4
4
|
import { S as StringSort } from "./index.js";
|
|
5
|
+
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../hook-form/RHFormProvider/schema.js";
|
|
5
6
|
class SortHelpers {
|
|
6
7
|
getComponent() {
|
|
7
8
|
return StringSort;
|
|
@@ -59,9 +60,9 @@ class SortHelpers {
|
|
|
59
60
|
* getSchema obtiene el esquema de un campo de tipo string
|
|
60
61
|
*/
|
|
61
62
|
getSchema(getLabel) {
|
|
62
|
-
return
|
|
63
|
+
return createValidationSchema(createValidationFullObject(createValidationPartialObject({
|
|
63
64
|
formValueOperator: Yup.string().required(getLabel(`dynamic_Sort.error_operator_required`))
|
|
64
|
-
});
|
|
65
|
+
})));
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* verifySort verifica si un campo de tipo string es válido
|
|
@@ -3,7 +3,7 @@ import { u as useDynamicSortBase } from "../DynamicSortBase/useDynamicSortBase.j
|
|
|
3
3
|
import { D as DataTypeComponent } from "../FieldTypes/DataTypeComponent.js";
|
|
4
4
|
import { u as usePopoverSort } from "./usePopoverSort.js";
|
|
5
5
|
import { e as PopoverStyled, f as PopoverContainerFieldsStyled, g as PopoverHeaderActionsStyled } from "../../slots/DynamicSortSlots.js";
|
|
6
|
-
import { R as RHFormProvider } from "../../../hook-form/
|
|
6
|
+
import { R as RHFormProvider } from "../../../hook-form/RHFormProvider/RHFormProvider.js";
|
|
7
7
|
import { W as WindowBase } from "../../../WindowBase/WindowBase.js";
|
|
8
8
|
import { A as ActionCancel } from "../../../CommonActions/components/ActionCancel/ActionCancel.js";
|
|
9
9
|
import { A as ActionIntro } from "../../../CommonActions/components/ActionIntro/ActionIntro.js";
|
|
@@ -16,13 +16,7 @@ declare function usePopoverSort(): {
|
|
|
16
16
|
onClose: () => void;
|
|
17
17
|
sortFormValue: import('../../types').FormSortValueBase;
|
|
18
18
|
formSort: FormSortFieldApplied;
|
|
19
|
-
popupValidationSchema: import('
|
|
20
|
-
[x: string]: import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>> | import('yup').BaseSchema<any, import('yup/lib/object').AnyObject, any> | import('yup').ArraySchema<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown> | import('yup/lib/Lazy').default<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown>, import('yup/lib/object').AnyObject>, import('yup/lib/types').AnyObject, unknown[] | undefined, unknown[] | undefined> | import('yup/lib/Lazy').default<import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>>, any>;
|
|
21
|
-
}, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape<{
|
|
22
|
-
[x: string]: import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>> | import('yup').BaseSchema<any, import('yup/lib/object').AnyObject, any> | import('yup').ArraySchema<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown> | import('yup/lib/Lazy').default<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown>, import('yup/lib/object').AnyObject>, import('yup/lib/types').AnyObject, unknown[] | undefined, unknown[] | undefined> | import('yup/lib/Lazy').default<import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>>, any>;
|
|
23
|
-
}>, import('yup/lib/object').AssertsShape<{
|
|
24
|
-
[x: string]: import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>> | import('yup').BaseSchema<any, import('yup/lib/object').AnyObject, any> | import('yup').ArraySchema<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown> | import('yup/lib/Lazy').default<import('yup').BaseSchema<unknown, import('yup/lib/object').AnyObject, unknown>, import('yup/lib/object').AnyObject>, import('yup/lib/types').AnyObject, unknown[] | undefined, unknown[] | undefined> | import('yup/lib/Lazy').default<import('yup').ObjectSchema</*elided*/ any, import('yup/lib/object').AnyObject, import('yup/lib/object').TypeOfShape</*elided*/ any>, import('yup/lib/object').AssertsShape</*elided*/ any>>, any>;
|
|
25
|
-
}>> | undefined;
|
|
19
|
+
popupValidationSchema: import('../../..').ValidationSchema<import('../../types').FormSortValueBase> | undefined;
|
|
26
20
|
statusLoad: "initial" | "reload_values_provider" | "ready";
|
|
27
21
|
};
|
|
28
22
|
export default usePopoverSort;
|
|
@@ -134,7 +134,7 @@ const AreasAdmin = (props) => {
|
|
|
134
134
|
}
|
|
135
135
|
),
|
|
136
136
|
maximizedId && windowsLayouts.length > 1 && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(ContainerAdminWindowsStyled, { size: currentSize, ownerState, children: [
|
|
137
|
-
/* @__PURE__ */ jsx(Typography, { size: currentSize, children: getLabel(getAreasDictionary(AREAS_DICCTIONARY.label_window)) }),
|
|
137
|
+
/* @__PURE__ */ jsx(Typography, { size: currentSize, skeletonWidth: "80px", children: getLabel(getAreasDictionary(AREAS_DICCTIONARY.label_window)) }),
|
|
138
138
|
/* @__PURE__ */ jsx(
|
|
139
139
|
MenuActions,
|
|
140
140
|
{
|
|
@@ -12,8 +12,9 @@ import { g as getAreasDictionary, A as AREAS_DICCTIONARY } from "../../../../dic
|
|
|
12
12
|
import { A as AREAS_ADMIN_KEY_COMPONENT } from "../../constants.js";
|
|
13
13
|
import { g as getComponentClasses } from "../../../../../../utils/getComponentSlotRoot.js";
|
|
14
14
|
import { u as useComponentSize } from "../../../../../../hooks/useComponentSize/useComponentSize.js";
|
|
15
|
+
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../../hook-form/RHFormProvider/schema.js";
|
|
15
16
|
import { A as AreasAdminSlots } from "../../slots/AreasAdminEnum.js";
|
|
16
|
-
import { R as RHFormProvider } from "../../../../../hook-form/
|
|
17
|
+
import { R as RHFormProvider } from "../../../../../hook-form/RHFormProvider/RHFormProvider.js";
|
|
17
18
|
import { T as Typography } from "../../../../../mui_extended/Typography/Typography.js";
|
|
18
19
|
import { R as RHFTextField } from "../../../../../hook-form/RHFTextField/RHFTextField.js";
|
|
19
20
|
import { A as ActionsContainer } from "../../../../../CommonActions/components/ActionsContainer/ActionsContainer.js";
|
|
@@ -56,11 +57,11 @@ const AreaChip = (props) => {
|
|
|
56
57
|
inputEditArea: areaName
|
|
57
58
|
};
|
|
58
59
|
const validationSchema = useMemo(
|
|
59
|
-
() =>
|
|
60
|
+
() => createValidationSchema(createValidationFullObject(createValidationPartialObject({
|
|
60
61
|
inputEditArea: Yup.string().required(
|
|
61
62
|
getLabel(getAreasDictionary(AREAS_DICCTIONARY.validation_edit_area))
|
|
62
63
|
)
|
|
63
|
-
}),
|
|
64
|
+
}))),
|
|
64
65
|
[getLabel]
|
|
65
66
|
);
|
|
66
67
|
const handlerOnClick = (e) => {
|
|
@@ -9,9 +9,10 @@ import { g as getAreasDictionary, A as AREAS_DICCTIONARY } from "../../../../../
|
|
|
9
9
|
import { I as ICONS } from "../../../../../../icons.js";
|
|
10
10
|
import { C as ChipActionsMobile } from "../../../AreaChip/subcomponents/ChipActionsMobile/ChipActionsMobile.js";
|
|
11
11
|
import { l as ChipMobileRootStyled, m as ChipMobileContentStyled, N as NameChipMobileStyled, n as EditAreaChipMobileContainerStyled } from "../../../../slots/AreasAdminSlots.js";
|
|
12
|
-
import { R as RHFormProvider } from "../../../../../../../hook-form/
|
|
12
|
+
import { R as RHFormProvider } from "../../../../../../../hook-form/RHFormProvider/RHFormProvider.js";
|
|
13
13
|
import { T as Typography } from "../../../../../../../mui_extended/Typography/Typography.js";
|
|
14
14
|
import { A as ActionsContainer } from "../../../../../../../CommonActions/components/ActionsContainer/ActionsContainer.js";
|
|
15
|
+
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../../../../hook-form/RHFormProvider/schema.js";
|
|
15
16
|
import { M as MenuActions } from "../../../../../../../MenuActions/MenuActions.js";
|
|
16
17
|
import { P as Popover } from "../../../../../../../mui_extended/Popover/Popover.js";
|
|
17
18
|
import { R as RHFTextField } from "../../../../../../../hook-form/RHFTextField/RHFTextField.js";
|
|
@@ -44,11 +45,11 @@ const ChipMobile = (props) => {
|
|
|
44
45
|
inputEditArea: areaName
|
|
45
46
|
};
|
|
46
47
|
const validationSchema = useMemo(
|
|
47
|
-
() =>
|
|
48
|
+
() => createValidationSchema(createValidationFullObject(createValidationPartialObject({
|
|
48
49
|
inputEditArea: Yup.string().required(
|
|
49
50
|
getLabel(getAreasDictionary(AREAS_DICCTIONARY.validation_edit_area))
|
|
50
51
|
)
|
|
51
|
-
}),
|
|
52
|
+
}))),
|
|
52
53
|
[getLabel]
|
|
53
54
|
);
|
|
54
55
|
const handlerOnClick = (e) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactElement, RefAttributes } from 'react';
|
|
2
|
+
import { CustomFormArguments, FormProviderCustomProps, RHFormProviderProps, RHFormProviderRef, RHFormValues } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* useCustomForm se encarga de crear los metodos del formulario y validar el statusLoad para recargar los valores del formulario nuevamente.
|
|
5
|
+
* Cuando statusLoad es 'reload_values_provider' se actualizan los valores del formulario, debido a que se cargaron del backend.
|
|
6
|
+
* Cuando statusLoad es 'ready' se actualiza el statusLoad del formulario a 'ready', para que los que useWatch puedan ser efectivos despues de la carga de los datos.
|
|
7
|
+
* Se recomienda usar useFormReadyForUpdate que se nutre de statusLoad e indica que el formulario esta listo para ser usado.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useCustomForm<T extends RHFormValues>({ validationSchema, values, statusLoad, mode, }: CustomFormArguments<T>): import('react-hook-form').UseFormReturn<T, undefined, T>;
|
|
10
|
+
/**
|
|
11
|
+
* Componente que extiende FormProviderCustomBase para poder ser usado dentro del forwardRef garantizando el tipado.
|
|
12
|
+
*/
|
|
13
|
+
export declare const FormProviderCustom: <T extends RHFormValues>(props: FormProviderCustomProps<T> & RefAttributes<RHFormProviderRef<T>>) => ReactElement;
|
|
14
|
+
export declare const RHFormProvider: <T extends RHFormValues>(props: RHFormProviderProps<T> & RefAttributes<RHFormProviderRef<T>>) => ReactElement;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useImperativeHandle } from "react";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useForm, FormProvider } from "react-hook-form";
|
|
5
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
6
|
+
import { F as FormProviderRoot } from "./styles.js";
|
|
7
|
+
import { R as RHFormProviderUtilityClasses } from "./classes/index.js";
|
|
8
|
+
const classes = RHFormProviderUtilityClasses();
|
|
9
|
+
function useCustomForm({
|
|
10
|
+
validationSchema,
|
|
11
|
+
values,
|
|
12
|
+
statusLoad,
|
|
13
|
+
mode
|
|
14
|
+
}) {
|
|
15
|
+
const formMethods = useForm({
|
|
16
|
+
resolver: yupResolver(validationSchema),
|
|
17
|
+
defaultValues: values,
|
|
18
|
+
...mode && { mode }
|
|
19
|
+
});
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (statusLoad === "reload_values_provider") {
|
|
22
|
+
const keys = Object.keys(values);
|
|
23
|
+
keys.forEach((key) => {
|
|
24
|
+
const fieldName = key;
|
|
25
|
+
const fieldValue = values[key];
|
|
26
|
+
formMethods.setValue(fieldName, fieldValue, {
|
|
27
|
+
shouldValidate: false,
|
|
28
|
+
shouldDirty: false,
|
|
29
|
+
shouldTouch: false
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
formMethods.clearErrors();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}, [formMethods, statusLoad, values]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (statusLoad === "ready") {
|
|
38
|
+
formMethods.setValue("statusLoad", "ready", {
|
|
39
|
+
shouldValidate: false,
|
|
40
|
+
shouldDirty: false,
|
|
41
|
+
shouldTouch: false
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}, [statusLoad]);
|
|
45
|
+
return formMethods;
|
|
46
|
+
}
|
|
47
|
+
const FormProviderCustomBase = (props, ref) => {
|
|
48
|
+
const { children, onSubmit, onSubmitError, className, formMethods } = props;
|
|
49
|
+
useImperativeHandle(
|
|
50
|
+
ref,
|
|
51
|
+
() => ({
|
|
52
|
+
formMethods,
|
|
53
|
+
onSubmit
|
|
54
|
+
}),
|
|
55
|
+
[formMethods, onSubmit]
|
|
56
|
+
);
|
|
57
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...formMethods, children: /* @__PURE__ */ jsx(
|
|
58
|
+
FormProviderRoot,
|
|
59
|
+
{
|
|
60
|
+
className: clsx(classes.root, className),
|
|
61
|
+
onSubmit: formMethods.handleSubmit(
|
|
62
|
+
onSubmit,
|
|
63
|
+
onSubmitError
|
|
64
|
+
),
|
|
65
|
+
children
|
|
66
|
+
}
|
|
67
|
+
) });
|
|
68
|
+
};
|
|
69
|
+
const FormProviderCustomForward = forwardRef(FormProviderCustomBase);
|
|
70
|
+
FormProviderCustomForward.displayName = "FormProviderCustom";
|
|
71
|
+
const FormProviderCustom = FormProviderCustomForward;
|
|
72
|
+
const RHFormProviderBase = forwardRef(
|
|
73
|
+
(props, ref) => {
|
|
74
|
+
const { children, onSubmit, onSubmitError, values, validationSchema, statusLoad = "ready", className, mode } = props;
|
|
75
|
+
const formMethods = useCustomForm({ validationSchema, statusLoad, values, mode });
|
|
76
|
+
return /* @__PURE__ */ jsx(
|
|
77
|
+
FormProviderCustom,
|
|
78
|
+
{
|
|
79
|
+
ref,
|
|
80
|
+
className,
|
|
81
|
+
values,
|
|
82
|
+
validationSchema,
|
|
83
|
+
statusLoad,
|
|
84
|
+
onSubmit,
|
|
85
|
+
onSubmitError,
|
|
86
|
+
formMethods,
|
|
87
|
+
children
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
RHFormProviderBase.displayName = "RHFormProvider";
|
|
93
|
+
const RHFormProvider = RHFormProviderBase;
|
|
94
|
+
export {
|
|
95
|
+
FormProviderCustom as F,
|
|
96
|
+
RHFormProvider as R,
|
|
97
|
+
useCustomForm as u
|
|
98
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './RHFormProvider';
|
|
2
|
+
export type { ValidationSchema, ValidationShape, ValidationFullObject as ValidationObject, ValidationPartialObject, RHFormInitialValues, RHFormValues, } from './types';
|
|
3
|
+
export { VALIDATION_SCHEMA_BRAND, VALIDATION_PARTIAL_OBJECT_BRAND, VALIDATION_OBJECT_BRAND, } from './types';
|
|
4
|
+
export * from './schema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RHFormValues, ValidationFullObject, ValidationSchema, ValidationShape, ValidationPartialObject } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Crea un esquema de Yup a partir de un shape tipado y mantiene la asociación con el tipo del formulario.
|
|
4
|
+
*/
|
|
5
|
+
export declare const createValidationSchema: <T extends RHFormValues>(valitionFullObject: ValidationFullObject<T>) => ValidationSchema<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Crea un esquema de Yup a partir de un shape tipado y mantiene la asociación con el tipo del formulario.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createValidationPartialObject: <T extends RHFormValues>(partialObjectShape: ValidationShape<T>) => ValidationPartialObject<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Marca un ObjectShape para garantizar que fue construido mediante createValidationObject.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createValidationFullObject: <T extends RHFormValues>(...partialObjectShape: Array<ValidationPartialObject<T>>) => ValidationFullObject<T>;
|
|
14
|
+
/**
|
|
15
|
+
* crea un squema de validación vacío, para los testing
|
|
16
|
+
*/
|
|
17
|
+
export declare const createEmptyValidationSchema: <T extends RHFormValues>() => ValidationSchema<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as Yup from "yup";
|
|
2
|
+
import { V as VALIDATION_OBJECT_BRAND } from "./types.js";
|
|
3
|
+
const createValidationSchema = (valitionFullObject) => {
|
|
4
|
+
const schema = Yup.object().shape(valitionFullObject);
|
|
5
|
+
return schema;
|
|
6
|
+
};
|
|
7
|
+
const createValidationPartialObject = (partialObjectShape) => {
|
|
8
|
+
const validationPartialObject = { ...partialObjectShape };
|
|
9
|
+
return validationPartialObject;
|
|
10
|
+
};
|
|
11
|
+
const createValidationFullObject = (...partialObjectShape) => {
|
|
12
|
+
const mergedShape = Object.assign({}, ...partialObjectShape);
|
|
13
|
+
Object.defineProperty(mergedShape, VALIDATION_OBJECT_BRAND, {
|
|
14
|
+
configurable: false,
|
|
15
|
+
enumerable: false,
|
|
16
|
+
writable: false,
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
return mergedShape;
|
|
20
|
+
};
|
|
21
|
+
const createEmptyValidationSchema = () => {
|
|
22
|
+
return createValidationSchema(createValidationFullObject(createValidationPartialObject({})));
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
createValidationFullObject as a,
|
|
26
|
+
createValidationPartialObject as b,
|
|
27
|
+
createValidationSchema as c,
|
|
28
|
+
createEmptyValidationSchema as d
|
|
29
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { Mode, SubmitErrorHandler, UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import { ObjectSchema } from 'yup';
|
|
4
|
+
import { ObjectShape } from 'yup/lib/object';
|
|
5
|
+
/**
|
|
6
|
+
* Estados de carga del formulario que determinan cuándo y cómo actualizar los valores.
|
|
7
|
+
*
|
|
8
|
+
* - `initial`: Estado inicial del formulario
|
|
9
|
+
* - `new`: Formulario para crear un nuevo elemento
|
|
10
|
+
* - `edit`: Formulario para editar un elemento existente
|
|
11
|
+
* - `reload_values_provider`: Estado que indica que se deben recargar los valores del proveedor
|
|
12
|
+
* - `ready`: Formulario listo para ser usado
|
|
13
|
+
* - `error`: Estado de error en el formulario
|
|
14
|
+
*/
|
|
15
|
+
export type FormStatusLoad = 'initial' | 'new' | 'edit' | 'reload_values_provider' | 'ready' | 'error';
|
|
16
|
+
export type RHFormValues = {};
|
|
17
|
+
/**
|
|
18
|
+
* Tipo que define los valores iniciales del formulario.
|
|
19
|
+
* Extiende FieldValues de React Hook Form para mayor flexibilidad.
|
|
20
|
+
*/
|
|
21
|
+
export type RHFormInitialValues<T extends RHFormValues> = Partial<T>;
|
|
22
|
+
/**
|
|
23
|
+
* LiteralKeys es un tipo que define las claves literales del formulario. excepto statusLoad, que no es necesario que el usuario la aporte.
|
|
24
|
+
*/
|
|
25
|
+
export type LiteralKeys<T> = Exclude<Extract<keyof T, string>, 'statusLoad'>;
|
|
26
|
+
/**
|
|
27
|
+
* StrictFormValues es un tipo que define los valores del formulario explicitamente.
|
|
28
|
+
*/
|
|
29
|
+
export type StrictFormValues<T extends RHFormValues> = Pick<RHFormInitialValues<T>, LiteralKeys<RHFormInitialValues<T>>>;
|
|
30
|
+
/**
|
|
31
|
+
* Garantiza que el shape sólo contenga claves declaradas en el tipo del formulario.
|
|
32
|
+
* Si usa un key que no está en el tipo del formulario, se devuelve never. Protegiendo el ingreso de claves diferentes.
|
|
33
|
+
*/
|
|
34
|
+
export type EnsureAllowedKeys<Shape, Allowed extends string> = Exclude<keyof Shape, Allowed> extends never ? Shape : never;
|
|
35
|
+
/**
|
|
36
|
+
* YupShapeEntry es un tipo que define la entrada de un shape de Yup.
|
|
37
|
+
*/
|
|
38
|
+
type YupShapeEntry = ObjectShape[string];
|
|
39
|
+
/**
|
|
40
|
+
* ValidationShape veririca que solo YupShapeEntry puedan ser usados en algunos campos de RHFormValues.
|
|
41
|
+
*/
|
|
42
|
+
export type ValidationShape<T extends RHFormValues> = Partial<Record<LiteralKeys<T>, YupShapeEntry>>;
|
|
43
|
+
/**
|
|
44
|
+
* Symbol que contiene el ValidationSchema que lo hace diferente a ObjectSchema normal de Yup.
|
|
45
|
+
*/
|
|
46
|
+
export declare const VALIDATION_SCHEMA_BRAND: unique symbol;
|
|
47
|
+
/**
|
|
48
|
+
* Symbol que identifica que un ValidationShape fue construido mediante createValidationObject.
|
|
49
|
+
*/
|
|
50
|
+
export declare const VALIDATION_OBJECT_BRAND: unique symbol;
|
|
51
|
+
/**
|
|
52
|
+
* Symbol que identifica que un ValidationShape parcial fue construido mediante createValidationPartialObject.
|
|
53
|
+
*/
|
|
54
|
+
export declare const VALIDATION_PARTIAL_OBJECT_BRAND: unique symbol;
|
|
55
|
+
/**
|
|
56
|
+
* ValidationSchema es un tipo que define el schema de validación del formulario. Aporta el brand VALIDATION_SCHEMA_BRAND para hacer diferentes a ObjectSchema normal de Yup.
|
|
57
|
+
* y asi poder garantizar que se use la función createValidationSchema para crear la schema.
|
|
58
|
+
*/
|
|
59
|
+
export type ValidationSchema<T extends RHFormValues> = ObjectSchema<any> & {
|
|
60
|
+
/**
|
|
61
|
+
* Aunque no se use en el codigo a nivel de javascript, es necesario para que el tipo de la schema para hacerlos diferente a ObjectSchema. y obliga
|
|
62
|
+
* a que se use la función createValidationSchema para crear la schema.
|
|
63
|
+
*/
|
|
64
|
+
readonly [VALIDATION_SCHEMA_BRAND]: ValidationShape<T>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* ValidationFullObject garantiza que el shape sea construido mediante createValidationObject.
|
|
68
|
+
* con base en los partialObjectShape que se le pasan a createValidationObject.
|
|
69
|
+
*/
|
|
70
|
+
export type ValidationFullObject<T extends RHFormValues> = ValidationShape<T> & {
|
|
71
|
+
readonly [VALIDATION_OBJECT_BRAND]: true;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* ValidationPartialObject garantiza que el shape parcial sea construido mediante createValidationPartialObject.
|
|
75
|
+
*/
|
|
76
|
+
export type ValidationPartialObject<T extends RHFormValues> = ValidationShape<T> & {
|
|
77
|
+
readonly [VALIDATION_PARTIAL_OBJECT_BRAND]: true;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Propiedades del componente principal RHFormProvider.
|
|
81
|
+
* Define la interfaz para crear formularios con React Hook Form y validación Yup.
|
|
82
|
+
*/
|
|
83
|
+
export interface RHFormProviderProps<T extends RHFormValues> {
|
|
84
|
+
/** Elementos hijos del formulario */
|
|
85
|
+
children: ReactNode;
|
|
86
|
+
/** Función que se ejecuta al enviar el formulario con los datos validados */
|
|
87
|
+
onSubmit: ((data: T) => void) | ((data: T) => Promise<void>);
|
|
88
|
+
/**
|
|
89
|
+
* Cuando hay un error en la validación del formulario, se ejecuta esta función.
|
|
90
|
+
*/
|
|
91
|
+
onSubmitError?: SubmitErrorHandler<T>;
|
|
92
|
+
/** Valores iniciales del formulario si es un new o cargados del backend si son edit */
|
|
93
|
+
values: RHFormInitialValues<T>;
|
|
94
|
+
/** Esquema de validación de Yup */
|
|
95
|
+
validationSchema: ValidationSchema<T>;
|
|
96
|
+
/** Estado de carga del formulario (opcional, por defecto 'ready') */
|
|
97
|
+
statusLoad?: FormStatusLoad;
|
|
98
|
+
/** Clases CSS adicionales (opcional) */
|
|
99
|
+
className?: string;
|
|
100
|
+
/** Modo de validación del formulario (opcional) */
|
|
101
|
+
mode?: Mode;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Propiedades del componente FormProviderCustom.
|
|
105
|
+
* Combina las propiedades de React Hook Form con las propiedades personalizadas del formulario.
|
|
106
|
+
*/
|
|
107
|
+
export interface FormProviderCustomProps<T extends RHFormValues> extends RHFormProviderProps<T> {
|
|
108
|
+
formMethods: UseFormReturn<T, undefined, T>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Argumentos para el hook useCustomForm.
|
|
112
|
+
* Define los parámetros necesarios para configurar un formulario personalizado.
|
|
113
|
+
*/
|
|
114
|
+
export interface CustomFormArguments<T extends RHFormValues> {
|
|
115
|
+
/** Valores iniciales del formulario */
|
|
116
|
+
values: RHFormInitialValues<T>;
|
|
117
|
+
/** Esquema de validación de Yup */
|
|
118
|
+
validationSchema: ValidationSchema<T>;
|
|
119
|
+
/** Estado de carga del formulario (opcional) */
|
|
120
|
+
statusLoad?: FormStatusLoad;
|
|
121
|
+
/** Modo de validación del formulario (opcional) */
|
|
122
|
+
mode?: Mode;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Interfaz que define los métodos expuestos a través de la ref del RHFormProvider.
|
|
126
|
+
* Permite acceso programático a los métodos de React Hook Form desde componentes padre.
|
|
127
|
+
*/
|
|
128
|
+
export interface RHFormProviderRef<T extends RHFormValues> {
|
|
129
|
+
/** Objeto completo con todos los métodos de React Hook Form */
|
|
130
|
+
formMethods: UseFormReturn<T, undefined, T>;
|
|
131
|
+
onSubmit: (data: T) => void;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const VALIDATION_SCHEMA_BRAND = Symbol("VALIDATION_SCHEMA_BRAND");
|
|
2
|
+
const VALIDATION_OBJECT_BRAND = Symbol("VALIDATION_OBJECT_BRAND");
|
|
3
|
+
const VALIDATION_PARTIAL_OBJECT_BRAND = Symbol("VALIDATION_PARTIAL_OBJECT_BRAND");
|
|
4
|
+
export {
|
|
5
|
+
VALIDATION_OBJECT_BRAND as V,
|
|
6
|
+
VALIDATION_SCHEMA_BRAND as a,
|
|
7
|
+
VALIDATION_PARTIAL_OBJECT_BRAND as b
|
|
8
|
+
};
|