@formisch/solid 0.7.5 → 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/dev.js CHANGED
@@ -43,7 +43,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
43
43
  initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
44
44
  path.pop();
45
45
  }
46
- } else for (let index = 0; index < schema.items; index++) {
46
+ } else for (let index = 0; index < schema.items.length; index++) {
47
47
  internalFieldStore.children[index] = {};
48
48
  path.push(index);
49
49
  initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
@@ -277,7 +277,7 @@ function setNestedInput(internalFieldStore, input) {
277
277
  }
278
278
  for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
279
279
  internalFieldStore.input.value = input == null ? input : true;
280
- internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
280
+ internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
281
281
  } else if (internalFieldStore.kind === "object") {
282
282
  for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
283
283
  internalFieldStore.input.value = input == null ? input : true;
@@ -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;
@@ -652,6 +652,14 @@ function useField(form, config) {
652
652
  get isValid() {
653
653
  return getIsValid();
654
654
  },
655
+ onInput(value) {
656
+ setFieldInput(getInternalFormStore(), getPath(), value);
657
+ validateIfRequired(
658
+ getInternalFormStore(),
659
+ getInternalFieldStore(),
660
+ "input"
661
+ );
662
+ },
655
663
  props: {
656
664
  get name() {
657
665
  return getInternalFieldStore().name;
package/dist/dev.jsx CHANGED
@@ -41,7 +41,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
41
41
  initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
42
42
  path.pop();
43
43
  }
44
- } else for (let index = 0; index < schema.items; index++) {
44
+ } else for (let index = 0; index < schema.items.length; index++) {
45
45
  internalFieldStore.children[index] = {};
46
46
  path.push(index);
47
47
  initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
@@ -275,7 +275,7 @@ function setNestedInput(internalFieldStore, input) {
275
275
  }
276
276
  for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
277
277
  internalFieldStore.input.value = input == null ? input : true;
278
- internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
278
+ internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
279
279
  } else if (internalFieldStore.kind === "object") {
280
280
  for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
281
281
  internalFieldStore.input.value = input == null ? input : true;
@@ -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;
@@ -657,6 +657,14 @@ function useField(form, config) {
657
657
  get isValid() {
658
658
  return getIsValid();
659
659
  },
660
+ onInput(value) {
661
+ setFieldInput(getInternalFormStore(), getPath(), value);
662
+ validateIfRequired(
663
+ getInternalFormStore(),
664
+ getInternalFieldStore(),
665
+ "input"
666
+ );
667
+ },
660
668
  props: {
661
669
  get name() {
662
670
  return getInternalFieldStore().name;
package/dist/index.d.ts CHANGED
@@ -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
  /**
@@ -860,6 +875,10 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
860
875
  */
861
876
  readonly isValid: boolean;
862
877
  /**
878
+ * Sets the field input value programmatically.
879
+ */
880
+ readonly onInput: (value: PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>) => void;
881
+ /**
863
882
  * The props to spread onto the field element for integration.
864
883
  */
865
884
  readonly props: FieldElementProps;
@@ -1012,7 +1031,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<JSX.FormHTMLAttributes<HT
1012
1031
  /**
1013
1032
  * The submit handler called when the form is submitted and validation succeeds.
1014
1033
  */
1015
- readonly onSubmit: SubmitHandler<TSchema>;
1034
+ readonly onSubmit: SubmitHandler<TSchema> | SubmitEventHandler<TSchema>;
1016
1035
  };
1017
1036
  /**
1018
1037
  * Form component that manages form submission and applies internal state.
@@ -1075,4 +1094,4 @@ interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArrayPath e
1075
1094
  */
1076
1095
  declare function useFieldArray<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: MaybeGetter<FormStore<TSchema>>, config: MaybeGetter<UseFieldArrayConfig<TSchema, TFieldArrayPath>>): FieldArrayStore<TSchema, TFieldArrayPath>;
1077
1096
  //#endregion
1078
- 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
@@ -43,7 +43,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
43
43
  initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
44
44
  path.pop();
45
45
  }
46
- } else for (let index = 0; index < schema.items; index++) {
46
+ } else for (let index = 0; index < schema.items.length; index++) {
47
47
  internalFieldStore.children[index] = {};
48
48
  path.push(index);
49
49
  initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
@@ -277,7 +277,7 @@ function setNestedInput(internalFieldStore, input) {
277
277
  }
278
278
  for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
279
279
  internalFieldStore.input.value = input == null ? input : true;
280
- internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
280
+ internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
281
281
  } else if (internalFieldStore.kind === "object") {
282
282
  for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
283
283
  internalFieldStore.input.value = input == null ? input : true;
@@ -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;
@@ -652,6 +652,14 @@ function useField(form, config) {
652
652
  get isValid() {
653
653
  return getIsValid();
654
654
  },
655
+ onInput(value) {
656
+ setFieldInput(getInternalFormStore(), getPath(), value);
657
+ validateIfRequired(
658
+ getInternalFormStore(),
659
+ getInternalFieldStore(),
660
+ "input"
661
+ );
662
+ },
655
663
  props: {
656
664
  get name() {
657
665
  return getInternalFieldStore().name;
package/dist/index.jsx CHANGED
@@ -41,7 +41,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path, nu
41
41
  initializeFieldStore(internalFieldStore.children[index], schema.item, initialInput[index], path);
42
42
  path.pop();
43
43
  }
44
- } else for (let index = 0; index < schema.items; index++) {
44
+ } else for (let index = 0; index < schema.items.length; index++) {
45
45
  internalFieldStore.children[index] = {};
46
46
  path.push(index);
47
47
  initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
@@ -275,7 +275,7 @@ function setNestedInput(internalFieldStore, input) {
275
275
  }
276
276
  for (let index = 0; index < arrayInput.length; index++) setNestedInput(internalFieldStore.children[index], arrayInput[index]);
277
277
  internalFieldStore.input.value = input == null ? input : true;
278
- internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== items.length;
278
+ internalFieldStore.isDirty.value = internalFieldStore.startInput.value !== internalFieldStore.input.value || internalFieldStore.startItems.value.length !== internalFieldStore.items.value.length;
279
279
  } else if (internalFieldStore.kind === "object") {
280
280
  for (const key in internalFieldStore.children) setNestedInput(internalFieldStore.children[key], input?.[key]);
281
281
  internalFieldStore.input.value = input == null ? input : true;
@@ -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;
@@ -657,6 +657,14 @@ function useField(form, config) {
657
657
  get isValid() {
658
658
  return getIsValid();
659
659
  },
660
+ onInput(value) {
661
+ setFieldInput(getInternalFormStore(), getPath(), value);
662
+ validateIfRequired(
663
+ getInternalFormStore(),
664
+ getInternalFieldStore(),
665
+ "input"
666
+ );
667
+ },
660
668
  props: {
661
669
  get name() {
662
670
  return getInternalFieldStore().name;
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.7.5",
4
+ "version": "0.9.0",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -44,12 +44,8 @@
44
44
  "access": "public"
45
45
  },
46
46
  "devDependencies": {
47
- "@eslint/js": "^9.31.0",
48
47
  "@vitest/coverage-v8": "^3.2.4",
49
48
  "eslint": "^9.31.0",
50
- "eslint-plugin-import": "^2.32.0",
51
- "eslint-plugin-jsdoc": "^51.3.4",
52
- "eslint-plugin-security": "^3.0.1",
53
49
  "eslint-plugin-solid": "^0.14.5",
54
50
  "jsdom": "^26.1.0",
55
51
  "rollup": "^4.45.0",
@@ -59,11 +55,11 @@
59
55
  "tsup": "^8.5.0",
60
56
  "tsup-preset-solid": "^2.2.0",
61
57
  "typescript": "^5.8.3",
62
- "typescript-eslint": "^8.36.0",
63
58
  "valibot": "^1.2.0",
64
59
  "vitest": "3.2.4",
65
- "@formisch/core": "0.4.5",
66
- "@formisch/methods": "0.5.2"
60
+ "@formisch/eslint-config": "0.1.0",
61
+ "@formisch/methods": "0.7.0",
62
+ "@formisch/core": "0.6.0"
67
63
  },
68
64
  "peerDependencies": {
69
65
  "solid-js": "^1.6.0",
@@ -78,7 +74,6 @@
78
74
  "browser": {},
79
75
  "typesVersions": {},
80
76
  "scripts": {
81
- "test": "vitest --typecheck",
82
77
  "lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
83
78
  "lint.fix": "eslint \"src/**/*.ts*\" --fix",
84
79
  "format": "prettier --write ./src",