UNPKG

alinea

Version:
40 lines (39 loc) 2.75 kB
import type { FieldOptions, WithoutLabel } from 'alinea/core/Field'; import { ListField } from 'alinea/core/field/ListField'; import { UnionField } from 'alinea/core/field/UnionField'; import type { EdgeEntries, EdgeEntry, GraphQuery, IncludeGuard, SelectionGuard, TypeGuard } from 'alinea/core/Graph'; import type { Picker } from 'alinea/core/Picker'; import { Reference } from 'alinea/core/Reference'; import { ListRow } from 'alinea/core/shape/ListShape'; import type { ReactNode } from 'react'; /** Optional settings to configure a link field */ export interface LinkFieldOptions<Value> extends FieldOptions<Value> { /** Width of the field in the dashboard UI (0-1) */ width?: number; /** Add instructional text to a field */ help?: ReactNode; /** Display a minimal version */ inline?: boolean; max?: number; } export interface LinkOptions<Value> extends LinkFieldOptions<Value> { pickers: Record<string, Picker<any, any>>; } export declare class LinkField<StoredValue extends Reference, QueryValue> extends UnionField<StoredValue, QueryValue, LinkOptions<StoredValue>> { first<Selection extends SelectionGuard = undefined, const Type extends TypeGuard = undefined, Include extends IncludeGuard = undefined>(query: GraphQuery<Selection, Type, Include>): GraphQuery<Selection, Type, Include> & EdgeEntry & { first: true; }; } export declare function createLink<StoredValue extends Reference, QueryValue>(label: string, options: WithoutLabel<LinkOptions<StoredValue>>): LinkField<StoredValue, QueryValue>; /** Internal representation of a link field */ export declare class LinksField<StoredValue extends ListRow, QueryValue> extends ListField<StoredValue, QueryValue, LinkOptions<Array<StoredValue>>> { find<Selection extends SelectionGuard = undefined, Type extends TypeGuard = undefined, Include extends IncludeGuard = undefined>(query: GraphQuery<Selection, Type, Include>): GraphQuery<Selection, Type, Include> & EdgeEntries; first<Selection extends SelectionGuard = undefined, const Type extends TypeGuard = undefined, Include extends IncludeGuard = undefined>(query?: GraphQuery<Selection, Type, Include>): GraphQuery<Selection, Type, Include> & EdgeEntries & { first: true; }; count<Selection extends SelectionGuard = undefined, const Type extends TypeGuard = undefined, Include extends IncludeGuard = undefined>(query?: GraphQuery<Selection, Type, Include>): GraphQuery<Selection, Type, Include> & EdgeEntries & { count: true; }; } /** Create a link field configuration */ export declare function createLinks<StoredValue extends ListRow, QueryValue>(label: string, options: WithoutLabel<LinkOptions<Array<StoredValue>>>): LinksField<StoredValue, QueryValue>;