1- import { type AnyTuple , type Kind } from "@duplojs/utils" ;
1+ import { type UnionToIntersection , type AnyTuple , type Kind } from "@duplojs/utils" ;
22import type * as DP from "@duplojs/utils/dataParser" ;
33import type * as EE from "@duplojs/utils/either" ;
44import { createVueFormKind } from "./kind" ;
55import { type Ref , type VNode } from "vue" ;
66import { type Templates } from "./template" ;
77
8+ export interface FormFieldSlotParams <
9+ GenericValue extends unknown = unknown ,
10+ > {
11+ fieldKey : string ;
12+ value : GenericValue ;
13+ update ( value : GenericValue ) : void ;
14+ formField ?( ) : VNode ;
15+ }
16+
17+ export type FormFieldSlots = Record <
18+ string ,
19+ FormFieldSlotParams
20+ > ;
21+
822export type FormFieldInstanceParams <
923 GenericValue extends unknown = unknown ,
1024> = [
1125 modelValue : Ref < GenericValue > ,
1226 parentKey : string ,
1327 templates : Templates ,
28+ getSlot : (
29+ name : string ,
30+ params : FormFieldSlotParams
31+ ) => VNode | null ,
1432] ;
1533
1634export interface ErrorProperties {
@@ -30,9 +48,11 @@ export interface FormFieldInstance<
3048export interface FormFieldProperties <
3149 GenericValue extends unknown = unknown ,
3250 GenericCheckedValue extends unknown = unknown ,
51+ GenericSlots extends FormFieldSlots = FormFieldSlots ,
3352> {
3453 value : GenericValue ;
3554 checkedValue : GenericCheckedValue ;
55+ slots : GenericSlots ;
3656}
3757
3858export const formFieldKind = createVueFormKind <
@@ -43,11 +63,13 @@ export const formFieldKind = createVueFormKind<
4363export interface FormField <
4464 GenericValue extends unknown = unknown ,
4565 GenericCheckedValue extends unknown = unknown ,
66+ GenericSlots extends FormFieldSlots = FormFieldSlots ,
4667> extends Kind <
4768 typeof formFieldKind . definition ,
4869 FormFieldProperties <
4970 GenericValue ,
50- GenericCheckedValue
71+ GenericCheckedValue ,
72+ GenericSlots
5173 >
5274 > {
5375 "new" (
@@ -59,6 +81,7 @@ export interface FormField<
5981export function createFormField <
6082 GenericValue extends unknown ,
6183 GenericCheckedValue extends unknown ,
84+ GenericSlots extends FormFieldSlots ,
6285> (
6386 theFunction : (
6487 ...args : FormFieldInstanceParams < GenericValue >
@@ -68,7 +91,8 @@ export function createFormField<
6891 defaultValue : NoInfer < GenericValue > ,
6992) : FormField <
7093 GenericValue ,
71- GenericCheckedValue
94+ GenericCheckedValue ,
95+ GenericSlots
7296 > {
7397 return formFieldKind . setTo (
7498 {
@@ -90,3 +114,23 @@ export type GetFormFieldCheckedValue<
90114> = GenericFormField extends FormField < any , infer InferredCheckedValue >
91115 ? InferredCheckedValue
92116 : never ;
117+
118+ export type GetFormFieldSlots <
119+ GenericFormField extends FormField ,
120+ > = GenericFormField extends FormField < any , any , infer InferredSlots >
121+ ? InferredSlots
122+ : never ;
123+
124+ export type MergeFormFieldSlots <
125+ GenericFormField extends FormField ,
126+ > = Extract <
127+ keyof UnionToIntersection < GetFormFieldSlots < GenericFormField > > extends infer InferredKeyof extends string
128+ ? {
129+ [ Prop in InferredKeyof ] : Extract <
130+ GetFormFieldSlots < GenericFormField > ,
131+ Record < Prop , unknown >
132+ > [ Prop ]
133+ }
134+ : never ,
135+ FormFieldSlots
136+ > ;
0 commit comments