formstand 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +294 -0
- package/README.md +4 -0
- package/dist/index.cjs +61 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -255,10 +255,17 @@ type UseFieldReturn<TValue> = Readonly<{
|
|
|
255
255
|
validateAsync: () => Promise<FieldValidationResult>;
|
|
256
256
|
onBlur: () => void;
|
|
257
257
|
}>;
|
|
258
|
+
declare const inferredCallsOnly$2: unique symbol;
|
|
259
|
+
interface InferredTypeArg$2 {
|
|
260
|
+
readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
|
|
261
|
+
}
|
|
258
262
|
declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
|
|
259
263
|
schema: TSchema;
|
|
260
264
|
store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
|
|
261
265
|
}>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
266
|
+
declare function useField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
|
|
267
|
+
schema: z.ZodType;
|
|
268
|
+
}>, path: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
262
269
|
declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
263
270
|
readonly schema?: undefined;
|
|
264
271
|
}, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
@@ -269,10 +276,17 @@ type CommonKeys<V> = keyof V;
|
|
|
269
276
|
type AllKeys<V> = V extends unknown ? keyof V : never;
|
|
270
277
|
type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
|
|
271
278
|
type UnionValueAt<TValues, P extends string> = P extends keyof TValues ? NonNullable<TValues[P]> : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : never : never;
|
|
272
|
-
declare
|
|
279
|
+
declare const inferredCallsOnly$1: unique symbol;
|
|
280
|
+
interface InferredTypeArg$1 {
|
|
281
|
+
readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
|
|
282
|
+
}
|
|
283
|
+
declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi & Readonly<{
|
|
284
|
+
schema: z.ZodType;
|
|
285
|
+
}>, unionPath: TValue extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
|
|
273
286
|
declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
|
|
274
287
|
readonly schema?: undefined;
|
|
275
288
|
}, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
|
|
289
|
+
declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends VariantKeys<UnionValueAt<z.input<TSchema>, P>>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, unionPath: P, field: TField): UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
|
|
276
290
|
|
|
277
291
|
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
278
292
|
type FieldArrayFormApi = Readonly<{
|
|
@@ -282,6 +296,7 @@ type FieldArrayFormApi = Readonly<{
|
|
|
282
296
|
arrayInsert(path: string, index: number, item: unknown): void;
|
|
283
297
|
arrayMove(path: string, from: number, to: number): void;
|
|
284
298
|
arraySwap(path: string, a: number, b: number): void;
|
|
299
|
+
validateField?(path: string): FieldValidationResult;
|
|
285
300
|
}>;
|
|
286
301
|
type FieldArrayEntry<TItem> = Readonly<{
|
|
287
302
|
id: string;
|
|
@@ -299,10 +314,17 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
299
314
|
swap: (a: number, b: number) => void;
|
|
300
315
|
}>;
|
|
301
316
|
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
317
|
+
declare const inferredCallsOnly: unique symbol;
|
|
318
|
+
interface InferredTypeArg {
|
|
319
|
+
readonly [inferredCallsOnly]: typeof inferredCallsOnly;
|
|
320
|
+
}
|
|
302
321
|
declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
|
|
303
322
|
schema: TSchema;
|
|
304
323
|
store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
|
|
305
324
|
}>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
325
|
+
declare function useFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
|
|
326
|
+
schema: z.ZodType;
|
|
327
|
+
}>, path: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
|
|
306
328
|
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
307
329
|
readonly schema?: undefined;
|
|
308
330
|
}, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
|
|
@@ -355,6 +377,11 @@ declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
|
355
377
|
readonly schema?: undefined;
|
|
356
378
|
}, selector: (state: FormState<unknown>) => U): U;
|
|
357
379
|
|
|
380
|
+
declare function useFormValues<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>): z.input<TSchema>;
|
|
381
|
+
declare function useFormValues(form: FormStateApi & {
|
|
382
|
+
readonly schema?: undefined;
|
|
383
|
+
}): unknown;
|
|
384
|
+
|
|
358
385
|
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
359
386
|
|
|
360
387
|
declare function useIsDirty(form: FormStateApi & {
|
|
@@ -497,4 +524,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
497
524
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
498
525
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
499
526
|
|
|
500
|
-
export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, type DefaultPathDepth, type ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, type FieldPath, type FieldPathArg, type FieldRef, type FieldSnapshot, type FieldValidationResult, type FieldValue, type FieldsValidationResult, type Form, type FormContextApi, type FormHooks, type FormProviderProps, type FormState, type FormStateApi, type InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, type PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, type ReadonlyStoreApi, type ResetOptions, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SettledFieldValidationResult, type SettledFieldsValidationResult, type SettledValidationResult, type SubmitHandler, type SubmitOptions, type SubmitResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type ValidationMode, type ValidationResult, type ValidationTrigger, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
|
|
527
|
+
export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, type DefaultPathDepth, type ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, type FieldPath, type FieldPathArg, type FieldRef, type FieldSnapshot, type FieldValidationResult, type FieldValue, type FieldsValidationResult, type Form, type FormContextApi, type FormHooks, type FormProviderProps, type FormState, type FormStateApi, type InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, type PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, type ReadonlyStoreApi, type ResetOptions, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SettledFieldValidationResult, type SettledFieldsValidationResult, type SettledValidationResult, type SubmitHandler, type SubmitOptions, type SubmitResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type ValidationMode, type ValidationResult, type ValidationTrigger, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -255,10 +255,17 @@ type UseFieldReturn<TValue> = Readonly<{
|
|
|
255
255
|
validateAsync: () => Promise<FieldValidationResult>;
|
|
256
256
|
onBlur: () => void;
|
|
257
257
|
}>;
|
|
258
|
+
declare const inferredCallsOnly$2: unique symbol;
|
|
259
|
+
interface InferredTypeArg$2 {
|
|
260
|
+
readonly [inferredCallsOnly$2]: typeof inferredCallsOnly$2;
|
|
261
|
+
}
|
|
258
262
|
declare function useField<TSchema extends z.ZodType>(form: FieldFormApi & Readonly<{
|
|
259
263
|
schema: TSchema;
|
|
260
264
|
store: ReadonlyStore$2<FormState<z.input<TSchema>>>;
|
|
261
265
|
}>, pathSelector: (state: FormState<z.input<TSchema>>) => string, options?: UseFieldOptions): UseFieldReturn<unknown>;
|
|
266
|
+
declare function useField<TValue = InferredTypeArg$2>(form: FieldFormApi & Readonly<{
|
|
267
|
+
schema: z.ZodType;
|
|
268
|
+
}>, path: TValue extends InferredTypeArg$2 ? never : "Remove the explicit type argument: a schema-typed form infers the value type from the path", options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
262
269
|
declare function useField<TValue = unknown>(form: FieldFormApi & {
|
|
263
270
|
readonly schema?: undefined;
|
|
264
271
|
}, path: FieldPathArg<unknown>, options?: UseFieldOptions): UseFieldReturn<TValue>;
|
|
@@ -269,10 +276,17 @@ type CommonKeys<V> = keyof V;
|
|
|
269
276
|
type AllKeys<V> = V extends unknown ? keyof V : never;
|
|
270
277
|
type VariantKeys<V> = Exclude<AllKeys<V>, CommonKeys<V>> & string;
|
|
271
278
|
type UnionValueAt<TValues, P extends string> = P extends keyof TValues ? NonNullable<TValues[P]> : P extends `${infer Head}.${infer Tail}` ? Head extends keyof TValues ? UnionValueAt<NonNullable<TValues[Head]>, Tail> : never : never;
|
|
272
|
-
declare
|
|
279
|
+
declare const inferredCallsOnly$1: unique symbol;
|
|
280
|
+
interface InferredTypeArg$1 {
|
|
281
|
+
readonly [inferredCallsOnly$1]: typeof inferredCallsOnly$1;
|
|
282
|
+
}
|
|
283
|
+
declare function useVariantField<TValue = InferredTypeArg$1>(form: FieldFormApi & Readonly<{
|
|
284
|
+
schema: z.ZodType;
|
|
285
|
+
}>, unionPath: TValue extends InferredTypeArg$1 ? never : "Remove the explicit type argument: a schema-typed form infers the variant value from the union path and field", field: string): UseFieldReturn<TValue | undefined>;
|
|
273
286
|
declare function useVariantField<TValue = unknown>(form: FieldFormApi & {
|
|
274
287
|
readonly schema?: undefined;
|
|
275
288
|
}, unionPath: string, field: string): UseFieldReturn<TValue | undefined>;
|
|
289
|
+
declare function useVariantField<TSchema extends z.ZodType, P extends string, TField extends VariantKeys<UnionValueAt<z.input<TSchema>, P>>, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, unionPath: P, field: TField): UseFieldReturn<VariantFieldValue<UnionValueAt<z.input<TSchema>, P>, TField> | undefined>;
|
|
276
290
|
|
|
277
291
|
type ReadonlyStore$1<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
|
|
278
292
|
type FieldArrayFormApi = Readonly<{
|
|
@@ -282,6 +296,7 @@ type FieldArrayFormApi = Readonly<{
|
|
|
282
296
|
arrayInsert(path: string, index: number, item: unknown): void;
|
|
283
297
|
arrayMove(path: string, from: number, to: number): void;
|
|
284
298
|
arraySwap(path: string, a: number, b: number): void;
|
|
299
|
+
validateField?(path: string): FieldValidationResult;
|
|
285
300
|
}>;
|
|
286
301
|
type FieldArrayEntry<TItem> = Readonly<{
|
|
287
302
|
id: string;
|
|
@@ -299,10 +314,17 @@ type UseFieldArrayReturn<TItem> = Readonly<{
|
|
|
299
314
|
swap: (a: number, b: number) => void;
|
|
300
315
|
}>;
|
|
301
316
|
type ArrayItemOf<T> = [NonNullable<T>] extends [readonly (infer U)[]] ? U : never;
|
|
317
|
+
declare const inferredCallsOnly: unique symbol;
|
|
318
|
+
interface InferredTypeArg {
|
|
319
|
+
readonly [inferredCallsOnly]: typeof inferredCallsOnly;
|
|
320
|
+
}
|
|
302
321
|
declare function useFieldArray<TSchema extends z.ZodType>(form: FieldArrayFormApi & Readonly<{
|
|
303
322
|
schema: TSchema;
|
|
304
323
|
store: ReadonlyStore$1<FormState<z.input<TSchema>>>;
|
|
305
324
|
}>, pathSelector: (state: FormState<z.input<TSchema>>) => string): UseFieldArrayReturn<unknown>;
|
|
325
|
+
declare function useFieldArray<TItem = InferredTypeArg>(form: FieldArrayFormApi & Readonly<{
|
|
326
|
+
schema: z.ZodType;
|
|
327
|
+
}>, path: TItem extends InferredTypeArg ? never : "Remove the explicit type argument: a schema-typed form infers the item type from the path"): UseFieldArrayReturn<TItem>;
|
|
306
328
|
declare function useFieldArray<TItem = unknown>(form: FieldArrayFormApi & {
|
|
307
329
|
readonly schema?: undefined;
|
|
308
330
|
}, path: FieldPathArg<unknown>): UseFieldArrayReturn<TItem>;
|
|
@@ -355,6 +377,11 @@ declare function useFormSelectorShallow<U>(form: FormStateApi & {
|
|
|
355
377
|
readonly schema?: undefined;
|
|
356
378
|
}, selector: (state: FormState<unknown>) => U): U;
|
|
357
379
|
|
|
380
|
+
declare function useFormValues<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>): z.input<TSchema>;
|
|
381
|
+
declare function useFormValues(form: FormStateApi & {
|
|
382
|
+
readonly schema?: undefined;
|
|
383
|
+
}): unknown;
|
|
384
|
+
|
|
358
385
|
declare const useFormError: (form: FormStateApi) => readonly string[] | undefined;
|
|
359
386
|
|
|
360
387
|
declare function useIsDirty(form: FormStateApi & {
|
|
@@ -497,4 +524,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
497
524
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
498
525
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
499
526
|
|
|
500
|
-
export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, type DefaultPathDepth, type ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, type FieldPath, type FieldPathArg, type FieldRef, type FieldSnapshot, type FieldValidationResult, type FieldValue, type FieldsValidationResult, type Form, type FormContextApi, type FormHooks, type FormProviderProps, type FormState, type FormStateApi, type InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, type PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, type ReadonlyStoreApi, type ResetOptions, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SettledFieldValidationResult, type SettledFieldsValidationResult, type SettledValidationResult, type SubmitHandler, type SubmitOptions, type SubmitResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type ValidationMode, type ValidationResult, type ValidationTrigger, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
|
|
527
|
+
export { type BoolMap, type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, type CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, type DefaultPathDepth, type ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, type FieldPath, type FieldPathArg, type FieldRef, type FieldSnapshot, type FieldValidationResult, type FieldValue, type FieldsValidationResult, type Form, type FormContextApi, type FormHooks, type FormProviderProps, type FormState, type FormStateApi, type InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, type PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, type ReadonlyStoreApi, type ResetOptions, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, type SettledFieldValidationResult, type SettledFieldsValidationResult, type SettledValidationResult, type SubmitHandler, type SubmitOptions, type SubmitResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type ValidationMode, type ValidationResult, type ValidationTrigger, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
|
package/dist/index.js
CHANGED
|
@@ -179,6 +179,14 @@ var slotAtPath = (obj, path) => {
|
|
|
179
179
|
);
|
|
180
180
|
return walked.ok ? { exists: true, value: walked.current } : { exists: false };
|
|
181
181
|
};
|
|
182
|
+
var hasOwnSlot = (obj, path) => parsePath(path).reduce(
|
|
183
|
+
(acc, segment) => {
|
|
184
|
+
const container = acc.current;
|
|
185
|
+
const owns = Array.isArray(container) ? typeof segment === "number" && segment < container.length : isPlainRecord(container) && Object.hasOwn(container, String(segment));
|
|
186
|
+
return !acc.ok || !owns ? { ok: false, current: void 0 } : { ok: true, current: readSegment(container, segment) };
|
|
187
|
+
},
|
|
188
|
+
{ ok: true, current: obj }
|
|
189
|
+
).ok;
|
|
182
190
|
var writeIntoArray = (arr, index, rest, value) => {
|
|
183
191
|
const length = Math.max(arr.length, index + 1);
|
|
184
192
|
return Array.from(
|
|
@@ -881,6 +889,10 @@ var createForm = (schema, options) => {
|
|
|
881
889
|
});
|
|
882
890
|
},
|
|
883
891
|
setValue: (path, value) => {
|
|
892
|
+
const currentValues = store.getState().values;
|
|
893
|
+
if (Object.is(getAtPath(currentValues, path), value) && (value !== void 0 || hasOwnSlot(currentValues, path))) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
884
896
|
clearArrayOpsUnder(store, path);
|
|
885
897
|
store.setState((state) => ({
|
|
886
898
|
...state,
|
|
@@ -1278,8 +1290,10 @@ function useField(form, pathArg, options) {
|
|
|
1278
1290
|
}, [form, path, debounceMs]);
|
|
1279
1291
|
const setValue = useCallback(
|
|
1280
1292
|
(value) => {
|
|
1293
|
+
const before = form.store.getState();
|
|
1281
1294
|
form.setValue(path, value);
|
|
1282
1295
|
const state = form.store.getState();
|
|
1296
|
+
if (state === before) return;
|
|
1283
1297
|
if (shouldValidateOn(
|
|
1284
1298
|
"change",
|
|
1285
1299
|
state.mode,
|
|
@@ -1473,25 +1487,52 @@ function useFieldArray(form, pathArg) {
|
|
|
1473
1487
|
const items = slice.items;
|
|
1474
1488
|
const error = slice.error;
|
|
1475
1489
|
const ids = deriveIds(form.store, path, items).ids;
|
|
1490
|
+
const revalidate = useCallback(() => {
|
|
1491
|
+
const state = form.store.getState();
|
|
1492
|
+
if (shouldValidateOn(
|
|
1493
|
+
"change",
|
|
1494
|
+
state.mode,
|
|
1495
|
+
state.reValidateMode,
|
|
1496
|
+
state.submitCount > 0,
|
|
1497
|
+
state.touched[path] ?? false
|
|
1498
|
+
)) {
|
|
1499
|
+
form.validateField?.(path);
|
|
1500
|
+
}
|
|
1501
|
+
}, [form, path]);
|
|
1476
1502
|
const push = useCallback(
|
|
1477
|
-
(item) =>
|
|
1478
|
-
|
|
1503
|
+
(item) => {
|
|
1504
|
+
form.arrayPush(path, item);
|
|
1505
|
+
revalidate();
|
|
1506
|
+
},
|
|
1507
|
+
[form, path, revalidate]
|
|
1479
1508
|
);
|
|
1480
1509
|
const remove = useCallback(
|
|
1481
|
-
(index) =>
|
|
1482
|
-
|
|
1510
|
+
(index) => {
|
|
1511
|
+
form.arrayRemove(path, index);
|
|
1512
|
+
revalidate();
|
|
1513
|
+
},
|
|
1514
|
+
[form, path, revalidate]
|
|
1483
1515
|
);
|
|
1484
1516
|
const insert = useCallback(
|
|
1485
|
-
(index, item) =>
|
|
1486
|
-
|
|
1517
|
+
(index, item) => {
|
|
1518
|
+
form.arrayInsert(path, index, item);
|
|
1519
|
+
revalidate();
|
|
1520
|
+
},
|
|
1521
|
+
[form, path, revalidate]
|
|
1487
1522
|
);
|
|
1488
1523
|
const move = useCallback(
|
|
1489
|
-
(from, to) =>
|
|
1490
|
-
|
|
1524
|
+
(from, to) => {
|
|
1525
|
+
form.arrayMove(path, from, to);
|
|
1526
|
+
revalidate();
|
|
1527
|
+
},
|
|
1528
|
+
[form, path, revalidate]
|
|
1491
1529
|
);
|
|
1492
1530
|
const swap = useCallback(
|
|
1493
|
-
(a, b) =>
|
|
1494
|
-
|
|
1531
|
+
(a, b) => {
|
|
1532
|
+
form.arraySwap(path, a, b);
|
|
1533
|
+
revalidate();
|
|
1534
|
+
},
|
|
1535
|
+
[form, path, revalidate]
|
|
1495
1536
|
);
|
|
1496
1537
|
const fields = useMemo(
|
|
1497
1538
|
() => items.map((value, index) => ({
|
|
@@ -1580,6 +1621,9 @@ var createFormHooks = (form, name) => {
|
|
|
1580
1621
|
[`use${prefix}SubmitCount`]: useBoundSubmitCount
|
|
1581
1622
|
};
|
|
1582
1623
|
};
|
|
1624
|
+
function useFormValues(form) {
|
|
1625
|
+
return useStore(form.store, (state) => state.values);
|
|
1626
|
+
}
|
|
1583
1627
|
|
|
1584
1628
|
// src/react/inputProps.ts
|
|
1585
1629
|
var hasFieldError = (error) => error !== void 0 && error.length > 0;
|
|
@@ -1932,7 +1976,10 @@ var nameMatchesAny = (el, paths) => {
|
|
|
1932
1976
|
const name = el.getAttribute("name");
|
|
1933
1977
|
return name !== null && paths.some((p) => isPathOrChild(name, p));
|
|
1934
1978
|
};
|
|
1935
|
-
var cssQuoted = (value) => `"${value.replace(/[\\"]/g, (ch) => `\\${ch}`)
|
|
1979
|
+
var cssQuoted = (value) => `"${value.replace(/[\\"]/g, (ch) => `\\${ch}`).replace(
|
|
1980
|
+
/[\x00-\x1f\x7f]/g,
|
|
1981
|
+
(ch) => `\\${ch.codePointAt(0).toString(16)} `
|
|
1982
|
+
)}"`;
|
|
1936
1983
|
var idMatches = (scope, path) => path === "" ? [] : [...scope.querySelectorAll(`[id=${cssQuoted(path)}]`)];
|
|
1937
1984
|
var inDomOrder = (els) => [...els].sort(
|
|
1938
1985
|
(a, b) => a === b ? 0 : (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0 ? -1 : 1
|
|
@@ -1940,8 +1987,9 @@ var inDomOrder = (els) => [...els].sort(
|
|
|
1940
1987
|
var pathCandidates = (scope, paths) => {
|
|
1941
1988
|
const controls = namedControls(scope);
|
|
1942
1989
|
const named = controls.filter((el) => nameMatchesAny(el, paths));
|
|
1990
|
+
const focusableControls = controls.filter(isFocusCandidate);
|
|
1943
1991
|
const unnamedPaths = paths.filter(
|
|
1944
|
-
(p) => !
|
|
1992
|
+
(p) => !focusableControls.some((el) => nameMatchesAny(el, [p]))
|
|
1945
1993
|
);
|
|
1946
1994
|
const byId = unnamedPaths.flatMap((p) => idMatches(scope, p));
|
|
1947
1995
|
return inDomOrder([.../* @__PURE__ */ new Set([...named, ...byId])]);
|
|
@@ -1965,6 +2013,6 @@ var focusField = (path, root) => {
|
|
|
1965
2013
|
return path === "" ? (root !== void 0 || document.querySelectorAll("form").length <= 1) && focusFirstOf(namedControls(scope).filter(isFocusCandidate)) : focusFirstOf(pathCandidates(scope, [path]).filter(isFocusCandidate));
|
|
1966
2014
|
};
|
|
1967
2015
|
|
|
1968
|
-
export { CheckboxField, DateField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
|
|
2016
|
+
export { CheckboxField, DateField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, getAtPath, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, shouldValidateOn, textInputProps, useField, useFieldArray, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useNumberInput, useSubmitCount, useVariantField, validateAsync, validateSync };
|
|
1969
2017
|
//# sourceMappingURL=index.js.map
|
|
1970
2018
|
//# sourceMappingURL=index.js.map
|