UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

48 lines (47 loc) 2.31 kB
import { LinkResolver } from 'alinea/backend/resolver/LinkResolver'; import { Expr } from 'alinea/core/pages/Expr'; import type { ComponentType } from 'react'; import { Hint } from './Hint.js'; import { Shape } from './Shape.js'; export interface FieldOptions<Value> { label: string; /** Hide this field in the dashboard */ hidden?: boolean; /** Mark this field as read-only */ readOnly?: boolean; /** The initial value of the field */ initialValue?: Value; } export type WithoutLabel<Options extends FieldOptions<any>> = Omit<Options, 'label'>; export interface FieldMeta<Value, Mutator, Options extends FieldOptions<Value>> { hint: Hint; options: Options; view?: FieldView<Value, Mutator, Options>; postProcess?: (value: Value, loader: LinkResolver) => Promise<void>; } export interface FieldData<Value, Mutator, Options extends FieldOptions<Value>> extends FieldMeta<Value, Mutator, Options> { shape: Shape<Value, Mutator>; } export type FieldView<Value, Mutator, Options extends FieldOptions<Value>> = ComponentType<{ field: Field<Value, Mutator, Options>; }>; export interface Field<Value, Mutator, Options extends FieldOptions<Value>> extends Expr<Value> { [Field.Data]: FieldData<Value, Mutator, Options>; [Field.Ref]: symbol; } export declare class Field<Value = any, Mutator = any, Options extends FieldOptions<Value> = FieldOptions<Value>> { static index: number; constructor(data: FieldData<Value, Mutator, Options>); } export declare namespace Field { const Data: unique symbol; const Ref: unique symbol; function provideView<Value, Mutator, Options extends FieldOptions<Value>, Factory extends (...args: Array<any>) => Field<Value, Mutator, Options>>(view: FieldView<Value, Mutator, Options>, factory: Factory): Factory; function ref(field: Field): symbol; function shape(field: Field<any, any>): Shape; function hint(field: Field): Hint; function label(field: Field): string; function view<Value, Mutator, Options extends FieldOptions<Value>>(field: Field<Value, Mutator, Options>): FieldView<Value, Mutator, Options> | undefined; function options<Value, Options extends FieldOptions<Value>>(field: Field<Value, any, Options>): Options; function isField(value: any): value is Field; }