import { Projector, VNode } from 'maquette'; import { Path } from 'path-parser'; import { PropsWithFields } from './props-field-registry'; export interface IValidationObject { notEmpty?: { value: boolean; message: string; }; minLength?: { value: number; message: string; }; maxLength?: { value: number; message: string; }; } export interface IRegisteredField { handler: (evt: Event, skipValidation?: boolean) => void | boolean; validate: () => void; validationErrors: string[]; isValid: () => boolean; isDirty: () => boolean; value: T; clear: () => void; key: string; } export interface IRouteRegistry { [key: string]: { calculator: (routeName: string, routeParams: any, props: Readonly) => T; spec: Path; }; } declare type ActionFn = (e: Event, data: Readonly) => Partial; declare type RouteActionFn = (context: { key: string; path: string; data: any; }, present: IPresent) => void; export interface IActionsObj { [k: string]: ActionFn; } /** * FRETS class is the main way to instantiate a new application and hang your models, actions, and state off it * @template T, U */ export declare type IPresent = (proposal: Partial) => void; export declare type IActionEventHandler = (event: Event) => void; export declare type IActionFn = (event: Event, present: IPresent) => void; export declare type IModelPresenter = (proposal: Partial, state: (props: Partial) => void) => void; export declare type IRegisterFieldFn = (key: string, defaultValue?: U, validation?: IValidationObject) => IRegisteredField; export interface IFunFrets { modelProps: T; present: (proposal: Partial) => void; projector: Projector; registerView: (renderFn: (app: IFunFrets) => VNode) => void; registerField: IRegisterFieldFn; registerAction: (key: string, actionFn: IActionFn) => IActionEventHandler; registerRouteAction: (key: string, path: string, actionFn: RouteActionFn) => void; registerAcceptor: (presenterFn: IModelPresenter) => void; registerStateGraph: (entryState: IStateNode) => void; currentStateNode: IStateNode; getRouteLink: (key: string, data?: any) => string | false; navToRoute: (key: string, data?: any) => void; navToPath: (key: string, data?: any) => void; } export interface IMountable { fretsApp: IFunFrets; mountTo: (id: string) => void; stateRenderer: () => VNode; present: (proposal: Partial) => void; } export interface ISetupOptions { projector: Projector; } export interface IStateNode { name: string; guard?: (modelProps: T) => boolean; edges?: Array>; renderer: (app: IFunFrets) => VNode; } export declare function setup(modelProps: T, setupFn: (fretsApp: IFunFrets) => void, opts?: ISetupOptions): IMountable; export {};