import type { Values } from "../values"; import type { ItemValues, FlowValues, ListValues, CondValues, LoopValues, SwitchValues, FormValues, YieldValues, ReturnValues, VariablesValues } from "../values"; import type { OnNext, OnBack, GetState, SetState } from "../controls"; /** * Defines the structure and behavior of a multi-step form. * * @template T The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template U A type extending `Values` that defines the structure of the multi-step form, * including the values handled in each phase. * * @template V An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template W An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type Schema = Record, W extends Record = Record> = ListSchema; /** * Defines the structure and behavior of any element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `ItemValues` that defines the structure of the multi-step form, * including the values handled in each phase. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type ItemSchema, Params extends Record> = Values extends FlowValues ? FlowSchema : Values extends FormValues ? FormSchema : Values extends YieldValues ? YieldSchema : Values extends ReturnValues ? ReturnSchema : Values extends VariablesValues ? VariablesSchema : never; /** * Defines the structure and behavior of any flow element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `FlowValues` that defines the structure of the multi-step form, * including the values handled in each phase. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type FlowSchema, Params extends Record> = Values extends ListValues ? ListSchema : Values extends CondValues ? CondSchema : Values extends LoopValues ? LoopSchema : Values extends SwitchValues ? SwitchSchema : never; /** * Defines the structure and behavior of a list element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `ListValues` that defines the structure of the multi-step form, * including the values handled in each phase. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type ListSchema, Params extends Record> = Values extends [infer Head, ...infer Others] ? Head extends ItemValues ? Others extends ListValues ? [ ItemSchema, ...ListSchema>, Params> ] : never : never : []; /** * Defines the structure and behavior of a condition element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `CondValues` that defines the structure of the multi-step form, * including the values handled in each phase. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type CondSchema, Params extends Record> = { cond: { if: (inputs: Inputs) => boolean; then: ListSchema; else: ListSchema; }; }; /** * Defines the structure and behavior of a loop element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `LoopValues` that defines the structure of the multi-step form, * including the values handled in each phase. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type LoopSchema, Params extends Record> = { loop: { while: (inputs: Inputs) => boolean; do: ListSchema; }; }; /** * Defines the structure and behavior of a switch element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `SwitchValues` that defines the structure of the multi-step * form, including the values handled in each phase. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type SwitchSchema, Params extends Record> = { switch: { branches: SwitchBranchesSchema; default: ListSchema; }; }; type SwitchBranchesSchema, Params extends Record> = Values extends [infer Head, ...infer Others] ? Head extends ListValues ? Others extends ListValues[] ? [ { case: (inputs: Inputs) => boolean; then: ListSchema; }, ...SwitchBranchesSchema ] : never : never : []; /** * Defines the structure and behavior of a form element in a multi-step form. * * @template Render The type of the rendered output for each form step. This can vary depending on * the framework; for example, in React, it would typically be `ReactNode`. * * @template Values A type extending `FormValues` that defines the values of the form element. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. * * @template Params An object type defining the values accessible when rendering each form step in * the multi-step process. */ export type FormSchema, Params extends Record> = { form: { values: (inputs: Inputs) => { [K in keyof Values["form"]]: [Values["form"][K], PropertyKey[]]; }; render: (args: { inputs: Inputs; values: Values["form"]; params: Params; onNext: OnNext; onBack: OnBack; getState: GetState; setState: SetState; }) => Render; }; }; /** * Defines the structure and behavior of a yield element in a multi-step form. * * @template Values A type extending `YieldValues` that defines the values of the yield element. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. */ export type YieldSchema> = { yield: { next: (inputs: Inputs) => Values["yield"]["next"]; back: (inputs: Inputs) => Values["yield"]["back"]; }; }; /** * Defines the structure and behavior of a return element in a multi-step form. * * @template Values A type extending `ReturnValues` that defines the values of the return element. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. */ export type ReturnSchema> = { return: (inputs: Inputs) => Values["return"]; }; /** * Defines the structure and behavior of a variables element in a multi-step form. * * @template Values A type extending `VariablesValues` that defines the values of the variables element. * * @template Inputs An object type representing additional values available during form execution, * beyond those generated by the multi-step form itself. */ export type VariablesSchema> = { variables: (inputs: Inputs) => Values["variables"]; }; type Joined, U extends Record> = Omit & U; type ItemOutput = Values extends FormValues ? FormOutput : Values extends VariablesValues ? VariablesOutput : Record; type FormOutput = Values["form"]; type VariablesOutput = Values["variables"]; export {}; //# sourceMappingURL=typed.d.ts.map