@trackunit/react-form-wizard 0.1.71 → 0.1.74

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 CHANGED
@@ -276,11 +276,15 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
276
276
  setSubmitHandlerInternal(() => wrappedCallbackFunction);
277
277
  }, [setSubmitHandlerInternal]);
278
278
  const isEmptyStep = sharedUtils.objectKeys(form.getValues()).length === 0;
279
- const emptyStepSubmitHandler = react.useCallback((e) => {
280
- e === null || e === void 0 ? void 0 : e.preventDefault();
281
- submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(fullFormState);
282
- }, [fullFormState, submitHandlerInternal]);
283
- const nonEmptyStepSubmitHandler = react.useMemo(() => form.handleSubmit((data) => __awaiter(void 0, void 0, void 0, function* () {
279
+ const emptyStepSubmitHandler = react.useCallback(() => {
280
+ if (isLastStep) {
281
+ submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(fullFormState);
282
+ }
283
+ else if (nextStepPath) {
284
+ navigate({ to: basePath, params: { stepPath: nextStepPath } });
285
+ }
286
+ }, [basePath, fullFormState, isLastStep, navigate, nextStepPath, submitHandlerInternal]);
287
+ const stepSubmitHandler = react.useMemo(() => form.handleSubmit((data) => __awaiter(void 0, void 0, void 0, function* () {
284
288
  //? This state is not updated for the submit handler below; therefore, there is duplication.
285
289
  setFullFormState(prev => (Object.assign(Object.assign({}, prev), { [stepKey]: data })));
286
290
  if (isLastStep) {
@@ -301,8 +305,24 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
301
305
  stepKey,
302
306
  submitHandlerInternal,
303
307
  ]);
304
- const handleSubmit = react.useMemo(() => (isEmptyStep ? emptyStepSubmitHandler : nonEmptyStepSubmitHandler), [emptyStepSubmitHandler, isEmptyStep, nonEmptyStepSubmitHandler]);
305
- return (jsxRuntime.jsxs("form", { className: cvaFormWizardComponentStepForm(), onSubmit: handleSubmit, ref: formRef, children: [jsxRuntime.jsx(FormWizardHeader, { title, description }), jsxRuntime.jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
308
+ const handleSubmit = react.useMemo(() => (isEmptyStep ? emptyStepSubmitHandler : stepSubmitHandler), [emptyStepSubmitHandler, isEmptyStep, stepSubmitHandler]);
309
+ react.useEffect(() => {
310
+ // submit on cmd/ctrl + enter, always
311
+ const handleKeyDown = (event) => {
312
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
313
+ event.preventDefault();
314
+ stepSubmitHandler();
315
+ }
316
+ };
317
+ document.addEventListener("keydown", handleKeyDown);
318
+ return () => {
319
+ document.removeEventListener("keydown", handleKeyDown);
320
+ };
321
+ }, [stepSubmitHandler]);
322
+ return (jsxRuntime.jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: e => {
323
+ e.preventDefault();
324
+ handleSubmit();
325
+ }, ref: formRef, children: [jsxRuntime.jsx(FormWizardHeader, { title, description }), jsxRuntime.jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
306
326
  form,
307
327
  fullForm,
308
328
  setSubmitHandler: isLastStep ? setSubmitHandler : null,
package/index.esm.js CHANGED
@@ -272,11 +272,15 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
272
272
  setSubmitHandlerInternal(() => wrappedCallbackFunction);
273
273
  }, [setSubmitHandlerInternal]);
274
274
  const isEmptyStep = objectKeys(form.getValues()).length === 0;
275
- const emptyStepSubmitHandler = useCallback((e) => {
276
- e === null || e === void 0 ? void 0 : e.preventDefault();
277
- submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(fullFormState);
278
- }, [fullFormState, submitHandlerInternal]);
279
- const nonEmptyStepSubmitHandler = useMemo(() => form.handleSubmit((data) => __awaiter(void 0, void 0, void 0, function* () {
275
+ const emptyStepSubmitHandler = useCallback(() => {
276
+ if (isLastStep) {
277
+ submitHandlerInternal === null || submitHandlerInternal === void 0 ? void 0 : submitHandlerInternal(fullFormState);
278
+ }
279
+ else if (nextStepPath) {
280
+ navigate({ to: basePath, params: { stepPath: nextStepPath } });
281
+ }
282
+ }, [basePath, fullFormState, isLastStep, navigate, nextStepPath, submitHandlerInternal]);
283
+ const stepSubmitHandler = useMemo(() => form.handleSubmit((data) => __awaiter(void 0, void 0, void 0, function* () {
280
284
  //? This state is not updated for the submit handler below; therefore, there is duplication.
281
285
  setFullFormState(prev => (Object.assign(Object.assign({}, prev), { [stepKey]: data })));
282
286
  if (isLastStep) {
@@ -297,8 +301,24 @@ const FormWizardStepWrapper = ({ stepKey, onCancel, description, title, componen
297
301
  stepKey,
298
302
  submitHandlerInternal,
299
303
  ]);
300
- const handleSubmit = useMemo(() => (isEmptyStep ? emptyStepSubmitHandler : nonEmptyStepSubmitHandler), [emptyStepSubmitHandler, isEmptyStep, nonEmptyStepSubmitHandler]);
301
- return (jsxs("form", { className: cvaFormWizardComponentStepForm(), onSubmit: handleSubmit, ref: formRef, children: [jsx(FormWizardHeader, { title, description }), jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
304
+ const handleSubmit = useMemo(() => (isEmptyStep ? emptyStepSubmitHandler : stepSubmitHandler), [emptyStepSubmitHandler, isEmptyStep, stepSubmitHandler]);
305
+ useEffect(() => {
306
+ // submit on cmd/ctrl + enter, always
307
+ const handleKeyDown = (event) => {
308
+ if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
309
+ event.preventDefault();
310
+ stepSubmitHandler();
311
+ }
312
+ };
313
+ document.addEventListener("keydown", handleKeyDown);
314
+ return () => {
315
+ document.removeEventListener("keydown", handleKeyDown);
316
+ };
317
+ }, [stepSubmitHandler]);
318
+ return (jsxs("form", { className: cvaFormWizardComponentStepForm(), noValidate: true, onSubmit: e => {
319
+ e.preventDefault();
320
+ handleSubmit();
321
+ }, ref: formRef, children: [jsx(FormWizardHeader, { title, description }), jsx("div", { className: cvaFormWizardComponentContainer({ className: containerClassName }), children: component({
302
322
  form,
303
323
  fullForm,
304
324
  setSubmitHandler: isLastStep ? setSubmitHandler : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-wizard",
3
- "version": "0.1.71",
3
+ "version": "0.1.74",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {