@formisch/qwik 0.3.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,7 +2,7 @@
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], and [Vue][formisch-vue]. Svelte will follow soon.
5
+ Formisch is also available for [Preact][formisch-preact], [SolidJS][formisch-solid], [Svelte][formisch-svelte] and [Vue][formisch-vue].
6
6
 
7
7
  ## Highlights
8
8
 
@@ -82,4 +82,5 @@ This project is available free of charge and licensed under the [MIT license](ht
82
82
 
83
83
  [formisch-preact]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/preact
84
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
85
86
  [formisch-vue]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/vue
package/dist/index.d.ts CHANGED
@@ -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
  /**
@@ -370,7 +262,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
370
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
  };
@@ -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,23 +277,24 @@ 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;
299
300
  internalFieldStore.isTouched.value = true;
@@ -305,17 +306,18 @@ function setFieldInput(internalFieldStore, input) {
305
306
  function setInitialFieldInput(internalFieldStore, initialInput) {
306
307
  batch(() => {
307
308
  if (internalFieldStore.kind === "array") {
308
- if (initialInput.length > internalFieldStore.children.length) {
309
+ const initialArrayInput = initialInput ?? [];
310
+ if (initialArrayInput.length > internalFieldStore.children.length) {
309
311
  const path = JSON.parse(internalFieldStore.name);
310
- for (let index = internalFieldStore.children.length; index < initialInput.length; index++) {
312
+ for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
311
313
  internalFieldStore.children[index] = {};
312
314
  path.push(index);
313
- initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialInput[index], path);
315
+ initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
314
316
  path.pop();
315
317
  }
316
318
  }
317
- internalFieldStore.initialItems.value = initialInput.map(createId);
318
- 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]);
319
321
  } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
320
322
  else internalFieldStore.initialInput.value = initialInput;
321
323
  });
@@ -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.3.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
+ }