@modular-forms/solid
Advanced tools
Comparing version 0.20.0 to 0.21.0
@@ -0,1 +1,2 @@ | ||
import { safeParseAsync, } from 'valibot'; | ||
/** | ||
@@ -10,5 +11,7 @@ * Creates a validation functions that parses the Valibot schema of a field. | ||
return async (value) => { | ||
const result = await schema._parse(value, { abortPipeEarly: true }); | ||
const result = await safeParseAsync(schema, value, { | ||
abortPipeEarly: true, | ||
}); | ||
return result.issues?.[0]?.message || ''; | ||
}; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { getDotPath, safeParseAsync, } from 'valibot'; | ||
/** | ||
@@ -10,10 +11,13 @@ * Creates a validation functions that parses the Valibot schema of a form. | ||
return async (values) => { | ||
const result = await schema._parse(values, { abortPipeEarly: true }); | ||
return result.issues | ||
? result.issues.reduce((errors, issue) => ({ | ||
...errors, | ||
[issue.path.map(({ key }) => key).join('.')]: issue.message, | ||
}), {}) | ||
: {}; | ||
const result = await safeParseAsync(schema, values, { | ||
abortPipeEarly: true, | ||
}); | ||
const formErrors = {}; | ||
if (result.issues) { | ||
for (const issue of result.issues) { | ||
formErrors[getDotPath(issue)] = issue.message; | ||
} | ||
} | ||
return formErrors; | ||
}; | ||
} |
@@ -11,12 +11,13 @@ /** | ||
const result = schema.safeParse(values); | ||
return result.success | ||
? {} | ||
: result.error.issues.reduce((errors, error) => { | ||
const path = error.path.join('.'); | ||
if (!errors[path]) { | ||
errors[path] = error.message; | ||
const formErrors = {}; | ||
if (!result.success) { | ||
for (const issue of result.error.issues) { | ||
const path = issue.path.join('.'); | ||
if (!formErrors[path]) { | ||
formErrors[path] = issue.message; | ||
} | ||
return errors; | ||
}, {}); | ||
} | ||
} | ||
return formErrors; | ||
}; | ||
} |
import { initializeFieldStore } from '../utils'; | ||
/** | ||
* Returns the value of the specified field. | ||
* | ||
* @param form The form of the field. | ||
* @param name The name of the field. | ||
* @param options The value options. | ||
* | ||
* @returns The value of the field. | ||
*/ | ||
export function getValue(form, name, { shouldActive = true, shouldTouched = false, shouldDirty = false, shouldValid = false, } = {}) { | ||
@@ -12,0 +3,0 @@ // Get store of specified field |
import { batch } from 'solid-js'; | ||
import { initializeFieldStore, updateFieldDirty, validateIfRequired, } from '../utils'; | ||
/** | ||
* Sets the value of the specified field. | ||
* | ||
* @param form The form of the field. | ||
* @param name The name of the field. | ||
* @param value The value to bet set. | ||
* @param options The value options. | ||
*/ | ||
export function setValue(form, name, value, { shouldTouched = true, shouldDirty = true, shouldValidate = true, shouldFocus = true, } = {}) { | ||
@@ -12,0 +4,0 @@ batch(() => { |
import { mergeProps } from 'solid-js'; | ||
import { Form, Field, FieldArray } from '../components'; | ||
import { createFormStore } from './createFormStore'; | ||
/** | ||
* Creates and returns the store of the form as well as a linked Form, Field | ||
* and FieldArray component. | ||
* | ||
* @param options The form options. | ||
* | ||
* @returns The store and linked components. | ||
*/ | ||
export function createForm(options) { | ||
@@ -13,0 +5,0 @@ // Create form store |
import { batch, createEffect, onCleanup, untrack } from 'solid-js'; | ||
import { reset } from '../methods'; | ||
import { getUniqueId, updateFormState } from '../utils'; | ||
/** | ||
* Handles the lifecycle dependent state of a field or field array. | ||
* | ||
* @param props The lifecycle properties. | ||
*/ | ||
export function createLifecycle({ of: form, name, getStore, validate, transform, keepActive = false, keepState = true, }) { | ||
@@ -10,0 +5,0 @@ createEffect(() => { |
import { batch } from 'solid-js'; | ||
import { updateFieldDirty } from './updateFieldDirty'; | ||
import { validateIfRequired } from './validateIfRequired'; | ||
/** | ||
* Handles the input, change and blur event of a field. | ||
* | ||
* @param form The form of the field. | ||
* @param field The store of the field. | ||
* @param name The name of the field. | ||
* @param event The event of the field. | ||
* @param validationModes The modes of the validation. | ||
* @param inputValue The value of the input. | ||
*/ | ||
export function handleFieldEvent(form, field, name, event, validationModes, inputValue) { | ||
@@ -15,0 +5,0 @@ batch(() => { |
import { createSignal } from '../primitives'; | ||
import { getFieldStore } from './getFieldStore'; | ||
import { getPathValue } from './getPathValue'; | ||
/** | ||
* Initializes and returns the store of a field. | ||
* | ||
* @param form The form of the field. | ||
* @param name The name of the field. | ||
* | ||
* @returns The reactive store. | ||
*/ | ||
export function initializeFieldStore(form, name) { | ||
@@ -27,2 +19,3 @@ // Initialize store on first request | ||
// Add store of field to form | ||
// @ts-expect-error | ||
form.internal.fields[name] = { | ||
@@ -29,0 +22,0 @@ // Signals |
@@ -1,2 +0,2 @@ | ||
import type { BaseSchema, BaseSchemaAsync } from 'valibot'; | ||
import { type GenericSchema, type GenericSchemaAsync } from 'valibot'; | ||
import type { FieldValue, ValidateField } from '../types'; | ||
@@ -10,2 +10,2 @@ /** | ||
*/ | ||
export declare function valiField<TFieldValue extends FieldValue>(schema: BaseSchema<TFieldValue, any> | BaseSchemaAsync<TFieldValue, any>): ValidateField<TFieldValue>; | ||
export declare function valiField<TFieldValue extends FieldValue>(schema: GenericSchema | GenericSchemaAsync): ValidateField<TFieldValue>; |
@@ -1,2 +0,2 @@ | ||
import type { BaseSchema, BaseSchemaAsync } from 'valibot'; | ||
import { type GenericSchema, type GenericSchemaAsync } from 'valibot'; | ||
import type { FieldValues, ValidateForm } from '../types'; | ||
@@ -10,2 +10,2 @@ /** | ||
*/ | ||
export declare function valiForm<TFieldValues extends FieldValues>(schema: BaseSchema<TFieldValues, any> | BaseSchemaAsync<TFieldValues, any>): ValidateForm<TFieldValues>; | ||
export declare function valiForm<TFieldValues extends FieldValues>(schema: GenericSchema | GenericSchemaAsync): ValidateForm<TFieldValues>; |
@@ -20,2 +20,2 @@ import type { FieldPath, FieldPathValue, FieldValues, FormStore, Maybe, ResponseData } from '../types'; | ||
*/ | ||
export declare function getValue<TFieldValues extends FieldValues, TResponseData extends ResponseData, TFieldName extends FieldPath<TFieldValues>>(form: FormStore<TFieldValues, TResponseData>, name: TFieldName, { shouldActive, shouldTouched, shouldDirty, shouldValid, }?: Maybe<GetValueOptions>): Maybe<FieldPathValue<TFieldValues, TFieldName>>; | ||
export declare function getValue<TFieldValues extends FieldValues, TResponseData extends ResponseData, TFieldName extends FieldPath<TFieldValues>>(form: FormStore<TFieldValues, TResponseData>, name: TFieldName, options?: Maybe<GetValueOptions>): Maybe<FieldPathValue<TFieldValues, TFieldName>>; |
@@ -20,3 +20,3 @@ import type { FieldValues, FieldPath, FieldPathValue, ResponseData, FormStore, Maybe, FieldArrayPath, PartialValues } from '../types'; | ||
/** | ||
* Resets the entire form, several fields and field arrays or a singel field or | ||
* Resets the entire form, several fields and field arrays or a single field or | ||
* field array. | ||
@@ -29,3 +29,3 @@ * | ||
/** | ||
* Resets the entire form, several fields and field arrays or a singel field or | ||
* Resets the entire form, several fields and field arrays or a single field or | ||
* field array. | ||
@@ -39,3 +39,3 @@ * | ||
/** | ||
* Resets the entire form, several fields and field arrays or a singel field or | ||
* Resets the entire form, several fields and field arrays or a single field or | ||
* field array. | ||
@@ -42,0 +42,0 @@ * |
@@ -19,2 +19,2 @@ import type { FieldPath, FieldPathValue, FieldValues, FormStore, Maybe, ResponseData } from '../types'; | ||
*/ | ||
export declare function setValue<TFieldValues extends FieldValues, TResponseData extends ResponseData, TFieldName extends FieldPath<TFieldValues>>(form: FormStore<TFieldValues, TResponseData>, name: TFieldName, value: FieldPathValue<TFieldValues, TFieldName>, { shouldTouched, shouldDirty, shouldValidate, shouldFocus, }?: Maybe<SetValueOptions>): void; | ||
export declare function setValue<TFieldValues extends FieldValues, TResponseData extends ResponseData, TFieldName extends FieldPath<TFieldValues>>(form: FormStore<TFieldValues, TResponseData>, name: TFieldName, value: FieldPathValue<TFieldValues, TFieldName>, options?: Maybe<SetValueOptions>): void; |
@@ -19,3 +19,3 @@ import type { FieldArrayPath, FieldPath, FieldPathValue, FieldValues, FormStore, InternalFieldArrayStore, InternalFieldStore, Maybe, MaybeArray, ResponseData, TransformField, ValidateField, ValidateFieldArray } from '../types'; | ||
*/ | ||
export declare function createLifecycle<TFieldValues extends FieldValues, TResponseData extends ResponseData, TFieldName extends FieldPath<TFieldValues>>({ of: form, name, getStore, validate, transform, keepActive, keepState, }: LifecycleProps<TFieldValues, TResponseData, TFieldName>): void; | ||
export declare function createLifecycle<TFieldValues extends FieldValues, TResponseData extends ResponseData, TFieldName extends FieldPath<TFieldValues>>(props: LifecycleProps<TFieldValues, TResponseData, TFieldName>): void; | ||
export {}; |
{ | ||
"name": "@modular-forms/solid", | ||
"description": "The modular and type-safe form library for SolidJS", | ||
"version": "0.20.0", | ||
"version": "0.21.0", | ||
"license": "MIT", | ||
@@ -49,24 +49,27 @@ "author": "Fabian Hiller", | ||
}, | ||
"scripts": { | ||
"build": "rollup -c ./rollup.config.js", | ||
"format": "prettier --write .", | ||
"format.check": "prettier --check .", | ||
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit", | ||
"publish": "npm publish" | ||
}, | ||
"dependencies": { | ||
"valibot": ">=0.31.0 <1" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "^8.44.0", | ||
"@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"@typescript-eslint/parser": "^5.62.0", | ||
"eslint": "^8.44.0", | ||
"eslint-plugin-solid": "^0.12.1", | ||
"rollup": "3.20.2", | ||
"@types/eslint": "^8.56.10", | ||
"@typescript-eslint/eslint-plugin": "^7.12.0", | ||
"@typescript-eslint/parser": "^7.12.0", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-solid": "^0.14.0", | ||
"rollup": "4.18.0", | ||
"rollup-preset-solid": "^2.0.1", | ||
"solid-js": "^1.7.8", | ||
"typescript": "4.9.5", | ||
"valibot": "^0.13.1", | ||
"zod": "^3.21.4" | ||
"solid-js": "^1.8.17", | ||
"typescript": "5.4.5", | ||
"zod": "^3.23.8" | ||
}, | ||
"peerDependencies": { | ||
"solid-js": "^1.3.1" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c ./rollup.config.js", | ||
"format": "prettier --write .", | ||
"format.check": "prettier --check .", | ||
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
10
720070
2
198
8650
+ Addedvalibot@>=0.31.0 <1
+ Addedvalibot@0.42.1(transitive)