@formisch/qwik 0.2.0 → 0.3.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
@@ -2,6 +2,8 @@
2
2
 
3
3
  Formisch is a schema-based, headless form library for Qwik. It manages form state and validation. It is type-safe, fast by default and its bundle size is small due to its modular design. Try it out in our [playground](https://stackblitz.com/edit/formisch-playground-qwik)!
4
4
 
5
+ Formisch is also available for [Preact][formisch-preact], [SolidJS][formisch-solid], [Svelte][formisch-svelte] and [Vue][formisch-vue].
6
+
5
7
  ## Highlights
6
8
 
7
9
  - Small bundle size starting at 2.5 kB
@@ -60,6 +62,16 @@ export default component$(() => {
60
62
 
61
63
  In addition, Formisch offers several functions (we call them "methods") that can be used to read and manipulate the form state. These include `focus`, `getErrors`, `getAllErrors`, `getInput`, `insert`, `move`, `remove`, `replace`, `reset`, `setErrors`, `setInput`, `submit`, `swap` and `validate`. These methods allow you to control the form programmatically.
62
64
 
65
+ ## Comparison
66
+
67
+ What makes Formisch unique is its framework-agnostic core, which is fully native to the framework you are using. It works by inserting framework-specific reactivity blocks when the core package is built. The result is a small bundle size and native performance for any UI update. This feature, along with a few others, distinguishes Formisch from other form libraries. My vision for Formisch is to create a framework-agnostic platform similar to [Vite](https://vite.dev/), but for forms.
68
+
69
+ ## Partners
70
+
71
+ Thanks to our partners who support the development! [Join them](https://github.com/sponsors/fabian-hiller) and contribute to the sustainability of open source software!
72
+
73
+ ![Partners of Formisch](https://github.com/fabian-hiller/formisch/blob/main/partners.webp?raw=true)
74
+
63
75
  ## Feedback
64
76
 
65
77
  Find a bug or have an idea how to improve the library? Please fill out an [issue](https://github.com/fabian-hiller/formisch/issues/new). Together we can make forms even better!
@@ -67,3 +79,8 @@ Find a bug or have an idea how to improve the library? Please fill out an [issue
67
79
  ## License
68
80
 
69
81
  This project is available free of charge and licensed under the [MIT license](https://github.com/fabian-hiller/formisch/blob/main/LICENSE.md).
82
+
83
+ [formisch-preact]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/preact
84
+ [formisch-solid]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/solid
85
+ [formisch-svelte]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/svelte
86
+ [formisch-vue]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/vue
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
  //#region src/types/schema.d.ts
@@ -78,7 +78,7 @@ type PartialValues<TValue> = TValue extends readonly unknown[] ? number extends
78
78
  * Value type of the validation mode.
79
79
  */
80
80
  type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submit";
81
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<void>;
81
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
82
82
  //#endregion
83
83
  //#region src/types/form.qwik.d.ts
84
84
  interface FormConfig<TSchema extends Schema = Schema> {
@@ -129,16 +129,16 @@ type MergeUnion<T> = { [K in KeyOf<T>]: T extends Record<K, infer V> ? V : never
129
129
  /**
130
130
  * Lazily evaluate only the first valid path segment based on the given value.
131
131
  */
132
- type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends KeyOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<MergeUnion<TValue>[TFirstKey], TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOf<TValue>> extends false ? readonly [...TValidPath, KeyOf<TValue>] : TValidPath;
132
+ type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends KeyOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOf<TValue>> extends false ? readonly [...TValidPath, KeyOf<TValue>] : TValidPath;
133
133
  /**
134
134
  * Returns the path if valid, otherwise the first possible valid path based on
135
135
  * the given value.
136
136
  */
137
- type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<TValue, TPath> ? TPath : LazyPath<TValue, TPath>;
137
+ type ValidPath<TValue, TPath extends RequiredPath> = TPath extends LazyPath<Required<TValue>, TPath> ? TPath : LazyPath<Required<TValue>, TPath>;
138
138
  /**
139
139
  * Extracts the value type at the given path.
140
140
  */
141
- type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends KeyOf<TValue> ? PathValue<MergeUnion<TValue>[TKey], TRest> : unknown : TValue;
141
+ type PathValue<TValue, TPath extends Path> = TPath extends readonly [infer TKey, ...infer TRest extends Path] ? TKey extends KeyOf<Required<TValue>> ? PathValue<MergeUnion<Required<TValue>>[TKey], TRest> : unknown : TValue;
142
142
  /**
143
143
  * Checks if a value is an array or contains one.
144
144
  */
@@ -146,16 +146,16 @@ type IsOrHasArray<TValue> = IsAny<TValue> extends true ? false : TValue extends
146
146
  /**
147
147
  * Extracts the exact keys of a tuple, array or object that contain arrays.
148
148
  */
149
- type KeyOfArrayPath<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? IsOrHasArray<TItem> extends true ? number : never : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? IsOrHasArray<TValue[TKey]> extends true ? TIndex : never : never }[number] : TValue extends Record<string, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<TValue[TKey]> extends true ? TKey : never }[keyof TValue] & PathKey : never;
149
+ type KeyOfArrayPath<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? IsOrHasArray<TItem> extends true ? number : never : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TIndex : never : never }[number] : TValue extends Record<string, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TKey : never }[keyof TValue] & PathKey : never;
150
150
  /**
151
151
  * Lazily evaluate only the first valid array path segment based on the given value.
152
152
  */
153
- type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, KeyOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends KeyOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<MergeUnion<TValue>[TFirstKey], TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOfArrayPath<TValue>> extends false ? readonly [...TValidPath, KeyOfArrayPath<TValue>] : never;
153
+ type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, KeyOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends KeyOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOfArrayPath<TValue>> extends false ? readonly [...TValidPath, KeyOfArrayPath<TValue>] : never;
154
154
  /**
155
155
  * Returns the path if valid, otherwise the first possible valid array path based on
156
156
  * the given value.
157
157
  */
158
- type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<TValue, TPath> ? TPath : LazyArrayPath<TValue, TPath>;
158
+ type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
159
159
  //#endregion
160
160
  //#region src/array/copyItemState/copyItemState.d.ts
161
161
  /**
@@ -169,129 +169,21 @@ type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArra
169
169
  */
170
170
  //#endregion
171
171
  //#region ../../packages/methods/dist/index.qwik.d.ts
172
- //#region src/focus/focus.d.ts
173
- interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
174
- readonly form: BaseFormStore<TSchema>;
175
- readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
176
- }
177
- declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(config: FocusFieldConfig<TSchema, TFieldPath>): void;
178
- //#endregion
179
- //#region src/getAllErrors/getAllErrors.d.ts
180
- declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
181
- //#endregion
182
- //#region src/getErrors/getErrors.d.ts
183
- interface GetFormErrorsConfig {
184
- readonly path?: undefined;
185
- }
186
- interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
187
- readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
188
- }
189
- declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
190
- declare function getErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldErrorsConfig<TSchema, TFieldPath> : GetFormErrorsConfig): [string, ...string[]] | null;
191
- //#endregion
192
- //#region src/getInput/getInput.d.ts
193
- interface GetFormInputConfig {
194
- readonly path?: undefined;
195
- }
196
- interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
197
- readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
198
- }
199
- declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>): PartialValues<v.InferInput<TSchema>>;
200
- declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldInputConfig<TSchema, TFieldPath> : GetFormInputConfig): PartialValues<TFieldPath extends RequiredPath ? PathValue<v.InferInput<TSchema>, TFieldPath> : v.InferInput<TSchema>>;
201
- //#endregion
202
- //#region src/handleSubmit/handleSubmit.d.ts
203
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => void;
204
- //#endregion
205
- //#region src/insert/insert.d.ts
206
- interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
207
- readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
208
- readonly at?: number | undefined;
209
- readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
210
- }
211
- declare function insert<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
212
- //#endregion
213
- //#region src/move/move.d.ts
214
- interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
215
- readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
216
- readonly from: number;
217
- readonly to: number;
218
- }
219
- declare function move<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
220
- //#endregion
221
- //#region src/remove/remove.d.ts
222
- interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
223
- readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
224
- readonly at: number;
225
- }
226
- declare function remove<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
227
- //#endregion
228
- //#region src/replace/replace.d.ts
229
- interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
230
- readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
231
- readonly at: number;
232
- readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
233
- }
234
- declare function replace<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
235
- //#endregion
236
- //#region src/reset/reset.d.ts
237
- interface ResetBaseConfig {
238
- readonly keepInput?: boolean | undefined;
239
- readonly keepTouched?: boolean | undefined;
240
- readonly keepErrors?: boolean | undefined;
241
- }
242
- interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
243
- readonly path?: undefined;
244
- readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
245
- readonly keepSubmitCount?: boolean | undefined;
246
- readonly keepSubmitted?: boolean | undefined;
247
- }
248
- interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
249
- readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
250
- readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, TFieldPath>>;
251
- }
252
- declare function reset(form: BaseFormStore): void;
253
- declare function reset<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? ResetFieldConfig<TSchema, TFieldPath> : ResetFormConfig<TSchema>): void;
254
- //#endregion
255
- //#region src/setErrors/setErrors.d.ts
256
- interface SetFormErrorsConfig {
257
- readonly path?: undefined;
258
- readonly errors: [string, ...string[]] | null;
259
- }
260
- interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
261
- readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
262
- readonly errors: [string, ...string[]] | null;
263
- }
264
- declare function setErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
265
- //#endregion
266
- //#region src/setInput/setInput.d.ts
267
- interface SetFormInputConfig<TSchema extends Schema> {
268
- readonly path?: undefined;
269
- readonly input: v.InferInput<TSchema>;
270
- }
271
- interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
272
- readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
273
- readonly input: PathValue<v.InferInput<TSchema>, TFieldPath>;
274
- }
275
- declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>, config: SetFormInputConfig<TSchema>): void;
276
- declare function setInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldInputConfig<TSchema, TFieldPath> : SetFormInputConfig<TSchema>): void;
277
- //#endregion
278
- //#region src/submit/submit.d.ts
279
- declare function submit(form: BaseFormStore): void;
280
- //#endregion
281
- //#region src/swap/swap.d.ts
282
- interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
283
- readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
284
- readonly at: number;
285
- readonly and: number;
286
- }
287
- declare function swap<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
288
- //#endregion
289
- //#region src/validate/validate.d.ts
290
- interface ValidateFormConfig {
291
- readonly shouldFocus?: boolean | undefined;
292
- }
293
- declare function validate<TSchema extends Schema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
294
- //#endregion
172
+ declare function focus(config: any): void;
173
+ declare function getAllErrors(form: any): null;
174
+ declare function getErrors(form: any, config: any): any;
175
+ declare function getInput(form: any, config: any): unknown;
176
+ declare function handleSubmit(form: any, handler: any): (event: any) => Promise<void>;
177
+ declare function insert(form: any, config: any): void;
178
+ declare function move(form: any, config: any): void;
179
+ declare function remove(form: any, config: any): void;
180
+ declare function replace(form: any, config: any): void;
181
+ declare function reset(form: any, config: any): void;
182
+ declare function setErrors(form: any, config: any): void;
183
+ declare function setInput(form: any, config: any): void;
184
+ declare function submit(form: any): void;
185
+ declare function swap(form: any, config: any): void;
186
+ declare function validate(form: any, config: any): Promise<v.SafeParseResult<Schema>>;
295
187
  //#endregion
