UNPKG

react-signal-forms

Version:

A forms library focusing on performance and modular extensibility.

31 lines 2.5 kB
import { FieldContext, IFieldContext } from "@/fieldContext"; import { ArrayFieldBase, ArrayItemType, Field } from "@/fields"; import { IFormContextLike } from "@/formContext"; import { SignalFormPlugin } from "@/plugins/types"; import { FormValues } from "@/types"; import { Signal } from "@preact/signals-react"; export type IArrayFieldContext<TValue extends FormValues[] = FormValues[], TParentForm extends IFormContextLike = any, TPlugins extends SignalFormPlugin[] = []> = IFieldContext<TValue, TPlugins> & { arrayItems: Signal<ArrayFieldItemContext<TValue, TParentForm, TPlugins>[]>; addItem: () => void; removeItem: (id: number) => void; }; export type ArrayFieldItemContext<TValue = FormValues[], TParentForm extends IFormContextLike = any, TPlugins extends SignalFormPlugin[] = []> = IFormContextLike<ArrayItemType<TValue>, TParentForm, TPlugins> & { id: any; }; export declare class ArrayFieldContext<TValue extends FormValues[]> extends FieldContext<TValue> implements IArrayFieldContext<TValue> { __parentForm: IFormContextLike; protected __plugins: SignalFormPlugin[]; lastItemId: number; constructor(parentForm: IFormContextLike, field: Field<any, any, ArrayFieldBase<TValue>>, initialValue: TValue | undefined, plugins: SignalFormPlugin[]); addItem: () => void; removeItem: (id: number) => void; arrayItems: Signal<ArrayFieldItemContext<TValue>[]>; createItemId: () => number; } export declare function createContextForArrayField<TValue extends FormValues[] = FormValues[]>(field: ArrayFieldBase<TValue>, parentForm: IFormContextLike, createItemId: () => number, initialValues?: FormValues[]): ArrayFieldItemContext<TValue>[]; export declare function createContextForArrayFieldItem<TValue extends FormValues[] = FormValues[], TParentForm extends IFormContextLike = any>(id: any, field: ArrayFieldBase<TValue>, parentForm: TParentForm, initialValues: ArrayItemType<TValue>): ArrayFieldItemContext<TValue, TParentForm>; export declare function addFieldExtensionsToArrayItems(field: ArrayFieldBase, items: ArrayFieldItemContext[], plugins: SignalFormPlugin[]): void; export declare function isArrayFieldContext<TValue, TPlugins extends SignalFormPlugin[] = []>(fieldContext: IFieldContext<TValue, TPlugins>): fieldContext is IArrayFieldContext<AsArrayFieldValue<TValue>, any, TPlugins>; type AsArrayFieldValue<TValue> = TValue extends FormValues[] ? TValue : TValue & FormValues[]; export {}; //# sourceMappingURL=fieldContext.d.ts.map