alinea
Version:
Headless git-based CMS
57 lines (56 loc) • 2.16 kB
TypeScript
import { Field } from 'alinea/core/Field';
import { Type } from 'alinea/core/Type';
import { type Atom } from 'jotai';
import { type PropsWithChildren } from 'react';
import * as Y from 'yjs';
export interface FieldInfo<StoredValue = any, QueryValue = any, Mutator = any, Options = any> {
key: string;
field: Field<StoredValue, QueryValue, Mutator, Options>;
value: Atom<StoredValue>;
options: Atom<Options | Promise<Options>>;
error: Atom<boolean | string | undefined>;
mutator: Mutator;
}
export declare class FormAtoms<T = any> {
type: Type<T>;
container: Y.Map<any>;
path: string;
options: {
parent?: FormAtoms;
readOnly?: boolean;
};
private fields;
private errorMap;
errors: import("jotai").WritableAtom<Map<string, {
field: Field;
error: boolean | string;
}>, [path: string, field: Field<any, any, any, any>, error: string | boolean | undefined], void>;
hasErrors: Atom<boolean>;
constructor(type: Type<T>, container: Y.Map<any>, path?: string, options?: {
parent?: FormAtoms;
readOnly?: boolean;
});
data(): Type.Infer<T>;
private getter;
private valueAtom;
fieldByKey(key: string): Field;
keyOf(field: Field): string;
fieldInfo<StoredValue, QueryValue, Mutator, Options>(field: Field<StoredValue, QueryValue, Mutator, Options>): FieldInfo<StoredValue, QueryValue, Mutator, Options>;
}
export interface UseFormOptions<T> {
doc?: Y.Doc;
initialValue?: Partial<Type.Infer<T>>;
}
export declare function useForm<T>(type: Type<T>, options?: UseFormOptions<T>): FormAtoms<T>;
export declare function useFormContext(): FormAtoms<any>;
export interface FieldAtomsProviderProps {
form: FormAtoms;
}
export declare function FormProvider({ children, form }: PropsWithChildren<FieldAtomsProviderProps>): import("react/jsx-runtime").JSX.Element;
export interface FormRowProps {
field: Field;
rowId?: string;
type: Type;
readOnly?: boolean;
}
export declare function FormRow({ children, field, type, rowId, readOnly }: PropsWithChildren<FormRowProps>): import("react/jsx-runtime").JSX.Element;