296
188
  //#region src/types/field.d.ts
297
189
  /**
@@ -353,7 +245,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
353
245
  /**
354
246
  * Headless form field that provides reactive properties and state.
355
247
  */
356
- 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;
248
+ 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;
357
249
  //#endregion
358
250
  //#region src/components/FieldArray/FieldArray.d.ts
359
251
  /**
@@ -367,14 +259,14 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
367
259
  /**
368
260
  * Headless field array that provides reactive properties and state.
369
261
  */
370
- 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;
262
+ 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;
371
263
  //#endregion
372
264
  //#region src/components/Form/Form.d.ts
373
- type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmit$'> & {
265
+ type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmit$' | 'noValidate'> & {
374
266
  of: FormStore<TSchema>;
375
267
  onSubmit$: QRL<SubmitHandler<TSchema>>;
376
268
  };
377
- 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;
269
+ 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;
378
270
  //#endregion
379
271
  //#region src/hooks/useField/useField.d.ts
380
272
  interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
@@ -392,4 +284,4 @@ declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends R
392
284
  declare function useFormQrl<TSchema extends Schema>(configQrl: QRL<FormConfig<TSchema>>): FormStore<TSchema>;
393
285
  declare const useForm$: <TSchema extends Schema>(qrl: FormConfig<TSchema>) => FormStore<TSchema>;
