import type { Schema } from "../schema"; import type { ItemStruct, NestStruct, ListStruct, ConditionStruct, LoopStruct, SwitchStruct, FormStruct, YieldStruct, ReturnStruct, VariablesStruct, JumpStruct } from "../struct"; import type { OnNext, OnBack, OnJump, GetState, SetState } from "../form-controls"; /** * Defines the structure and behavior of a multi-step form. * * @template T An object type extending `Schema` with the following properties: * - `render` - the type of the rendered output for each form step. * - `struct` — the structure of the multi-step form, including the values handled in each phase. * - `inputs` — additional values available across all steps of the multi-step form. * - `params` — values accessible when rendering each form step. */ export type Flow = ListFlow; export type ItemFlow, Values extends Record, Params extends Record> = Struct extends NestStruct ? NestFlow : Struct extends FormStruct ? FormFlow : Struct extends VariablesStruct ? VariablesFlow : Struct extends YieldStruct ? YieldFlow : Struct extends ReturnStruct ? ReturnFlow : never; export type NestFlow, Values extends Record, Params extends Record> = Struct extends ListStruct ? ListFlow : Struct extends ConditionStruct ? ConditionFlow : Struct extends LoopStruct ? LoopFlow : Struct extends SwitchStruct ? SwitchFlow : Struct extends JumpStruct ? JumpFlow : never; export type ListFlow, Values extends Record, Params extends Record> = Struct extends [infer Head, ...infer Others] ? Head extends ItemStruct ? Others extends ListStruct ? [ ItemFlow, ...ListFlow, Params> ] : never : never : []; export type ConditionFlow, Values extends Record, Params extends Record> = { condition: { if: (values: Values) => boolean; then: ListFlow; else: ListFlow; }; }; export type LoopFlow, Values extends Record, Params extends Record> = { loop: { while: (values: Values) => boolean; do: ListFlow; }; }; export type SwitchFlow, Values extends Record, Params extends Record> = { switch: { branches: SwitchBranchesFlow; default: ListFlow; }; }; type SwitchBranchesFlow, Values extends Record, Params extends Record> = Struct extends [infer Head, ...infer Others] ? Head extends ListStruct ? Others extends ListStruct[] ? [ { case: (values: Values) => boolean; then: ListFlow; }, ...SwitchBranchesFlow ] : never : never : []; export type JumpFlow, Params extends Record> = { jump: { id: unknown; at: FormFlow; }; }; export type FormFlow, Params extends Record> = { form: { fields: (values: Values) => { [K in keyof Struct["form"]["fields"]]: [ Struct["form"]["fields"][K], PropertyKey[] ]; }; render: (args: { fields: Struct["form"]["fields"]; values: Values; params: Params; onNext: OnNext; onBack: OnBack; onJump: OnJump; getState: GetState; setState: SetState; }) => Render; }; }; export type VariablesFlow> = { variables: (values: Values) => Struct["variables"]; }; export type YieldFlow> = { yield: { next: (values: Values) => Struct["yield"]["next"]; back: (values: Values) => Struct["yield"]["back"]; }; }; export type ReturnFlow> = { return: (values: Values) => Struct["return"]; }; type Output, Values extends Record> = Struct extends FormStruct ? FormOutput : Struct extends VariablesStruct ? VariablesOutput : Struct extends ListStruct ? ListOutput : Struct extends ConditionStruct ? ConditionOutput : Struct extends LoopStruct ? LoopOutput : Struct extends SwitchStruct ? SwitchOutput : Struct extends JumpStruct ? JumpOutput : Values; type FormOutput> = Join; type VariablesOutput> = Join; type ListOutput, Values extends Record> = ListContainsJump extends true ? Inputs : Values; type ConditionOutput, Values extends Record> = BranchesContainsJump<[ Struct["condition"]["then"], Struct["condition"]["else"] ]> extends true ? Inputs : Values; type LoopOutput, Values extends Record> = ListContainsJump extends true ? Inputs : Values; type SwitchOutput, Values extends Record> = BranchesContainsJump<[ ...Struct["switch"]["branches"], Struct["switch"]["default"] ]> extends true ? Inputs : Values; type JumpOutput> = FormOutput; type BranchesContainsJump = Series extends [ infer Head, ...infer Others ] ? Head extends ListStruct ? Others extends ListStruct[] ? ListContainsJump extends true ? true : BranchesContainsJump : never : never : false; type ListContainsJump = Struct extends [ infer Head, ...infer Others ] ? Head extends ItemStruct ? Others extends ListStruct ? Head extends JumpStruct ? true : ListContainsJump : never : never : false; type Join, U extends Record> = Omit & U; export {}; //# sourceMappingURL=typed.d.ts.map