@formisch/qwik 0.7.4 → 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
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { JSXOutput, NoSerialize, PropsOf, QRL, ReadonlySignal } from "@qwik.dev/core";
3
- import * as _qwik_dev_core_internal1 from "@qwik.dev/core/internal";
3
+ import * as _qwik_dev_core_internal3 from "@qwik.dev/core/internal";
4
4
 
5
5
  //#region ../../packages/core/dist/index.qwik.d.ts
6
6
 
@@ -227,7 +227,11 @@ type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submi
227
227
  /**
228
228
  * Submit handler type.
229
229
  */
230
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
230
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
231
+ /**
232
+ * Submit event handler type.
233
+ */
234
+ type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
231
235
  //#endregion
232
236
  //#region src/types/form.qwik.d.ts
233
237
  /**
@@ -483,6 +487,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
483
487
  //#endregion
484
488
  //#region src/handleSubmit/handleSubmit.d.ts
485
489
  /**
490
+ * Creates a submit event handler for the form that validates the form input,
491
+ * and calls the provided handler if validation succeeds. This is designed to
492
+ * be used with the form's onsubmit event.
493
+ *
494
+ * @param form The form store to handle submission for.
495
+ * @param handler The submit handler function called with validated output if validation succeeds.
496
+ *
497
+ * @returns A submit event handler function to attach to the form element.
498
+ */
499
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
500
+ /**
486
501
  * Creates a submit event handler for the form that prevents default browser
487
502
  * submission, validates the form input, and calls the provided handler if
488
503
  * validation succeeds. This is designed to be used with the form's onsubmit event.
@@ -492,7 +507,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
492
507
  *
493
508
  * @returns A submit event handler function to attach to the form element.
494
509
  */
495
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
510
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
496
511
  //#endregion
497
512
  //#region src/insert/insert.d.ts
498
513
  /**
@@ -868,6 +883,10 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
868
883
  * Whether the field is valid according to the schema.
869
884
  */
870
885
  readonly isValid: ReadonlySignal<boolean>;
886
+ /**
887
+ * Sets the field input value programmatically.
888
+ */
889
+ readonly onInput: QRL<(value: PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>) => void>;
871
890
  /**
872
891
  * The props to spread onto the field element for integration.
873
892
  */
@@ -966,7 +985,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
966
985
  *
967
986
  * @returns The UI of the field to be rendered.
968
987
  */
969
- declare const Field: <TSchema extends Schema, TFieldPath extends RequiredPath>(props: _qwik_dev_core_internal1.PublicProps<FieldProps<TSchema, TFieldPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal1.DevJSX) => JSXOutput;
988
+ declare const Field: <TSchema extends Schema, TFieldPath extends RequiredPath>(props: _qwik_dev_core_internal3.PublicProps<FieldProps<TSchema, TFieldPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal3.DevJSX) => JSXOutput;
970
989
  //#endregion
971
990
  //#region src/components/FieldArray/FieldArray.d.ts
972
991
  /**
@@ -994,7 +1013,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
994
1013
  *
995
1014
  * @returns The UI of the field array to be rendered.
996
1015
  */
997
- declare const FieldArray: <TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: _qwik_dev_core_internal1.PublicProps<FieldArrayProps<TSchema, TFieldArrayPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal1.DevJSX) => JSXOutput;
1016
+ declare const FieldArray: <TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: _qwik_dev_core_internal3.PublicProps<FieldArrayProps<TSchema, TFieldArrayPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal3.DevJSX) => JSXOutput;
998
1017
  //#endregion
999
1018
  //#region src/components/Form/Form.d.ts
1000
1019
  /**
@@ -1008,7 +1027,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmi
1008
1027
  /**
1009
1028
  * The submit handler called when the form is submitted and validation succeeds.
1010
1029
  */
1011
- readonly onSubmit$: QRL<SubmitHandler<TSchema>>;
1030
+ readonly onSubmit$: QRL<SubmitHandler<TSchema> | SubmitEventHandler<TSchema>>;
1012
1031
  };
1013
1032
  /**
1014
1033
  * Form component that manages form submission and applies internal state.
@@ -1016,7 +1035,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmi
1016
1035
  *
1017
1036
  * @returns The a native form element.
1018
1037
  */
1019
- declare const Form: <TSchema extends Schema>(props: _qwik_dev_core_internal1.PublicProps<FormProps<TSchema>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal1.DevJSX) => JSXOutput;
1038
+ declare const Form: <TSchema extends Schema>(props: _qwik_dev_core_internal3.PublicProps<FormProps<TSchema>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal3.DevJSX) => JSXOutput;
1020
1039
  //#endregion
1021
1040
  //#region src/hooks/useField/useField.d.ts
1022
1041
  /**
@@ -1031,6 +1050,9 @@ interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends Req
1031
1050
  /**
1032
1051
  * Creates a reactive field store of a specific field within a form store.
1033
1052
  *
1053
+ * @param form The form store instance.
1054
+ * @param config The field configuration.
1055
+ *
1034
1056
  * @returns The field store with reactive properties and element props.
1035
1057
  */
1036
1058
  declare function useField<TSchema extends Schema, TFieldPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldConfig<TSchema, TFieldPath>): FieldStore<TSchema, TFieldPath>;
@@ -1048,6 +1070,9 @@ interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath e
1048
1070
  /**
1049
1071
  * Creates a reactive field array store of a specific field array within a form store.
1050
1072
  *
1073
+ * @param form The form store instance.
1074
+ * @param config The field array configuration.
1075
+ *
1051
1076
  * @returns The field array store with reactive properties for array management.
1052
1077
  */
1053
1078
  declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: FormStore<TSchema>, config: UseFieldArrayConfig<TSchema, TFieldArrayPath>): FieldArrayStore<TSchema, TFieldArrayPath>;
@@ -1057,6 +1082,8 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
1057
1082
  * Creates a reactive form store from a form configuration. The form store
1058
1083
  * manages form state and provides reactive properties.
1059
1084
  *
1085
+ * @param configQrl The QRL containing the form configuration.
1086
+ *
1060
1087
  * @returns The form store with reactive properties.
1061
1088
  */
1062
1089
  declare function useFormQrl<TSchema extends Schema>(configQrl: QRL<FormConfig<TSchema>>): FormStore<TSchema>;
@@ -1068,4 +1095,4 @@ declare function useFormQrl<TSchema extends Schema>(configQrl: QRL<FormConfig<TS
1068
1095
  */
1069
1096
  declare const useForm$: <TSchema extends Schema>(qrl: FormConfig<TSchema>) => FormStore<TSchema>;
1070
1097
  //#endregion
1071
- 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$, useFormQrl, validate };
1098
+ 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$, useFormQrl, validate };
@@ -65,7 +65,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
65
65
  initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
66
66
  path.pop();
67
67
  }
68
- } else for (let index = 0; index < schema.items; index++) {
68
+ } else for (let index = 0; index < schema.items.length; index++) {
69
69
  internalFieldStore.children[index] = {};
70
70
  path.push(index);
71
71
  initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
@@ -378,7 +378,7 @@ function setNestedInput(internalFieldStore, input) {
378
378
  }
379
379
  for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
380
380
  internalFieldStore.input.value = input == null ? input : true;
381
- internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
381
+ internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
382
382
  } else if (internalFieldStore.kind === "object") {
383
383
  for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
384
384
  internalFieldStore.input.value = input == null ? input : true;
@@ -585,7 +585,7 @@ function getInput(form, config) {
585
585
  /* @__NO_SIDE_EFFECTS__ */
586
586
  function handleSubmit(form, handler) {
587
587
  return async (event) => {
588
- event.preventDefault();
588
+ event?.preventDefault();
589
589
  const internalFormStore = form[INTERNAL];
590
590
  internalFormStore.isSubmitted.value = true;
591
591
  internalFormStore.isSubmitting.value = true;
@@ -829,6 +829,10 @@ function useField(form, config) {
829
829
  isTouched: createComputed$(() => getFieldBool(internalFieldStore.value, "isTouched")),
830
830
  isDirty: createComputed$(() => getFieldBool(internalFieldStore.value, "isDirty")),
831
831
  isValid: createComputed$(() => !getFieldBool(internalFieldStore.value, "errors")),
832
+ onInput: $((value) => {
833
+ setFieldInput(internalFormStore, pathSignal.value, value);
834
+ validateIfRequired(internalFormStore, internalFieldStore.value, "input");
835
+ }),
832
836
  props: {
833
837
  get name() {
834
838
  return internalFieldStore.value.name;
@@ -973,7 +977,7 @@ const Form = component$(({ of, onSubmit$,...other }) => {
973
977
  ref: (element) => {
974
978
  of[INTERNAL].element = element;
975
979
  },
976
- onSubmit$: (event) => handleSubmit(of, onSubmit$)(event),
980
+ onSubmit$: handleSubmit(of, onSubmit$),
977
981
  children: /* @__PURE__ */ jsx(Slot, {})
978
982
  });
979
983
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/qwik",
3
3
  "description": "The modular and type-safe form library for Qwik",
4
- "version": "0.7.4",
4
+ "version": "0.9.0",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -36,7 +36,6 @@
36
36
  "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@eslint/js": "^9.31.0",
40
39
  "@qwik.dev/core": "2.0.0-beta.5",
41
40
  "@types/node": "24.0.13",
42
41
  "eslint": "9.31.0",
@@ -45,12 +44,12 @@
45
44
  "prettier": "3.6.2",
46
45
  "tsdown": "0.12.9",
47
46
  "typescript": "5.8.3",
48
- "typescript-eslint": "8.36.0",
49
47
  "valibot": "^1.2.0",
50
48
  "vite": "7.0.4",
51
49
  "vite-tsconfig-paths": "^5.1.4",
52
- "@formisch/core": "0.4.5",
53
- "@formisch/methods": "0.5.2"
50
+ "@formisch/core": "0.6.0",
51
+ "@formisch/methods": "0.7.0",
52
+ "@formisch/eslint-config": "0.1.0"
54
53
  },
55
54
  "peerDependencies": {
56
55
  "@qwik.dev/core": ">=2",