New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More →

@modular-forms/preact

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@modular-forms/preact - npm Package Compare versions

Comparing version

to
0.10.0

@@ -9,6 +9,6 @@ /**

export function zodField(schema) {
return (value) => {
const result = schema.safeParse(value);
return async (value) => {
const result = await schema.safeParseAsync(value);
return result.success ? '' : result.error.issues[0].message;
};
}

@@ -9,4 +9,4 @@ /**

export function zodForm(schema) {
return (values) => {
const result = schema.safeParse(values);
return async (values) => {
const result = await schema.safeParseAsync(values);
const formErrors = {};

@@ -13,0 +13,0 @@ if (!result.success) {

@@ -34,3 +34,3 @@ import { jsx as _jsx } from "preact/jsx-runtime";

if (await validate(form, options)) {
await onSubmit(getValues(form, options), event);
await onSubmit?.(getValues(form, options), event);
}

@@ -37,0 +37,0 @@ // If an error occurred, set error to fields and response

@@ -5,3 +5,3 @@ import { batch } from '@preact/signals';

import { getUniqueId, updateFormState } from '../utils';
export function useLifecycle({ of: form, name, store, validate, transform, keepActive = false, keepState = true, }) {
export function useLifecycle({ of: form, name, store, validate, validateOn, revalidateOn, transform, keepActive = false, keepState = true, }) {
useEffect(() => {

@@ -14,2 +14,5 @@ // Add validation functions

: [];
// Set validation mode overrides
store.validateOn = validateOn;
store.revalidateOn = revalidateOn;
// Add transformation functions

@@ -23,3 +26,3 @@ if ('transform' in store) {

}
}, [store, transform, validate]);
}, [store, transform, validate, validateOn, revalidateOn]);
useEffect(() => {

@@ -26,0 +29,0 @@ // Create unique consumer ID

@@ -30,2 +30,4 @@ import { signal } from '@preact/signals';

validate: [],
validateOn: undefined,
revalidateOn: undefined,
consumers: new Set(),

@@ -32,0 +34,0 @@ };

@@ -23,2 +23,4 @@ import { signal } from '@preact/signals';

validate: [],
validateOn: undefined,
revalidateOn: undefined,
transform: [],

@@ -25,0 +27,0 @@ consumers: new Set(),

@@ -11,9 +11,11 @@ import { validate } from '../methods';

export function validateIfRequired(form, fieldOrFieldArray, name, { on: modes, shouldFocus = false }) {
if (modes.includes((form.internal.validateOn === 'submit'
const validateOn = fieldOrFieldArray.validateOn ?? form.internal.validateOn;
const revalidateOn = fieldOrFieldArray.revalidateOn ?? form.internal.revalidateOn;
if (modes.includes((validateOn === 'submit'
? form.submitted.peek()
: fieldOrFieldArray.error.peek())
? form.internal.revalidateOn
: form.internal.validateOn)) {
? revalidateOn
: validateOn)) {
validate(form, name, { shouldFocus });
}
}
import { type ReadonlySignal } from '@preact/signals';
import type { ComponentChild, RefCallback } from 'preact';
import type { JSX } from 'preact/jsx-runtime';
import type { FieldElement, FieldPath, FieldPathValue, FieldType, FieldValues, FormStore, Maybe, MaybeArray, MaybeValue, PartialKey, ResponseData, TransformField, ValidateField } from '../types';
import type { FieldElement, FieldPath, FieldPathValue, FieldType, FieldValues, FormStore, Maybe, MaybeArray, MaybeValue, PartialKey, ResponseData, TransformField, ValidateField, ValidationMode } from '../types';
/**

@@ -35,2 +35,4 @@ * Value type ot the field store.

validate?: Maybe<MaybeArray<ValidateField<FieldPathValue<TFieldValues, TFieldName>>>>;
validateOn?: Maybe<ValidationMode>;
revalidateOn?: Maybe<ValidationMode>;
transform?: Maybe<MaybeArray<TransformField<FieldPathValue<TFieldValues, TFieldName>>>>;

@@ -37,0 +39,0 @@ keepActive?: boolean;

import type { ReadonlySignal } from '@preact/signals';
import type { ComponentChild } from 'preact';
import type { JSX } from 'preact/jsx-runtime';
import type { FieldArrayPath, FieldValues, FormStore, Maybe, MaybeArray, ResponseData, ValidateFieldArray } from '../types';
import type { FieldArrayPath, FieldValues, FormStore, Maybe, MaybeArray, ResponseData, ValidateFieldArray, ValidationMode } from '../types';
/**

@@ -24,2 +24,4 @@ * Value type ot the field store.

validate?: Maybe<MaybeArray<ValidateFieldArray<number[]>>>;
validateOn?: Maybe<ValidationMode>;
revalidateOn?: Maybe<ValidationMode>;
keepActive?: Maybe<boolean>;

@@ -26,0 +28,0 @@ keepState?: Maybe<boolean>;

@@ -22,3 +22,3 @@ import type { ComponentChildren } from 'preact';

of: FormStore<TFieldValues, TResponseData>;
onSubmit: SubmitHandler<TFieldValues>;
onSubmit?: Maybe<SubmitHandler<TFieldValues>>;
responseDuration?: Maybe<number>;

@@ -25,0 +25,0 @@ keepResponse?: Maybe<boolean>;

@@ -1,2 +0,2 @@

import type { FieldArrayPath, FieldPath, FieldPathValue, FieldValues, FormStore, InternalFieldArrayStore, InternalFieldStore, Maybe, MaybeArray, ResponseData, TransformField, ValidateField, ValidateFieldArray } from '../types';
import type { FieldArrayPath, FieldPath, FieldPathValue, FieldValues, FormStore, InternalFieldArrayStore, InternalFieldStore, Maybe, MaybeArray, ResponseData, TransformField, ValidateField, ValidateFieldArray, ValidationMode } from '../types';
/**

@@ -10,2 +10,4 @@ * Value type of the lifecycle properties.

validate?: Maybe<MaybeArray<ValidateField<FieldPathValue<TFieldValues, TFieldName>>> | MaybeArray<ValidateFieldArray<number[]>>>;
validateOn?: Maybe<ValidationMode>;
revalidateOn?: Maybe<ValidationMode>;
transform?: Maybe<MaybeArray<TransformField<FieldPathValue<TFieldValues, TFieldName>>>>;

@@ -12,0 +14,0 @@ keepActive?: Maybe<boolean>;

import type { Signal } from '@preact/signals';
import type { FieldPath, FieldPathValue } from './path';
import type { MaybeValue, MaybePromise, Maybe } from './utils';
import type { ValidationMode } from './form';
/**

@@ -54,2 +55,4 @@ * Value type of the field value.

validate: ValidateField<FieldPathValue<TFieldValues, TFieldName>>[];
validateOn: Maybe<ValidationMode>;
revalidateOn: Maybe<ValidationMode>;
transform: TransformField<FieldPathValue<TFieldValues, TFieldName>>[];

@@ -56,0 +59,0 @@ consumers: Set<number>;

import type { Signal } from '@preact/signals';
import type { MaybePromise } from './utils';
import type { Maybe, MaybePromise } from './utils';
import type { ValidationMode } from './form';
/**

@@ -24,2 +25,4 @@ * Function type to validate a field array.

validate: ValidateFieldArray<number[]>[];
validateOn: Maybe<ValidationMode>;
revalidateOn: Maybe<ValidationMode>;
consumers: Set<number>;

@@ -26,0 +29,0 @@ };

{
"name": "@modular-forms/preact",
"description": "The modular and type-safe form library for Preact",
"version": "0.9.1",
"version": "0.10.0",
"license": "MIT",

@@ -47,4 +47,3 @@ "author": "Fabian Hiller",

"format.check": "prettier --check \"./src\"",
"lint": "eslint \"./src/**/*.ts*\" && tsc --noEmit",
"publish": "npm publish"
"lint": "eslint \"./src/**/*.ts*\" && tsc --noEmit"
},

@@ -55,12 +54,12 @@ "dependencies": {

"devDependencies": {
"@preact/preset-vite": "^2.8.2",
"@preact/signals": "^1.2.3",
"@types/eslint": "^8.56.10",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"@preact/preset-vite": "^2.9.0",
"@preact/signals": "^1.3.0",
"@types/eslint": "^8.56.12",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "8.57.0",
"eslint-config-preact": "^1.4.0",
"preact": "^10.22.0",
"typescript": "5.4.5",
"vite": "^5.2.12",
"preact": "^10.23.2",
"typescript": "^5.5.4",
"vite": "^5.4.2",
"zod": "^3.23.8"

@@ -67,0 +66,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet