1
1
import { useEffect , useMemo } from "react" ;
2
2
import * as R from "remeda" ;
3
3
import {
4
- Rvf ,
5
- scopeRvf ,
4
+ FormScope ,
5
+ scopeFormScope ,
6
6
SubmitStatus ,
7
7
FormStoreValue ,
8
8
getFieldValue ,
@@ -44,12 +44,12 @@ import {
44
44
ValidInputPropsValues ,
45
45
} from "./inputs/getInputProps" ;
46
46
47
- type MinimalRvf < FieldPaths extends string > = {
47
+ type MinimalFormScope < FieldPaths extends string > = {
48
48
resetField : ( fieldName : FieldPaths , nextValue ?: any ) => void ;
49
49
} ;
50
50
51
51
export type FormFields < Form > =
52
- Form extends MinimalRvf < infer FieldPaths > ? FieldPaths : never ;
52
+ Form extends MinimalFormScope < infer FieldPaths > ? FieldPaths : never ;
53
53
54
54
interface FormProps {
55
55
onSubmit : ( event : React . FormEvent < HTMLFormElement > ) => void ;
@@ -64,7 +64,7 @@ export type ManualSubmitOption = SubmitterOptions & {
64
64
value ?: string ;
65
65
} ;
66
66
67
- export interface RvfReact < FormInputData > {
67
+ export interface ReactFormApi < FormInputData > {
68
68
/**
69
69
* Gets whether the field has been touched.
70
70
* @willRerender
@@ -234,14 +234,14 @@ export interface RvfReact<FormInputData> {
234
234
) => void ;
235
235
236
236
/**
237
- * Creates an `Rvf ` scoped to the specified field.
237
+ * Creates an `FormScope ` scoped to the specified field.
238
238
* This is useful for creating subforms.
239
239
* In order to use this, you can pass it to `useForm`.
240
240
*
241
241
* @example
242
242
* ```tsx
243
243
* type PersonFormProps = {
244
- * rvf: Rvf <{ name: string }>;
244
+ * rvf: FormScope <{ name: string }>;
245
245
* }
246
246
*
247
247
* const PersonForm = ({ rvf }: PersonFormProps) => {
@@ -272,12 +272,12 @@ export interface RvfReact<FormInputData> {
272
272
*/
273
273
scope < Field extends ValidStringPaths < FormInputData > > (
274
274
fieldName : Field ,
275
- ) : Rvf < ValueAtPath < FormInputData , StringToPathTuple < Field > > > ;
275
+ ) : FormScope < ValueAtPath < FormInputData , StringToPathTuple < Field > > > ;
276
276
277
277
/**
278
- * Returns an `Rvf ` without scoping any further.
278
+ * Returns an `FormScope ` without scoping any further.
279
279
*/
280
- scope ( ) : Rvf < FormInputData > ;
280
+ scope ( ) : FormScope < FormInputData > ;
281
281
282
282
getFormProps : ( props ?: Partial < FormProps > ) => FormProps ;
283
283
@@ -369,17 +369,17 @@ export interface RvfReact<FormInputData> {
369
369
submit : ( option ?: ManualSubmitOption ) => void ;
370
370
}
371
371
372
- export type BaseRvfReactParams < FormInputData > = {
373
- form : Rvf < FormInputData > ;
372
+ export type BaseReactFormParams < FormInputData > = {
373
+ form : FormScope < FormInputData > ;
374
374
prefix : string ;
375
375
trackedState : FormStoreValue ;
376
376
} ;
377
377
378
- export const makeBaseRvfReact = < FormInputData , > ( {
378
+ export const makeBaseReactFormApi = < FormInputData , > ( {
379
379
trackedState,
380
380
prefix,
381
381
form,
382
- } : BaseRvfReactParams < FormInputData > ) : RvfReact < FormInputData > => {
382
+ } : BaseReactFormParams < FormInputData > ) : ReactFormApi < FormInputData > => {
383
383
const f = ( fieldName ?: string ) =>
384
384
pathArrayToString ( [ prefix , fieldName ] . filter ( R . isNonNullish ) ) ;
385
385
const transientState = ( ) => form . __store__ . store . getState ( ) ;
@@ -392,7 +392,7 @@ export const makeBaseRvfReact = <FormInputData,>({
392
392
makeFieldArrayImpl ( {
393
393
trackedState,
394
394
arrayFieldName,
395
- form : scopeRvf ( form , arrayFieldName ) as Rvf < any [ ] > ,
395
+ form : scopeFormScope ( form , arrayFieldName ) as FormScope < any [ ] > ,
396
396
} ) ,
397
397
) ;
398
398
@@ -505,7 +505,7 @@ export const makeBaseRvfReact = <FormInputData,>({
505
505
form . __store__ . store . getState ( ) . resetField ( f ( fieldName ) , nextValue ) ,
506
506
507
507
scope : ( fieldName ?: string ) =>
508
- fieldName == null ? form : ( scopeRvf ( form , fieldName ) as any ) ,
508
+ fieldName == null ? form : ( scopeFormScope ( form , fieldName ) as any ) ,
509
509
510
510
name : ( fieldName ?: string ) => f ( fieldName ) ,
511
511
@@ -594,7 +594,9 @@ export const makeBaseRvfReact = <FormInputData,>({
594
594
} ;
595
595
} ;
596
596
597
- export const useFormInternal = < FormInputData , > ( form : Rvf < FormInputData > ) => {
597
+ export const useFormInternal = < FormInputData , > (
598
+ form : FormScope < FormInputData > ,
599
+ ) => {
598
600
const prefix = form . __field_prefix__ ;
599
601
const { useStoreState, resolvers } = form . __store__ ;
600
602
const trackedState = useStoreState ( ) ;
@@ -610,7 +612,7 @@ export const useFormInternal = <FormInputData,>(form: Rvf<FormInputData>) => {
610
612
611
613
const base = useMemo (
612
614
( ) =>
613
- makeBaseRvfReact ( {
615
+ makeBaseReactFormApi ( {
614
616
form,
615
617
prefix,
616
618
trackedState,
0 commit comments