formstand 0.17.0 → 0.19.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 +81 -0
- package/dist/{createForm-D0xLZH-Q.d.cts → createForm-B73p1TgL.d.cts} +2 -1
- package/dist/{createForm-D0xLZH-Q.d.ts → createForm-B73p1TgL.d.ts} +2 -1
- package/dist/devtools/index.d.cts +1 -1
- package/dist/devtools/index.d.ts +1 -1
- package/dist/index.cjs +66 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -4
- package/dist/index.d.ts +14 -4
- package/dist/index.js +65 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-
|
|
2
|
-
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult,
|
|
1
|
+
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, I as InvalidSubmitHandler, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-B73p1TgL.cjs';
|
|
2
|
+
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult, R as ReadonlyStoreApi, g as ResetOptions, h as SettledFieldsValidationResult, i as SettledValidationResult, j as SubmitHandler, k as SubmitOptions, l as SubmitResult, V as ValidationMode, m as ValidationResult, n as ValidationTrigger, o as createForm, p as emptyValueForSchema, q as flattenIssues, r as isAsyncRequiredError, s as isClearableSchema, t as shouldValidateOn, v as validateAsync, u as validateSync } from './createForm-B73p1TgL.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ReactNode, ChangeEvent } from 'react';
|
|
@@ -23,7 +23,7 @@ type PersistOptions<TSchema extends z.ZodType> = Readonly<{
|
|
|
23
23
|
apply?: "adopt" | "restore" | "manual";
|
|
24
24
|
}>;
|
|
25
25
|
type PersistHandle = Readonly<{
|
|
26
|
-
|
|
26
|
+
load: () => boolean;
|
|
27
27
|
clear: () => void;
|
|
28
28
|
dispose: () => void;
|
|
29
29
|
}>;
|
|
@@ -33,6 +33,15 @@ declare const usePersistForm: <TSchema extends z.ZodType, D extends PathDepth =
|
|
|
33
33
|
|
|
34
34
|
declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
|
|
35
35
|
|
|
36
|
+
type FormActionHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>, formData: FormData) => void | Promise<void>;
|
|
37
|
+
type FormActionStateHandler<TSchema extends z.ZodType, S> = (prevState: S, data: z.output<TSchema>, formData: FormData) => S | Promise<S>;
|
|
38
|
+
type FormActionOptions = Readonly<{
|
|
39
|
+
onInvalid?: InvalidSubmitHandler;
|
|
40
|
+
onError?: (error: unknown) => void;
|
|
41
|
+
}>;
|
|
42
|
+
declare const useFormAction: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, onValid: FormActionHandler<TSchema>, options?: FormActionOptions) => ((formData: FormData) => Promise<void>);
|
|
43
|
+
declare const useFormActionState: <TSchema extends z.ZodType, S, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, action: FormActionStateHandler<TSchema, S>, initialState: S, options?: FormActionOptions) => [state: S, formAction: (formData: FormData) => void, isPending: boolean];
|
|
44
|
+
|
|
36
45
|
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
37
46
|
form: Form<TSchema, D>;
|
|
38
47
|
children: ReactNode;
|
|
@@ -62,6 +71,7 @@ type UseFieldReturn<TValue> = Readonly<{
|
|
|
62
71
|
value: TValue;
|
|
63
72
|
initialValue: TValue;
|
|
64
73
|
emptyValue: null | undefined;
|
|
74
|
+
clearable: boolean;
|
|
65
75
|
error: readonly string[] | undefined;
|
|
66
76
|
firstError: string | undefined;
|
|
67
77
|
touched: boolean;
|
|
@@ -379,4 +389,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
379
389
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
380
390
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
381
391
|
|
|
382
|
-
export { type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, DefaultPathDepth, ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, FieldPath, type FieldPathArg, type FieldRef, FieldValidationResult, FieldValue, Form, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, SettledFieldValidationResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
|
392
|
+
export { type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, DefaultPathDepth, ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, FieldPath, type FieldPathArg, type FieldRef, FieldValidationResult, FieldValue, Form, type FormActionHandler, type FormActionOptions, type FormActionStateHandler, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, SettledFieldValidationResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-
|
|
2
|
-
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult,
|
|
1
|
+
import { P as PathDepth, D as DefaultPathDepth, F as Form, C as CreateFormOptions, I as InvalidSubmitHandler, a as FieldValidationResult, S as SettledFieldValidationResult, b as FormState, c as FieldPath, d as FieldValue, E as ErrorMap } from './createForm-B73p1TgL.js';
|
|
2
|
+
export { B as BoolMap, e as FieldSnapshot, f as FieldsValidationResult, R as ReadonlyStoreApi, g as ResetOptions, h as SettledFieldsValidationResult, i as SettledValidationResult, j as SubmitHandler, k as SubmitOptions, l as SubmitResult, V as ValidationMode, m as ValidationResult, n as ValidationTrigger, o as createForm, p as emptyValueForSchema, q as flattenIssues, r as isAsyncRequiredError, s as isClearableSchema, t as shouldValidateOn, v as validateAsync, u as validateSync } from './createForm-B73p1TgL.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ReactNode, ChangeEvent } from 'react';
|
|
@@ -23,7 +23,7 @@ type PersistOptions<TSchema extends z.ZodType> = Readonly<{
|
|
|
23
23
|
apply?: "adopt" | "restore" | "manual";
|
|
24
24
|
}>;
|
|
25
25
|
type PersistHandle = Readonly<{
|
|
26
|
-
|
|
26
|
+
load: () => boolean;
|
|
27
27
|
clear: () => void;
|
|
28
28
|
dispose: () => void;
|
|
29
29
|
}>;
|
|
@@ -33,6 +33,15 @@ declare const usePersistForm: <TSchema extends z.ZodType, D extends PathDepth =
|
|
|
33
33
|
|
|
34
34
|
declare const useForm: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(schema: TSchema, options: CreateFormOptions<TSchema, D>) => Form<TSchema, D>;
|
|
35
35
|
|
|
36
|
+
type FormActionHandler<TSchema extends z.ZodType> = (data: z.output<TSchema>, formData: FormData) => void | Promise<void>;
|
|
37
|
+
type FormActionStateHandler<TSchema extends z.ZodType, S> = (prevState: S, data: z.output<TSchema>, formData: FormData) => S | Promise<S>;
|
|
38
|
+
type FormActionOptions = Readonly<{
|
|
39
|
+
onInvalid?: InvalidSubmitHandler;
|
|
40
|
+
onError?: (error: unknown) => void;
|
|
41
|
+
}>;
|
|
42
|
+
declare const useFormAction: <TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, onValid: FormActionHandler<TSchema>, options?: FormActionOptions) => ((formData: FormData) => Promise<void>);
|
|
43
|
+
declare const useFormActionState: <TSchema extends z.ZodType, S, D extends PathDepth = DefaultPathDepth>(form: Form<TSchema, D>, action: FormActionStateHandler<TSchema, S>, initialState: S, options?: FormActionOptions) => [state: S, formAction: (formData: FormData) => void, isPending: boolean];
|
|
44
|
+
|
|
36
45
|
type FormProviderProps<TSchema extends z.ZodType, D extends PathDepth = DefaultPathDepth> = Readonly<{
|
|
37
46
|
form: Form<TSchema, D>;
|
|
38
47
|
children: ReactNode;
|
|
@@ -62,6 +71,7 @@ type UseFieldReturn<TValue> = Readonly<{
|
|
|
62
71
|
value: TValue;
|
|
63
72
|
initialValue: TValue;
|
|
64
73
|
emptyValue: null | undefined;
|
|
74
|
+
clearable: boolean;
|
|
65
75
|
error: readonly string[] | undefined;
|
|
66
76
|
firstError: string | undefined;
|
|
67
77
|
touched: boolean;
|
|
@@ -379,4 +389,4 @@ declare const dateInputProps: <T extends Date | null | undefined>(field: UseFiel
|
|
|
379
389
|
declare const checkboxProps: <T extends boolean | null | undefined>(field: UseFieldReturn<T>) => CheckboxProps;
|
|
380
390
|
declare const selectProps: <T extends string | null | undefined>(field: UseFieldReturn<T>) => SelectProps;
|
|
381
391
|
|
|
382
|
-
export { type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, DefaultPathDepth, ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, FieldPath, type FieldPathArg, type FieldRef, FieldValidationResult, FieldValue, Form, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, SettledFieldValidationResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
|
392
|
+
export { type BoundUseField, type BoundUseFieldArray, type BoundUseFlag, type BoundUseSelector, CheckboxField, type CheckboxFieldProps, type CheckboxProps, CreateFormOptions, DateField, type DateFieldProps, type DateInputProps, DefaultPathDepth, ErrorMap, type FieldArrayEntry, type FieldArrayFormApi, type FieldFormApi, FieldPath, type FieldPathArg, type FieldRef, FieldValidationResult, FieldValue, Form, type FormActionHandler, type FormActionOptions, type FormActionStateHandler, type FormContextApi, type FormHooks, type FormProviderProps, FormState, type FormStateApi, InvalidSubmitHandler, NumberField, type NumberFieldProps, type NumberInputBinding, type NumberInputProps, type ParsedDateText, type ParsedNumberText, PathDepth, type PathSegment, type PathsOf, type PersistHandle, type PersistOptions, type PersistStorage, SelectField, type SelectFieldOption, type SelectFieldProps, type SelectProps, SettledFieldValidationResult, TextField, type TextFieldProps, type TextInputProps, type UseFieldArrayReturn, type UseFieldOptions, type UseFieldReturn, type UseFieldsReturn, checkboxProps, createFormContext, createFormHooks, dateInputProps, dateToInputText, focusField, focusFirstError, getAtPath, hasFieldError, numberInputProps, numberToInputText, parseDateText, parseNumberText, parsePath, persistForm, selectProps, setAtPath, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormSelector, useFormSelectorShallow, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { getAtPath, parsePath, setAtPath, useFormSelector, useFormSelectorShallo
|
|
|
3
3
|
import { createStore } from 'zustand/vanilla';
|
|
4
4
|
import { devtools } from 'zustand/middleware';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import { useRef, useEffect, useMemo,
|
|
6
|
+
import { useRef, useEffect, useMemo, useCallback, useActionState, createContext, useState, useContext, useId } from 'react';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import { useStore } from 'zustand/react';
|
|
9
9
|
import { useShallow } from 'zustand/react/shallow';
|
|
@@ -142,6 +142,7 @@ var emptyValueForSchema = (schema) => {
|
|
|
142
142
|
};
|
|
143
143
|
return walk(schema, false);
|
|
144
144
|
};
|
|
145
|
+
var isClearableSchema = (schema) => schema instanceof z.ZodOptional || schema instanceof z.ZodNullable || schema instanceof z.ZodDefault || schema instanceof z.ZodPrefault;
|
|
145
146
|
var unwrapForWalk = (s) => {
|
|
146
147
|
if (s instanceof z.ZodOptional || s instanceof z.ZodNullable) {
|
|
147
148
|
return s.unwrap();
|
|
@@ -1063,7 +1064,7 @@ var persistForm = (form, options) => {
|
|
|
1063
1064
|
return void 0;
|
|
1064
1065
|
}
|
|
1065
1066
|
};
|
|
1066
|
-
const
|
|
1067
|
+
const load = () => {
|
|
1067
1068
|
try {
|
|
1068
1069
|
const raw = storage === null ? null : storage.getItem(options.key);
|
|
1069
1070
|
if (raw === null) return false;
|
|
@@ -1108,7 +1109,7 @@ var persistForm = (form, options) => {
|
|
|
1108
1109
|
}
|
|
1109
1110
|
};
|
|
1110
1111
|
if (apply !== "manual") {
|
|
1111
|
-
|
|
1112
|
+
load();
|
|
1112
1113
|
}
|
|
1113
1114
|
const unsubscribe = form.watchValues((values) => {
|
|
1114
1115
|
cancelPending();
|
|
@@ -1122,7 +1123,7 @@ var persistForm = (form, options) => {
|
|
|
1122
1123
|
}
|
|
1123
1124
|
});
|
|
1124
1125
|
return Object.freeze({
|
|
1125
|
-
|
|
1126
|
+
load,
|
|
1126
1127
|
clear: () => {
|
|
1127
1128
|
cancelPending();
|
|
1128
1129
|
try {
|
|
@@ -1153,7 +1154,7 @@ var usePersistForm = (form, options) => {
|
|
|
1153
1154
|
}, [form, key]);
|
|
1154
1155
|
return useMemo(
|
|
1155
1156
|
() => ({
|
|
1156
|
-
|
|
1157
|
+
load: () => inner.current?.load() ?? false,
|
|
1157
1158
|
clear: () => inner.current?.clear(),
|
|
1158
1159
|
// dispose stops THIS component's watching early; the effect cleanup
|
|
1159
1160
|
// still runs its own dispose harmlessly (persistForm's dispose is
|
|
@@ -1182,6 +1183,51 @@ var useForm = (schema, options) => {
|
|
|
1182
1183
|
}, [form, schema, options.initialValues]);
|
|
1183
1184
|
return form;
|
|
1184
1185
|
};
|
|
1186
|
+
var warnUnobserved = (result, options, site) => {
|
|
1187
|
+
if (result.kind === "error" && options?.onError === void 0 && process.env.NODE_ENV !== "production") {
|
|
1188
|
+
console.warn(
|
|
1189
|
+
`[formstand] action handler threw and nothing observed it \u2014 the form shows no feedback. Pass { onError } to ${site} (or setError inside your handler):`,
|
|
1190
|
+
result.error
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
var useFormAction = (form, onValid, options) => {
|
|
1195
|
+
const latest = useRef({ onValid, options });
|
|
1196
|
+
useEffect(() => {
|
|
1197
|
+
latest.current = { onValid, options };
|
|
1198
|
+
});
|
|
1199
|
+
return useCallback(
|
|
1200
|
+
async (formData) => {
|
|
1201
|
+
const { onValid: handler, options: opts } = latest.current;
|
|
1202
|
+
const result = await form.submit(
|
|
1203
|
+
(data) => handler(data, formData),
|
|
1204
|
+
opts?.onInvalid,
|
|
1205
|
+
opts?.onError === void 0 ? void 0 : { onError: opts.onError }
|
|
1206
|
+
);
|
|
1207
|
+
warnUnobserved(result, opts, "useFormAction");
|
|
1208
|
+
},
|
|
1209
|
+
[form]
|
|
1210
|
+
);
|
|
1211
|
+
};
|
|
1212
|
+
var useFormActionState = (form, action, initialState, options) => {
|
|
1213
|
+
const [state, formAction, isPending] = useActionState(
|
|
1214
|
+
async (prevState, formData) => {
|
|
1215
|
+
const prev = prevState;
|
|
1216
|
+
const nextRef = { current: prev };
|
|
1217
|
+
const result = await form.submit(
|
|
1218
|
+
async (data) => {
|
|
1219
|
+
nextRef.current = await action(prev, data, formData);
|
|
1220
|
+
},
|
|
1221
|
+
options?.onInvalid,
|
|
1222
|
+
options?.onError === void 0 ? void 0 : { onError: options.onError }
|
|
1223
|
+
);
|
|
1224
|
+
warnUnobserved(result, options, "useFormActionState");
|
|
1225
|
+
return nextRef.current;
|
|
1226
|
+
},
|
|
1227
|
+
initialState
|
|
1228
|
+
);
|
|
1229
|
+
return [state, formAction, isPending];
|
|
1230
|
+
};
|
|
1185
1231
|
var createFormContext = () => {
|
|
1186
1232
|
const Context = createContext(null);
|
|
1187
1233
|
const Provider = ({ form, children }) => /* @__PURE__ */ jsx(Context.Provider, { value: form, children });
|
|
@@ -1217,12 +1263,17 @@ function useField(form, pathArg, options) {
|
|
|
1217
1263
|
const path = slice.path;
|
|
1218
1264
|
const formSchema = form.schema;
|
|
1219
1265
|
const initialValue = slice.initialValue;
|
|
1220
|
-
const emptyValue = useMemo(() => {
|
|
1266
|
+
const { emptyValue, clearable } = useMemo(() => {
|
|
1221
1267
|
if (formSchema !== void 0) {
|
|
1222
1268
|
const sub = fieldSchemaAtPath(formSchema, path);
|
|
1223
|
-
if (sub !== null)
|
|
1269
|
+
if (sub !== null) {
|
|
1270
|
+
return {
|
|
1271
|
+
emptyValue: emptyValueForSchema(sub),
|
|
1272
|
+
clearable: isClearableSchema(sub)
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1224
1275
|
}
|
|
1225
|
-
return initialValue === null ? null : void 0;
|
|
1276
|
+
return initialValue === null ? { emptyValue: null, clearable: true } : { emptyValue: void 0, clearable: false };
|
|
1226
1277
|
}, [formSchema, path, initialValue]);
|
|
1227
1278
|
const debounceMs = options?.debounceMs;
|
|
1228
1279
|
const debounceTimerRef = useRef(null);
|
|
@@ -1308,6 +1359,7 @@ function useField(form, pathArg, options) {
|
|
|
1308
1359
|
value: slice.value,
|
|
1309
1360
|
initialValue: slice.initialValue,
|
|
1310
1361
|
emptyValue,
|
|
1362
|
+
clearable,
|
|
1311
1363
|
error: slice.error,
|
|
1312
1364
|
// `?.[0]` covers both the undefined channel and an empty array.
|
|
1313
1365
|
firstError: slice.error?.[0],
|
|
@@ -1322,7 +1374,7 @@ function useField(form, pathArg, options) {
|
|
|
1322
1374
|
validateAsync: validateAsync2,
|
|
1323
1375
|
onBlur
|
|
1324
1376
|
}),
|
|
1325
|
-
[slice, emptyValue, setValue, setTouched, setError, clearError, validate, validateAsync2, onBlur]
|
|
1377
|
+
[slice, emptyValue, clearable, setValue, setTouched, setError, clearError, validate, validateAsync2, onBlur]
|
|
1326
1378
|
);
|
|
1327
1379
|
}
|
|
1328
1380
|
|
|
@@ -1657,9 +1709,7 @@ var textInputProps = (field) => ({
|
|
|
1657
1709
|
"aria-invalid": ariaInvalid(field),
|
|
1658
1710
|
onChange: (e) => {
|
|
1659
1711
|
const text = e.target.value;
|
|
1660
|
-
field.setValue(
|
|
1661
|
-
text === "" && field.emptyValue === null ? null : text
|
|
1662
|
-
);
|
|
1712
|
+
field.setValue(text === "" && field.clearable ? field.emptyValue : text);
|
|
1663
1713
|
},
|
|
1664
1714
|
onBlur: field.onBlur
|
|
1665
1715
|
});
|
|
@@ -1733,9 +1783,7 @@ var selectProps = (field) => ({
|
|
|
1733
1783
|
"aria-invalid": ariaInvalid(field),
|
|
1734
1784
|
onChange: (e) => {
|
|
1735
1785
|
const v = e.target.value;
|
|
1736
|
-
field.setValue(
|
|
1737
|
-
v === "" && field.emptyValue === null ? null : v
|
|
1738
|
-
);
|
|
1786
|
+
field.setValue(v === "" && field.clearable ? field.emptyValue : v);
|
|
1739
1787
|
},
|
|
1740
1788
|
onBlur: field.onBlur
|
|
1741
1789
|
});
|
|
@@ -1942,7 +1990,7 @@ var SelectField = ({
|
|
|
1942
1990
|
const field = useField(form, path);
|
|
1943
1991
|
const a11y = useFieldA11y(field.error);
|
|
1944
1992
|
const select = selectProps(field);
|
|
1945
|
-
const clearable = field.
|
|
1993
|
+
const clearable = field.clearable;
|
|
1946
1994
|
const hasExplicitEmptyOption = options.some((opt) => opt.value === "");
|
|
1947
1995
|
const showEmptyOption = !hasExplicitEmptyOption && (clearable || select.value === "" || placeholder !== void 0);
|
|
1948
1996
|
return /* @__PURE__ */ jsx(
|
|
@@ -2031,6 +2079,6 @@ var focusField = (path, root) => {
|
|
|
2031
2079
|
return path === "" ? (root !== void 0 || document.querySelectorAll("form").length <= 1) && focusFirstOf(namedControls(scope).filter(isFocusCandidate)) : focusFirstOf(pathCandidates(scope, [path]).filter(isFocusCandidate));
|
|
2032
2080
|
};
|
|
2033
2081
|
|
|
2034
|
-
export { CheckboxField, DateField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, hasFieldError, isAsyncRequiredError, numberInputProps, numberToInputText, parseDateText, parseNumberText, persistForm, selectProps, shouldValidateOn, textInputProps, useField, useFieldArray, useFields, useForm, useFormError, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField, validateAsync, validateSync };
|
|
2082
|
+
export { CheckboxField, DateField, NumberField, SelectField, TextField, checkboxProps, createForm, createFormContext, createFormHooks, dateInputProps, dateToInputText, emptyValueForSchema, flattenIssues, focusField, focusFirstError, hasFieldError, isAsyncRequiredError, isClearableSchema, numberInputProps, numberToInputText, parseDateText, parseNumberText, persistForm, selectProps, shouldValidateOn, textInputProps, useField, useFieldArray, useFields, useForm, useFormAction, useFormActionState, useFormError, useFormValues, useIsDirty, useIsSubmitting, useIsValid, useIsValidating, useNumberInput, usePersistForm, useSubmitCount, useVariantField, validateAsync, validateSync };
|
|
2035
2083
|
//# sourceMappingURL=index.js.map
|
|
2036
2084
|
//# sourceMappingURL=index.js.map
|