394
286
  //#endregion
395
- export { Field, FieldArray, FieldArrayProps, FieldArrayStore, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, RemoveConfig, ReplaceConfig, ResetFieldConfig, ResetFormConfig, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, ValidateFormConfig, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm$, useFormQrl, validate };
287
+ export { Field, FieldArray, FieldArrayProps, FieldArrayStore, FieldElementProps, FieldProps, FieldStore, Form, FormProps, FormStore, type SubmitHandler, UseFieldArrayConfig, UseFieldConfig, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm$, useFormQrl, validate };
@@ -39,7 +39,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
39
39
  } else for (let index = 0; index < schema.items; index++) {
40
40
  internalFieldStore.children[index] = {};
41
41
  path.push(index);
42
- initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput && initialInput[index], path);
42
+ initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
43
43
  path.pop();
44
44
  }
45
45
  const initialItems = internalFieldStore.children.map(createId);
@@ -57,7 +57,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
57
57
  for (const key in schema.entries) {
58
58
  internalFieldStore.children[key] = {};
59
59
  path.push(key);
60
- initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput && initialInput[key], path);
60
+ initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
61
61
  path.pop();
62
62
  }
63
63
  }
@@ -277,25 +277,27 @@ function setFieldBool(internalFieldStore, type, bool) {
277
277
  function setFieldInput(internalFieldStore, input) {
278
278
  batch(() => {
279
279
  if (internalFieldStore.kind === "array") {
280
+ const arrayInput = input ?? [];
280
281
  const items = untrack(() => internalFieldStore.items.value);
281
- if (input.length < items.length) internalFieldStore.items.value = items.slice(0, input.length);
282
- else if (input.length > items.length) {
283
- if (input.length > internalFieldStore.children.length) {
282
+ if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
283
+ else if (arrayInput.length > items.length) {
284
+ if (arrayInput.length > internalFieldStore.children.length) {
284
285
  const path = JSON.parse(internalFieldStore.name);
285
- for (let index = internalFieldStore.children.length; index < input.length; index++) {
286
+ for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
286
287
  internalFieldStore.children[index] = {};
287
288
  path.push(index);
288
- initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, input[index], path);
289
+ initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
289
290
  path.pop();
290
291
  }
291
292
  }
292
- internalFieldStore.items.value = [...items, ...input.slice(items.length).map(createId)];
293
+ internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createId)];
293
294
  }
294
- for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], input[index]);
295
+ for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
295
296
  internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
296
- } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
297
+ } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
297
298
  else {
298
299
  internalFieldStore.input.value = input;
300
+ internalFieldStore.isTouched.value = true;
299
301
  const startInput = untrack(() => internalFieldStore.startInput.value);
300
302
  internalFieldStore.isDirty.value = startInput !== input && (startInput !== void 0 || input !== "" && !Number.isNaN(input));
301
303
  }
