@trackunit/react-form-wizard 2.6.24-alpha-3e7014314a8.0 → 2.6.29
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/index.cjs.js +7 -4
- package/index.esm.js +7 -4
- package/migrations/entry.js.map +1 -0
- package/package.json +5 -5
- package/src/FormWizard/useFormWizard.d.ts +2 -0
package/index.cjs.js
CHANGED
|
@@ -212,6 +212,7 @@ const cvaFormWizardComponentStepForm = cssClassVarianceUtilities.cvaMerge(["grid
|
|
|
212
212
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, initialFullFormState, }) => {
|
|
213
213
|
const navigate = reactRouter.useNavigate();
|
|
214
214
|
const [isSubmitting, setIsSubmitting] = react.useState(false);
|
|
215
|
+
const [primaryActionDisabledByStep, setPrimaryActionDisabledByStep] = react.useState(false);
|
|
215
216
|
const [submitHandlerInternal, setSubmitHandlerInternal] = react.useState(null);
|
|
216
217
|
const [beforeSubmitInternal, setBeforeSubmitInternal] = react.useState(null);
|
|
217
218
|
const form = reactHookForm.useForm({
|
|
@@ -297,9 +298,10 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
297
298
|
return isEmptyStep && form.formState.isValid ? emptyStepSubmitHandler : stepSubmitHandler;
|
|
298
299
|
}, [emptyStepSubmitHandler, form.formState.isValid, isEmptyStep, stepSubmitHandler]);
|
|
299
300
|
react.useEffect(() => {
|
|
300
|
-
// submit on cmd/ctrl + enter,
|
|
301
|
+
// submit on cmd/ctrl + enter, unless a submit is already running or the step disabled the
|
|
302
|
+
// primary action — the shortcut must not bypass the footer button's disabled state
|
|
301
303
|
const handleKeyDown = (event) => {
|
|
302
|
-
if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
|
|
304
|
+
if (event.key === "Enter" && (event.ctrlKey || event.metaKey) && !isSubmitting && !primaryActionDisabledByStep) {
|
|
303
305
|
event.preventDefault();
|
|
304
306
|
void stepSubmitHandler();
|
|
305
307
|
}
|
|
@@ -308,7 +310,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
308
310
|
return () => {
|
|
309
311
|
document.removeEventListener("keydown", handleKeyDown);
|
|
310
312
|
};
|
|
311
|
-
}, [stepSubmitHandler]);
|
|
313
|
+
}, [stepSubmitHandler, isSubmitting, primaryActionDisabledByStep]);
|
|
312
314
|
return (jsxRuntime.jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: async (e) => {
|
|
313
315
|
e.preventDefault();
|
|
314
316
|
try {
|
|
@@ -324,6 +326,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
324
326
|
setSubmitHandler: isLastStep ? setSubmitHandler : null,
|
|
325
327
|
beforeStepSubmit: beforeStepSubmit,
|
|
326
328
|
resetFullFormState,
|
|
329
|
+
setPrimaryActionDisabled: setPrimaryActionDisabledByStep,
|
|
327
330
|
}) }) }), jsxRuntime.jsx(FormWizardFooter, { stepForms,
|
|
328
331
|
onClickBack: previousStepPath
|
|
329
332
|
? () => navigate({ to: basePath, params: { stepPath: previousStepPath } })
|
|
@@ -331,7 +334,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
331
334
|
primaryActionLabel: isLastStep ? lastStepPrimaryActionLabel : undefined,
|
|
332
335
|
onClickCancel: handleCancel,
|
|
333
336
|
loading: isLastStep ? isSubmitting : false,
|
|
334
|
-
disablePrimaryAction: isSubmitting })] }, String(stepKey)));
|
|
337
|
+
disablePrimaryAction: isSubmitting || primaryActionDisabledByStep })] }, String(stepKey)));
|
|
335
338
|
};
|
|
336
339
|
|
|
337
340
|
const cvaFormWizardContainer = cssClassVarianceUtilities.cvaMerge(["h-full"]);
|
package/index.esm.js
CHANGED
|
@@ -210,6 +210,7 @@ const cvaFormWizardComponentStepForm = cvaMerge(["grid-rows-min-fr-min", "grid",
|
|
|
210
210
|
const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, component, nextStepPath, previousStepPath, lastStepPrimaryActionLabel, fullFormSchema, setFullFormState, fullFormState, stepForms, setStepForms, setStepStates, basePath, containerClassName, onPrimaryAction, initialFullFormState, }) => {
|
|
211
211
|
const navigate = useNavigate();
|
|
212
212
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
213
|
+
const [primaryActionDisabledByStep, setPrimaryActionDisabledByStep] = useState(false);
|
|
213
214
|
const [submitHandlerInternal, setSubmitHandlerInternal] = useState(null);
|
|
214
215
|
const [beforeSubmitInternal, setBeforeSubmitInternal] = useState(null);
|
|
215
216
|
const form = useForm({
|
|
@@ -295,9 +296,10 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
295
296
|
return isEmptyStep && form.formState.isValid ? emptyStepSubmitHandler : stepSubmitHandler;
|
|
296
297
|
}, [emptyStepSubmitHandler, form.formState.isValid, isEmptyStep, stepSubmitHandler]);
|
|
297
298
|
useEffect(() => {
|
|
298
|
-
// submit on cmd/ctrl + enter,
|
|
299
|
+
// submit on cmd/ctrl + enter, unless a submit is already running or the step disabled the
|
|
300
|
+
// primary action — the shortcut must not bypass the footer button's disabled state
|
|
299
301
|
const handleKeyDown = (event) => {
|
|
300
|
-
if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
|
|
302
|
+
if (event.key === "Enter" && (event.ctrlKey || event.metaKey) && !isSubmitting && !primaryActionDisabledByStep) {
|
|
301
303
|
event.preventDefault();
|
|
302
304
|
void stepSubmitHandler();
|
|
303
305
|
}
|
|
@@ -306,7 +308,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
306
308
|
return () => {
|
|
307
309
|
document.removeEventListener("keydown", handleKeyDown);
|
|
308
310
|
};
|
|
309
|
-
}, [stepSubmitHandler]);
|
|
311
|
+
}, [stepSubmitHandler, isSubmitting, primaryActionDisabledByStep]);
|
|
310
312
|
return (jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: async (e) => {
|
|
311
313
|
e.preventDefault();
|
|
312
314
|
try {
|
|
@@ -322,6 +324,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
322
324
|
setSubmitHandler: isLastStep ? setSubmitHandler : null,
|
|
323
325
|
beforeStepSubmit: beforeStepSubmit,
|
|
324
326
|
resetFullFormState,
|
|
327
|
+
setPrimaryActionDisabled: setPrimaryActionDisabledByStep,
|
|
325
328
|
}) }) }), jsx(FormWizardFooter, { stepForms,
|
|
326
329
|
onClickBack: previousStepPath
|
|
327
330
|
? () => navigate({ to: basePath, params: { stepPath: previousStepPath } })
|
|
@@ -329,7 +332,7 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
|
|
|
329
332
|
primaryActionLabel: isLastStep ? lastStepPrimaryActionLabel : undefined,
|
|
330
333
|
onClickCancel: handleCancel,
|
|
331
334
|
loading: isLastStep ? isSubmitting : false,
|
|
332
|
-
disablePrimaryAction: isSubmitting })] }, String(stepKey)));
|
|
335
|
+
disablePrimaryAction: isSubmitting || primaryActionDisabledByStep })] }, String(stepKey)));
|
|
333
336
|
};
|
|
334
337
|
|
|
335
338
|
const cvaFormWizardContainer = cvaMerge(["h-full"]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/form-wizard/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-wizard",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.29",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"zod": "^3.25.76",
|
|
8
8
|
"@hookform/resolvers": "^3.3.4",
|
|
9
9
|
"@tanstack/router-core": "1.114.29",
|
|
10
|
-
"@trackunit/shared-utils": "1.16.
|
|
11
|
-
"@trackunit/css-class-variance-utilities": "1.14.
|
|
12
|
-
"@trackunit/react-components": "2.10.
|
|
13
|
-
"@trackunit/i18n-library-translation": "2.4.
|
|
10
|
+
"@trackunit/shared-utils": "1.16.22",
|
|
11
|
+
"@trackunit/css-class-variance-utilities": "1.14.19",
|
|
12
|
+
"@trackunit/react-components": "2.10.21",
|
|
13
|
+
"@trackunit/i18n-library-translation": "2.4.27"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=24.x",
|
|
@@ -17,6 +17,8 @@ export type StepComponentPropsInner<TStepSchema extends TFullSchemaValue[keyof T
|
|
|
17
17
|
setSubmitHandler: ((onFinalSubmit: (fullFormState: TFullSchemaValue) => void) => void) | null;
|
|
18
18
|
beforeStepSubmit?: ((beforeSubmit: (fullFormState: TFullSchemaValue) => void) => void) | null;
|
|
19
19
|
resetFullFormState?: ((reset: () => void) => void) | null;
|
|
20
|
+
/** Lets the step disable the footer's primary action, e.g. after a completed final submit. */
|
|
21
|
+
setPrimaryActionDisabled?: ((disabled: boolean) => void) | null;
|
|
20
22
|
};
|
|
21
23
|
export interface SimpleStepProps {
|
|
22
24
|
title: string;
|