@formisch/solid 0.8.0 → 0.9.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/dev.js CHANGED
@@ -411,7 +411,7 @@ function getInput(form, config) {
411
411
  // @__NO_SIDE_EFFECTS__
412
412
  function handleSubmit(form, handler) {
413
413
  return async (event) => {
414
- event.preventDefault();
414
+ event?.preventDefault();
415
415
  const internalFormStore = form[INTERNAL];
416
416
  internalFormStore.isSubmitted.value = true;
417
417
  internalFormStore.isSubmitting.value = true;
package/dist/dev.jsx CHANGED
@@ -409,7 +409,7 @@ function getInput(form, config) {
409
409
  // @__NO_SIDE_EFFECTS__
410
410
  function handleSubmit(form, handler) {
411
411
  return async (event) => {
412
- event.preventDefault();
412
+ event?.preventDefault();
413
413
  const internalFormStore = form[INTERNAL];
414
414
  internalFormStore.isSubmitted.value = true;
415
415
  internalFormStore.isSubmitting.value = true;
package/dist/index.d.ts CHANGED
@@ -206,11 +206,11 @@ type MaybePromise<TValue> = TValue | Promise<TValue>;
206
206
  /**
207
207
  * Makes all properties deeply optional.
208
208
  */
209
- 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;
209
+ type DeepPartial<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]?: DeepPartial<TValue[Key]> | undefined } : TValue | undefined;
210
210
  /**
211
211
  * Makes all value properties optional.
212
212
  */
213
- 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;
213
+ type PartialValues<TValue> = TValue extends Record<PropertyKey, unknown> | readonly unknown[] ? { [Key in keyof TValue]: PartialValues<TValue[Key]> } : TValue | undefined;
214
214
  //#endregion
215
215
  //#region src/types/form.d.ts
216
216
  /**
@@ -289,7 +289,11 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
289
289
  /**
290
290
  * Submit handler type.
291
291
  */
292
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
292
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
293
+ /**
294
+ * Submit event handler type.
295
+ */
296
+ type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
293
297
  //#endregion
294
298
  //#region src/types/path.d.ts
295
299
  /**
@@ -474,6 +478,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
474
478
  //#endregion
475
479
  //#region src/handleSubmit/handleSubmit.d.ts
476
480
  /**
481
+ * Creates a submit event handler for the form that validates the form input,
482
+ * and calls the provided handler if validation succeeds. This is designed to
483
+ * be used with the form's onsubmit event.
484
+ *
485
+ * @param form The form store to handle submission for.
486
+ * @param handler The submit handler function called with validated output if validation succeeds.
487
+ *
488
+ * @returns A submit event handler function to attach to the form element.
489
+ */
490
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
491
+ /**
477
492
  * Creates a submit event handler for the form that prevents default browser
478
493
  * submission, validates the form input, and calls the provided handler if
479
494
  * validation succeeds. This is designed to be used with the form's onsubmit event.
@@ -483,7 +498,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
483
498
  *
484
499
  * @returns A submit event handler function to attach to the form element.
485
500
  */
486
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
501
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
487
502
  //#endregion
488
503
  //#region src/insert/insert.d.ts
489
504
  /**
@@ -1016,7 +1031,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HT
1016
1031
  /**
1017
1032
  * The submit handler called when the form is submitted and validation succeeds.
1018
1033
  */
1019
- readonly onSubmit: SubmitHandler<TSchema>;
1034
+ readonly onSubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
1020
1035
  };
1021
1036
  /**
1022
1037
  * Form component that manages form submission and applies internal state.
@@ -1079,4 +1094,4 @@ interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath e
1079
1094
  */
1080
1095
  declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: MaybeGetter<FormStore<TSchema>>, config: MaybeGetter<UseFieldArrayConfig<TSchema, TFieldArrayPath>>): FieldArrayStore<TSchema, TFieldArrayPath>;
1081
1096
  //#endregion
1082
- export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MaybeGetter, 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, createForm, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, validate };
1097
+ export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MaybeGetter, 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, createForm, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, validate };
package/dist/index.js CHANGED
@@ -411,7 +411,7 @@ function getInput(form, config) {
411
411
  // @__NO_SIDE_EFFECTS__
412
412
  function handleSubmit(form, handler) {
413
413
  return async (event) => {
414
- event.preventDefault();
414
+ event?.preventDefault();
415
415
  const internalFormStore = form[INTERNAL];
416
416
  internalFormStore.isSubmitted.value = true;
417
417
  internalFormStore.isSubmitting.value = true;
package/dist/index.jsx CHANGED
@@ -409,7 +409,7 @@ function getInput(form, config) {
409
409
  // @__NO_SIDE_EFFECTS__
410
410
  function handleSubmit(form, handler) {
411
411
  return async (event) => {
412
- event.preventDefault();
412
+ event?.preventDefault();
413
413
  const internalFormStore = form[INTERNAL];
414
414
  internalFormStore.isSubmitted.value = true;
415
415
  internalFormStore.isSubmitting.value = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/solid",
3
3
  "description": "The modular and type-safe form library for SolidJS",
4
- "version": "0.8.0",
4
+ "version": "0.9.1",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -57,9 +57,9 @@
57
57
  "typescript": "^5.8.3",
58
58
  "valibot": "^1.2.0",
59
59
  "vitest": "3.2.4",
60
- "@formisch/methods": "0.6.0",
61
60
  "@formisch/eslint-config": "0.1.0",
62
- "@formisch/core": "0.5.0"
61
+ "@formisch/methods": "0.7.0",
62
+ "@formisch/core": "0.6.1"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "solid-js": "^1.6.0",