@m4l/components 9.3.19-BE093025-beta.1 → 9.3.19-BE101025-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/@types/types.d.ts +8 -0
- package/components/Card/constants.d.ts +1 -1
- package/components/Chip/constants.d.ts +1 -1
- package/components/ContainerFlow/constants.d.ts +1 -1
- package/components/DataGrid/subcomponents/editors/EditLabelEditor/formatter.d.ts +8 -0
- package/components/DataGrid/subcomponents/editors/EditLabelEditor/index.d.ts +3 -0
- package/components/DataGrid/subcomponents/editors/EditLabelEditor/types.d.ts +5 -0
- package/components/DataGrid/subcomponents/editors/EditLabelEditor/useColumnEditLabel.d.ts +9 -0
- package/components/DataGrid/tests/helpers/types.d.ts +2 -0
- package/components/EditLabel/EditLabel.d.ts +7 -0
- package/components/EditLabel/EditLabel.styles.d.ts +2 -0
- package/components/EditLabel/constants.d.ts +2 -0
- package/components/EditLabel/hooks/useEditLabel.d.ts +23 -0
- package/components/EditLabel/icons.d.ts +5 -0
- package/components/EditLabel/index.d.ts +2 -0
- package/components/EditLabel/slots/EditLabelEnum.d.ts +8 -0
- package/components/EditLabel/slots/EditLabelSlots.d.ts +18 -0
- package/components/EditLabel/test/EditLabel.test.d.ts +1 -0
- package/components/EditLabel/types.d.ts +43 -0
- package/components/FormContainer/constants.d.ts +1 -1
- package/components/Image/constant.d.ts +1 -1
- package/components/ImageText/ImageText.styles.js +1 -1
- package/components/ImageText/constants.d.ts +1 -1
- package/components/MFIsolationApp/MFIsolationApp.js +13 -5
- package/components/MFIsolationApp/icons.d.ts +3 -0
- package/components/MFIsolationApp/icons.js +6 -0
- package/components/MFIsolationApp/subcomponents/AppBarSettings/AppBarSettings.d.ts +4 -0
- package/components/MFIsolationApp/subcomponents/AppBarSettings/AppBarSettings.js +21 -0
- package/components/MFIsolationApp/subcomponents/AppBarSettings/index.d.ts +1 -0
- package/components/MFIsolationApp/subcomponents/AppBarSettings/index.js +1 -0
- package/components/MFIsolationApp/types.d.ts +1 -0
- package/components/MFIsolationAppStorybook/MFIsolationAppStorybook.d.ts +5 -0
- package/components/MFIsolationAppStorybook/MFIsolationAppStorybook.js +154 -0
- package/components/MFIsolationAppStorybook/constants.d.ts +1 -0
- package/components/MFIsolationAppStorybook/icons.d.ts +3 -0
- package/components/MFIsolationAppStorybook/icons.js +6 -0
- package/components/MFIsolationAppStorybook/index.d.ts +1 -0
- package/components/MFIsolationAppStorybook/index.js +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/AppBarSettings/AppBarSettings.d.ts +4 -0
- package/components/MFIsolationAppStorybook/subcomponents/AppBarSettings/AppBarSettings.js +21 -0
- package/components/MFIsolationAppStorybook/subcomponents/AppBarSettings/index.d.ts +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/AppBarSettings/index.js +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/MFAuthAppStorybook.d.ts +5 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/MFAuthAppStorybook.js +44 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/index.d.ts +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/index.js +1 -0
- package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/types.d.ts +4 -0
- package/components/MFIsolationAppStorybook/types.d.ts +31 -0
- package/components/MenuActions/constants.d.ts +1 -1
- package/components/ModalDialog/ModalDialog.js +1 -0
- package/components/NoItemSelected/constant.d.ts +1 -1
- package/components/Stepper/Stepper.styles.js +17 -14
- package/components/Stepper/helpers/getInitialFieldValues/index.d.ts +12 -0
- package/components/Stepper/helpers/getInitialFieldValues/index.js +14 -0
- package/components/Stepper/helpers/index.d.ts +2 -0
- package/components/Stepper/helpers/parseWatchedValues/index.d.ts +17 -0
- package/components/Stepper/helpers/parseWatchedValues/index.js +12 -0
- package/components/Stepper/hooks/useDynamicValidation/index.d.ts +11 -0
- package/components/Stepper/hooks/useDynamicValidation/index.js +69 -0
- package/components/Stepper/hooks/useStepperActions/index.js +19 -3
- package/components/Stepper/store/StepperStore/index.js +20 -1
- package/components/Stepper/subcomponents/StepArea/index.js +45 -25
- package/components/Stepper/subcomponents/StepArea/subcomponents/Inidicator/index.js +18 -10
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.d.ts +2 -1
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.js +38 -5
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.d.ts +2 -1
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.js +5 -3
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.d.ts +2 -1
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.js +5 -3
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.d.ts +2 -1
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.js +5 -3
- package/components/Stepper/subcomponents/StepperContent/subcomponents/Step/index.js +30 -11
- package/components/Stepper/subcomponents/StepperFooter/subcomponents/StepperFooterRightActions/index.js +20 -10
- package/components/Stepper/types.d.ts +7 -0
- package/components/WindowBase/constants.d.ts +1 -1
- package/components/extended/React-Json-Viewer/constants.d.ts +1 -1
- package/components/extended/React-resizable-panels/SplitLayout.js +1 -1
- package/components/formatters/ChipStatusFormatter/constants.d.ts +1 -1
- package/components/formatters/EditLabelFormatter/EditLabelFormatter.d.ts +5 -0
- package/components/formatters/EditLabelFormatter/EditLabelFormatter.styles.d.ts +2 -0
- package/components/formatters/EditLabelFormatter/constants.d.ts +5 -0
- package/components/formatters/EditLabelFormatter/index.d.ts +2 -0
- package/components/formatters/EditLabelFormatter/slots/EditLabelFormatterEnum.d.ts +4 -0
- package/components/formatters/EditLabelFormatter/slots/EditLabelFormatterSlots.d.ts +5 -0
- package/components/formatters/EditLabelFormatter/test/EditLabelFormatter.test.d.ts +1 -0
- package/components/formatters/EditLabelFormatter/types.d.ts +23 -0
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.js +8 -2
- package/components/hook-form/RHFAutocomplete/types.d.ts +13 -0
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.js +8 -2
- package/components/hook-form/RHFCheckbox/constants.d.ts +1 -1
- package/components/hook-form/RHFSelect/constants.d.ts +1 -1
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/constants.d.ts +25 -1
- package/components/hook-form/RHFUpload/RHFUploadSingleFile/constants.js +5 -1
- package/components/hook-form/RHFormContext/index.d.ts +110 -10
- package/components/hook-form/RHFormContext/index.js +35 -8
- package/components/hook-form/RHFormContext/types.d.ts +64 -1
- package/components/index.d.ts +1 -0
- package/components/mui_extended/Autocomplete/Autocomplete.js +6 -2
- package/components/mui_extended/Autocomplete/hooks/useStartAdornments.d.ts +3 -1
- package/components/mui_extended/Autocomplete/hooks/useStartAdornments.js +9 -3
- package/components/mui_extended/Autocomplete/types.d.ts +8 -0
- package/components/mui_extended/Button/Button.js +15 -4
- package/components/mui_extended/Button/ButtonStyles.js +155 -82
- package/components/mui_extended/Button/{constans.d.ts → constants.d.ts} +1 -0
- package/components/mui_extended/Button/constants.js +8 -0
- package/components/mui_extended/Button/slots/ButtonSlots.js +1 -1
- package/components/mui_extended/Button/types.d.ts +1 -1
- package/components/mui_extended/IconButton/constants.d.ts +1 -1
- package/components/mui_extended/IconButton/constants.js +4 -1
- package/components/mui_extended/MenuItem/MenuItem.js +1 -1
- package/components/mui_extended/MenuItem/constants.d.ts +1 -1
- package/components/mui_extended/NavLink/constants.d.ts +1 -1
- package/components/mui_extended/Select/Select.js +2 -2
- package/components/mui_extended/Select/constants.d.ts +1 -1
- package/components/mui_extended/TextField/constants.d.ts +1 -1
- package/components/mui_extended/Tooltip/Tooltip.styles.js +8 -1
- package/components/mui_extended/Tooltip/constants.d.ts +1 -1
- package/components/mui_extended/Typography/constants.d.ts +1 -1
- package/components/mui_extended/Typography/types.d.ts +1 -1
- package/contexts/AppearanceComponentContext/AppearanceComponentContext.js +6 -1
- package/index.js +12 -10
- package/package.json +1 -1
- package/utils/getComponentSlotRoot.d.ts +3 -1
- package/components/mui_extended/Button/constans.js +0 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useThemeSettingsStore } from "@m4l/graphics";
|
|
3
|
+
import { P as PATH_ICONS } from "../../icons.js";
|
|
4
|
+
import { useEnvironment } from "@m4l/core";
|
|
5
|
+
import { S as Stack } from "../../../mui_extended/Stack/Stack.js";
|
|
6
|
+
import { I as IconButton } from "../../../mui_extended/IconButton/IconButton.js";
|
|
7
|
+
import { L as LanguagePopover } from "../../../LanguagePopover/LanguagePopover.js";
|
|
8
|
+
function AppBarSettings() {
|
|
9
|
+
const handleOpen = useThemeSettingsStore((state) => state.settingsActions.handleOpen);
|
|
10
|
+
const { host_static_assets, environment_assets } = useEnvironment();
|
|
11
|
+
return /* @__PURE__ */ jsxs(Stack, { width: "100%", height: "40px", justifyContent: "space-between", flexDirection: "row", overflow: "hidden", position: "relative", padding: [0, 2], children: [
|
|
12
|
+
/* @__PURE__ */ jsx(Stack, { width: "100%", height: "100%" }),
|
|
13
|
+
/* @__PURE__ */ jsxs(Stack, { flexDirection: "row", gap: 2, height: "100%", width: "auto", alignItems: "center", children: [
|
|
14
|
+
/* @__PURE__ */ jsx(LanguagePopover, {}),
|
|
15
|
+
/* @__PURE__ */ jsx(IconButton, { src: `${host_static_assets}/${environment_assets}/${PATH_ICONS.SETTINGS}`, onClick: handleOpen })
|
|
16
|
+
] })
|
|
17
|
+
] });
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
AppBarSettings as A
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AppBarSettings } from './AppBarSettings';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/components/MFIsolationAppStorybook/subcomponents/MFAuthAppStorybook/MFAuthAppStorybook.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { format } from "date-fns";
|
|
3
|
+
import { DomainCountryProvider } from "@m4l/core";
|
|
4
|
+
import { HostThemeProvider, FormatterProvider } from "@m4l/graphics";
|
|
5
|
+
import { fnComponentsOverrides, getUserThemeOptions } from "@m4l/styles";
|
|
6
|
+
function MFAuthAppStorybook(props) {
|
|
7
|
+
const { children } = props;
|
|
8
|
+
const domianCountry = {
|
|
9
|
+
currency: "USD",
|
|
10
|
+
currency_decimal_digits: 2
|
|
11
|
+
};
|
|
12
|
+
const domainCountry = {
|
|
13
|
+
id: 1,
|
|
14
|
+
currency: "USD",
|
|
15
|
+
currency_decimal_digits: 2,
|
|
16
|
+
decimal_symbol: ".",
|
|
17
|
+
thousands_symbol: ","
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
HostThemeProvider,
|
|
21
|
+
{
|
|
22
|
+
hostThemeOptions: getUserThemeOptions("light", "patronus"),
|
|
23
|
+
fnComponentsOverrides,
|
|
24
|
+
isMicroFrontEnd: true,
|
|
25
|
+
children: /* @__PURE__ */ jsx(DomainCountryProvider, { ...domainCountry, isMicroFrontEnd: false, children: /* @__PURE__ */ jsx(
|
|
26
|
+
FormatterProvider,
|
|
27
|
+
{
|
|
28
|
+
isMicroFrontEnd: false,
|
|
29
|
+
dateFormatter: {
|
|
30
|
+
formatDate: format
|
|
31
|
+
},
|
|
32
|
+
currencyFormatter: {
|
|
33
|
+
code: domianCountry.currency,
|
|
34
|
+
decimalDigits: domianCountry.currency_decimal_digits
|
|
35
|
+
},
|
|
36
|
+
children
|
|
37
|
+
}
|
|
38
|
+
) })
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
MFAuthAppStorybook as M
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MFAuthAppStorybook } from './MFAuthAppStorybook';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ModuleDictionary } from '@m4l/core';
|
|
2
|
+
import { BaseModuleProps } from '../BaseModule';
|
|
3
|
+
import { DeviceType } from '@m4l/graphics';
|
|
4
|
+
export type MFIsolationAppStorybookProps = BaseModuleProps & {
|
|
5
|
+
host_api_local: string;
|
|
6
|
+
host_api_icons?: string;
|
|
7
|
+
database?: string;
|
|
8
|
+
host_api_remote: string;
|
|
9
|
+
host_static_assets: string;
|
|
10
|
+
environment_assets: string;
|
|
11
|
+
onLoad: () => void;
|
|
12
|
+
activeAreasNetwork?: boolean;
|
|
13
|
+
activeCookiesFromNetwork?: boolean;
|
|
14
|
+
appBarSettings?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Diccionario de componentes, se puede proporcionar ya el diccionario cargado, para evitar que se llame al endpoint nuevamente.
|
|
17
|
+
*/
|
|
18
|
+
moduleDictionaryLoaded?: ModuleDictionary;
|
|
19
|
+
/**
|
|
20
|
+
* Tipo de dispositivo forzado, si no se proporciona se determina automáticamente. Normalmente se usa esta propieadad para pruebas en storybook.
|
|
21
|
+
*/
|
|
22
|
+
forcedDeviceType?: DeviceType;
|
|
23
|
+
/**
|
|
24
|
+
* Id del store de las áreas
|
|
25
|
+
*/
|
|
26
|
+
areasStoreId?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Determina si se debe usar devtools para el store de las áreas
|
|
29
|
+
*/
|
|
30
|
+
areasStoreDevtoolsEnabled?: boolean;
|
|
31
|
+
};
|
|
@@ -20,4 +20,4 @@ export declare const MENU_ACTIONS_EMPTY = "menu_action_empty";
|
|
|
20
20
|
* Prefijo de la clave que se utiliza cuando un ítem del menú está cargando en React.
|
|
21
21
|
*/
|
|
22
22
|
export declare const MENU_ACTIONS_ = "menu_action_";
|
|
23
|
-
export declare const MENU_ACTIONS_CLASSES: Record<
|
|
23
|
+
export declare const MENU_ACTIONS_CLASSES: Record<"selected" | "root" | "menuList" | "menuLoader" | "iconButton" | "headerMenuActions" | "footerMenuActions", string>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const NO_ITEM_SELECTED_KEY_COMPONENT = "M4LNoItemSelected";
|
|
2
|
-
export declare const NO_ITEM_SELECTED_CLASSES: Record<
|
|
2
|
+
export declare const NO_ITEM_SELECTED_CLASSES: Record<"root", string>;
|
|
@@ -24,8 +24,13 @@ const stepperStyles = {
|
|
|
24
24
|
flexDirection: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "column" : "row",
|
|
25
25
|
gap: theme.vars.size.baseSpacings.sp8
|
|
26
26
|
}),
|
|
27
|
+
/**
|
|
28
|
+
* Estilos para el contenido del paso dentro del Stepper.
|
|
29
|
+
*/
|
|
27
30
|
stepContent: ({ ownerState }) => ({
|
|
28
|
-
|
|
31
|
+
height: "100%",
|
|
32
|
+
display: ownerState?.isStepVisible ? "flex" : "none",
|
|
33
|
+
flexDirection: "column"
|
|
29
34
|
}),
|
|
30
35
|
/**
|
|
31
36
|
* Estilos para la sección que contiene los botones de acción del Stepper.
|
|
@@ -71,8 +76,7 @@ const stepperStyles = {
|
|
|
71
76
|
const isLastStep = step === totalSteps - 1;
|
|
72
77
|
return {
|
|
73
78
|
cursor: "pointer",
|
|
74
|
-
display: "flex",
|
|
75
|
-
visibility: ownerState?.isStepVisible ? "visible" : "hidden",
|
|
79
|
+
display: ownerState?.isStepVisible ? "flex" : "none",
|
|
76
80
|
flexDirection: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "column" : "row",
|
|
77
81
|
alignItems: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "center" : "start",
|
|
78
82
|
justifyContent: ownerState?.visibleTitle ? "space-between" : "center",
|
|
@@ -126,7 +130,7 @@ const stepperStyles = {
|
|
|
126
130
|
whiteSpace: "normal",
|
|
127
131
|
order: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? 1 : 0,
|
|
128
132
|
"&.M4LTypography-root": {
|
|
129
|
-
color:
|
|
133
|
+
color: ownerState?.originalStepIndex !== void 0 && typeof ownerState.originalStepIndex === "number" ? (ownerState.currentStep ?? 0) > ownerState.originalStepIndex ? theme.vars.palette.primary.semanticText : (ownerState.currentStep ?? 0) === ownerState.originalStepIndex ? theme.vars.palette.text.primary : theme.vars.palette.text.secondary : theme.vars.palette.text.secondary,
|
|
130
134
|
textAlign: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "center" : "right"
|
|
131
135
|
}
|
|
132
136
|
}),
|
|
@@ -134,13 +138,12 @@ const stepperStyles = {
|
|
|
134
138
|
* Estilos para el indicador numérico de cada paso del Stepper.
|
|
135
139
|
*/
|
|
136
140
|
indicator: ({ theme, ownerState }) => {
|
|
137
|
-
const currentStep = ownerState?.currentStep ?? 0;
|
|
138
141
|
const step = ownerState?.step ?? 0;
|
|
139
142
|
const totalSteps = ownerState?.totalSteps ?? 0;
|
|
140
|
-
const isCompleted =
|
|
141
|
-
const isCurrent =
|
|
143
|
+
const isCompleted = ownerState?.isCompleted ?? false;
|
|
144
|
+
const isCurrent = ownerState?.isCurrent ?? false;
|
|
145
|
+
const isValidStep = ownerState?.isValidStep ?? true;
|
|
142
146
|
const isLastStep = step === totalSteps - 1;
|
|
143
|
-
const isValidStep = ownerState?.stepValidationStatus?.[step] ?? true;
|
|
144
147
|
return {
|
|
145
148
|
...ownerState?.orientation === "horizontal" ? {
|
|
146
149
|
marginTop: theme.generalSettings.isMobile ? "6px" : theme.vars.size.baseSpacings.sp1
|
|
@@ -150,7 +153,7 @@ const stepperStyles = {
|
|
|
150
153
|
justifyContent: "center",
|
|
151
154
|
flexShrink: 0,
|
|
152
155
|
order: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? 0 : 1,
|
|
153
|
-
background: isCompleted ? ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.primary.toneOpacity :
|
|
156
|
+
background: !isValidStep && ownerState?.hasBeenValidated ? theme.vars.palette.error.enabled : isCompleted && isValidStep ? ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.primary.toneOpacity : isCurrent ? ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.primary.enabled : ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.default.enabled,
|
|
154
157
|
borderRadius: theme.vars.size.borderRadius.r2,
|
|
155
158
|
...ownerState?.indicatorType === "number" && !theme.generalSettings.isMobile && {
|
|
156
159
|
boxShadow: isCurrent ? "0 2px 8px 0 rgb(0, 100, 255, 0.16)" : "none"
|
|
@@ -178,13 +181,13 @@ const stepperStyles = {
|
|
|
178
181
|
* Estilos para el número de texto dentro del indicador numérico del Stepper.
|
|
179
182
|
*/
|
|
180
183
|
textNumber: ({ theme, ownerState }) => {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const
|
|
184
|
+
const isCompleted = ownerState?.isCompleted ?? false;
|
|
185
|
+
const isCurrent = ownerState?.isCurrent ?? false;
|
|
186
|
+
const isValidStep = ownerState?.isValidStep ?? true;
|
|
187
|
+
const hasBeenValidated = ownerState?.hasBeenValidated ?? false;
|
|
185
188
|
return {
|
|
186
189
|
"&.M4LTypography-root": {
|
|
187
|
-
color: isCompleted || isCurrent ? theme.vars.palette.primary.contrastText : theme.vars.palette.text.primary
|
|
190
|
+
color: !isValidStep && hasBeenValidated ? theme.vars.palette.error.contrastText : isCompleted || isCurrent ? theme.vars.palette.primary.contrastText : theme.vars.palette.text.primary
|
|
188
191
|
}
|
|
189
192
|
};
|
|
190
193
|
},
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Obtiene los valores iniciales de campos específicos del formulario.
|
|
3
|
+
* Se usa para inicializar el ref que trackea cambios en los campos.
|
|
4
|
+
* @param allValues - Todos los valores del formulario (de getValues())
|
|
5
|
+
* @param fields - Lista de nombres de campos de los que queremos obtener valores
|
|
6
|
+
* @returns Objeto con solo los valores de los campos especificados
|
|
7
|
+
* @example
|
|
8
|
+
* const formValues = { name: 'John', age: 25, city: 'NY', country: 'USA' };
|
|
9
|
+
* getInitialFieldValues(formValues, ['name', 'age'])
|
|
10
|
+
* // Retorna: { name: 'John', age: 25 }
|
|
11
|
+
*/
|
|
12
|
+
export declare function getInitialFieldValues(allValues: Record<string, any>, fields?: string[]): Record<string, any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function getInitialFieldValues(allValues, fields = []) {
|
|
2
|
+
if (fields.length === 0) {
|
|
3
|
+
return {};
|
|
4
|
+
}
|
|
5
|
+
return fields.reduce((acc, field) => {
|
|
6
|
+
if (field in allValues) {
|
|
7
|
+
acc[field] = allValues[field];
|
|
8
|
+
}
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
getInitialFieldValues as g
|
|
14
|
+
};
|
|
@@ -2,3 +2,5 @@ export { evaluateVisibilityStepCondition } from './evaluateVisibilityStepConditi
|
|
|
2
2
|
export { findNextVisibleValidStep } from './findNextVisibleValidStep';
|
|
3
3
|
export { findPrevVisibleValidStep } from './findPrevVisibleValidStep';
|
|
4
4
|
export { isLastVisibleValidStep } from './isLastVisibleValidStep';
|
|
5
|
+
export { parseWatchedValues } from './parseWatchedValues';
|
|
6
|
+
export { getInitialFieldValues } from './getInitialFieldValues';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convierte los valores observados de useWatch en un objeto estructurado con los nombres de campos como keys.
|
|
3
|
+
*
|
|
4
|
+
* useWatch de react-hook-form retorna diferentes estructuras según la cantidad de campos observados:
|
|
5
|
+
* - Un solo campo: retorna el valor directamente
|
|
6
|
+
* - Múltiples campos: retorna un array con los valores en el mismo orden de los campos
|
|
7
|
+
* @param watchValues - Valores observados de useWatch (puede ser un valor único o un array)
|
|
8
|
+
* @param fields - Lista de nombres de campos que se están observando
|
|
9
|
+
* @returns Objeto con los valores actuales mapeados a sus respectivos nombres de campo
|
|
10
|
+
* @example
|
|
11
|
+
* // Para un solo campo
|
|
12
|
+
* parseWatchedValues('John', ['name']) // { name: 'John' }
|
|
13
|
+
*
|
|
14
|
+
* // Para múltiples campos
|
|
15
|
+
* parseWatchedValues(['John', 25], ['name', 'age']) // { name: 'John', age: 25 }
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseWatchedValues(watchValues: any, fields: string[]): Record<string, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function parseWatchedValues(watchValues, fields) {
|
|
2
|
+
if (fields.length === 1) {
|
|
3
|
+
return { [fields[0]]: watchValues };
|
|
4
|
+
}
|
|
5
|
+
return fields.reduce((acc, field, index) => {
|
|
6
|
+
acc[field] = Array.isArray(watchValues) ? watchValues[index] : watchValues;
|
|
7
|
+
return acc;
|
|
8
|
+
}, {});
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
parseWatchedValues as p
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook que simula validación onChange de campos específicos del Stepper, manteniendo el formulario en modo onSubmit para preservar el rendimiento.
|
|
3
|
+
* @returns Objeto con funciones para manejar la validación dinámica
|
|
4
|
+
*/
|
|
5
|
+
export declare function useDynamicValidation(): {
|
|
6
|
+
activateFieldsValidation: (fields: string[], skipIfValidating?: boolean) => void;
|
|
7
|
+
clearAllValidation: () => void;
|
|
8
|
+
activeFields: string[];
|
|
9
|
+
startExternalValidation: () => void;
|
|
10
|
+
endExternalValidation: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useState, useRef, useEffect, useCallback } from "react";
|
|
2
|
+
import { useFormContext, useWatch } from "react-hook-form";
|
|
3
|
+
import { p as parseWatchedValues } from "../../helpers/parseWatchedValues/index.js";
|
|
4
|
+
import { g as getInitialFieldValues } from "../../helpers/getInitialFieldValues/index.js";
|
|
5
|
+
function useDynamicValidation() {
|
|
6
|
+
const { trigger, getValues } = useFormContext();
|
|
7
|
+
const [activeFields, setActiveFields] = useState([]);
|
|
8
|
+
const [isValidating, setIsValidating] = useState(false);
|
|
9
|
+
const statusLoad = useWatch({
|
|
10
|
+
name: "statusLoad"
|
|
11
|
+
});
|
|
12
|
+
const watchValues = useWatch({
|
|
13
|
+
name: activeFields.length > 0 ? activeFields : ["__dummy__"]
|
|
14
|
+
});
|
|
15
|
+
const lastValuesRef = useRef({});
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (activeFields.length === 0 || statusLoad !== "ready" || isValidating) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const currentValues = parseWatchedValues(watchValues, activeFields);
|
|
21
|
+
const changedFields = activeFields.filter((field) => {
|
|
22
|
+
const currentValue = currentValues[field];
|
|
23
|
+
const lastValue = lastValuesRef.current[field];
|
|
24
|
+
const hasChanged = JSON.stringify(currentValue) !== JSON.stringify(lastValue);
|
|
25
|
+
if (hasChanged) {
|
|
26
|
+
lastValuesRef.current[field] = currentValue;
|
|
27
|
+
}
|
|
28
|
+
return hasChanged;
|
|
29
|
+
});
|
|
30
|
+
if (changedFields.length > 0) {
|
|
31
|
+
const timeoutId = setTimeout(() => {
|
|
32
|
+
trigger(changedFields);
|
|
33
|
+
}, 100);
|
|
34
|
+
return () => clearTimeout(timeoutId);
|
|
35
|
+
}
|
|
36
|
+
}, [activeFields, trigger, watchValues, statusLoad, isValidating]);
|
|
37
|
+
const startExternalValidation = useCallback(() => {
|
|
38
|
+
setIsValidating(true);
|
|
39
|
+
}, []);
|
|
40
|
+
const endExternalValidation = useCallback(() => {
|
|
41
|
+
setIsValidating(false);
|
|
42
|
+
}, []);
|
|
43
|
+
const activateFieldsValidation = useCallback(
|
|
44
|
+
(fields, skipIfValidating = true) => {
|
|
45
|
+
if (skipIfValidating && isValidating) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const formValues = getValues();
|
|
49
|
+
setActiveFields(fields);
|
|
50
|
+
const initialValues = getInitialFieldValues(formValues, fields);
|
|
51
|
+
lastValuesRef.current = initialValues;
|
|
52
|
+
},
|
|
53
|
+
[getValues, isValidating]
|
|
54
|
+
);
|
|
55
|
+
const clearAllValidation = useCallback(() => {
|
|
56
|
+
setActiveFields([]);
|
|
57
|
+
lastValuesRef.current = {};
|
|
58
|
+
}, []);
|
|
59
|
+
return {
|
|
60
|
+
activateFieldsValidation,
|
|
61
|
+
clearAllValidation,
|
|
62
|
+
activeFields,
|
|
63
|
+
startExternalValidation,
|
|
64
|
+
endExternalValidation
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
useDynamicValidation as u
|
|
69
|
+
};
|
|
@@ -2,8 +2,10 @@ import { useCallback } from "react";
|
|
|
2
2
|
import { u as useStepper } from "../useStepper/index.js";
|
|
3
3
|
import { useFormContext } from "react-hook-form";
|
|
4
4
|
import { shallow } from "zustand/shallow";
|
|
5
|
+
import { u as useDynamicValidation } from "../useDynamicValidation/index.js";
|
|
5
6
|
function useStepperActions() {
|
|
6
7
|
const { trigger, clearErrors, getValues, reset } = useFormContext();
|
|
8
|
+
const { activateFieldsValidation, clearAllValidation } = useDynamicValidation();
|
|
7
9
|
const {
|
|
8
10
|
nextStep,
|
|
9
11
|
prevStep,
|
|
@@ -41,9 +43,20 @@ function useStepperActions() {
|
|
|
41
43
|
if (fieldsToValidate.length === 0) {
|
|
42
44
|
return true;
|
|
43
45
|
}
|
|
44
|
-
|
|
46
|
+
const result = await trigger(fieldsToValidate);
|
|
47
|
+
if (!result) {
|
|
48
|
+
activateFieldsValidation(fieldsToValidate);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
45
51
|
};
|
|
46
52
|
const success = await nextStep(validateFn, formData);
|
|
53
|
+
if (success) {
|
|
54
|
+
const currentStepData = steps[currentStep - 1];
|
|
55
|
+
const fieldsJustValidated = currentStepData?.validationFields || [];
|
|
56
|
+
if (fieldsJustValidated.length > 0) {
|
|
57
|
+
clearAllValidation();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
47
60
|
if (success && futureFields.length > 0) {
|
|
48
61
|
clearErrors(futureFields);
|
|
49
62
|
setTimeout(() => {
|
|
@@ -62,13 +75,16 @@ function useStepperActions() {
|
|
|
62
75
|
steps,
|
|
63
76
|
currentStep,
|
|
64
77
|
trigger,
|
|
65
|
-
getValues
|
|
78
|
+
getValues,
|
|
79
|
+
activateFieldsValidation,
|
|
80
|
+
clearAllValidation
|
|
66
81
|
]);
|
|
67
82
|
const cancelAction = useCallback(() => {
|
|
68
83
|
reset();
|
|
69
84
|
clearErrors();
|
|
85
|
+
clearAllValidation();
|
|
70
86
|
resetStepper();
|
|
71
|
-
}, [reset, clearErrors, resetStepper]);
|
|
87
|
+
}, [reset, clearErrors, clearAllValidation, resetStepper]);
|
|
72
88
|
return { prevStepAction, nextStepAction, cancelAction };
|
|
73
89
|
}
|
|
74
90
|
export {
|
|
@@ -35,6 +35,18 @@ const createStepperStore = (initProps, storeDevtoolsEnabled = false) => {
|
|
|
35
35
|
if (!preserveStepValidationStatus) {
|
|
36
36
|
state.stepValidationStatus = {};
|
|
37
37
|
}
|
|
38
|
+
if (!preserveStepValidationStatus) {
|
|
39
|
+
const firstVisibleStepIndex = findNextVisibleValidStep(
|
|
40
|
+
-1,
|
|
41
|
+
// Comenzar desde -1 para encontrar el primer step visible
|
|
42
|
+
steps,
|
|
43
|
+
{},
|
|
44
|
+
state.visibilityData
|
|
45
|
+
);
|
|
46
|
+
if (firstVisibleStepIndex !== 0 && firstVisibleStepIndex < steps.length) {
|
|
47
|
+
state.currentStep = firstVisibleStepIndex;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
38
50
|
});
|
|
39
51
|
},
|
|
40
52
|
/**
|
|
@@ -114,9 +126,16 @@ const createStepperStore = (initProps, storeDevtoolsEnabled = false) => {
|
|
|
114
126
|
*/
|
|
115
127
|
resetStepper: () => {
|
|
116
128
|
set((state) => {
|
|
117
|
-
state.currentStep = 0;
|
|
118
129
|
state.stepValidationStatus = {};
|
|
119
130
|
state.isValidating = false;
|
|
131
|
+
const firstVisibleStepIndex = findNextVisibleValidStep(
|
|
132
|
+
-1,
|
|
133
|
+
// Comenzar desde -1 para encontrar el primer step visible
|
|
134
|
+
state.steps,
|
|
135
|
+
{},
|
|
136
|
+
state.visibilityData
|
|
137
|
+
);
|
|
138
|
+
state.currentStep = firstVisibleStepIndex < state.steps.length ? firstVisibleStepIndex : 0;
|
|
120
139
|
});
|
|
121
140
|
}
|
|
122
141
|
}
|
|
@@ -5,10 +5,16 @@ import { u as useStepper } from "../../hooks/useStepper/index.js";
|
|
|
5
5
|
import { e as StepAreaStyled, f as StepStyled, g as StepNameStyled } from "../../slots/StepperSlot.js";
|
|
6
6
|
import { I as Indicator } from "./subcomponents/Inidicator/index.js";
|
|
7
7
|
import { shallow } from "zustand/shallow";
|
|
8
|
+
import { u as useDynamicValidation } from "../../hooks/useDynamicValidation/index.js";
|
|
8
9
|
import { e as evaluateVisibilityStepCondition } from "../../helpers/evaluateVisibilityStepCondition/index.js";
|
|
9
10
|
function StepArea() {
|
|
10
11
|
const { trigger, clearErrors } = useFormContext();
|
|
11
12
|
const formValues = useWatch();
|
|
13
|
+
const {
|
|
14
|
+
activateFieldsValidation,
|
|
15
|
+
startExternalValidation,
|
|
16
|
+
endExternalValidation
|
|
17
|
+
} = useDynamicValidation();
|
|
12
18
|
const {
|
|
13
19
|
currentStep,
|
|
14
20
|
steps,
|
|
@@ -32,16 +38,19 @@ function StepArea() {
|
|
|
32
38
|
}),
|
|
33
39
|
shallow
|
|
34
40
|
);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const allSteps = steps;
|
|
42
|
+
const visibleSteps = useMemo(() => {
|
|
43
|
+
return steps.filter(
|
|
44
|
+
(step) => evaluateVisibilityStepCondition(step, formValues || {}, visibilityData)
|
|
45
|
+
);
|
|
46
|
+
}, [steps, formValues, visibilityData]);
|
|
38
47
|
const ownerState = {
|
|
39
48
|
visibleTitle,
|
|
40
49
|
orientation,
|
|
41
|
-
totalSteps:
|
|
50
|
+
totalSteps: visibleSteps.length
|
|
42
51
|
};
|
|
43
52
|
const handleStepClick = async (targetIndex) => {
|
|
44
|
-
const currentIndex =
|
|
53
|
+
const currentIndex = visibleSteps.findIndex(
|
|
45
54
|
(step) => step.key === steps[currentStep].key
|
|
46
55
|
);
|
|
47
56
|
if (targetIndex === currentIndex) {
|
|
@@ -49,7 +58,7 @@ function StepArea() {
|
|
|
49
58
|
}
|
|
50
59
|
const isNavigatingForward = targetIndex > currentIndex;
|
|
51
60
|
const targetOriginalIndex = steps.findIndex(
|
|
52
|
-
(s) => s.key ===
|
|
61
|
+
(s) => s.key === visibleSteps[targetIndex].key
|
|
53
62
|
);
|
|
54
63
|
if (!isNavigatingForward) {
|
|
55
64
|
setCurrentStep(targetOriginalIndex);
|
|
@@ -58,37 +67,43 @@ function StepArea() {
|
|
|
58
67
|
const isSkippingSteps = targetIndex > currentIndex + 1;
|
|
59
68
|
if (isSkippingSteps) {
|
|
60
69
|
for (let i = currentIndex; i < targetIndex; i++) {
|
|
61
|
-
const step =
|
|
70
|
+
const step = visibleSteps[i];
|
|
62
71
|
const stepOriginalIndex = steps.findIndex((s) => s.key === step.key);
|
|
72
|
+
startExternalValidation();
|
|
63
73
|
const isValid = await trigger(step.validationFields);
|
|
74
|
+
endExternalValidation();
|
|
64
75
|
if (!isValid) {
|
|
65
76
|
setCurrentStep(stepOriginalIndex);
|
|
66
77
|
setStepValidationStatus(stepOriginalIndex, false);
|
|
78
|
+
activateFieldsValidation(step.validationFields || []);
|
|
67
79
|
return;
|
|
68
80
|
}
|
|
69
81
|
setStepValidationStatus(stepOriginalIndex, true);
|
|
70
82
|
}
|
|
71
83
|
} else {
|
|
72
|
-
const currentStepData =
|
|
84
|
+
const currentStepData = visibleSteps[currentIndex];
|
|
73
85
|
const currentStepOriginalIndex = steps.findIndex(
|
|
74
86
|
(s) => s.key === currentStepData.key
|
|
75
87
|
);
|
|
88
|
+
startExternalValidation();
|
|
76
89
|
const isCurrentValid = await trigger(currentStepData.validationFields);
|
|
90
|
+
endExternalValidation();
|
|
77
91
|
if (!isCurrentValid) {
|
|
78
92
|
setStepValidationStatus(currentStepOriginalIndex, false);
|
|
93
|
+
activateFieldsValidation(currentStepData.validationFields || []);
|
|
79
94
|
return;
|
|
80
95
|
}
|
|
81
96
|
setStepValidationStatus(currentStepOriginalIndex, true);
|
|
82
97
|
}
|
|
83
98
|
setCurrentStep(targetOriginalIndex);
|
|
84
99
|
if (isNavigatingForward) {
|
|
85
|
-
const currentStepData =
|
|
100
|
+
const currentStepData = visibleSteps[currentIndex];
|
|
86
101
|
const currentStepOriginalIndex = steps.findIndex(
|
|
87
102
|
(s) => s.key === currentStepData.key
|
|
88
103
|
);
|
|
89
104
|
const isCurrentStepValid = stepValidationStatus[currentStepOriginalIndex] !== false;
|
|
90
105
|
if (isCurrentStepValid) {
|
|
91
|
-
const targetStep =
|
|
106
|
+
const targetStep = visibleSteps[targetIndex];
|
|
92
107
|
const targetStepFields = targetStep.validationFields || [];
|
|
93
108
|
if (targetStepFields.length > 0) {
|
|
94
109
|
clearErrors(targetStepFields);
|
|
@@ -100,25 +115,24 @@ function StepArea() {
|
|
|
100
115
|
}
|
|
101
116
|
}
|
|
102
117
|
};
|
|
103
|
-
return /* @__PURE__ */ jsx(StepAreaStyled, { ownerState,
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
return /* @__PURE__ */ jsx(StepAreaStyled, { ownerState, children: allSteps.map((step, originalIndex) => {
|
|
119
|
+
const isStepVisible = evaluateVisibilityStepCondition(
|
|
120
|
+
step,
|
|
121
|
+
formValues || {},
|
|
122
|
+
visibilityData
|
|
123
|
+
);
|
|
124
|
+
const visibleStepIndex = isStepVisible ? visibleSteps.findIndex((visStep) => visStep.key === step.key) : -1;
|
|
108
125
|
return /* @__PURE__ */ jsxs(
|
|
109
126
|
StepStyled,
|
|
110
127
|
{
|
|
111
128
|
role: "button",
|
|
112
|
-
onClick: () => handleStepClick(
|
|
129
|
+
onClick: () => isStepVisible ? handleStepClick(visibleStepIndex) : void 0,
|
|
113
130
|
ownerState: {
|
|
114
131
|
...ownerState,
|
|
115
132
|
currentStep,
|
|
116
|
-
step:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
formValues || {},
|
|
120
|
-
visibilityData
|
|
121
|
-
)
|
|
133
|
+
step: visibleStepIndex,
|
|
134
|
+
// Usa el índice en la secuencia visible
|
|
135
|
+
isStepVisible
|
|
122
136
|
},
|
|
123
137
|
"data-testid": `stepper-step-${step.key}`,
|
|
124
138
|
children: [
|
|
@@ -126,7 +140,13 @@ function StepArea() {
|
|
|
126
140
|
StepNameStyled,
|
|
127
141
|
{
|
|
128
142
|
variant: "body",
|
|
129
|
-
ownerState: {
|
|
143
|
+
ownerState: {
|
|
144
|
+
...ownerState,
|
|
145
|
+
currentStep,
|
|
146
|
+
step: visibleStepIndex,
|
|
147
|
+
originalStepIndex: originalIndex,
|
|
148
|
+
isStepVisible
|
|
149
|
+
},
|
|
130
150
|
children: step.title
|
|
131
151
|
}
|
|
132
152
|
),
|
|
@@ -134,8 +154,8 @@ function StepArea() {
|
|
|
134
154
|
Indicator,
|
|
135
155
|
{
|
|
136
156
|
currentStep,
|
|
137
|
-
step:
|
|
138
|
-
totalSteps:
|
|
157
|
+
step: visibleStepIndex,
|
|
158
|
+
totalSteps: visibleSteps.length,
|
|
139
159
|
originalStepIndex: originalIndex
|
|
140
160
|
}
|
|
141
161
|
)
|