@formisch/react 0.3.0 → 0.4.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/README.md CHANGED
@@ -32,7 +32,7 @@ export default function LoginPage() {
32
32
  });
33
33
 
34
34
  return (
35
- <Form of={loginForm} onSubmit={(output) => console.log(output)}>
35
+ <Form of={loginForm} onSubmit={(output, event) => console.log(output)}>
36
36
  <Field of={loginForm} path={['email']}>
37
37
  {(field) => (
38
38
  <div>
package/dist/index.d.ts CHANGED
@@ -200,11 +200,11 @@ type MaybePromise<TValue> = TValue | Promise<TValue>;
200
200
  /**
201
201
  * Makes all properties deeply optional.
202
202
  */
203
- type DeepPartial<TValue> = TValue extends readonly unknown[] ? number extends TValue["length"] ? TValue : { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue extends Record<PropertyKey, unknown> ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
203
+ type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
204
204
  /**
205
205
  * Makes all value properties optional.
206
206
  */
207
- type PartialValues<TValue> = TValue extends readonly unknown[] ? number extends TValue["length"] ? TValue : { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue extends Record<PropertyKey, unknown> ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
207
+ type PartialValues<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
208
208
  //#endregion
209
209
  //#region src/values.d.ts
210
210
  /**
@@ -289,9 +289,13 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
289
289
  //#endregion
290
290
  //#region src/types/form.react.d.ts
291
291
  /**
292
- * Submit handler type for React.
292
+ * Submit handler type.
293
293
  */
294
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: FormEvent<HTMLFormElement>) => MaybePromise<unknown>;
294
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
295
+ /**
296
+ * Submit event handler type.
297
+ */
298
+ type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: FormEvent<HTMLFormElement>) => MaybePromise<unknown>;
295
299
  //#endregion
296
300
  //#region src/types/path.d.ts
297
301
  /**
@@ -475,6 +479,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
475
479
  //#endregion
476
480
  //#region src/handleSubmit/handleSubmit.react.d.ts
477
481
  /**
482
+ * Creates a submit event handler for the form that validates the form input,
483
+ * and calls the provided handler if validation succeeds. This is designed to
484
+ * be used with the form's onsubmit event.
485
+ *
486
+ * @param form The form store to handle submission for.
487
+ * @param handler The submit handler function called with validated output if validation succeeds.
488
+ *
489
+ * @returns A submit event handler function to attach to the form element.
490
+ */
491
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
492
+ /**
478
493
  * Creates a submit event handler for the form that prevents default browser
479
494
  * submission, validates the form input, and calls the provided handler if
480
495
  * validation succeeds. This is designed to be used with the form's onsubmit event.
@@ -484,7 +499,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
484
499
  *
485
500
  * @returns A submit event handler function to attach to the form element.
486
501
  */
487
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: FormEvent<HTMLFormElement>) => Promise<void>;
502
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: FormEvent<HTMLFormElement>) => Promise<void>;
488
503
  //#endregion
489
504
  //#region src/insert/insert.d.ts
490
505
  /**
@@ -1014,7 +1029,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<FormHTMLAttributes<HTMLFo
1014
1029
  /**
1015
1030
  * The submit handler called when the form is submitted and validation succeeds.
1016
1031
  */
1017
- readonly onSubmit: SubmitHandler<TSchema>;
1032
+ readonly onSubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
1018
1033
  };
1019
1034
  /**
1020
1035
  * Form component that manages form submission and applies internal state.
@@ -1077,4 +1092,4 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
1077
1092
  */
1078
1093
  declare function useForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1079
1094
  //#endregion
1080
- export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, type SetFieldInputConfig, SetFormErrorsConfig, type SetFormInputConfig, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
1095
+ export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, type SetFieldInputConfig, SetFormErrorsConfig, type SetFormInputConfig, type SubmitEventHandler, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm, validate };
package/dist/index.js CHANGED
@@ -661,7 +661,7 @@ function getInput(form, config) {
661
661
  /* @__NO_SIDE_EFFECTS__ */
662
662
  function handleSubmit$1(form, handler) {
663
663
  return async (event) => {
664
- event.preventDefault();
664
+ event?.preventDefault();
665
665
  const internalFormStore = form[INTERNAL];
666
666
  internalFormStore.isSubmitted.value = true;
667
667
  internalFormStore.isSubmitting.value = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/react",
3
3
  "description": "The modular and type-safe form library for React",
4
- "version": "0.3.0",
4
+ "version": "0.4.1",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -46,9 +46,9 @@
46
46
  "tsdown": "^0.16.8",
47
47
  "typescript": "~5.9.3",
48
48
  "vite": "^7.2.4",
49
- "@formisch/core": "0.5.0",
49
+ "@formisch/core": "0.6.1",
50
50
  "@formisch/eslint-config": "0.1.0",
51
- "@formisch/methods": "0.6.0"
51
+ "@formisch/methods": "0.7.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",