Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@conform-to/react

Package Overview
Dependencies
Maintainers
0
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conform-to/react - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

246

context.d.ts

@@ -1,200 +0,72 @@

import {
type Constraint,
type Combine,
type FormId,
type FieldName,
type FormContext as BaseFormContext,
type FormValue,
type FormState,
type Intent,
type SubscriptionScope,
type SubscriptionSubject,
type FormOptions as BaseFormOptions,
} from '@conform-to/dom';
import {
type FormEvent,
type ReactElement,
type ReactNode,
type MutableRefObject,
} from 'react';
import { type Constraint, type Combine, type FormId, type FieldName, type FormContext as BaseFormContext, type FormValue, type FormState, type Intent, type SubscriptionScope, type SubscriptionSubject, type FormOptions as BaseFormOptions } from '@conform-to/dom';
import { type FormEvent, type ReactElement, type ReactNode, type MutableRefObject } from 'react';
export type Pretty<T> = {
[K in keyof T]: T[K];
[K in keyof T]: T[K];
} & {};
export type Primitive =
| string
| number
| bigint
| boolean
| Date
| File
| null
| undefined;
export type Metadata<
Schema,
FormSchema extends Record<string, unknown>,
FormError = string[],
> = {
key: string | undefined;
id: string;
errorId: string;
descriptionId: string;
name: FieldName<Schema, FormSchema, FormError>;
initialValue: FormValue<Schema>;
value: FormValue<Schema>;
errors: FormError | undefined;
allErrors: Record<string, FormError>;
valid: boolean;
dirty: boolean;
export type Primitive = string | number | bigint | boolean | Date | File | null | undefined;
export type Metadata<Schema, FormSchema extends Record<string, unknown>, FormError = string[]> = {
key: string | undefined;
id: string;
errorId: string;
descriptionId: string;
name: FieldName<Schema, FormSchema, FormError>;
initialValue: FormValue<Schema>;
value: FormValue<Schema>;
errors: FormError | undefined;
allErrors: Record<string, FormError>;
valid: boolean;
dirty: boolean;
};
export type FormMetadata<
Schema extends Record<string, unknown> = Record<string, unknown>,
FormError = string[],
> = Omit<Metadata<Schema, Schema, FormError>, 'id'> &
Pick<FormContext<Schema, FormError>, Intent['type']> & {
id: FormId<Schema, FormError>;
context: Wrapped<FormContext<Schema, FormError>>;
status?: 'success' | 'error';
getFieldset: () => Required<{
[Key in keyof Combine<Schema>]: FieldMetadata<
Combine<Schema>[Key],
Schema,
FormError
>;
}>;
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
noValidate: boolean;
};
type SubfieldMetadata<
Schema,
FormSchema extends Record<string, any>,
FormError,
> = [Schema] extends [Primitive]
? {}
: [Schema] extends [Array<infer Item> | null | undefined]
? {
getFieldList: () => Array<FieldMetadata<Item, FormSchema, FormError>>;
}
: [Schema] extends [Record<string, any> | null | undefined]
? {
getFieldset: () => Required<{
[Key in keyof Combine<Schema>]: FieldMetadata<
Combine<Schema>[Key],
FormSchema,
FormError
>;
}>;
}
: {};
export type FieldMetadata<
Schema = unknown,
FormSchema extends Record<string, any> = Record<string, unknown>,
FormError = string[],
> = Metadata<Schema, FormSchema, FormError> &
Constraint & {
formId: FormId<FormSchema, FormError>;
} & SubfieldMetadata<Schema, FormSchema, FormError>;
export declare const Form: import('react').Context<
FormContext<any, string[], any>[]
>;
export type FormMetadata<Schema extends Record<string, unknown> = Record<string, unknown>, FormError = string[]> = Omit<Metadata<Schema, Schema, FormError>, 'id'> & Pick<FormContext<Schema, FormError>, Intent['type']> & {
id: FormId<Schema, FormError>;
context: Wrapped<FormContext<Schema, FormError>>;
status?: 'success' | 'error';
getFieldset: () => Required<{
[Key in keyof Combine<Schema>]: FieldMetadata<Combine<Schema>[Key], Schema, FormError>;
}>;
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
noValidate: boolean;
};
type SubfieldMetadata<Schema, FormSchema extends Record<string, any>, FormError> = [Schema] extends [Primitive] ? {} : [Schema] extends [Array<infer Item> | null | undefined] ? {
getFieldList: () => Array<FieldMetadata<Item, FormSchema, FormError>>;
} : [Schema] extends [Record<string, any> | null | undefined] ? {
getFieldset: () => Required<{
[Key in keyof Combine<Schema>]: FieldMetadata<Combine<Schema>[Key], FormSchema, FormError>;
}>;
} : {};
export type FieldMetadata<Schema = unknown, FormSchema extends Record<string, any> = Record<string, unknown>, FormError = string[]> = Metadata<Schema, FormSchema, FormError> & Constraint & {
formId: FormId<FormSchema, FormError>;
} & SubfieldMetadata<Schema, FormSchema, FormError>;
export declare const Form: import("react").Context<FormContext<any, string[], any>[]>;
declare const wrappedSymbol: unique symbol;
export type Wrapped<Type> = {
[wrappedSymbol]: Type;
[wrappedSymbol]: Type;
};
export declare function getWrappedFormContext(
context: Wrapped<FormContext>,
): FormContext;
export declare function useFormContext<
Schema extends Record<string, any>,
FormError,
>(formId?: FormId<Schema, FormError>): FormContext<Schema, FormError, unknown>;
export declare function useFormState<FormError>(
form: FormContext<any, FormError>,
subjectRef?: MutableRefObject<SubscriptionSubject>,
): FormState<FormError>;
export declare function getWrappedFormContext(context: Wrapped<FormContext>): FormContext;
export declare function useFormContext<Schema extends Record<string, any>, FormError>(formId?: FormId<Schema, FormError>): FormContext<Schema, FormError, unknown>;
export declare function useFormState<FormError>(form: FormContext<any, FormError>, subjectRef?: MutableRefObject<SubscriptionSubject>): FormState<FormError>;
export declare function FormProvider(props: {
context: Wrapped<FormContext<any, any>>;
children: ReactNode;
context: Wrapped<FormContext<any, any>>;
children: ReactNode;
}): ReactElement;
export declare function FormStateInput(props: {
formId?: string;
formId?: string;
}): React.ReactElement;
export declare function useSubjectRef(
initialSubject?: SubscriptionSubject,
): MutableRefObject<SubscriptionSubject>;
export declare function updateSubjectRef(
ref: MutableRefObject<SubscriptionSubject>,
subject: 'status' | 'formId',
): void;
export declare function updateSubjectRef(
ref: MutableRefObject<SubscriptionSubject>,
subject: Exclude<keyof SubscriptionSubject, 'status' | 'formId'>,
scope: keyof SubscriptionScope,
name: string,
): void;
export declare function getMetadata<
Schema,
FormError,
FormSchema extends Record<string, any>,
>(
context: FormContext<FormSchema, FormError, any>,
subjectRef: MutableRefObject<SubscriptionSubject>,
stateSnapshot: FormState<FormError>,
name?: FieldName<Schema, FormSchema, FormError>,
): Metadata<Schema, FormSchema, FormError>;
export declare function getFieldMetadata<
Schema,
FormSchema extends Record<string, any>,
FormError,
>(
context: FormContext<FormSchema, FormError, any>,
subjectRef: MutableRefObject<SubscriptionSubject>,
stateSnapshot: FormState<FormError>,
prefix?: string,
key?: string | number,
): FieldMetadata<Schema, FormSchema, FormError>;
export declare function getFormMetadata<
Schema extends Record<string, any>,
FormError = string[],
FormValue = Schema,
>(
context: FormContext<Schema, FormError, FormValue>,
subjectRef: MutableRefObject<SubscriptionSubject>,
stateSnapshot: FormState<FormError>,
noValidate: boolean,
): FormMetadata<Schema, FormError>;
export type FormOptions<
Schema extends Record<string, any> = any,
FormError = string[],
FormValue = Schema,
> = BaseFormOptions<Schema, FormError, FormValue> & {
/**
* A function to be called before the form is submitted.
*/
onSubmit?: (
event: FormEvent<HTMLFormElement>,
context: ReturnType<
BaseFormContext<Schema, FormError, FormValue>['submit']
>,
) => void;
export declare function useSubjectRef(initialSubject?: SubscriptionSubject): MutableRefObject<SubscriptionSubject>;
export declare function updateSubjectRef(ref: MutableRefObject<SubscriptionSubject>, subject: 'status' | 'formId'): void;
export declare function updateSubjectRef(ref: MutableRefObject<SubscriptionSubject>, subject: Exclude<keyof SubscriptionSubject, 'status' | 'formId'>, scope: keyof SubscriptionScope, name: string): void;
export declare function getMetadata<Schema, FormError, FormSchema extends Record<string, any>>(context: FormContext<FormSchema, FormError, any>, subjectRef: MutableRefObject<SubscriptionSubject>, stateSnapshot: FormState<FormError>, name?: FieldName<Schema, FormSchema, FormError>): Metadata<Schema, FormSchema, FormError>;
export declare function getFieldMetadata<Schema, FormSchema extends Record<string, any>, FormError>(context: FormContext<FormSchema, FormError, any>, subjectRef: MutableRefObject<SubscriptionSubject>, stateSnapshot: FormState<FormError>, prefix?: string, key?: string | number): FieldMetadata<Schema, FormSchema, FormError>;
export declare function getFormMetadata<Schema extends Record<string, any>, FormError = string[], FormValue = Schema>(context: FormContext<Schema, FormError, FormValue>, subjectRef: MutableRefObject<SubscriptionSubject>, stateSnapshot: FormState<FormError>, noValidate: boolean): FormMetadata<Schema, FormError>;
export type FormOptions<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema> = BaseFormOptions<Schema, FormError, FormValue> & {
/**
* A function to be called before the form is submitted.
*/
onSubmit?: (event: FormEvent<HTMLFormElement>, context: ReturnType<BaseFormContext<Schema, FormError, FormValue>['submit']>) => void;
};
export type FormContext<
Schema extends Record<string, any> = any,
FormError = string[],
FormValue = Schema,
> = Omit<
BaseFormContext<Schema, FormError, FormValue>,
'submit' | 'onUpdate'
> & {
submit: (event: FormEvent<HTMLFormElement>) => void;
onUpdate: (
options: Partial<FormOptions<Schema, FormError, FormValue>>,
) => void;
export type FormContext<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema> = Omit<BaseFormContext<Schema, FormError, FormValue>, 'submit' | 'onUpdate'> & {
submit: (event: FormEvent<HTMLFormElement>) => void;
onUpdate: (options: Partial<FormOptions<Schema, FormError, FormValue>>) => void;
};
export declare function createFormContext<
Schema extends Record<string, any> = any,
FormError = string[],
FormValue = Schema,
>(
options: FormOptions<Schema, FormError, FormValue>,
): FormContext<Schema, FormError, FormValue>;
export declare function createFormContext<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema>(options: FormOptions<Schema, FormError, FormValue>): FormContext<Schema, FormError, FormValue>;
export {};
import { type FormId, type FieldName } from '@conform-to/dom';
import { useEffect } from 'react';
import {
type FormMetadata,
type FieldMetadata,
type Pretty,
type FormOptions,
} from './context';
import { type FormMetadata, type FieldMetadata, type Pretty, type FormOptions } from './context';
/**

@@ -14,51 +9,27 @@ * useLayoutEffect is client-only.

export declare const useSafeLayoutEffect: typeof useEffect;
export declare function useFormId<
Schema extends Record<string, unknown>,
FormError,
>(preferredId?: string): FormId<Schema, FormError>;
export declare function useFormId<Schema extends Record<string, unknown>, FormError>(preferredId?: string): FormId<Schema, FormError>;
export declare function useNoValidate(defaultNoValidate?: boolean): boolean;
export declare function useForm<
Schema extends Record<string, any>,
FormValue = Schema,
FormError = string[],
>(
options: Pretty<
Omit<FormOptions<Schema, FormError, FormValue>, 'formId'> & {
/**
* The form id. If not provided, a random id will be generated.
*/
id?: string;
/**
* Enable constraint validation before the dom is hydated.
*
* Default to `true`.
*/
defaultNoValidate?: boolean;
}
>,
): [
FormMetadata<Schema, FormError>,
ReturnType<FormMetadata<Schema, FormError>['getFieldset']>,
export declare function useForm<Schema extends Record<string, any>, FormValue = Schema, FormError = string[]>(options: Pretty<Omit<FormOptions<Schema, FormError, FormValue>, 'formId'> & {
/**
* The form id. If not provided, a random id will be generated.
*/
id?: string;
/**
* Enable constraint validation before the dom is hydated.
*
* Default to `true`.
*/
defaultNoValidate?: boolean;
}>): [
FormMetadata<Schema, FormError>,
ReturnType<FormMetadata<Schema, FormError>['getFieldset']>
];
export declare function useFormMetadata<
Schema extends Record<string, any>,
FormError = string[],
>(
formId?: FormId<Schema, FormError>,
options?: {
defaultNoValidate?: boolean;
},
): FormMetadata<Schema, FormError>;
export declare function useField<
FieldSchema,
FormSchema extends Record<string, unknown> = Record<string, unknown>,
FormError = string[],
>(
name: FieldName<FieldSchema, FormSchema, FormError>,
options?: {
formId?: FormId<FormSchema, FormError>;
},
): [
FieldMetadata<FieldSchema, FormSchema, FormError>,
FormMetadata<FormSchema, FormError>,
export declare function useFormMetadata<Schema extends Record<string, any>, FormError = string[]>(formId?: FormId<Schema, FormError>, options?: {
defaultNoValidate?: boolean;
}): FormMetadata<Schema, FormError>;
export declare function useField<FieldSchema, FormSchema extends Record<string, unknown> = Record<string, unknown>, FormError = string[]>(name: FieldName<FieldSchema, FormSchema, FormError>, options?: {
formId?: FormId<FormSchema, FormError>;
}): [
FieldMetadata<FieldSchema, FormSchema, FormError>,
FormMetadata<FormSchema, FormError>
];

@@ -92,4 +92,4 @@ 'use strict';

var defaultValue = stateSnapshot.initialValue[element.name];
if (prev === 'managed') {
// Skip fields managed by useInputControl()
if (prev === 'managed' || element.type === 'submit' || element.type === 'reset' || element.type === 'button') {
// Skip buttons and fields managed by useInputControl()
continue;

@@ -96,0 +96,0 @@ }

@@ -1,29 +0,5 @@

export {
type Submission,
type SubmissionResult,
type DefaultValue,
type Intent,
type FormId,
type FieldName,
parse,
} from '@conform-to/dom';
export {
type FieldMetadata,
type FormMetadata,
FormProvider,
FormStateInput,
} from './context';
export { type Submission, type SubmissionResult, type DefaultValue, type Intent, type FormId, type FieldName, parse, } from '@conform-to/dom';
export { type FieldMetadata, type FormMetadata, FormProvider, FormStateInput, } from './context';
export { useForm, useFormMetadata, useField } from './hooks';
export {
Control as unstable_Control,
useControl as unstable_useControl,
useInputControl,
} from './integrations';
export {
getFormProps,
getFieldsetProps,
getInputProps,
getSelectProps,
getTextareaProps,
getCollectionProps,
} from './helpers';
export { Control as unstable_Control, useControl as unstable_useControl, useInputControl, } from './integrations';
export { getFormProps, getFieldsetProps, getInputProps, getSelectProps, getTextareaProps, getCollectionProps, } from './helpers';

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.2.0",
"version": "1.2.1",
"main": "index.js",

@@ -34,3 +34,3 @@ "module": "index.mjs",

"dependencies": {
"@conform-to/dom": "1.2.0"
"@conform-to/dom": "1.2.1"
},

@@ -37,0 +37,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc