@formisch/qwik 0.9.6 → 0.10.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/README.md CHANGED
@@ -28,9 +28,9 @@ const LoginSchema = v.object({
28
28
  });
29
29
 
30
30
  export default component$(() => {
31
- const loginForm = useForm$({
31
+ const loginForm = useForm$(() => ({
32
32
  schema: LoginSchema,
33
- });
33
+ }));
34
34
 
35
35
  return (
36
36
  <Form of={loginForm} onSubmit$={(output, event) => console.log(output)}>
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_internal3 from "@qwik.dev/core/internal";
3
+ import * as _qwik_dev_core_internal0 from "@qwik.dev/core/internal";
4
4
 
5
5
  //#region ../../packages/core/dist/index.qwik.d.ts
6
6
 
@@ -989,7 +989,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
989
989
  *
990
990
  * @returns The UI of the field to be rendered.
991
991
  */
992
- 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;
992
+ declare const Field: <TSchema extends Schema, TFieldPath extends RequiredPath>(props: _qwik_dev_core_internal0.PublicProps<FieldProps<TSchema, TFieldPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal0.DevJSX) => JSXOutput;
993
993
  //#endregion
994
994
  //#region src/components/FieldArray/FieldArray.d.ts
995
995
  /**
@@ -1017,7 +1017,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
1017
1017
  *
1018
1018
  * @returns The UI of the field array to be rendered.
1019
1019
  */
1020
- 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;
1020
+ declare const FieldArray: <TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: _qwik_dev_core_internal0.PublicProps<FieldArrayProps<TSchema, TFieldArrayPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal0.DevJSX) => JSXOutput;
1021
1021
  //#endregion
1022
1022
  //#region src/components/Form/Form.d.ts
1023
1023
  /**
@@ -1039,7 +1039,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmi
1039
1039
  *
1040
1040
  * @returns The a native form element.
1041
1041
  */
1042
- 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;
1042
+ declare const Form: <TSchema extends Schema>(props: _qwik_dev_core_internal0.PublicProps<FormProps<TSchema>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal0.DevJSX) => JSXOutput;
1043
1043
  //#endregion
1044
1044
  //#region src/hooks/useField/useField.d.ts
1045
1045
  /**
@@ -1086,17 +1086,19 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
1086
1086
  * Creates a reactive form store from a form configuration. The form store
1087
1087
  * manages form state and provides reactive properties.
1088
1088
  *
1089
- * @param configQrl The QRL containing the form configuration.
1089
+ * @param configQrl The QRL containing a function that returns the form configuration.
1090
1090
  *
1091
1091
  * @returns The form store with reactive properties.
1092
1092
  */
1093
- declare function useFormQrl<TSchema extends Schema>(configQrl: QRL<FormConfig<TSchema>>): FormStore<TSchema>;
1093
+ declare function useFormQrl<TSchema extends Schema>(configQrl: QRL<() => FormConfig<TSchema>>): FormStore<TSchema>;
1094
1094
  /**
1095
1095
  * Creates a reactive form store from a form configuration. The form store
1096
1096
  * manages form state and provides reactive properties.
1097
1097
  *
1098
+ * @param configFn A function that returns the form configuration.
1099
+ *
1098
1100
  * @returns The form store with reactive properties.
1099
1101
  */
1100
- declare const useForm$: <TSchema extends Schema>(qrl: FormConfig<TSchema>) => FormStore<TSchema>;
1102
+ declare const useForm$: <TSchema extends Schema>(qrl: () => FormConfig<TSchema>) => FormStore<TSchema>;
1101
1103
  //#endregion
1102
1104
  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 };
@@ -568,6 +568,7 @@ function focus(form, config) {
568
568
  function getAllErrors(form) {
569
569
  let allErrors = null;
570
570
  walkFieldStore(form[INTERNAL], (internalFieldStore) => {
571
+ if (internalFieldStore.kind === "array") internalFieldStore.items.value;
571
572
  const errors = internalFieldStore.errors.value;
572
573
  if (errors) if (allErrors) allErrors.push(...errors);
573
574
  else allErrors = [...errors];
@@ -620,7 +621,15 @@ function insert(form, config) {
620
621
  const newItems = [...items];
621
622
  newItems.splice(insertIndex, 0, createId());
622
623
  internalArrayStore.items.value = newItems;
623
- for (let index = items.length; index > insertIndex; index--) copyItemState(internalArrayStore.children[index - 1], internalArrayStore.children[index]);
624
+ for (let index = items.length; index > insertIndex; index--) {
625
+ if (!internalArrayStore.children[index]) {
626
+ const path = JSON.parse(internalArrayStore.name);
627
+ internalArrayStore.children[index] = {};
628
+ path.push(index);
629
+ initializeFieldStore(internalArrayStore.children[index], internalArrayStore.schema.item, void 0, path);
630
+ }
631
+ copyItemState(internalArrayStore.children[index - 1], internalArrayStore.children[index]);
632
+ }
624
633
  if (!internalArrayStore.children[insertIndex]) {
625
634
  const path = JSON.parse(internalArrayStore.name);
626
635
  internalArrayStore.children[insertIndex] = {};
@@ -899,12 +908,13 @@ function useResolvedQrl(qrl) {
899
908
  //#region src/hooks/useForm$/useForm$.ts
900
909
  /* @__NO_SIDE_EFFECTS__ */
901
910
  function useFormQrl(configQrl) {
902
- const config = useResolvedQrl(configQrl);
911
+ const configFn = useResolvedQrl(configQrl);
912
+ const config = configFn();
903
913
  const form = useConstant(() => {
904
914
  const internalFormStore = createFormStore({
905
915
  ...config,
906
916
  schema: JSON.parse(JSON.stringify(config.schema))
907
- }, $(async (input) => v.safeParseAsync((await configQrl.resolve()).schema, input)));
917
+ }, $(async (input) => v.safeParseAsync((await configQrl.resolve())().schema, input)));
908
918
  return {
909
919
  [INTERNAL]: internalFormStore,
910
920
  isSubmitting: internalFormStore.isSubmitting,
@@ -926,6 +936,8 @@ function useFormQrl(configQrl) {
926
936
  * Creates a reactive form store from a form configuration. The form store
927
937
  * manages form state and provides reactive properties.
928
938
  *
939
+ * @param configFn A function that returns the form configuration.
940
+ *
929
941
  * @returns The form store with reactive properties.
930
942
  */
931
943
  const useForm$ = implicit$FirstArg(useFormQrl);
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.9.6",
4
+ "version": "0.10.0",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",