Skip to content

Commit 24dfa76

Browse files
committed
refactor: rename
1 parent 54c9d98 commit 24dfa76

22 files changed

+140
-130
lines changed

apps/test-app/app/components/Fieldset.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { FC, PropsWithChildren } from "react";
2-
import { Rvf, useField } from "@rvf/remix";
2+
import { FormScope, useField } from "@rvf/remix";
33

44
type FieldsetProps = PropsWithChildren<{
55
label: string;
66
name: string;
7-
rvf?: Rvf<any>;
7+
rvf?: FormScope<any>;
88
}>;
99

1010
export const Fieldset: FC<FieldsetProps> = ({ children, label, name, rvf }) => {

apps/test-app/app/components/Input.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { forwardRef } from "react";
2-
import { useField, Rvf } from "@rvf/remix";
2+
import { useField, FormScope } from "@rvf/remix";
33

44
type InputProps = {
5-
name: string | Rvf<string | boolean | string[]>;
5+
name: string | FormScope<string | boolean | string[]>;
66
label: string;
77
type?: string;
88
value?: string;

apps/test-app/app/components/SubmitButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Rvf,
2+
FormScope,
33
useIsSubmitting,
44
useIsValid,
55
useFormScopeOrContext,
@@ -9,7 +9,7 @@ type Props = {
99
label?: string;
1010
submittingLabel?: string;
1111
disableWhenInvalid?: boolean;
12-
form?: Rvf<any>;
12+
form?: FormScope<any>;
1313
name?: string;
1414
value?: string;
1515
"data-testid"?: string;

apps/test-app/app/routes/context-hooks.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DataFunctionArgs, json } from "@remix-run/node";
22
import { useActionData } from "@remix-run/react";
33
import { withYup } from "@rvf/yup";
44
import {
5-
Rvf,
5+
FormScope,
66
FormProvider,
77
useRemixFormResponse,
88
useForm,
@@ -23,7 +23,7 @@ const DisplayContext = ({
2323
form,
2424
}: {
2525
testid: string;
26-
form?: Rvf<any>;
26+
form?: FormScope<any>;
2727
}) => {
2828
const context = useFormScopeOrContext(form);
2929

packages/core/src/dom/dom.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Rvf, RvfStore } from "../form";
1+
import { FormScope, FormStore } from "../form";
22
import { getFieldValue } from "../getters";
33
import { MultiValueMap } from "../native-form-data/MultiValueMap";
44
import * as R from "remeda";
@@ -140,7 +140,7 @@ export const getElementsWithNames = (
140140
) as HTMLElement[];
141141
};
142142

143-
export const registerFormElementEvents = (store: RvfStore) => {
143+
export const registerFormElementEvents = (store: FormStore) => {
144144
const transientState = () => store.store.getState();
145145

146146
const onChange = (event: Event) => {

packages/core/src/form.ts

+18-15
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ type FormInit<FormInputData extends FieldValues, FormOutputData> = {
4848
flags: StoreFlags;
4949
} & SubmitTypes<FormOutputData>;
5050

51-
export interface Rvf<FormInputData> {
51+
export interface FormScope<FormInputData> {
5252
__brand__: "rvf";
5353
__type__FormInputData: FormInputData;
5454
__field_prefix__: string;
55-
__store__: RvfStore;
55+
__store__: FormStore;
5656
scope<Path extends ValidStringPaths<FormInputData>>(
5757
field: Path,
58-
): Rvf<ValueAtPath<FormInputData, StringToPathTuple<Path>>>;
58+
): FormScope<ValueAtPath<FormInputData, StringToPathTuple<Path>>>;
5959
}
6060

61-
export interface RvfStore {
61+
export interface FormStore {
6262
transientFieldRefs: RefStore;
6363
controlledFieldRefs: RefStore;
6464
fieldSerializerRefs: RefStore<FieldSerializer>;
@@ -70,7 +70,10 @@ export interface RvfStore {
7070
subformCache: Map<string, any>;
7171
}
7272

73-
export const createRvf = <FormInputData extends FieldValues, FormOutputData>({
73+
export const createFormScope = <
74+
FormInputData extends FieldValues,
75+
FormOutputData,
76+
>({
7477
defaultValues,
7578
serverValidationErrors,
7679
validator,
@@ -81,7 +84,7 @@ export const createRvf = <FormInputData extends FieldValues, FormOutputData>({
8184
submitSource,
8285
formProps,
8386
flags,
84-
}: FormInit<FormInputData, FormOutputData>): Rvf<FormInputData> => {
87+
}: FormInit<FormInputData, FormOutputData>): FormScope<FormInputData> => {
8588
const transientFieldRefs = createRefStore<HTMLElement>();
8689
const controlledFieldRefs = createRefStore<HTMLElement>();
8790
const fieldSerializerRefs = createRefStore<FieldSerializer>();
@@ -109,7 +112,7 @@ export const createRvf = <FormInputData extends FieldValues, FormOutputData>({
109112
});
110113
const subformCache = new Map<string, any>();
111114

112-
const rvfStore: RvfStore = {
115+
const rvfStore: FormStore = {
113116
transientFieldRefs,
114117
controlledFieldRefs,
115118
fieldSerializerRefs,
@@ -121,13 +124,13 @@ export const createRvf = <FormInputData extends FieldValues, FormOutputData>({
121124
useStoreState: createTrackedSelector(store),
122125
};
123126

124-
return instantiateRvf<FormInputData>(rvfStore, "");
127+
return instantiateFormScope<FormInputData>(rvfStore, "");
125128
};
126129

127-
const instantiateRvf = <FormInputData extends FieldValues>(
128-
store: RvfStore,
130+
const instantiateFormScope = <FormInputData extends FieldValues>(
131+
store: FormStore,
129132
prefix: string,
130-
): Rvf<FormInputData> => ({
133+
): FormScope<FormInputData> => ({
131134
__brand__: "rvf",
132135
__type__FormInputData: {} as any,
133136
__field_prefix__: prefix,
@@ -137,15 +140,15 @@ const instantiateRvf = <FormInputData extends FieldValues>(
137140
if (store.subformCache.has(newPrefix))
138141
return store.subformCache.get(newPrefix);
139142

140-
const scoped = instantiateRvf(store, newPrefix);
143+
const scoped = instantiateFormScope(store, newPrefix);
141144
store.subformCache.set(newPrefix, scoped);
142145
return scoped;
143146
},
144147
});
145148

146-
export const scopeRvf = (
147-
parentForm: Rvf<unknown>,
149+
export const scopeFormScope = (
150+
parentForm: FormScope<unknown>,
148151
prefix: string,
149-
): Rvf<unknown> => {
152+
): FormScope<unknown> => {
150153
return parentForm.scope(prefix as never);
151154
};

packages/react/src/ValidatedForm.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FieldValues, AllProps } from "@rvf/core";
22
import { FormOpts, useForm } from "./useForm";
3-
import { RvfReact } from "./base";
3+
import { ReactFormApi } from "./base";
44
import { FormProvider } from "./context";
55

66
export type ValidatedFormProps<
@@ -17,7 +17,7 @@ export type ValidatedFormProps<
1717

1818
children:
1919
| React.ReactNode
20-
| ((form: RvfReact<FormInputData>) => React.ReactNode);
20+
| ((form: ReactFormApi<FormInputData>) => React.ReactNode);
2121
};
2222

2323
export const ValidatedForm = <

packages/react/src/array.tsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ReactNode, useMemo } from "react";
22
import {
33
FormStoreValue,
4-
Rvf,
4+
FormScope,
55
getFieldError,
66
getFieldValue,
7-
scopeRvf,
7+
scopeFormScope,
88
getArrayUpdateKey,
99
FieldArrayValidationBehaviorConfig,
1010
} from "@rvf/core";
1111
import { makeImplFactory } from "./implFactory";
12-
import { RvfReact, makeBaseRvfReact } from "./base";
12+
import { ReactFormApi, makeBaseReactFormApi } from "./base";
1313
import { ValidationBehaviorConfig } from "@rvf/core";
1414
import { useFormScopeOrContextInternal } from "./context";
1515

@@ -38,7 +38,7 @@ export interface FieldArrayApi<FormInputData extends Array<any>> {
3838
map: (
3939
callback: (
4040
key: string,
41-
form: RvfReact<FormInputData[number]>,
41+
form: ReactFormApi<FormInputData[number]>,
4242
index: number,
4343
) => ReactNode,
4444
) => ReactNode;
@@ -94,7 +94,7 @@ export interface FieldArrayApi<FormInputData extends Array<any>> {
9494
}
9595

9696
export type FieldArrayParams<FormInputData> = {
97-
form: Rvf<FormInputData>;
97+
form: FormScope<FormInputData>;
9898
arrayFieldName: string;
9999
trackedState: FormStoreValue;
100100
validationBehavior?: FieldArrayValidationBehaviorConfig;
@@ -107,8 +107,10 @@ export const makeFieldArrayImpl = <FormInputData extends Array<any>>({
107107
validationBehavior,
108108
}: FieldArrayParams<FormInputData>): FieldArrayApi<FormInputData> => {
109109
const itemImpl = makeImplFactory(arrayFieldName, (itemFieldName) =>
110-
makeBaseRvfReact({
111-
form: scopeRvf(form, itemFieldName) as Rvf<FormInputData[number]>,
110+
makeBaseReactFormApi({
111+
form: scopeFormScope(form, itemFieldName) as FormScope<
112+
FormInputData[number]
113+
>,
112114
prefix: itemFieldName,
113115
trackedState,
114116
}),
@@ -135,8 +137,8 @@ export const makeFieldArrayImpl = <FormInputData extends Array<any>>({
135137
return trackedState
136138
.getFieldArrayKeys(arrayFieldName)
137139
.map((key, index) => {
138-
const itemRvf = itemImpl(String(index));
139-
return callback(key, itemRvf, index);
140+
const itemFormScope = itemImpl(String(index));
141+
return callback(key, itemFormScope, index);
140142
});
141143
},
142144
push: (value) =>
@@ -182,15 +184,15 @@ export type UseFieldArrayOpts = {
182184
validationBehavior?: FieldArrayValidationBehaviorConfig;
183185
};
184186
export function useFieldArray<FormInputData extends any[]>(
185-
form: Rvf<FormInputData>,
187+
form: FormScope<FormInputData>,
186188
{ validationBehavior }?: UseFieldArrayOpts,
187189
): FieldArrayApi<FormInputData>;
188190
export function useFieldArray<FormInputData extends any[] = unknown[]>(
189191
name: string,
190192
opts?: UseFieldArrayOpts,
191193
): FieldArrayApi<FormInputData>;
192194
export function useFieldArray<FormInputData extends any[]>(
193-
formOrName: Rvf<FormInputData> | string,
195+
formOrName: FormScope<FormInputData> | string,
194196
{ validationBehavior }: UseFieldArrayOpts = {},
195197
) {
196198
const scope = useFormScopeOrContextInternal(formOrName);
@@ -217,7 +219,7 @@ export function useFieldArray<FormInputData extends any[]>(
217219
}
218220

219221
export type FieldArrayPropsWithScope<FormInputData extends any[]> = {
220-
scope: Rvf<FormInputData>;
222+
scope: FormScope<FormInputData>;
221223
children: (field: FieldArrayApi<FormInputData>) => React.ReactNode;
222224
};
223225

packages/react/src/base.tsx

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useEffect, useMemo } from "react";
22
import * as R from "remeda";
33
import {
4-
Rvf,
5-
scopeRvf,
4+
FormScope,
5+
scopeFormScope,
66
SubmitStatus,
77
FormStoreValue,
88
getFieldValue,
@@ -44,12 +44,12 @@ import {
4444
ValidInputPropsValues,
4545
} from "./inputs/getInputProps";
4646

47-
type MinimalRvf<FieldPaths extends string> = {
47+
type MinimalFormScope<FieldPaths extends string> = {
4848
resetField: (fieldName: FieldPaths, nextValue?: any) => void;
4949
};
5050

5151
export type FormFields<Form> =
52-
Form extends MinimalRvf<infer FieldPaths> ? FieldPaths : never;
52+
Form extends MinimalFormScope<infer FieldPaths> ? FieldPaths : never;
5353

5454
interface FormProps {
5555
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
@@ -64,7 +64,7 @@ export type ManualSubmitOption = SubmitterOptions & {
6464
value?: string;
6565
};
6666

67-
export interface RvfReact<FormInputData> {
67+
export interface ReactFormApi<FormInputData> {
6868
/**
6969
* Gets whether the field has been touched.
7070
* @willRerender
@@ -234,14 +234,14 @@ export interface RvfReact<FormInputData> {
234234
) => void;
235235

236236
/**
237-
* Creates an `Rvf` scoped to the specified field.
237+
* Creates an `FormScope` scoped to the specified field.
238238
* This is useful for creating subforms.
239239
* In order to use this, you can pass it to `useForm`.
240240
*
241241
* @example
242242
* ```tsx
243243
* type PersonFormProps = {
244-
* rvf: Rvf<{ name: string }>;
244+
* rvf: FormScope<{ name: string }>;
245245
* }
246246
*
247247
* const PersonForm = ({ rvf }: PersonFormProps) => {
@@ -272,12 +272,12 @@ export interface RvfReact<FormInputData> {
272272
*/
273273
scope<Field extends ValidStringPaths<FormInputData>>(
274274
fieldName: Field,
275-
): Rvf<ValueAtPath<FormInputData, StringToPathTuple<Field>>>;
275+
): FormScope<ValueAtPath<FormInputData, StringToPathTuple<Field>>>;
276276

277277
/**
278-
* Returns an `Rvf` without scoping any further.
278+
* Returns an `FormScope` without scoping any further.
279279
*/
280-
scope(): Rvf<FormInputData>;
280+
scope(): FormScope<FormInputData>;
281281

282282
getFormProps: (props?: Partial<FormProps>) => FormProps;
283283

@@ -369,17 +369,17 @@ export interface RvfReact<FormInputData> {
369369
submit: (option?: ManualSubmitOption) => void;
370370
}
371371

372-
export type BaseRvfReactParams<FormInputData> = {
373-
form: Rvf<FormInputData>;
372+
export type BaseReactFormParams<FormInputData> = {
373+
form: FormScope<FormInputData>;
374374
prefix: string;
375375
trackedState: FormStoreValue;
376376
};
377377

378-
export const makeBaseRvfReact = <FormInputData,>({
378+
export const makeBaseReactFormApi = <FormInputData,>({
379379
trackedState,
380380
prefix,
381381
form,
382-
}: BaseRvfReactParams<FormInputData>): RvfReact<FormInputData> => {
382+
}: BaseReactFormParams<FormInputData>): ReactFormApi<FormInputData> => {
383383
const f = (fieldName?: string) =>
384384
pathArrayToString([prefix, fieldName].filter(R.isNonNullish));
385385
const transientState = () => form.__store__.store.getState();
@@ -392,7 +392,7 @@ export const makeBaseRvfReact = <FormInputData,>({
392392
makeFieldArrayImpl({
393393
trackedState,
394394
arrayFieldName,
395-
form: scopeRvf(form, arrayFieldName) as Rvf<any[]>,
395+
form: scopeFormScope(form, arrayFieldName) as FormScope<any[]>,
396396
}),
397397
);
398398

@@ -505,7 +505,7 @@ export const makeBaseRvfReact = <FormInputData,>({
505505
form.__store__.store.getState().resetField(f(fieldName), nextValue),
506506

507507
scope: (fieldName?: string) =>
508-
fieldName == null ? form : (scopeRvf(form, fieldName) as any),
508+
fieldName == null ? form : (scopeFormScope(form, fieldName) as any),
509509

510510
name: (fieldName?: string) => f(fieldName),
511511

@@ -594,7 +594,9 @@ export const makeBaseRvfReact = <FormInputData,>({
594594
};
595595
};
596596

597-
export const useFormInternal = <FormInputData,>(form: Rvf<FormInputData>) => {
597+
export const useFormInternal = <FormInputData,>(
598+
form: FormScope<FormInputData>,
599+
) => {
598600
const prefix = form.__field_prefix__;
599601
const { useStoreState, resolvers } = form.__store__;
600602
const trackedState = useStoreState();
@@ -610,7 +612,7 @@ export const useFormInternal = <FormInputData,>(form: Rvf<FormInputData>) => {
610612

611613
const base = useMemo(
612614
() =>
613-
makeBaseRvfReact({
615+
makeBaseReactFormApi({
614616
form,
615617
prefix,
616618
trackedState,

0 commit comments

Comments
 (0)