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)

89 lines (88 loc) 3.44 kB
import { EntryPhase, Expand } from 'alinea/core'; import { Cursor } from 'alinea/core/pages/Cursor'; import { Expr } from 'alinea/core/pages/Expr'; import { EntryEditProps } from 'alinea/dashboard/view/EntryEdit'; import { Callable } from 'rado/util/Callable'; import type { ComponentType } from 'react'; import { Field } from './Field.js'; import { Hint } from './Hint.js'; import { Label } from './Label.js'; import { Meta, StripMeta } from './Meta.js'; import { Section } from './Section.js'; import type { View } from './View.js'; import { RecordShape } from './shape/RecordShape.js'; export interface EntryUrlMeta { phase: EntryPhase; path: string; parentPaths: Array<string>; locale?: string | null; } /** Optional settings to configure a Type */ export interface TypeMeta { /** Entries can be created as children of this entry */ isContainer?: true; /** Entries do not show up in the sidebar content tree */ isHidden?: true; /** Accepts entries of these types as children */ contains?: Array<string>; /** An icon (React component) to represent this type in the dashboard */ icon?: ComponentType; /** A React component used to view an entry of this type in the dashboard */ view?: ComponentType<EntryEditProps>; /** A React component used to view a row of this type in the dashboard */ summaryRow?: View<any>; /** A React component used to view a thumbnail of this type in the dashboard */ summaryThumb?: View<any>; /** Create indexes on fields of this type */ entryUrl?: (meta: EntryUrlMeta) => string; } export interface TypeData { label: Label; shape: RecordShape; hint: Hint; definition: TypeDefinition; meta: TypeMeta; sections: Array<Section>; target: TypeTarget; } export declare class TypeTarget { } export declare class TypeI<Definition = object> { get [Type.Data](): TypeData; } export interface TypeI<Definition = object> extends Callable { (): Cursor.Find<TypeRow<Definition>>; (partial: Partial<TypeRow<Definition>>): Cursor.Partial<Definition>; } export type Type<Definition = object> = Definition & TypeI<Definition>; export type TypeRow<Definition> = Expand<{ [K in keyof Definition as Definition[K] extends Expr<any> ? K : never]: Definition[K] extends Expr<infer T> ? T : never; }>; export declare namespace Type { type Infer<Definition> = TypeRow<Definition>; const Data: unique symbol; function label(type: Type): Label; function meta(type: Type): TypeMeta; function shape(type: Type): RecordShape; function hint(type: Type): Hint; function sections(type: Type): Section[]; function isContainer(type: Type): boolean; function target(type: Type): TypeTarget; function field(type: Type, name: string): Field | undefined; function isType(type: any): type is Type; function blankEntry(name: string, type: Type): { id: string; type: string; [key: string]: any; }; } export interface TypeDefinition { [key: string]: Field<any, any> | Section; readonly [Meta]?: TypeMeta; } /** Create a new type */ export declare function type<Definition extends TypeDefinition>(definition: Definition): Type<StripMeta<Definition>>; export declare function type<Definition extends TypeDefinition>(label: string, definition: Definition): Type<StripMeta<Definition>>; export declare namespace type { const meta: typeof Meta; }