@formisch/preact 0.8.0 → 0.9.0

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/dist/index.d.ts CHANGED
@@ -282,7 +282,11 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
282
282
  /**
283
283
  * Submit handler type.
284
284
  */
285
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
285
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
286
+ /**
287
+ * Submit event handler type.
288
+ */
289
+ type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
286
290
  //#endregion
287
291
  //#region src/types/path.d.ts
288
292
  /**
@@ -467,6 +471,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
467
471
  //#endregion
468
472
  //#region src/handleSubmit/handleSubmit.d.ts
469
473
  /**
474
+ * Creates a submit event handler for the form that validates the form input,
475
+ * and calls the provided handler if validation succeeds. This is designed to
476
+ * be used with the form's onsubmit event.
477
+ *
478
+ * @param form The form store to handle submission for.
479
+ * @param handler The submit handler function called with validated output if validation succeeds.
480
+ *
481
+ * @returns A submit event handler function to attach to the form element.
482
+ */
483
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
484
+ /**
470
485
  * Creates a submit event handler for the form that prevents default browser
471
486
  * submission, validates the form input, and calls the provided handler if
472
487
  * validation succeeds. This is designed to be used with the form's onsubmit event.
@@ -476,7 +491,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
476
491
  *
477
492
  * @returns A submit event handler function to attach to the form element.
478
493
  */
479
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
494
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
480
495
  //#endregion
481
496
  //#region src/insert/insert.d.ts
482
497
  /**
@@ -1008,7 +1023,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HT
1008
1023
  /**
1009
1024
  * The submit handler called when the form is submitted and validation succeeds.
1010
1025
  */
1011
- readonly onSubmit: SubmitHandler<TSchema>;
1026
+ readonly onSubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
1012
1027
  };
1013
1028
  /**
1014
1029
  * Form component that manages form submission and applies internal state.
@@ -1071,4 +1086,4 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
1071
1086
  */
1072
1087
  declare function useForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
1073
1088
  //#endregion
1074
- 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, SetFieldInputConfig, SetFormErrorsConfig, 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 };
1089
+ 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, SetFieldInputConfig, SetFormErrorsConfig, 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
@@ -575,7 +575,7 @@ function getInput(form, config) {
575
575
  /* @__NO_SIDE_EFFECTS__ */
576
576
  function handleSubmit(form, handler) {
577
577
  return async (event) => {
578
- event.preventDefault();
578
+ event?.preventDefault();
579
579
  const internalFormStore = form[INTERNAL];
580
580
  internalFormStore.isSubmitted.value = true;
581
581
  internalFormStore.isSubmitting.value = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/preact",
3
3
  "description": "The modular and type-safe form library for Preact",
4
- "version": "0.8.0",
4
+ "version": "0.9.0",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -42,9 +42,9 @@
42
42
  "typescript": "^5.8.3",
43
43
  "valibot": "^1.2.0",
44
44
  "vite": "^6.0.4",
45
- "@formisch/methods": "0.6.0",
46
45
  "@formisch/eslint-config": "0.1.0",
47
- "@formisch/core": "0.5.0"
46
+ "@formisch/core": "0.6.0",
47
+ "@formisch/methods": "0.7.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@preact/signals": "^2.0.0",