import { DefaultValues, Field, FieldComponentProps, FieldGroupWithChildren, FieldType, RepeaterGroup, RequiredField } from './fieldTypes.js'; import { GroupProps } from './FieldGroup.js'; /** Field types built by a plain leaf builder (`choice` and groups have their own). */ declare type LeafFieldType = Exclude; declare type DistributiveOmit = T extends unknown ? Omit : never; /** * The props of the field's JSX component, minus `name`: a field's name is its * key in the object passed to `defineFields`. */ declare type FieldConfig = DistributiveOmit, 'name'>; /** * ``'s props, minus `name`. `choices`, `multiple` and `required` * are replaced: `V` is inferred from `choices` as the choice values, and the * `ChoiceBuilder` overloads set `M` and `R` for `FieldValues`. */ declare type ChoiceConfig = DistributiveOmit, 'name' | 'choices' | 'multiple' | 'required'> & { choices: readonly (readonly [V, string])[]; multiple?: M; required?: R; }; /** `` / `` props, minus `name`. */ declare type GroupConfig = Omit; export interface LeafDefinition { readonly type: T; readonly config: FieldConfig & { required?: R; }; } export interface ChoiceDefinition { readonly type: 'choice'; readonly config: ChoiceConfig; } export interface GroupDefinition { readonly type: 'group'; readonly repeated: Repeated; readonly config: GroupConfig & { children: C; }; } /** * A set of fields keyed by field name, made with the `field` builders: what * `defineFields` and a group's `children` take. Only `type` is constrained: a * builder call inside the object would otherwise take its return type from * this constraint and widen `required: true` and the choice values. */ export declare type FieldShape = { readonly [name: string]: { readonly type: FieldType; }; }; export interface LeafBuilder { (config: FieldConfig & { required: R; }): LeafDefinition; (config: FieldConfig): LeafDefinition; } export interface ChoiceBuilder { (config: ChoiceConfig & { multiple: M; required: R; }): ChoiceDefinition; (config: ChoiceConfig & { multiple: M; }): ChoiceDefinition; (config: ChoiceConfig & { required: R; }): ChoiceDefinition; (config: ChoiceConfig): ChoiceDefinition; (config: ChoiceConfig & { required: R; }): ChoiceDefinition; (config: ChoiceConfig): ChoiceDefinition; } declare type FieldBuilders = { [T in LeafFieldType]: LeafBuilder; } & { choice: ChoiceBuilder; /** A group of fields; `children` is a set of fields, like `defineFields` takes. */ group(config: GroupConfig & { children: C; }): GroupDefinition; /** A repeatable group of fields; `children` is a set of fields, like `defineFields` takes. */ repeatedGroup(config: GroupConfig & { children: C; }): GroupDefinition; }; /** * Field builders for `defineFields`. Each takes the props of the field's JSX * component (`field.text` takes ``'s props), minus `name`. */ export declare const field: FieldBuilders; declare const fieldShape: unique symbol; /** * The `fields.json` entries `defineFields` returns: at runtime a plain * `Field[]`. The optional `fieldShape` property exists only in the type: its * `shape` carries the shape to `FieldValues`. Its `keys` keeps a larger set * from counting as a subtype of a smaller one; otherwise * `cond ? defineFields(withCta) : defineFields(base)` would collapse to the * smaller set's type instead of a union. */ export declare type DefinedFields = Field[] & { readonly [fieldShape]?: { shape: S; keys: keyof S; }; }; /** * Declares a module's fields as an object of `field.*` builders keyed by field * name, and returns the same `fields.json` entries the equivalent * `` JSX produces. Export the result as `fields`, and type the * module's props with `FieldValues`. */ export declare function defineFields(shape: S): DefinedFields; declare type UntypedFieldType = 'crmobjectproperty' | 'variantmanagement'; declare type IsTrue = NonNullable extends true ? true : false; declare type GeneratedFieldType = D extends GroupDefinition ? Repeated extends true ? RepeaterGroup> : FieldGroupWithChildren> : D extends ChoiceDefinition ? boolean extends NonNullable ? ChoiceValue | Array> : IsTrue extends true ? Array> : ChoiceValue : D extends LeafDefinition ? IsTrue extends true ? RequiredField> : FieldComponentProps : never; declare type ChoiceValue = D['config']['choices'][number][0]; declare type EntryAt = NonNullable; declare type TypedKeys = { [K in keyof S]-?: EntryAt extends { type: UntypedFieldType; } ? never : K; }[keyof S]; declare type RequiredKeys = { [K in TypedKeys]-?: {} extends Pick ? never : EntryAt extends GroupDefinition ? K : EntryAt extends { config: { required?: infer R; }; } ? IsTrue extends true ? K : never : never; }[TypedKeys]; declare type GeneratedShape = { [K in RequiredKeys]: GeneratedFieldType>; } & { [K in Exclude, RequiredKeys>]?: GeneratedFieldType>; }; /** * The field values a module receives for fields declared with `defineFields`, * for `ModuleProps>`. The same type the dev server * generates for the equivalent JSX fields: only `required: true` makes a key * required. */ export declare type FieldValues = F extends { readonly [fieldShape]?: { shape: infer S; }; } ? S extends FieldShape ? DefaultValues> : never : never; export {};