@@ -304,17 +306,18 @@ function setFieldInput(internalFieldStore, input) {
304
306
  function setInitialFieldInput(internalFieldStore, initialInput) {
305
307
  batch(() => {
306
308
  if (internalFieldStore.kind === "array") {
307
- if (initialInput.length > internalFieldStore.children.length) {
309
+ const initialArrayInput = initialInput ?? [];
310
+ if (initialArrayInput.length > internalFieldStore.children.length) {
308
311
  const path = JSON.parse(internalFieldStore.name);
309
- for (let index = internalFieldStore.children.length; index < initialInput.length; index++) {
312
+ for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
310
313
  internalFieldStore.children[index] = {};
311
314
  path.push(index);
312
- initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialInput[index], path);
315
+ initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
313
316
  path.pop();
314
317
  }
315
318
  }
316
- internalFieldStore.initialItems.value = initialInput.map(createId);
317
- for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialInput?.[index]);
319
+ internalFieldStore.initialItems.value = initialArrayInput.map(createId);
320
+ for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
318
321
  } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
319
322
  else internalFieldStore.initialInput.value = initialInput;
320
323
  });
@@ -521,7 +524,6 @@ function setInput(form, config) {
521
524
  batch(() => {
522
525
  const internalFormStore = form[INTERNAL];
523
526
  const internalFieldStore = config.path ? getFieldStore(internalFormStore, config.path) : internalFormStore;
524
- setFieldBool(internalFieldStore, "isTouched", true);
525
527
  setFieldInput(internalFieldStore, config.input);
526
528
  validateIfRequired(internalFormStore, internalFieldStore, "input");
527
529
  });
@@ -667,8 +669,7 @@ const useForm$ = implicit$FirstArg(useFormQrl);
667
669
  */
668
670
  const Field = component$(({ of, path, render$ }) => {
669
671
  const field = useField(of, { path });
670
- const render = useResolvedQrl(render$);
671
- return render(field);
672
+ return useResolvedQrl(render$)(field);
672
673
  });
673
674
 
674
675
  //#endregion
@@ -678,8 +679,7 @@ const Field = component$(({ of, path, render$ }) => {
678
679
  */
679
680
  const FieldArray = component$(({ of, path, render$ }) => {
680
681
  const field = useFieldArray(of, { path });
681
- const render = useResolvedQrl(render$);
682
- return render(field);
682
+ return useResolvedQrl(render$)(field);
683
683
  });
684
684
 
685
685
  //#endregion
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.2.0",
4
+ "version": "0.3.1",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -35,18 +35,8 @@
35
35
  "engines": {
36
36
  "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
37
37
  },
38
- "scripts": {
39
- "build": "tsdown",
40
- "lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
41
- "lint.fix": "eslint \"src/**/*.ts*\" --fix",
42
- "format": "prettier --write ./src",
43
- "format.check": "prettier --check ./src",
44
- "qwik": "qwik"
45
- },
46
38
  "devDependencies": {
47
39
  "@eslint/js": "^9.31.0",
48
- "@formisch/core": "workspace:*",
49
- "@formisch/methods": "workspace:*",
50
40
  "@qwik.dev/core": "2.0.0-beta.5",
51
41
  "@types/node": "24.0.13",
52
42
  "eslint": "9.31.0",
@@ -58,7 +48,9 @@
58
48
  "typescript-eslint": "8.36.0",
59
49
  "valibot": "^1.1.0",
60
50
  "vite": "7.0.4",
61
- "vite-tsconfig-paths": "^5.1.4"
51
+ "vite-tsconfig-paths": "^5.1.4",
52
+ "@formisch/core": "0.3.1",
53
+ "@formisch/methods": "0.2.0"
62
54
  },
63
55
  "peerDependencies": {
64
56
  "@qwik.dev/core": ">=2",
@@ -69,5 +61,13 @@
69
61
  "typescript": {
70
62
  "optional": true
71
63
  }
64
+ },
65
+ "scripts": {
66
+ "build": "tsdown",
67
+ "lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
68
+ "lint.fix": "eslint \"src/**/*.ts*\" --fix",
69
+ "format": "prettier --write ./src",
70
+ "format.check": "prettier --check ./src",
71
+ "qwik": "qwik"
72
72
  }
73
- }
73
+ }